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.java52
-rw-r--r--adapters/mso-openstack-adapters/src/main/resources/application.yaml4
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vdu/mapper/VfModuleCustomizationToVduMapperTest.java146
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java3
4 files changed, 187 insertions, 18 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
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vdu/mapper/VfModuleCustomizationToVduMapperTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vdu/mapper/VfModuleCustomizationToVduMapperTest.java
new file mode 100644
index 0000000000..c982f8beb1
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vdu/mapper/VfModuleCustomizationToVduMapperTest.java
@@ -0,0 +1,146 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2018 Nokia
+ * ================================================================================
+ * 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
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vdu.mapper;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.common.collect.Lists;
+import java.util.List;
+import org.junit.Test;
+import org.onap.so.adapters.vdu.VduArtifact;
+import org.onap.so.adapters.vdu.VduArtifact.ArtifactType;
+import org.onap.so.adapters.vdu.VduModelInfo;
+import org.onap.so.db.catalog.beans.HeatEnvironment;
+import org.onap.so.db.catalog.beans.HeatFiles;
+import org.onap.so.db.catalog.beans.HeatTemplate;
+import org.onap.so.db.catalog.beans.VfModule;
+import org.onap.so.db.catalog.beans.VfModuleCustomization;
+
+public class VfModuleCustomizationToVduMapperTest {
+
+ private static final String MODEL_CUSTOMIZATION_UUID = "modelCustomizationUUID";
+ private static final String HEAT_ENV_NAME = "heatEnvName";
+ private static final String HEAT_ENV_CONTENT = "heatEnvContent";
+ private static final String MODULE_HEAT_TEMPLATE_NAME = "moduleHeatTemplateName";
+ private static final String MODULE_HEAT_TEMPLATE_BODY = "moduleHeatTemplateBody";
+ private static final String NESTED_TEMPLATE_NAME = "nestedTemplateName";
+ private static final String NESTED_TEMPLATE_BODY = "nestedTemplateBody";
+ private static final int TIMEOUT_IN_MIN = 66;
+ private static final String VF_MODULE_MODEL_INVARIANT_UUID = "vfModuleModelInvariantUUID";
+ private static final String CLOUD_FILE_NAME = "cloudFileName";
+ private static final String CLOUD_FILE_BODY = "cloudFileBody";
+
+
+ @Test
+ public void mapVfModuleCustomizationToVdu_successful() {
+ // GIVEN
+ VfModuleCustomization vfModuleCustomization = createVfModuleCustomization();
+ vfModuleCustomization.setHeatEnvironment(createHeatEnvironment(HEAT_ENV_NAME, HEAT_ENV_CONTENT));
+ VfModule vfModule = createVfModule();
+ vfModule.setModuleHeatTemplate(createHeatTemplate(
+ MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY,
+ NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY));
+ vfModuleCustomization.setVfModule(vfModule);
+
+ // WHEN
+ VduModelInfo vduModelInfo = new VfModuleCustomizationToVduMapper()
+ .mapVfModuleCustomizationToVdu(vfModuleCustomization);
+
+ // THEN
+ assertThat(vduModelInfo.getModelCustomizationUUID()).isEqualTo(MODEL_CUSTOMIZATION_UUID);
+ assertThat(vduModelInfo.getTimeoutMinutes()).isEqualTo(TIMEOUT_IN_MIN);
+ assertThat(vduModelInfo.getArtifacts()).containsExactlyElementsOf(createExpectedVduArtifacts());
+ }
+
+ @Test
+ public void mapVfModuleCustVolumeToVdu_successful() {
+ // GIVEN
+ VfModuleCustomization vfModuleCustomization = createVfModuleCustomization();
+ vfModuleCustomization.setVolumeHeatEnv(createHeatEnvironment(HEAT_ENV_NAME, HEAT_ENV_CONTENT));
+ VfModule vfModule = createVfModule();
+ vfModule.setVolumeHeatTemplate(createHeatTemplate(
+ MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY,
+ NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY));
+ vfModuleCustomization.setVfModule(vfModule);
+
+ // WHEN
+ VduModelInfo vduModelInfo = new VfModuleCustomizationToVduMapper()
+ .mapVfModuleCustVolumeToVdu(vfModuleCustomization);
+
+ // THEN
+ assertThat(vduModelInfo.getModelCustomizationUUID()).isEqualTo(MODEL_CUSTOMIZATION_UUID);
+ assertThat(vduModelInfo.getTimeoutMinutes()).isEqualTo(TIMEOUT_IN_MIN);
+ assertThat(vduModelInfo.getArtifacts()).containsExactlyElementsOf(createExpectedVduArtifacts());
+ }
+
+ private VfModuleCustomization createVfModuleCustomization() {
+ VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
+ vfModuleCustomization.setModelCustomizationUUID(MODEL_CUSTOMIZATION_UUID);
+ return vfModuleCustomization;
+ }
+
+ private HeatEnvironment createHeatEnvironment(String volHeatEnvName, String volHeatEnvContent) {
+ HeatEnvironment heatEnvironment = new HeatEnvironment();
+ heatEnvironment.setName(volHeatEnvName);
+ heatEnvironment.setEnvironment(volHeatEnvContent);
+ return heatEnvironment;
+ }
+
+ private VfModule createVfModule() {
+ VfModule vfModule = new VfModule();
+ vfModule.setModelInvariantUUID(VF_MODULE_MODEL_INVARIANT_UUID);
+ vfModule.setHeatFiles(createHeatFiles(CLOUD_FILE_NAME, CLOUD_FILE_BODY));
+ return vfModule;
+ }
+
+ private List<HeatFiles> createHeatFiles(String fileName, String fileBody) {
+ HeatFiles heatFiles = new HeatFiles();
+ heatFiles.setFileName(fileName);
+ heatFiles.setFileBody(fileBody);
+ return Lists.newArrayList(heatFiles);
+ }
+
+ private HeatTemplate createHeatTemplate(String moduleHeatTemplateName, String moduleHeatTemplateBody,
+ String childTemplateName, String childTemplateBody) {
+ HeatTemplate heatTemplate = new HeatTemplate();
+ heatTemplate.setTemplateName(moduleHeatTemplateName);
+ heatTemplate.setTemplateBody(moduleHeatTemplateBody);
+ heatTemplate.setTimeoutMinutes(TIMEOUT_IN_MIN);
+ heatTemplate.setChildTemplates(createChildHeatTemplate(childTemplateName, childTemplateBody));
+ return heatTemplate;
+ }
+
+ private List<HeatTemplate> createChildHeatTemplate(String moduleHeatTemplateName, String moduleHeatTemplateBody) {
+ HeatTemplate heatTemplate = new HeatTemplate();
+ heatTemplate.setTemplateName(moduleHeatTemplateName);
+ heatTemplate.setTemplateBody(moduleHeatTemplateBody);
+ return Lists.newArrayList(heatTemplate);
+ }
+
+ private List<VduArtifact> createExpectedVduArtifacts() {
+ return Lists.newArrayList(
+ new VduArtifact(MODULE_HEAT_TEMPLATE_NAME, MODULE_HEAT_TEMPLATE_BODY.getBytes(),
+ ArtifactType.MAIN_TEMPLATE),
+ new VduArtifact(NESTED_TEMPLATE_NAME, NESTED_TEMPLATE_BODY.getBytes(), ArtifactType.NESTED_TEMPLATE),
+ new VduArtifact(CLOUD_FILE_NAME, CLOUD_FILE_BODY.getBytes(), ArtifactType.TEXT_FILE),
+ new VduArtifact(HEAT_ENV_NAME, HEAT_ENV_CONTENT.getBytes(), ArtifactType.ENVIRONMENT));
+ }
+}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java
index cf68f097dc..d2b6d4f633 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/vnf/BaseRestTestUtils.java
@@ -33,7 +33,6 @@ import org.onap.so.db.catalog.beans.AuthenticationType;
import org.onap.so.db.catalog.beans.CloudIdentity;
import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.db.catalog.beans.ServerType;
-import org.onap.so.db.catalog.data.repository.CloudIdentityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
@@ -76,8 +75,6 @@ public class BaseRestTestUtils {
public ObjectMapper mapper;
- @Autowired
- private CloudIdentityRepository cloudIdentityRepository;
protected String readJsonFileAsString(String fileLocation) throws JsonParseException, JsonMappingException, IOException{
ObjectMapper mapper = new ObjectMapper();