diff options
Diffstat (limited to 'src')
3 files changed, 140 insertions, 81 deletions
diff --git a/src/main/java/org/onap/sdc/dcae/FeApp.java b/src/main/java/org/onap/sdc/dcae/FeApp.java index c2e3bc9..7463c63 100644 --- a/src/main/java/org/onap/sdc/dcae/FeApp.java +++ b/src/main/java/org/onap/sdc/dcae/FeApp.java @@ -1,3 +1,22 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 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.sdc.dcae; import org.onap.sdc.dcae.controller.proxy.DcaeProxyOld; @@ -8,7 +27,10 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.boot.web.support.SpringBootServletInitializer; -import org.springframework.context.annotation.*; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; import javax.servlet.ServletContext; import java.io.IOException; @@ -21,50 +43,50 @@ import java.util.jar.Manifest; @ComponentScan() @EnableAutoConfiguration @PropertySource("file:${jetty.base}/config/dcae-dt/application.properties") -public class FeApp extends SpringBootServletInitializer implements CommandLineRunner{ +public class FeApp extends SpringBootServletInitializer implements CommandLineRunner { - private static final String SPECIFICATION_VERSION = "Specification-Version"; - @Autowired - ServletContext servletContext; + private static final String SPECIFICATION_VERSION = "Specification-Version"; + @Autowired + private ServletContext servletContext; - private static final String MANIFEST_FILE_NAME = "/META-INF/MANIFEST.MF"; - private static String dcaeVersion; + private static final String MANIFEST_FILE_NAME = "/META-INF/MANIFEST.MF"; + private static String dcaeVersion; @Value("${newFeUrl}") - private String newFeUrl; + private String newFeUrl; @Value("${newFeContextPath}") - private String newFeContextPath; + private String newFeContextPath; public static void main(String[] args) { SpringApplication.run(FeApp.class, args); } - public void run(String... arg0) throws Exception { - InputStream inputStream = servletContext.getResourceAsStream(MANIFEST_FILE_NAME); - - System.out.println("Server is starting..reading DCAE version..."); - - String version = null; - try { - Manifest mf = new Manifest(inputStream); - Attributes atts = mf.getMainAttributes(); - version = atts.getValue(SPECIFICATION_VERSION); - if (version == null || version.isEmpty()) { - System.err.println("failed to read DCAE version from MANIFEST."); - } else { - System.out.println("DCAE version from MANIFEST is "+ version); - dcaeVersion = version; - } - - } catch (IOException e) { - System.err.println("failed to read DCAE version from MANIFEST: "+ e.getMessage()); - } - } - - public static String getDcaeVersion() { - return dcaeVersion; - } + public void run(String... arg0) throws Exception { + InputStream inputStream = servletContext.getResourceAsStream(MANIFEST_FILE_NAME); + + System.out.println("Server is starting..reading DCAE version..."); + + String version = null; + try { + Manifest mf = new Manifest(inputStream); + Attributes atts = mf.getMainAttributes(); + version = atts.getValue(SPECIFICATION_VERSION); + if (version == null || version.isEmpty()) { + System.err.println("failed to read DCAE version from MANIFEST."); + } else { + System.out.println("DCAE version from MANIFEST is " + version); + dcaeVersion = version; + } + + } catch (IOException e) { + System.err.println("failed to read DCAE version from MANIFEST: " + e.getMessage()); + } + } + + public static String getDcaeVersion() { + return dcaeVersion; + } @Bean diff --git a/src/main/java/org/onap/sdc/dcae/controller/health/HealthController.java b/src/main/java/org/onap/sdc/dcae/controller/health/HealthController.java index 9086600..1ef27d0 100644 --- a/src/main/java/org/onap/sdc/dcae/controller/health/HealthController.java +++ b/src/main/java/org/onap/sdc/dcae/controller/health/HealthController.java @@ -1,3 +1,22 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 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.sdc.dcae.controller.health; import java.util.ArrayList; @@ -19,54 +38,51 @@ import com.google.gson.Gson; /** - * * @author lezer * Example: * { - "healthCheckComponent": "DCAE Designer", - "healthCheckStatus": "UP", - "description": "OK", - "componentsInfo": [{ - "healthCheckComponent": "FE", - "healthCheckStatus": "UP", - "description": "OK" - }] -} - * + * "healthCheckComponent": "DCAE Designer", + * "healthCheckStatus": "UP", + * "description": "OK", + * "componentsInfo": [{ + * "healthCheckComponent": "FE", + * "healthCheckStatus": "UP", + * "description": "OK" + * }] + * } */ @RestController @EnableAutoConfiguration @CrossOrigin public class HealthController { - Gson gson = new Gson(); + private Gson gson = new Gson(); - @RequestMapping(value = "/healthCheckOld", method = RequestMethod.GET) - public ResponseEntity<String> healthCheck() { - try{ - HealthResponse healthResponse = new HealthResponse(); - healthResponse.setHealthCheckComponent(DcaeFeConstants.Health.APP_NAME); - healthResponse.setHealthCheckStatus(DcaeFeConstants.Health.UP); - healthResponse.setSdcVersion(FeApp.getDcaeVersion()); - healthResponse.setDescription(DcaeFeConstants.Health.OK); + @RequestMapping(value = "/healthCheckOld", method = RequestMethod.GET) + public ResponseEntity<String> healthCheck() { + try { + HealthResponse healthResponse = new HealthResponse(); + healthResponse.setHealthCheckComponent(DcaeFeConstants.Health.APP_NAME); + healthResponse.setHealthCheckStatus(DcaeFeConstants.Health.UP); + healthResponse.setSdcVersion(FeApp.getDcaeVersion()); + healthResponse.setDescription(DcaeFeConstants.Health.OK); - List<ComponentsInfo> componentsInfoList = new ArrayList<ComponentsInfo>(); - ComponentsInfo componentsInfo = new ComponentsInfo(); - componentsInfo.setHealthCheckComponent(DcaeFeConstants.Health.FE); - componentsInfo.setHealthCheckStatus(DcaeFeConstants.Health.UP); - componentsInfo.setVersion(FeApp.getDcaeVersion()); - componentsInfo.setDescription(DcaeFeConstants.Health.OK); - componentsInfoList.add(componentsInfo); + List<ComponentsInfo> componentsInfoList = new ArrayList<ComponentsInfo>(); + ComponentsInfo componentsInfo = new ComponentsInfo(); + componentsInfo.setHealthCheckComponent(DcaeFeConstants.Health.FE); + componentsInfo.setHealthCheckStatus(DcaeFeConstants.Health.UP); + componentsInfo.setVersion(FeApp.getDcaeVersion()); + componentsInfo.setDescription(DcaeFeConstants.Health.OK); + componentsInfoList.add(componentsInfo); - healthResponse.setComponentsInfo(componentsInfoList); - String json = gson.toJson(healthResponse, HealthResponse.class); - System.out.println("Health Check response: "+json); + healthResponse.setComponentsInfo(componentsInfoList); + String json = gson.toJson(healthResponse, HealthResponse.class); + System.out.println("Health Check response: " + json); - return new ResponseEntity<String>(json, HttpStatus.OK); - } - catch(Exception e){ - System.err.println("Error occured while performing HealthCheck: "+e.getLocalizedMessage()); - return new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); - } - } + return new ResponseEntity<String>(json, HttpStatus.OK); + } catch (Exception e) { + System.err.println("Error occured while performing HealthCheck: " + e.getLocalizedMessage()); + return new ResponseEntity<String>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + } } diff --git a/src/main/java/org/onap/sdc/dcae/controller/proxy/DcaeProxyOld.java b/src/main/java/org/onap/sdc/dcae/controller/proxy/DcaeProxyOld.java index cacb092..dbd475e 100644 --- a/src/main/java/org/onap/sdc/dcae/controller/proxy/DcaeProxyOld.java +++ b/src/main/java/org/onap/sdc/dcae/controller/proxy/DcaeProxyOld.java @@ -1,3 +1,22 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2019 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.sdc.dcae.controller.proxy; import com.google.common.cache.Cache; @@ -19,15 +38,16 @@ import java.util.concurrent.TimeUnit; public class DcaeProxyOld extends ProxyServlet { + private static final int EXPIRATION_TIME = 10; + private static final int TIMEOUT = 180000; private static Logger log = LoggerFactory.getLogger(DcaeProxyOld.class); - private static Cache<String, MdcData> mdcDataCache = CacheBuilder.newBuilder().expireAfterWrite(10, TimeUnit.SECONDS).build(); - + private static Cache<String, MdcData> mdcDataCache = CacheBuilder.newBuilder().expireAfterWrite(EXPIRATION_TIME, TimeUnit.SECONDS).build(); //TODO proper configuration class private String newFeUrl; private String newFeContextPath; - public DcaeProxyOld(String newFeUrl, String newFeContextPath){ + public DcaeProxyOld(String newFeUrl, String newFeContextPath) { this.newFeUrl = newFeUrl; this.newFeContextPath = newFeContextPath; } @@ -41,16 +61,16 @@ public class DcaeProxyOld extends ProxyServlet { @Override protected HttpClient createHttpClient() throws ServletException { HttpClient client = super.createHttpClient(); - client.setIdleTimeout(180000); - client.setConnectTimeout(180000); + client.setIdleTimeout(TIMEOUT); + client.setConnectTimeout(TIMEOUT); return client; } @Override protected String rewriteTarget(HttpServletRequest request) { - try{ + try { logRequest(request); - }catch (Exception e){ + } catch (Exception e) { log.error("Unexpected FE request logging error :", e); } String uri = request.getRequestURI(); @@ -59,8 +79,9 @@ public class DcaeProxyOld extends ProxyServlet { String query = request.getQueryString(); StringBuilder url = new StringBuilder(); url.append(newFeUrl).append(uri); - if(null != query) + if (null != query) { url.append("?").append(query); + } String urlString = url.toString(); log.info("Proxy outgoing request={}", urlString); return urlString; @@ -68,9 +89,9 @@ public class DcaeProxyOld extends ProxyServlet { @Override protected void onProxyResponseSuccess(HttpServletRequest clientRequest, HttpServletResponse proxyResponse, Response serverResponse) { - try{ + try { logResponse(clientRequest, serverResponse); - }catch (Exception e){ + } catch (Exception e) { log.error("Unexpected FE response logging error :", e); } super.onProxyResponseSuccess(clientRequest, proxyResponse, serverResponse); |