X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=aai-service%2Fprovider%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fccsdk%2Fsli%2Fadaptors%2Faai%2FAAIService.java;h=4d51550a3eb5439056d348c78d377cf9dbf1d553;hb=4ba6431d471aa47f3f31b756a4e46c646a938f15;hp=bfed619c66a7421db076c90465edce42c43078db;hpb=3547d659591f07e9e5405462818cb4f776009e76;p=ccsdk%2Fsli%2Fadaptors.git diff --git a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java index bfed619c..4d51550a 100755 --- a/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java +++ b/aai-service/provider/src/main/java/org/onap/ccsdk/sli/adaptors/aai/AAIService.java @@ -5,6 +5,8 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights * reserved. * ================================================================================ + * Modifications Copyright (C) 2019 IBM. + * ================================================================================ * 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 @@ -18,10 +20,12 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - +/** + * @author Rich Tabedzki + * + */ package org.onap.ccsdk.sli.adaptors.aai; - import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; @@ -77,11 +81,12 @@ import org.onap.ccsdk.sli.core.sli.MetricLogger; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; import org.onap.ccsdk.sli.core.sli.SvcLogicException; import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.aai.inventory.v14.GenericVnf; -import org.onap.aai.inventory.v14.PhysicalLink; -import org.onap.aai.inventory.v14.ResultData; -import org.onap.aai.inventory.v14.SearchResults; -import org.onap.aai.inventory.v14.Vserver; +import org.onap.aai.inventory.v21.GenericVnf; +import org.onap.aai.inventory.v21.PhysicalLink; +import org.onap.aai.inventory.v21.ResultData; +import org.onap.aai.inventory.v21.SearchResults; +import org.onap.aai.inventory.v21.Vserver; +import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -93,8 +98,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector; import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector; -import com.sun.jersey.api.client.config.DefaultClientConfig; -import com.sun.jersey.client.urlconnection.HTTPSProperties; public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicResource { @@ -113,7 +116,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe private final String targetUri; private final String networkVserverPath; - private final String svc_inst_qry_path; + private final String svc_inst_query_path; private final String ubb_notify_path; private final String selflinkAvpn; @@ -147,16 +150,6 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe this(getProperties(url)); } - private static Properties getProperties(URL url) { - Properties properties = new Properties(); - try { - properties.load(url.openStream()); - } catch (IOException exc) { - LOG.error("getProperties", exc); - } - return properties; - } - public AAIService(Properties props) { LOG.info("Entered AAIService.ctor"); @@ -222,11 +215,9 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe networkVserverPath =props.getProperty(NETWORK_VSERVER_PATH); props.getProperty(SVC_INSTANCE_PATH); - svc_inst_qry_path = props.getProperty(SVC_INST_QRY_PATH); + svc_inst_query_path = props.getProperty(SVC_INST_QRY_PATH); props.getProperty(PARAM_SERVICE_TYPE, "service-type"); - props.getProperty(P_INTERFACE_PATH); - props.getProperty(VNF_IMAGE_QUERY_PATH); ubb_notify_path = props.getProperty(UBB_NOTIFY_PATH); @@ -259,7 +250,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe } if(keystorePath != null && keystorePassword != null && (new File(keystorePath)).exists()) { - DefaultClientConfig config = new DefaultClientConfig(); + //DefaultClientConfig config = new DefaultClientConfig(); //both jersey and HttpURLConnection can use this SSLContext ctx = null; try { @@ -285,13 +276,16 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe LOG.error("AAIResource", ex); } - ctx.init(kmf.getKeyManagers(), null, null); - config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties( new HostnameVerifier() { - @Override - public boolean verify( String s, SSLSession sslSession ) { - return ignoreCertificateHostError; - } - }, ctx)); + if(null!=kmf) { + ctx.init(kmf.getKeyManagers(), null, null); + } + /* + * config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new + * HTTPSProperties( new HostnameVerifier() { + * + * @Override public boolean verify( String s, SSLSession sslSession ) { return + * ignoreCertificateHostError; } }, ctx)); + */ CTX = ctx; LOG.debug("SSLContext created"); @@ -322,11 +316,21 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe methodsField.set(null, methods); } catch (SecurityException | IllegalArgumentException | IllegalAccessException | NoSuchFieldException e) { - e.printStackTrace(); + LOG.error("Exception occured", e); } } + private static Properties getProperties(URL url) { + Properties properties = new Properties(); + try { + properties.load(url.openStream()); + } catch (IOException exc) { + LOG.error("getProperties", exc); + } + return properties; + } + public void setExecutor(AAIExecutorInterface executor) { this.executor = executor; } @@ -360,7 +364,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe String mlId = ml.getRequestID(); if(mlId != null && !mlId.isEmpty()) { LOG.debug(String.format("MetricLogger requestId = %s", mlId)); - con.setRequestProperty(MetricLogger.REQUEST_ID, mlId); + con.setRequestProperty(ONAPLogConstants.MDCs.REQUEST_ID, mlId); } else { LOG.debug("MetricLogger requestId is null"); } @@ -424,7 +428,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe InputStream inputStream = null; try { - String path = svc_inst_qry_path; + String path = svc_inst_query_path; path = path.replace("{svc-instance-id}", encodeQuery(svc_instance_id)); String request_url = targetUri+path; @@ -472,6 +476,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe try { inputStream.close(); } catch(Exception exc) { + LOG.warn("Error closing Inputstream", exc); } } } @@ -727,7 +732,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe try { inputStream.close(); } catch(Exception exc) { - + LOG.warn("Error closing InputStream", exc); } } } @@ -844,7 +849,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe if(inputStream != null) inputStream.close(); } catch (Exception exc) { - + LOG.warn("Error closing Input stream", exc); } } } @@ -904,7 +909,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe try { inputStream.close(); } catch(Exception exc) { - + LOG.warn("Error closing Input stream", exc); } } } @@ -974,7 +979,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe try { inputStream.close(); } catch(Exception exc) { - + LOG.warn("Error closing Input stream", exc); } } } @@ -1206,12 +1211,14 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe try { u = new URL(url); } catch (MalformedURLException e) { + LOG.warn("MalformedURLException", e); return false; } try { u.toURI(); } catch (URISyntaxException e) { + LOG.warn("URISyntaxException", e); return false; } @@ -1226,6 +1233,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe try { u = new URI(url); } catch (URISyntaxException e) { + LOG.warn("URISyntaxException", e); return false; } @@ -1233,7 +1241,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe } - protected boolean deleteList(URL httpReqUrl, String json_text) throws AAIServiceException { + protected boolean deleteList(URL httpReqUrl, String jsonText) throws AAIServiceException { if(httpReqUrl == null) { throw new NullPointerException(); } @@ -1246,15 +1254,15 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe // SSLSocketFactory sockFact = CTX.getSocketFactory(); // con.setSSLSocketFactory( sockFact ); - if (json_text != null) { + if (jsonText != null) { OutputStreamWriter osw = new OutputStreamWriter(con.getOutputStream()); - osw.write(json_text); + osw.write(jsonText); osw.flush(); osw.close(); } LOGwriteFirstTrace("DELETE", httpReqUrl.toString()); - LOGwriteDateTrace("data", json_text); + LOGwriteDateTrace("data", jsonText); // Check for errors int responseCode = con.getResponseCode(); @@ -1348,7 +1356,6 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe case "custom-query": case "formatted-query": case "generic-query": - case "named-query": case "nodes-query": case "linterface": case "l2-bridge-sbg": @@ -1377,7 +1384,6 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe case "custom-query": case "formatted-query": case "generic-query": - case "named-query": case "nodes-query": case "linterface": case "l2-bridge-sbg": @@ -1406,7 +1412,6 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe case "custom-query": case "formatted-query": case "generic-query": - case "named-query": case "nodes-query": case "linterface": case "l2-bridge-sbg": @@ -1435,7 +1440,6 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe case "custom-query": case "formatted-query": case "generic-query": - case "named-query": case "nodes-query": case "linterface": case "l2-bridge-sbg":