diff options
Diffstat (limited to 'adapters/mso-vfc-adapter/src/main/java/org')
8 files changed, 190 insertions, 81 deletions
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.<Object>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/application/MSOVfcApplication.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/MSOVfcApplication.java index c6d141391d..5bb83a7c1b 100644 --- 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/MSOVfcApplication.java @@ -18,19 +18,18 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc.application; +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"}) -@EnableJpaRepositories({"org.onap.so.db.request.data.repository"}) -@EntityScan({"org.onap.so.db.request.beans"}) public class MSOVfcApplication { public static void main(String... 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/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/AaiUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/onap/so/adapters/vfc/rest/AaiUtil.java index a4f05158a8..6ae2ba0aca 100644 --- 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/rest/AaiUtil.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc; +package org.onap.so.adapters.vfc.rest; import org.onap.so.adapters.vfc.model.RestfulResponse; 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/rest/HealthCheckHandler.java index 8fcf315641..c39a165338 100644 --- 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/rest/HealthCheckHandler.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc; +package org.onap.so.adapters.vfc.rest; import javax.ws.rs.HEAD; import javax.ws.rs.Path; 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/rest/VfcAdapterRest.java index e07753b33a..9489ef14f5 100644 --- 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/rest/VfcAdapterRest.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc; +package org.onap.so.adapters.vfc.rest; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -28,7 +28,6 @@ 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; 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/rest/VfcManager.java index 47d3842c03..2dbc444bc3 100644 --- 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/rest/VfcManager.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.adapters.vfc; +package org.onap.so.adapters.vfc.rest; import java.util.HashMap; import java.util.Map; @@ -48,6 +48,7 @@ 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; @@ -60,6 +61,7 @@ import org.springframework.stereotype.Component; * @version ONAP Amsterdam Release 2017-08-28 */ @Component +@Primary public class VfcManager { private static final Logger LOGGER = LoggerFactory.getLogger(VfcManager.class); @@ -67,25 +69,23 @@ public class VfcManager { /** * nfvo url map */ - private static Map<String, String> nfvoUrlMap; + private Map<String, String> 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() { - + + 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); } /** |