Browse Source
Merge pull request #11948 from thingsboard/feature/dashboard-sync
Sync with Git: ignore if no changes
pull/11952/head
Andrew Shvayka
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with
15 additions and
9 deletions
-
application/src/main/java/org/thingsboard/server/service/entitiy/dashboard/DashboardSyncService.java
-
application/src/main/java/org/thingsboard/server/service/install/InstallScripts.java
-
application/src/main/java/org/thingsboard/server/service/sync/DefaultGitSyncService.java
-
common/dao-api/src/main/java/org/thingsboard/server/dao/resource/ResourceService.java
-
common/version-control/src/main/java/org/thingsboard/server/service/sync/vc/GitRepository.java
-
dao/src/main/java/org/thingsboard/server/dao/resource/BaseResourceService.java
|
|
|
@ -74,7 +74,7 @@ public class DashboardSyncService { |
|
|
|
List<RepoFile> resources = listFiles("resources"); |
|
|
|
for (RepoFile resourceFile : resources) { |
|
|
|
String data = getFileContent(resourceFile.path()); |
|
|
|
resourceService.updateSystemResource(ResourceType.JS_MODULE, resourceFile.name(), data); |
|
|
|
resourceService.createOrUpdateSystemResource(ResourceType.JS_MODULE, resourceFile.name(), data); |
|
|
|
} |
|
|
|
|
|
|
|
Stream<String> widgetsBundles = listFiles("widget_bundles").stream() |
|
|
|
@ -85,7 +85,7 @@ public class DashboardSyncService { |
|
|
|
|
|
|
|
RepoFile dashboardFile = listFiles("dashboards").get(0); |
|
|
|
String dashboardJson = getFileContent(dashboardFile.path()); |
|
|
|
resourceService.updateSystemResource(ResourceType.DASHBOARD, GATEWAYS_DASHBOARD_KEY, dashboardJson); |
|
|
|
resourceService.createOrUpdateSystemResource(ResourceType.DASHBOARD, GATEWAYS_DASHBOARD_KEY, dashboardJson); |
|
|
|
|
|
|
|
log.info("Gateways dashboard sync completed"); |
|
|
|
} |
|
|
|
|
|
|
|
@ -523,7 +523,7 @@ public class InstallScripts { |
|
|
|
String resourceKey = resourceFile.getFileName().toString(); |
|
|
|
try { |
|
|
|
String data = getContent(resourceFile); |
|
|
|
TbResource resource = resourceService.updateSystemResource(resourceType, resourceKey, data); |
|
|
|
TbResource resource = resourceService.createOrUpdateSystemResource(resourceType, resourceKey, data); |
|
|
|
log.info("{} resource {}", (resource.getId() == null ? "Created" : "Updated"), resourceKey); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new RuntimeException("Unable to load system resource " + resourceFile, e); |
|
|
|
|
|
|
|
@ -70,8 +70,12 @@ public class DefaultGitSyncService implements GitSyncService { |
|
|
|
|
|
|
|
try { |
|
|
|
log.debug("[{}] Fetching repository", key); |
|
|
|
repository.fetch(); |
|
|
|
onUpdate(key); |
|
|
|
boolean updated = repository.fetch(); |
|
|
|
if (updated) { |
|
|
|
onUpdate(key); |
|
|
|
} else { |
|
|
|
log.debug("[{}] No changes in the repository", key); |
|
|
|
} |
|
|
|
} catch (Throwable e) { |
|
|
|
log.error("[{}] Failed to fetch repository", key, e); |
|
|
|
} |
|
|
|
|
|
|
|
@ -64,7 +64,7 @@ public interface ResourceService extends EntityDaoService { |
|
|
|
|
|
|
|
long sumDataSizeByTenantId(TenantId tenantId); |
|
|
|
|
|
|
|
TbResource updateSystemResource(ResourceType resourceType, String resourceKey, String data); |
|
|
|
TbResource createOrUpdateSystemResource(ResourceType resourceType, String resourceKey, String data); |
|
|
|
|
|
|
|
String checkSystemResourcesUsage(String content, ResourceType... usedResourceTypes); |
|
|
|
|
|
|
|
|
|
|
|
@ -68,6 +68,7 @@ import org.thingsboard.server.common.data.page.SortOrder; |
|
|
|
import org.thingsboard.server.common.data.sync.vc.BranchInfo; |
|
|
|
import org.thingsboard.server.common.data.sync.vc.RepositoryAuthMethod; |
|
|
|
import org.thingsboard.server.common.data.sync.vc.RepositorySettings; |
|
|
|
import org.thingsboard.server.common.data.util.CollectionsUtil; |
|
|
|
|
|
|
|
import java.io.ByteArrayInputStream; |
|
|
|
import java.io.ByteArrayOutputStream; |
|
|
|
@ -184,9 +185,9 @@ public class GitRepository { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public void fetch() throws GitAPIException { |
|
|
|
public boolean fetch() throws GitAPIException { |
|
|
|
if (settings.isLocalOnly()) { |
|
|
|
return; |
|
|
|
return false; |
|
|
|
} |
|
|
|
log.debug("Executing fetch [{}]", settings.getRepositoryUri()); |
|
|
|
FetchResult result = execute(git.fetch() |
|
|
|
@ -195,6 +196,7 @@ public class GitRepository { |
|
|
|
if (head != null) { |
|
|
|
this.headId = head.getObjectId(); |
|
|
|
} |
|
|
|
return CollectionsUtil.isNotEmpty(result.getTrackingRefUpdates()); |
|
|
|
} |
|
|
|
|
|
|
|
public void deleteLocalBranchIfExists(String branch) throws GitAPIException { |
|
|
|
|
|
|
|
@ -240,7 +240,7 @@ public class BaseResourceService extends AbstractCachedEntityService<ResourceInf |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public TbResource updateSystemResource(ResourceType resourceType, String resourceKey, String data) { |
|
|
|
public TbResource createOrUpdateSystemResource(ResourceType resourceType, String resourceKey, String data) { |
|
|
|
if (resourceType == ResourceType.DASHBOARD) { |
|
|
|
data = checkSystemResourcesUsage(data, ResourceType.JS_MODULE); |
|
|
|
} |
|
|
|
|