openstack_adapter container fails to start 89/61689/1
authorRob Daugherty <rd472p@att.com>
Tue, 21 Aug 2018 22:42:55 +0000 (18:42 -0400)
committerRob Daugherty <rd472p@att.com>
Tue, 21 Aug 2018 22:42:55 +0000 (18:42 -0400)
The reported problem occurs because the openstack-adapters app
is attempting to do a migration on top of a migration already
performed by the catalog-db app.

I'm adding these options to flyway in openstack-adapters:
  baseline-on-migrate: true
  validate-on-migrate: false

Another issue is that the java-based CloudConfig migration class
was looking for CloudConfig data only in the application.yaml
file in the classpath.  It was not looking for CloudConfig data
in the override file.  I've changed this logic to look in the
override file first and then in application.yaml.  Ideally, these
sources would be merged, but I don't see a reasonable way to do it.

Change-Id: I7ba07c1f8f00b4c628e825393ee31502950fe592
Issue-ID: SO-868
Signed-off-by: Rob Daugherty <rd472p@att.com>
adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java
adapters/mso-openstack-adapters/src/main/resources/application.yaml
packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml

index fd2ec17..87ea49e 100644 (file)
@@ -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;
index 4a4c83e..4b2cf8e 100644 (file)
@@ -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
index dbba5da..df6d921 100644 (file)
         name="org.camunda.bpm.engine.impl.persistence.entity.JobEntity.level"
         level="WARN" />
 
+    <logger name="db.migration" level="DEBUG" />
     <logger name="org.apache.wire" level="DEBUG" />
     <logger name="org.onap" level="DEBUG" />
     <logger name="com.att.ecomp" level="DEBUG" />
         <appender-ref ref="asyncError" />
     </root>
 
-</configuration>
\ No newline at end of file
+</configuration>