Skip to content

Commit

Permalink
Changes to be in sync with master
Browse files Browse the repository at this point in the history
  • Loading branch information
volodymyr-babak committed Mar 19, 2024
1 parent d4fdeca commit 4fc4a12
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@ public void performInstall() {
entityDatabaseSchemaService.createOrUpdateViewsAndFunctions();
entityDatabaseSchemaService.createOrUpdateDeviceInfoView(persistToTelemetry);

// edge specific
dataUpdateService.deleteAllWidgetBundlesAndTypes();

log.info("Updating system data...");
// dataUpdateService.upgradeRuleNodes();
systemDataLoaderService.loadSystemWidgets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,11 @@
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.WidgetTypeId;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.widget.DeprecatedFilter;
import org.thingsboard.server.common.data.widget.WidgetType;
import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
import org.thingsboard.server.common.data.widget.WidgetTypeInfo;
import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.gen.edge.v1.WidgetTypeUpdateMsg;
import org.thingsboard.server.service.edge.rpc.processor.BaseEdgeProcessor;

import java.util.List;
import java.util.UUID;

@Component
Expand All @@ -57,17 +50,7 @@ public ListenableFuture<Void> processWidgetTypeMsgFromCloud(TenantId tenantId, W
if (widgetTypeByTenantIdAndFqn != null && !widgetTypeByTenantIdAndFqn.getId().equals(widgetTypeDetails.getId())) {
widgetTypeService.deleteWidgetType(widgetTypeByTenantIdAndFqn.getTenantId(), widgetTypeByTenantIdAndFqn.getId());
}
try {
widgetTypeService.saveWidgetType(widgetTypeDetails, false);
} catch (Exception e) {
if (e instanceof DataValidationException && e.getMessage().contains("fqn already exists")) {
deleteWidgetBundlesAndTypes(TenantId.SYS_TENANT_ID);
deleteWidgetBundlesAndTypes(tenantId);
widgetTypeService.saveWidgetType(widgetTypeDetails, false);
} else {
throw new RuntimeException(e);
}
}
widgetTypeService.saveWidgetType(widgetTypeDetails, false);
} finally {
widgetCreationLock.unlock();
}
Expand All @@ -86,22 +69,4 @@ public ListenableFuture<Void> processWidgetTypeMsgFromCloud(TenantId tenantId, W
}
return Futures.immediateFuture(null);
}

private void deleteWidgetBundlesAndTypes(TenantId tenantId) {
List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles(tenantId);
for (WidgetsBundle systemWidgetsBundle : systemWidgetsBundles) {
if (systemWidgetsBundle != null) {
PageData<WidgetTypeInfo> widgetTypes;
var pageLink = new PageLink(1024);
do {
widgetTypes = widgetTypeService.findWidgetTypesInfosByWidgetsBundleId(tenantId, systemWidgetsBundle.getId(), false, DeprecatedFilter.ALL, null, pageLink);
for (var widgetType : widgetTypes.getData()) {
widgetTypeService.deleteWidgetType(tenantId, widgetType.getId());
}
pageLink.nextPageLink();
} while (widgetTypes.hasNext());
widgetsBundleService.deleteWidgetsBundle(tenantId, systemWidgetsBundle.getId());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@ public interface DataUpdateService {
void updateData(String fromVersion) throws Exception;

void upgradeRuleNodes();

void deleteAllWidgetBundlesAndTypes();
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.query.DynamicValue;
import org.thingsboard.server.common.data.query.FilterPredicateValue;
import org.thingsboard.server.common.data.widget.DeprecatedFilter;
import org.thingsboard.server.common.data.widget.WidgetTypeInfo;
import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.alarm.AlarmDao;
import org.thingsboard.server.dao.audit.AuditLogDao;
Expand All @@ -52,7 +50,6 @@
import org.thingsboard.server.dao.tenant.TenantProfileService;
import org.thingsboard.server.dao.tenant.TenantService;
import org.thingsboard.server.dao.timeseries.TimeseriesService;
import org.thingsboard.server.dao.widget.WidgetTypeService;
import org.thingsboard.server.dao.widget.WidgetsBundleService;
import org.thingsboard.server.service.component.ComponentDiscoveryService;
import org.thingsboard.server.service.component.RuleNodeClassInfo;
Expand Down Expand Up @@ -88,9 +85,6 @@ public class DefaultDataUpdateService implements DataUpdateService {
@Autowired
private WidgetsBundleService widgetsBundleService;

@Autowired
private WidgetTypeService widgetTypeService;

@Autowired
private CloudEventService cloudEventService;

Expand Down Expand Up @@ -139,33 +133,6 @@ public void updateData(String fromVersion) throws Exception {
}
}

@Override
public void deleteAllWidgetBundlesAndTypes() {
PageData<Tenant> tenants = tenantService.findTenants(new PageLink(Integer.MAX_VALUE));
for (Tenant tenant : tenants.getData()) {
deleteWidgetBundlesAndTypes(tenant.getId());
}
deleteWidgetBundlesAndTypes(TenantId.SYS_TENANT_ID);
}

private void deleteWidgetBundlesAndTypes(TenantId tenantId) {
List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles(tenantId);
for (WidgetsBundle systemWidgetsBundle : systemWidgetsBundles) {
if (systemWidgetsBundle != null) {
PageData<WidgetTypeInfo> widgetTypes;
var pageLink = new PageLink(1024);
do {
widgetTypes = widgetTypeService.findWidgetTypesInfosByWidgetsBundleId(tenantId, systemWidgetsBundle.getId(), false, DeprecatedFilter.ALL, null, pageLink);
for (var widgetType : widgetTypes.getData()) {
widgetTypeService.deleteWidgetType(tenantId, widgetType.getId());
}
pageLink.nextPageLink();
} while (widgetTypes.hasNext());
widgetsBundleService.deleteWidgetsBundle(tenantId, systemWidgetsBundle.getId());
}
}
}

private void migrateEdgeEvents(String logPrefix) {
boolean skipEdgeEventsMigration = getEnv("TB_SKIP_EDGE_EVENTS_MIGRATION", false);
if (!skipEdgeEventsMigration) {
Expand Down

0 comments on commit 4fc4a12

Please sign in to comment.