public ResponseEntity performMigrations()

in streampipes-rest/src/main/java/org/apache/streampipes/rest/impl/admin/MigrationResource.java [88:140]


  public ResponseEntity<Void> performMigrations(
      @Parameter(
          in = ParameterIn.PATH,
          description = "the id of the extensions service that requests migrations",
          required = true
      )
      @PathVariable("serviceId") String serviceId,
      @Parameter(
          description = "list of configs (ModelMigratorConfig) that describe the requested migrations",
          required = true
      )
      @RequestBody List<ModelMigratorConfig> migrationConfigs) {

    var serviceManager = new ServiceRegistrationManager(extensionsServiceStorage);
    try {
      var extensionsServiceConfig = serviceManager.getService(serviceId);
      if (!CoreInitialInstallationProgress.INSTANCE.isInitiallyInstalling()) {
        if (!migrationConfigs.isEmpty()) {
          var anyServiceMigrating = serviceManager.isAnyServiceMigrating();
          var coreReady = isCoreReady();
          if (anyServiceMigrating || !coreReady) {
            LOG.info(
                "Refusing migration request since precondition is not met (anyServiceMigrating={}, coreReady={}.",
                anyServiceMigrating,
                coreReady
            );
            return ResponseEntity.status(HttpStatus.SC_CONFLICT).build();
          } else {
            serviceManager.applyServiceStatus(serviceId, SpServiceStatus.MIGRATING);
            var adapterMigrations = filterConfigs(migrationConfigs, List.of(SpServiceTagPrefix.ADAPTER));
            var pipelineElementMigrations = filterConfigs(
                migrationConfigs,
                List.of(SpServiceTagPrefix.DATA_PROCESSOR, SpServiceTagPrefix.DATA_SINK)
            );

            new AdapterMigrationManager(adapterStorage, adapterDescriptionStorage)
              .handleMigrations(extensionsServiceConfig, adapterMigrations);
            new PipelineElementMigrationManager(
                pipelineStorage,
                dataProcessorStorage,
                dataSinkStorage)
                .handleMigrations(extensionsServiceConfig, pipelineElementMigrations);
          }
        }
      }
      new ServiceRegistrationManager(extensionsServiceStorage)
          .applyServiceStatus(extensionsServiceConfig.getSvcId(), SpServiceStatus.HEALTHY);
      return ok();
    } catch (IllegalArgumentException e) {
      LOG.warn("Refusing migration request since the service {} is not registered.", serviceId);
      throw new SpMessageException(org.springframework.http.HttpStatus.NOT_FOUND, e);
    }
  }