From 74fe8ef18daf5fa716f1d1cb3c4b7975b0399b44 Mon Sep 17 00:00:00 2001 From: "Smokowski, Steve (ss835w)" Date: Fri, 3 Aug 2018 14:34:07 -0400 Subject: Fix Junit Junit was using an illegal http error code Issue-ID: SO-793 Change-Id: Ica36a5e22f32680710da649eb0dbfe5cac93b93c Signed-off-by: Smokowski, Steve (ss835w) --- adapters/mso-vfc-adapter/.springBeans | 16 + .../WebContent/META-INF/MANIFEST.MF | 3 - ....openstack.base.client.OpenStackClientConnector | 1 - .../WEB-INF/jboss-deployment-structure.xml | 21 - adapters/mso-vfc-adapter/WebContent/check.html | 9 - adapters/mso-vfc-adapter/pom.xml | 94 ++-- .../java/org/onap/so/adapters/vfc/AaiUtil.java | 47 -- .../org/onap/so/adapters/vfc/CXFConfiguration.java | 91 ++++ .../onap/so/adapters/vfc/HealthCheckHandler.java | 65 --- .../onap/so/adapters/vfc/MSOVfcApplication.java | 39 ++ .../org/onap/so/adapters/vfc/RequestDBConfig.java | 80 ++++ .../org/onap/so/adapters/vfc/VfcAdapterRest.java | 225 ---------- .../java/org/onap/so/adapters/vfc/VfcManager.java | 496 --------------------- .../vfc/application/JerseyConfiguration.java | 60 --- .../vfc/application/MSOVfcApplication.java | 40 -- .../org/onap/so/adapters/vfc/rest/AaiUtil.java | 47 ++ .../so/adapters/vfc/rest/HealthCheckHandler.java | 65 +++ .../onap/so/adapters/vfc/rest/VfcAdapterRest.java | 224 ++++++++++ .../org/onap/so/adapters/vfc/rest/VfcManager.java | 496 +++++++++++++++++++++ .../src/main/resources/application-local.yaml | 34 ++ .../src/main/resources/application.yaml | 53 +-- .../vfc/exceptions/ApplicationExceptionTest.java | 6 +- .../adapters/vfc/rest/EmbeddedMariaDbConfig.java | 102 +++++ .../adapters/vfc/rest/HealthCheckHandlerTest.java | 72 +++ .../src/test/resources/application-test.yaml | 49 +- 25 files changed, 1372 insertions(+), 1063 deletions(-) create mode 100644 adapters/mso-vfc-adapter/.springBeans delete mode 100644 adapters/mso-vfc-adapter/WebContent/META-INF/MANIFEST.MF delete mode 100644 adapters/mso-vfc-adapter/WebContent/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector delete mode 100644 adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml delete mode 100644 adapters/mso-vfc-adapter/WebContent/check.html delete mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/AaiUtil.java create mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/CXFConfiguration.java delete mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/HealthCheckHandler.java create mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java create mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/RequestDBConfig.java delete mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcAdapterRest.java delete mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcManager.java delete mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/JerseyConfiguration.java delete mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/MSOVfcApplication.java create mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/AaiUtil.java create mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/HealthCheckHandler.java create mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcAdapterRest.java create mode 100644 adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcManager.java create mode 100644 adapters/mso-vfc-adapter/src/main/resources/application-local.yaml create mode 100644 adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/EmbeddedMariaDbConfig.java create mode 100644 adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/HealthCheckHandlerTest.java diff --git a/adapters/mso-vfc-adapter/.springBeans b/adapters/mso-vfc-adapter/.springBeans new file mode 100644 index 0000000000..1310366fc4 --- /dev/null +++ b/adapters/mso-vfc-adapter/.springBeans @@ -0,0 +1,16 @@ + + + 1 + + + + + + + java:org.onap.so.adapters.vfc.MSOVfcApplication + + + + + + diff --git a/adapters/mso-vfc-adapter/WebContent/META-INF/MANIFEST.MF b/adapters/mso-vfc-adapter/WebContent/META-INF/MANIFEST.MF deleted file mode 100644 index 5e9495128c..0000000000 --- a/adapters/mso-vfc-adapter/WebContent/META-INF/MANIFEST.MF +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -Class-Path: - diff --git a/adapters/mso-vfc-adapter/WebContent/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector b/adapters/mso-vfc-adapter/WebContent/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector deleted file mode 100644 index 1281d32948..0000000000 --- a/adapters/mso-vfc-adapter/WebContent/META-INF/services/com.woorea.openstack.base.client.OpenStackClientConnector +++ /dev/null @@ -1 +0,0 @@ -com.woorea.openstack.connector.HttpClientConnector \ No newline at end of file diff --git a/adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml b/adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml deleted file mode 100644 index 70f8299675..0000000000 --- a/adapters/mso-vfc-adapter/WebContent/WEB-INF/jboss-deployment-structure.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - diff --git a/adapters/mso-vfc-adapter/WebContent/check.html b/adapters/mso-vfc-adapter/WebContent/check.html deleted file mode 100644 index b4250aa782..0000000000 --- a/adapters/mso-vfc-adapter/WebContent/check.html +++ /dev/null @@ -1,9 +0,0 @@ - - - - -Health Check - -Application ready - - \ No newline at end of file diff --git a/adapters/mso-vfc-adapter/pom.xml b/adapters/mso-vfc-adapter/pom.xml index 6fbfb810ec..9392db2a2a 100644 --- a/adapters/mso-vfc-adapter/pom.xml +++ b/adapters/mso-vfc-adapter/pom.xml @@ -28,7 +28,7 @@ org.springframework.boot spring-boot-maven-plugin - org.onap.so.adapters.vfc.application.MSOVfcApplication + org.onap.so.adapters.vfc.MSOVfcApplication @@ -45,8 +45,6 @@ - org.springframework.boot spring-boot-starter-actuator @@ -57,89 +55,61 @@ org.springframework.boot - spring-boot-starter-data-jpa - true - - - org.springframework.boot - spring-boot-starter-test - test + spring-boot-starter-jdbc + + + org.apache.tomcat + tomcat-jdbc + + - org.springframework.boot - spring-boot-starter-jersey - - - com.h2database - h2 - test + org.apache.commons + commons-dbcp2 - org.webjars - swagger-ui - 3.5.0 + org.apache.cxf + cxf-spring-boot-starter-jaxws + 3.1.12 - io.swagger - swagger-jersey2-jaxrs - 1.5.16 + org.apache.cxf + cxf-spring-boot-starter-jaxrs + 3.1.12 - javax.ws.rs - javax.ws.rs-api - 2.0 - - - org.onap.so.adapters - mso-adapter-utils - ${project.version} + org.apache.cxf + cxf-rt-rs-service-description-swagger + 3.1.11 - org.onap.so.adapters - mso-adapters-rest-interface - ${project.version} + org.springframework.boot + spring-boot-starter-data-jpa - javax.servlet - javax.servlet-api - 3.1.0 + org.springframework.boot + spring-boot-starter-test test - - org.jboss.spec.javax.ejb - jboss-ejb-api_3.2_spec - 1.0.0.Final - provided - - - org.jboss.ejb3 - jboss-ejb3-ext-api - 2.2.0.Final - provided - org.onap.so mso-requests-db ${project.version} - commons-io - commons-io - - - javax.servlet - javax.servlet-api - 3.1.0 + org.mariadb.jdbc + mariadb-java-client - io.micrometer - micrometer-spring-legacy - 1.0.5 + ch.vorburger.mariaDB4j + mariaDB4j + 2.2.3 + test - io.micrometer - micrometer-registry-prometheus - 1.0.5 + org.springframework.boot + spring-boot-configuration-processor + true diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/AaiUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/AaiUtil.java deleted file mode 100644 index a4f05158a8..0000000000 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/AaiUtil.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters.vfc; - -import org.onap.so.adapters.vfc.model.RestfulResponse; - -/** - * Implement class of operating aai database table
- *

- *

- * - * @author - * @version ONAP Amsterdam Release 2017-08-28 - */ -public class AaiUtil { - - public static RestfulResponse addRelation(String globalSubsriberId, String serviceType, - String serviceInstanceId, String resourceInstanceId) { - // sent rest to aai to add relation for service and ns. - - return null; - } - - public static RestfulResponse removeRelation(String globalSubsriberId, String serviceType, - String serviceInstanceId, String resourceInstanceId) { - // sent rest to aai to remove relation between service an ns. - return null; - } -} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/CXFConfiguration.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/CXFConfiguration.java new file mode 100644 index 0000000000..3034cbcac3 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/CXFConfiguration.java @@ -0,0 +1,91 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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 org.onap.so.adapters.vfc; + +import java.util.Arrays; +import javax.xml.ws.Endpoint; + +import org.apache.cxf.Bus; +import org.apache.cxf.endpoint.Server; +import org.apache.cxf.feature.LoggingFeature; +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; +import org.apache.cxf.jaxrs.swagger.Swagger2Feature; +import org.apache.cxf.jaxws.EndpointImpl; +import org.apache.cxf.transport.servlet.CXFServlet; +import org.onap.so.adapters.vfc.rest.HealthCheckHandler; +import org.onap.so.adapters.vfc.rest.VfcAdapterRest; +import org.onap.so.logging.jaxrs.filter.jersey.JaxRsFilterLogging; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; + + +@Configuration +public class CXFConfiguration { + + @Autowired + private Bus bus; + + @Autowired + private VfcAdapterRest vfcAdapterRest; + + @Autowired + private HealthCheckHandler healthCheckHandler; + + @Autowired + private JaxRsFilterLogging jaxRsFilterLogging; + + @Autowired + private ObjectMapper mapper; + + @Bean + public ServletRegistrationBean cxfServlet() { + return new ServletRegistrationBean(new CXFServlet(), "/services/*"); + } + + @Bean + public Server rsServer() { + JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); + endpoint.setBus(bus); + endpoint.setServiceBeans(Arrays.asList(vfcAdapterRest, healthCheckHandler)); + endpoint.setAddress("/"); + endpoint.setFeatures(Arrays.asList(createSwaggerFeature(), new LoggingFeature())); + endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper),jaxRsFilterLogging)); + return endpoint.create(); + } + + @Bean + public Swagger2Feature createSwaggerFeature() { + Swagger2Feature swagger2Feature = new Swagger2Feature(); + swagger2Feature.setPrettyPrint(true); + swagger2Feature.setTitle("SO Request Adapter"); + swagger2Feature.setContact("The ONAP SO team"); + swagger2Feature.setDescription("This project is the SO Orchestration Engine"); + swagger2Feature.setVersion("1.0.0"); + swagger2Feature.setResourcePackage("org.onap.so.adapters.requestdb"); + swagger2Feature.setScan(true); + return swagger2Feature; + } + +} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/HealthCheckHandler.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/HealthCheckHandler.java deleted file mode 100644 index 8fcf315641..0000000000 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/HealthCheckHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters.vfc; - -import javax.ws.rs.HEAD; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response; - -import org.apache.http.HttpStatus; -import org.onap.so.logger.MsoLogger; -import org.onap.so.utils.UUIDChecker; -import org.springframework.stereotype.Component; - -/** - * Health Check - *
- *

- *

- * - * @author - * @version ONAP Amsterdam Release 2017-08-28 - */ -@Path("/") -@Component -public class HealthCheckHandler { - - private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, HealthCheckHandler.class); - - - private static final String CHECK_HTML = "Health CheckApplication ready"; - - public static final Response HEALTH_CHECK_RESPONSE = Response.status (HttpStatus.SC_OK) - .entity (CHECK_HTML) - .build (); - - @HEAD - @Path("/healthcheck") - @Produces("text/html") - public Response healthcheck(@QueryParam("requestId") String requestId) { - MsoLogger.setServiceName("Healthcheck"); - UUIDChecker.verifyOldUUID(requestId, msoLogger); - return HEALTH_CHECK_RESPONSE; - } - -} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java new file mode 100644 index 0000000000..5bb83a7c1b --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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 org.onap.so.adapters.vfc; + + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; + + + +@SpringBootApplication(scanBasePackages = {"org.onap.so"}) +public class MSOVfcApplication { + + public static void main(String... args) { + SpringApplication.run(MSOVfcApplication.class, args); + } + +} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/RequestDBConfig.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/RequestDBConfig.java new file mode 100644 index 0000000000..2ff66d2c25 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/RequestDBConfig.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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 org.onap.so.adapters.vfc; + + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Profile({"!test"}) +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories( + entityManagerFactoryRef = "requestEntityManagerFactory",transactionManagerRef = "requestTransactionManager", + basePackages = { "org.onap.so.db.request.data.repository" } + ) +public class RequestDBConfig { + + @Primary + @Bean(name = "requestDataSource") + @ConfigurationProperties(prefix = "spring.datasource") + public DataSource dataSource() { + return DataSourceBuilder.create().build(); + } + + @Primary + @Bean(name = "requestEntityManagerFactory") + public LocalContainerEntityManagerFactoryBean + entityManagerFactory( + EntityManagerFactoryBuilder builder, + @Qualifier("requestDataSource") DataSource dataSource + ) { + return builder + .dataSource(dataSource) + .packages("org.onap.so.db.request.beans") + .persistenceUnit("requestDB") + .build(); + } + + @Primary + @Bean(name = "requestTransactionManager") + public PlatformTransactionManager transactionManager( + @Qualifier("requestEntityManagerFactory") EntityManagerFactory + entityManagerFactory + ) { + return new JpaTransactionManager(entityManagerFactory); + } + +} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcAdapterRest.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcAdapterRest.java deleted file mode 100644 index e07753b33a..0000000000 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcAdapterRest.java +++ /dev/null @@ -1,225 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters.vfc; - -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -import org.onap.so.adapters.vfc.exceptions.ApplicationException; -import org.onap.so.adapters.vfc.model.NSResourceInputParameter; -import org.onap.so.adapters.vfc.model.NsOperationKey; -import org.onap.so.adapters.vfc.model.RestfulResponse; -import org.onap.so.adapters.vfc.util.JsonUtil; -import org.onap.so.adapters.vfc.util.ValidateUtil; -import org.onap.so.logger.MsoLogger; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * The rest class for VF-c Adapter
- *

- *

- * - * @author - * @version ONAP Amsterdam Release 2017-08-28 - */ -@Component -@Path("/v1/vfcadapter") -public class VfcAdapterRest { - - private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, VfcAdapterRest.class); - - @Autowired - private VfcManager driverMgr ; - - public VfcAdapterRest() { - - } - - /** - * Create a NS
- * - * @param data http request - * @return - * @since ONAP Amsterdam Release - */ - @POST - @Path("/ns") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response createNfvoNs(String data) { - try { - ValidateUtil.assertObjectNotNull(data); - LOGGER.debug("body from request is {}" + data); - NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class); - RestfulResponse rsp = driverMgr.createNs(nsInput); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } - } - - /** - * Delete NS instance
- * - * @param data The http request - * @param nsInstanceId The NS instance id - * @return response - * @since ONAP Amsterdam Release - */ - @DELETE - @Path("/ns/{nsInstanceId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response deleteNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) { - try { - - ValidateUtil.assertObjectNotNull(data); - LOGGER.debug("body from request is {}" + data); - NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class); - RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } - } - - /** - * Query Operation job status
- * - * @param data The Http Request - * @param jobId The job id - * @return - * @since ONAP Amsterdam Release - */ - @POST - @Path("/jobs/{jobId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response queryNfvoJobStatus(String data, @PathParam("jobId") String jobId) { - try { - ValidateUtil.assertObjectNotNull(data); - LOGGER.debug("body from request is {}" + data); - NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class); - RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } - } - - /** - * Instantiate NS instance
- * - * @param data The http request - * @param nsInstanceId The NS instance id - * @return - * @since ONAP Amsterdam Release - */ - @POST - @Path("/ns/{nsInstanceId}/instantiate") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response instantiateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) { - try { - ValidateUtil.assertObjectNotNull(data); - LOGGER.debug("body from request is {}" + data); - NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class); - RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } - } - - /** - * Terminate NS instance
- * - * @param data The http request - * @param nsInstanceId The NS instance id - * @return - * @since ONAP Amsterdam Release - */ - @POST - @Path("/ns/{nsInstanceId}/terminate") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response terminateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) { - try { - ValidateUtil.assertObjectNotNull(data); - LOGGER.debug("body from request is {}" + data); - NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class); - RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } - } - - /** - * Scale NS instance - *
- * - * @param servletReq The http request - * @param nsInstanceId The NS instance id - * @return - * @since ONAP Amsterdam Release - */ - @POST - @Path("/ns/{nsInstanceId}/scale") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response scaleNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) { - try { - ValidateUtil.assertObjectNotNull(data); - LOGGER.debug("Scale Ns Request Received.Body from request is {}" + data); - NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class); - RestfulResponse rsp = driverMgr.scaleNs(nsInstanceId, nsInput); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } - } - - - /** - * build response from restful response
- * - * @param rsp general response object - * @return - * @since ONAP Amsterdam Release - */ - private Response buildResponse(RestfulResponse rsp) { - return Response.status(rsp.getStatus()).entity(rsp.getResponseContent()).build(); - } -} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcManager.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcManager.java deleted file mode 100644 index 47d3842c03..0000000000 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/VfcManager.java +++ /dev/null @@ -1,496 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters.vfc; - -import java.util.HashMap; -import java.util.Map; - -import org.onap.so.adapters.vfc.constant.CommonConstant; -import org.onap.so.adapters.vfc.constant.CommonConstant.Step; -import org.onap.so.adapters.vfc.constant.DriverExceptionID; -import org.onap.so.adapters.vfc.constant.HttpCode; -import org.onap.so.adapters.vfc.exceptions.ApplicationException; -import org.onap.so.adapters.vfc.model.CustomerModel; -import org.onap.so.adapters.vfc.model.NSResourceInputParameter; -import org.onap.so.adapters.vfc.model.NsCreateReq; -import org.onap.so.adapters.vfc.model.NsInstantiateReq; -import org.onap.so.adapters.vfc.model.NsOperationKey; -import org.onap.so.adapters.vfc.model.NsParameters; -import org.onap.so.adapters.vfc.model.NsProgressStatus; -import org.onap.so.adapters.vfc.model.NsScaleParameters; -import org.onap.so.adapters.vfc.model.ResponseDescriptor; -import org.onap.so.adapters.vfc.model.RestfulResponse; -import org.onap.so.adapters.vfc.model.VFCScaleData; -import org.onap.so.adapters.vfc.util.JsonUtil; -import org.onap.so.adapters.vfc.util.RestfulUtil; -import org.onap.so.adapters.vfc.util.ValidateUtil; -import org.onap.so.db.request.beans.ResourceOperationStatus; -import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository; -import org.onap.so.requestsdb.RequestsDbConstant; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Example; -import org.springframework.stereotype.Component; - -/** - * VF-C Manager
- *

- *

- * - * @author - * @version ONAP Amsterdam Release 2017-08-28 - */ -@Component -public class VfcManager { - - private static final Logger LOGGER = LoggerFactory.getLogger(VfcManager.class); - - /** - * nfvo url map - */ - private static Map nfvoUrlMap; - @Autowired - private ResourceOperationStatusRepository resourceOperationStatusRepository; - - @Autowired - private RestfulUtil restfulUtil; - - static { - nfvoUrlMap = new HashMap<>(); - nfvoUrlMap.put(Step.CREATE, CommonConstant.NFVO_CREATE_URL); - nfvoUrlMap.put(Step.INSTANTIATE, CommonConstant.NFVO_INSTANTIATE_URL); - nfvoUrlMap.put(Step.TERMINATE, CommonConstant.NFVO_TERMINATE_URL); - nfvoUrlMap.put(Step.DELETE, CommonConstant.NFVO_DELETE_URL); - nfvoUrlMap.put(Step.QUERY, CommonConstant.NFVO_QUERY_URL); - nfvoUrlMap.put(Step.SCALE, CommonConstant.NFVO_SCALE_URL); - } - - public VfcManager() { - - } - - /** - * create network service
- * - * @param segInput input parameters for current node from http request - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse createNs(NSResourceInputParameter segInput) throws ApplicationException { - - // Step1: get service template by node type - String csarId = segInput.getNsServiceModelUUID(); - // nsdId for NFVO is "id" in the response, while for SDNO is "servcice template id" - LOGGER.info("serviceTemplateId is {}, id is {}", csarId, csarId); - - LOGGER.info("create ns -> begin"); - // Step2: Prepare url and method type - String url = getUrl(null, CommonConstant.Step.CREATE); - String methodType = CommonConstant.MethodType.POST; - - // Step3: Prepare restful parameters and options - NsCreateReq oRequest = new NsCreateReq(); - oRequest.setCsarId(csarId); - oRequest.setNsName(segInput.getNsServiceName()); - oRequest.setDescription(segInput.getNsServiceDescription()); - CustomerModel context = new CustomerModel(); - context.setGlobalCustomerId(segInput.getNsOperationKey().getGlobalSubscriberId()); - context.setServiceType(segInput.getNsOperationKey().getServiceType()); - oRequest.setContext(context); - String createReq = JsonUtil.marshal(oRequest); - - // Step4: Call NFVO or SDNO lcm to create ns - RestfulResponse createRsp = restfulUtil.send(url, methodType, createReq); - ValidateUtil.assertObjectNotNull(createRsp); - LOGGER.info("create ns response status is : {}", createRsp.getStatus()); - LOGGER.info("create ns response content is : {}", createRsp.getResponseContent()); - - // Step 5: save resource operation information - ResourceOperationStatus status = new ResourceOperationStatus(segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(), segInput.getNsOperationKey().getNodeTemplateUUID()); - status.setStatus(RequestsDbConstant.Status.PROCESSING); - status = resourceOperationStatusRepository.save(status); - if (!HttpCode.isSucess(createRsp.getStatus())) { - LOGGER.error("update segment operation status : fail to create ns"); - status.setProgress("40"); - status.setStatusDescription("NS is created"); - status.setStatus(RequestsDbConstant.Status.ERROR); - status.setErrorCode(String.valueOf(createRsp.getStatus())); - resourceOperationStatusRepository.save(status); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.FAIL_TO_CREATE_NS); - } - @SuppressWarnings("unchecked") - Map rsp = JsonUtil.unMarshal(createRsp.getResponseContent(), Map.class); - String nsInstanceId = rsp.get(CommonConstant.NS_INSTANCE_ID); - if (ValidateUtil.isStrEmpty(nsInstanceId)) { - LOGGER.error("Invalid instanceId from create operation"); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.INVALID_RESPONSEE_FROM_CREATE_OPERATION); - } - LOGGER.info("create ns -> end"); - LOGGER.info("save segment and operaton info -> begin"); - // Step 6: add relation between service and NS - AaiUtil.addRelation(segInput.getNsOperationKey().getGlobalSubscriberId(), - segInput.getNsOperationKey().getServiceType(), segInput.getNsOperationKey().getServiceId(), - nsInstanceId); - LOGGER.info("save segment and operation info -> end"); - return createRsp; - } - - /** - * delete network service
- * - * @param nsOperationKey The operation key of the NS resource - * @param nsInstanceId The NS instance id - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse deleteNs(NsOperationKey nsOperationKey, String nsInstanceId) - throws ApplicationException { - LOGGER.info("delete ns -> begin"); - // Step1: prepare url and methodType - String url = getUrl(nsInstanceId, CommonConstant.Step.DELETE); - String methodType = CommonConstant.MethodType.DELETE; - - // Step2: prepare restful parameters and options - RestfulResponse deleteRsp = restfulUtil.send(url, methodType, ""); - ValidateUtil.assertObjectNotNull(deleteRsp); - LOGGER.info("delete ns response status is : {}", deleteRsp.getStatus()); - LOGGER.info("delete ns response content is : {}", deleteRsp.getResponseContent()); - LOGGER.info("delete ns -> end"); - - ResourceOperationStatus status = new ResourceOperationStatus(nsOperationKey.getServiceId(), nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); - if (!HttpCode.isSucess(deleteRsp.getStatus())) { - LOGGER.error("fail to delete ns"); - - status.setStatus(RequestsDbConstant.Status.ERROR); - status.setErrorCode(String.valueOf(deleteRsp.getStatus())); - status.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); - resourceOperationStatusRepository.save(status); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.FAIL_TO_DELETE_NS); - } - - // Step3: remove relation info between service and ns - AaiUtil.removeRelation(nsOperationKey.getGlobalSubscriberId(), nsOperationKey.getServiceType(), - nsOperationKey.getServiceId(), nsInstanceId); - LOGGER.info("delete segment information -> end"); - - // Step4: update service segment operation status - status.setStatus(RequestsDbConstant.Status.FINISHED); - status.setErrorCode(String.valueOf(deleteRsp.getStatus())); - status.setProgress("100"); - status.setStatusDescription("VFC resource deletion finished"); - resourceOperationStatusRepository.save(status); - LOGGER.info("update segment operaton status for delete -> end"); - - return deleteRsp; - - } - - /** - * instantiate network service
- * - * @param nsInstanceId The NS instance id - * @param segInput input parameters for current node from http request - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse instantiateNs(String nsInstanceId, NSResourceInputParameter segInput) - throws ApplicationException { - // Call the NFVO or SDNO service to instantiate service - LOGGER.info("instantiate ns -> begin"); - - // Step1: Prepare restful parameters and options - NsInstantiateReq oRequest = new NsInstantiateReq(); - oRequest.setNsInstanceId(nsInstanceId); - NsParameters nsParameters = segInput.getNsParameters(); - oRequest.setLocationConstraints(nsParameters.getLocationConstraints()); - oRequest.setAdditionalParamForNs(nsParameters.getAdditionalParamForNs()); - String instReq = JsonUtil.marshal(oRequest); - // Step2: prepare url and - String url = getUrl(nsInstanceId, CommonConstant.Step.INSTANTIATE); - String methodType = CommonConstant.MethodType.POST; - - RestfulResponse instRsp = restfulUtil.send(url, methodType, instReq); - ResourceOperationStatus status = new ResourceOperationStatus(segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(), segInput.getNsOperationKey().getNodeTemplateUUID()); - ValidateUtil.assertObjectNotNull(instRsp); - if (!HttpCode.isSucess(instRsp.getStatus())) { - LOGGER.error("update segment operation status : fail to instantiate ns"); - status.setStatus(RequestsDbConstant.Status.ERROR); - status.setErrorCode(String.valueOf(instRsp.getStatus())); - status.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED); - resourceOperationStatusRepository.save(status); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.FAIL_TO_INSTANTIATE_NS); - } - LOGGER.info("instantiate ns response status is : {}", instRsp.getStatus()); - LOGGER.info("instantiate ns response content is : {}", instRsp.getResponseContent()); - ValidateUtil.assertObjectNotNull(instRsp.getResponseContent()); - @SuppressWarnings("unchecked") - Map rsp = JsonUtil.unMarshal(instRsp.getResponseContent(), Map.class); - String jobId = rsp.get(CommonConstant.JOB_ID); - if (ValidateUtil.isStrEmpty(jobId)) { - LOGGER.error("Invalid jobId from instantiate operation"); - status.setStatus(RequestsDbConstant.Status.ERROR); - status.setErrorCode(String.valueOf(instRsp.getStatus())); - status.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED); - resourceOperationStatusRepository.save(status); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.INVALID_RESPONSE_FROM_INSTANTIATE_OPERATION); - } - LOGGER.info("instantiate ns -> end"); - // Step 3: update segment operation job id - LOGGER.info("update resource operation status job id -> begin"); - status.setJobId(jobId); - status.setProgress("100"); - status.setStatusDescription("NS initiation completed."); - resourceOperationStatusRepository.save(status); - LOGGER.info("update segment operation job id -> end"); - - return instRsp; - } - - /** - * terminate network service
- * - * @param nsOperationKey The operation key for NS resource - * @param nsInstanceId The NS instance id - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse terminateNs(NsOperationKey nsOperationKey, String nsInstanceId) - throws ApplicationException { - // Step1: save segment operation info for delete process - LOGGER.info("save segment operation for delete process"); - ResourceOperationStatus status = new ResourceOperationStatus(nsOperationKey.getServiceId(), nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); - status.setStatus(RequestsDbConstant.Status.PROCESSING); - resourceOperationStatusRepository.save(status); - - LOGGER.info("terminate ns -> begin"); - // Step2: prepare url and method type - String url = getUrl(nsInstanceId, CommonConstant.Step.TERMINATE); - String methodType = CommonConstant.MethodType.POST; - - // Step3: prepare restful parameters and options - Map reqBody = new HashMap<>(); - reqBody.put("nsInstanceId", nsInstanceId); - reqBody.put("terminationType", "graceful"); - reqBody.put("gracefulTerminationTimeout", "60"); - - // Step4: Call the NFVO or SDNO service to terminate service - RestfulResponse terminateRsp = restfulUtil.send(url, methodType, JsonUtil.marshal(reqBody)); - ValidateUtil.assertObjectNotNull(terminateRsp); - LOGGER.info("terminate ns response status is : {}", terminateRsp.getStatus()); - LOGGER.info("terminate ns response content is : {}", terminateRsp.getResponseContent()); - // Step 3: update segment operation - if (!HttpCode.isSucess(terminateRsp.getStatus())) { - LOGGER.error("fail to instantiate ns"); - status.setStatus(RequestsDbConstant.Status.ERROR); - status.setErrorCode(String.valueOf(terminateRsp.getStatus())); - status.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); - resourceOperationStatusRepository.save(status); - - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.FAIL_TO_TERMINATE_NS); - } - @SuppressWarnings("unchecked") - Map rsp = JsonUtil.unMarshal(terminateRsp.getResponseContent(), Map.class); - String jobId = rsp.get(CommonConstant.JOB_ID); - if (ValidateUtil.isStrEmpty(jobId)) { - LOGGER.error("Invalid jobId from terminate operation"); - status.setStatus(RequestsDbConstant.Status.ERROR); - status.setErrorCode(String.valueOf(terminateRsp.getStatus())); - status.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); - resourceOperationStatusRepository.save(status); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.INVALID_RESPONSE_FROM_TERMINATE_OPERATION); - } - LOGGER.info("terminate ns -> end"); - - LOGGER.info("update segment job id -> begin"); - status.setProgress("60"); - status.setStatusDescription("NS is termination completed"); - status.setJobId(jobId); - resourceOperationStatusRepository.save(status); - LOGGER.info("update segment job id -> end"); - - return terminateRsp; - } - - /** - * get ns progress by job Id
- * - * @param nsOperationKey The OperationKey for NS resource - * @param jobId the job id - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse getNsProgress(NsOperationKey nsOperationKey, String jobId) - throws ApplicationException { - - ValidateUtil.assertObjectNotNull(jobId); - // Step 1: query the current resource operation status - ResourceOperationStatus status = new ResourceOperationStatus(nsOperationKey.getServiceId(), nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); - status = resourceOperationStatusRepository.findOne(Example.of(status)); - // Step 2: start query - LOGGER.info("query ns status -> begin"); - String url = getUrl(jobId, CommonConstant.Step.QUERY); - String methodType = CommonConstant.MethodType.GET; - // prepare restful parameters and options - RestfulResponse rsp = restfulUtil.send(url, methodType, ""); - ValidateUtil.assertObjectNotNull(rsp); - LOGGER.info("query ns progress response status is : {}", rsp.getStatus()); - LOGGER.info("query ns progress response content is : {}", rsp.getResponseContent()); - // Step 3:check the response staus - if (!HttpCode.isSucess(rsp.getStatus())) { - LOGGER.info("fail to query job status"); - status.setErrorCode(String.valueOf(rsp.getStatus())); - status.setStatus(RequestsDbConstant.Status.ERROR); - status.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); - resourceOperationStatusRepository.save(status); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.FAIL_TO_QUERY_JOB_STATUS); - } - // Step 4: Process Network Service Instantiate Response - NsProgressStatus nsProgress = - JsonUtil.unMarshal(rsp.getResponseContent(), NsProgressStatus.class); - ResponseDescriptor rspDesc = nsProgress.getResponseDescriptor(); - // Step 5: update segment operation progress - - status.setProgress(rspDesc.getProgress()); - status.setStatusDescription(rspDesc.getStatusDescription()); - resourceOperationStatusRepository.save(status); - - // Step 6: update segment operation status - if (RequestsDbConstant.Progress.ONE_HUNDRED.equals(rspDesc.getProgress()) - && RequestsDbConstant.Status.FINISHED.equals(rspDesc.getStatus())) { - LOGGER.info("job result is succeeded, operType is {}", status.getOperType()); - status.setErrorCode(String.valueOf(rsp.getStatus())); - status.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); - - if(RequestsDbConstant.OperationType.CREATE.equalsIgnoreCase(status.getOperType()) || "createInstance".equalsIgnoreCase (status.getOperType())) { - status.setStatus(RequestsDbConstant.Status.FINISHED); - } - resourceOperationStatusRepository.save(status); - } else if (RequestsDbConstant.Status.ERROR.equals(rspDesc.getStatus())) { - LOGGER.error("job result is failed, operType is {}", status.getOperType()); - status.setErrorCode(String.valueOf(rsp.getStatus())); - status.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); - status.setStatus(RequestsDbConstant.Status.ERROR); - resourceOperationStatusRepository.save(status); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.JOB_STATUS_ERROR); - } else { - LOGGER.error("unexcepted response status"); - } - LOGGER.info("query ns status -> end"); - - return rsp; - } - - /** - * Scale NS instance - *
- * - * @param nsInstanceId The NS instance id - * @param segInput input parameters for current node from http request - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse scaleNs(String nsInstanceId, NSResourceInputParameter segInput) - throws ApplicationException { - // Call the NFVO to scale service - LOGGER.info("scale ns -> begin"); - - // Step1: Prepare restful parameters and options - VFCScaleData oRequest = new VFCScaleData(); - oRequest.setNsInstanceId(nsInstanceId); - NsScaleParameters nsScaleParameters = segInput.getNsScaleParameters(); - oRequest.setScaleType(nsScaleParameters.getScaleType()); - oRequest.setScaleNsData(nsScaleParameters.getScaleNsByStepsData()); - String scaleReq = JsonUtil.marshal(oRequest); - - // Step2: prepare url and method type - String url = getUrl(nsInstanceId, CommonConstant.Step.SCALE); - String methodType = CommonConstant.MethodType.POST; - LOGGER.info("scale ns request is {}", scaleReq); - // Step3: Call NFVO lcm to scale ns - RestfulResponse scaleRsp = restfulUtil.send(url, methodType, scaleReq); - - ResourceOperationStatus status = new ResourceOperationStatus(segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(), segInput.getNsOperationKey().getNodeTemplateUUID()); - ResourceOperationStatus nsOperInfo = resourceOperationStatusRepository.findOne(Example.of(status)); - ValidateUtil.assertObjectNotNull(scaleRsp); - if(!HttpCode.isSucess(scaleRsp.getStatus())) { - LOGGER.error("update segment operation status : fail to scale ns"); - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - nsOperInfo.setErrorCode(String.valueOf(scaleRsp.getStatus())); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.SCALE_NS_FAILED); - resourceOperationStatusRepository.save(nsOperInfo); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_SCALE_NS); - } - LOGGER.info("scale ns response status is {}", scaleRsp.getStatus()); - LOGGER.info("scale ns response content is {}", scaleRsp.getResponseContent()); - - ValidateUtil.assertObjectNotNull(scaleRsp.getResponseContent()); - @SuppressWarnings("unchecked") - Map rsp = JsonUtil.unMarshal(scaleRsp.getResponseContent(), Map.class); - String jobId = rsp.get(CommonConstant.JOB_ID); - if(ValidateUtil.isStrEmpty(jobId)) { - LOGGER.error("Invalid jobId from scale operation"); - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - nsOperInfo.setErrorCode(String.valueOf(scaleRsp.getStatus())); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.SCALE_NS_FAILED); - resourceOperationStatusRepository.save(nsOperInfo); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.INVALID_RESPONSE_FROM_SCALE_OPERATION); - } - - LOGGER.info("update resource operation status job id -> begin"); - // Step 4: update segment operation job id - nsOperInfo.setJobId(jobId); - resourceOperationStatusRepository.save(nsOperInfo); - LOGGER.info("update segment operation job id -> end"); - LOGGER.info("scale ns -> end"); - - return scaleRsp; - } - - /** - * get url for the operation
- * - * @param variable variable should be put in the url - * @param step step of the operation (terminate,query,delete) - * @return - * @since ONAP Amsterdam Release - */ - private String getUrl(String variable, String step) { - - String url; - String originalUrl; - originalUrl = nfvoUrlMap.get(step); - url = String.format(originalUrl, variable); - return url; - - } - -} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/JerseyConfiguration.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/JerseyConfiguration.java deleted file mode 100644 index a97549189d..0000000000 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/JerseyConfiguration.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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 org.onap.so.adapters.vfc.application; - -import javax.annotation.PostConstruct; -import javax.ws.rs.ApplicationPath; - -import org.glassfish.jersey.server.ResourceConfig; -import org.onap.so.adapters.vfc.HealthCheckHandler; -import org.onap.so.adapters.vfc.VfcAdapterRest; -import org.springframework.context.annotation.Configuration; - -import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.jaxrs.listing.ApiListingResource; -import io.swagger.jaxrs.listing.SwaggerSerializers; - -@Configuration -@ApplicationPath("/vfc") -public class JerseyConfiguration extends ResourceConfig { - - public JerseyConfiguration() { - - } - - @PostConstruct - public void setUp() { - register(VfcAdapterRest.class); - register(HealthCheckHandler.class); - - this.register(ApiListingResource.class); - this.register(SwaggerSerializers.class); - - BeanConfig beanConfig = new BeanConfig(); - beanConfig.setVersion("1.0.2"); - beanConfig.setSchemes(new String[] { "http" }); - beanConfig.setHost("localhost:8080"); - beanConfig.setBasePath("/"); - beanConfig.setResourcePackage("org.onap.so.adapters.vfc.application"); - beanConfig.setPrettyPrint(true); - beanConfig.setScan(true); - } -} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/MSOVfcApplication.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/MSOVfcApplication.java deleted file mode 100644 index c6d141391d..0000000000 --- a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/application/MSOVfcApplication.java +++ /dev/null @@ -1,40 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 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 org.onap.so.adapters.vfc.application; - - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; - - - -@SpringBootApplication(scanBasePackages = {"org.onap.so"}) -@EnableJpaRepositories({"org.onap.so.db.request.data.repository"}) -@EntityScan({"org.onap.so.db.request.beans"}) -public class MSOVfcApplication { - - public static void main(String... args) { - SpringApplication.run(MSOVfcApplication.class, args); - } - -} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/AaiUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/AaiUtil.java new file mode 100644 index 0000000000..6ae2ba0aca --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/AaiUtil.java @@ -0,0 +1,47 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters.vfc.rest; + +import org.onap.so.adapters.vfc.model.RestfulResponse; + +/** + * Implement class of operating aai database table
+ *

+ *

+ * + * @author + * @version ONAP Amsterdam Release 2017-08-28 + */ +public class AaiUtil { + + public static RestfulResponse addRelation(String globalSubsriberId, String serviceType, + String serviceInstanceId, String resourceInstanceId) { + // sent rest to aai to add relation for service and ns. + + return null; + } + + public static RestfulResponse removeRelation(String globalSubsriberId, String serviceType, + String serviceInstanceId, String resourceInstanceId) { + // sent rest to aai to remove relation between service an ns. + return null; + } +} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/HealthCheckHandler.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/HealthCheckHandler.java new file mode 100644 index 0000000000..c39a165338 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/HealthCheckHandler.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters.vfc.rest; + +import javax.ws.rs.HEAD; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +import org.apache.http.HttpStatus; +import org.onap.so.logger.MsoLogger; +import org.onap.so.utils.UUIDChecker; +import org.springframework.stereotype.Component; + +/** + * Health Check + *
+ *

+ *

+ * + * @author + * @version ONAP Amsterdam Release 2017-08-28 + */ +@Path("/") +@Component +public class HealthCheckHandler { + + private static MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, HealthCheckHandler.class); + + + private static final String CHECK_HTML = "Health CheckApplication ready"; + + public static final Response HEALTH_CHECK_RESPONSE = Response.status (HttpStatus.SC_OK) + .entity (CHECK_HTML) + .build (); + + @HEAD + @Path("/healthcheck") + @Produces("text/html") + public Response healthcheck(@QueryParam("requestId") String requestId) { + MsoLogger.setServiceName("Healthcheck"); + UUIDChecker.verifyOldUUID(requestId, msoLogger); + return HEALTH_CHECK_RESPONSE; + } + +} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcAdapterRest.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcAdapterRest.java new file mode 100644 index 0000000000..9489ef14f5 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcAdapterRest.java @@ -0,0 +1,224 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters.vfc.rest; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.onap.so.adapters.vfc.exceptions.ApplicationException; +import org.onap.so.adapters.vfc.model.NSResourceInputParameter; +import org.onap.so.adapters.vfc.model.NsOperationKey; +import org.onap.so.adapters.vfc.model.RestfulResponse; +import org.onap.so.adapters.vfc.util.JsonUtil; +import org.onap.so.adapters.vfc.util.ValidateUtil; +import org.onap.so.logger.MsoLogger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * The rest class for VF-c Adapter
+ *

+ *

+ * + * @author + * @version ONAP Amsterdam Release 2017-08-28 + */ +@Component +@Path("/v1/vfcadapter") +public class VfcAdapterRest { + + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA, VfcAdapterRest.class); + + @Autowired + private VfcManager driverMgr ; + + public VfcAdapterRest() { + + } + + /** + * Create a NS
+ * + * @param data http request + * @return + * @since ONAP Amsterdam Release + */ + @POST + @Path("/ns") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response createNfvoNs(String data) { + try { + ValidateUtil.assertObjectNotNull(data); + LOGGER.debug("body from request is {}" + data); + NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class); + RestfulResponse rsp = driverMgr.createNs(nsInput); + return buildResponse(rsp); + } catch(ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); + } + } + + /** + * Delete NS instance
+ * + * @param data The http request + * @param nsInstanceId The NS instance id + * @return response + * @since ONAP Amsterdam Release + */ + @DELETE + @Path("/ns/{nsInstanceId}") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response deleteNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) { + try { + + ValidateUtil.assertObjectNotNull(data); + LOGGER.debug("body from request is {}" + data); + NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class); + RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId); + return buildResponse(rsp); + } catch(ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); + } + } + + /** + * Query Operation job status
+ * + * @param data The Http Request + * @param jobId The job id + * @return + * @since ONAP Amsterdam Release + */ + @POST + @Path("/jobs/{jobId}") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response queryNfvoJobStatus(String data, @PathParam("jobId") String jobId) { + try { + ValidateUtil.assertObjectNotNull(data); + LOGGER.debug("body from request is {}" + data); + NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class); + RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId); + return buildResponse(rsp); + } catch(ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); + } + } + + /** + * Instantiate NS instance
+ * + * @param data The http request + * @param nsInstanceId The NS instance id + * @return + * @since ONAP Amsterdam Release + */ + @POST + @Path("/ns/{nsInstanceId}/instantiate") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response instantiateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) { + try { + ValidateUtil.assertObjectNotNull(data); + LOGGER.debug("body from request is {}" + data); + NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class); + RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput); + return buildResponse(rsp); + } catch(ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); + } + } + + /** + * Terminate NS instance
+ * + * @param data The http request + * @param nsInstanceId The NS instance id + * @return + * @since ONAP Amsterdam Release + */ + @POST + @Path("/ns/{nsInstanceId}/terminate") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response terminateNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) { + try { + ValidateUtil.assertObjectNotNull(data); + LOGGER.debug("body from request is {}" + data); + NsOperationKey nsOperationKey = JsonUtil.unMarshal(data, NsOperationKey.class); + RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId); + return buildResponse(rsp); + } catch(ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); + } + } + + /** + * Scale NS instance + *
+ * + * @param servletReq The http request + * @param nsInstanceId The NS instance id + * @return + * @since ONAP Amsterdam Release + */ + @POST + @Path("/ns/{nsInstanceId}/scale") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response scaleNfvoNs(String data, @PathParam("nsInstanceId") String nsInstanceId) { + try { + ValidateUtil.assertObjectNotNull(data); + LOGGER.debug("Scale Ns Request Received.Body from request is {}" + data); + NSResourceInputParameter nsInput = JsonUtil.unMarshal(data, NSResourceInputParameter.class); + RestfulResponse rsp = driverMgr.scaleNs(nsInstanceId, nsInput); + return buildResponse(rsp); + } catch(ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); + } + } + + + /** + * build response from restful response
+ * + * @param rsp general response object + * @return + * @since ONAP Amsterdam Release + */ + private Response buildResponse(RestfulResponse rsp) { + return Response.status(rsp.getStatus()).entity(rsp.getResponseContent()).build(); + } +} diff --git a/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcManager.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcManager.java new file mode 100644 index 0000000000..2dbc444bc3 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/VfcManager.java @@ -0,0 +1,496 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.adapters.vfc.rest; + +import java.util.HashMap; +import java.util.Map; + +import org.onap.so.adapters.vfc.constant.CommonConstant; +import org.onap.so.adapters.vfc.constant.CommonConstant.Step; +import org.onap.so.adapters.vfc.constant.DriverExceptionID; +import org.onap.so.adapters.vfc.constant.HttpCode; +import org.onap.so.adapters.vfc.exceptions.ApplicationException; +import org.onap.so.adapters.vfc.model.CustomerModel; +import org.onap.so.adapters.vfc.model.NSResourceInputParameter; +import org.onap.so.adapters.vfc.model.NsCreateReq; +import org.onap.so.adapters.vfc.model.NsInstantiateReq; +import org.onap.so.adapters.vfc.model.NsOperationKey; +import org.onap.so.adapters.vfc.model.NsParameters; +import org.onap.so.adapters.vfc.model.NsProgressStatus; +import org.onap.so.adapters.vfc.model.NsScaleParameters; +import org.onap.so.adapters.vfc.model.ResponseDescriptor; +import org.onap.so.adapters.vfc.model.RestfulResponse; +import org.onap.so.adapters.vfc.model.VFCScaleData; +import org.onap.so.adapters.vfc.util.JsonUtil; +import org.onap.so.adapters.vfc.util.RestfulUtil; +import org.onap.so.adapters.vfc.util.ValidateUtil; +import org.onap.so.db.request.beans.ResourceOperationStatus; +import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository; +import org.onap.so.requestsdb.RequestsDbConstant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Primary; +import org.springframework.data.domain.Example; +import org.springframework.stereotype.Component; + +/** + * VF-C Manager
+ *

+ *

+ * + * @author + * @version ONAP Amsterdam Release 2017-08-28 + */ +@Component +@Primary +public class VfcManager { + + private static final Logger LOGGER = LoggerFactory.getLogger(VfcManager.class); + + /** + * nfvo url map + */ + private Map nfvoUrlMap; + + @Autowired + private ResourceOperationStatusRepository resourceOperationStatusRepository; + + @Autowired + private RestfulUtil restfulUtil; + + + public VfcManager() { + nfvoUrlMap = new HashMap<>(); + nfvoUrlMap.put(Step.CREATE, CommonConstant.NFVO_CREATE_URL); + nfvoUrlMap.put(Step.INSTANTIATE, CommonConstant.NFVO_INSTANTIATE_URL); + nfvoUrlMap.put(Step.TERMINATE, CommonConstant.NFVO_TERMINATE_URL); + nfvoUrlMap.put(Step.DELETE, CommonConstant.NFVO_DELETE_URL); + nfvoUrlMap.put(Step.QUERY, CommonConstant.NFVO_QUERY_URL); + nfvoUrlMap.put(Step.SCALE, CommonConstant.NFVO_SCALE_URL); + } + + /** + * create network service
+ * + * @param segInput input parameters for current node from http request + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse createNs(NSResourceInputParameter segInput) throws ApplicationException { + + // Step1: get service template by node type + String csarId = segInput.getNsServiceModelUUID(); + // nsdId for NFVO is "id" in the response, while for SDNO is "servcice template id" + LOGGER.info("serviceTemplateId is {}, id is {}", csarId, csarId); + + LOGGER.info("create ns -> begin"); + // Step2: Prepare url and method type + String url = getUrl(null, CommonConstant.Step.CREATE); + String methodType = CommonConstant.MethodType.POST; + + // Step3: Prepare restful parameters and options + NsCreateReq oRequest = new NsCreateReq(); + oRequest.setCsarId(csarId); + oRequest.setNsName(segInput.getNsServiceName()); + oRequest.setDescription(segInput.getNsServiceDescription()); + CustomerModel context = new CustomerModel(); + context.setGlobalCustomerId(segInput.getNsOperationKey().getGlobalSubscriberId()); + context.setServiceType(segInput.getNsOperationKey().getServiceType()); + oRequest.setContext(context); + String createReq = JsonUtil.marshal(oRequest); + + // Step4: Call NFVO or SDNO lcm to create ns + RestfulResponse createRsp = restfulUtil.send(url, methodType, createReq); + ValidateUtil.assertObjectNotNull(createRsp); + LOGGER.info("create ns response status is : {}", createRsp.getStatus()); + LOGGER.info("create ns response content is : {}", createRsp.getResponseContent()); + + // Step 5: save resource operation information + ResourceOperationStatus status = new ResourceOperationStatus(segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(), segInput.getNsOperationKey().getNodeTemplateUUID()); + status.setStatus(RequestsDbConstant.Status.PROCESSING); + status = resourceOperationStatusRepository.save(status); + if (!HttpCode.isSucess(createRsp.getStatus())) { + LOGGER.error("update segment operation status : fail to create ns"); + status.setProgress("40"); + status.setStatusDescription("NS is created"); + status.setStatus(RequestsDbConstant.Status.ERROR); + status.setErrorCode(String.valueOf(createRsp.getStatus())); + resourceOperationStatusRepository.save(status); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_CREATE_NS); + } + @SuppressWarnings("unchecked") + Map rsp = JsonUtil.unMarshal(createRsp.getResponseContent(), Map.class); + String nsInstanceId = rsp.get(CommonConstant.NS_INSTANCE_ID); + if (ValidateUtil.isStrEmpty(nsInstanceId)) { + LOGGER.error("Invalid instanceId from create operation"); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.INVALID_RESPONSEE_FROM_CREATE_OPERATION); + } + LOGGER.info("create ns -> end"); + LOGGER.info("save segment and operaton info -> begin"); + // Step 6: add relation between service and NS + AaiUtil.addRelation(segInput.getNsOperationKey().getGlobalSubscriberId(), + segInput.getNsOperationKey().getServiceType(), segInput.getNsOperationKey().getServiceId(), + nsInstanceId); + LOGGER.info("save segment and operation info -> end"); + return createRsp; + } + + /** + * delete network service
+ * + * @param nsOperationKey The operation key of the NS resource + * @param nsInstanceId The NS instance id + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse deleteNs(NsOperationKey nsOperationKey, String nsInstanceId) + throws ApplicationException { + LOGGER.info("delete ns -> begin"); + // Step1: prepare url and methodType + String url = getUrl(nsInstanceId, CommonConstant.Step.DELETE); + String methodType = CommonConstant.MethodType.DELETE; + + // Step2: prepare restful parameters and options + RestfulResponse deleteRsp = restfulUtil.send(url, methodType, ""); + ValidateUtil.assertObjectNotNull(deleteRsp); + LOGGER.info("delete ns response status is : {}", deleteRsp.getStatus()); + LOGGER.info("delete ns response content is : {}", deleteRsp.getResponseContent()); + LOGGER.info("delete ns -> end"); + + ResourceOperationStatus status = new ResourceOperationStatus(nsOperationKey.getServiceId(), nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); + if (!HttpCode.isSucess(deleteRsp.getStatus())) { + LOGGER.error("fail to delete ns"); + + status.setStatus(RequestsDbConstant.Status.ERROR); + status.setErrorCode(String.valueOf(deleteRsp.getStatus())); + status.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); + resourceOperationStatusRepository.save(status); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_DELETE_NS); + } + + // Step3: remove relation info between service and ns + AaiUtil.removeRelation(nsOperationKey.getGlobalSubscriberId(), nsOperationKey.getServiceType(), + nsOperationKey.getServiceId(), nsInstanceId); + LOGGER.info("delete segment information -> end"); + + // Step4: update service segment operation status + status.setStatus(RequestsDbConstant.Status.FINISHED); + status.setErrorCode(String.valueOf(deleteRsp.getStatus())); + status.setProgress("100"); + status.setStatusDescription("VFC resource deletion finished"); + resourceOperationStatusRepository.save(status); + LOGGER.info("update segment operaton status for delete -> end"); + + return deleteRsp; + + } + + /** + * instantiate network service
+ * + * @param nsInstanceId The NS instance id + * @param segInput input parameters for current node from http request + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse instantiateNs(String nsInstanceId, NSResourceInputParameter segInput) + throws ApplicationException { + // Call the NFVO or SDNO service to instantiate service + LOGGER.info("instantiate ns -> begin"); + + // Step1: Prepare restful parameters and options + NsInstantiateReq oRequest = new NsInstantiateReq(); + oRequest.setNsInstanceId(nsInstanceId); + NsParameters nsParameters = segInput.getNsParameters(); + oRequest.setLocationConstraints(nsParameters.getLocationConstraints()); + oRequest.setAdditionalParamForNs(nsParameters.getAdditionalParamForNs()); + String instReq = JsonUtil.marshal(oRequest); + // Step2: prepare url and + String url = getUrl(nsInstanceId, CommonConstant.Step.INSTANTIATE); + String methodType = CommonConstant.MethodType.POST; + + RestfulResponse instRsp = restfulUtil.send(url, methodType, instReq); + ResourceOperationStatus status = new ResourceOperationStatus(segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(), segInput.getNsOperationKey().getNodeTemplateUUID()); + ValidateUtil.assertObjectNotNull(instRsp); + if (!HttpCode.isSucess(instRsp.getStatus())) { + LOGGER.error("update segment operation status : fail to instantiate ns"); + status.setStatus(RequestsDbConstant.Status.ERROR); + status.setErrorCode(String.valueOf(instRsp.getStatus())); + status.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED); + resourceOperationStatusRepository.save(status); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_INSTANTIATE_NS); + } + LOGGER.info("instantiate ns response status is : {}", instRsp.getStatus()); + LOGGER.info("instantiate ns response content is : {}", instRsp.getResponseContent()); + ValidateUtil.assertObjectNotNull(instRsp.getResponseContent()); + @SuppressWarnings("unchecked") + Map rsp = JsonUtil.unMarshal(instRsp.getResponseContent(), Map.class); + String jobId = rsp.get(CommonConstant.JOB_ID); + if (ValidateUtil.isStrEmpty(jobId)) { + LOGGER.error("Invalid jobId from instantiate operation"); + status.setStatus(RequestsDbConstant.Status.ERROR); + status.setErrorCode(String.valueOf(instRsp.getStatus())); + status.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED); + resourceOperationStatusRepository.save(status); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.INVALID_RESPONSE_FROM_INSTANTIATE_OPERATION); + } + LOGGER.info("instantiate ns -> end"); + // Step 3: update segment operation job id + LOGGER.info("update resource operation status job id -> begin"); + status.setJobId(jobId); + status.setProgress("100"); + status.setStatusDescription("NS initiation completed."); + resourceOperationStatusRepository.save(status); + LOGGER.info("update segment operation job id -> end"); + + return instRsp; + } + + /** + * terminate network service
+ * + * @param nsOperationKey The operation key for NS resource + * @param nsInstanceId The NS instance id + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse terminateNs(NsOperationKey nsOperationKey, String nsInstanceId) + throws ApplicationException { + // Step1: save segment operation info for delete process + LOGGER.info("save segment operation for delete process"); + ResourceOperationStatus status = new ResourceOperationStatus(nsOperationKey.getServiceId(), nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); + status.setStatus(RequestsDbConstant.Status.PROCESSING); + resourceOperationStatusRepository.save(status); + + LOGGER.info("terminate ns -> begin"); + // Step2: prepare url and method type + String url = getUrl(nsInstanceId, CommonConstant.Step.TERMINATE); + String methodType = CommonConstant.MethodType.POST; + + // Step3: prepare restful parameters and options + Map reqBody = new HashMap<>(); + reqBody.put("nsInstanceId", nsInstanceId); + reqBody.put("terminationType", "graceful"); + reqBody.put("gracefulTerminationTimeout", "60"); + + // Step4: Call the NFVO or SDNO service to terminate service + RestfulResponse terminateRsp = restfulUtil.send(url, methodType, JsonUtil.marshal(reqBody)); + ValidateUtil.assertObjectNotNull(terminateRsp); + LOGGER.info("terminate ns response status is : {}", terminateRsp.getStatus()); + LOGGER.info("terminate ns response content is : {}", terminateRsp.getResponseContent()); + // Step 3: update segment operation + if (!HttpCode.isSucess(terminateRsp.getStatus())) { + LOGGER.error("fail to instantiate ns"); + status.setStatus(RequestsDbConstant.Status.ERROR); + status.setErrorCode(String.valueOf(terminateRsp.getStatus())); + status.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); + resourceOperationStatusRepository.save(status); + + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_TERMINATE_NS); + } + @SuppressWarnings("unchecked") + Map rsp = JsonUtil.unMarshal(terminateRsp.getResponseContent(), Map.class); + String jobId = rsp.get(CommonConstant.JOB_ID); + if (ValidateUtil.isStrEmpty(jobId)) { + LOGGER.error("Invalid jobId from terminate operation"); + status.setStatus(RequestsDbConstant.Status.ERROR); + status.setErrorCode(String.valueOf(terminateRsp.getStatus())); + status.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); + resourceOperationStatusRepository.save(status); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.INVALID_RESPONSE_FROM_TERMINATE_OPERATION); + } + LOGGER.info("terminate ns -> end"); + + LOGGER.info("update segment job id -> begin"); + status.setProgress("60"); + status.setStatusDescription("NS is termination completed"); + status.setJobId(jobId); + resourceOperationStatusRepository.save(status); + LOGGER.info("update segment job id -> end"); + + return terminateRsp; + } + + /** + * get ns progress by job Id
+ * + * @param nsOperationKey The OperationKey for NS resource + * @param jobId the job id + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse getNsProgress(NsOperationKey nsOperationKey, String jobId) + throws ApplicationException { + + ValidateUtil.assertObjectNotNull(jobId); + // Step 1: query the current resource operation status + ResourceOperationStatus status = new ResourceOperationStatus(nsOperationKey.getServiceId(), nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); + status = resourceOperationStatusRepository.findOne(Example.of(status)); + // Step 2: start query + LOGGER.info("query ns status -> begin"); + String url = getUrl(jobId, CommonConstant.Step.QUERY); + String methodType = CommonConstant.MethodType.GET; + // prepare restful parameters and options + RestfulResponse rsp = restfulUtil.send(url, methodType, ""); + ValidateUtil.assertObjectNotNull(rsp); + LOGGER.info("query ns progress response status is : {}", rsp.getStatus()); + LOGGER.info("query ns progress response content is : {}", rsp.getResponseContent()); + // Step 3:check the response staus + if (!HttpCode.isSucess(rsp.getStatus())) { + LOGGER.info("fail to query job status"); + status.setErrorCode(String.valueOf(rsp.getStatus())); + status.setStatus(RequestsDbConstant.Status.ERROR); + status.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); + resourceOperationStatusRepository.save(status); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_QUERY_JOB_STATUS); + } + // Step 4: Process Network Service Instantiate Response + NsProgressStatus nsProgress = + JsonUtil.unMarshal(rsp.getResponseContent(), NsProgressStatus.class); + ResponseDescriptor rspDesc = nsProgress.getResponseDescriptor(); + // Step 5: update segment operation progress + + status.setProgress(rspDesc.getProgress()); + status.setStatusDescription(rspDesc.getStatusDescription()); + resourceOperationStatusRepository.save(status); + + // Step 6: update segment operation status + if (RequestsDbConstant.Progress.ONE_HUNDRED.equals(rspDesc.getProgress()) + && RequestsDbConstant.Status.FINISHED.equals(rspDesc.getStatus())) { + LOGGER.info("job result is succeeded, operType is {}", status.getOperType()); + status.setErrorCode(String.valueOf(rsp.getStatus())); + status.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); + + if(RequestsDbConstant.OperationType.CREATE.equalsIgnoreCase(status.getOperType()) || "createInstance".equalsIgnoreCase (status.getOperType())) { + status.setStatus(RequestsDbConstant.Status.FINISHED); + } + resourceOperationStatusRepository.save(status); + } else if (RequestsDbConstant.Status.ERROR.equals(rspDesc.getStatus())) { + LOGGER.error("job result is failed, operType is {}", status.getOperType()); + status.setErrorCode(String.valueOf(rsp.getStatus())); + status.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); + status.setStatus(RequestsDbConstant.Status.ERROR); + resourceOperationStatusRepository.save(status); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.JOB_STATUS_ERROR); + } else { + LOGGER.error("unexcepted response status"); + } + LOGGER.info("query ns status -> end"); + + return rsp; + } + + /** + * Scale NS instance + *
+ * + * @param nsInstanceId The NS instance id + * @param segInput input parameters for current node from http request + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse scaleNs(String nsInstanceId, NSResourceInputParameter segInput) + throws ApplicationException { + // Call the NFVO to scale service + LOGGER.info("scale ns -> begin"); + + // Step1: Prepare restful parameters and options + VFCScaleData oRequest = new VFCScaleData(); + oRequest.setNsInstanceId(nsInstanceId); + NsScaleParameters nsScaleParameters = segInput.getNsScaleParameters(); + oRequest.setScaleType(nsScaleParameters.getScaleType()); + oRequest.setScaleNsData(nsScaleParameters.getScaleNsByStepsData()); + String scaleReq = JsonUtil.marshal(oRequest); + + // Step2: prepare url and method type + String url = getUrl(nsInstanceId, CommonConstant.Step.SCALE); + String methodType = CommonConstant.MethodType.POST; + LOGGER.info("scale ns request is {}", scaleReq); + // Step3: Call NFVO lcm to scale ns + RestfulResponse scaleRsp = restfulUtil.send(url, methodType, scaleReq); + + ResourceOperationStatus status = new ResourceOperationStatus(segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(), segInput.getNsOperationKey().getNodeTemplateUUID()); + ResourceOperationStatus nsOperInfo = resourceOperationStatusRepository.findOne(Example.of(status)); + ValidateUtil.assertObjectNotNull(scaleRsp); + if(!HttpCode.isSucess(scaleRsp.getStatus())) { + LOGGER.error("update segment operation status : fail to scale ns"); + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + nsOperInfo.setErrorCode(String.valueOf(scaleRsp.getStatus())); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.SCALE_NS_FAILED); + resourceOperationStatusRepository.save(nsOperInfo); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_SCALE_NS); + } + LOGGER.info("scale ns response status is {}", scaleRsp.getStatus()); + LOGGER.info("scale ns response content is {}", scaleRsp.getResponseContent()); + + ValidateUtil.assertObjectNotNull(scaleRsp.getResponseContent()); + @SuppressWarnings("unchecked") + Map rsp = JsonUtil.unMarshal(scaleRsp.getResponseContent(), Map.class); + String jobId = rsp.get(CommonConstant.JOB_ID); + if(ValidateUtil.isStrEmpty(jobId)) { + LOGGER.error("Invalid jobId from scale operation"); + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + nsOperInfo.setErrorCode(String.valueOf(scaleRsp.getStatus())); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.SCALE_NS_FAILED); + resourceOperationStatusRepository.save(nsOperInfo); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.INVALID_RESPONSE_FROM_SCALE_OPERATION); + } + + LOGGER.info("update resource operation status job id -> begin"); + // Step 4: update segment operation job id + nsOperInfo.setJobId(jobId); + resourceOperationStatusRepository.save(nsOperInfo); + LOGGER.info("update segment operation job id -> end"); + LOGGER.info("scale ns -> end"); + + return scaleRsp; + } + + /** + * get url for the operation
+ * + * @param variable variable should be put in the url + * @param step step of the operation (terminate,query,delete) + * @return + * @since ONAP Amsterdam Release + */ + private String getUrl(String variable, String step) { + + String url; + String originalUrl; + originalUrl = nfvoUrlMap.get(step); + url = String.format(originalUrl, variable); + return url; + + } + +} diff --git a/adapters/mso-vfc-adapter/src/main/resources/application-local.yaml b/adapters/mso-vfc-adapter/src/main/resources/application-local.yaml new file mode 100644 index 0000000000..0519f50c46 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/main/resources/application-local.yaml @@ -0,0 +1,34 @@ +server: + port: 8091 + tomcat: + max-threads: 50 +ssl-enable: false +mso: + logPath: logs + site-name: localSite +spring: + datasource: + url: jdbc:mariadb://localhost:3306/requestdb + username: mso + password: mso123 + 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 diff --git a/adapters/mso-vfc-adapter/src/main/resources/application.yaml b/adapters/mso-vfc-adapter/src/main/resources/application.yaml index ba574ba3e9..2cee9cf7dc 100644 --- a/adapters/mso-vfc-adapter/src/main/resources/application.yaml +++ b/adapters/mso-vfc-adapter/src/main/resources/application.yaml @@ -1,37 +1,32 @@ -logging: - path: logs - -# H2 -spring: - datasource: - url: jdbc:h2:mem:test;DB_CLOSE_DELAY=-1; - username: sa - password: sa - driver-class-name: org.h2.Driver - intialize: true - h2: - console: - enabled: true - path: /h2 server: port: 8080 tomcat: max-threads: 50 -mso: - site-name: localSite -#Actuator -management: - security: - enabled: false - basic: - enabled: false - 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. +mso: + site-name: unknown + logPath: ./logs/vfc/ +spring: + datasource: + 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: + dialect: org.hibernate.dialect.MySQL5Dialect + ddl-auto: validate + naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy + enable-lazy-load-no-trans: true +#Actuator +management: + context-path: /manage diff --git a/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/exceptions/ApplicationExceptionTest.java b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/exceptions/ApplicationExceptionTest.java index ec3741dc1a..efd3359821 100644 --- a/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/exceptions/ApplicationExceptionTest.java +++ b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/exceptions/ApplicationExceptionTest.java @@ -25,13 +25,13 @@ import static org.junit.Assert.*; import org.junit.Test; public class ApplicationExceptionTest { - private ApplicationException application = new ApplicationException(0,null); + private ApplicationException application = new ApplicationException(500,null); @Test public void testApplicationException() { - application.setErrorCode(0); + application.setErrorCode(500); application.setErrorMsg("ErrorMsg"); - assertEquals(application.getErrorCode(), 0); + assertEquals(application.getErrorCode(), 500); assertEquals(application.getErrorMsg(), "ErrorMsg"); } diff --git a/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/EmbeddedMariaDbConfig.java b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/EmbeddedMariaDbConfig.java new file mode 100644 index 0000000000..e5324d348a --- /dev/null +++ b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/EmbeddedMariaDbConfig.java @@ -0,0 +1,102 @@ +/*- + * ============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 org.onap.so.adapters.vfc.rest; +import ch.vorburger.exec.ManagedProcessException; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; +import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService; + +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +@Configuration +@Profile({"test"}) +@EnableTransactionManagement +@EnableJpaRepositories( + entityManagerFactoryRef = "requestEntityManagerFactory",transactionManagerRef = "requestTransactionManager", + basePackages = { "org.onap.so.db.request.data.repository"} + ) +public class EmbeddedMariaDbConfig { + + @Bean + MariaDB4jSpringService mariaDB4jSpringService() { + return new MariaDB4jSpringService(); + } + + @Primary + @Bean(name = "requestDataSource") + @ConfigurationProperties(prefix = "spring.datasource") + DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService, + @Value("${mariaDB4j.databaseName}") String databaseName, + @Value("${spring.datasource.username}") String datasourceUsername, + @Value("${spring.datasource.password}") String datasourcePassword, + @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException { + //Create our database with default root user and no password + mariaDB4jSpringService.getDB().createDB(databaseName); + + DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration(); + + return DataSourceBuilder + .create() + .username(datasourceUsername) + .password(datasourcePassword) + .url(config.getURL(databaseName)) + .driverClassName(datasourceDriver) + .build(); + } + + @Primary + @Bean(name = "requestEntityManagerFactory") + public LocalContainerEntityManagerFactoryBean + entityManagerFactory( + EntityManagerFactoryBuilder builder, + @Qualifier("requestDataSource") DataSource dataSource + ) { + return builder + .dataSource(dataSource) + .packages("org.onap.so.db.request.beans") + .persistenceUnit("requestDB") + .build(); + } + + @Primary + @Bean(name = "requestTransactionManager") + public PlatformTransactionManager transactionManager( + @Qualifier("requestEntityManagerFactory") EntityManagerFactory + entityManagerFactory + ) { + return new JpaTransactionManager(entityManagerFactory); + } +} diff --git a/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/HealthCheckHandlerTest.java b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/HealthCheckHandlerTest.java new file mode 100644 index 0000000000..10fa02a1d1 --- /dev/null +++ b/adapters/mso-vfc-adapter/src/test/java/org/onap/so/adapters/vfc/rest/HealthCheckHandlerTest.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 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 org.onap.so.adapters.vfc.rest; + +import static org.junit.Assert.*; + + + +import javax.ws.rs.core.Response; + +import org.json.JSONException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.vfc.MSOVfcApplication; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = MSOVfcApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class HealthCheckHandlerTest { + + @LocalServerPort + private int port; + + TestRestTemplate restTemplate = new TestRestTemplate(); + + HttpHeaders headers = new HttpHeaders(); + + + @Test + public void testHealthcheck() throws JSONException { + + HttpEntity entity = new HttpEntity(null, headers); + + ResponseEntity response = restTemplate.exchange( + createURLWithPort("manage/health"), + HttpMethod.GET, entity, String.class); + + assertEquals(Response.Status.OK.getStatusCode(),response.getStatusCode().value()); + } + + private String createURLWithPort(String uri) { + return "http://localhost:" + port + uri; + } +} diff --git a/adapters/mso-vfc-adapter/src/test/resources/application-test.yaml b/adapters/mso-vfc-adapter/src/test/resources/application-test.yaml index ab5fa612eb..64de62c2d6 100644 --- a/adapters/mso-vfc-adapter/src/test/resources/application-test.yaml +++ b/adapters/mso-vfc-adapter/src/test/resources/application-test.yaml @@ -1,6 +1,51 @@ + +server: + port: 8080 + tomcat: + max-threads: 50 +ssl-enable: false mso: + logPath: logs site-name: localSite - msb-ip: "127.0.0.1" - msb-port: 8080 + infra-requests: + archived: + period: 1 +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: test + password: '$2a$12$Zi3AuYcZoZO/gBQyUtST2.F5N6HqcTtaNci2Et.ufsQhski56srIu' + role: BPEL-Client +mariaDB4j: + dataDir: + port: 3307 + databaseName: requestdb +#Actuator +management: + security: + enabled: false + basic: + enabled: false +flyway: + baseline-on-migrate: false + url: jdbc:mariadb://localhost:3307/requestdb + user: root + password: password -- cgit 1.2.3-korg