diff options
Diffstat (limited to 'adapters/mso-openstack-adapters')
-rw-r--r-- | adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java | 52 | ||||
-rw-r--r-- | adapters/mso-openstack-adapters/src/main/resources/application.yaml | 4 |
2 files changed, 41 insertions, 15 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java b/adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java index fd2ec179dc..ed64abd982 100644 --- a/adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java +++ b/adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java @@ -13,6 +13,8 @@ import org.onap.so.db.catalog.beans.CloudSite; import org.onap.so.db.catalog.beans.CloudifyManager; import org.onap.so.logger.MsoLogger; +import java.io.FileInputStream; +import java.io.InputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -33,10 +35,31 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro @Override public void migrate(Connection connection) throws Exception { LOGGER.debug("Starting migration for CloudConfig"); - CloudConfig cloudConfig = loadCloudConfig(); - if(cloudConfig == null){ - LOGGER.debug("No CloudConfig defined in :"+getApplicationYamlName()+" exiting."); - }else{ + + CloudConfig cloudConfig = null; + + // Try the override file + String configLocation = System.getProperty("spring.config.location"); + if (configLocation != null) { + try (InputStream stream = new FileInputStream(configLocation)) { + cloudConfig = loadCloudConfig(stream); + } + } + + if (cloudConfig == null) { + LOGGER.debug("No CloudConfig defined in " + configLocation); + + // Try the application.yaml file + try (InputStream stream = R__CloudConfigMigration.class.getResourceAsStream(getApplicationYamlName())) { + cloudConfig = loadCloudConfig(stream); + } + + if (cloudConfig == null) { + LOGGER.debug("No CloudConfig defined in " + getApplicationYamlName()); + } + } + + if(cloudConfig != null){ migrateCloudIdentity(cloudConfig.getIdentityServices().values(), connection); migrateCloudSite(cloudConfig.getCloudSites().values(), connection); migrateCloudifyManagers(cloudConfig.getCloudifyManagers().values(), connection); @@ -51,13 +74,14 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro this.cloudConfig = cloudConfig; } - private CloudConfig loadCloudConfig() throws Exception { + private CloudConfig loadCloudConfig(InputStream stream) throws Exception { ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); - R__CloudConfigMigration cloudConfigMigration = mapper.readValue(R__CloudConfigMigration.class - .getResourceAsStream(getApplicationYamlName()), R__CloudConfigMigration.class); + R__CloudConfigMigration cloudConfigMigration = + mapper.readValue(stream, R__CloudConfigMigration.class); CloudConfig cloudConfig = cloudConfigMigration.getCloudConfig(); + if(cloudConfig != null){ - cloudConfig.populateId(); + cloudConfig.populateId(); } return cloudConfig; @@ -72,8 +96,8 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro LOGGER.debug("Starting migration for CloudConfig-->IdentityService"); String insert = "INSERT INTO `identity_services` (`ID`, `IDENTITY_URL`, `MSO_ID`, `MSO_PASS`, `ADMIN_TENANT`, `MEMBER_ROLE`, `TENANT_METADATA`, `IDENTITY_SERVER_TYPE`, `IDENTITY_AUTHENTICATION_TYPE`, `LAST_UPDATED_BY`) " + "VALUES (?,?,?,?,?,?,?,?,?,?);"; - PreparedStatement ps = connection.prepareStatement(insert); - try (Statement stmt = connection.createStatement()) { + + try (Statement stmt = connection.createStatement();PreparedStatement ps = connection.prepareStatement(insert)) { for (CloudIdentity cloudIdentity : entities) { try (ResultSet rows = stmt.executeQuery("Select count(1) from identity_services where id='" + cloudIdentity.getId() + "'")) { int count = 0; @@ -102,8 +126,8 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro LOGGER.debug("Starting migration for CloudConfig-->CloudSite"); String insert = "INSERT INTO `cloud_sites` (`ID`, `REGION_ID`, `IDENTITY_SERVICE_ID`, `CLOUD_VERSION`, `CLLI`, `CLOUDIFY_ID`, `PLATFORM`, `ORCHESTRATOR`, `LAST_UPDATED_BY`) " + "VALUES (?,?,?,?,?,?,?,?,?);"; - PreparedStatement ps = connection.prepareStatement(insert); - try (Statement stmt = connection.createStatement()) { + + try (Statement stmt = connection.createStatement();PreparedStatement ps = connection.prepareStatement(insert)) { for (CloudSite cloudSite : entities) { try (ResultSet rows = stmt.executeQuery("Select count(1) from cloud_sites where id='" + cloudSite.getId() + "'")) { int count = 0; @@ -130,8 +154,8 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro private void migrateCloudifyManagers(Collection<CloudifyManager> entities, Connection connection) throws Exception { String insert = "INSERT INTO `cloudify_managers` (`ID`, `CLOUDIFY_URL`, `USERNAME`, `PASSWORD`, `VERSION`, `LAST_UPDATED_BY`)" + " VALUES (?,?,?,?,?,?);"; - PreparedStatement ps = connection.prepareStatement(insert); - try (Statement stmt = connection.createStatement()) { + + try (Statement stmt = connection.createStatement();PreparedStatement ps = connection.prepareStatement(insert)) { for (CloudifyManager cloudifyManager : entities) { try (ResultSet rows = stmt.executeQuery("Select count(1) from cloudify_managers where id='" + cloudifyManager.getId() + "'")) { int count = 0; diff --git a/adapters/mso-openstack-adapters/src/main/resources/application.yaml b/adapters/mso-openstack-adapters/src/main/resources/application.yaml index 4a4c83e4a5..4b2cf8eb60 100644 --- a/adapters/mso-openstack-adapters/src/main/resources/application.yaml +++ b/adapters/mso-openstack-adapters/src/main/resources/application.yaml @@ -41,4 +41,6 @@ management: flyway: outOfOrder: true - ignoreMissingMigrations: true
\ No newline at end of file + ignoreMissingMigrations: true + baseline-on-migrate: true + validate-on-migrate: false |