Browse Source

sparkplug: commit1

pull/8235/head
nickAS21 4 years ago
parent
commit
8fa4617a7a
  1. 8
      application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java
  2. 20
      application/src/main/java/org/thingsboard/server/service/install/InstallScripts.java

8
application/src/main/java/org/thingsboard/server/install/ThingsboardInstallService.java

@ -22,7 +22,6 @@ import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Profile; import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.thingsboard.server.dao.resource.ResourceService;
import org.thingsboard.server.service.component.ComponentDiscoveryService; import org.thingsboard.server.service.component.ComponentDiscoveryService;
import org.thingsboard.server.service.install.DatabaseEntitiesUpgradeService; import org.thingsboard.server.service.install.DatabaseEntitiesUpgradeService;
import org.thingsboard.server.service.install.DatabaseTsUpgradeService; import org.thingsboard.server.service.install.DatabaseTsUpgradeService;
@ -90,9 +89,6 @@ public class ThingsboardInstallService {
@Autowired(required = false) @Autowired(required = false)
private TsLatestMigrateService latestMigrateService; private TsLatestMigrateService latestMigrateService;
@Autowired
private ResourceService resourceService;
@Autowired @Autowired
private InstallScripts installScripts; private InstallScripts installScripts;
@ -250,7 +246,7 @@ public class ThingsboardInstallService {
databaseEntitiesUpgradeService.upgradeDatabase("3.4.4"); databaseEntitiesUpgradeService.upgradeDatabase("3.4.4");
log.info("Updating system data..."); log.info("Updating system data...");
systemDataLoaderService.updateSystemWidgets(); systemDataLoaderService.updateSystemWidgets();
installScripts.migrateLwm2mResources(); installScripts.loadSystemLwm2mResources();
break; break;
//TODO update CacheCleanupService on the next version upgrade //TODO update CacheCleanupService on the next version upgrade
default: default:
@ -293,7 +289,7 @@ public class ThingsboardInstallService {
systemDataLoaderService.createQueues(); systemDataLoaderService.createQueues();
// systemDataLoaderService.loadSystemPlugins(); // systemDataLoaderService.loadSystemPlugins();
// systemDataLoaderService.loadSystemRules(); // systemDataLoaderService.loadSystemRules();
installScripts.migrateLwm2mResources(); installScripts.loadSystemLwm2mResources();
if (loadDemo) { if (loadDemo) {
log.info("Loading demo data..."); log.info("Loading demo data...");

20
application/src/main/java/org/thingsboard/server/service/install/InstallScripts.java

@ -267,13 +267,7 @@ public class InstallScripts {
} }
} }
/** public void loadSystemLwm2mResources() {
* TbResource res = new TbResource();
* res.setTenantId(TenantId.SYS_TENANT_ID); // SisAdmin
* res.setData("File base64");
* res.setResourceType(ResourceType.LWM2M_MODEL);
*/
public void migrateLwm2mResources() {
Path resourceLwm2mPath = Paths.get(dataDir, MODELS_LWM2M_DIR); Path resourceLwm2mPath = Paths.get(dataDir, MODELS_LWM2M_DIR);
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(resourceLwm2mPath, path -> path.toString().endsWith(InstallScripts.XML_EXT))) { try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(resourceLwm2mPath, path -> path.toString().endsWith(InstallScripts.XML_EXT))) {
dirStream.forEach( dirStream.forEach(
@ -281,7 +275,7 @@ public class InstallScripts {
try { try {
String data = Base64.getEncoder().encodeToString(Files.readAllBytes(path)); String data = Base64.getEncoder().encodeToString(Files.readAllBytes(path));
TbResource tbResource = new TbResource(); TbResource tbResource = new TbResource();
tbResource.setTenantId(TenantId.SYS_TENANT_ID); // SisAdmin tbResource.setTenantId(TenantId.SYS_TENANT_ID);
tbResource.setData(data); tbResource.setData(data);
tbResource.setResourceType(ResourceType.LWM2M_MODEL); tbResource.setResourceType(ResourceType.LWM2M_MODEL);
tbResource.setFileName(path.toFile().getName()); tbResource.setFileName(path.toFile().getName());
@ -306,12 +300,10 @@ public class InstallScripts {
} }
toLwm2mResource(resource); toLwm2mResource(resource);
resourceService.saveResource(resource); resourceService.saveResource(resource);
} catch (Exception e) { } catch (DataValidationException e) {
if (e.getMessage().equals("Resource with such resourceKey already exists!")) { log.error("[{}] {}", resource.getFileName(), e.getMessage());
log.trace("File of lwm2m model: [{}]. [{}]", resource.getFileName(), e.getMessage()); } catch (Exception ex) {
} else { throw ex;
throw e;
}
} }
} }
} }

Loading…
Cancel
Save