aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/aai
diff options
context:
space:
mode:
authorSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
committerSonsino, Ofir (os0695) <os0695@intl.att.com>2018-07-10 14:20:54 +0300
commitc72d565bb58226b20625b2bce5f0019046bee649 (patch)
tree8658e49595705b02e47ddc14afa20d6bb7123547 /vid-app-common/src/main/java/org/onap/vid/aai
parentef8a6b47847012fd59ea20da21d8d3d7c4a301ed (diff)
Merge 1806 code of vid-common
Change-Id: I75d52abed4a24dfe3827d79edc4a2938726aa87a Issue-ID: VID-208 Signed-off-by: Sonsino, Ofir (os0695) <os0695@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/aai')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java590
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java26
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java2
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseTranslator.java103
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseWithRequestInfo.java44
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java54
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java50
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/PombaClientInterface.java7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java73
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/ResponseWithRequestInfo.java29
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java8
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetInstanceGroupsByCloudRegion.java20
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetNetworkCollectionDetails.java23
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetNetworkCollectionDetailsHelper.java38
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetRelatedInstanceGroupsByVnfId.java181
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Collection.java130
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/InstanceGroup.java105
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Network.java142
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelatedToProperty.java37
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Relationship.java67
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipData.java29
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java25
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Result.java64
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/ServiceInstance.java17
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPortMirroringSourcePorts.java18
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/AaiNodeQueryResponse.java26
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/InstanceGroupInfo.java32
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/InstanceGroupWrapper.java20
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/PortDetailsTranslator.java138
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/Properties.java33
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedTo.java39
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedToProperty.java6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java6
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipData.java5
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/ResourceType.java44
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/model/SimpleResult.java85
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java245
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/CustomJacksonJaxBJsonProvider.java4
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/HttpClientMode.java9
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsAuthClient.java253
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java54
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/JettyObfuscationConversionCommandLineUtil.java8
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/aai/util/VidObjectMapperType.java6
44 files changed, 2406 insertions, 493 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
index 6ed34590..c1964c16 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClient.java
@@ -1,37 +1,46 @@
package org.onap.vid.aai;
+import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpStatus;
import org.apache.http.client.utils.URIBuilder;
+import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
-import org.onap.vid.aai.util.AAIRestInterface;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.aai.model.AaiGetAicZone.AicZones;
-import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
import org.onap.vid.aai.model.*;
+import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.*;
+import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.onap.vid.aai.model.Relationship;
+import org.onap.vid.aai.model.RelationshipData;
+import org.onap.vid.aai.model.RelationshipList;
+import org.onap.vid.aai.util.AAIRestInterface;
+import org.onap.vid.aai.util.VidObjectMapperType;
+import org.onap.vid.exceptions.GenericUncheckedException;
import org.onap.vid.model.SubscriberList;
-import org.springframework.beans.factory.annotation.Autowired;
+import org.onap.vid.model.probes.ErrorMetadata;
+import org.onap.vid.model.probes.ExternalComponentStatus;
+import org.onap.vid.model.probes.HttpRequestMetadata;
+import org.onap.vid.utils.Logging;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.springframework.web.util.UriUtils;
-import javax.servlet.ServletContext;
-import javax.ws.rs.BadRequestException;
+import javax.inject.Inject;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
-import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Iterator;
-import java.util.List;
-import java.util.UUID;
+import java.util.*;
+
+import static java.util.Collections.emptyList;
+import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
/**
@@ -39,27 +48,37 @@ import java.util.UUID;
*/
public class AaiClient implements AaiClientInterface {
- /**
- * The Constant dateFormat.
- */
- final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
+
+ public static final String QUERY_FORMAT_RESOURCE = "query?format=resource";
+ public static final String SERVICE_SUBSCRIPTIONS_PATH = "/service-subscriptions/service-subscription/";
+ public static final String MODEL_INVARIANT_ID = "&model-invariant-id=";
+ public static final String QUERY_FORMAT_SIMPLE = "query?format=simple";
+ public static final String BUSINESS_CUSTOMER = "/business/customers/customer/";
+ public static final String SERVICE_INSTANCE = "/service-instances/service-instance/";
+ public static final String BUSINESS_CUSTOMERS_CUSTOMER = "business/customers/customer/";
+
protected String fromAppId = "VidAaiController";
- @Autowired
- ServletContext servletContext;
+
+ private PortDetailsTranslator portDetailsTranslator;
+
+ private final AAIRestInterface restController;
+
/**
* The logger
*/
-
EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AaiClient.class);
- private final String getServiceModelsResponseBody = "{\"start\" : \"service-design-and-creation/models/\", \"query\" : \"query/serviceModels-byDistributionStatus?distributionStatus=DISTRIBUTION_COMPLETE_OK\"}";
- public AaiClient() {
- // certiPath = getCertificatesFile().getAbsolutePath();
- // depth = "0";
- }
+ /**
+ * The Constant dateFormat.
+ */
+ static final DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
+
+ static final String GET_SERVICE_MODELS_RESPONSE_BODY = "{\"start\" : \"service-design-and-creation/models/\", \"query\" : \"query/serviceModels-byDistributionStatus?distributionStatus=DISTRIBUTION_COMPLETE_OK\"}";
- public AaiClient(ServletContext context) {
- servletContext = context;
+ @Inject
+ public AaiClient(AAIRestInterface restController, PortDetailsTranslator portDetailsTranslator) {
+ this.restController = restController;
+ this.portDetailsTranslator = portDetailsTranslator;
}
@@ -73,67 +92,131 @@ public class AaiClient implements AaiClientInterface {
@Override
public AaiResponse getServicesByOwningEntityId(List<String> owningEntityIds){
- File certiPath = getCertificatesFile();
- Response resp = doAaiGet(certiPath.getAbsolutePath(), getUrlFromLIst("business/owning-entities?", "owning-entity-id=", owningEntityIds), false);
- AaiResponse aaiResponse = proccessAaiResponse(resp, OwningEntityResponse.class, null);
-
- return aaiResponse;
+ Response resp = doAaiGet(getUrlFromLIst("business/owning-entities?", "owning-entity-id=", owningEntityIds), false);
+ return processAaiResponse(resp, OwningEntityResponse.class, null);
}
@Override
public AaiResponse getServicesByProjectNames(List<String> projectNames){
- File certiPath = getCertificatesFile();
- Response resp = doAaiGet(certiPath.getAbsolutePath(), getUrlFromLIst("business/projects?", "project-name=", projectNames), false);
- AaiResponse aaiResponse = proccessAaiResponse(resp, ProjectResponse.class, null);
-
- return aaiResponse;
+ Response resp = doAaiGet(getUrlFromLIst("business/projects?", "project-name=", projectNames), false);
+ return processAaiResponse(resp, ProjectResponse.class, null);
}
@Override
public AaiResponse getServiceModelsByDistributionStatus() {
- File certiPath = getCertificatesFile();
- Response resp = doAaiPut(certiPath.getAbsolutePath(), "query?format=resource", getServiceModelsResponseBody, false);
- AaiResponse aaiResponse = proccessAaiResponse(resp, GetServiceModelsByDistributionStatusResponse.class, null);
+ Response resp = doAaiPut(QUERY_FORMAT_RESOURCE, GET_SERVICE_MODELS_RESPONSE_BODY, false);
+ return processAaiResponse(resp, GetServiceModelsByDistributionStatusResponse.class, null);
+ }
+
+ @Override
+ public AaiResponse getNetworkCollectionDetails(String serviceInstanceId) {
+ Response resp = doAaiPut(QUERY_FORMAT_RESOURCE, "{\"start\": [\"nodes/service-instances/service-instance/" + serviceInstanceId + "\"],\"query\": \"query/network-collection-ByServiceInstance\"}\n", false);
+ AaiResponse<AaiGetNetworkCollectionDetailsHelper> aaiResponse = processAaiResponse(resp, AaiGetNetworkCollectionDetailsHelper.class, null, VidObjectMapperType.FASTERXML);
+ return getNetworkCollectionDetailsResponse(aaiResponse);
+ }
+
+ @Override
+ public AaiResponse getInstanceGroupsByCloudRegion(String cloudOwner, String cloudRegionId, String networkFunction) {
+ Response resp = doAaiPut(QUERY_FORMAT_RESOURCE,
+ "{\"start\": [\"cloud-infrastructure/cloud-regions/cloud-region/" + cloudOwner + "/" + cloudRegionId + "\"]," +
+ "\"query\": \"query/instance-group-byCloudRegion?type=L3-NETWORK&role=SUB-INTERFACE&function=" + networkFunction + "\"}\n", false);
+ return processAaiResponse(resp, AaiGetInstanceGroupsByCloudRegion.class, null, VidObjectMapperType.FASTERXML);
+ }
+ private AaiResponse getNetworkCollectionDetailsResponse(AaiResponse<AaiGetNetworkCollectionDetailsHelper> aaiResponse){
+ if(aaiResponse.getHttpCode() == 200) {
+ com.fasterxml.jackson.databind.ObjectMapper om = new com.fasterxml.jackson.databind.ObjectMapper();
+ AaiGetNetworkCollectionDetails aaiGetNetworkCollectionDetails = new AaiGetNetworkCollectionDetails();
+ try {
+ for (int i = 0; i < aaiResponse.getT().getResults().size(); i++) {
+ LinkedHashMap<String, Object> temp = ((LinkedHashMap) aaiResponse.getT().getResults().get(i));
+ if (temp.get("service-instance") != null)
+ aaiGetNetworkCollectionDetails.getResults().setServiceInstance(om.readValue(om.writeValueAsString(temp.get("service-instance")), org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.ServiceInstance.class));
+ else if (temp.get("collection") != null)
+ aaiGetNetworkCollectionDetails.getResults().setCollection(om.readValue(om.writeValueAsString(temp.get("collection")), org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.Collection.class));
+ else if (temp.get("instance-group") != null)
+ aaiGetNetworkCollectionDetails.getResults().setInstanceGroup(om.readValue(om.writeValueAsString(temp.get("instance-group")), InstanceGroup.class));
+ else if (temp.get("l3-network") != null)
+ aaiGetNetworkCollectionDetails.getResults().getNetworks().add(om.readValue(om.writeValueAsString(temp.get("l3-network")), Network.class));
+ }
+ return new AaiResponse(aaiGetNetworkCollectionDetails, null, HttpStatus.SC_OK);
+ }
+ catch (com.fasterxml.jackson.databind.JsonMappingException e) {
+ return new AaiResponse(e.getCause(), "AAI response parsing Error" , aaiResponse.getHttpCode());
+ }
+ catch (Exception e) {
+ return new AaiResponse(e.getCause(), "Got " + aaiResponse.getHttpCode() + " from a&ai" , aaiResponse.getHttpCode());
+ }
+ }
return aaiResponse;
}
@Override
public AaiResponse getPNFData(String globalCustomerId, String serviceType, String modelVersionId, String modelInvariantId, String cloudRegion, String equipVendor, String equipModel) {
- String certiPath = getCertificatesFile().getAbsolutePath();
- String siQuery = "/business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances?model-version-id=" + modelVersionId + "&model-invariant-id=" + modelInvariantId;
+ String siQuery = BUSINESS_CUSTOMER + globalCustomerId + SERVICE_SUBSCRIPTIONS_PATH + encodePathSegment(serviceType) + "/service-instances?model-version-id=" + modelVersionId + MODEL_INVARIANT_ID + modelInvariantId;
String pnfQuery = "query/pnf-fromModel-byRegion?cloudRegionId=" + encodePathSegment(cloudRegion) + "&equipVendor=" + encodePathSegment(equipVendor) + "&equipModel=" + encodePathSegment(equipModel);
String payload = "{\"start\":\"" + siQuery + "\",\"query\":\"" + pnfQuery + "\"}";
- Response resp = doAaiPut(certiPath, "query?format=simple", payload, false);
- return proccessAaiResponse(resp, AaiGetPnfResponse.class, null);
+ Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false);
+ return processAaiResponse(resp, AaiGetPnfResponse.class, null);
}
@Override
public AaiResponse<Pnf> getSpecificPnf(String pnfId) {
- File certiPath = getCertificatesFile();
- Response resp = doAaiGet(certiPath.getAbsolutePath(), "network/pnfs/pnf/"+pnfId, false);
- AaiResponse aaiResponse = proccessAaiResponse(resp, Pnf.class, null);
+ Response resp = doAaiGet("network/pnfs/pnf/"+pnfId, false);
+ return processAaiResponse(resp, Pnf.class, null);
+ }
- return aaiResponse;
+
+ public AaiResponse getInstanceGroupsByVnfInstanceId(String vnfInstanceId){
+ Response resp = doAaiGet("network/generic-vnfs/generic-vnf/" + vnfInstanceId + "?depth=0", false);
+ return processAaiResponse(resp, AaiGetRelatedInstanceGroupsByVnfId.class , null, null);
+ }
+
+
+ @Override
+ public List<PortDetailsTranslator.PortDetails> getPortMirroringSourcePorts(String configurationID) {
+ String payload = "{\"start\":\"/network/configurations/configuration/" + configurationID + "\",\"query\":\"query/pserver-fromConfiguration\"}";
+ Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false);
+ resp.bufferEntity(); // avoid later "Entity input stream has already been closed" problems
+ String rawPayload = resp.readEntity(String.class);
+ AaiResponse<AaiGetPortMirroringSourcePorts> aaiResponse = processAaiResponse(resp, AaiGetPortMirroringSourcePorts.class, rawPayload);
+ return portDetailsTranslator.extractPortDetails(aaiResponse, rawPayload);
}
+
+
public AaiResponse getServiceInstance(String globalCustomerId, String serviceType, String serviceInstanceId) {
- String certiPath = getCertificatesFile().getAbsolutePath();
- String getServiceInstancePath = "business/customers/customer/"+globalCustomerId+"/service-subscriptions/service-subscription/"+serviceType+"/service-instances/service-instance/"+serviceInstanceId;
- Response resp = doAaiGet(certiPath , getServiceInstancePath , false);
- return proccessAaiResponse(resp, ServiceRelationships.class, null);
+ String getServiceInstancePath = BUSINESS_CUSTOMERS_CUSTOMER + globalCustomerId+ SERVICE_SUBSCRIPTIONS_PATH +serviceType+ SERVICE_INSTANCE +serviceInstanceId;
+ Response resp = doAaiGet(getServiceInstancePath , false);
+ return processAaiResponse(resp, ServiceRelationships.class, null);
}
@Override
public AaiResponse getLogicalLink(String link) {
- String certiPath = getCertificatesFile().getAbsolutePath();
- Response resp = doAaiGet(certiPath , "network/logical-links/logical-link/" + link , false);
- return proccessAaiResponse(resp, LogicalLinkResponse.class, null);
+ Response resp = doAaiGet("network/logical-links/logical-link/" + link , false);
+ return processAaiResponse(resp, LogicalLinkResponse.class, null);
+ }
+
+ @Override
+ public AaiResponse<AaiNodeQueryResponse> searchNodeTypeByName(String name, ResourceType type) {
+ String path = String.format(
+ "search/nodes-query?search-node-type=%s&filter=%s:EQUALS:%s",
+ type.getAaiFormat(),
+ type.getNameFilter(),
+ name
+ );
+ return typedAaiGet(path, AaiNodeQueryResponse.class);
}
+ private <T> AaiResponse<T> typedAaiGet(String path, Class<T> clz) {
+ Response resp = doAaiGet(path , false);
+ return processAaiResponse(resp, clz, null, VidObjectMapperType.FASTERXML);
+ }
+
+
+
private String getUrlFromLIst(String url, String paramKey, List<String> params){
- url.concat(paramKey);
int i = 0;
for(String param: params){
i ++;
@@ -157,99 +240,89 @@ public class AaiClient implements AaiClientInterface {
@Override
public AaiResponse<SubscriberList> getAllSubscribers() {
- String certiPath = getCertificatesFile().getAbsolutePath();
+ return getAllSubscribers(false).getAaiResponse();
+ }
+
+ AaiResponseWithRequestInfo<SubscriberList> getAllSubscribers(boolean propagateExceptions){
String depth = "0";
- Response resp = doAaiGet(certiPath, "business/customers?subscriber-type=INFRA&depth=" + depth, false);
- return proccessAaiResponse(resp, SubscriberList.class, null);
+ ResponseWithRequestInfo aaiGetResult = doAaiGet("business/customers?subscriber-type=INFRA&depth=" + depth, false, propagateExceptions);
+ AaiResponseWithRequestInfo<SubscriberList> responseWithRequestInfo = processAaiResponse(aaiGetResult, SubscriberList.class, propagateExceptions);
+ responseWithRequestInfo.setRequestedUrl(aaiGetResult.getRequestUrl());
+ responseWithRequestInfo.setHttpMethod(aaiGetResult.getRequestHttpMethod());
+ return responseWithRequestInfo;
}
@Override
public AaiResponse getAllAicZones() {
- String certiPath = getCertificatesFile().getAbsolutePath();
- Response resp = doAaiGet(certiPath, "network/zones", false);
- AaiResponse aaiAicZones = proccessAaiResponse(resp, AicZones.class, null);
- return aaiAicZones;
+ Response resp = doAaiGet("network/zones", false);
+ return processAaiResponse(resp, AicZones.class, null);
}
@Override
public AaiResponse<String> getAicZoneForPnf(String globalCustomerId , String serviceType , String serviceId) {
- String certiPath = getCertificatesFile().getAbsolutePath();
- String aicZonePath = "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + serviceType + "/service-instances/service-instance/" + serviceId;
- Response resp = doAaiGet(certiPath , aicZonePath , false);
- AaiResponse<ServiceRelationships> aaiResponse = proccessAaiResponse(resp , ServiceRelationships.class , null);
- ServiceRelationships serviceRelationships = (ServiceRelationships)aaiResponse.getT();
+ String aicZonePath = BUSINESS_CUSTOMERS_CUSTOMER + globalCustomerId + SERVICE_SUBSCRIPTIONS_PATH + serviceType + SERVICE_INSTANCE + serviceId;
+ Response resp = doAaiGet(aicZonePath , false);
+ AaiResponse<ServiceRelationships> aaiResponse = processAaiResponse(resp , ServiceRelationships.class , null);
+ ServiceRelationships serviceRelationships = aaiResponse.getT();
RelationshipList relationshipList = serviceRelationships.getRelationshipList();
Relationship relationship = relationshipList.getRelationship().get(0);
RelationshipData relationshipData= relationship.getRelationDataList().get(0);
String aicZone = relationshipData.getRelationshipValue();
- AaiResponse<String> aaiAicZonaForPnfResponse = new AaiResponse(aicZone , null ,HttpStatus.SC_OK);
- return aaiAicZonaForPnfResponse;
+ return new AaiResponse(aicZone , null ,HttpStatus.SC_OK);
}
@Override
public AaiResponse getVNFData() {
- String certiPath = getCertificatesFile().getAbsolutePath();
String payload = "{\"start\": [\"/business/customers/customer/e433710f-9217-458d-a79d-1c7aff376d89/service-subscriptions/service-subscription/VIRTUAL%20USP/service-instances/service-instance/3f93c7cb-2fd0-4557-9514-e189b7b04f9d\"], \"query\": \"query/vnf-topology-fromServiceInstance\"}";
- Response resp = doAaiPut(certiPath, "query?format=simple", payload, false);
- return proccessAaiResponse(resp, AaiGetVnfResponse.class, null);
-
+ Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false);
+ return processAaiResponse(resp, AaiGetVnfResponse.class, null);
}
@Override
public Response getVNFData(String globalSubscriberId, String serviceType) {
- String certiPath = getCertificatesFile().getAbsolutePath();
- String payload = "{\"start\": [\"business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/"+ encodePathSegment(serviceType) +"/service-instances\"]," +
+ String payload = "{\"start\": [\"business/customers/customer/" + globalSubscriberId + SERVICE_SUBSCRIPTIONS_PATH + encodePathSegment(serviceType) +"/service-instances\"]," +
"\"query\": \"query/vnf-topology-fromServiceInstance\"}";
- return doAaiPut(certiPath, "query?format=simple", payload, false);
-
+ return doAaiPut(QUERY_FORMAT_SIMPLE, payload, false);
}
@Override
public AaiResponse getVNFData(String globalSubscriberId, String serviceType, String serviceInstanceId) {
- String certiPath = getCertificatesFile().getAbsolutePath();
- String payload = "{\"start\": [\"/business/customers/customer/" + globalSubscriberId + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances/service-instance/" + serviceInstanceId + "\"], \"query\": \"query/vnf-topology-fromServiceInstance\"}";
- Response resp = doAaiPut(certiPath, "query?format=simple", payload, false);
- return proccessAaiResponse(resp, AaiGetVnfResponse.class, null);
+ String payload = "{\"start\": [\"/business/customers/customer/" + globalSubscriberId + SERVICE_SUBSCRIPTIONS_PATH + encodePathSegment(serviceType) + SERVICE_INSTANCE + serviceInstanceId + "\"], \"query\": \"query/vnf-topology-fromServiceInstance\"}";
+ Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false);
+ return processAaiResponse(resp, AaiGetVnfResponse.class, null);
}
@Override
public Response getVersionByInvariantId(List<String> modelInvariantId) {
- File certiPath = getCertificatesFile();
StringBuilder sb = new StringBuilder();
for (String id : modelInvariantId){
- sb.append("&model-invariant-id=");
+ sb.append(MODEL_INVARIANT_ID);
sb.append(id);
}
- Response resp = doAaiGet(certiPath.getAbsolutePath(), "service-design-and-creation/models?depth=2"+ sb.toString(), false);
- return resp;
+ return doAaiGet("service-design-and-creation/models?depth=2"+ sb.toString(), false);
}
@Override
public AaiResponse getSubscriberData(String subscriberId) {
- File certiPath = getCertificatesFile();
String depth = "2";
AaiResponse subscriberDataResponse;
- Response resp = doAaiGet(certiPath.getAbsolutePath(), "business/customers/customer/" + subscriberId + "?depth=" + depth, false);
- subscriberDataResponse = proccessAaiResponse(resp, Services.class, null);
+ Response resp = doAaiGet(BUSINESS_CUSTOMERS_CUSTOMER + subscriberId + "?depth=" + depth, false);
+ subscriberDataResponse = processAaiResponse(resp, Services.class, null);
return subscriberDataResponse;
}
@Override
public AaiResponse getServices() {
- File certiPath = getCertificatesFile();
- Response resp = doAaiGet(certiPath.getAbsolutePath(), "service-design-and-creation/services", false);
- AaiResponse<GetServicesAAIRespone> getServicesResponse = proccessAaiResponse(resp, GetServicesAAIRespone.class, null);
-
- return getServicesResponse;
+ Response resp = doAaiGet("service-design-and-creation/services", false);
+ return processAaiResponse(resp, GetServicesAAIRespone.class, null);
}
@Override
public AaiResponse getOperationalEnvironments(String operationalEnvironmentType, String operationalEnvironmentStatus) {
- File certiPath = getCertificatesFile();
String url = "cloud-infrastructure/operational-environments";
URIBuilder urlBuilder = new URIBuilder();
if (operationalEnvironmentType != null)
@@ -257,47 +330,83 @@ public class AaiClient implements AaiClientInterface {
if (operationalEnvironmentStatus != null)
urlBuilder.addParameter("operational-environment-status", operationalEnvironmentStatus);
url += urlBuilder.toString();
- Response resp = doAaiGet(certiPath.getAbsolutePath(), url, false);
- AaiResponse<OperationalEnvironmentList> getOperationalEnvironmentsResponse = proccessAaiResponse(resp, OperationalEnvironmentList.class, null);
- return getOperationalEnvironmentsResponse;
-
+ Response resp = doAaiGet(url, false);
+ return processAaiResponse(resp, OperationalEnvironmentList.class, null);
}
@Override
public AaiResponse getTenants(String globalCustomerId, String serviceType) {
- File certiPath = getCertificatesFile();
- String url = "business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + serviceType;
+ AaiResponse aaiResponse;
- Response resp = doAaiGet(certiPath.getAbsolutePath(), url, false);
+ if ((globalCustomerId == null || globalCustomerId.isEmpty()) || ((serviceType == null) || (serviceType.isEmpty())) ){
+ aaiResponse = new AaiResponse<>(null, "{\"statusText\":\" Failed to retrieve LCP Region & Tenants from A&AI, Subscriber ID or Service Type is missing.\"}", HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ return aaiResponse;
+ }
+
+ String url = BUSINESS_CUSTOMERS_CUSTOMER + globalCustomerId + SERVICE_SUBSCRIPTIONS_PATH + serviceType;
+
+ Response resp = doAaiGet(url, false);
String responseAsString = parseForTenantsByServiceSubscription(resp.readEntity(String.class));
if (responseAsString.equals("")){
- AaiResponse aaiResponse = new AaiResponse<>(null, String.format("{\"statusText\":\" A&AI has no LCP Region & Tenants associated to subscriber '%s' and service type '%s'\"}", globalCustomerId, serviceType), HttpStatus.SC_INTERNAL_SERVER_ERROR);
- return aaiResponse;
+ return new AaiResponse<>(null, String.format("{\"statusText\":\" A&AI has no LCP Region & Tenants associated to subscriber '%s' and service type '%s'\"}", globalCustomerId, serviceType), HttpStatus.SC_INTERNAL_SERVER_ERROR);
}
else {
- AaiResponse<GetTenantsResponse[]> getTenantsResponse = proccessAaiResponse(resp, GetTenantsResponse[].class, responseAsString);
- return getTenantsResponse;
+ return processAaiResponse(resp, GetTenantsResponse[].class, responseAsString);
}
-
}
@Override
public AaiResponse getNodeTemplateInstances(String globalCustomerId, String serviceType, String modelVersionId, String modelInvariantId, String cloudRegion) {
- String certiPath = getCertificatesFile().getAbsolutePath();
-
- String siQuery = "/business/customers/customer/" + globalCustomerId + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances?model-version-id=" + modelVersionId + "&model-invariant-id=" + modelInvariantId;
+ String siQuery = BUSINESS_CUSTOMER + globalCustomerId + SERVICE_SUBSCRIPTIONS_PATH + encodePathSegment(serviceType) + "/service-instances?model-version-id=" + modelVersionId + MODEL_INVARIANT_ID + modelInvariantId;
String vnfQuery = "query/queryvnfFromModelbyRegion?cloudRegionId=" + encodePathSegment(cloudRegion);
String payload1 = "{\"start\":\"" + siQuery + "\",\"query\":\"" + vnfQuery + "\"}";
- Response resp1 = doAaiPut(certiPath, "query?format=simple", payload1, false);
- AaiResponse aaiResponse1 = proccessAaiResponse(resp1, AaiGetVnfResponse.class, null);
+ Response resp1 = doAaiPut(QUERY_FORMAT_SIMPLE, payload1, false);
+ AaiResponse aaiResponse1 = processAaiResponse(resp1, AaiGetVnfResponse.class, null);
logger.debug(EELFLoggerDelegate.debugLogger, "getNodeTemplateInstances AAI's response: {}", aaiResponse1);
return aaiResponse1;
}
- private AaiResponse proccessAaiResponse(Response resp, Class classType, String responseBody) {
- AaiResponse subscriberDataResponse = null;
+ @Override
+ public AaiResponse<JsonNode> getCloudRegionAndSourceByPortMirroringConfigurationId(String configurationId) {
+ final String start = "[\"network/configurations/configuration/" + configurationId + "\"]";
+ final String query = "\"query/cloud-region-and-source-FromConfiguration\"";
+ String payload = "{\"start\":" + start + ",\"query\":" + query + "}";
+
+ Response response = doAaiPut("query?format=simple&nodesOnly=true", payload, false);
+ AaiResponse<JsonNode> aaiResponse = processAaiResponse(response, JsonNode.class, null);
+
+ logger.debug(EELFLoggerDelegate.debugLogger, "getNodeTemplateInstances AAI's response: {}", aaiResponse);
+ return aaiResponse;
+ }
+
+ private <T> AaiResponseWithRequestInfo<T> processAaiResponse(ResponseWithRequestInfo responseWithRequestInfo, Class<? extends T> classType, boolean propagateExceptions) {
+ String responseBody = null;
+ Integer responseHttpCode = null;
+ try {
+ Response response = responseWithRequestInfo.getResponse();
+ responseHttpCode = (response != null) ? response.getStatus() : null;
+ responseBody = (response != null) ? response.readEntity(String.class) : null;
+ AaiResponse<T> processedAaiResponse = processAaiResponse(response, classType, responseBody, VidObjectMapperType.CODEHAUS, propagateExceptions);
+ return new AaiResponseWithRequestInfo<>(responseWithRequestInfo.getRequestHttpMethod(), responseWithRequestInfo.getRequestUrl(), processedAaiResponse,
+ responseBody);
+ } catch (Exception e) {
+ throw new ExceptionWithRequestInfo(responseWithRequestInfo.getRequestHttpMethod(),
+ responseWithRequestInfo.getRequestUrl(), responseBody, responseHttpCode, e);
+ }
+ }
+
+ private AaiResponse processAaiResponse(Response resp, Class classType, String responseBody) {
+ return processAaiResponse(resp, classType, responseBody, VidObjectMapperType.CODEHAUS);
+ }
+
+ private AaiResponse processAaiResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType) {
+ return processAaiResponse(resp, classType, responseBody, omType, false);
+ }
+
+ private AaiResponse processAaiResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) {
+ AaiResponse subscriberDataResponse;
if (resp == null) {
subscriberDataResponse = new AaiResponse<>(null, null, HttpStatus.SC_INTERNAL_SERVER_ERROR);
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "Invalid response from AAI");
@@ -305,54 +414,81 @@ public class AaiClient implements AaiClientInterface {
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString());
if (resp.getStatus() != HttpStatus.SC_OK) {
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "Invalid response from AAI");
- subscriberDataResponse = new AaiResponse<>(null, resp.readEntity(String.class), resp.getStatus());
+ String rawData = resp.readEntity(String.class);
+ subscriberDataResponse = new AaiResponse<>(null, rawData, resp.getStatus());
} else {
- String finalResponse = null;
- try {
- if (responseBody != null) {
- finalResponse = responseBody;
- } else {
- finalResponse = resp.readEntity(String.class);
- }
+ subscriberDataResponse = processOkResponse(resp, classType, responseBody, omType, propagateExceptions);
+ }
+ }
+ return subscriberDataResponse;
+ }
- subscriberDataResponse = new AaiResponse<>((new ObjectMapper().readValue(finalResponse, classType)), null, HttpStatus.SC_OK);
+ private AaiResponse processOkResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) {
+ AaiResponse subscriberDataResponse;
+ String finalResponse = null;
+ try {
+ if (responseBody != null) {
+ finalResponse = responseBody;
+ } else {
+ finalResponse = resp.readEntity(String.class);
+ }
- } catch(Exception e){
- subscriberDataResponse = new AaiResponse<>(null, null, HttpStatus.SC_INTERNAL_SERVER_ERROR);
- logger.error("Failed to parse aai response: \"{}\" to class {}", finalResponse, classType, e);
- }
+ if(omType == VidObjectMapperType.CODEHAUS)
+ subscriberDataResponse = parseCodeHausObject(classType, finalResponse);
+ else
+ subscriberDataResponse = parseFasterXmlObject(classType, finalResponse);
+
+ } catch(Exception e){
+ if (propagateExceptions) {
+ throw new GenericUncheckedException(e);
+ } else {
+ subscriberDataResponse = new AaiResponse<>(null, null, HttpStatus.SC_INTERNAL_SERVER_ERROR);
+ logger.error("Failed to parse aai response: \"{}\" to class {}", finalResponse, classType, e);
}
}
return subscriberDataResponse;
}
- private File getCertificatesFile() {
- if (servletContext != null)
- return new File(servletContext.getRealPath("/WEB-INF/cert/"));
- return null;
+ private AaiResponse parseFasterXmlObject(Class classType, String finalResponse) throws IOException {
+ com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper();
+ return new AaiResponse<>((objectMapper.readValue(finalResponse, classType)), null, HttpStatus.SC_OK);
+ }
+
+ private AaiResponse parseCodeHausObject(Class classType, String finalResponse) throws IOException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ return new AaiResponse<>((objectMapper.readValue(finalResponse, classType)), null, HttpStatus.SC_OK);
}
- @SuppressWarnings("all")
- public Response doAaiGet(String certiPath, String uri, boolean xml) {
+ public Response doAaiGet(String uri, boolean xml) {
+ return doAaiGet(uri, xml, false).getResponse();
+ }
+
+
+ public ResponseWithRequestInfo doAaiGet(String uri, boolean xml, boolean propagateExceptions) {
String methodName = "doAaiGet";
String transId = UUID.randomUUID().toString();
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
- Response resp = null;
+ ResponseWithRequestInfo resp;
try {
+ resp = restController.RestGet(fromAppId, transId, uri, xml, propagateExceptions);
- AAIRestInterface restContrller = new AAIRestInterface(certiPath);
- resp = restContrller.RestGet(fromAppId, transId, uri, xml);
-
- } catch (WebApplicationException e) {
- final String message = ((BadRequestException) e).getResponse().readEntity(String.class);
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
} catch (Exception e) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
- }
+ if (propagateExceptions) {
+ throw (e instanceof RuntimeException) ? (RuntimeException)e : new GenericUncheckedException(e);
+ } else {
+ final Exception actual =
+ e instanceof ExceptionWithRequestInfo ? (Exception) e.getCause() : e;
+
+ final String message =
+ actual instanceof WebApplicationException ? ((WebApplicationException) actual).getResponse().readEntity(String.class) : e.toString();
+ //ToDo: change parameter of requestUrl to real url from RestGet function
+ resp = new ResponseWithRequestInfo(null, null, org.springframework.http.HttpMethod.GET);
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + message);
+ }
+ }
return resp;
}
@@ -366,13 +502,12 @@ public class AaiClient implements AaiClientInterface {
return parseServiceSubscriptionObjectForTenants(jsonObject);
} catch (Exception ex) {
-
+ logger.debug(EELFLoggerDelegate.debugLogger, "parseForTenantsByServiceSubscription error while parsing tenants by service subscription", ex);
}
-
return tenantList;
}
- protected Response doAaiPut(String certiPath, String uri, String payload, boolean xml) {
+ protected Response doAaiPut(String uri, String payload, boolean xml) {
String methodName = "doAaiPut";
String transId = UUID.randomUUID().toString();
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
@@ -380,95 +515,31 @@ public class AaiClient implements AaiClientInterface {
Response resp = null;
try {
- AAIRestInterface restContrller = new AAIRestInterface(certiPath);
- resp = restContrller.RestPut(fromAppId, transId, uri, payload, xml);
+ resp = restController.RestPut(fromAppId, uri, payload, xml);
} catch (Exception e) {
logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
}
-
return resp;
}
- public static String parseServiceSubscriptionObjectForTenants(JSONObject jsonObject) {
-
+ private String parseServiceSubscriptionObjectForTenants(JSONObject jsonObject) {
JSONArray tenantArray = new JSONArray();
boolean bconvert = false;
-
try {
JSONObject relationShipListsObj = (JSONObject) jsonObject.get("relationship-list");
if (relationShipListsObj != null) {
JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship");
- if (rShipArray != null) {
- Iterator i1 = rShipArray.iterator();
-
- while (i1.hasNext()) {
-
- JSONObject inner1Obj = (JSONObject) i1.next();
-
- if (inner1Obj == null)
- continue;
-
- String relatedTo = checkForNull((String) inner1Obj.get("related-to"));
- if (relatedTo.equalsIgnoreCase("tenant")) {
- JSONObject tenantNewObj = new JSONObject();
-
- String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
- tenantNewObj.put("link", relatedLink);
-
- JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
- if (rDataArray != null) {
- Iterator i2 = rDataArray.iterator();
-
- while (i2.hasNext()) {
- JSONObject inner2Obj = (JSONObject) i2.next();
-
- if (inner2Obj == null)
- continue;
-
- String rShipKey = checkForNull((String) inner2Obj.get("relationship-key"));
- String rShipVal = checkForNull((String) inner2Obj.get("relationship-value"));
- if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner")) {
- tenantNewObj.put("cloudOwner", rShipVal);
- } else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id")) {
- tenantNewObj.put("cloudRegionID", rShipVal);
- }
-
- if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) {
- tenantNewObj.put("tenantID", rShipVal);
- }
- }
- }
-
- JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
- if (relatedTPropArray != null) {
- Iterator i3 = relatedTPropArray.iterator();
-
- while (i3.hasNext()) {
- JSONObject inner3Obj = (JSONObject) i3.next();
-
- if (inner3Obj == null)
- continue;
-
- String propKey = checkForNull((String) inner3Obj.get("property-key"));
- String propVal = checkForNull((String) inner3Obj.get("property-value"));
- if (propKey.equalsIgnoreCase("tenant.tenant-name")) {
- tenantNewObj.put("tenantName", propVal);
- }
- }
- }
- bconvert = true;
- tenantArray.add(tenantNewObj);
- }
+ for (Object innerObj : defaultIfNull(rShipArray, emptyList())) {
+ if (innerObj != null) {
+ bconvert = parseTenant(tenantArray, bconvert, (JSONObject) innerObj);
}
-
}
}
} catch (NullPointerException ex) {
-
-
+ logger.debug(EELFLoggerDelegate.debugLogger, "parseServiceSubscriptionObjectForTenants. error while parsing service subscription object for tenants", ex);
}
if (bconvert)
@@ -478,12 +549,99 @@ public class AaiClient implements AaiClientInterface {
}
+ private static boolean parseTenant(JSONArray tenantArray, boolean bconvert, JSONObject inner1Obj) {
+ String relatedTo = checkForNull((String) inner1Obj.get("related-to"));
+ if (relatedTo.equalsIgnoreCase("tenant")) {
+ JSONObject tenantNewObj = new JSONObject();
+
+ String relatedLink = checkForNull((String) inner1Obj.get("related-link"));
+ tenantNewObj.put("link", relatedLink);
+
+ JSONArray rDataArray = (JSONArray) inner1Obj.get("relationship-data");
+ for (Object innerObj : defaultIfNull(rDataArray, emptyList())) {
+ parseRelationShip(tenantNewObj, (JSONObject) innerObj);
+ }
+
+ JSONArray relatedTPropArray = (JSONArray) inner1Obj.get("related-to-property");
+ for (Object innerObj : defaultIfNull(relatedTPropArray, emptyList())) {
+ parseRelatedTProp(tenantNewObj, (JSONObject) innerObj);
+ }
+ bconvert = true;
+ tenantArray.add(tenantNewObj);
+ }
+ return bconvert;
+ }
+
+ private static void parseRelatedTProp(JSONObject tenantNewObj, JSONObject innerObj) {
+ if (innerObj == null)
+ return;
+
+ String propKey = checkForNull((String) innerObj.get("property-key"));
+ String propVal = checkForNull((String) innerObj.get("property-value"));
+ if (propKey.equalsIgnoreCase("tenant.tenant-name")) {
+ tenantNewObj.put("tenantName", propVal);
+ }
+ }
+
+ private static void parseRelationShip(JSONObject tenantNewObj, JSONObject inner2Obj) {
+ if (inner2Obj == null)
+ return;
+
+ String rShipKey = checkForNull((String) inner2Obj.get("relationship-key"));
+ String rShipVal = checkForNull((String) inner2Obj.get("relationship-value"));
+ if (rShipKey.equalsIgnoreCase("cloud-region.cloud-owner")) {
+ tenantNewObj.put("cloudOwner", rShipVal);
+ } else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id")) {
+ tenantNewObj.put("cloudRegionID", rShipVal);
+ }
+
+ if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) {
+ tenantNewObj.put("tenantID", rShipVal);
+ }
+ }
+
private static String encodePathSegment(String segmentToEncode) {
try {
return UriUtils.encodePathSegment(segmentToEncode, "UTF-8");
} catch (UnsupportedEncodingException e) {
- throw new RuntimeException("URI encoding failed unexpectedly", e);
+ throw new GenericUncheckedException("URI encoding failed unexpectedly", e);
}
}
+ @Override
+ public ExternalComponentStatus probeAaiGetAllSubscribers(){
+ long startTime = System.currentTimeMillis();
+ try {
+ AaiResponseWithRequestInfo<SubscriberList> responseWithRequestInfo = getAllSubscribers(true);
+ AaiResponse<SubscriberList> aaiResponse = responseWithRequestInfo.getAaiResponse();
+ long duration = System.currentTimeMillis() - startTime;
+
+ SubscriberList subscribersList = (aaiResponse != null) ? aaiResponse.getT() : null;
+ boolean isAvailable = subscribersList != null && subscribersList.customer != null && !subscribersList.customer.isEmpty();
+
+ HttpRequestMetadata metadata = new HttpRequestMetadata(
+ responseWithRequestInfo.getHttpMethod(),
+ (aaiResponse != null) ? aaiResponse.getHttpCode() : 0,
+ responseWithRequestInfo.getRequestedUrl(),
+ StringUtils.substring(responseWithRequestInfo.getRawData(), 0, 500),
+ isAvailable ? "OK" : "No subscriber received",
+ duration
+ );
+ return new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, isAvailable, metadata);
+
+ } catch (ExceptionWithRequestInfo e) {
+ long duration = System.currentTimeMillis() - startTime;
+ return new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, false,
+ new HttpRequestMetadata(
+ e.getHttpMethod(),
+ defaultIfNull(e.getHttpCode(), 0),
+ e.getRequestedUrl(),
+ e.getRawData(),
+ Logging.exceptionToDescription(e.getCause()), duration));
+ } catch (Exception e) {
+ long duration = System.currentTimeMillis() - startTime;
+ return new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, false,
+ new ErrorMetadata(Logging.exceptionToDescription(e), duration));
+ }
+ }
} \ No newline at end of file
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
index 5095f48b..901591a8 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiClientInterface.java
@@ -1,16 +1,16 @@
package org.onap.vid.aai;
-import org.codehaus.jackson.JsonParseException;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
+import org.codehaus.jackson.JsonNode;
import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
-import org.onap.vid.aai.model.AaiGetServicesRequestModel.GetServicesAAIRespone;
+import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.onap.vid.aai.model.AaiNodeQueryResponse;
+import org.onap.vid.aai.model.PortDetailsTranslator;
+import org.onap.vid.aai.model.ResourceType;
import org.onap.vid.model.SubscriberList;
+import org.onap.vid.model.probes.ExternalComponentStatus;
import javax.ws.rs.core.Response;
-
-import java.io.IOException;
import java.util.List;
/**
@@ -18,6 +18,8 @@ import java.util.List;
*/
public interface AaiClientInterface {
+ AaiResponse<AaiNodeQueryResponse> searchNodeTypeByName(String name, ResourceType type);
+
AaiResponse<SubscriberList> getAllSubscribers();
AaiResponse getSubscriberData(String subscriberId);
@@ -36,6 +38,10 @@ public interface AaiClientInterface {
AaiResponse getVNFData();
+ AaiResponse getNetworkCollectionDetails(String serviceInstanceId);
+
+ AaiResponse getInstanceGroupsByCloudRegion(String cloudOwner, String cloudRegionId, String networkFunction);
+
Response getVNFData(String globalSubscriberId, String serviceType);
AaiResponse getVNFData(String globalSubscriberId, String serviceType, String serviceInstanceId);
@@ -55,4 +61,12 @@ public interface AaiClientInterface {
AaiResponse getServiceInstance(String globalCustomerId, String serviceType, String serviceInstanceId);
AaiResponse getLogicalLink(String link);
+
+ AaiResponse<JsonNode> getCloudRegionAndSourceByPortMirroringConfigurationId(String configurationId);
+
+ List<PortDetailsTranslator.PortDetails> getPortMirroringSourcePorts(String configurationID);
+
+ AaiResponse getInstanceGroupsByVnfInstanceId(String vnfInstanceId);
+
+ ExternalComponentStatus probeAaiGetAllSubscribers();
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java
index 14e8e5dc..08585206 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiGetVnfResponse.java
@@ -17,7 +17,7 @@ public class AaiGetVnfResponse {
@JsonProperty("results")
public List<VnfResult> results = null;
@JsonIgnore
- private Map<String, Object> additionalProperties = new HashMap<String, Object>();
+ private Map<String, Object> additionalProperties = new HashMap<>();
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseTranslator.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseTranslator.java
new file mode 100644
index 00000000..6f503799
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseTranslator.java
@@ -0,0 +1,103 @@
+package org.onap.vid.aai;
+
+import org.apache.commons.lang3.StringUtils;
+import org.codehaus.jackson.JsonNode;
+import org.springframework.stereotype.Component;
+
+import java.util.Optional;
+
+@Component
+public class AaiResponseTranslator {
+
+ public PortMirroringConfigData extractPortMirroringConfigData(AaiResponse<JsonNode> aaiResponse) {
+ return extractErrorResponseIfHttpError(aaiResponse).orElseGet(() -> extractPortMirroringConfigData(aaiResponse.getT()));
+ }
+
+ public PortMirroringConfigData extractPortMirroringConfigData(JsonNode cloudRegionAndSourceFromConfigurationResponse) {
+ final JsonNode payload = cloudRegionAndSourceFromConfigurationResponse;
+ if (payload == null) {
+ return new PortMirroringConfigDataError("Response payload is null", null);
+ }
+
+ final JsonNode results = payload.path("results");
+ if (results.isMissingNode()) {
+ return new PortMirroringConfigDataError("Root node 'results' is missing", payload.toString());
+ }
+
+ for (JsonNode resultNode : results) {
+ final JsonNode nodeType = resultNode.path("node-type");
+ if (nodeType.isTextual() && "cloud-region".equals(nodeType.getTextValue())) {
+ return getPortMirroringConfigData(payload, resultNode);
+ }
+ }
+ return new PortMirroringConfigDataError("Root node 'results' has no node where 'node-TYPE' is 'cloud-region'", payload.toString());
+ }
+
+ private PortMirroringConfigData getPortMirroringConfigData(JsonNode payload, JsonNode resultNode) {
+ final JsonNode properties = resultNode.path("properties");
+ if (properties.isMissingNode()) {
+ final String message = "The node-type 'cloud-region' does not contain a 'properties' node";
+ return new PortMirroringConfigDataError(message, payload.toString());
+ }
+
+ final JsonNode cloudRegionIdNode = properties.path("cloud-region-id");
+ if (cloudRegionIdNode.isMissingNode()) {
+ return new PortMirroringConfigDataError("The node-type 'cloud-region' does not contain the property 'cloud-region-id'", payload.toString());
+ }
+ if (!cloudRegionIdNode.isTextual()) {
+ return new PortMirroringConfigDataError("The node-type 'cloud-region' contains a non-textual value for the property 'cloud-region-id'", payload.toString());
+ }
+
+ final String cloudRegionId = cloudRegionIdNode.asText();
+ if (StringUtils.isBlank(cloudRegionId)) {
+ return new PortMirroringConfigDataError("Node 'properties.cloud-region-id' of node-type 'cloud-region' is blank", payload.toString());
+ }
+
+ return new PortMirroringConfigDataOk(cloudRegionId);
+ }
+
+ private Optional<PortMirroringConfigData> extractErrorResponseIfHttpError(AaiResponse aaiResponse) {
+ if (aaiResponse.getHttpCode() != org.springframework.http.HttpStatus.OK.value()) {
+ final String errorMessage = aaiResponse.getErrorMessage();
+ return Optional.of(new PortMirroringConfigDataError(
+ "Got " + aaiResponse.getHttpCode() + " from aai",
+ errorMessage != null ? errorMessage.toString() : null)
+ );
+ } else {
+ return Optional.empty();
+ }
+ }
+
+ public abstract static class PortMirroringConfigData {
+ }
+
+ public static class PortMirroringConfigDataOk extends PortMirroringConfigData {
+ private final String cloudRegionId;
+
+ public PortMirroringConfigDataOk(String cloudRegionId) {
+ this.cloudRegionId = cloudRegionId;
+ }
+
+ public String getCloudRegionId() {
+ return cloudRegionId;
+ }
+ }
+
+ public static class PortMirroringConfigDataError extends PortMirroringConfigData {
+ private final String errorDescription;
+ private final String rawAaiResponse;
+
+ public PortMirroringConfigDataError(String errorDescription, String rawAaiResponse) {
+ this.errorDescription = errorDescription;
+ this.rawAaiResponse = rawAaiResponse;
+ }
+
+ public String getErrorDescription() {
+ return errorDescription;
+ }
+
+ public String getRawAaiResponse() {
+ return rawAaiResponse;
+ }
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseWithRequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseWithRequestInfo.java
new file mode 100644
index 00000000..cd1f9044
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiResponseWithRequestInfo.java
@@ -0,0 +1,44 @@
+package org.onap.vid.aai;
+
+
+import org.springframework.http.HttpMethod;
+
+import java.io.Serializable;
+
+public class AaiResponseWithRequestInfo<T> implements Serializable {
+ private AaiResponse<T> aaiResponse;
+ private String requestedUrl;
+ private String rawData;
+ private HttpMethod httpMethod;
+
+ public AaiResponseWithRequestInfo(HttpMethod httpMethod, String requestedUrl, AaiResponse<T> aaiResponse, String rawData) {
+ this.aaiResponse = aaiResponse;
+ this.requestedUrl = requestedUrl;
+ this.rawData = rawData;
+ this.httpMethod = httpMethod;
+ }
+
+ public void setRequestedUrl(String requestedUrl) {
+ this.requestedUrl = requestedUrl;
+ }
+
+ public void setHttpMethod(HttpMethod httpMethod) {
+ this.httpMethod = httpMethod;
+ }
+
+ public AaiResponse<T> getAaiResponse() {
+ return aaiResponse;
+ }
+
+ public String getRequestedUrl() {
+ return requestedUrl;
+ }
+
+ public String getRawData() {
+ return rawData;
+ }
+
+ public HttpMethod getHttpMethod() {
+ return httpMethod;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java
new file mode 100644
index 00000000..dcca3ec4
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/ExceptionWithRequestInfo.java
@@ -0,0 +1,54 @@
+package org.onap.vid.aai;
+
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.http.HttpMethod;
+
+import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
+
+public class ExceptionWithRequestInfo extends RuntimeException {
+
+ private final HttpMethod httpMethod;
+ private final String requestedUrl;
+ private final Integer httpCode;
+ private final String rawData;
+
+ public ExceptionWithRequestInfo(HttpMethod httpMethod, String requestedUrl, String rawData, Integer httpCode, Throwable cause) {
+ super(toMessage(httpMethod, requestedUrl, cause), cause);
+ this.httpMethod = httpMethod;
+ this.requestedUrl = requestedUrl;
+ this.rawData = rawData;
+ this.httpCode = httpCode;
+ }
+
+ public ExceptionWithRequestInfo(HttpMethod httpMethod, String requestedUrl, Throwable cause) {
+ this(httpMethod, requestedUrl, null, null, cause);
+ }
+
+ public String getRequestedUrl() {
+ return requestedUrl;
+ }
+
+ public String getRawData() {
+ return rawData;
+ }
+
+ public HttpMethod getHttpMethod() {
+ return httpMethod;
+ }
+
+ public Integer getHttpCode() {
+ return httpCode;
+ }
+
+ private static String toMessage(HttpMethod httpMethod, String requestedUrl, Throwable cause) {
+ if (StringUtils.isEmpty(requestedUrl)) {
+ return cause.toString();
+ } else {
+ return "" +
+ "Exception while handling " +
+ defaultIfNull(httpMethod, "request").toString() +
+ " " + requestedUrl +
+ ": " + cause.toString();
+ }
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java b/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java
new file mode 100644
index 00000000..28b6f542
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientImpl.java
@@ -0,0 +1,50 @@
+package org.onap.vid.aai;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.onap.vid.model.PombaInstance.PombaRequest;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import javax.servlet.ServletContext;
+import javax.ws.rs.core.Response;
+import java.io.File;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class PombaClientImpl implements PombaClientInterface {
+
+ final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
+ protected String fromAppId = "VidAaiController";
+ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AaiClient.class);
+
+ @Autowired
+ ServletContext servletContext;
+
+ @Autowired
+ PombaRestInterface pombaRestInterface;
+
+
+ @Override
+ public void verify(PombaRequest request) {
+ String methodName = "doAaiPost";
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start");
+ String uri = SystemProperties.getProperty("pomba.server.url");
+
+
+ try {
+ Response response = pombaRestInterface.RestPost(fromAppId, uri, new ObjectMapper().writeValueAsString(request));
+ } catch (Exception e) {
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString());
+ }
+ }
+
+
+ private File getCertificatesFile() {
+ if (servletContext != null)
+ return new File(servletContext.getRealPath("/WEB-INF/cert/"));
+ return null;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientInterface.java
new file mode 100644
index 00000000..328f31ac
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/PombaClientInterface.java
@@ -0,0 +1,7 @@
+package org.onap.vid.aai;
+
+import org.onap.vid.model.PombaInstance.PombaRequest;
+
+public interface PombaClientInterface {
+ void verify(PombaRequest request);
+} \ No newline at end of file
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java
new file mode 100644
index 00000000..73ebf69d
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java
@@ -0,0 +1,73 @@
+package org.onap.vid.aai;
+
+import org.onap.vid.aai.util.AAIRestInterface;
+import org.onap.vid.aai.util.HttpClientMode;
+import org.onap.vid.aai.util.HttpsAuthClient;
+import org.onap.vid.utils.Logging;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.springframework.http.HttpMethod;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.Date;
+import java.util.UUID;
+
+import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
+
+public class PombaRestInterface extends AAIRestInterface {
+
+ public PombaRestInterface (HttpsAuthClient httpsAuthClientFactory) {
+ super(httpsAuthClientFactory);
+ }
+
+ private Client client = null;
+
+ private void initRestClient()
+ {
+ if (client == null) {
+ try {
+ client = httpsAuthClientFactory.getClient(HttpClientMode.UNSECURE);
+ }
+ catch (Exception e) {
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== Exception in REST call to DB in initRestClient" + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== Exception in REST call to DB : " + e.toString());
+ }
+ }
+ }
+
+
+ public Response RestPost(String fromAppId, String url, String payload) {
+ String methodName = "RestPost";
+ String transId = UUID.randomUUID().toString();
+ try {
+ String responseType = MediaType.APPLICATION_JSON;
+ initRestClient();
+
+ Logging.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload);
+ final Response cres = client.target(url)
+ .request()
+ .accept(responseType)
+ .header(TRANSACTION_ID_HEADER, transId)
+ .header(FROM_APP_ID_HEADER, fromAppId)
+ .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
+ .post(Entity.entity(payload, MediaType.APPLICATION_JSON));
+ Logging.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, cres);
+
+ if (cres.getStatus() == 200 && cres.getStatus() <= 299) {
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION);
+ } else {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " with status="+cres.getStatus()+ URL_DECLARATION +url);
+ }
+ return cres;
+ } catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION +url+ ", Exception: " + e.toString());
+ }
+ return null;
+ }
+
+}
+
+
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ResponseWithRequestInfo.java b/vid-app-common/src/main/java/org/onap/vid/aai/ResponseWithRequestInfo.java
new file mode 100644
index 00000000..eb57b34f
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/ResponseWithRequestInfo.java
@@ -0,0 +1,29 @@
+package org.onap.vid.aai;
+
+import org.springframework.http.HttpMethod;
+
+import javax.ws.rs.core.Response;
+
+public class ResponseWithRequestInfo {
+ private String requestUrl;
+ private HttpMethod requestHttpMethod;
+ private Response response;
+
+ public ResponseWithRequestInfo(Response response, String requestUrl, HttpMethod requestHttpMethod) {
+ this.response = response;
+ this.requestUrl = requestUrl;
+ this.requestHttpMethod = requestHttpMethod;
+ }
+
+ public String getRequestUrl() {
+ return requestUrl;
+ }
+
+ public HttpMethod getRequestHttpMethod() {
+ return requestHttpMethod;
+ }
+
+ public Response getResponse() {
+ return response;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java b/vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java
index e6296488..f80cae50 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/exceptions/InvalidAAIResponseException.java
@@ -1,7 +1,13 @@
package org.onap.vid.aai.exceptions;
+import org.onap.vid.aai.AaiResponse;
+import org.onap.vid.exceptions.GenericUncheckedException;
+
/**
* Created by Oren on 7/4/17.
*/
-public class InvalidAAIResponseException extends Exception {
+public class InvalidAAIResponseException extends GenericUncheckedException {
+ public InvalidAAIResponseException(AaiResponse aaiResponse) {
+ super(String.format("errorCode: %d, raw: %s", aaiResponse.getHttpCode(), aaiResponse.getErrorMessage()));
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetInstanceGroupsByCloudRegion.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetInstanceGroupsByCloudRegion.java
new file mode 100644
index 00000000..a1fec6b8
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetInstanceGroupsByCloudRegion.java
@@ -0,0 +1,20 @@
+package org.onap.vid.aai.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class AaiGetInstanceGroupsByCloudRegion {
+
+ private final List<InstanceGroupWrapper> results;
+
+ public AaiGetInstanceGroupsByCloudRegion(@JsonProperty("results") List<InstanceGroupWrapper> results) {
+ this.results = results;
+ }
+
+ public List<InstanceGroupWrapper> getResults() {
+ return results;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetNetworkCollectionDetails.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetNetworkCollectionDetails.java
new file mode 100644
index 00000000..a1047862
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetNetworkCollectionDetails.java
@@ -0,0 +1,23 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+public class AaiGetNetworkCollectionDetails {
+
+ public AaiGetNetworkCollectionDetails(){
+ results = new Result();
+ }
+ @JsonProperty("results")
+ private Result results = null;
+
+ @JsonProperty("results")
+ public Result getResults() {
+ return results;
+ }
+
+ @JsonProperty("results")
+ public void setResults(Result results) {
+ this.results = results;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetNetworkCollectionDetailsHelper.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetNetworkCollectionDetailsHelper.java
new file mode 100644
index 00000000..2d3cfb91
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetNetworkCollectionDetailsHelper.java
@@ -0,0 +1,38 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter;
+import com.fasterxml.jackson.annotation.JsonAnySetter;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class AaiGetNetworkCollectionDetailsHelper {
+ @JsonProperty("results")
+ private List<Object> results = null;
+ @JsonIgnore
+ private Map<String, Object> additionalProperties = new HashMap<String, Object>();
+
+ @JsonProperty("results")
+ public List<Object> getResults() {
+ return results;
+ }
+
+ @JsonProperty("results")
+ public void setResults(List<Object> results) {
+ this.results = results;
+ }
+
+ @JsonAnyGetter
+ public Map<String, Object> getAdditionalProperties() {
+ return this.additionalProperties;
+ }
+
+ @JsonAnySetter
+ public void setAdditionalProperty(String name, Object value) {
+ this.additionalProperties.put(name, value);
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetRelatedInstanceGroupsByVnfId.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetRelatedInstanceGroupsByVnfId.java
new file mode 100644
index 00000000..d5556511
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/AaiGetRelatedInstanceGroupsByVnfId.java
@@ -0,0 +1,181 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class AaiGetRelatedInstanceGroupsByVnfId {
+
+ @JsonProperty("vnf-id")
+ private String vnfId;
+ @JsonProperty("vnf-name")
+ private String vnfName;
+ @JsonProperty("vnf-type")
+ private String vnfType;
+ @JsonProperty("prov-status")
+ private String provStatus;
+ @JsonProperty("operational-status")
+ private String operationalStatus;
+ @JsonProperty("equipment-role")
+ private String equipmentRole;
+ @JsonProperty("in-maint")
+ private Boolean inMaint;
+ @JsonProperty("is-closed-loop-disabled")
+ private Boolean isClosedLoopDisabled;
+ @JsonProperty("resource-version")
+ private String resourceVersion;
+ @JsonProperty("model-invariant-id")
+ private String modelInvariantId;
+ @JsonProperty("model-version-id")
+ private String modelVersionId;
+ @JsonProperty("model-customization-id")
+ private String modelCustomizationId;
+ @JsonProperty("selflink")
+ private String selflink;
+ @JsonProperty("relationship-list")
+ private RelationshipList relationshipList;
+
+
+ @JsonProperty("vnf-id")
+ public String getVnfId() {
+ return vnfId;
+ }
+
+ @JsonProperty("vnf-id")
+ public void setVnfId(String vnfId) {
+ this.vnfId = vnfId;
+ }
+
+ @JsonProperty("vnf-name")
+ public String getVnfName() {
+ return vnfName;
+ }
+
+ @JsonProperty("vnf-name")
+ public void setVnfName(String vnfName) {
+ this.vnfName = vnfName;
+ }
+
+ @JsonProperty("vnf-type")
+ public String getVnfType() {
+ return vnfType;
+ }
+
+ @JsonProperty("vnf-type")
+ public void setVnfType(String vnfType) {
+ this.vnfType = vnfType;
+ }
+
+ @JsonProperty("prov-status")
+ public String getProvStatus() {
+ return provStatus;
+ }
+
+ @JsonProperty("prov-status")
+ public void setProvStatus(String provStatus) {
+ this.provStatus = provStatus;
+ }
+
+ @JsonProperty("operational-status")
+ public String getOperationalStatus() {
+ return operationalStatus;
+ }
+
+ @JsonProperty("operational-status")
+ public void setOperationalStatus(String operationalStatus) {
+ this.operationalStatus = operationalStatus;
+ }
+
+ @JsonProperty("equipment-role")
+ public String getEquipmentRole() {
+ return equipmentRole;
+ }
+
+ @JsonProperty("equipment-role")
+ public void setEquipmentRole(String equipmentRole) {
+ this.equipmentRole = equipmentRole;
+ }
+
+ @JsonProperty("in-maint")
+ public Boolean getInMaint() {
+ return inMaint;
+ }
+
+ @JsonProperty("in-maint")
+ public void setInMaint(Boolean inMaint) {
+ this.inMaint = inMaint;
+ }
+
+ @JsonProperty("is-closed-loop-disabled")
+ public Boolean getIsClosedLoopDisabled() {
+ return isClosedLoopDisabled;
+ }
+
+ @JsonProperty("is-closed-loop-disabled")
+ public void setIsClosedLoopDisabled(Boolean isClosedLoopDisabled) {
+ this.isClosedLoopDisabled = isClosedLoopDisabled;
+ }
+
+ @JsonProperty("resource-version")
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ @JsonProperty("resource-version")
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ @JsonProperty("model-invariant-id")
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ @JsonProperty("model-invariant-id")
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ @JsonProperty("model-version-id")
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ @JsonProperty("model-version-id")
+ public void setModelVersionId(String modelVersionId) {
+ this.modelVersionId = modelVersionId;
+ }
+
+ @JsonProperty("model-customization-id")
+ public String getModelCustomizationId() {
+ return modelCustomizationId;
+ }
+
+ @JsonProperty("model-customization-id")
+ public void setModelCustomizationId(String modelCustomizationId) {
+ this.modelCustomizationId = modelCustomizationId;
+ }
+
+ @JsonProperty("selflink")
+ public String getSelflink() {
+ return selflink;
+ }
+
+ @JsonProperty("selflink")
+ public void setSelflink(String selflink) {
+ this.selflink = selflink;
+ }
+
+ @JsonProperty("relationship-list")
+ public RelationshipList getRelationshipList() {
+ return relationshipList;
+ }
+
+ @JsonProperty("relationship-list")
+ public void setRelationshipList(RelationshipList relationshipList) {
+ this.relationshipList = relationshipList;
+ }
+
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Collection.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Collection.java
new file mode 100644
index 00000000..7badaa29
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Collection.java
@@ -0,0 +1,130 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Collection {
+ @JsonProperty("collection-id")
+ private String collectionId;
+ @JsonProperty("model-invariant-id")
+ private String modelInvariantId;
+ @JsonProperty("model-version-id")
+ private String modelVersionId;
+ @JsonProperty("collection-name")
+ private String collectionName;
+ @JsonProperty("collection-type")
+ private String collectionType;
+ @JsonProperty("collection-role")
+ private String collectionRole;
+ @JsonProperty("collection-function")
+ private String collectionFunction;
+ @JsonProperty("collection-customization-id")
+ private String collectionCustomizationId;
+ @JsonProperty("relationship-list")
+ private RelationshipList relationshipList;
+ @JsonProperty("resource-version")
+ private String resourceVersion;
+
+ @JsonProperty("collection-id")
+ public String getCollectionId() {
+ return collectionId;
+ }
+
+ @JsonProperty("collection-id")
+ public void setCollectionId(String collectionId) {
+ this.collectionId = collectionId;
+ }
+
+ @JsonProperty("model-invariant-id")
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ @JsonProperty("model-invariant-id")
+ public void setModelInvariantId(String modelInvariantId) {
+ this.modelInvariantId = modelInvariantId;
+ }
+
+ @JsonProperty("model-version-id")
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ @JsonProperty("model-version-id")
+ public void setModelVersionId(String modelVersionId) {
+ this.modelVersionId = modelVersionId;
+ }
+
+ @JsonProperty("collection-name")
+ public String getCollectionName() {
+ return collectionName;
+ }
+
+ @JsonProperty("collection-name")
+ public void setCollectionName(String collectionName) {
+ this.collectionName = collectionName;
+ }
+
+ @JsonProperty("collection-type")
+ public String getCollectionType() {
+ return collectionType;
+ }
+
+ @JsonProperty("collection-type")
+ public void setCollectionType(String collectionType) {
+ this.collectionType = collectionType;
+ }
+
+ @JsonProperty("collection-role")
+ public String getCollectionRole() {
+ return collectionRole;
+ }
+
+ @JsonProperty("collection-role")
+ public void setCollectionRole(String collectionRole) {
+ this.collectionRole = collectionRole;
+ }
+
+ @JsonProperty("collection-function")
+ public String getCollectionFunction() {
+ return collectionFunction;
+ }
+
+ @JsonProperty("collection-function")
+ public void setCollectionFunction(String collectionFunction) {
+ this.collectionFunction = collectionFunction;
+ }
+
+ @JsonProperty("collection-customization-id")
+ public String getCollectionCustomizationId() {
+ return collectionCustomizationId;
+ }
+
+ @JsonProperty("collection-customization-id")
+ public void setCollectionCustomizationId(String collectionCustomizationId) {
+ this.collectionCustomizationId = collectionCustomizationId;
+ }
+
+ @JsonProperty("relationship-list")
+ public RelationshipList getRelationshipList() {
+ return relationshipList;
+ }
+
+ @JsonProperty("relationship-list")
+ public void setRelationshipList(RelationshipList relationshipList) {
+ this.relationshipList = relationshipList;
+ }
+
+ @JsonProperty("resource-version")
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ @JsonProperty("resource-version")
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/InstanceGroup.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/InstanceGroup.java
new file mode 100644
index 00000000..b540fa40
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/InstanceGroup.java
@@ -0,0 +1,105 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class InstanceGroup {
+ @JsonProperty("instance-group-role")
+ private String instanceGroupRole;
+ @JsonProperty("model-invariant-id")
+ private String modelInvariantId;
+ @JsonProperty("model-version-id")
+ private String modelVersionId;
+ private String id;
+ private String description;
+ @JsonProperty("instance-group-type")
+ private String instanceGroupType;
+ @JsonProperty("resource-version")
+ private String resourceVersion;
+ @JsonProperty("instance-group-name")
+ private String instanceGroupName;
+ @JsonProperty("instance-group-function")
+ private String instanceGroupFunction;
+ @JsonProperty("relationship-list")
+ private RelationshipList relationshipList;
+
+ public InstanceGroup(){
+ super();
+ }
+
+ @JsonIgnoreProperties(ignoreUnknown = true)
+ public InstanceGroup(
+ @JsonProperty("instance-group-role")
+ String instanceGroupRole,
+ @JsonProperty("model-invariant-id")
+ String modelInvariantId,
+ @JsonProperty("model-version-id")
+ String modelVersionId,
+ @JsonProperty(value = "id", required = true)
+ String id,
+ @JsonProperty(value = "description", required = true)
+ String description,
+ @JsonProperty(value = "instance-group-type", required = true)
+ String instanceGroupType,
+ @JsonProperty("resource-version")
+ String resourceVersion,
+ @JsonProperty("instance-group-name")
+ String instanceGroupName,
+ @JsonProperty("instance-group-function")
+ String instanceGroupFunction,
+ @JsonProperty("relationship-list")
+ RelationshipList relationshipList) {
+ this.instanceGroupRole = instanceGroupRole;
+ this.modelInvariantId = modelInvariantId;
+ this.modelVersionId = modelVersionId;
+ this.id = id;
+ this.description = description;
+ this.instanceGroupType = instanceGroupType;
+ this.resourceVersion = resourceVersion;
+ this.instanceGroupName = instanceGroupName;
+ this.instanceGroupFunction = instanceGroupFunction;
+ this.relationshipList = relationshipList;
+ }
+
+ public String getInstanceGroupRole() {
+ return instanceGroupRole;
+ }
+
+ public String getModelInvariantId() {
+ return modelInvariantId;
+ }
+
+ public String getModelVersionId() {
+ return modelVersionId;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getInstanceGroupType() {
+ return instanceGroupType;
+ }
+
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ public String getInstanceGroupName() {
+ return instanceGroupName;
+ }
+
+ public String getInstanceGroupFunction() {
+ return instanceGroupFunction;
+ }
+
+ public RelationshipList getRelationshipList() {
+ return relationshipList;
+ }
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Network.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Network.java
new file mode 100644
index 00000000..29450a8f
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Network.java
@@ -0,0 +1,142 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Network {
+ @JsonProperty("network-id")
+ private String networkId;
+ @JsonProperty("network-name")
+ private String networkName;
+ @JsonProperty("network-type")
+ private String networkType;
+ @JsonProperty("network-role")
+ private String networkRole;
+ @JsonProperty("network-technology")
+ private String networkTechnology;
+ @JsonProperty("is-bound-to-vpn")
+ private Boolean isBoundToVpn;
+ @JsonProperty("resource-version")
+ private String resourceVersion;
+ @JsonProperty("is-provider-network")
+ private Boolean isProviderNetwork;
+ @JsonProperty("is-shared-network")
+ private Boolean isSharedNetwork;
+ @JsonProperty("is-external-network")
+ private Boolean isExternalNetwork;
+ @JsonProperty("relationship-list")
+ private RelationshipList relationshipList;
+
+
+ @JsonProperty("network-id")
+ public String getNetworkId() {
+ return networkId;
+ }
+
+ @JsonProperty("network-id")
+ public void setNetworkId(String networkId) {
+ this.networkId = networkId;
+ }
+
+ @JsonProperty("network-name")
+ public String getNetworkName() {
+ return networkName;
+ }
+
+ @JsonProperty("network-name")
+ public void setNetworkName(String networkName) {
+ this.networkName = networkName;
+ }
+
+ @JsonProperty("network-type")
+ public String getNetworkType() {
+ return networkType;
+ }
+
+ @JsonProperty("network-type")
+ public void setNetworkType(String networkType) {
+ this.networkType = networkType;
+ }
+
+ @JsonProperty("network-role")
+ public String getNetworkRole() {
+ return networkRole;
+ }
+
+ @JsonProperty("network-role")
+ public void setNetworkRole(String networkRole) {
+ this.networkRole = networkRole;
+ }
+
+ @JsonProperty("network-technology")
+ public String getNetworkTechnology() {
+ return networkTechnology;
+ }
+
+ @JsonProperty("network-technology")
+ public void setNetworkTechnology(String networkTechnology) {
+ this.networkTechnology = networkTechnology;
+ }
+
+ @JsonProperty("is-bound-to-vpn")
+ public Boolean getIsBoundToVpn() {
+ return isBoundToVpn;
+ }
+
+ @JsonProperty("is-bound-to-vpn")
+ public void setIsBoundToVpn(Boolean isBoundToVpn) {
+ this.isBoundToVpn = isBoundToVpn;
+ }
+
+ @JsonProperty("resource-version")
+ public String getResourceVersion() {
+ return resourceVersion;
+ }
+
+ @JsonProperty("resource-version")
+ public void setResourceVersion(String resourceVersion) {
+ this.resourceVersion = resourceVersion;
+ }
+
+ @JsonProperty("is-provider-network")
+ public Boolean getIsProviderNetwork() {
+ return isProviderNetwork;
+ }
+
+ @JsonProperty("is-provider-network")
+ public void setIsProviderNetwork(Boolean isProviderNetwork) {
+ this.isProviderNetwork = isProviderNetwork;
+ }
+
+ @JsonProperty("is-shared-network")
+ public Boolean getIsSharedNetwork() {
+ return isSharedNetwork;
+ }
+
+ @JsonProperty("is-shared-network")
+ public void setIsSharedNetwork(Boolean isSharedNetwork) {
+ this.isSharedNetwork = isSharedNetwork;
+ }
+
+ @JsonProperty("is-external-network")
+ public Boolean getIsExternalNetwork() {
+ return isExternalNetwork;
+ }
+
+ @JsonProperty("is-external-network")
+ public void setIsExternalNetwork(Boolean isExternalNetwork) {
+ this.isExternalNetwork = isExternalNetwork;
+ }
+
+ @JsonProperty("relationship-list")
+ public RelationshipList getRelationshipList() {
+ return relationshipList;
+ }
+
+ @JsonProperty("relationship-list")
+ public void setRelationshipList(RelationshipList relationshipList) {
+ this.relationshipList = relationshipList;
+ }
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelatedToProperty.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelatedToProperty.java
new file mode 100644
index 00000000..1c10500a
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelatedToProperty.java
@@ -0,0 +1,37 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RelatedToProperty {
+
+ public String getPropertyKey() {
+ return propertyKey;
+ }
+
+
+ public void setPropertyKey(String propertyKey) {
+ this.propertyKey = propertyKey;
+ }
+
+
+ public String getPropertyValue() {
+ return propertyValue;
+ }
+
+
+ public void setPropertyValue(String propertyValue) {
+ this.propertyValue = propertyValue;
+ }
+
+
+ @JsonProperty("property-key")
+ public String propertyKey;
+
+
+ @JsonProperty("property-value")
+ public String propertyValue;
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Relationship.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Relationship.java
new file mode 100644
index 00000000..56c08ed0
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Relationship.java
@@ -0,0 +1,67 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.List;
+
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Relationship {
+
+ @JsonProperty("related-to")
+ public String relatedTo;
+
+ @JsonProperty("related-link")
+ public String relatedLink;
+
+ @JsonProperty("relationship-label")
+ public String relationshipLabel;
+
+ @JsonProperty("relationship-data")
+ public List<RelationshipData> relationshipData;
+
+ @JsonProperty("related-to-property")
+ public List<RelatedToProperty> relatedToProperty;
+
+
+ public String getRelatedTo() {
+ return relatedTo;
+ }
+
+ public void setRelatedTo(String relatedTo) {
+ this.relatedTo = relatedTo;
+ }
+
+ public String getRelatedLink() {
+ return relatedLink;
+ }
+
+ public void setRelatedLink(String relatedLink) {
+ this.relatedLink = relatedLink;
+ }
+
+ public List<RelationshipData> getRelationDataList() {
+ return relationshipData;
+ }
+
+ public void setRelationDataList(List<RelationshipData> relationDataList) {
+ this.relationshipData = relationDataList;
+ }
+
+ public List<RelatedToProperty> getRelatedToPropertyList() {
+ return relatedToProperty;
+ }
+
+ public void setRelatedToPropertyList(List<RelatedToProperty> relatedToPropertyList) {
+ this.relatedToProperty = relatedToPropertyList;
+ }
+
+ public String getRelationshipLabel() {
+ return relationshipLabel;
+ }
+
+ public void setRelationshipLabel(String relationshipLabel) {
+ this.relationshipLabel = relationshipLabel;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipData.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipData.java
new file mode 100644
index 00000000..48cc000e
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipData.java
@@ -0,0 +1,29 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RelationshipData {
+ @JsonProperty("relationship-key")
+ public String getRelationshipKey() {
+ return relationshipKey;
+ }
+ @JsonProperty("relationship-key")
+ public void setRelationshipKey(String relationshipKey) {
+ this.relationshipKey = relationshipKey;
+ }
+ @JsonProperty("relationship-value")
+ public String getRelationshipValue() {
+ return relationshipValue;
+ }
+ @JsonProperty("relationship-value")
+ public void setRelationshipValue(String relationshipValue) {
+ this.relationshipValue = relationshipValue;
+ }
+
+ public String relationshipKey;
+
+ public String relationshipValue;
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java
new file mode 100644
index 00000000..df1e03a0
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/RelationshipList.java
@@ -0,0 +1,25 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RelationshipList {
+
+ @JsonProperty("relationship")
+ public List<Relationship> getRelationship() {
+ return relationship;
+ }
+
+ @JsonProperty("relationship")
+ public void setRelationship(List<Relationship> relationship) {
+ this.relationship = relationship;
+ }
+
+ public List<Relationship> relationship;
+
+
+
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Result.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Result.java
new file mode 100644
index 00000000..776493a5
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Result.java
@@ -0,0 +1,64 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Result {
+
+ @JsonProperty("service-instance")
+ private ServiceInstance serviceInstance;
+ @JsonProperty("collection")
+ private Collection collection;
+ @JsonProperty("instance-group")
+ private InstanceGroup instanceGroup;
+ @JsonProperty("networks")
+ private List<Network> networks;
+
+ public Result(){
+ this.networks = new ArrayList<>();
+ }
+
+
+ @JsonProperty("service-instance")
+ public ServiceInstance getServiceInstance() {
+ return serviceInstance;
+ }
+
+ @JsonProperty("service-instance")
+ public void setServiceInstance(ServiceInstance serviceInstance) {
+ this.serviceInstance = serviceInstance;
+ }
+
+ @JsonProperty("collection")
+ public Collection getCollection() {
+ return collection;
+ }
+
+ @JsonProperty("collection")
+ public void setCollection(Collection collection) {
+ this.collection = collection;
+ }
+
+ @JsonProperty("instance-group")
+ public InstanceGroup getInstanceGroup() {
+ return instanceGroup;
+ }
+
+ @JsonProperty("instance-group")
+ public void setInstanceGroup(InstanceGroup instanceGroup) {
+ this.instanceGroup = instanceGroup;
+ }
+
+ @JsonProperty("networks")
+ public List<Network> getNetworks() { return networks; }
+
+ @JsonProperty("networks")
+ public void setNetworks(List<Network> networks) { this.networks = networks; }
+
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/ServiceInstance.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/ServiceInstance.java
new file mode 100644
index 00000000..c366402e
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/ServiceInstance.java
@@ -0,0 +1,17 @@
+package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class ServiceInstance {
+
+ @JsonProperty("service-instance-id")
+ public String serviceInstanceId;
+
+ @JsonProperty("resource-version")
+ public String resourceVersion;
+
+ @JsonProperty("relationship-list")
+ public RelationshipList relationshipList;
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPortMirroringSourcePorts.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPortMirroringSourcePorts.java
new file mode 100644
index 00000000..47a57daf
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPortMirroringSourcePorts.java
@@ -0,0 +1,18 @@
+package org.onap.vid.aai.model;
+
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import java.util.List;
+
+public class AaiGetPortMirroringSourcePorts {
+
+ private final List<SimpleResult> results;
+
+ public AaiGetPortMirroringSourcePorts(@JsonProperty("results") List<SimpleResult> results) {
+ this.results = results;
+ }
+
+ public List<SimpleResult> getResults() {
+ return results;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiNodeQueryResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiNodeQueryResponse.java
new file mode 100644
index 00000000..18bf1619
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiNodeQueryResponse.java
@@ -0,0 +1,26 @@
+package org.onap.vid.aai.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import java.util.List;
+
+public class AaiNodeQueryResponse {
+
+ public static class ResultData {
+
+ public final ResourceType resourceType;
+ public final String resourceLink;
+
+ public ResultData(@JsonProperty("resource-type") ResourceType resourceType,
+ @JsonProperty("resource-link") String resourceLink) {
+ this.resourceType = resourceType;
+ this.resourceLink = resourceLink;
+ }
+ }
+
+ public final List<ResultData> resultData;
+
+ public AaiNodeQueryResponse(@JsonProperty("result-data") List<ResultData> resultData) {
+ this.resultData = resultData;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/InstanceGroupInfo.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/InstanceGroupInfo.java
new file mode 100644
index 00000000..c2eb7094
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/InstanceGroupInfo.java
@@ -0,0 +1,32 @@
+package org.onap.vid.aai.model;
+
+public class InstanceGroupInfo {
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ private String type;
+ private String name;
+
+ public InstanceGroupInfo(String name){
+ this.name = name;
+ this.type = "instance-group";
+ }
+
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+
+
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/InstanceGroupWrapper.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/InstanceGroupWrapper.java
new file mode 100644
index 00000000..879fa63a
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/InstanceGroupWrapper.java
@@ -0,0 +1,20 @@
+package org.onap.vid.aai.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.InstanceGroup;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class InstanceGroupWrapper {
+
+ private InstanceGroup instanceGroup;
+
+ @JsonProperty("instance-group")
+ public InstanceGroup getInstanceGroup() {
+ return instanceGroup;
+ }
+ @JsonProperty("instance-group")
+ public void setInstanceGroup(InstanceGroup instanceGroup) {
+ this.instanceGroup = instanceGroup;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/PortDetailsTranslator.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/PortDetailsTranslator.java
new file mode 100644
index 00000000..f8980457
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/PortDetailsTranslator.java
@@ -0,0 +1,138 @@
+package org.onap.vid.aai.model;
+
+
+import com.google.common.collect.ImmutableList;
+import org.onap.vid.aai.AaiResponse;
+import org.onap.vid.properties.Features;
+import org.togglz.core.manager.FeatureManager;
+
+import javax.inject.Inject;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
+
+public class PortDetailsTranslator {
+
+ @Inject
+ FeatureManager featureManager;
+
+ public static class PortDetailsOk extends PortDetails {
+
+ private final String interfaceId;
+ private final String interfaceName;
+ private final boolean isPortMirrored;
+
+ public PortDetailsOk(String interfaceId, String interfaceName, boolean isPortMirrored) {
+ this.interfaceId = interfaceId;
+ this.interfaceName = interfaceName;
+ this.isPortMirrored = isPortMirrored;
+ }
+
+ public String getInterfaceId() {
+ return interfaceId;
+ }
+
+ public String getInterfaceName() {
+ return interfaceName;
+ }
+
+ public boolean getIsPortMirrored() {
+ return isPortMirrored;
+ }
+ }
+
+ public abstract static class PortDetails {
+ }
+
+ public static class PortDetailsError extends PortDetails {
+ private final String errorDescription;
+ private final String rawAaiResponse;
+
+ public PortDetailsError(String errorDescription, String rawAaiResponse){
+ this.errorDescription = errorDescription;
+ this.rawAaiResponse = rawAaiResponse;
+ }
+
+ public String getErrorDescription() {
+ return errorDescription;
+ }
+
+ public String getRawAaiResponse() {
+ return rawAaiResponse;
+ }
+ }
+
+ public static PortDetails extractPortDetailsFromProperties(Properties properties, String rawPayload){
+ List<String> errorDescriptions = new LinkedList<>();
+ describeIfNullOrEmpty("interface-id", properties.getInterfaceId(), errorDescriptions);
+ describeIfNullOrEmpty("interface-name", properties.getInterfaceName(), errorDescriptions);
+ describeIfNullOrEmpty("is-port-mirrored", properties.getIsPortMirrored(), errorDescriptions);
+
+ if(errorDescriptions.isEmpty()){
+ return new PortDetailsOk(properties.getInterfaceId(), properties.getInterfaceName(), properties.getIsPortMirrored());
+ } else {
+ return new PortDetailsError(String.join(" ", errorDescriptions), rawPayload);
+ }
+ }
+
+ private static void describeIfNullOrEmpty(String name, Object value, List<String> errorDescriptions) {
+ if (value == null) {
+ errorDescriptions.add("Value of '" + name + "' is missing.");
+ } else if (value.toString().isEmpty()) {
+ errorDescriptions.add("Value of '" + name + "' is empty.");
+ }
+ }
+
+ private static Optional<List<PortDetails>> extractErrorResponseIfHttpError(AaiResponse aaiResponse, String rawPayload) {
+ if (aaiResponse.getHttpCode() != org.springframework.http.HttpStatus.OK.value()) {
+ final String errorMessage = aaiResponse.getErrorMessage();
+ return Optional.of(ImmutableList.of(new PortDetailsError(
+ "Got " + aaiResponse.getHttpCode() + " from aai",
+ errorMessage != null ? errorMessage.toString() : rawPayload)
+ ));
+ } else {
+ return Optional.empty();
+ }
+ }
+
+ public List<PortDetails> extractPortDetailsInternal(AaiGetPortMirroringSourcePorts aaiGetPortsResponse, String rawPayload){
+ List<SimpleResult> filteredResult = getFilteredPortList(aaiGetPortsResponse.getResults());
+
+ return filteredResult.stream()
+ .map(SimpleResult::getProperties)
+ .map(p -> extractPortDetailsFromProperties(p, rawPayload))
+ .collect(Collectors.toList());
+ }
+
+ public List<SimpleResult> getFilteredPortList(List<SimpleResult> results) {
+ String LINTERFACE = "l-interface";
+
+ final Predicate<SimpleResult> ifIsPort = (SimpleResult r) -> LINTERFACE.equals(r.getNodeType());
+ Predicate<SimpleResult> ifIsSource = getIsSourcePredicate();
+
+ return results.stream()
+ .filter(ifIsPort)
+ .filter(ifIsSource)
+ .collect(Collectors.toList());
+ }
+
+ private Predicate<SimpleResult> getIsSourcePredicate() {
+ boolean FLAG_ADVANCED_PORTS_FILTER = featureManager.isActive(Features.FLAG_ADVANCED_PORTS_FILTER);
+
+ if (FLAG_ADVANCED_PORTS_FILTER) {
+ String PORT_LABEL = "org.onap.relationships.inventory.Source";
+ return (SimpleResult r) -> r.getRelatedTo().stream()
+ .anyMatch(relatedTo -> PORT_LABEL.equalsIgnoreCase(relatedTo.getRelationshipLabel()));
+ } else {
+ return (SimpleResult r) -> true;
+ }
+ }
+
+ public List<PortDetails> extractPortDetails(AaiResponse<AaiGetPortMirroringSourcePorts> aaiGetPortsResponse, String rawPayload){
+ return extractErrorResponseIfHttpError(aaiGetPortsResponse, rawPayload).orElseGet(() -> extractPortDetailsInternal(aaiGetPortsResponse.getT(), rawPayload));
+
+ }
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Properties.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Properties.java
new file mode 100644
index 00000000..6fecbed5
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Properties.java
@@ -0,0 +1,33 @@
+package org.onap.vid.aai.model;
+
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class Properties {
+
+ private final String interfaceName;
+ private final String interfaceId;
+ private final Boolean isPortMirrored;
+
+ public Properties(
+ @JsonProperty("interface-name") String interfaceName,
+ @JsonProperty("interface-id") String interfaceId,
+ @JsonProperty("is-port-mirrored") Boolean isPortMirrored) {
+ this.interfaceName = interfaceName;
+ this.interfaceId = interfaceId;
+ this.isPortMirrored = isPortMirrored;
+ }
+
+ public String getInterfaceName() {
+ return interfaceName;
+ }
+
+ public String getInterfaceId() {
+ return interfaceId;
+ }
+
+ public Boolean getIsPortMirrored() {
+ return isPortMirrored;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedTo.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedTo.java
new file mode 100644
index 00000000..f14a445f
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedTo.java
@@ -0,0 +1,39 @@
+package org.onap.vid.aai.model;
+
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class RelatedTo {
+ private final String id;
+ private final String relationshipLabel;
+ private final String nodeType;
+ private final String url;
+
+ public RelatedTo(
+ @JsonProperty("id") String id,
+ @JsonProperty("relationship-label") String relationshipLabel,
+ @JsonProperty("node-type") String nodeType,
+ @JsonProperty("url") String url) {
+ this.id = id;
+ this.relationshipLabel = relationshipLabel;
+ this.nodeType = nodeType;
+ this.url = url;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public String getRelationshipLabel() {
+ return relationshipLabel;
+ }
+
+ public String getNodeType() {
+ return nodeType;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedToProperty.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedToProperty.java
index 38003aec..a2a98fc2 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedToProperty.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelatedToProperty.java
@@ -1,8 +1,10 @@
package org.onap.vid.aai.model;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
+@JsonIgnoreProperties(ignoreUnknown = true)
public class RelatedToProperty {
public String getPropertyKey() {
@@ -27,8 +29,8 @@ public class RelatedToProperty {
@JsonProperty("property-key")
public String propertyKey;
-
-
+
+
@JsonProperty("property-value")
public String propertyValue;
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java
index c80d5b6b..6bf63c43 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java
@@ -1,14 +1,14 @@
package org.onap.vid.aai.model;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
-
import java.util.List;
-
+@JsonIgnoreProperties(ignoreUnknown = true)
public class Relationship {
-
+
@JsonProperty("related-to")
public String relatedTo;
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipData.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipData.java
index 5d2d4091..41536651 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipData.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipData.java
@@ -1,8 +1,9 @@
package org.onap.vid.aai.model;
-
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
+@JsonIgnoreProperties(ignoreUnknown = true)
public class RelationshipData {
@JsonProperty("relationship-key")
public String getRelationshipKey() {
@@ -21,10 +22,8 @@ public class RelationshipData {
this.relationshipValue = relationshipValue;
}
- @JsonProperty("relationship-key")
public String relationshipKey;
- @JsonProperty("relationship-value")
public String relationshipValue;
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java
index 43194fc7..b16ddd01 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/RelationshipList.java
@@ -1,10 +1,11 @@
package org.onap.vid.aai.model;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
import org.codehaus.jackson.annotate.JsonProperty;
import java.util.List;
-
+@JsonIgnoreProperties(ignoreUnknown = true)
public class RelationshipList {
@JsonProperty("relationship")
@@ -17,7 +18,6 @@ public class RelationshipList {
this.relationship = relationship;
}
- @JsonProperty("relationship")
public List<Relationship> relationship;
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ResourceType.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ResourceType.java
new file mode 100644
index 00000000..736a1aa9
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ResourceType.java
@@ -0,0 +1,44 @@
+package org.onap.vid.aai.model;
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public enum ResourceType {
+
+ SERVICE_INSTANCE("service-instance", "service-instance-name"),
+ GENERIC_VNF("generic-vnf", "vnf-name"),
+ VF_MODULE("vf-module", "vf-module-name"),
+ VOLUME_GROUP("volume-group", "volume-group-name");
+
+ private static Map<String, ResourceType> AAI_FORMAT_MAP = Stream
+ .of(ResourceType.values())
+ .collect(Collectors.toMap(s -> s.aaiFormat, Function.identity()));
+
+ private final String aaiFormat;
+ private final String nameFilter;
+
+ ResourceType(String formatted, String nameFilter) {
+ this.aaiFormat = formatted;
+ this.nameFilter = nameFilter;
+ }
+
+ public String getAaiFormat() {
+ return aaiFormat;
+ }
+
+ public String getNameFilter() {
+ return nameFilter;
+ }
+
+ @JsonCreator
+ public static ResourceType fromString(String string) {
+ return Optional
+ .ofNullable(AAI_FORMAT_MAP.get(string))
+ .orElseThrow(() -> new IllegalArgumentException(string));
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/SimpleResult.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/SimpleResult.java
new file mode 100644
index 00000000..b2edfc17
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/SimpleResult.java
@@ -0,0 +1,85 @@
+package org.onap.vid.aai.model;
+
+import org.codehaus.jackson.annotate.JsonAnyGetter;
+import org.codehaus.jackson.annotate.JsonAnySetter;
+import org.codehaus.jackson.annotate.JsonIgnore;
+import org.codehaus.jackson.annotate.JsonProperty;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SimpleResult {
+ @JsonProperty("id")
+ private String id;
+ @JsonProperty("node-type")
+ private String nodeType;
+ @JsonProperty("url")
+ private String url;
+ @JsonProperty("properties")
+ private Properties properties;
+ @JsonProperty("related-to")
+ private List<RelatedTo> relatedTo = null;
+ @JsonIgnore
+ private Map<String, Object> additionalProperties = new HashMap<String, Object>();
+
+ @JsonProperty("id")
+ public String getId() {
+ return id;
+ }
+
+ @JsonProperty("id")
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @JsonProperty("node-type")
+ public String getNodeType() {
+ return nodeType;
+ }
+
+ @JsonProperty("node-type")
+ public void setNodeType(String nodeType) {
+ this.nodeType = nodeType;
+ }
+
+ @JsonProperty("url")
+ public String getUrl() {
+ return url;
+ }
+
+ @JsonProperty("url")
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @JsonProperty("properties")
+ public Properties getProperties() {
+ return properties;
+ }
+
+ @JsonProperty("properties")
+ public void setProperties(Properties properties) {
+ this.properties = properties;
+ }
+
+ @JsonProperty("related-to")
+ public List<RelatedTo> getRelatedTo() {
+ return relatedTo;
+ }
+
+ @JsonProperty("related-to")
+ public void setRelatedTo(List<RelatedTo> relatedTo) {
+ this.relatedTo = relatedTo;
+ }
+
+ @JsonAnyGetter
+ public Map<String, Object> getAdditionalProperties() {
+ return this.additionalProperties;
+ }
+
+ @JsonAnySetter
+ public void setAdditionalProperty(String name, Object value) {
+ this.additionalProperties.put(name, value);
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
index 226850d2..ac38b505 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAIRestInterface.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,28 +20,31 @@
package org.onap.vid.aai.util;
+import com.att.eelf.configuration.EELFLogger;
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.eclipse.jetty.util.security.Password;
+import org.onap.vid.aai.ExceptionWithRequestInfo;
+import org.onap.vid.aai.ResponseWithRequestInfo;
+import org.onap.vid.utils.Logging;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
+import org.onap.portalsdk.core.util.SystemProperties;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpMethod;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
-import java.security.KeyManagementException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Base64;
import java.util.Date;
import java.util.UUID;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-
-import com.att.eelf.configuration.EELFLogger;
-import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
-import org.onap.portalsdk.core.util.SystemProperties;
-import org.eclipse.jetty.util.security.Password;
-import org.onap.vid.utils.Logging;
-import org.springframework.http.HttpMethod;
-import static org.onap.vid.utils.Logging.getHttpServletRequest;
-import static org.onap.vid.utils.Logging.requestIdHeaderKey;
+import static org.apache.commons.lang3.ObjectUtils.defaultIfNull;
+import static org.onap.vid.utils.Logging.REQUEST_ID_HEADER_KEY;
/**
@@ -49,43 +52,32 @@ import static org.onap.vid.utils.Logging.requestIdHeaderKey;
*/
public class AAIRestInterface {
+ public static final String WITH_STATUS = " with status=";
/** The logger. */
- EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AAIRestInterface.class);
+ protected EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AAIRestInterface.class);
- final private EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("aai");
+ protected final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("aai");
/** The Constant dateFormat. */
- final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
+ protected final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");
/** The client. */
- private static Client client = null;
+ private Client client = null;
/** The rest srvr base URL. */
private String restSrvrBaseURL;
- /** The certificate path. */
- public String certificatePath = "";
+ @Autowired
+ protected HttpsAuthClient httpsAuthClientFactory;
private String START_STRING = " start";
-
- private String TRANSACTION_ID_HEADER = "X-TransactionId";
- private String FROM_APP_ID_HEADER = "X-FromAppId";
+ protected String TRANSACTION_ID_HEADER = "X-TransactionId";
+ protected String FROM_APP_ID_HEADER = "X-FromAppId";
private String SUCCESSFUL_API_MESSAGE=" REST api POST was successful!";
- private String URL_DECLERATION = ", url=";
-
-
-
-
+ protected String URL_DECLARATION = ", url=";
-
- /**
- * Instantiates a new AAI rest interface.
- *
- * @param certPath the cert path
- */
- public AAIRestInterface(String certPath)
- {
- certificatePath = certPath;
+ public AAIRestInterface(HttpsAuthClient httpsAuthClientFactory) {
+ this.httpsAuthClientFactory = httpsAuthClientFactory;
}
/**
@@ -99,27 +91,28 @@ public class AAIRestInterface {
return URLEncoder.encode(nodeKey, "UTF-8").replaceAll("\\+", "%20");
}
- /**
- * Inits the rest client.
- */
- private void initRestClient()
- {
- String methodName = "initRestClient";
+ private void initRestClient() {
+ initRestClient(false);
+ }
+
+ private void initRestClient(boolean propagateExceptions)
+ {
if (client == null) {
try {
- client = HttpsAuthClient.getClient(certificatePath);
- }
- catch (KeyManagementException e){
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== KeyManagementException in " + methodName + e.toString());
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== KeyManagementException in " + methodName + e.toString());
+ client = httpsAuthClientFactory.getClient(HttpClientMode.WITHOUT_KEYSTORE);
} catch (Exception e) {
logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== Exception in REST call to DB in initRestClient" + e.toString());
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== Exception in REST call to DB : " + e.toString());
+ if (propagateExceptions) {
+ ExceptionUtils.rethrow(e);
+ }
}
}
}
+
+
/**
* Sets the rest srvr base URL.
*
@@ -155,70 +148,82 @@ public class AAIRestInterface {
* @param requestUri the request uri
* @param xml the xml
* @return the string
- * @throws UnsupportedEncodingException
*/
- public Response RestGet(String fromAppId, String transId, String requestUri, boolean xml) throws UnsupportedEncodingException {
- String methodName = "RestGet";
-
- String responseType = MediaType.APPLICATION_JSON;
- if (xml)
- responseType = MediaType.APPLICATION_XML;
- initRestClient();
+ public ResponseWithRequestInfo RestGet(String fromAppId, String transId, String requestUri, boolean xml) {
+ return RestGet(fromAppId, transId, requestUri, xml, false);
+ }
- String clientCert = SystemProperties.getProperty(AAIProperties.AAI_USE_CLIENT_CERT);
+ public ResponseWithRequestInfo RestGet(String fromAppId, String transId, String requestUri, boolean xml, boolean propagateExceptions) {
+ String url = null;
+ try {
+ String methodName = "RestGet";
+ url = SystemProperties.getProperty(AAIProperties.AAI_SERVER_URL) + requestUri;
- boolean useClientCert = false;
- if (clientCert != null &&
- SystemProperties.getProperty(AAIProperties.AAI_USE_CLIENT_CERT).equalsIgnoreCase("true")) {
- useClientCert = true;
- }
- String url = "";
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START_STRING);
+ String responseType = MediaType.APPLICATION_JSON;
+ if (xml)
+ responseType = MediaType.APPLICATION_XML;
- url = SystemProperties.getProperty(AAIProperties.AAI_SERVER_URL) + requestUri;
+ initRestClient(propagateExceptions);
+ String clientCert = SystemProperties.getProperty(AAIProperties.AAI_USE_CLIENT_CERT);
- logger.debug(dateFormat.format(new Date()) + "<== " + url + " for the get REST API");
- Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url);
+ boolean useClientCert = false;
+ if (clientCert != null &&
+ SystemProperties.getProperty(AAIProperties.AAI_USE_CLIENT_CERT).equalsIgnoreCase("true")) {
+ useClientCert = true;
+ }
- final Response cres;
- if (useClientCert == true) {
- cres = client.target(url)
- .request()
- .accept(responseType)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(FROM_APP_ID_HEADER, fromAppId)
- .header("Content-Type", MediaType.APPLICATION_JSON)
- .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey))
- .get();
- } else {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START_STRING);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + url + " for the get REST API");
+
+ Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url);
+
+ final Response cres;
+ if (useClientCert == true) {
+ cres = client.target(url)
+ .request()
+ .accept(responseType)
+ .header(TRANSACTION_ID_HEADER, transId)
+ .header(FROM_APP_ID_HEADER, fromAppId)
+ .header("Content-Type", MediaType.APPLICATION_JSON)
+ .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
+ .get();
+ } else {
- String vidUsername = SystemProperties.getProperty(AAIProperties.AAI_VID_USERNAME);
- String vidPassword = Password.deobfuscate(SystemProperties.getProperty(AAIProperties.AAI_VID_PASSWD_X));
- String encodeThis = vidUsername + ":" + vidPassword;
+ String vidUsername = SystemProperties.getProperty(AAIProperties.AAI_VID_USERNAME);
+ String vidPassword = Password.deobfuscate(SystemProperties.getProperty(AAIProperties.AAI_VID_PASSWD_X));
+ String encodeThis = vidUsername + ":" + vidPassword;
+
+ cres = client.target(url)
+ .request()
+ .accept(responseType)
+ .header(TRANSACTION_ID_HEADER, transId)
+ .header(FROM_APP_ID_HEADER, fromAppId)
+ .header("Content-Type", "application/json")
+ .header("Authorization", "Basic " + Base64.getEncoder().encodeToString(encodeThis.getBytes("utf-8")))
+ .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
+ .get();
+ }
+ Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, cres);
- cres = client.target(url)
- .request()
- .accept(responseType)
- .header(TRANSACTION_ID_HEADER, transId)
- .header(FROM_APP_ID_HEADER, fromAppId)
- .header("Content-Type", "application/json")
- .header("Authorization", "Basic " + Base64.getEncoder().encodeToString(encodeThis.getBytes("utf-8")))
- .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey))
- .get();
- }
- Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, cres);
-// String r = cres.readEntity(String.class);
- if (cres.getStatus() == 200) {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + SUCCESSFUL_API_MESSAGE);
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + SUCCESSFUL_API_MESSAGE);
- } else {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName +" with status="+cres.getStatus()+URL_DECLERATION+url);
+ if (cres.getStatus() == 200) {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + SUCCESSFUL_API_MESSAGE);
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + SUCCESSFUL_API_MESSAGE);
+ } else {
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + WITH_STATUS + cres.getStatus() + URL_DECLARATION + url);
+ }
+ return new ResponseWithRequestInfo(cres, url, HttpMethod.GET);
+ } catch (Exception e) {
+ // no need to ask if "propagateExceptions" because any exception
+ // at this point should have already obey to the
+ // "propagateExceptions" flag
+ throw new ExceptionWithRequestInfo(HttpMethod.GET, defaultIfNull(url, requestUri), e);
}
- return cres;
-// logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName +" resp=" + r );
-// return r;
+ }
+
+ protected String extractOrGenerateRequestId() {
+ return Logging.extractOrGenerateRequestId();
}
@@ -237,7 +242,6 @@ public class AAIRestInterface {
logger.debug(dateFormat.format(new Date()) + "<== " + methodName + START_STRING);
initRestClient();
- String request = "{}";
url = SystemProperties.getProperty(AAIProperties.AAI_SERVER_URL) + path;
Logging.logRequest(outgoingRequestsLogger, HttpMethod.DELETE, url);
final Response cres = client.target(url)
@@ -245,8 +249,7 @@ public class AAIRestInterface {
.accept(MediaType.APPLICATION_JSON)
.header(TRANSACTION_ID_HEADER, transId)
.header(FROM_APP_ID_HEADER, sourceID)
- .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey))
- //.entity(request)
+ .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
.delete();
Logging.logResponse(outgoingRequestsLogger, HttpMethod.DELETE, url, cres);
if (cres.getStatus() == 404) { // resource not found
@@ -271,16 +274,15 @@ public class AAIRestInterface {
* Rest put.
*
* @param fromAppId the from app id
- * @param transId the trans id
* @param path the path
* @param payload the payload
* @param xml the xml
* @return the string
*/
- public Response RestPut(String fromAppId, String transId, String path, String payload, boolean xml) {
+ public Response RestPut(String fromAppId, String path, String payload, boolean xml) {
String methodName = "RestPut";
String url="";
- transId = UUID.randomUUID().toString();
+ String transId = UUID.randomUUID().toString();
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START_STRING);
try {
@@ -303,19 +305,19 @@ public class AAIRestInterface {
.header(TRANSACTION_ID_HEADER, transId)
.header(FROM_APP_ID_HEADER, fromAppId)
.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(encodeThis.getBytes("utf-8")))
- .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey))
+ .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
.put(Entity.entity(payload, MediaType.APPLICATION_JSON));
Logging.logResponse(outgoingRequestsLogger, HttpMethod.PUT, url, cres);
if (cres.getStatus() == 200 && cres.getStatus() <= 299) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLERATION);
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLERATION);
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION);
} else {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName +" with status="+cres.getStatus()+URL_DECLERATION+url);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + WITH_STATUS +cres.getStatus()+ URL_DECLARATION +url);
}
return cres;
} catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLERATION+url+ ", Exception: " + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION +url+ ", Exception: " + e.toString());
}
return null;
}
@@ -326,16 +328,15 @@ public class AAIRestInterface {
* Rest post.
*
* @param fromAppId the from app id
- * @param transId the trans id
* @param path the path
* @param payload the payload
* @param xml the xml
* @return the string
*/
- public Response RestPost(String fromAppId, String transId, String path, String payload, boolean xml) {
+ public Response RestPost(String fromAppId, String path, String payload, boolean xml) {
String methodName = "RestPost";
String url="";
- transId = UUID.randomUUID().toString();
+ String transId = UUID.randomUUID().toString();
logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + START_STRING);
try {
@@ -358,19 +359,19 @@ public class AAIRestInterface {
.header(TRANSACTION_ID_HEADER, transId)
.header(FROM_APP_ID_HEADER, fromAppId)
.header("Authorization", "Basic " + Base64.getEncoder().encodeToString(encodeThis.getBytes("utf-8")))
- .header(requestIdHeaderKey, getHttpServletRequest().getHeader(requestIdHeaderKey))
+ .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId())
.post(Entity.entity(payload, MediaType.APPLICATION_JSON));
Logging.logResponse(outgoingRequestsLogger, HttpMethod.POST, url, cres);
if (cres.getStatus() == 200 && cres.getStatus() <= 299) {
- logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLERATION);
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLERATION);
+ logger.info(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION);
} else {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " with status="+cres.getStatus()+URL_DECLERATION+url);
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + WITH_STATUS +cres.getStatus()+ URL_DECLARATION +url);
}
return cres;
} catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLERATION+url+ ", Exception: " + e.toString());
+ logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + URL_DECLARATION +url+ ", Exception: " + e.toString());
}
return null;
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/CustomJacksonJaxBJsonProvider.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/CustomJacksonJaxBJsonProvider.java
index 996341a9..375f0b2d 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/CustomJacksonJaxBJsonProvider.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/CustomJacksonJaxBJsonProvider.java
@@ -21,8 +21,6 @@
package org.onap.vid.aai.util;
-import javax.ws.rs.ext.Provider;
-
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
@@ -30,6 +28,8 @@ import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider;
import com.fasterxml.jackson.module.jaxb.JaxbAnnotationModule;
+import javax.ws.rs.ext.Provider;
+
/**
* The Class CustomJacksonJaxBJsonProvider.
*/
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpClientMode.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpClientMode.java
new file mode 100644
index 00000000..e1992826
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpClientMode.java
@@ -0,0 +1,9 @@
+package org.onap.vid.aai.util;
+
+public enum HttpClientMode {
+
+ WITH_KEYSTORE,
+ WITHOUT_KEYSTORE(),
+ UNSECURE,
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsAuthClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsAuthClient.java
index 3bc8e4a3..f1eafe42 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsAuthClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsAuthClient.java
@@ -7,9 +7,9 @@
* 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.
@@ -21,120 +21,151 @@
package org.onap.vid.aai.util;
-import java.io.FileInputStream;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
-import javax.net.ssl.SSLSession;
-import javax.ws.rs.client.Client;
-import javax.ws.rs.client.ClientBuilder;
-
import org.eclipse.jetty.util.security.Password;
import org.glassfish.jersey.client.ClientConfig;
+import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.HttpUrlConnectorProvider;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SystemProperties;
+
+import javax.net.ssl.*;
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.security.*;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+
/**
* The Class HttpsAuthClient.
*/
-public class HttpsAuthClient{
- /** The logger. */
- static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsAuthClient.class);
-
- /**
- * Gets the client.
- *
- * @param certFilePath the cert file path
- * @return the client
- * @throws KeyManagementException the key management exception
- */
- public static Client getClient(String certFilePath) throws KeyManagementException {
-
- ClientConfig config = new ClientConfig();
- //config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
- //config.getClasses().add(org.onap.aai.util.CustomJacksonJaxBJsonProvider.class);
-
- try {
-
- config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, Boolean.TRUE );
-
- config.connectorProvider(new HttpUrlConnectorProvider().useSetMethodWorkaround());
- String truststore_path = certFilePath + org.onap.vid.aai.util.AAIProperties.FILESEPARTOR + SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_TRUSTSTORE_FILENAME);
- String truststore_password = SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_TRUSTSTORE_PASSWD_X);
- String decrypted_truststore_password = Password.deobfuscate(truststore_password);
-
- boolean useClientCert = false;
-
- String keystore_path = certFilePath + org.onap.vid.aai.util.AAIProperties.FILESEPARTOR + SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_KEYSTORE_FILENAME);
- String keystore_password = SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_KEYSTORE_PASSWD_X);
- String decrypted_keystore_password = Password.deobfuscate(keystore_password);
-
- String clientCert = SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_USE_CLIENT_CERT);
-
- if (clientCert != null &&
- SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_USE_CLIENT_CERT).equalsIgnoreCase("true")) {
- useClientCert = true;
- }
-
- System.setProperty("javax.net.ssl.trustStore", truststore_path);
- System.setProperty("javax.net.ssl.trustStorePassword", decrypted_truststore_password);
- HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){
- public boolean verify(String string,SSLSession ssls) {
- return true;
- }
- });
-
- final SSLContext ctx = SSLContext.getInstance("TLS");
-
- KeyManagerFactory kmf = null;
- if (useClientCert) {
-
- try {
- kmf = KeyManagerFactory.getInstance("SunX509");
- FileInputStream fin = new FileInputStream(keystore_path);
- KeyStore ks = KeyStore.getInstance("PKCS12");
- char[] pwd = decrypted_keystore_password.toCharArray();
- ks.load(fin, pwd);
- kmf.init(ks, pwd);
- } catch (Exception e) {
- //System.out.println("Error setting up kmf: exiting");
- logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up kmf: exiting");
- e.printStackTrace();
- return null;
- }
- ctx.init(kmf.getKeyManagers(), null, null);
-
- return ClientBuilder.newBuilder()
- .sslContext(ctx)
- .hostnameVerifier(new HostnameVerifier() {
- @Override
- public boolean verify( String s, SSLSession sslSession ) {
- return true;
- }
- }).withConfig(config)
- .build()
- .register(org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider.class);
- } else {
- return ClientBuilder.newBuilder()
- .hostnameVerifier(new HostnameVerifier() {
- @Override
- public boolean verify( String s, SSLSession sslSession ) {
- return true;
- }
- }).withConfig(config)
- .build()
- .register(org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider.class);
- }
- } catch (Exception e) {
- logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config: exiting");
- //System.out.println("Error setting up config: exiting");
- e.printStackTrace();
- System.exit(1);
- return null;
- }
- }
-}
+public class HttpsAuthClient {
+
+
+ public HttpsAuthClient(String certFilePath) {
+ this.certFilePath = certFilePath;
+ }
+
+ private final String certFilePath;
+
+ /** The logger. */
+ static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsAuthClient.class);
+
+ /**
+ * Gets the client.
+ *
+ * @return the client
+ * @throws KeyManagementException the key management exception
+ */
+ public Client getClient(HttpClientMode mode) throws GeneralSecurityException, IOException {
+ ClientConfig config = new ClientConfig();
+ SSLContext ctx;
+
+ try {
+ String truststorePath = getCertificatesPath() + org.onap.vid.aai.util.AAIProperties.FILESEPARTOR + SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_TRUSTSTORE_FILENAME);
+ String truststorePassword = SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_TRUSTSTORE_PASSWD_X);
+ String decryptedTruststorePassword = Password.deobfuscate(truststorePassword);
+
+ System.setProperty("javax.net.ssl.trustStore", truststorePath);
+ System.setProperty("javax.net.ssl.trustStorePassword", decryptedTruststorePassword);
+
+ HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
+ public boolean verify(String string, SSLSession ssls) {
+ return true;
+ }
+ });
+ ctx = SSLContext.getInstance("TLSv1.2");
+ KeyManager[] keyManagers = null;
+ TrustManager[] trustManagers = getTrustManager(mode);
+
+ switch (mode) {
+ case WITH_KEYSTORE:
+ String aaiKeystorePath = getCertificatesPath() + org.onap.vid.aai.util.AAIProperties.FILESEPARTOR + SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_KEYSTORE_FILENAME);
+ String aaiKeystorePassword = SystemProperties.getProperty(org.onap.vid.aai.util.AAIProperties.AAI_KEYSTORE_PASSWD_X);
+ config.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, Boolean.TRUE);
+ config.connectorProvider(new HttpUrlConnectorProvider().useSetMethodWorkaround());
+ KeyManagerFactory kmf = getKeyManagerFactory(aaiKeystorePath, aaiKeystorePassword);
+ keyManagers = kmf.getKeyManagers();
+ break;
+
+ case WITHOUT_KEYSTORE:
+ config.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
+ break;
+
+ default:
+ logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config. HttpClientMode is " + mode);
+ }
+
+ ctx.init(keyManagers, trustManagers, null);
+ return ClientBuilder.newBuilder()
+ .sslContext(ctx)
+ .hostnameVerifier(new HostnameVerifier() {
+ @Override
+ public boolean verify(String s, SSLSession sslSession) {
+ return true;
+ }
+ }).withConfig(config)
+ .build()
+ .register(org.onap.vid.aai.util.CustomJacksonJaxBJsonProvider.class);
+ } catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up config", e);
+ throw e;
+ }
+
+ }
+
+ /**
+ * @param aaiKeystorePath
+ * @param aaiKeystorePassword - in OBF format
+ * @return
+ * @throws NoSuchAlgorithmException
+ * @throws KeyStoreException
+ * @throws IOException
+ * @throws CertificateException
+ * @throws UnrecoverableKeyException
+ */
+ private KeyManagerFactory getKeyManagerFactory(String aaiKeystorePath, String aaiKeystorePassword) throws IOException, GeneralSecurityException {
+ String aaiDecryptedKeystorePassword = Password.deobfuscate(aaiKeystorePassword);
+ KeyManagerFactory kmf = null;
+ try (FileInputStream fin = new FileInputStream(aaiKeystorePath)) {
+ kmf = KeyManagerFactory.getInstance("SunX509");
+ KeyStore ks = KeyStore.getInstance("PKCS12");
+ char[] pwd = aaiDecryptedKeystorePassword.toCharArray();
+ ks.load(fin, pwd);
+ kmf.init(ks, pwd);
+ } catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up kmf");
+ logger.error(EELFLoggerDelegate.errorLogger, "Error setting up kmf (keystore path: {}, obfuascated keystore password: {})", aaiKeystorePath, aaiKeystorePassword, e);
+ throw e;
+ }
+ return kmf;
+ }
+
+ private String getCertificatesPath() {
+ return certFilePath;
+ }
+
+ private TrustManager[] getTrustManager(HttpClientMode httpClientMode) {
+ //Creating a trustManager that will accept all certificates.
+ //TODO - remove this one the POMBA certificate is added to the tomcat_keystore file
+ TrustManager[] trustAllCerts = null;
+ if (httpClientMode == HttpClientMode.UNSECURE) {
+
+ trustAllCerts = new TrustManager[]{new X509TrustManager() {
+ public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+ return null;
+ }
+
+ public void checkClientTrusted(X509Certificate[] certs, String authType) {
+ }
+
+ public void checkServerTrusted(X509Certificate[] certs, String authType) {
+ }
+ }};
+ }
+ return trustAllCerts;
+ }
+
+
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java
index 10022219..d1f1cfc8 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java
@@ -20,25 +20,29 @@
package org.onap.vid.aai.util;
-import java.io.FileInputStream;
-import java.security.KeyManagementException;
-import java.security.KeyStore;
-
-import javax.net.ssl.SSLContext;
-
+import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLContextBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
-import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.HttpClients;
import org.eclipse.jetty.util.security.Password;
+import org.onap.vid.exceptions.GenericUncheckedException;
+import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.util.SystemProperties;
+import javax.net.ssl.SSLContext;
+import java.io.FileInputStream;
+import java.security.GeneralSecurityException;
+import java.security.KeyManagementException;
+import java.security.KeyStore;
+
/**
* The Class HttpsComponentsClient.
*/
public class HttpsComponentsClient{
-
+
+ static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsComponentsClient.class);
+
/**
* Gets the client.
*
@@ -46,10 +50,10 @@ public class HttpsComponentsClient{
* @return the client
* @throws KeyManagementException the key management exception
*/
- public static CloseableHttpClient getClient(String certFilePath) throws Exception {
+ public static CloseableHttpClient getClient(String certFilePath) {
CloseableHttpClient httpclient = null;
try {
-
+
String truststore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_TRUSTSTORE_FILENAME);
String truststore_password = SystemProperties.getProperty(AAIProperties.AAI_TRUSTSTORE_PASSWD_X);
String decrypted_truststore_password = Password.deobfuscate(truststore_password);
@@ -60,17 +64,31 @@ public class HttpsComponentsClient{
SSLContextBuilder sslContextB = new SSLContextBuilder();
KeyStore ks = KeyStore.getInstance("PKCS12");
- FileInputStream fin = new FileInputStream(keystore_path);
char[] pwd = decrypted_keystore_password.toCharArray();
- ks.load(fin, pwd);
-
+
+ try(FileInputStream fin = new FileInputStream(keystore_path)) {
+ ks.load(fin, pwd);
+ }
+ catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up keystore");
+ logger.error(EELFLoggerDelegate.errorLogger, "Error loading keystore materials: (keystore path: {}, obfuascated keystore password: {})", keystore_path, keystore_password);
+ throw new GenericUncheckedException(e);
+ }
+
sslContextB.loadKeyMaterial(ks, pwd);
KeyStore ts = KeyStore.getInstance("JKS");
- FileInputStream fin1 = new FileInputStream(truststore_path);
char[] pwd1 = decrypted_truststore_password.toCharArray();
- ts.load(fin1, pwd1);
-
+
+ try(FileInputStream fin1 = new FileInputStream(truststore_path)) {
+ ts.load(fin1, pwd1);
+ }
+ catch (Exception e) {
+ logger.debug(EELFLoggerDelegate.debugLogger, "Error setting up truststore");
+ logger.error(EELFLoggerDelegate.errorLogger, "Error loading truststore materials: (truststore path: {}, obfuascated truststore password: {})", truststore_path, truststore_password);
+ throw new GenericUncheckedException(e);
+ }
+
sslContextB.loadTrustMaterial(ts);
sslContextB.loadKeyMaterial(ks, pwd);
sslContextB.useTLS();
@@ -88,8 +106,8 @@ public class HttpsComponentsClient{
.build();
- } catch (Exception e) {
- throw e;
+ } catch (GeneralSecurityException e) {
+ throw new GenericUncheckedException(e);
}
return httpclient;
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/JettyObfuscationConversionCommandLineUtil.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/JettyObfuscationConversionCommandLineUtil.java
index 8a3ba88f..cfc56d18 100644
--- a/vid-app-common/src/main/java/org/onap/vid/aai/util/JettyObfuscationConversionCommandLineUtil.java
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/JettyObfuscationConversionCommandLineUtil.java
@@ -21,11 +21,7 @@
package org.onap.vid.aai.util;
-import org.apache.commons.cli.BasicParser;
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
+import org.apache.commons.cli.*;
import org.eclipse.jetty.util.security.Password;
@@ -70,7 +66,7 @@ public class JettyObfuscationConversionCommandLineUtil {
* Usage.
*/
private static void usage(){
- System.out.println("usage:");;
+ System.out.println("usage:");
System.out.println("-e [string] to obfuscate");
System.out.println("-d [string] to deobfuscate");
System.out.println("-h help");
diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/VidObjectMapperType.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/VidObjectMapperType.java
new file mode 100644
index 00000000..931987ae
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/VidObjectMapperType.java
@@ -0,0 +1,6 @@
+package org.onap.vid.aai.util;
+
+public enum VidObjectMapperType {
+ CODEHAUS,
+ FASTERXML
+} \ No newline at end of file