From a3c9519d6aa7eb8e1f450a7d041047f2c0a5cc07 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Fri, 17 Aug 2018 19:45:00 +0000 Subject: Controller Blueprints Microservice Restcontroller Swagger Implementation with Embeded jar for Controller Bluprints MS Change-Id: I0c0a33f0e29dad0d4aa703e3e381068b510e57d4 Issue-ID: CCSDK-468 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../application/src/assembly/distribution.xml | 8 -- .../ControllerBluprintsApplication.java | 8 +- .../ControllerBluprintsFilterConfiguration.java | 37 -------- .../apps/controllerblueprints/CorsConfig.java | 22 ++--- .../controllerblueprints/JerseyConfiguration.java | 102 --------------------- .../apps/controllerblueprints/SwaggerConfig.java | 70 ++++++++++++++ .../ccsdk/apps/controllerblueprints/WebConfig.java | 37 ++++++++ .../controllerblueprints/WebMvcConfiguration.java | 37 -------- .../ControllerBluprintsApplicationTest.java | 3 +- .../src/test/resources/application.properties | 45 --------- .../application/src/test/resources/logback.xml | 36 ++++++++ 11 files changed, 161 insertions(+), 244 deletions(-) delete mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsFilterConfiguration.java delete mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java create mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java create mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebConfig.java delete mode 100644 ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebMvcConfiguration.java create mode 100644 ms/controllerblueprints/application/src/test/resources/logback.xml (limited to 'ms/controllerblueprints/application/src') diff --git a/ms/controllerblueprints/application/src/assembly/distribution.xml b/ms/controllerblueprints/application/src/assembly/distribution.xml index adfb52d10..c58c20d78 100644 --- a/ms/controllerblueprints/application/src/assembly/distribution.xml +++ b/ms/controllerblueprints/application/src/assembly/distribution.xml @@ -27,14 +27,6 @@ /opt/app/onap/lib - org.slf4j:slf4j-log4j12 - javax.servlet:servlet-api - javax.servlet:javax.servlet-api - j2ee:j2ee - log4j:log4j - com.sun:j2ee - log4j:apache-log4j-extras - org.slf4j:slf4j-simple diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplication.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplication.java index 96d82e7e4..447e1966d 100644 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplication.java +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplication.java @@ -16,22 +16,26 @@ package org.onap.ccsdk.apps.controllerblueprints; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; +import org.springframework.web.reactive.config.EnableWebFlux; /** - * - * * @author Brinda Santh */ @SpringBootApplication +@EnableWebFlux @ComponentScan(basePackages = {"org.onap.ccsdk.apps.controllerblueprints"}) @EnableAutoConfiguration public class ControllerBluprintsApplication { + private static EELFLogger log = EELFManager.getInstance().getLogger(ControllerBluprintsApplication.class); public static void main(String[] args) { + log.info("****** Starting Controller Bluprints Application **************"); SpringApplication.run(ControllerBluprintsApplication.class, args); } diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsFilterConfiguration.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsFilterConfiguration.java deleted file mode 100644 index 6f4bfc988..000000000 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsFilterConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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. - */ - -package org.onap.ccsdk.apps.controllerblueprints; - - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; -/** - * - * - * @author Brinda Santh - */ -@Configuration -public class ControllerBluprintsFilterConfiguration { - private static Logger log = LoggerFactory.getLogger(JerseyConfiguration.class); - - @Value("${server.routingPath:#{null}}") - private String routingPath; - - -} diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java index 0d9ab1623..5d682ed50 100644 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/CorsConfig.java @@ -1,17 +1,17 @@ /* - * Copyright © 2017-2018 AT&T Intellectual Property. + * Copyright © 2017-2018 AT&T Intellectual Property. * - * 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 + * 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 + * 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. + * 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. */ package org.onap.ccsdk.apps.controllerblueprints; @@ -29,7 +29,7 @@ import org.springframework.web.filter.CorsFilter; * @author Brinda Santh * @version 1.0 */ -@Configuration +//@Configuration public class CorsConfig { /** * This is a CORS Implementation for different Orgin GUI to access. diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java deleted file mode 100644 index a3b0faf0c..000000000 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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. - */ - -package org.onap.ccsdk.apps.controllerblueprints; - - -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.MapperFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import io.swagger.jaxrs.config.BeanConfig; -import io.swagger.jaxrs.listing.ApiListingResource; -import io.swagger.jaxrs.listing.SwaggerSerializers; -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.servlet.ServletProperties; -import org.onap.ccsdk.apps.controllerblueprints.service.common.ServiceExceptionMapper; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ConfigModelRestImpl; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ModelTypeRestImpl; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ResourceDictionaryRestImpl; -import org.onap.ccsdk.apps.controllerblueprints.service.rs.ServiceTemplateRestImpl; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - -import javax.ws.rs.core.MediaType; - -/** - * - * - * @author Brinda Santh - */ -@Component -public class JerseyConfiguration extends ResourceConfig { - private static Logger log = LoggerFactory.getLogger(JerseyConfiguration.class); - /** - * - */ - @Autowired - public JerseyConfiguration() { - register(ConfigModelRestImpl.class); - register(ModelTypeRestImpl.class); - register(ResourceDictionaryRestImpl.class); - register(ServiceTemplateRestImpl.class); - register(ServiceExceptionMapper.class); - property(ServletProperties.FILTER_FORWARD_ON_404, true); - configureSwagger(); - } - - /** - * - * @return ObjectMapper - */ - @Bean - @Primary - public ObjectMapper objectMapper() { - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); - objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); - objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); - objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); - return objectMapper; - } - - /** - * - */ - private void configureSwagger() { - register(ApiListingResource.class); - register(SwaggerSerializers.class); - BeanConfig beanConfig = new BeanConfig(); - beanConfig.setVersion("1.0.0"); - beanConfig.setSchemes(new String[]{"http", "https"}); - beanConfig.setBasePath("/api/controller-blueprints/v1"); - beanConfig.setTitle("Controller Blueprints API"); - beanConfig.setDescription("Controller BluePrints API"); - beanConfig.getSwagger().addConsumes(MediaType.APPLICATION_JSON); - beanConfig.getSwagger().addProduces(MediaType.APPLICATION_JSON); - beanConfig.setResourcePackage("org.onap.ccsdk.apps.controllerblueprints"); - beanConfig.setPrettyPrint(true); - beanConfig.setScan(true); - } - - -} \ No newline at end of file diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java new file mode 100644 index 000000000..5970bafde --- /dev/null +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/SwaggerConfig.java @@ -0,0 +1,70 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.service.Contact; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; +import springfox.documentation.swagger2.annotations.EnableSwagger2; + +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +/** + * SwaggerConfig + * + * @author Brinda Santh 8/13/2018 + */ +@Configuration +@EnableSwagger2 +public class SwaggerConfig { + private static final Set DEFAULT_PRODUCES_AND_CONSUMES = + new HashSet(Arrays.asList("application/json", + "application/xml")); + private static Logger log = LoggerFactory.getLogger(SwaggerConfig.class); + + @Bean + public Docket api() { + return new Docket(DocumentationType.SWAGGER_2) + .select() + .apis(RequestHandlerSelectors.any()) + .paths(PathSelectors.any()) + .build() + .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo() { + return new ApiInfo( + "Controller Blueprints API", + "Controller blueprints API for VNF Self Service.", + "1.0.0", + "Terms of service", + new Contact("Brinda Santh", "www.onap.com", "brindasanth@onap.com"), + "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0", Collections.emptyList()); + } + + +} diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebConfig.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebConfig.java new file mode 100644 index 000000000..1eba97cdc --- /dev/null +++ b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebConfig.java @@ -0,0 +1,37 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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. + */ + +package org.onap.ccsdk.apps.controllerblueprints; + +import org.springframework.context.annotation.Configuration; +import org.springframework.web.reactive.config.ResourceHandlerRegistry; +import org.springframework.web.reactive.config.WebFluxConfigurationSupport; + +/** + * WebConfig + * + * @author Brinda Santh 8/13/2018 + */ +@Configuration +public class WebConfig extends WebFluxConfigurationSupport { + public void addResourceHandlers(ResourceHandlerRegistry registry) { + registry.addResourceHandler("swagger-ui.html") + .addResourceLocations("classpath:/META-INF/resources/"); + + registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + } +} diff --git a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebMvcConfiguration.java b/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebMvcConfiguration.java deleted file mode 100644 index a690c056c..000000000 --- a/ms/controllerblueprints/application/src/main/java/org/onap/ccsdk/apps/controllerblueprints/WebMvcConfiguration.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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. - */ - -package org.onap.ccsdk.apps.controllerblueprints; - -import org.springframework.context.annotation.Configuration; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; - -/** - * - * WebMvcConfiguration WebMvcConfiguration - * @author Brinda Santh - */ -@Configuration -@EnableWebMvc -public class WebMvcConfiguration extends WebMvcConfigurerAdapter { - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/swagger-ui/**").addResourceLocations("classpath:/swagger-ui/dist/"); - } - -} diff --git a/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java b/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java index 4bdbde008..95639bd32 100644 --- a/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java +++ b/ms/controllerblueprints/application/src/test/java/org/onap/ccsdk/apps/controllerblueprints/ControllerBluprintsApplicationTest.java @@ -46,9 +46,8 @@ public class ControllerBluprintsApplicationTest { @Test public void testConfigModel() { - ResponseEntity entity = this.restTemplate - .getForEntity("/api/controller-blueprints/v1/service/configmodel/1", String.class); + .getForEntity("/api/v1/config-model/1", String.class); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } } diff --git a/ms/controllerblueprints/application/src/test/resources/application.properties b/ms/controllerblueprints/application/src/test/resources/application.properties index c6057e563..55ffeaf16 100644 --- a/ms/controllerblueprints/application/src/test/resources/application.properties +++ b/ms/controllerblueprints/application/src/test/resources/application.properties @@ -14,51 +14,6 @@ # limitations under the License. # -info.build.artifact=@project.artifactId@ -info.build.name=@project.name@ -info.build.description=@project.description@ -info.build.version=@project.version@ -info.build.groupId=@project.groupId@ -logging.level.root=info - -server.contextPath=/ -server.servlet-path=/ -spring.jersey.application-path=/api/controller-blueprints/v1 -server.routingPath=/api - -mots.application.acronym=MOTS_ID -platform.identifier=AJSC7_JERSEY -#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration,org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration - -#logging.pattern.console=%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(%5p) %clr($ threadId: {PID:- }){magenta} %clr(---){faint} %clr([ hostname: %X{hostname} serviceName: %X{serviceName} version: %X{version} transactionId: %X{transactionId} requestTimeStamp: %X{requestTimestamp} responseTimeStamp: %X{responseTimestamp} duration: %X{duration}]){yellow} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n%wex - -#The max number of active threads in this pool -server.tomcat.max-threads=200 -#The minimum number of threads always kept alive -server.tomcat.min-Spare-Threads=25 -#The number of milliseconds before an idle thread shutsdown, unless the number of active threads are less or equal to minSpareThreads -server.tomcat.max-idle-time=60000 - -#for changing the tomcat port... -#server.port=8081 - -#Servlet context parameters -server.context_parameters.p-name=value #context parameter with p-name as key and value as value. - -# make this true for AAF authentication and place cadi.properties into etc folder -aaf.enabled=false - -# set to true to enable version proxy -#ivp.enabled=false - -logging.level.org.springframework.web=INFO -logging.level.org.hibernate.SQL=warn -logging.level.org.hibernate.type.descriptor.sql=debug - -spring.jpa.properties.hibernate.show_sql=true -spring.jpa.properties.hibernate.use_sql_comments=true -spring.jpa.properties.hibernate.format_sql=true - #Load Blueprints # blueprints.load.initial-data may be overridden by ENV variables blueprints.load.initial-data=true diff --git a/ms/controllerblueprints/application/src/test/resources/logback.xml b/ms/controllerblueprints/application/src/test/resources/logback.xml new file mode 100644 index 000000000..b9b97dc89 --- /dev/null +++ b/ms/controllerblueprints/application/src/test/resources/logback.xml @@ -0,0 +1,36 @@ + + + + + + + %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n + + + + + + + + + + + + + + -- cgit 1.2.3-korg