Improve upgrade script to separate long running resources update.
This commit is contained in:
		
							parent
							
								
									b9a5fd0088
								
							
						
					
					
						commit
						15d22e9e6b
					
				@ -35,6 +35,8 @@ import org.thingsboard.server.service.install.migrate.TsLatestMigrateService;
 | 
			
		||||
import org.thingsboard.server.service.install.update.CacheCleanupService;
 | 
			
		||||
import org.thingsboard.server.service.install.update.DataUpdateService;
 | 
			
		||||
 | 
			
		||||
import static org.thingsboard.server.service.install.update.DefaultDataUpdateService.getEnv;
 | 
			
		||||
 | 
			
		||||
@Service
 | 
			
		||||
@Profile("install")
 | 
			
		||||
@Slf4j
 | 
			
		||||
@ -99,6 +101,8 @@ public class ThingsboardInstallService {
 | 
			
		||||
                if ("cassandra-latest-to-postgres".equals(upgradeFromVersion)) {
 | 
			
		||||
                    log.info("Migrating ThingsBoard latest timeseries data from cassandra to SQL database ...");
 | 
			
		||||
                    latestMigrateService.migrate();
 | 
			
		||||
                } else if (upgradeFromVersion.equals("3.9.0-resources")) {
 | 
			
		||||
                    installScripts.updateResourcesUsage();
 | 
			
		||||
                } else {
 | 
			
		||||
                    // TODO DON'T FORGET to update SUPPORTED_VERSIONS_FROM in DefaultDatabaseSchemaSettingsService
 | 
			
		||||
                    databaseSchemaVersionService.validateSchemaSettings();
 | 
			
		||||
@ -118,6 +122,14 @@ public class ThingsboardInstallService {
 | 
			
		||||
                    entityDatabaseSchemaService.createDatabaseIndexes();
 | 
			
		||||
                    // Runs upgrade scripts that are not possible in plain SQL.
 | 
			
		||||
                    // TODO: cleanup update code after each release
 | 
			
		||||
                    if (!getEnv("SKIP_RESOURCES_USAGE_MIGRATION", false)) {
 | 
			
		||||
                        installScripts.setUpdateResourcesUsage(true);
 | 
			
		||||
                    } else {
 | 
			
		||||
                        log.info("Skipping resources usage migration. Run the upgrade with fromVersion as '3.9.0-resources' to migrate");
 | 
			
		||||
                    }
 | 
			
		||||
                    if (installScripts.isUpdateResourcesUsage()) {
 | 
			
		||||
                        installScripts.updateResourcesUsage();
 | 
			
		||||
                    }
 | 
			
		||||
                    dataUpdateService.updateData();
 | 
			
		||||
                    log.info("Updating system data...");
 | 
			
		||||
                    dataUpdateService.upgradeRuleNodes();
 | 
			
		||||
 | 
			
		||||
@ -123,6 +123,9 @@ public class InstallScripts {
 | 
			
		||||
    @Getter @Setter
 | 
			
		||||
    private boolean updateImages = false;
 | 
			
		||||
 | 
			
		||||
    @Getter @Setter
 | 
			
		||||
    private boolean updateResourcesUsage = false;
 | 
			
		||||
 | 
			
		||||
    @Autowired
 | 
			
		||||
    private ImageService imageService;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -65,7 +65,6 @@ public class DefaultDataUpdateService implements DataUpdateService {
 | 
			
		||||
    public void updateData() throws Exception {
 | 
			
		||||
        log.info("Updating data ...");
 | 
			
		||||
        //TODO: should be cleaned after each release
 | 
			
		||||
        installScripts.updateResourcesUsage();
 | 
			
		||||
        log.info("Data updated.");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -113,7 +113,7 @@ public class ResourcesUpdater {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        executor.shutdown();
 | 
			
		||||
        if (!executor.awaitTermination(10, TimeUnit.MINUTES)) {
 | 
			
		||||
        if (!executor.awaitTermination(5, TimeUnit.HOURS)) {
 | 
			
		||||
            throw new RuntimeException("Dashboards resources update timeout"); // just in case, should happen
 | 
			
		||||
        }
 | 
			
		||||
        log.info("Updated {} dashboards", updatedCount);
 | 
			
		||||
@ -142,7 +142,7 @@ public class ResourcesUpdater {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        executor.shutdown();
 | 
			
		||||
        if (!executor.awaitTermination(10, TimeUnit.MINUTES)) {
 | 
			
		||||
        if (!executor.awaitTermination(5, TimeUnit.HOURS)) {
 | 
			
		||||
            throw new RuntimeException("Widgets resources update timeout");
 | 
			
		||||
        }
 | 
			
		||||
        log.info("Updated {} widgets", updatedCount);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user