From f744247f2b725152d4959eb6fe4cb59d9d7223d7 Mon Sep 17 00:00:00 2001 From: "Determe, Sebastien (sd378r)" Date: Fri, 3 Aug 2018 15:52:19 +0200 Subject: Restore Swagger Restore swagger generation at runtime, + Clamp versioning rework + log level set differently Issue-ID: CLAMP-169 Change-Id: Ibf9eedb7028dedc610b36546f57ee5b3095cd20d Signed-off-by: Determe, Sebastien (sd378r) --- src/main/java/org/onap/clamp/clds/Application.java | 3 +- .../onap/clamp/clds/config/CamelConfiguration.java | 17 +- .../onap/clamp/clds/service/CldsInfoProvider.java | 30 +- .../org/onap/clamp/clds/service/CldsService.java | 6 +- .../org/onap/clamp/clds/util/ClampVersioning.java | 57 ++ src/main/resources/META-INF/resources/swagger.html | 913 +++++++-------------- src/main/resources/application-noaaf.properties | 2 +- src/main/resources/application.properties | 2 +- src/main/resources/logback.xml | 26 +- .../java/org/onap/clamp/clds/it/HttpsItCase.java | 53 +- src/test/resources/application.properties | 8 +- src/test/resources/https/https-test.properties | 18 +- 12 files changed, 451 insertions(+), 684 deletions(-) create mode 100644 src/main/java/org/onap/clamp/clds/util/ClampVersioning.java (limited to 'src') diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java index fd5deb91..0eb48075 100644 --- a/src/main/java/org/onap/clamp/clds/Application.java +++ b/src/main/java/org/onap/clamp/clds/Application.java @@ -26,10 +26,10 @@ package org.onap.clamp.clds; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import org.apache.camel.component.servlet.CamelHttpTransportServlet; import org.apache.catalina.connector.Connector; import org.onap.clamp.clds.model.properties.Holmes; import org.onap.clamp.clds.model.properties.ModelProperties; +import org.onap.clamp.clds.util.ClampVersioning; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -85,6 +85,7 @@ public class Application extends SpringBootServletInitializer { } public static void main(String[] args) { + EELF_LOGGER.info("Starting :: CLAMP :: (v"+ ClampVersioning.getCldsVersionFromProps()+")"); // This is to initialize some Onap Clamp components initializeComponents(); // Start the Spring application diff --git a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java index 16cbd840..c80fd0ec 100644 --- a/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java +++ b/src/main/java/org/onap/clamp/clds/config/CamelConfiguration.java @@ -20,9 +20,10 @@ * =================================================================== */ package org.onap.clamp.clds.config; + import org.apache.camel.builder.RouteBuilder; import org.apache.camel.model.rest.RestBindingMode; -import org.onap.clamp.clds.model.CldsInfo; +import org.onap.clamp.clds.util.ClampVersioning; import org.springframework.stereotype.Component; @Component @@ -30,11 +31,13 @@ public class CamelConfiguration extends RouteBuilder { @Override public void configure() { - restConfiguration().component("servlet") - .bindingMode(RestBindingMode.json); - - rest("/clds") - .get("/test").description("Find user by id").outType(CldsInfo.class).produces("application/json") - .to("bean:org.onap.clamp.clds.service.CldsService?method=getCldsInfo()") ; + restConfiguration().component("servlet").bindingMode(RestBindingMode.json) + .dataFormatProperty("prettyPrint", "true")//.enableCORS(true) + // turn on swagger api-doc + .apiContextPath("api-doc") + .apiVendorExtension(true) + .apiProperty("api.title", "Clamp Rest API").apiProperty("api.version", ClampVersioning.getCldsVersionFromProps()) + .apiProperty("base.path", "/restservices/clds/v1/"); + //.apiProperty("cors", "true"); } } diff --git a/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java b/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java index 66890aa1..6bebde92 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsInfoProvider.java @@ -24,30 +24,22 @@ package org.onap.clamp.clds.service; -import static org.onap.clamp.clds.service.CldsService.RESOURCE_NAME; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import java.io.InputStream; -import java.util.Properties; import org.onap.clamp.clds.model.CldsInfo; -import org.onap.clamp.clds.util.ResourceFileUtil; +import org.onap.clamp.clds.util.ClampVersioning; class CldsInfoProvider { - private static final String CLDS_VERSION = "clds.version"; - private final CldsService cldsService; - private final EELFLogger logger = EELFManager.getInstance().getLogger(CldsInfoProvider.class); + private final CldsService cldsService; - CldsInfoProvider(CldsService cldsService) { + public CldsInfoProvider(CldsService cldsService) { this.cldsService = cldsService; } - CldsInfo getCldsInfo(){ + public CldsInfo getCldsInfo() { CldsInfo cldsInfo = new CldsInfo(); cldsInfo.setUserName(cldsService.getUserName()); - cldsInfo.setCldsVersion(getCldsVersionFromProps()); + cldsInfo.setCldsVersion(ClampVersioning.getCldsVersionFromProps()); cldsInfo.setPermissionReadCl(cldsService.isAuthorizedNoException(cldsService.permissionReadCl)); cldsInfo.setPermissionUpdateCl(cldsService.isAuthorizedNoException(cldsService.permissionUpdateCl)); @@ -55,16 +47,4 @@ class CldsInfoProvider { cldsInfo.setPermissionUpdateTemplate(cldsService.isAuthorizedNoException(cldsService.permissionUpdateTemplate)); return cldsInfo; } - - private String getCldsVersionFromProps() { - String cldsVersion = ""; - Properties props = new Properties(); - try (InputStream resourceStream = ResourceFileUtil.getResourceAsStream(RESOURCE_NAME)) { - props.load(resourceStream); - cldsVersion = props.getProperty(CLDS_VERSION); - } catch (Exception ex) { - logger.error("Exception caught during the clds.version reading", ex); - } - return cldsVersion; - } } diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java index d6fbde35..74c78aee 100644 --- a/src/main/java/org/onap/clamp/clds/service/CldsService.java +++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java @@ -36,10 +36,11 @@ import java.util.Date; import java.util.List; import java.util.Optional; import java.util.UUID; + import javax.ws.rs.BadRequestException; +import javax.ws.rs.NotAuthorizedException; import javax.xml.transform.TransformerException; - import org.apache.camel.Produce; import org.apache.commons.codec.DecoderException; import org.apache.commons.lang3.StringUtils; @@ -50,7 +51,6 @@ import org.onap.clamp.clds.client.DcaeInventoryServices; import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices; import org.onap.clamp.clds.config.ClampProperties; import org.onap.clamp.clds.dao.CldsDao; - import org.onap.clamp.clds.exception.CldsConfigException; import org.onap.clamp.clds.exception.policy.PolicyClientException; import org.onap.clamp.clds.exception.sdc.SdcCommunicationException; @@ -89,7 +89,7 @@ public class CldsService extends SecureServiceBase { @Produce(uri = "direct:processSubmit") private CamelProxy camelProxy; protected static final EELFLogger securityLogger = EELFManager.getInstance().getSecurityLogger(); - static final String RESOURCE_NAME = "clds-version.properties"; + public static final String GLOBAL_PROPERTIES_KEY = "files.globalProperties"; private final String cldsPersmissionTypeCl; private final String cldsPermissionTypeClManage; diff --git a/src/main/java/org/onap/clamp/clds/util/ClampVersioning.java b/src/main/java/org/onap/clamp/clds/util/ClampVersioning.java new file mode 100644 index 00000000..06330091 --- /dev/null +++ b/src/main/java/org/onap/clamp/clds/util/ClampVersioning.java @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 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============================================ + * Modifications copyright (c) 2018 Nokia + * =================================================================== + * + */ + +package org.onap.clamp.clds.util; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +import java.io.InputStream; +import java.util.Properties; + +/** + * This class give a way to know the Clamp version easily, the version in that + * file is set by maven at build time. + * + */ +public class ClampVersioning { + private static final String RESOURCE_NAME = "clds-version.properties"; + private static final String CLDS_VERSION_PROPERTY = "clds.version"; + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ClampVersioning.class); + + private ClampVersioning() { + } + + public static String getCldsVersionFromProps() { + String cldsVersion = ""; + Properties props = new Properties(); + try (InputStream resourceStream = ResourceFileUtil.getResourceAsStream(RESOURCE_NAME)) { + props.load(resourceStream); + cldsVersion = props.getProperty(CLDS_VERSION_PROPERTY); + } catch (Exception ex) { + LOGGER.error("Exception caught during the "+CLDS_VERSION_PROPERTY+" property reading", ex); + } + return cldsVersion; + } +} diff --git a/src/main/resources/META-INF/resources/swagger.html b/src/main/resources/META-INF/resources/swagger.html index d5d2832f..e4d45de1 100644 --- a/src/main/resources/META-INF/resources/swagger.html +++ b/src/main/resources/META-INF/resources/swagger.html @@ -4,8 +4,8 @@ - -clamp + +Clamp Rest API