summaryrefslogtreecommitdiffstats
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/pom.xml4
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/db/migration/CloudConfig.java87
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java236
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java2
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java8
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java34
-rw-r--r--adapters/mso-openstack-adapters/src/main/resources/application-local.yaml5
-rw-r--r--adapters/mso-openstack-adapters/src/main/resources/application.yaml20
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/db/migration/CloudConfigMigrationTest.java127
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java44
-rw-r--r--adapters/mso-openstack-adapters/src/test/resources/GetResourcesNoServer.json25
-rw-r--r--adapters/mso-openstack-adapters/src/test/resources/application-test.yaml38
12 files changed, 90 insertions, 540 deletions
diff --git a/adapters/mso-openstack-adapters/pom.xml b/adapters/mso-openstack-adapters/pom.xml
index 8d4f30b631..46e73246a0 100644
--- a/adapters/mso-openstack-adapters/pom.xml
+++ b/adapters/mso-openstack-adapters/pom.xml
@@ -261,10 +261,6 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.flywaydb</groupId>
- <artifactId>flyway-core</artifactId>
- </dependency>
- <dependency>
<groupId>org.onap.so</groupId>
<artifactId>cxf-logging</artifactId>
<version>${project.version}</version>
diff --git a/adapters/mso-openstack-adapters/src/main/java/db/migration/CloudConfig.java b/adapters/mso-openstack-adapters/src/main/java/db/migration/CloudConfig.java
deleted file mode 100644
index 82139f21af..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/db/migration/CloudConfig.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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 db.migration;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import org.onap.so.db.catalog.beans.CloudIdentity;
-import org.onap.so.db.catalog.beans.CloudSite;
-import org.onap.so.db.catalog.beans.CloudifyManager;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @deprecated
- * This class is introduced as deprecated as its only purpose is for migration of cloud config data. It shouldnt be used elsewhere.
- */
-
-@Deprecated
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class CloudConfig {
- @JsonProperty("identity_services")
- private Map<String, CloudIdentity> identityServices = new HashMap<>();
-
- @JsonProperty("cloud_sites")
- private Map<String, CloudSite> cloudSites = new HashMap<>();
-
- @JsonProperty("cloudify_managers")
- private Map<String, CloudifyManager> cloudifyManagers = new HashMap<>();
-
-
- public Map<String, CloudIdentity> getIdentityServices() {
- return identityServices;
- }
-
- public void setIdentityServices(Map<String, CloudIdentity> identityServices) {
- this.identityServices = identityServices;
- }
-
- public Map<String, CloudSite> getCloudSites() {
- return cloudSites;
- }
-
- public void setCloudSites(Map<String, CloudSite> cloudSites) {
- this.cloudSites = cloudSites;
- }
-
- public Map<String, CloudifyManager> getCloudifyManagers() {
- return cloudifyManagers;
- }
-
- public void setCloudifyManagers(Map<String, CloudifyManager> cloudifyManagers) {
- this.cloudifyManagers = cloudifyManagers;
- }
-
- public void populateId(){
- for (Map.Entry<String, CloudIdentity> entry : identityServices.entrySet()) {
- entry.getValue().setId(entry.getKey());
- }
-
- for (Map.Entry <String, CloudSite> entry : cloudSites.entrySet()) {
- entry.getValue().setId(entry.getKey());
- }
-
- for (Map.Entry<String, CloudifyManager> entry : cloudifyManagers.entrySet()) {
- entry.getValue().setId(entry.getKey());
- }
- }
-}
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
deleted file mode 100644
index 5acd8359ec..0000000000
--- a/adapters/mso-openstack-adapters/src/main/java/db/migration/R__CloudConfigMigration.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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 db.migration;
-
-import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
-import org.flywaydb.core.api.MigrationVersion;
-import org.flywaydb.core.api.migration.MigrationChecksumProvider;
-import org.flywaydb.core.api.migration.MigrationInfoProvider;
-import org.flywaydb.core.api.migration.jdbc.JdbcMigration;
-import org.onap.so.db.catalog.beans.CloudIdentity;
-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.nio.file.Paths;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Collection;
-
-/**
- * Performs migration using JDBC Connection from the cloud config provided in the environment (application-{profile}.yaml) and persist data (when not already present) to the catalod database.
- */
-@JsonIgnoreProperties(ignoreUnknown = true)
-public class R__CloudConfigMigration implements JdbcMigration , MigrationInfoProvider, MigrationChecksumProvider {
- public static final String FLYWAY = "FLYWAY";
-
- private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, R__CloudConfigMigration.class);
- @JsonProperty("cloud_config")
- private CloudConfig cloudConfig;
-
- @Override
- public boolean isUndo(){
- return false;
- }
-
- @Override
- public void migrate(Connection connection) throws Exception {
- LOGGER.debug("Starting migration for CloudConfig");
-
- CloudConfig cloudConfig = null;
-
- String tableQuery = "SELECT * FROM identity_services";
- int totalRetries = 20;
- boolean tableExists = false;
- int count = 1;
- while(!tableExists && count != totalRetries) {
- try(Statement stmt = connection.createStatement();) {
- stmt.executeQuery(tableQuery);
- tableExists = true;
- } catch (SQLException e) {
- count++;
- // Wait 5 mintues
- Thread.sleep(300000);
- }
- }
-
- // Try the override file
- String configLocation = System.getProperty("spring.config.additional-location");
- if (configLocation != null) {
- try (InputStream stream = new FileInputStream(Paths.get(configLocation).normalize().toString())) {
- cloudConfig = loadCloudConfig(stream);
- }catch(Exception e){
- LOGGER.warnSimple("Error Loading override.yaml",e);
- }
- }
-
- 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);
- }
- }
-
- public CloudConfig getCloudConfig() {
- return cloudConfig;
- }
-
- public void setCloudConfig(CloudConfig cloudConfig) {
- this.cloudConfig = cloudConfig;
- }
-
- private CloudConfig loadCloudConfig(InputStream stream) throws IOException {
- ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
- R__CloudConfigMigration cloudConfigMigration =
- mapper.readValue(stream, R__CloudConfigMigration.class);
- CloudConfig cloudConfig = cloudConfigMigration.getCloudConfig();
-
- if(cloudConfig != null){
- cloudConfig.populateId();
- }
-
- return cloudConfig;
- }
-
- private String getApplicationYamlName() {
- String profile = System.getProperty("spring.profiles.active") == null ? "" : "-" + System.getProperty("spring.profiles.active");
- return "/application" + profile + ".yaml";
- }
-
- 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 (?,?,?,?,?,?,?,?,?,?);";
-
- 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;
- while (rows.next()) {
- count = rows.getInt(1);
- }
- if (count == 0) {
- ps.setString(1, cloudIdentity.getId());
- ps.setString(2, cloudIdentity.getIdentityUrl());
- ps.setString(3, cloudIdentity.getMsoId());
- ps.setString(4, cloudIdentity.getMsoPass());
- ps.setString(5, cloudIdentity.getAdminTenant());
- ps.setString(6, cloudIdentity.getMemberRole());
- ps.setBoolean(7, cloudIdentity.getTenantMetadata());
- ps.setString(8, cloudIdentity.getIdentityServerType() != null ? cloudIdentity.getIdentityServerType().name() : null);
- ps.setString(9, cloudIdentity.getIdentityAuthenticationType() != null ? cloudIdentity.getIdentityAuthenticationType().name() : null);
- ps.setString(10, FLYWAY);
- ps.executeUpdate();
- }
- }
- }
- }
- }
-
- 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 (?,?,?,?,?,?,?,?,?);";
-
- 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;
- while (rows.next()) {
- count = rows.getInt(1);
- }
- if (count == 0) {
- ps.setString(1, cloudSite.getId());
- ps.setString(2, cloudSite.getRegionId());
- ps.setString(3, cloudSite.getIdentityServiceId());
- ps.setString(4, cloudSite.getCloudVersion());
- ps.setString(5, cloudSite.getClli());
- ps.setString(6, cloudSite.getCloudifyId());
- ps.setString(7, cloudSite.getPlatform());
- ps.setString(8, cloudSite.getOrchestrator());
- ps.setString(9, FLYWAY);
- ps.executeUpdate();
- }
- }
- }
- }
- }
-
- 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 (?,?,?,?,?,?);";
-
- 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;
- while (rows.next()) {
- count = rows.getInt(1);
- }
- if (count == 0) {
- ps.setString(1, cloudifyManager.getId());
- ps.setString(2, cloudifyManager.getCloudifyUrl());
- ps.setString(3, cloudifyManager.getUsername());
- ps.setString(4, cloudifyManager.getPassword());
- ps.setString(5, cloudifyManager.getVersion());
- ps.setString(6, FLYWAY);
- ps.executeUpdate();
- }
- }
- }
- }
- }
-
- public MigrationVersion getVersion() {
- return null;
- }
-
- public String getDescription() {
- return "R_CloudConfigMigration";
- }
-
- public Integer getChecksum() {
- return Math.toIntExact(System.currentTimeMillis() / 1000);
- }
-}
-
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java
index 38b00688a7..aace75ff99 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java
@@ -60,7 +60,7 @@ public class AuditStackService {
auth);
ExternalTaskClient client = ExternalTaskClient.create()
.baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(5).addInterceptor(interceptor)
- .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build();
+ .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(5000, 2, 30000)).build();
client.subscribe("InventoryAudit").lockDuration(5000)
.handler(auditStack::executeExternalTask).open();
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java
index b0369395ed..ffbe1b4c46 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackServiceData.java
@@ -24,9 +24,11 @@ import java.util.Collections;
import org.camunda.bpm.client.task.ExternalTask;
import org.camunda.bpm.client.task.ExternalTaskService;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.audit.beans.AuditInventory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@@ -49,6 +51,7 @@ public class AuditStackServiceData {
protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService){
AuditInventory auditInventory = externalTask.getVariable("auditInventory");
+ setupMDC(externalTask);
boolean success = false;
try {
logger.info("Executing External Task Audit Inventory, Retry Number: {} \n {}", auditInventory,externalTask.getRetries());
@@ -78,6 +81,11 @@ public class AuditStackServiceData {
}
+ private void setupMDC(ExternalTask externalTask) {
+ String msoRequestId = (String)externalTask.getVariable("mso-request-id");
+ if(msoRequestId != null && !msoRequestId.isEmpty())
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
+ }
protected long calculateRetryDelay(int currentRetries){
int retrySequence = RETRY_SEQUENCE.length - currentRetries;
long retryMultiplier = Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier","6000"));
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java
index 974315374a..da833c7b07 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/HeatStackAudit.java
@@ -25,6 +25,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -63,10 +65,14 @@ public class HeatStackAudit {
.filter(p -> "OS::Nova::Server".equals(p.getType())).collect(Collectors.toList());
List<Resource> resourceGroups = resources.getList().stream()
.filter(p -> "OS::Heat::ResourceGroup".equals(p.getType()) && p.getName().contains("subinterfaces")).collect(Collectors.toList());
- Set<Vserver> vserversToAudit = createVserverSet(resources, novaResources);
- Set<Vserver> vserversWithSubInterfaces = processSubInterfaces(cloudRegion, tenantId, resourceGroups,
- vserversToAudit);
- return auditVservers.auditVservers(vserversWithSubInterfaces, tenantId, cloudOwner, cloudRegion);
+ if(novaResources.isEmpty())
+ return true;
+ else{
+ Set<Vserver> vserversToAudit = createVserverSet(resources, novaResources);
+ Set<Vserver> vserversWithSubInterfaces = processSubInterfaces(cloudRegion, tenantId, resourceGroups,
+ vserversToAudit);
+ return auditVservers.auditVservers(vserversWithSubInterfaces, tenantId, cloudOwner, cloudRegion);
+ }
} catch (Exception e) {
logger.error("Error during auditing stack resources", e);
return false;
@@ -174,11 +180,13 @@ public class HeatStackAudit {
return vserversToAudit;
}
- protected Optional<String> extractResourcePathFromHref(String href) {
- URI uri;
+ protected Optional<String> extractResourcePathFromHref(String href) {
try {
- uri = new URI(href);
- return Optional.of(uri.getPath().replaceFirst("/v\\d+", "")+RESOURCES);
+ Optional<String> stackPath = extractStackPathFromHref(href);
+ if (stackPath.isPresent()){
+ return Optional.of(stackPath.get()+RESOURCES);
+ }else
+ return Optional.empty();
} catch (Exception e) {
logger.error("Error parsing URI", e);
}
@@ -186,10 +194,14 @@ public class HeatStackAudit {
}
protected Optional<String> extractStackPathFromHref(String href) {
- URI uri;
try {
- uri = new URI(href);
- return Optional.of(uri.getPath().replaceFirst("/v\\d+", ""));
+ URI uri = new URI(href);
+ Pattern p = Pattern.compile("/stacks.*");
+ Matcher m = p.matcher(uri.getPath());
+ if (m.find()){
+ return Optional.of(m.group());
+ }else
+ return Optional.empty();
} catch (Exception e) {
logger.error("Error parsing URI", e);
}
diff --git a/adapters/mso-openstack-adapters/src/main/resources/application-local.yaml b/adapters/mso-openstack-adapters/src/main/resources/application-local.yaml
index 67c4dd3c22..ef9b113e70 100644
--- a/adapters/mso-openstack-adapters/src/main/resources/application-local.yaml
+++ b/adapters/mso-openstack-adapters/src/main/resources/application-local.yaml
@@ -108,8 +108,3 @@ spring:
password: '$2a$12$tidKuu.h88E2nuL95pTVY.ZOYMN/1dp29A9b1o.0GFDsVVSYlMkHa'
role: ACTUATOR
-
-flyway:
- outOfOrder: true
- ignoreMissingMigrations: true
-
diff --git a/adapters/mso-openstack-adapters/src/main/resources/application.yaml b/adapters/mso-openstack-adapters/src/main/resources/application.yaml
index 18084ced8d..e682060c74 100644
--- a/adapters/mso-openstack-adapters/src/main/resources/application.yaml
+++ b/adapters/mso-openstack-adapters/src/main/resources/application.yaml
@@ -18,10 +18,12 @@ mso:
retryMultiplier: 60000
spring:
datasource:
- jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
+ type: com.zaxxer.hikari.HikariDataSource
+ url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: org.mariadb.jdbc.Driver
+ initialization-mode: never
jpa:
show-sql: true
hibernate:
@@ -43,18 +45,4 @@ management:
export:
prometheus:
enabled: true # Whether exporting of metrics to Prometheus is enabled.
- step: 1m # Step size (i.e. reporting frequency) to use.
-
-
-flyway:
- outOfOrder: true
- ignoreMissingMigrations: true
- baseline-on-migrate: true
- validate-on-migrate: false
-
-org:
- onap:
- so:
- adapters:
- network:
- encryptionKey: aa3871669d893c7fb8abbcda31b88b4f
+ step: 1m # Step size (i.e. reporting frequency) to use.
diff --git a/adapters/mso-openstack-adapters/src/test/java/db/migration/CloudConfigMigrationTest.java b/adapters/mso-openstack-adapters/src/test/java/db/migration/CloudConfigMigrationTest.java
deleted file mode 100644
index d83e929d6e..0000000000
--- a/adapters/mso-openstack-adapters/src/test/java/db/migration/CloudConfigMigrationTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * 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 db.migration;
-
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.so.adapters.vnf.BaseRestTestUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-public class CloudConfigMigrationTest extends BaseRestTestUtils {
-
- @Qualifier("dataSource")
- @Autowired
- DataSource dataSource;
-
- R__CloudConfigMigration cloudConfigMigration;
-
- @Before
- public void setup() {
- cloudConfigMigration = new R__CloudConfigMigration();
- }
-
- @Test
- public void testMigrate() throws Exception {
- System.setProperty("spring.profiles.active", "test");
- cloudConfigMigration.migrate(dataSource.getConnection());
- assertMigratedIdentityServiceData();
- assertMigratedCloudSiteData();
- assertMigratedCloudManagerData();
- }
-
- @Test
- public void testMigrateNoData() throws Exception {
- System.setProperty("spring.profiles.active", "nomigrate");
- int identityCount = getDataCount("identity_services");
- int cloudSiteCount = getDataCount("cloud_sites");
- int cloudManagerCount = getDataCount("cloudify_managers");
-
- cloudConfigMigration.migrate(dataSource.getConnection());
-
- Assert.assertEquals(identityCount, getDataCount("identity_services"));
- Assert.assertEquals(cloudSiteCount, getDataCount("cloud_sites"));
- Assert.assertEquals(cloudManagerCount, getDataCount("cloudify_managers"));
- }
-
-
- private int getDataCount(String tableName) throws Exception {
- try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select count(1) from " + tableName)) {
- while (rs.next()) {
- return rs.getInt(1);
- }
- }
- return 0;
- }
-
- private void assertMigratedIdentityServiceData() throws Exception {
- try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from identity_services where id='MTKEYSTONE'")) {
- boolean dataAvailable = false;
- while (rs.next()) {
- dataAvailable = true;
- Assert.assertEquals("MTKEYSTONE", rs.getString("id"));
- Assert.assertEquals("http://localhost:5000/v2.0", rs.getString("identity_url"));
- Assert.assertEquals("john", rs.getString("mso_id"));
- Assert.assertEquals("313DECE408AF7759D442D7B06DD9A6AA", rs.getString("mso_pass"));
- Assert.assertEquals("admin", rs.getString("admin_tenant"));
- Assert.assertEquals("_member_", rs.getString("member_role"));
- Assert.assertEquals("KEYSTONE", rs.getString("identity_server_type"));
- Assert.assertEquals("USERNAME_PASSWORD", rs.getString("identity_authentication_type"));
- }
- Assert.assertTrue("Expected data in identity_services table post migration but didnt find any!!!", dataAvailable);
- }
- }
-
- private void assertMigratedCloudSiteData() throws Exception {
- try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from cloud_sites where id='regionOne'")) {
- boolean dataAvailable = false;
- while (rs.next()) {
- dataAvailable = true;
- Assert.assertEquals("regionOne", rs.getString("id"));
- Assert.assertEquals("regionOne", rs.getString("region_id"));
- Assert.assertEquals("MT2", rs.getString("clli"));
- Assert.assertEquals("2.5", rs.getString("cloud_version"));
- Assert.assertEquals("MTKEYSTONE", rs.getString("identity_service_id"));
- }
- Assert.assertTrue("Expected data in identity_services table post migration but didnt find any!!!", dataAvailable);
- }
- }
-
- private void assertMigratedCloudManagerData() throws Exception {
- try (Connection con = dataSource.getConnection(); Statement stmt = con.createStatement(); ResultSet rs = stmt.executeQuery("select * from cloudify_managers where id='manager'")) {
- boolean dataAvailable = false;
- while (rs.next()) {
- dataAvailable = true;
- Assert.assertEquals("http://localhost:8080", rs.getString("cloudify_url"));
- Assert.assertEquals("user", rs.getString("username"));
- Assert.assertEquals("password", rs.getString("password"));
- Assert.assertEquals("2.0", rs.getString("version"));
- }
- Assert.assertTrue("Expected data in identity_services table post migration but didnt find any!!!", dataAvailable);
- }
- }
-}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java
index c5b93a7cb9..696784110b 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/HeatStackAuditTest.java
@@ -80,19 +80,19 @@ public class HeatStackAuditTest extends HeatStackAudit {
@Test
public void extract_proper_path_Test(){
- Optional<String> actualResult = extractStackPathFromHref("https://orchestration.com:8004/v1/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
- assertEquals("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81", actualResult.get());
+ Optional<String> actualResult = extractStackPathFromHref("https://orchestration.com:8004/v1/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
+ assertEquals("/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81", actualResult.get());
}
@Test
public void extract_proper_resources_path_Test(){
- Optional<String> actualResult = extractResourcePathFromHref("https://orchestration.com:8004/v1/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
- assertEquals("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81/resources", actualResult.get());
+ Optional<String> actualResult = extractResourcePathFromHref("https://orchestration.com:8004/v1/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
+ assertEquals("/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81/resources", actualResult.get());
}
@Test
public void extract_invalid_uri_Test(){
- Optional<String> actualResult = extractStackPathFromHref("orchestrn.com:8004/v18b44d60a6f94bdcb2738f9e/stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
+ Optional<String> actualResult = extractStackPathFromHref("orchestrn.com:8004/v18b44d60a6f94bdcb2738f9e//stacks/test_stack/f711be16-2654-4a09-b89d-0511fda20e81");
assertEquals(false, actualResult.isPresent());
}
@@ -114,6 +114,8 @@ public class HeatStackAuditTest extends HeatStackAudit {
ssc_1_trusted_port_0.setInterfaceId("d2f51f82-0ec2-4581-bd1a-d2a82073e52b");
vServer1.getLInterfaces().getLInterface().add(ssc_1_trusted_port_0);
+
+
LInterface ssc_1_mgmt_port_1 = new LInterface();
ssc_1_mgmt_port_1.setInterfaceId("07f5b14c-147a-4d14-8c94-a9e94dbc097b");
vServer1.getLInterfaces().getLInterface().add(ssc_1_mgmt_port_1);
@@ -156,33 +158,34 @@ public class HeatStackAuditTest extends HeatStackAudit {
expectedVservers.add(vServer1);
+
Resources service1QueryResponse = objectMapper.readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class);
- doReturn(service1QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz/31d0647a-6043-49a4-81b6-ccab29380672/resources", cloudRegion, tenantId, Resources.class);
+ doReturn(service1QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz/31d0647a-6043-49a4-81b6-ccab29380672/resources", cloudRegion, tenantId, Resources.class);
Resources service2QueryResponse =objectMapper.readValue(new File("src/test/resources/Service2ResourceGroupResponse.json"), Resources.class);
- doReturn(service2QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst/447a9b41-714e-434b-b1d0-6cce8d9f0f0c/resources", cloudRegion, tenantId, Resources.class);
+ doReturn(service2QueryResponse).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst/447a9b41-714e-434b-b1d0-6cce8d9f0f0c/resources", cloudRegion, tenantId, Resources.class);
Stack service2StackQuerySubInt = stackObjectMapper.readValue(new File("src/test/resources/Service2SubInterface0.json"), Stack.class);
- doReturn(service2StackQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81", cloudRegion,tenantId, Stack.class);
+ doReturn(service2StackQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81", cloudRegion,tenantId, Stack.class);
Resources service2ResourceQuerySubInt = objectMapper.readValue(new File("src/test/resources/Service2SubInterface1Resources.json"), Resources.class);
- doReturn(service2ResourceQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81/resources", cloudRegion,tenantId, Resources.class);
+ doReturn(service2ResourceQuerySubInt).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service2_port_0_subinterfaces-hlzdigtimzst-0-upfi5nhurk7y/f711be16-2654-4a09-b89d-0511fda20e81/resources", cloudRegion,tenantId, Resources.class);
Stack service1StackQuerySubInt1 =stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface0.json"), Stack.class);
- doReturn(service1StackQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb", cloudRegion,tenantId, Stack.class);
+ doReturn(service1StackQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb", cloudRegion,tenantId, Stack.class);
Resources service1ResourceQuerySubInt1 = objectMapper.readValue(new File("src/test/resources/Service1SubInterface0Resources.json"), Resources.class);
- doReturn(service1ResourceQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb/resources", cloudRegion,tenantId, Resources.class);
+ doReturn(service1ResourceQuerySubInt1).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-1-fmn5laetg5cs/0d9cd813-2ae1-46c0-9ebb-48081f6cffbb/resources", cloudRegion,tenantId, Resources.class);
Stack service1StackQuerySubInt2 =stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface1.json"), Stack.class);
- doReturn(service1StackQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a", cloudRegion,tenantId, Stack.class);
+ doReturn(service1StackQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a", cloudRegion,tenantId, Stack.class);
Resources service1ResourceQuerySubInt2 = objectMapper.readValue(new File("src/test/resources/Service1SubInterface1Resources.json"), Resources.class);
- doReturn(service1ResourceQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a/resources", cloudRegion,tenantId, Resources.class);
+ doReturn(service1ResourceQuerySubInt2).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-0-yghihziaf36m/b7019dd0-2ee9-4447-bdef-ac25676b205a/resources", cloudRegion,tenantId, Resources.class);
Stack service1StackQuerySubInt3 =stackObjectMapper.readValue(new File("src/test/resources/Service1SubInterface2.json"), Stack.class);
- doReturn(service1StackQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c", cloudRegion,tenantId, Stack.class);
+ doReturn(service1StackQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c", cloudRegion,tenantId, Stack.class);
Resources service1ResourceQuerySubInt3 = objectMapper.readValue(new File("src/test/resources/Service1SubInterface2Resources.json"), Resources.class);
- doReturn(service1ResourceQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest("/ea2d13cc98b44d60a6f94bdcb2738f9e/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c/resources", cloudRegion,tenantId, Resources.class);
+ doReturn(service1ResourceQuerySubInt3).when(msoHeatUtilsMock).executeHeatClientRequest("/stacks/tsbc0005vm002ssc001-ssc_1_subint_service1_port_0_subinterfaces-dtmxjmny7yjz-2-y3ndsavmsymv/bd0fc728-cbde-4301-a581-db56f494675c/resources", cloudRegion,tenantId, Resources.class);
Set<Vserver> vServersToAudit = heatStackAudit.createVserverSet(resources, novaResources);
Set<Vserver> vserversWithSubInterfaces = heatStackAudit.processSubInterfaces(cloudRegion,tenantId,resourceGroups, vServersToAudit);
@@ -193,6 +196,17 @@ public class HeatStackAuditTest extends HeatStackAudit {
JSONAssert.assertEquals(expectedValue, actualValue, false);
}
+ @Test
+ public void auditHeatStackNoServers_Test() throws Exception{
+
+
+ Resources getResource = objectMapper.readValue(new File("src/test/resources/Service1ResourceGroupResponse.json"), Resources.class);
+ doReturn(getResource).when(msoHeatUtilsMock).queryStackResources(cloudRegion, tenantId, "heatStackName");
+
+ boolean actual = heatStackAudit.auditHeatStack(cloudRegion, "cloudOwner", tenantId, "heatStackName");
+ assertEquals(true, actual);
+ }
+
@Test
public void findInterfaceInformation_Test(){
diff --git a/adapters/mso-openstack-adapters/src/test/resources/GetResourcesNoServer.json b/adapters/mso-openstack-adapters/src/test/resources/GetResourcesNoServer.json
new file mode 100644
index 0000000000..cfc9e5a0f1
--- /dev/null
+++ b/adapters/mso-openstack-adapters/src/test/resources/GetResourcesNoServer.json
@@ -0,0 +1,25 @@
+{
+ "resources": [
+ {
+ "resource_name": "OAMFW_SECURITY_GROUP",
+ "links": [
+ {
+ "href": "http://orchestration.com:443/v1/872f331350c54e59991a8de2cbffb40c/stacks/zauk51bfrwl03_base_NC_01/08c898a4-ba71-4365-9681-993d4129164a/resources/OAMFW_SECURITY_GROUP",
+ "rel": "self"
+ },
+ {
+ "href": "http://orchestration.com:443/v1/872f331350c54e59991a8de2cbffb40c/stacks/zauk51bfrwl03_base_NC_01/08c898a4-ba71-4365-9681-993d4129164a",
+ "rel": "stack"
+ }
+ ],
+ "logical_resource_id": "OAMFW_SECURITY_GROUP",
+ "creation_time": "2019-02-13T21:17:03Z",
+ "resource_status": "CREATE_COMPLETE",
+ "updated_time": "2019-02-13T21:17:03Z",
+ "required_by": [],
+ "resource_status_reason": "state changed",
+ "physical_resource_id": "420833ff-2733-4043-868c-2f2d5bee8f93",
+ "resource_type": "OS::Neutron::SecurityGroup"
+ }
+ ]
+} \ No newline at end of file
diff --git a/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml b/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml
index 175b08f747..781d49f908 100644
--- a/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml
+++ b/adapters/mso-openstack-adapters/src/test/resources/application-test.yaml
@@ -88,10 +88,6 @@ spring:
hibernate:
ddl-auto: none
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
- flyway:
- baseline-on-migrate: true
- out-of-order: true
- ignore-missing-migrations: true
security:
usercredentials:
-
@@ -119,37 +115,3 @@ management:
prometheus:
enabled: true # Whether exporting of metrics to Prometheus is enabled.
step: 1m # Step size (i.e. reporting frequency) to use.
-
-
-cloud_config:
- identity_services:
- MTKEYSTONE:
- identity_url: "http://localhost:5000/v2.0"
- mso_id: "john"
- mso_pass: "313DECE408AF7759D442D7B06DD9A6AA"
- admin_tenant: "admin"
- member_role: "_member_"
- tenant_metadata: false
- identity_server_type: "KEYSTONE"
- identity_authentication_type: "USERNAME_PASSWORD"
- cloud_sites:
- mtn13:
- region_id: "mtn13"
- clli: "MDT13"
- aic_version: "3.0"
- identity_service_id: "MTN13"
- orchestrator: "orchestrator"
- cloudify_id: "mtn13"
- regionOne:
- region_id: "regionOne"
- clli: "MT2"
- aic_version: "2.5"
- identity_service_id: "MTKEYSTONE"
- cloudify_managers:
- manager:
- cloudify_url: "http://localhost:8080"
- username: "user"
- password: "password"
- version: "2.0"
-
-