From dd1a88c29ba7fd4c30c29b54389be1084725a38d Mon Sep 17 00:00:00 2001 From: Rich Tabedzki Date: Thu, 4 May 2017 07:33:57 +0000 Subject: [SDNC-9] summary added custom query, removed deprecated features Change-Id: If44dcd154ef26b7ea146d31e8dc0c18d117c6ff8 Signed-off-by: Rich Tabedzki --- .../java/org/openecomp/sdnc/sli/aai/AAIClient.java | 3 - .../openecomp/sdnc/sli/aai/AAIDeclarations.java | 3 - .../org/openecomp/sdnc/sli/aai/AAIRequest.java | 4 +- .../org/openecomp/sdnc/sli/aai/AAIService.java | 85 +------------ .../openecomp/sdnc/sli/aai/CustomQueryRequest.java | 134 +++++++++++++++++++++ .../sdnc/sli/aai/FormattedQueryRequest.java | 134 --------------------- .../sli/aai/query/FormattedQueryRequestData.java | 4 + 7 files changed, 141 insertions(+), 226 deletions(-) create mode 100644 aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/CustomQueryRequest.java delete mode 100644 aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/FormattedQueryRequest.java (limited to 'aai-service/provider/src/main/java') diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIClient.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIClient.java index 7a1077a..fe358df 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIClient.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIClient.java @@ -41,9 +41,6 @@ import org.openecomp.aai.inventory.v10.*; public interface AAIClient extends SvcLogicResource, SvcLogicJavaPlugin { - // Availability Zone - public SdnZoneResponse requestSdnZoneQuery(String service_type, String vnf_type, String physical_location) throws AAIServiceException; - // VCE public boolean postNetworkVceData(String vnf_id, Vce request) throws AAIServiceException; public Vce requestNetworkVceData(String vnf_id) throws AAIServiceException; diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIDeclarations.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIDeclarations.java index a1bae3d..5d5c6d8 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIDeclarations.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIDeclarations.java @@ -100,9 +100,6 @@ public abstract class AAIDeclarations implements AAIClient { public static final String VNF_IMAGE_QUERY_PATH = "org.openecomp.sdnc.sli.aai.path.vnf.image.query"; - public static final String QUERY_FORMAT = "org.openecomp.sdnc.sli.aai.param.format"; - public static final String PARAM_VNF_TYPE = "org.openecomp.sdnc.sli.aai.param.vnf_type"; - public static final String PARAM_PHYS_LOC_ID = "org.openecomp.sdnc.sli.aai.param.physical.location.id"; public static final String PARAM_SERVICE_TYPE = "org.openecomp.sdnc.sli.aai.param.service.type"; public static final String CERTIFICATE_HOST_ERROR = "org.openecomp.sdnc.sli.aai.host.certificate.ignore"; diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIRequest.java index a237d84..4badf22 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIRequest.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIRequest.java @@ -113,8 +113,8 @@ public abstract class AAIRequest { return new NamedQueryRequest(); case "nodes-query": return new NodesQueryRequest(); - case "formatted-query": - return new FormattedQueryRequest(); + case "custom-query": + return new CustomQueryRequest(); case "linterface": return new LInterfaceRequest(LInterfaceRequest.TYPE.L2_BRIDGE_SBG); case "l2-bridge-sbg": diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIService.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIService.java index 8c917e9..f316ead 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIService.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/AAIService.java @@ -122,9 +122,6 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe private final String vnf_image_query_path; - private final String param_format; //= "filter=%s:%s"; - private final String param_vnf_type; //= "vnf-type"; - private final String param_physical_location_id; //= "physical-location-id"; private final String param_service_type; //= "service-type"; private final String ubb_notify_path; @@ -231,9 +228,6 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe svc_inst_qry_path = props.getProperty(SVC_INST_QRY_PATH); // "/aai/v1/search/generic-query?key=service-instance.service-instance-id:{svc-instance-id}&start-node-type=service-instance&include=service-instance"); - param_format = props.getProperty(QUERY_FORMAT, "filter=%s:%s"); - param_vnf_type = props.getProperty(PARAM_VNF_TYPE, "vnf-type"); - param_physical_location_id = props.getProperty(PARAM_PHYS_LOC_ID, "physical-location-id"); param_service_type = props.getProperty(PARAM_SERVICE_TYPE, "service-type"); // P-Interfaces @@ -383,67 +377,6 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe return con; } - /* (non-Javadoc) - * @see org.openecomp.sdnc.sli.resource.aic.AnAIClient#requestSdnZoneQuery(java.lang.String, java.lang.String, java.lang.String) - */ - @Override - public SdnZoneResponse requestSdnZoneQuery(String service_type, String vnf_type, String physical_location) throws AAIServiceException { - SdnZoneResponse response = null; - InputStream inputStream = null; - - try { - URL http_req_url = getRequestURL(service_type, vnf_type, physical_location); - - HttpURLConnection con = getConfiguredConnection(http_req_url, HttpMethod.GET); - - LOGwriteFirstTrace(HttpMethod.GET, http_req_url.toString()); - LOGwriteDateTrace("service_type", service_type); - LOGwriteDateTrace("vnf_type", vnf_type); - LOGwriteDateTrace("physical_location", physical_location); - - // Check for errors - int responseCode = con.getResponseCode(); - if (responseCode == HttpURLConnection.HTTP_OK) { - inputStream = con.getInputStream(); - } else { - inputStream = con.getErrorStream(); - } - - // Process the response - LOG.debug("HttpURLConnection result:" + responseCode); - if(inputStream == null) inputStream = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); - BufferedReader reader = new BufferedReader( new InputStreamReader( inputStream ) ); - - ObjectMapper mapper = getObjectMapper(); - - if (responseCode == HttpURLConnection.HTTP_OK) { - response = mapper.readValue(reader, SdnZoneResponse.class); - LOGwriteEndingTrace(HttpURLConnection.HTTP_OK, "SUCCESS", mapper.writeValueAsString(response)); - } else if(responseCode == HttpURLConnection.HTTP_NOT_FOUND ) { - LOGwriteEndingTrace(responseCode, "HTTP_NOT_FOUND", "Entry does not exist."); - return response; - } else { - ErrorResponse errorresponse = mapper.readValue(reader, ErrorResponse.class); - LOGwriteEndingTrace(responseCode, "FAILURE", mapper.writeValueAsString(errorresponse)); - throw new AAIServiceException(responseCode, errorresponse); - } - - } catch(AAIServiceException aaiexc) { - throw aaiexc; - } catch (Exception exc) { - LOG.warn("requestServiceInterfaceData", exc); - throw new AAIServiceException(exc); - } finally { - if(inputStream != null){ - try { - inputStream.close(); - } catch(Exception exc) { - - } - } - } - return response; - } @Override public GenericVnf requestGenericVnfData(String vnf_id) throws AAIServiceException { @@ -675,22 +608,6 @@ public class AAIService extends AAIDeclarations implements AAIClient, SvcLogicRe } } - /* - * Supporting methosd - */ - private URL getRequestURL(String service_type, String vnf_type, String physical_location_id) throws MalformedURLException, URISyntaxException, UnsupportedEncodingException { - - StringBuilder query = new StringBuilder(); - query.append("filter=vnf-type:").append(encodeQuery(vnf_type)); - query.append("&filter=service-type:").append(encodeQuery(service_type)); - query.append("&filter=physical-location-id:").append(physical_location_id); - - UriBuilder builder = javax.ws.rs.core.UriBuilder.fromUri(target_uri).path(query_path).replaceQuery(query.toString()); -// String y = x.build().toString(); - - return builder.build().toURL(); - - } private static Properties initialize(URL url ) throws ConfigurationException { @@ -3180,7 +3097,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.toBinaryString(responseCode), responseDescription); + ml.logResponse(responseCode < 400 ? "SUCCESS" : "FAILURE", Integer.toString(responseCode), responseDescription); } public void logKeyError(String keys){ diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/CustomQueryRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/CustomQueryRequest.java new file mode 100644 index 0000000..7980895 --- /dev/null +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/CustomQueryRequest.java @@ -0,0 +1,134 @@ +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 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.openecomp.sdnc.sli.aai; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Properties; + +import org.openecomp.sdnc.sli.aai.data.AAIDatum; +import org.openecomp.sdnc.sli.aai.query.FormattedQueryRequestData; +import org.openecomp.sdnc.sli.aai.query.FormattedQueryResultList; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; + + +public class CustomQueryRequest extends AAIRequest { + + public static final String GENERIC_SEARCH_PATH = "org.openecomp.sdnc.sli.aai.query.generic"; + + private final String generic_search_path; + + public static final String FORMAT = "format"; + + + public CustomQueryRequest() { + String tmp_generic_search_path = configProperties.getProperty(GENERIC_SEARCH_PATH); + tmp_generic_search_path = tmp_generic_search_path.split("search")[0]; + generic_search_path = tmp_generic_search_path +"query"; + } + + + @Override + public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException { + + String request_url = target_uri+generic_search_path; + + request_url = processPathData(request_url, requestProperties); + + String formatQuery = requestProperties.getProperty(FORMAT); + + if(formatQuery != null) { + request_url = request_url +"?format="+formatQuery; + } + URL http_req_url = new URL(request_url); + + aaiService.LOGwriteFirstTrace(method, http_req_url.toString()); + + return http_req_url; + } + + @Override + public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException { + return getRequestUrl(method, null); + } + + + @Override + public String toJSONString() { + ObjectMapper mapper = getObjectMapper(); + FormattedQueryRequestData tenant = (FormattedQueryRequestData)requestDatum; + String json_text = null; + try { + json_text = mapper.writeValueAsString(tenant); + } catch (JsonProcessingException exc) { + handleException(this, exc); + return null; + } + return json_text; + } + + + @Override + public String[] getArgsList() { + String[] args = {FORMAT}; + return args; + } + + + @Override + public Class getModelClass() { + return FormattedQueryRequestData.class; + } + + + public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException { + + String key = FORMAT; + + String encoded_vnf = encodeQuery(requestProperties.getProperty(key)); + request_url = request_url.replace("{identifier}", encoded_vnf) ; + aaiService.LOGwriteDateTrace("identifier", requestProperties.getProperty(key)); + + return request_url; + } + + public AAIDatum jsonStringToObject(String jsonData) throws JsonParseException, JsonMappingException, IOException { + if(jsonData == null) { + return null; + } + + AAIDatum response = null; + ObjectMapper mapper = getObjectMapper(); + response = mapper.readValue(jsonData, FormattedQueryResultList.class); + return response; + } + + protected boolean expectsDataFromPUTRequest() { + return true; + } +} diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/FormattedQueryRequest.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/FormattedQueryRequest.java deleted file mode 100644 index fba5bfe..0000000 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/FormattedQueryRequest.java +++ /dev/null @@ -1,134 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 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.openecomp.sdnc.sli.aai; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Properties; - -import org.openecomp.sdnc.sli.aai.data.AAIDatum; -import org.openecomp.sdnc.sli.aai.query.FormattedQueryRequestData; -import org.openecomp.sdnc.sli.aai.query.FormattedQueryResultList; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - - -public class FormattedQueryRequest extends AAIRequest { - - public static final String GENERIC_SEARCH_PATH = "com.att.sdnctl.sli.aai.query.generic"; - - private final String generic_search_path; - - public static final String FORMAT = "format"; - - - public FormattedQueryRequest() { - String tmp_generic_search_path = configProperties.getProperty(GENERIC_SEARCH_PATH); - tmp_generic_search_path = tmp_generic_search_path.split("search")[0]; - generic_search_path = tmp_generic_search_path +"query"; - } - - - @Override - public URL getRequestUrl(String method, String resourceVersion) throws UnsupportedEncodingException, MalformedURLException { - - String request_url = target_uri+generic_search_path; - - request_url = processPathData(request_url, requestProperties); - - String formatQuery = requestProperties.getProperty(FORMAT); - - if(formatQuery != null) { - request_url = request_url +"?format="+formatQuery; - } - URL http_req_url = new URL(request_url); - - aaiService.LOGwriteFirstTrace(method, http_req_url.toString()); - - return http_req_url; - } - - @Override - public URL getRequestQueryUrl(String method) throws UnsupportedEncodingException, MalformedURLException { - return getRequestUrl(method, null); - } - - - @Override - public String toJSONString() { - ObjectMapper mapper = getObjectMapper(); - FormattedQueryRequestData tenant = (FormattedQueryRequestData)requestDatum; - String json_text = null; - try { - json_text = mapper.writeValueAsString(tenant); - } catch (JsonProcessingException exc) { - handleException(this, exc); - return null; - } - return json_text; - } - - - @Override - public String[] getArgsList() { - String[] args = {FORMAT}; - return args; - } - - - @Override - public Class getModelClass() { - return FormattedQueryRequestData.class; - } - - - public static String processPathData(String request_url, Properties requestProperties) throws UnsupportedEncodingException { - - String key = FORMAT; - - String encoded_vnf = encodeQuery(requestProperties.getProperty(key)); - request_url = request_url.replace("{identifier}", encoded_vnf) ; - aaiService.LOGwriteDateTrace("identifier", requestProperties.getProperty(key)); - - return request_url; - } - - public AAIDatum jsonStringToObject(String jsonData) throws JsonParseException, JsonMappingException, IOException { - if(jsonData == null) { - return null; - } - - AAIDatum response = null; - ObjectMapper mapper = getObjectMapper(); - response = mapper.readValue(jsonData, FormattedQueryResultList.class); - return response; - } - - protected boolean expectsDataFromPUTRequest() { - return true; - } -} diff --git a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/FormattedQueryRequestData.java b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/FormattedQueryRequestData.java index 72222d9..1a281af 100644 --- a/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/FormattedQueryRequestData.java +++ b/aai-service/provider/src/main/java/org/openecomp/sdnc/sli/aai/query/FormattedQueryRequestData.java @@ -76,4 +76,8 @@ public class FormattedQueryRequestData implements AAIDatum { return " [start = "+start+", query = "+query+"]"; } + public String getResourceVersion() { + return null; + } + } -- cgit 1.2.3-korg