aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-openstack-adapters')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java62
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImpl.java17
-rw-r--r--adapters/mso-openstack-adapters/src/main/resources/application.yaml4
3 files changed, 57 insertions, 26 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..d638e47e8c 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
@@ -2,6 +2,8 @@ package db.migration;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import org.flywaydb.core.api.MigrationVersion;
@@ -13,9 +15,13 @@ 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.IOException;
+import java.io.InputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
+import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
@@ -33,10 +39,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 +78,14 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro
this.cloudConfig = cloudConfig;
}
- private CloudConfig loadCloudConfig() throws Exception {
+ private CloudConfig loadCloudConfig(InputStream stream) throws JsonParseException, JsonMappingException, IOException {
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;
@@ -68,12 +96,12 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro
return "/application" + profile + ".yaml";
}
- private void migrateCloudIdentity(Collection<CloudIdentity> entities, Connection connection) throws Exception {
+ private void migrateCloudIdentity(Collection<CloudIdentity> entities, Connection connection) throws SQLException {
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;
@@ -98,12 +126,12 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro
}
}
- private void migrateCloudSite(Collection<CloudSite> entities, Connection connection) throws Exception {
+ private void migrateCloudSite(Collection<CloudSite> entities, Connection connection) throws SQLException {
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;
@@ -127,11 +155,11 @@ public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoPro
}
}
- private void migrateCloudifyManagers(Collection<CloudifyManager> entities, Connection connection) throws Exception {
+ private void migrateCloudifyManagers(Collection<CloudifyManager> entities, Connection connection) throws SQLException {
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/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImpl.java
index b483d40b8a..83db2add0a 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterAsyncImpl.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
* Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
* ================================================================================
+ * Modifications Copyright (C) 2018 IBM.
+ * ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -643,13 +645,14 @@ public class MsoNetworkAdapterAsyncImpl implements MsoNetworkAdapterAsync {
CreateNetworkNotification.SubnetIdMap subnetIdMap = new CreateNetworkNotification.SubnetIdMap ();
if (hMap != null && hMap.value != null) {
- Map <String, String> sMap = new HashMap <> ();
- sMap = hMap.value;
+ Map <String, String> sMap = hMap.value;
CreateNetworkNotification.SubnetIdMap.Entry entry = new CreateNetworkNotification.SubnetIdMap.Entry ();
- for (String key : sMap.keySet ()) {
+ for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
+ String key = mapEntry.getKey();
+ String value = mapEntry.getValue();
entry.setKey (key);
- entry.setValue (sMap.get (key));
+ entry.setValue (value);
subnetIdMap.getEntry ().add (entry);
}
}
@@ -661,8 +664,7 @@ public class MsoNetworkAdapterAsyncImpl implements MsoNetworkAdapterAsync {
UpdateNetworkNotification.SubnetIdMap subnetIdMap = new UpdateNetworkNotification.SubnetIdMap ();
if (hMap != null && hMap.value != null) {
- Map <String, String> sMap = new HashMap <> ();
- sMap = hMap.value;
+ Map <String, String> sMap = hMap.value;
UpdateNetworkNotification.SubnetIdMap.Entry entry = new UpdateNetworkNotification.SubnetIdMap.Entry ();
for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
@@ -681,8 +683,7 @@ public class MsoNetworkAdapterAsyncImpl implements MsoNetworkAdapterAsync {
QueryNetworkNotification.SubnetIdMap subnetIdMap = new QueryNetworkNotification.SubnetIdMap ();
if (hMap != null && hMap.value != null) {
- Map <String, String> sMap = new HashMap <> ();
- sMap = hMap.value;
+ Map <String, String> sMap = hMap.value;
QueryNetworkNotification.SubnetIdMap.Entry entry = new QueryNetworkNotification.SubnetIdMap.Entry ();
for (Map.Entry<String,String> mapEntry : sMap.entrySet ()) {
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