diff options
Diffstat (limited to 'adapters')
10 files changed, 279 insertions, 150 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java index 5c0110b680..49758a1240 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoMulticloudUtils.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2018 Intel Corp. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ * 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 @@ -20,6 +22,9 @@ package org.onap.so.openstack.utils; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.woorea.openstack.heat.model.CreateStackParam; import java.net.MalformedURLException; import java.net.URL; import java.util.Arrays; @@ -27,10 +32,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; - import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilderException; - import org.onap.so.adapters.vdu.CloudInfo; import org.onap.so.adapters.vdu.PluginAction; import org.onap.so.adapters.vdu.VduArtifact; @@ -59,10 +62,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.stereotype.Component; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.woorea.openstack.heat.model.CreateStackParam; - @Component public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ @@ -194,30 +193,35 @@ public class MsoMulticloudUtils extends MsoHeatUtils implements VduPlugin{ String multicloudEndpoint = getMulticloudEndpoint(cloudSiteId, null); RestClient multicloudClient = getMulticloudClient(multicloudEndpoint); - Response response = multicloudClient.post(multicloudRequest); + if (multicloudClient == null) { + MsoOpenstackException me = new MsoOpenstackException(0, "", "Multicloud client could not be initialized"); + me.addContext(CREATE_STACK); + throw me; + } - StackInfo createInfo = new StackInfo(); - createInfo.setName(stackName); + Response response = multicloudClient.post(multicloudRequest); MulticloudCreateResponse multicloudResponseBody = null; if (response.hasEntity()) { - multicloudResponseBody = getCreateBody((java.io.InputStream)response.getEntity()); + multicloudResponseBody = getCreateBody((java.io.InputStream) response.getEntity()); } if (response.getStatus() == Response.Status.CREATED.getStatusCode() && response.hasEntity()) { - createInfo.setCanonicalName(stackName + "/" + multicloudResponseBody.getWorkloadId()); - if (logger.isDebugEnabled()) { - logger.debug("Multicloud Create Response Body: " + multicloudResponseBody); + String canonicalName = stackName + "/"; + if (multicloudResponseBody != null) { + canonicalName = canonicalName + multicloudResponseBody.getWorkloadId(); } - return getStackStatus(cloudSiteId, tenantId, createInfo.getCanonicalName(), pollForCompletion, timeoutMinutes, backout); - } else { - StringBuilder stackErrorStatusReason = new StringBuilder(response.getStatusInfo().getReasonPhrase()); - if (null != multicloudResponseBody) { - stackErrorStatusReason.append(multicloudResponseBody.toString()); + if (logger.isDebugEnabled()) { + logger.debug("Multicloud Create Response Body: {}", multicloudResponseBody); } - MsoOpenstackException me = new MsoOpenstackException(0, "", stackErrorStatusReason.toString()); - me.addContext(CREATE_STACK); - throw me; + return getStackStatus(cloudSiteId, tenantId, canonicalName, pollForCompletion, timeoutMinutes, backout); + } + StringBuilder stackErrorStatusReason = new StringBuilder(response.getStatusInfo().getReasonPhrase()); + if (null != multicloudResponseBody) { + stackErrorStatusReason.append(multicloudResponseBody.toString()); } + MsoOpenstackException me = new MsoOpenstackException(0, "", stackErrorStatusReason.toString()); + me.addContext(CREATE_STACK); + throw me; } @Override diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java new file mode 100644 index 0000000000..fcb651e4dd --- /dev/null +++ b/adapters/mso-adapter-utils/src/test/java/org/onap/so/openstack/utils/MsoMulticloudUtilsTest.java @@ -0,0 +1,119 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Samsung 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 org.onap.so.openstack.utils; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Optional; +import org.apache.http.HttpStatus; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.onap.so.BaseTest; +import org.onap.so.cloud.CloudConfig; +import org.onap.so.db.catalog.beans.CloudIdentity; +import org.onap.so.db.catalog.beans.CloudSite; +import org.onap.so.openstack.beans.StackInfo; +import org.onap.so.openstack.exceptions.MsoException; +import org.springframework.beans.factory.annotation.Autowired; + +public class MsoMulticloudUtilsTest extends BaseTest { + + @Autowired + private MsoMulticloudUtils multicloudUtils; + + @InjectMocks + private MsoMulticloudUtils multicloudUtilsMock; + + @Mock + private CloudConfig cloudConfigMock; + + private static final String CREATE_STACK_RESPONSE = "{\"template_type\": \"TEST-template\", \"workload_id\": " + + "\"TEST-workload\", \"template_response\": {\"stack\": {\"id\": \"TEST-stack\", \"links\": []}}}"; + + @Test + public void createStackSuccess() throws MsoException, IOException { + stubFor(post(urlPathEqualTo("/v2.0")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withBody(CREATE_STACK_RESPONSE) + .withStatus(HttpStatus.SC_CREATED))); + StackInfo result = multicloudUtils.createStack("MTN13", "TEST-tenant", "TEST-stack", + "TEST-heat", new HashMap<>(), false, 200, "TEST-env", + new HashMap<>(), new HashMap<>()); + assertNotNull(result); + assertEquals("TEST-stack", result.getName()); + } + + @Test + public void createStackMulticloudClientIsNull() { + try { + multicloudUtilsMock.cloudConfig = cloudConfigMock; + CloudSite cloudSite = new CloudSite(); + cloudSite.setIdentityService(new CloudIdentity()); + when(cloudConfigMock.getCloudSite("MTN13")). + thenReturn(Optional.of(cloudSite)); + multicloudUtilsMock.createStack("MTN13", "TEST-tenant", "TEST-stack", + "TEST-heat", new HashMap<>(), false, 200, "TEST-env", + new HashMap<>(), new HashMap<>()); + } catch (MsoException e) { + assertEquals("0 : Multicloud client could not be initialized", e.toString()); + return; + } + fail("MsoOpenstackException expected!"); + } + + @Test + public void createStackBadRequest() { + try { + stubFor(post(urlPathEqualTo("/v2.0")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(HttpStatus.SC_BAD_REQUEST))); + multicloudUtils.createStack("MTN13", "TEST-tenant", "TEST-stack", + "TEST-heat", new HashMap<>(), false, 200, "TEST-env", + new HashMap<>(), new HashMap<>()); + } catch (MsoException e) { + assertEquals("0 : Bad Request", e.toString()); + return; + } + fail("MsoOpenstackException expected!"); + } + + @Test + public void createStackEmptyResponseEntity() throws MsoException { + stubFor(post(urlPathEqualTo("/v2.0")) + .willReturn(aResponse().withHeader("Content-Type", "application/json") + .withStatus(HttpStatus.SC_CREATED))); + StackInfo result = multicloudUtils.createStack("MTN13", "TEST-tenant", "TEST-stack", + "TEST-heat", new HashMap<>(), false, 200, "TEST-env", + new HashMap<>(), new HashMap<>()); + assertNotNull(result); + assertEquals("TEST-stack/", result.getName()); + } +} diff --git a/adapters/mso-catalog-db-adapter/pom.xml b/adapters/mso-catalog-db-adapter/pom.xml index 931dee2d5c..390c775cb2 100644 --- a/adapters/mso-catalog-db-adapter/pom.xml +++ b/adapters/mso-catalog-db-adapter/pom.xml @@ -144,6 +144,12 @@ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> + <exclusions> + <exclusion> + <groupId>org.apache.tomcat</groupId> + <artifactId>tomcat-jdbc</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml index 83101c1599..d46a8ee49d 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml +++ b/adapters/mso-catalog-db-adapter/src/main/resources/application.yaml @@ -16,7 +16,7 @@ mso: spring: datasource: - jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb + url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb username: ${DB_USERNAME} password: ${DB_PASSWORD} driver-class-name: org.mariadb.jdbc.Driver 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 ef9b113e70..771aa80081 100644 --- a/adapters/mso-openstack-adapters/src/main/resources/application-local.yaml +++ b/adapters/mso-openstack-adapters/src/main/resources/application-local.yaml @@ -64,7 +64,7 @@ mso: # H2 spring: datasource: - jdbc-url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1; + url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1; username: sa password: sa driver-class-name: org.h2.Driver diff --git a/adapters/mso-openstack-adapters/src/main/resources/application.yaml b/adapters/mso-openstack-adapters/src/main/resources/application.yaml index e682060c74..4e8d389998 100644 --- a/adapters/mso-openstack-adapters/src/main/resources/application.yaml +++ b/adapters/mso-openstack-adapters/src/main/resources/application.yaml @@ -18,7 +18,6 @@ mso: retryMultiplier: 60000 spring: datasource: - type: com.zaxxer.hikari.HikariDataSource url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/catalogdb username: ${DB_USERNAME} password: ${DB_PASSWORD} diff --git a/adapters/mso-requests-db-adapter/pom.xml b/adapters/mso-requests-db-adapter/pom.xml index 4a4d09a0a9..a4761adf62 100644 --- a/adapters/mso-requests-db-adapter/pom.xml +++ b/adapters/mso-requests-db-adapter/pom.xml @@ -59,6 +59,12 @@ <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> + <exclusions> + <exclusion> + <groupId>org.apache.tomcat</groupId> + <artifactId>tomcat-jdbc</artifactId> + </exclusion> + </exclusions> <optional>true</optional> </dependency> <dependency> diff --git a/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml b/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml index b2b16274aa..5d3a837180 100644 --- a/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml +++ b/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml @@ -1,51 +1,51 @@ -# will be used as entry in DB to say SITE OFF/ON for healthcheck - -server: - port: 8090 - tomcat: - max-threads: 50 -ssl-enable: false -mso: - adapters: - requestDb: - auth: Basic YnBlbDptc28tZGItMTUwNyE= - endpoint: http://localhost:8081 - logPath: logs - site-name: localSite - infra-requests: - archived: - period: 180 -spring: - datasource: - jdbc-url: jdbc:mariadb://localhost:3306/requestdb - username: catalog - password: catalog123 - driver-class-name: org.mariadb.jdbc.Driver - initialize: true - initialization-mode: never - jpa: - generate-ddl: false - show-sql: false - hibernate: - ddl-auto: validate - naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy - enable-lazy-load-no-trans: true - database-platform: org.hibernate.dialect.MySQL5InnoDBDialect - security: - usercredentials: - - - username: bpel - password: '$2a$12$1xyutEZNfjGewIZRfKaE8eZE99f5sYFUmmM80BobI65KNjmcK0JuO' - role: BPEL-Client - - - username: mso_admin - password: '$2a$12$tidKuu.h88E2nuL95pTVY.ZOYMN/1dp29A9b1o.0GFDsVVSYlMkHa' - role: ACTUATOR - - -flyway: - baseline-on-migrate: false - url: jdbc:mariadb://localhost:3306/requestdb - user: catalog - password: catalog123 +# will be used as entry in DB to say SITE OFF/ON for healthcheck
+
+server:
+ port: 8090
+ tomcat:
+ max-threads: 50
+ssl-enable: false
+mso:
+ adapters:
+ requestDb:
+ auth: Basic YnBlbDptc28tZGItMTUwNyE=
+ endpoint: http://localhost:8081
+ logPath: logs
+ site-name: localSite
+ infra-requests:
+ archived:
+ period: 180
+spring:
+ datasource:
+ url: jdbc:mariadb://localhost:3306/requestdb
+ username: catalog
+ password: catalog123
+ driver-class-name: org.mariadb.jdbc.Driver
+ initialize: true
+ initialization-mode: never
+ jpa:
+ generate-ddl: false
+ show-sql: false
+ hibernate:
+ ddl-auto: validate
+ naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
+ enable-lazy-load-no-trans: true
+ database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
+ security:
+ usercredentials:
+ -
+ username: bpel
+ password: '$2a$12$1xyutEZNfjGewIZRfKaE8eZE99f5sYFUmmM80BobI65KNjmcK0JuO'
+ role: BPEL-Client
+ -
+ username: mso_admin
+ password: '$2a$12$tidKuu.h88E2nuL95pTVY.ZOYMN/1dp29A9b1o.0GFDsVVSYlMkHa'
+ role: ACTUATOR
+
+
+flyway:
+ baseline-on-migrate: false
+ url: jdbc:mariadb://localhost:3306/requestdb
+ user: catalog
+ password: catalog123
\ No newline at end of file diff --git a/adapters/mso-requests-db-adapter/src/main/resources/application.yaml b/adapters/mso-requests-db-adapter/src/main/resources/application.yaml index 0da782bf00..9429592670 100644 --- a/adapters/mso-requests-db-adapter/src/main/resources/application.yaml +++ b/adapters/mso-requests-db-adapter/src/main/resources/application.yaml @@ -18,15 +18,10 @@ mso: # H2 spring: datasource: - jdbc-url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb + url: jdbc:mariadb://${DB_HOST}:${DB_PORT}/requestdb username: ${DB_USERNAME} password: ${DB_PASSWORD} driver-class-name: org.mariadb.jdbc.Driver - dbcp2: - initial-size: 5 - max-total: 20 - validation-query: select 1 - test-on-borrow: true jpa: show-sql: false hibernate: diff --git a/adapters/mso-requests-db-adapter/src/test/resources/application-test.yaml b/adapters/mso-requests-db-adapter/src/test/resources/application-test.yaml index 19bff50ea3..db9885285e 100644 --- a/adapters/mso-requests-db-adapter/src/test/resources/application-test.yaml +++ b/adapters/mso-requests-db-adapter/src/test/resources/application-test.yaml @@ -1,70 +1,70 @@ -# will be used as entry in DB to say SITE OFF/ON for healthcheck -security: - basic: - enabled: false -server: - port: 8080 - tomcat: - max-threads: 50 -ssl-enable: false -mso: - adapters: - requestDb: - auth: Basic YnBlbDptc28tZGItMTUwNyE= - endpoint: http://localhost:8081 - logPath: logs - site-name: localSite - infra-requests: - archived: - period: 0 -spring: - datasource: - jdbc-url: jdbc:mariadb://localhost:3307/requestdb - username: root - password: password - driver-class-name: org.mariadb.jdbc.Driver - initialize: true - initialization-mode: never - jpa: - generate-ddl: false - show-sql: false - hibernate: - ddl-auto: validate - naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy - enable-lazy-load-no-trans: true - database-platform: org.hibernate.dialect.MySQL5InnoDBDialect - security: - usercredentials: - - - username: bpel - password: '$2a$12$1xyutEZNfjGewIZRfKaE8eZE99f5sYFUmmM80BobI65KNjmcK0JuO' - role: BPEL-Client - - - username: mso_admin - password: '$2a$12$tidKuu.h88E2nuL95pTVY.ZOYMN/1dp29A9b1o.0GFDsVVSYlMkHa' - role: ACTUATOR -mariaDB4j: - dataDir: - port: 3307 - databaseName: requestdb - -management: - endpoints: - web: - base-path: /manage - server: - servlet: - context-path: /manage - metrics: - se-global-registry: false - export: - prometheus: - enabled: true # Whether exporting of metrics to Prometheus is enabled. - step: 1m # Step size (i.e. reporting frequency) to use. - - -flyway: - baseline-on-migrate: false - jdbc-url: jdbc:mariadb://localhost:3307/requestdb - user: root - password: password +# will be used as entry in DB to say SITE OFF/ON for healthcheck
+security:
+ basic:
+ enabled: false
+server:
+ port: 8080
+ tomcat:
+ max-threads: 50
+ssl-enable: false
+mso:
+ adapters:
+ requestDb:
+ auth: Basic YnBlbDptc28tZGItMTUwNyE=
+ endpoint: http://localhost:8081
+ logPath: logs
+ site-name: localSite
+ infra-requests:
+ archived:
+ period: 0
+spring:
+ datasource:
+ url: jdbc:mariadb://localhost:3307/requestdb
+ username: root
+ password: password
+ driver-class-name: org.mariadb.jdbc.Driver
+ initialize: true
+ initialization-mode: never
+ jpa:
+ generate-ddl: false
+ show-sql: false
+ hibernate:
+ ddl-auto: validate
+ naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
+ enable-lazy-load-no-trans: true
+ database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
+ security:
+ usercredentials:
+ -
+ username: bpel
+ password: '$2a$12$1xyutEZNfjGewIZRfKaE8eZE99f5sYFUmmM80BobI65KNjmcK0JuO'
+ role: BPEL-Client
+ -
+ username: mso_admin
+ password: '$2a$12$tidKuu.h88E2nuL95pTVY.ZOYMN/1dp29A9b1o.0GFDsVVSYlMkHa'
+ role: ACTUATOR
+mariaDB4j:
+ dataDir:
+ port: 3307
+ databaseName: requestdb
+
+management:
+ endpoints:
+ web:
+ base-path: /manage
+ server:
+ servlet:
+ context-path: /manage
+ metrics:
+ se-global-registry: false
+ export:
+ prometheus:
+ enabled: true # Whether exporting of metrics to Prometheus is enabled.
+ step: 1m # Step size (i.e. reporting frequency) to use.
+
+
+flyway:
+ baseline-on-migrate: false
+ url: jdbc:mariadb://localhost:3307/requestdb
+ user: root
+ password: password
|