Deprecated named-query from AAIService
[ccsdk/sli/adaptors.git] / aai-service / provider / src / main / java / org / onap / ccsdk / sli / adaptors / aai / AAIService.java
index 9e6e60f..d315f64 100755 (executable)
@@ -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
  * 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,11 @@ 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.openecomp.aai.inventory.v11.GenericVnf;
-import org.openecomp.aai.inventory.v11.PhysicalLink;
-import org.openecomp.aai.inventory.v11.ResultData;
-import org.openecomp.aai.inventory.v11.SearchResults;
-import org.openecomp.aai.inventory.v11.Vserver;
+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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.slf4j.MDC;
@@ -111,33 +115,19 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
     private final Boolean ignoreCertificateHostError;
 
     private final String targetUri;
-    private final String queryPath;
-
     private final String networkVserverPath;
 
-    private final String svcInstancePath;
-    private final String svc_inst_qry_path;
-
-    private final String vnf_image_query_path;
-
-    private final String param_service_type;            //= "service-type";
+    private final String svc_inst_query_path;
 
     private final String ubb_notify_path;
     private final String selflinkAvpn;
     private final String selflinkFqdn;
 
-    private final String pInterfacePath;
-
-    private final String servicePath;
-    private final String sitePairSetPath;
-
     private final int connectionTimeout;
     private final int readTimeout;
 
     // 1602
     private final String queryNodesPath;
-    private final String updatePath;
-
     private final String applicationId;
 
     // authentication credentials
@@ -161,16 +151,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");
 
@@ -206,8 +186,8 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
         keystorePassword     = props.getProperty(KEYSTORE_PSSWD);
 
         targetUri             = props.getProperty(TARGET_URI);
-        queryPath             = props.getProperty(QUERY_PATH);
-        updatePath         = props.getProperty(UPDATE_PATH);
+        props.getProperty(QUERY_PATH);
+        props.getProperty(UPDATE_PATH);
 
         String tmpApplicationId = props.getProperty(APPLICATION_ID);
         if(tmpApplicationId == null || tmpApplicationId.isEmpty()) {
@@ -235,22 +215,19 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
 
         networkVserverPath =props.getProperty(NETWORK_VSERVER_PATH);
 
-        svcInstancePath    = props.getProperty(SVC_INSTANCE_PATH);
-        svc_inst_qry_path    = props.getProperty(SVC_INST_QRY_PATH);
-        param_service_type     = props.getProperty(PARAM_SERVICE_TYPE, "service-type");
-
-        // P-Interfaces
-        pInterfacePath   = props.getProperty(P_INTERFACE_PATH);
+        props.getProperty(SVC_INSTANCE_PATH);
+        svc_inst_query_path    = props.getProperty(SVC_INST_QRY_PATH);
+        props.getProperty(PARAM_SERVICE_TYPE, "service-type");
 
-        vnf_image_query_path    = props.getProperty(VNF_IMAGE_QUERY_PATH);
+        props.getProperty(VNF_IMAGE_QUERY_PATH);
 
         ubb_notify_path = props.getProperty(UBB_NOTIFY_PATH);
         selflinkAvpn = props.getProperty(SELFLINK_AVPN);
         selflinkFqdn = props.getProperty(SELFLINK_FQDN);
 
-        servicePath  = props.getProperty(SERVICE_PATH);
+        props.getProperty(SERVICE_PATH);
 
-        sitePairSetPath  = props.getProperty(SITE_PAIR_SET_PATH);
+        props.getProperty(SITE_PAIR_SET_PATH);
 
         queryNodesPath = props.getProperty(QUERY_NODES_PATH);
 
@@ -300,7 +277,9 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
                 LOG.error("AAIResource", ex);
             }
 
-            ctx.init(kmf.getKeyManagers(), null, null);
+            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 ) {
@@ -337,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;
     }
@@ -439,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;
@@ -487,6 +476,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
                 try {
                     inputStream.close();
                 } catch(Exception exc) {
+                    LOG.warn("Error closing Inputstream", exc);
                 }
             }
         }
@@ -597,7 +587,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
 
     /*
      * (non-Javadoc)
-     * @see org.openecomp.sdnct.sli.aai.AAIClient#requestVServersData(java.lang.String, java.lang.String)
+     * @see org.onap.sdnct.sli.aai.AAIClient#requestVServersData(java.lang.String, java.lang.String)
      */
     @Override
     public Vserver requestVServerData(String tenantId, String vserverId, String cloudOwner, String cloudRegionId)    throws AAIServiceException {
@@ -742,7 +732,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
                 try {
                     inputStream.close();
                 } catch(Exception exc) {
-
+                    LOG.warn("Error closing InputStream", exc);
                 }
             }
         }
@@ -859,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);
             }
         }
     }
@@ -919,7 +909,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
                 try {
                     inputStream.close();
                 } catch(Exception exc) {
-
+                    LOG.warn("Error closing Input stream", exc);
                 }
             }
         }
@@ -989,7 +979,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
                 try {
                     inputStream.close();
                 } catch(Exception exc) {
-
+                    LOG.warn("Error closing Input stream", exc);
                 }
             }
         }
@@ -1011,8 +1001,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
 
         try {
             for (ResultData datum : resultDataList) {
-                String data_type = datum.getResourceType();
-                URL url = new URL(datum.getResourceLink());
+                URI url = new URI(datum.getResourceLink());
                 entity = this.getResource(url.toString(), GenericVnf.class);
             }
         }
@@ -1222,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;
             }
 
@@ -1242,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;
         }
 
@@ -1344,7 +1336,7 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe
     }
 
     public void logMetricResponse(String requestId, int responseCode, String responseDescription){
-        ml.logResponse(responseCode < 400 ? "SUCCESS" : "FAILURE", Integer.toString(responseCode), responseDescription);
+        ml.logResponse(responseCode < 400 ? "COMPLETE" : "ERROR", Integer.toString(responseCode), responseDescription);
     }
 
     public void logKeyError(String keys){
@@ -1364,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":
@@ -1393,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":
@@ -1422,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":
@@ -1451,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":