diff options
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/aai')
70 files changed, 1471 insertions, 715 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 baf92b880..e1a1e706f 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,25 +1,25 @@ package org.onap.vid.aai; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; 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.jetbrains.annotations.NotNull; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; +import org.onap.vid.aai.exceptions.InvalidAAIResponseException; import org.onap.vid.aai.model.AaiGetAicZone.AicZones; 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.Relationship; -import org.onap.vid.aai.model.RelationshipData; -import org.onap.vid.aai.model.RelationshipList; import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse; import org.onap.vid.aai.util.AAIRestInterface; +import org.onap.vid.aai.util.CacheProvider; import org.onap.vid.aai.util.VidObjectMapperType; import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.SubscriberList; @@ -27,6 +27,8 @@ 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.vid.utils.Unchecked; +import org.springframework.http.HttpMethod; import org.springframework.web.util.UriUtils; import javax.inject.Inject; @@ -34,15 +36,16 @@ import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import java.io.IOException; import java.io.UnsupportedEncodingException; +import java.net.URI; import java.net.URLEncoder; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Date; import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.UUID; +import java.util.function.Function; import static java.util.Collections.emptyList; +import static java.util.stream.Collectors.toMap; import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; /** @@ -52,13 +55,13 @@ import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; public class AaiClient implements AaiClientInterface { - 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/"; + private static final String QUERY_FORMAT_RESOURCE = "query?format=resource"; + private static final String SERVICE_SUBSCRIPTIONS_PATH = "/service-subscriptions/service-subscription/"; + private static final String MODEL_INVARIANT_ID = "&model-invariant-id="; + private static final String QUERY_FORMAT_SIMPLE = "query?format=simple"; + private static final String BUSINESS_CUSTOMER = "/business/customers/customer/"; + private static final String SERVICE_INSTANCE = "/service-instances/service-instance/"; + private static final String BUSINESS_CUSTOMERS_CUSTOMER = "business/customers/customer/"; protected String fromAppId = "VidAaiController"; @@ -66,22 +69,22 @@ public class AaiClient implements AaiClientInterface { private final AAIRestInterface restController; + private final CacheProvider cacheProvider; + + ObjectMapper objectMapper = new ObjectMapper(); + /** * The logger */ EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(AaiClient.class); - /** - * 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\"}"; + private static final String GET_SERVICE_MODELS_RESPONSE_BODY = "{\"start\" : \"service-design-and-creation/models/\", \"query\" : \"query/serviceModels-byDistributionStatus?distributionStatus=DISTRIBUTION_COMPLETE_OK\"}"; @Inject - public AaiClient(AAIRestInterface restController, PortDetailsTranslator portDetailsTranslator) { + public AaiClient(AAIRestInterface restController, PortDetailsTranslator portDetailsTranslator, CacheProvider cacheProvider) { this.restController = restController; this.portDetailsTranslator = portDetailsTranslator; + this.cacheProvider = cacheProvider; } @@ -107,8 +110,14 @@ public class AaiClient implements AaiClientInterface { @Override public AaiResponse getServiceModelsByDistributionStatus() { - Response resp = doAaiPut(QUERY_FORMAT_RESOURCE, GET_SERVICE_MODELS_RESPONSE_BODY, false); - return processAaiResponse(resp, GetServiceModelsByDistributionStatusResponse.class, null); + return getFromCache("getServiceModelsByDistributionStatus", this::getServiceModelsByDistributionStatusNonCached, + true, "Failed to get service models by distribution status"); + } + + private AaiResponse getServiceModelsByDistributionStatusNonCached(boolean propagateExceptions) { + GetServiceModelsByDistributionStatusResponse response = typedAaiRest(QUERY_FORMAT_RESOURCE, GetServiceModelsByDistributionStatusResponse.class, + GET_SERVICE_MODELS_RESPONSE_BODY, HttpMethod.PUT, propagateExceptions); + return new AaiResponse(response, "", HttpStatus.SC_OK); } @Override @@ -121,14 +130,14 @@ public class AaiClient implements AaiClientInterface { @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); + "{\"start\": [\"cloud-infrastructure/cloud-regions/cloud-region/" + encodePathSegment(cloudOwner) + "/" + encodePathSegment(cloudRegionId) + "\"]," + + "\"query\": \"query/instance-groups-byCloudRegion?type=L3-NETWORK&role=SUB-INTERFACE&function=" + encodePathSegment(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(); + ObjectMapper om = objectMapper; AaiGetNetworkCollectionDetails aaiGetNetworkCollectionDetails = new AaiGetNetworkCollectionDetails(); try { for (int i = 0; i < aaiResponse.getT().getResults().size(); i++) { @@ -145,7 +154,8 @@ public class AaiClient implements AaiClientInterface { 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()); + logger.error(EELFLoggerDelegate.errorLogger, "AAI response parsing Error", e); + return new AaiResponse(e.getCause(), "AAI response parsing Error" , HttpStatus.SC_INTERNAL_SERVER_ERROR); } catch (Exception e) { return new AaiResponse(e.getCause(), "Got " + aaiResponse.getHttpCode() + " from a&ai" , aaiResponse.getHttpCode()); @@ -183,7 +193,7 @@ public class AaiClient implements AaiClientInterface { 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); + AaiResponse<CustomQuerySimpleResult> aaiResponse = processAaiResponse(resp, CustomQuerySimpleResult.class, rawPayload); return portDetailsTranslator.extractPortDetails(aaiResponse, rawPayload); } @@ -202,21 +212,80 @@ public class AaiClient implements AaiClientInterface { } @Override - public AaiResponse<AaiNodeQueryResponse> searchNodeTypeByName(String name, ResourceType type) { - String path = String.format( - "search/nodes-query?search-node-type=%s&filter=%s:EQUALS:%s", + public boolean isNodeTypeExistsByName(String name, ResourceType type) { + if (StringUtils.isEmpty(name)) { + throw new GenericUncheckedException("Empty resource-name provided to searchNodeTypeByName; request is rejected as this will cause full resources listing"); + } + + URI path = Unchecked.toURI(String.format( // e.g. GET /aai/v$/nodes/vf-modules?vf-module-name={vf-module-name} + "nodes/%s?%s=%s", type.getAaiFormat(), type.getNameFilter(), - name - ); - return typedAaiGet(path, AaiNodeQueryResponse.class); + encodePathSegment(name) + )); + final ResponseWithRequestInfo responseWithRequestInfo = restController.RestGet(fromAppId, UUID.randomUUID().toString(), path, false, true); + + return isResourceExistByStatusCode(responseWithRequestInfo); + } + + public Map<String, Properties> getCloudRegionAndTenantByVnfId(String vnfId) { + String start = "/network/generic-vnfs/generic-vnf/" + vnfId; + String query = "/query/cloud-region-fromVnf"; + + String payload = "{\"start\":[\"" + start + "\"],\"query\":\"" + query + "\"}"; + CustomQuerySimpleResult result = typedAaiRest(QUERY_FORMAT_SIMPLE, CustomQuerySimpleResult.class, payload, HttpMethod.PUT, false); + + return result.getResults().stream() + .filter(res -> StringUtils.equals(res.getNodeType(), "tenant") || + StringUtils.equals(res.getNodeType(), "cloud-region")) + .collect(toMap(SimpleResult::getNodeType, SimpleResult::getProperties)); + } + + private boolean isResourceExistByStatusCode(ResponseWithRequestInfo responseWithRequestInfo) { + // 200 - is found + // 404 - resource not found + Response.Status statusInfo = responseWithRequestInfo.getResponse().getStatusInfo().toEnum(); + switch (statusInfo) { + case OK: + return true; + case NOT_FOUND: + return false; + default: + throw new GenericUncheckedException("Unexpected response-code (only OK and NOT_FOUND are expected): " + + responseWithRequestInfo.getResponse().getStatusInfo()); + } } - private <T> AaiResponse<T> typedAaiGet(String path, Class<T> clz) { - Response resp = doAaiGet(path , false); - return processAaiResponse(resp, clz, null, VidObjectMapperType.FASTERXML); + @Override + public <T> T typedAaiGet(URI uri, Class<T> clz) { + return typedAaiRest(uri, clz, null, HttpMethod.GET, false); } + public <T> T typedAaiRest(String path, Class<T> clz, String payload, HttpMethod method, boolean propagateExceptions) { + return typedAaiRest(Unchecked.toURI(path), clz, payload, method, propagateExceptions); + } + + + public <T> T typedAaiRest(URI path, Class<T> clz, String payload, HttpMethod method, boolean propagateExceptions) { + ResponseWithRequestInfo responseWithRequestInfo; + try { + responseWithRequestInfo = restController.doRest(fromAppId, UUID.randomUUID().toString(), path, payload, method, false, propagateExceptions); + } catch (Exception e) { + responseWithRequestInfo = handleExceptionFromRestCall(propagateExceptions, "doAai"+method.name(), e); + } + + final AaiResponseWithRequestInfo<T> aaiResponse = processAaiResponse(responseWithRequestInfo, clz, VidObjectMapperType.FASTERXML, true); + + if (aaiResponse.getAaiResponse().getHttpCode() > 399 || aaiResponse.getAaiResponse().getT() == null) { + throw new ExceptionWithRequestInfo(aaiResponse.getHttpMethod(), + aaiResponse.getRequestedUrl(), + aaiResponse.getRawData(), + responseWithRequestInfo.getResponse().getStatus(), + new InvalidAAIResponseException(aaiResponse.getAaiResponse())); + } + + return aaiResponse.getAaiResponse().getT(); + } private String getUrlFromLIst(String url, String paramKey, List<String> params){ @@ -229,8 +298,8 @@ public class AaiClient implements AaiClientInterface { encodedParam= URLEncoder.encode(param, "UTF-8"); } catch (UnsupportedEncodingException e) { String methodName = "getUrlFromList"; - logger.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "." + methodName + e.toString()); + logger.error(EELFLoggerDelegate.errorLogger, methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + e.toString()); } url = url.concat(encodedParam); if(i != params.size()){ @@ -241,9 +310,34 @@ public class AaiClient implements AaiClientInterface { } + @Override public AaiResponse<SubscriberList> getAllSubscribers() { - return getAllSubscribers(false).getAaiResponse(); + return getFromCache("getAllSubscribers", this::getAllSubscribersNonCached, true, "Failed to get all subscribers"); + } + + private <K> AaiResponse getFromCache(String cacheName, Function<K, AaiResponse> function, K argument, String errorMessage) { + try { + return cacheProvider + .aaiClientCacheFor(cacheName, function) + .get(argument); + } catch (ExceptionWithRequestInfo exception) { + logger.error(errorMessage, exception); + return new AaiResponse(null, exception.getRawData(), exception.getHttpCode()); + } + catch (Exception exception) { + logger.error(errorMessage, exception); + return new AaiResponse(null, exception.getMessage(), HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + } + + private AaiResponse<SubscriberList> getAllSubscribersNonCached(boolean propagateExceptions) { + AaiResponse<SubscriberList> aaiResponse = getAllSubscribers(propagateExceptions).getAaiResponse(); + if (propagateExceptions && (aaiResponse.getT() == null || aaiResponse.getT().customer == null || aaiResponse.getT().customer.isEmpty())) { + throw new GenericUncheckedException("Failed to get Subscribers data. The data is null or empty."); + } else { + return aaiResponse; + } } AaiResponseWithRequestInfo<SubscriberList> getAllSubscribers(boolean propagateExceptions){ @@ -262,33 +356,12 @@ public class AaiClient implements AaiClientInterface { return processAaiResponse(resp, AicZones.class, null); } - - @Override - public AaiResponse<String> getAicZoneForPnf(String globalCustomerId , String serviceType , String serviceId) { - 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(); - return new AaiResponse(aicZone , null ,HttpStatus.SC_OK); - } - - @Override - public AaiResponse getVNFData() { - 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(QUERY_FORMAT_SIMPLE, payload, false); - return processAaiResponse(resp, AaiGetVnfResponse.class, null); - } - - @Override - public Response getVNFData(String globalSubscriberId, String serviceType) { + public AaiResponse getVNFData(String globalSubscriberId, String serviceType) { String payload = "{\"start\": [\"business/customers/customer/" + globalSubscriberId + SERVICE_SUBSCRIPTIONS_PATH + encodePathSegment(serviceType) +"/service-instances\"]," + "\"query\": \"query/vnf-topology-fromServiceInstance\"}"; - return doAaiPut(QUERY_FORMAT_SIMPLE, payload, false); + Response resp = doAaiPut(QUERY_FORMAT_SIMPLE, payload, false); + return processAaiResponse(resp, AaiGetVnfResponse.class, null); } @Override @@ -343,22 +416,17 @@ public class AaiClient implements AaiClientInterface { @Override public AaiResponse getTenants(String globalCustomerId, String serviceType) { - AaiResponse aaiResponse; - 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; + return buildAaiResponseForGetTenantsFailure(" Failed to retrieve LCP Region & Tenants from A&AI, Subscriber ID or Service Type is missing."); } - - 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("")){ - 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); + try { + return cacheProvider + .aaiClientCacheFor("getTenants", this::getTenantsByKey) + .get(CacheProvider.compileKey(globalCustomerId, serviceType)); } - else { - return processAaiResponse(resp, GetTenantsResponse[].class, responseAsString); + catch (ParsingGetTenantsResponseFailure exception) { + logger.error("Failed to get tenants ", exception); + return buildAaiResponseForGetTenantsFailure(exception.getMessage()); } } @@ -389,13 +457,17 @@ public class AaiClient implements AaiClientInterface { } private <T> AaiResponseWithRequestInfo<T> processAaiResponse(ResponseWithRequestInfo responseWithRequestInfo, Class<? extends T> classType, boolean propagateExceptions) { + return processAaiResponse(responseWithRequestInfo, classType, VidObjectMapperType.CODEHAUS, propagateExceptions); + } + + private <T> AaiResponseWithRequestInfo<T> processAaiResponse(ResponseWithRequestInfo responseWithRequestInfo, Class<? extends T> classType, VidObjectMapperType omType, 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); + AaiResponse<T> processedAaiResponse = processAaiResponse(response, classType, responseBody, omType, propagateExceptions); return new AaiResponseWithRequestInfo<>(responseWithRequestInfo.getRequestHttpMethod(), responseWithRequestInfo.getRequestUrl(), processedAaiResponse, responseBody); } catch (Exception e) { @@ -408,17 +480,17 @@ public class AaiClient implements AaiClientInterface { return processAaiResponse(resp, classType, responseBody, VidObjectMapperType.CODEHAUS); } - private AaiResponse processAaiResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType) { + private <T> AaiResponse<T> processAaiResponse(Response resp, Class<? extends T> 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; + private <T> AaiResponse<T> processAaiResponse(Response resp, Class<? extends T> classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) { + AaiResponse<T> 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"); + logger.debug(EELFLoggerDelegate.debugLogger, "Invalid response from AAI"); } else { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "getSubscribers() resp=" + resp.getStatusInfo().toString()); + logger.debug(EELFLoggerDelegate.debugLogger, "getSubscribers() resp=" + resp.getStatusInfo().toString()); if (resp.getStatus() != HttpStatus.SC_OK) { subscriberDataResponse = processFailureResponse(resp,responseBody); } else { @@ -429,7 +501,7 @@ public class AaiClient implements AaiClientInterface { } private AaiResponse processFailureResponse(Response resp, String responseBody) { - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + "Invalid response from AAI"); + logger.debug(EELFLoggerDelegate.debugLogger, "Invalid response from AAI"); String rawData; if (responseBody != null) { rawData = responseBody; @@ -439,8 +511,8 @@ public class AaiClient implements AaiClientInterface { return new AaiResponse<>(null, rawData, resp.getStatus()); } - private AaiResponse processOkResponse(Response resp, Class classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) { - AaiResponse subscriberDataResponse; + private <T> AaiResponse<T> processOkResponse(Response resp, Class<? extends T> classType, String responseBody, VidObjectMapperType omType, boolean propagateExceptions) { + AaiResponse<T> subscriberDataResponse; String finalResponse = null; try { if (responseBody != null) { @@ -465,50 +537,59 @@ public class AaiClient implements AaiClientInterface { return subscriberDataResponse; } - private AaiResponse parseFasterXmlObject(Class classType, String finalResponse) throws IOException { - com.fasterxml.jackson.databind.ObjectMapper objectMapper = new com.fasterxml.jackson.databind.ObjectMapper(); + private <T> AaiResponse<T> parseFasterXmlObject(Class<? extends T> classType, String finalResponse) throws IOException { return new AaiResponse<>((objectMapper.readValue(finalResponse, classType)), null, HttpStatus.SC_OK); } - private AaiResponse parseCodeHausObject(Class classType, String finalResponse) throws IOException { - ObjectMapper objectMapper = new ObjectMapper(); + private <T> AaiResponse<T> parseCodeHausObject(Class<? extends T> classType, String finalResponse) throws IOException { return new AaiResponse<>((objectMapper.readValue(finalResponse, classType)), null, HttpStatus.SC_OK); } + @Override public Response doAaiGet(String uri, boolean xml) { return doAaiGet(uri, xml, false).getResponse(); } public ResponseWithRequestInfo doAaiGet(String uri, boolean xml, boolean propagateExceptions) { + return doAaiGet(Unchecked.toURI(uri), xml, propagateExceptions); + } + + public ResponseWithRequestInfo doAaiGet(URI uri, boolean xml, boolean propagateExceptions) { String methodName = "doAaiGet"; - String transId = UUID.randomUUID().toString(); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " start"); ResponseWithRequestInfo resp; try { - resp = restController.RestGet(fromAppId, transId, uri, xml, propagateExceptions); + resp = restController.RestGet(fromAppId, UUID.randomUUID().toString(), uri, xml, propagateExceptions); } catch (Exception e) { - if (propagateExceptions) { - throw (e instanceof RuntimeException) ? (RuntimeException)e : new GenericUncheckedException(e); - } else { - final Exception actual = - e instanceof ExceptionWithRequestInfo ? (Exception) e.getCause() : e; + resp = handleExceptionFromRestCall(propagateExceptions, methodName, e); + } + return resp; + } - final String message = - actual instanceof WebApplicationException ? ((WebApplicationException) actual).getResponse().readEntity(String.class) : e.toString(); + @NotNull + protected ResponseWithRequestInfo handleExceptionFromRestCall(boolean propagateExceptions, String methodName, Exception e) { + ResponseWithRequestInfo resp; + if (propagateExceptions) { + throw (e instanceof RuntimeException) ? (RuntimeException)e : new GenericUncheckedException(e); + } else { + final Exception actual = + e instanceof ExceptionWithRequestInfo ? (Exception) e.getCause() : e; - //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); - } + final String message = + actual instanceof WebApplicationException ? ((WebApplicationException) actual).getResponse().readEntity(String.class) : e.toString(); + + //ToDo: change parameter of requestUrl to real url from doRest function + resp = new ResponseWithRequestInfo(null, null, org.springframework.http.HttpMethod.GET); + logger.info(EELFLoggerDelegate.errorLogger, methodName + message); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + message); } return resp; } - private String parseForTenantsByServiceSubscription(String resp) { + private String parseForTenantsByServiceSubscription(String relatedToKey, String resp) { String tenantList = ""; try { @@ -516,7 +597,7 @@ public class AaiClient implements AaiClientInterface { JSONObject jsonObject = (JSONObject) jsonParser.parse(resp); - return parseServiceSubscriptionObjectForTenants(jsonObject); + return parseServiceSubscriptionObjectForTenants(relatedToKey, jsonObject); } catch (Exception ex) { logger.debug(EELFLoggerDelegate.debugLogger, "parseForTenantsByServiceSubscription error while parsing tenants by service subscription", ex); } @@ -524,24 +605,26 @@ public class AaiClient implements AaiClientInterface { } protected Response doAaiPut(String uri, String payload, boolean xml) { + return doAaiPut(uri, payload, xml, false).getResponse(); + } + + protected ResponseWithRequestInfo doAaiPut(String uri, String payload, boolean xml, boolean propagateExceptions) { String methodName = "doAaiPut"; - String transId = UUID.randomUUID().toString(); - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " start"); - Response resp = null; + ResponseWithRequestInfo resp; try { - resp = restController.RestPut(fromAppId, uri, payload, xml); + resp = restController.RestPut(fromAppId, uri, payload, xml, propagateExceptions); } 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()); + resp = handleExceptionFromRestCall(propagateExceptions, methodName, e); } return resp; } - private String parseServiceSubscriptionObjectForTenants(JSONObject jsonObject) { + private String parseServiceSubscriptionObjectForTenants(String relatedToKey, JSONObject jsonObject) { JSONArray tenantArray = new JSONArray(); boolean bconvert = false; try { @@ -550,7 +633,7 @@ public class AaiClient implements AaiClientInterface { JSONArray rShipArray = (JSONArray) relationShipListsObj.get("relationship"); for (Object innerObj : defaultIfNull(rShipArray, emptyList())) { if (innerObj != null) { - bconvert = parseTenant(tenantArray, bconvert, (JSONObject) innerObj); + bconvert = parseTenant(relatedToKey, tenantArray, bconvert, (JSONObject) innerObj); } } } @@ -565,9 +648,9 @@ public class AaiClient implements AaiClientInterface { } - private static boolean parseTenant(JSONArray tenantArray, boolean bconvert, JSONObject inner1Obj) { + private static boolean parseTenant(String relatedToKey, JSONArray tenantArray, boolean bconvert, JSONObject inner1Obj) { String relatedTo = checkForNull((String) inner1Obj.get("related-to")); - if (relatedTo.equalsIgnoreCase("tenant")) { + if (relatedTo.equalsIgnoreCase(relatedToKey)) { JSONObject tenantNewObj = new JSONObject(); String relatedLink = checkForNull((String) inner1Obj.get("related-link")); @@ -609,9 +692,7 @@ public class AaiClient implements AaiClientInterface { tenantNewObj.put("cloudOwner", rShipVal); } else if (rShipKey.equalsIgnoreCase("cloud-region.cloud-region-id")) { tenantNewObj.put("cloudRegionID", rShipVal); - } - - if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) { + } else if (rShipKey.equalsIgnoreCase("tenant.tenant-id")) { tenantNewObj.put("tenantID", rShipVal); } } @@ -639,7 +720,7 @@ public class AaiClient implements AaiClientInterface { responseWithRequestInfo.getHttpMethod(), (aaiResponse != null) ? aaiResponse.getHttpCode() : 0, responseWithRequestInfo.getRequestedUrl(), - StringUtils.substring(responseWithRequestInfo.getRawData(), 0, 500), + responseWithRequestInfo.getRawData(), isAvailable ? "OK" : "No subscriber received", duration ); @@ -648,16 +729,104 @@ public class AaiClient implements AaiClientInterface { } 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)); + new HttpRequestMetadata(e, duration)); } catch (Exception e) { long duration = System.currentTimeMillis() - startTime; return new ExternalComponentStatus(ExternalComponentStatus.Component.AAI, false, new ErrorMetadata(Logging.exceptionToDescription(e), duration)); } } + + @Override + public String getCloudOwnerByCloudRegionId(String cloudRegionId) { + return cacheProvider + .aaiClientCacheFor("getCloudOwnerByCloudRegionId", this::getCloudOwnerByCloudRegionIdNonCached) + .get(cloudRegionId); + } + + + @Override + public GetTenantsResponse getHomingDataByVfModule(String vnfInstanceId, String vfModuleId) { + + if (StringUtils.isEmpty(vnfInstanceId)||StringUtils.isEmpty(vfModuleId)){ + throw new GenericUncheckedException("Failed to retrieve homing data associated to vfModule from A&AI, VNF InstanceId or VF Module Id is missing."); + } + Response resp = doAaiGet("network/generic-vnfs/generic-vnf/" + vnfInstanceId +"/vf-modules/vf-module/"+ vfModuleId, false); + String responseAsString = parseForTenantsByServiceSubscription("vserver",resp.readEntity(String.class)); + if (responseAsString.equals("")){ + throw new GenericUncheckedException( String.format("A&AI has no homing data associated to vfModule '%s' of vnf '%s'", vfModuleId, vnfInstanceId)); + } + else { + AaiResponse aaiResponse = processAaiResponse(resp, GetTenantsResponse[].class, responseAsString); + return ((GetTenantsResponse[])aaiResponse.getT())[0]; + } + } + + @Override + public void resetCache(String cacheName) { + cacheProvider.resetCache(cacheName); + } + + String getCloudOwnerByCloudRegionIdNonCached(String cloudRegionId) { + String uri = "cloud-infrastructure/cloud-regions?cloud-region-id=" + encodePathSegment(cloudRegionId); + + final CloudRegion.Collection cloudRegionCollection = + typedAaiGet(Unchecked.toURI(uri), CloudRegion.Collection.class); + + return cloudRegionCollection + .getCloudRegions().stream() + .map(CloudRegion::getCloudOwner) + // from here we assure that the cloud owner is given, and not null + // and non-empty, and that if more than one cloud-owner is given - + // it is only a single value. + // exception is thrown if none or more than a single values are + // given. + .filter(StringUtils::isNotEmpty) + .distinct() + .reduce((a, b) -> { + // will be invoked only if distinct() leaves more than a single element + throw new GenericUncheckedException("Conflicting cloud-owner found for " + cloudRegionId + ": '" + a + "' / '" + b + "'"); + }) + .orElseThrow(() -> new GenericUncheckedException("No cloud-owner found for " + cloudRegionId)); + } + + private AaiResponse getTenantsByKey(String key) { + String[] args = CacheProvider.decompileKey(key); + String globalCustomerId = safeGetFromArray(args, 0); + String serviceType = safeGetFromArray(args, 1); + return getTenantsNonCached(globalCustomerId, serviceType); + } + + AaiResponse getTenantsNonCached(String globalCustomerId, String serviceType) { + String url = BUSINESS_CUSTOMERS_CUSTOMER + globalCustomerId + SERVICE_SUBSCRIPTIONS_PATH + serviceType; + + Response resp = doAaiGet(url, false); + String responseAsString = parseForTenantsByServiceSubscription("tenant",resp.readEntity(String.class)); + if (StringUtils.isEmpty(responseAsString)){ + throw new ParsingGetTenantsResponseFailure(String.format("A&AI has no LCP Region & Tenants associated to subscriber '%s' and service type '%s'", globalCustomerId, serviceType)); + } + else { + return processAaiResponse(resp, GetTenantsResponse[].class, responseAsString); + } + } + + public static class ParsingGetTenantsResponseFailure extends GenericUncheckedException { + + public ParsingGetTenantsResponseFailure(String message) { + super(message); + } + } + + @NotNull + private AaiResponse<String> buildAaiResponseForGetTenantsFailure(String errorText) { + return new AaiResponse<>(null, String.format("{\"statusText\":\"%s\"}", errorText), HttpStatus.SC_INTERNAL_SERVER_ERROR); + } + + private static String safeGetFromArray(String[] array, int i) { + if (i < 0 || i >= array.length) { + return null; + } else { + return array[i]; + } + } }
\ 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 901591a8c..bf97e5992 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,24 +1,29 @@ package org.onap.vid.aai; -import org.codehaus.jackson.JsonNode; +import com.fasterxml.jackson.databind.JsonNode; import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList; 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.CustomQuerySimpleResult; import org.onap.vid.aai.model.PortDetailsTranslator; +import org.onap.vid.aai.model.Properties; 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.net.URI; import java.util.List; +import java.util.Map; /** * Created by Oren on 7/4/17. */ public interface AaiClientInterface { - AaiResponse<AaiNodeQueryResponse> searchNodeTypeByName(String name, ResourceType type); + boolean isNodeTypeExistsByName(String name, ResourceType type); + + <T> T typedAaiGet(URI path, Class<T> clz); AaiResponse<SubscriberList> getAllSubscribers(); @@ -34,15 +39,11 @@ public interface AaiClientInterface { AaiResponse getAllAicZones(); - AaiResponse getAicZoneForPnf(String globalCustomerId , String serviceType , String serviceId); - - 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); AaiResponse getVNFData(String globalSubscriberId, String serviceType, String serviceInstanceId); @@ -69,4 +70,14 @@ public interface AaiClientInterface { AaiResponse getInstanceGroupsByVnfInstanceId(String vnfInstanceId); ExternalComponentStatus probeAaiGetAllSubscribers(); + + Response doAaiGet(String uri, boolean xml); + + String getCloudOwnerByCloudRegionId(String cloudRegionId); + + GetTenantsResponse getHomingDataByVfModule(String vnfInstanceId, String vfModuleId); + + void resetCache(String cacheName); + + Map<String, Properties> getCloudRegionAndTenantByVnfId(String vnfId); } 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 08585206d..479bd1384 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 @@ -1,8 +1,7 @@ package org.onap.vid.aai; -import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.*; import com.google.common.base.MoreObjects; -import org.codehaus.jackson.annotate.*; import org.onap.vid.aai.model.VnfResult; import java.util.HashMap; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java index 6e25e2715..fe62f029c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClient.java @@ -20,26 +20,25 @@ package org.onap.vid.aai; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.ACCEPT; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.CONTENT_TYPE; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.FROM_APP_ID_HEADER; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.REQUEST_ID; -import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.TRANSACTION_ID_HEADER; - import io.joshworks.restclient.http.HttpResponse; +import io.joshworks.restclient.http.JsonNode; import io.vavr.collection.HashMap; -import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.Collections; -import java.util.Map; -import javax.ws.rs.core.MediaType; +import org.apache.commons.lang3.StringUtils; import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.aai.model.AaiNodeQueryResponse; import org.onap.vid.aai.model.ResourceType; import org.onap.vid.aai.util.AAIProperties; import org.onap.vid.client.SyncRestClientInterface; +import org.onap.vid.exceptions.GenericUncheckedException; import org.onap.vid.model.SubscriberList; +import javax.ws.rs.core.MediaType; +import java.nio.charset.StandardCharsets; +import java.util.Base64; +import java.util.Collections; +import java.util.Map; + +import static org.onap.vid.aai.AaiOverTLSClientInterface.HEADERS.*; + public class AaiOverTLSClient implements AaiOverTLSClientInterface { private final AaiOverTLSPropertySupplier propertySupplier; @@ -64,9 +63,23 @@ public class AaiOverTLSClient implements AaiOverTLSClientInterface { } @Override - public HttpResponse<AaiNodeQueryResponse> searchNodeTypeByName(String name, ResourceType type) { - String uri = urlBase + String.format(URIS.NODE_TYPE_BY_NAME, type.getAaiFormat(), type.getNameFilter(), name); - return syncRestClient.get(uri, getRequestHeaders(), Collections.emptyMap(), AaiNodeQueryResponse.class); + public boolean isNodeTypeExistsByName(String name, ResourceType type) { + + if (StringUtils.isEmpty(name)) { + throw new GenericUncheckedException("Empty resource-name provided to isNodeTypeExistsByName; request is rejected as this will cause full resources listing"); + } + + String path = String.format( // e.g. GET /aai/v$/nodes/vf-modules?vf-module-name={vf-module-name} + "nodes/%s?%s=%s", + type.getAaiFormat(), + type.getNameFilter(), + name + ); + + String uri = urlBase + path; + final HttpResponse<JsonNode> response = syncRestClient.get(uri, getRequestHeaders(), Collections.emptyMap()); + + return response.isSuccessful(); } @Override diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java index ad43746ca..57ec519c8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/AaiOverTLSClientInterface.java @@ -22,7 +22,6 @@ package org.onap.vid.aai; import io.joshworks.restclient.http.HttpResponse; import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.aai.model.AaiNodeQueryResponse; import org.onap.vid.aai.model.ResourceType; import org.onap.vid.model.SubscriberList; @@ -44,7 +43,7 @@ public interface AaiOverTLSClientInterface { void setUseClientCert(boolean useClientCert); - HttpResponse<AaiNodeQueryResponse> searchNodeTypeByName(String name, ResourceType type); + boolean isNodeTypeExistsByName(String name, ResourceType type); HttpResponse<SubscriberList> getAllSubscribers(); 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 index c7a98a8cc..a0a8a30d6 100644 --- 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 @@ -1,7 +1,7 @@ package org.onap.vid.aai; +import com.fasterxml.jackson.databind.JsonNode; import org.apache.commons.lang3.StringUtils; -import org.codehaus.jackson.JsonNode; import org.springframework.stereotype.Component; import java.util.Optional; @@ -26,7 +26,7 @@ public class AaiResponseTranslator { for (JsonNode resultNode : results) { final JsonNode nodeType = resultNode.path("node-type"); - if (nodeType.isTextual() && "cloud-region".equals(nodeType.getTextValue())) { + if (nodeType.isTextual() && "cloud-region".equals(nodeType.textValue())) { return getPortMirroringConfigData(payload, resultNode); } } 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 index cd1f9044b..a1806f0c3 100644 --- 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 @@ -3,9 +3,8 @@ package org.onap.vid.aai; import org.springframework.http.HttpMethod; -import java.io.Serializable; -public class AaiResponseWithRequestInfo<T> implements Serializable { +public class AaiResponseWithRequestInfo<T> { private AaiResponse<T> aaiResponse; private String requestedUrl; private String rawData; 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 index dcca3ec4b..388c38193 100644 --- 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 @@ -42,13 +42,13 @@ public class ExceptionWithRequestInfo extends RuntimeException { private static String toMessage(HttpMethod httpMethod, String requestedUrl, Throwable cause) { if (StringUtils.isEmpty(requestedUrl)) { - return cause.toString(); + return String.valueOf(cause); } else { return "" + "Exception while handling " + defaultIfNull(httpMethod, "request").toString() + " " + requestedUrl + - ": " + cause.toString(); + ": " + (cause == null ? "null" : cause.toString()); } } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/OperationalEnvironment.java b/vid-app-common/src/main/java/org/onap/vid/aai/OperationalEnvironment.java index 10ad4e963..4b4a496cc 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/OperationalEnvironment.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/OperationalEnvironment.java @@ -1,12 +1,9 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; -import org.onap.vid.aai.model.Relationship; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import org.onap.vid.aai.model.RelationshipList; -import java.util.List; - @JsonIgnoreProperties(ignoreUnknown = true) public class OperationalEnvironment { @@ -33,75 +30,75 @@ public class OperationalEnvironment { this.relationshipList = relationshipList; } - @JsonProperty("operational-environment-id") public String getOperationalEnvironmentId() { return operationalEnvironmentId; } - public void setOperationalEnvironmentId(String operationalEnvironmentId) { + @JsonProperty("operational-environment-id") + public void setJsonOperationalEnvironmentId(String operationalEnvironmentId) { this.operationalEnvironmentId = operationalEnvironmentId; } - @JsonProperty("operational-environment-name") public String getOperationalEnvironmentName() { return operationalEnvironmentName; } - public void setOperationalEnvironmentName(String operationalEnvironmentName) { + @JsonProperty("operational-environment-name") + public void setJsonOperationalEnvironmentName(String operationalEnvironmentName) { this.operationalEnvironmentName = operationalEnvironmentName; } - @JsonProperty("operational-environment-type") public String getOperationalEnvironmentType() { return operationalEnvironmentType; } - public void setOperationalEnvironmentType(String operationalEnvironmentType) { + @JsonProperty("operational-environment-type") + public void setJsonOperationalEnvironmentType(String operationalEnvironmentType) { this.operationalEnvironmentType = operationalEnvironmentType; } - @JsonProperty("operational-environment-status") public String getOperationalEnvironmentStatus() { return operationalEnvironmentStatus; } - public void setOperationalEnvironmentStatus(String operationalEnvironmentStatus) { + @JsonProperty("operational-environment-status") + public void setJsonOperationalEnvironmentStatus(String operationalEnvironmentStatus) { this.operationalEnvironmentStatus = operationalEnvironmentStatus; } - @JsonProperty("tenant-context") public String getTenantContext() { return tenantContext; } - public void setTenantContext(String tenantContext) { + @JsonProperty("tenant-context") + public void setJsonTenantContext(String tenantContext) { this.tenantContext = tenantContext; } - @JsonProperty("workload-context") public String getWorkloadContext() { return workloadContext; } - public void setWorkloadContext(String workloadContext) { + @JsonProperty("workload-context") + public void setJsonWorkloadContext(String workloadContext) { this.workloadContext = workloadContext; } - @JsonProperty("resource-version") public String getResourceVersion() { return resourceVersion; } - public void setResourceVersion(String resourceVersion) { + @JsonProperty("resource-version") + public void setJsonResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } - @JsonProperty("relationship-list") public RelationshipList getRelationshipList() { return relationshipList; } - public void setRelationshipList(RelationshipList relationshipList) { + @JsonProperty("relationship-list") + public void setJsonRelationshipList(RelationshipList relationshipList) { this.relationshipList = relationshipList; } } 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 index 28b6f542f..000628d8a 100644 --- 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 @@ -1,21 +1,15 @@ 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.onap.vid.model.PombaInstance.PombaRequest; 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); @@ -29,22 +23,15 @@ public class PombaClientImpl implements PombaClientInterface { @Override public void verify(PombaRequest request) { String methodName = "doAaiPost"; - logger.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + "<== " + methodName + " start"); + logger.debug(EELFLoggerDelegate.debugLogger, methodName + " start"); String uri = SystemProperties.getProperty("pomba.server.url"); try { - Response response = pombaRestInterface.RestPost(fromAppId, uri, new ObjectMapper().writeValueAsString(request)); + 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()); + logger.info(EELFLoggerDelegate.errorLogger, methodName + e.toString()); + logger.debug(EELFLoggerDelegate.debugLogger, 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/PombaRestInterface.java b/vid-app-common/src/main/java/org/onap/vid/aai/PombaRestInterface.java index c4bc852ff..63762373a 100644 --- 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 @@ -42,11 +42,12 @@ public class PombaRestInterface extends AAIRestInterface { private Client client = null; - private void initRestClient() + @Override + protected void initRestClient() { if (client == null) { try { - client = httpsAuthClientFactory.getClient(HttpClientMode.UNSECURE); + client = httpsAuthClientFactory.getClient(HttpClientMode.WITH_KEYSTORE); } catch (Exception e) { logger.info(EELFLoggerDelegate.errorLogger, "Exception in REST call to DB in initRestClient" + e.toString()); @@ -78,6 +79,7 @@ public class PombaRestInterface extends AAIRestInterface { } else { logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, cres)); } + return cres; } catch (Exception e) { logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e)); } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstance.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstance.java index 26f4a21e7..59f367339 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstance.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstance.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class ServiceInstance { @@ -11,16 +11,16 @@ public class ServiceInstance { @JsonProperty("service-instance-name") public String serviceInstanceName; - + @JsonProperty("persona-model-id") public String personaModelId; - + @JsonProperty("persona-model-version") public String personaModelVersion; - + @JsonProperty("resource-version") public String resourceVersion; - + @JsonProperty("orchestration-status") public String orchestrationStatus; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstances.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstances.java index c92a47a36..fb5f18b64 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstances.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstances.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstancesSearchResults.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstancesSearchResults.java index b32a83a13..79d90986b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstancesSearchResults.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceInstancesSearchResults.java @@ -1,10 +1,9 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import org.onap.vid.model.ServiceInstanceSearchResult; -import java.util.ArrayList; import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscription.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscription.java index 5dc9d526b..805780144 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscription.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscription.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class ServiceSubscription { diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscriptions.java b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscriptions.java index 686dc7d60..8938f2cdf 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscriptions.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/ServiceSubscriptions.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/Services.java b/vid-app-common/src/main/java/org/onap/vid/aai/Services.java index fe70de5af..2a7fc407b 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/Services.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/Services.java @@ -1,7 +1,7 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Services { @@ -16,7 +16,7 @@ public class Services { @JsonProperty("resource-version") public String resourceVersion; - + @JsonProperty("service-subscriptions") public ServiceSubscriptions serviceSubscriptions; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberWithFilter.java b/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberWithFilter.java index aaaa14455..a91e33e5c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberWithFilter.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/SubscriberWithFilter.java @@ -1,6 +1,6 @@ package org.onap.vid.aai; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import org.onap.vid.model.Subscriber; /** diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java index c30aaeb8f..f91797a79 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/AicZones.java @@ -1,8 +1,8 @@ package org.onap.vid.aai.model.AaiGetAicZone; -import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; -import org.codehaus.jackson.annotate.JsonProperty; +import java.util.List; public class AicZones { @JsonProperty("zone") diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java index 89400f20e..13e26844c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetAicZone/Zone.java @@ -1,13 +1,13 @@ package org.onap.vid.aai.model.AaiGetAicZone; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Zone { @JsonProperty("zone-id") public String zoneId; - + @JsonProperty("zone-name") public String zoneName; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/CloudRegion.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/CloudRegion.java new file mode 100644 index 000000000..38dd2b128 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/CloudRegion.java @@ -0,0 +1,55 @@ +package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.apache.commons.lang3.ObjectUtils; + +import java.util.List; + +import static java.util.Collections.emptyList; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class CloudRegion { + + private final String cloudOwner; + private final String cloudRegionId; + + public CloudRegion( + @JsonProperty("cloud-owner") String cloudOwner, + @JsonProperty("cloud-region-id") String cloudRegionId + ) { + this.cloudOwner = cloudOwner; + this.cloudRegionId = cloudRegionId; + } + + public String getCloudOwner() { + return cloudOwner; + } + + public String getCloudRegionId() { + return cloudRegionId; + } + + /* + This will handle container like: + { + "cloud-region": [{ + "cloud-owner": "alfi", + "cloud-region-id": "foo", + . . . + }, { + "cloud-owner": "alba", + "cloud-region-id": "bar", + */ + public static class Collection { + private final List<CloudRegion> cloudRegions; + + public Collection(@JsonProperty("cloud-region") List<CloudRegion> cloudRegions) { + this.cloudRegions = ObjectUtils.defaultIfNull(cloudRegions, emptyList()); + } + + public List<CloudRegion> getCloudRegions() { + return cloudRegions; + } + } +} 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 index 29450a8f8..41b720a4d 100644 --- 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 @@ -2,9 +2,10 @@ package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; @JsonIgnoreProperties(ignoreUnknown = true) -public class Network { +public class Network implements AaiModelWithRelationships { @JsonProperty("network-id") private String networkId; @JsonProperty("network-name") @@ -19,6 +20,8 @@ public class Network { private Boolean isBoundToVpn; @JsonProperty("resource-version") private String resourceVersion; + @JsonProperty("orchestration-status") + private String orchestrationStatus; @JsonProperty("is-provider-network") private Boolean isProviderNetwork; @JsonProperty("is-shared-network") @@ -99,6 +102,16 @@ public class Network { this.resourceVersion = resourceVersion; } + @JsonProperty("orchestration-status") + public String getOrchestrationStatus() { + return orchestrationStatus; + } + + @JsonProperty("orchestration-status") + public void setOrchestrationStatus(String orchestrationStatus) { + this.orchestrationStatus = orchestrationStatus; + } + @JsonProperty("is-provider-network") public Boolean getIsProviderNetwork() { return isProviderNetwork; @@ -129,6 +142,7 @@ public class Network { this.isExternalNetwork = isExternalNetwork; } + @Override @JsonProperty("relationship-list") public RelationshipList getRelationshipList() { return relationshipList; 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 index c366402e4..49b8536c1 100644 --- 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 @@ -1,17 +1,51 @@ package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; + +import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL; @JsonIgnoreProperties(ignoreUnknown = true) -public class ServiceInstance { +public class ServiceInstance implements AaiModelWithRelationships { + + private final String serviceInstanceId; + private final String serviceInstanceName; + private final String resourceVersion; + private final RelationshipList relationshipList; + + public ServiceInstance( + @JsonProperty("service-instance-id") String serviceInstanceId, + @JsonProperty("service-instance-name") String serviceInstanceName, + @JsonProperty("resource-version") String resourceVersion, + @JsonProperty("relationship-list") RelationshipList relationshipList + ) { + this.serviceInstanceId = serviceInstanceId; + this.serviceInstanceName = serviceInstanceName; + this.resourceVersion = resourceVersion; + this.relationshipList = relationshipList; + } @JsonProperty("service-instance-id") - public String serviceInstanceId; + public String getServiceInstanceId() { + return serviceInstanceId; + } + + @JsonProperty("service-instance-name") + @JsonInclude(NON_NULL) + public String getServiceInstanceName() { + return serviceInstanceName; + } @JsonProperty("resource-version") - public String resourceVersion; + public String getResourceVersion() { + return resourceVersion; + } + @Override @JsonProperty("relationship-list") - public RelationshipList relationshipList; + public RelationshipList getRelationshipList() { + return relationshipList; + } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vlan.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vlan.java new file mode 100644 index 000000000..a18464850 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vlan.java @@ -0,0 +1,41 @@ +package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class Vlan implements AaiModelWithRelationships { + + public Vlan( + @JsonProperty("vlan-interface") String vlanInterface, + @JsonProperty("vlan-id-inner") String vlanIdInner, + @JsonProperty("relationship-list") RelationshipList relationshipList) { + this.vlanInterface = vlanInterface; + this.vlanIdInner = vlanIdInner; + this.relationshipList = relationshipList; + } + + @JsonProperty("vlan-interface") + private final String vlanInterface; + + @JsonProperty("vlan-id-inner") + private final String vlanIdInner; + + @JsonProperty("relationship-list") + public final RelationshipList relationshipList; + + public String getVlanInterface() { + return vlanInterface; + } + + public String getVlanIdInner() { + return vlanIdInner; + } + + @Override + public RelationshipList getRelationshipList() { + return relationshipList; + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vnf.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vnf.java new file mode 100644 index 000000000..5dc6e4d3b --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetNetworkCollectionDetails/Vnf.java @@ -0,0 +1,84 @@ +package org.onap.vid.aai.model.AaiGetNetworkCollectionDetails; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class Vnf implements AaiModelWithRelationships { + @JsonProperty("vnf-id") + private String vnfId; + @JsonProperty("vnf-name") + private String vnfName; + @JsonProperty("vnf-type") + private String vnfType; + @JsonProperty("resource-version") + private String resourceVersion; + @JsonProperty("orchestration-status") + private String orchestrationStatus; + @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("resource-version") + public String getResourceVersion() { + return resourceVersion; + } + + @JsonProperty("resource-version") + public void setResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + + @JsonProperty("orchestration-status") + public String getOrchestrationStatus() { + return orchestrationStatus; + } + + @JsonProperty("orchestration-status") + public void setOrchestrationStatus(String orchestrationStatus) { + this.orchestrationStatus = orchestrationStatus; + } + + @Override + @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/AaiGetOperationalEnvironments/OperationalEnvironmentList.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetOperationalEnvironments/OperationalEnvironmentList.java index 1f31cfaa9..254d5edc4 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetOperationalEnvironments/OperationalEnvironmentList.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetOperationalEnvironments/OperationalEnvironmentList.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model.AaiGetOperationalEnvironments; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.onap.vid.aai.OperationalEnvironment; import java.util.List; @@ -9,12 +9,11 @@ import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) public class OperationalEnvironmentList { - @JsonProperty("operational-environment") public List<OperationalEnvironment> getOperationalEnvironment() { return operationalEnvironment; } - @JsonProperty("operational-environment") + @JsonAlias("operational-environment") public void setOperationalEnvironment(List<OperationalEnvironment> operationalEnvironment) { this.operationalEnvironment = operationalEnvironment; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfResponse.java index fa9fe9350..93c12c8e3 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfResponse.java @@ -1,12 +1,7 @@ package org.onap.vid.aai.model; -import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.*; import com.google.common.base.MoreObjects; -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 org.codehaus.jackson.annotate.JsonPropertyOrder; import java.util.HashMap; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfs/Pnf.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfs/Pnf.java index 00a731a70..d359474d9 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfs/Pnf.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetPnfs/Pnf.java @@ -1,31 +1,25 @@ package org.onap.vid.aai.model.AaiGetPnfs; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import org.onap.vid.aai.model.AaiRelationResponse; @JsonIgnoreProperties(ignoreUnknown = true) public class Pnf extends AaiRelationResponse { - @JsonProperty("pnf-name") - public String pnfName; - @JsonProperty("pnf-name2") - public String pnfName2; - @JsonProperty("pnf-name2-source") - public String pnfName2Source; - @JsonProperty("pnf-id") - public String pnfId; - @JsonProperty("equip-type") - public String equipType; - @JsonProperty("equip-vendor") - public String equipVendor; - @JsonProperty("equip-model") - public String equipModel; + private String pnfName; + private String pnfName2; + private String pnfName2Source; + private String pnfId; + private String equipType; + private String equipVendor; + private String equipModel; public String getPnfName() { return pnfName; } + @JsonAlias("pnf-name") public void setPnfName(String pnfName) { this.pnfName = pnfName; } @@ -34,6 +28,7 @@ public class Pnf extends AaiRelationResponse { return equipType; } + @JsonAlias("equip-type") public void setEquipType(String equipType) { this.equipType = equipType; } @@ -42,6 +37,7 @@ public class Pnf extends AaiRelationResponse { return equipVendor; } + @JsonAlias("equip-vendor") public void setEquipVendor(String equipVendor) { this.equipVendor = equipVendor; } @@ -50,6 +46,7 @@ public class Pnf extends AaiRelationResponse { return pnfName2; } + @JsonAlias("pnf-name2") public void setPnfName2(String pnfName2) { this.pnfName2 = pnfName2; } @@ -58,6 +55,7 @@ public class Pnf extends AaiRelationResponse { return pnfId; } + @JsonAlias("pnf-id") public void setPnfId(String pnfId) { this.pnfId = pnfId; } @@ -66,12 +64,14 @@ public class Pnf extends AaiRelationResponse { return equipModel; } + @JsonAlias("equip-model") public void setEquipModel(String equipModel) { this.equipModel = equipModel; } public String getPnfName2Source() { return pnfName2Source; } + @JsonAlias("pnf-name2-source") public void setPnfName2Source(String pnfName2Source) { this.pnfName2Source = pnfName2Source; } } 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 index 47a57dafb..b629d9040 100644 --- 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 @@ -1,6 +1,6 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/GetServicesAAIRespone.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/GetServicesAAIRespone.java index d3dd7d26c..d5858de20 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/GetServicesAAIRespone.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/GetServicesAAIRespone.java @@ -1,7 +1,6 @@ package org.onap.vid.aai.model.AaiGetServicesRequestModel; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/Service.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/Service.java index 367287e1d..36b5a5140 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/Service.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetServicesRequestModel/Service.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model.AaiGetServicesRequestModel; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Created by Oren on 7/17/17. diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetTenatns/GetTenantsResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetTenatns/GetTenantsResponse.java index 1d0e84952..c799c8fa6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetTenatns/GetTenantsResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiGetTenatns/GetTenantsResponse.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model.AaiGetTenatns; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Created by Oren on 7/18/17. @@ -9,26 +9,29 @@ import org.codehaus.jackson.annotate.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class GetTenantsResponse { - @JsonProperty("cloudRegionID") - public String cloudRegionId; + public String cloudRegionID; - @JsonProperty("cloudOwner") public String cloudOwner; - - @JsonProperty("tenantName") + public String tenantName; - @JsonProperty("tenantID") public String tenantID; - @JsonProperty("is-permitted") public boolean isPermitted; + @JsonProperty("is-permitted") + public boolean getJsonIsPermitted() { + // this is a special case to *duplicate* the permission field + // as it might be that both -- camelCase and hyphen faces -- + // are in use + return isPermitted; + } + public GetTenantsResponse() { } public GetTenantsResponse(String cloudRegionId, String cloudOwner, String tenantName, String tenantID, boolean isPermitted) { - this.cloudRegionId = cloudRegionId; + this.cloudRegionID = cloudRegionId; this.cloudOwner = cloudOwner; this.tenantName = tenantName; this.tenantID = tenantID; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiRelationResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiRelationResponse.java index 7bc2e7a2e..981f85656 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiRelationResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/AaiRelationResponse.java @@ -1,9 +1,8 @@ package org.onap.vid.aai.model; - -import org.codehaus.jackson.annotate.JsonIgnore; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnore; import java.util.HashMap; import java.util.Map; @@ -13,30 +12,27 @@ import java.util.Map; */ public class AaiRelationResponse { - @JsonProperty("resource-version") private String resourceVersion; - @JsonProperty("relationship-list") private RelationshipList relationshipList; + @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + private Map<String, Object> additionalProperties = new HashMap<>(); - @JsonProperty("resource-version") public String getResourceVersion() { return resourceVersion; } - @JsonProperty("resource-version") + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } - @JsonProperty("relationship-list") public RelationshipList getRelationshipList() { return relationshipList; } - @JsonProperty("relationship-list") + @JsonAlias("relationship-list") public void setRelationshipList(RelationshipList relationshipList) { this.relationshipList = relationshipList; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/CustomQuerySimpleResult.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/CustomQuerySimpleResult.java new file mode 100644 index 000000000..4f91b7566 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/CustomQuerySimpleResult.java @@ -0,0 +1,18 @@ +package org.onap.vid.aai.model; + +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.List; + +public class CustomQuerySimpleResult { + + private final List<SimpleResult> results; + + public CustomQuerySimpleResult(@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/GetServiceModelsByDistributionStatusResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/GetServiceModelsByDistributionStatusResponse.java index 5a6924dcb..c17f930c0 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/GetServiceModelsByDistributionStatusResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/GetServiceModelsByDistributionStatusResponse.java @@ -1,8 +1,8 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/LogicalLinkResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/LogicalLinkResponse.java index 6625957ec..4d815bc3d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/LogicalLinkResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/LogicalLinkResponse.java @@ -1,31 +1,26 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; public class LogicalLinkResponse { - @JsonProperty("link-name") public String linkName; - @JsonProperty("in-maint") public Boolean inMaint; - @JsonProperty("link-type") public String linkType; - @JsonProperty("resource-version") public String resourceVersion; - @JsonProperty("purpose") public String purpose; - @JsonProperty("relationship-list") public RelationshipList relationshipList; public String getLinkName() { return linkName; } + @JsonAlias("link-name") public void setLinkName(String linkName) { this.linkName = linkName; } @@ -34,6 +29,7 @@ public class LogicalLinkResponse { return inMaint; } + @JsonAlias("in-maint") public void setInMaint(Boolean inMaint) { this.inMaint = inMaint; } @@ -42,6 +38,7 @@ public class LogicalLinkResponse { return linkType; } + @JsonAlias("link-type") public void setLinkType(String linkType) { this.linkType = linkType; } @@ -50,6 +47,7 @@ public class LogicalLinkResponse { return resourceVersion; } + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } @@ -58,6 +56,7 @@ public class LogicalLinkResponse { return purpose; } + @JsonAlias("purpose") public void setPurpose(String purpose) { this.purpose = purpose; } @@ -66,6 +65,7 @@ public class LogicalLinkResponse { return relationshipList; } + @JsonAlias("relationship-list") public void setRelationshipList(RelationshipList relationshipList) { this.relationshipList = relationshipList; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Model.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Model.java index 5f422f68a..7a771e4e8 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/Model.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Model.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; /** * Created by moriya1 on 15/10/2017. @@ -9,51 +9,43 @@ import org.codehaus.jackson.annotate.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) public class Model { - @JsonProperty("model-invariant-id") private String modelInvariantId; - @JsonProperty("model-type") private String modelType; - @JsonProperty("resource-version") private String resourceVersion; - @JsonProperty("model-vers") private ModelVers modelVers; - @JsonProperty("model-invariant-id") public String getModelInvariantId() { return modelInvariantId; } - @JsonProperty("model-invariant-id") + @JsonAlias("model-invariant-id") public void setModelInvariantId(String modelInvariantId) { this.modelInvariantId = modelInvariantId; } - @JsonProperty("model-type") public String getModelType() { return modelType; } - @JsonProperty("model-type") + @JsonAlias("model-type") public void setModelType(String modelType) { this.modelType = modelType; } - @JsonProperty("resource-version") public String getResourceVersion() { return resourceVersion; } - @JsonProperty("resource-version") + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } - @JsonProperty("model-vers") public ModelVers getModelVers() { return modelVers; } - @JsonProperty("model-vers") + @JsonAlias("model-vers") public void setModelVers(ModelVers modelVers) { this.modelVers = modelVers; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java index f02bbacfe..6908feb71 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVer.java @@ -1,82 +1,70 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class ModelVer { - @JsonProperty("model-version-id") private String modelVersionId; - @JsonProperty("model-name") private String modelName; - @JsonProperty("model-version") private String modelVersion; - @JsonProperty("distribution-status") private String distributionStatus; - @JsonProperty("resource-version") private String resourceVersion; - @JsonProperty("model-description") private String modelDescription; - @JsonProperty("model-version-id") public String getModelVersionId() { return modelVersionId; } - @JsonProperty("model-version-id") + @JsonAlias("model-version-id") public void setModelVersionId(String modelVersionId) { this.modelVersionId = modelVersionId; } - @JsonProperty("model-name") public String getModelName() { return modelName; } - @JsonProperty("model-name") + @JsonAlias("model-name") public void setModelName(String modelName) { this.modelName = modelName; } - @JsonProperty("model-version") public String getModelVersion() { return modelVersion; } - @JsonProperty("model-version") + @JsonAlias("model-version") public void setModelVersion(String modelVersion) { this.modelVersion = modelVersion; } - @JsonProperty("distribution-status") public String getDistributionStatus() { return distributionStatus; } - @JsonProperty("distribution-status") + @JsonAlias("distribution-status") public void setDistributionStatus(String distributionStatus) { this.distributionStatus = distributionStatus; } - @JsonProperty("resource-version") public String getResourceVersion() { return resourceVersion; } - @JsonProperty("resource-version") + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } - @JsonProperty("model-description") public String getModelDescription() { return modelDescription; } - @JsonProperty("model-description") + @JsonAlias("model-description") public void setModelDescription(String modelDescription) { this.modelDescription = modelDescription; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVers.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVers.java index f352158f2..eed40fc00 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVers.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ModelVers.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.util.List; @@ -11,15 +11,13 @@ import java.util.List; @JsonIgnoreProperties(ignoreUnknown = true) public class ModelVers { - @JsonProperty("model-ver") private List<ModelVer> modelVer; - @JsonProperty("model-ver") public List<ModelVer> getModelVer() { return modelVer; } - @JsonProperty("model-ver") + @JsonAlias("model-ver") public void setModelVer(List<ModelVer> modelVer) { this.modelVer = modelVer; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntity.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntity.java index edf5242d6..366a1088f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntity.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntity.java @@ -1,33 +1,29 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; /** * Created by moriya1 on 08/10/2017. */ public class OwningEntity extends AaiRelationResponse { - @JsonProperty("owning-entity-id") private String owningEntityId; - @JsonProperty("owning-entity-name") private String owningEntityName; - @JsonProperty("owning-entity-id") public String getOwningEntityId() { return owningEntityId; } - @JsonProperty("owning-entity-id") + @JsonAlias("owning-entity-id") public void setOwningEntityId(String owningEntityId) { this.owningEntityId = owningEntityId; } - @JsonProperty("owning-entity-name") public String getOwningEntityName() { return owningEntityName; } - @JsonProperty("owning-entity-name") + @JsonAlias("owning-entity-name") public void setOwningEntityName(String owningEntityName) { this.owningEntityName = owningEntityName; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntityResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntityResponse.java index 3a571ea14..1d9bd8393 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntityResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/OwningEntityResponse.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; @@ -10,17 +10,15 @@ import java.util.List; */ public class OwningEntityResponse { - @JsonProperty("owning-entity") private List<OwningEntity> owningEntity; - @JsonProperty("owning-entity") public List<OwningEntity> getOwningEntity() { return owningEntity; } @JsonProperty("owning-entity") - public void setOwningEntity(List<OwningEntity> owningEntity) { + public void setJsonOwningEntity(List<OwningEntity> owningEntity) { this.owningEntity = owningEntity; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Permissions.kt b/vid-app-common/src/main/java/org/onap/vid/aai/model/Permissions.kt new file mode 100644 index 000000000..472da8db4 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Permissions.kt @@ -0,0 +1,6 @@ +package org.onap.vid.aai.model + +import com.fasterxml.jackson.annotation.JsonProperty + + +data class Permissions(@get:JsonProperty("isEditPermitted") val isEditPermitted: Boolean)
\ No newline at end of file diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfProperties.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfProperties.java index 3481d263e..032714b93 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfProperties.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfProperties.java @@ -1,12 +1,6 @@ package org.onap.vid.aai.model; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.*; import java.util.HashMap; import java.util.Map; @@ -23,20 +17,15 @@ import java.util.Map; }) public class PnfProperties { - @JsonProperty("pnf-name") public String pnfName; - @JsonProperty("equip-type") public String equipType; - @JsonProperty("equip-vendor") public String equipVendor; - @JsonProperty("equip-model") public String equipModel; - @JsonProperty("in-maint") public Boolean inMaint; - @JsonProperty("resource-version") public String resourceVersion; + @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + private Map<String, Object> additionalProperties = new HashMap<>(); @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { @@ -48,4 +37,34 @@ public class PnfProperties { this.additionalProperties.put(name, value); } + @JsonProperty("pnf-name") + public void setJsonPnfName(String pnfName) { + this.pnfName = pnfName; + } + + @JsonProperty("equip-type") + public void setJsonEquipType(String equipType) { + this.equipType = equipType; + } + + @JsonProperty("equip-vendor") + public void setJsonEquipVendor(String equipVendor) { + this.equipVendor = equipVendor; + } + + @JsonProperty("equip-model") + public void setJsonEquipModel(String equipModel) { + this.equipModel = equipModel; + } + + @JsonProperty("in-maint") + public void setJsonInMaint(Boolean inMaint) { + this.inMaint = inMaint; + } + + @JsonProperty("resource-version") + public void setJsonResourceVersion(String resourceVersion) { + this.resourceVersion = resourceVersion; + } + } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfResult.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfResult.java index a727d8f3c..a2c3d3bed 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfResult.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/PnfResult.java @@ -1,12 +1,6 @@ package org.onap.vid.aai.model; -import com.fasterxml.jackson.annotation.JsonAnyGetter; -import com.fasterxml.jackson.annotation.JsonAnySetter; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.codehaus.jackson.annotate.JsonProperty; -import org.onap.vid.RelatedTo; +import com.fasterxml.jackson.annotation.*; import java.util.HashMap; import java.util.List; @@ -23,19 +17,39 @@ import java.util.Map; }) public class PnfResult { - @JsonProperty("id") public String id; - @JsonProperty("node-type") public String nodeType; - @JsonProperty("url") public String url; - @JsonProperty("properties") public PnfProperties properties; - @JsonProperty("related-to") public List<RelatedTo> relatedTo; @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + private Map<String, Object> additionalProperties = new HashMap<>(); + + @JsonProperty("id") + public void setJsonId(String id) { + this.id = id; + } + + @JsonProperty("node-type") + public void setJsonNodeType(String nodeType) { + this.nodeType = nodeType; + } + + @JsonProperty("url") + public void setJsonUrl(String url) { + this.url = url; + } + + @JsonProperty("properties") + public void setJsonProperties(PnfProperties properties) { + this.properties = properties; + } + + @JsonProperty("related-to") + public void setJsonRelatedTo(List<RelatedTo> relatedTo) { + this.relatedTo = relatedTo; + } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { 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 index f8980457a..ae74af6fa 100644 --- 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 @@ -3,10 +3,7 @@ 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; @@ -15,10 +12,7 @@ import java.util.stream.Collectors; public class PortDetailsTranslator { - @Inject - FeatureManager featureManager; - - public static class PortDetailsOk extends PortDetails { + public static class PortDetailsOk implements PortDetails { private final String interfaceId; private final String interfaceName; @@ -43,16 +37,16 @@ public class PortDetailsTranslator { } } - public abstract static class PortDetails { + public interface PortDetails { } - public static class PortDetailsError extends PortDetails { + public static class PortDetailsError implements PortDetails { private final String errorDescription; private final String rawAaiResponse; - public PortDetailsError(String errorDescription, String rawAaiResponse){ - this.errorDescription = errorDescription; - this.rawAaiResponse = rawAaiResponse; + public PortDetailsError(String errorDescription, String rawAaiResponse) { + this.errorDescription = errorDescription; + this.rawAaiResponse = rawAaiResponse; } public String getErrorDescription() { @@ -64,13 +58,13 @@ public class PortDetailsTranslator { } } - public static PortDetails extractPortDetailsFromProperties(Properties properties, String rawPayload){ + 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()){ + if (errorDescriptions.isEmpty()) { return new PortDetailsOk(properties.getInterfaceId(), properties.getInterfaceName(), properties.getIsPortMirrored()); } else { return new PortDetailsError(String.join(" ", errorDescriptions), rawPayload); @@ -90,14 +84,14 @@ public class PortDetailsTranslator { final String errorMessage = aaiResponse.getErrorMessage(); return Optional.of(ImmutableList.of(new PortDetailsError( "Got " + aaiResponse.getHttpCode() + " from aai", - errorMessage != null ? errorMessage.toString() : rawPayload) + errorMessage != null ? errorMessage : rawPayload) )); } else { return Optional.empty(); } } - public List<PortDetails> extractPortDetailsInternal(AaiGetPortMirroringSourcePorts aaiGetPortsResponse, String rawPayload){ + public List<PortDetails> extractPortDetailsInternal(CustomQuerySimpleResult aaiGetPortsResponse, String rawPayload) { List<SimpleResult> filteredResult = getFilteredPortList(aaiGetPortsResponse.getResults()); return filteredResult.stream() @@ -107,7 +101,7 @@ public class PortDetailsTranslator { } public List<SimpleResult> getFilteredPortList(List<SimpleResult> results) { - String LINTERFACE = "l-interface"; + final String LINTERFACE = "l-interface"; final Predicate<SimpleResult> ifIsPort = (SimpleResult r) -> LINTERFACE.equals(r.getNodeType()); Predicate<SimpleResult> ifIsSource = getIsSourcePredicate(); @@ -119,18 +113,12 @@ public class PortDetailsTranslator { } 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; - } + final String PORT_LABEL = "org.onap.relationships.inventory.Source"; + return (SimpleResult r) -> r.getRelatedTo().stream() + .anyMatch(relatedTo -> PORT_LABEL.equalsIgnoreCase(relatedTo.getRelationshipLabel())); } - public List<PortDetails> extractPortDetails(AaiResponse<AaiGetPortMirroringSourcePorts> aaiGetPortsResponse, String rawPayload){ + public List<PortDetails> extractPortDetails(AaiResponse<CustomQuerySimpleResult> 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/Project.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Project.java index 5931bb97a..4e9f945c4 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/Project.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Project.java @@ -1,20 +1,18 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; /** * Created by moriya1 on 08/10/2017. */ public class Project extends AaiRelationResponse { - @JsonProperty("project-name") private String projectName; - @JsonProperty("project-name") public String getProjectName() { return projectName; } - @JsonProperty("project-name") + @JsonAlias("project-name") public void setProjectName(String projectName) { this.projectName = projectName; } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ProjectResponse.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ProjectResponse.java index 0ca35b0a9..125e1061d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ProjectResponse.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ProjectResponse.java @@ -1,8 +1,6 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; - import java.util.List; /** @@ -10,16 +8,13 @@ import java.util.List; */ public class ProjectResponse { - @JsonProperty("project") private List<Project> project; - @JsonProperty("project") public List<Project> getProject() { return project; } - @JsonProperty("project") public void setProject(List<Project> project) { this.project = project; } 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 index 6fecbed53..dec632ea8 100644 --- 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 @@ -1,23 +1,38 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonProperty; + +import java.util.HashMap; +import java.util.Map; -@JsonIgnoreProperties(ignoreUnknown = true) public class Properties { - private final String interfaceName; - private final String interfaceId; - private final Boolean isPortMirrored; + //properties for l-interface node-type + @JsonProperty("interface-name") + private String interfaceName; - 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; - } + @JsonProperty("interface-id") + private String interfaceId; + + @JsonProperty("is-port-mirrored") + private Boolean isPortMirrored; + + //properties for tenant node-type + @JsonProperty("tenant-id") + private String tenantId; + + @JsonProperty("tenant-name") + private String tenantName; + + //properties for cloud-region node-type + @JsonProperty("cloud-region-id") + private String cloudRegionId; + + private Map<String, String> additionalProperties = new HashMap<>(); + + public Properties(){} public String getInterfaceName() { return interfaceName; @@ -30,4 +45,38 @@ public class Properties { public Boolean getIsPortMirrored() { return isPortMirrored; } + + public String getTenantId() { + return tenantId; + } + + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + public String getTenantName() { + return tenantName; + } + + public void setTenantName(String tenantName) { + this.tenantName = tenantName; + } + + public String getCloudRegionId() { + return cloudRegionId; + } + + public void setCloudRegionId(String cloudRegionId) { + this.cloudRegionId = cloudRegionId; + } + + @JsonAnyGetter + public Map<String, String> getAdditionalProperties() { + return additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperties(String name, String value) { + additionalProperties.put(name, value); + } } 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 index f14a445fe..fa0351e85 100644 --- 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 @@ -1,9 +1,11 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; @JsonIgnoreProperties(ignoreUnknown = true) +@JsonInclude(JsonInclude.Include.NON_NULL) public class RelatedTo { private final String id; private final String relationshipLabel; @@ -20,19 +22,19 @@ public class RelatedTo { this.nodeType = nodeType; this.url = url; } - + @JsonProperty("id") public String getId() { return id; } - + @JsonProperty("relationship-label") public String getRelationshipLabel() { return relationshipLabel; } - + @JsonProperty("node-type") public String getNodeType() { return nodeType; } - + @JsonProperty("url") 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 a2a98fc27..9227e87cf 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,8 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonIgnoreProperties(ignoreUnknown = true) public class RelatedToProperty { @@ -12,6 +12,7 @@ public class RelatedToProperty { } + @JsonAlias("property-key") public void setPropertyKey(String propertyKey) { this.propertyKey = propertyKey; } @@ -22,16 +23,15 @@ public class RelatedToProperty { } + @JsonAlias("property-value") 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/Relationship.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Relationship.java index 6bf63c433..d6ba8d84e 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,7 +1,8 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + import java.util.List; @@ -9,19 +10,14 @@ 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; @@ -29,6 +25,7 @@ public class Relationship { return relatedTo; } + @JsonAlias("related-to") public void setRelatedTo(String relatedTo) { this.relatedTo = relatedTo; } @@ -37,6 +34,7 @@ public class Relationship { return relatedLink; } + @JsonAlias("related-link") public void setRelatedLink(String relatedLink) { this.relatedLink = relatedLink; } @@ -45,6 +43,7 @@ public class Relationship { return relationshipData; } + @JsonAlias("relationship-data") public void setRelationDataList(List<RelationshipData> relationDataList) { this.relationshipData = relationDataList; } @@ -53,6 +52,7 @@ public class Relationship { return relatedToProperty; } + @JsonAlias("related-to-property") public void setRelatedToPropertyList(List<RelatedToProperty> relatedToPropertyList) { this.relatedToProperty = relatedToPropertyList; } @@ -61,6 +61,7 @@ public class Relationship { return relationshipLabel; } + @JsonAlias("relationship-label") public void setRelationshipLabel(String relationshipLabel) { this.relationshipLabel = relationshipLabel; } 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 415366514..55a0b77df 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,29 +1,29 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @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; - public String relationshipKey; - - public String relationshipValue; + public String getRelationshipKey() { + return relationshipKey; + } + + @JsonAlias("relationship-key") + public void setRelationshipKey(String relationshipKey) { + this.relationshipKey = relationshipKey; + } + + public String getRelationshipValue() { + return relationshipValue; + } + + @JsonAlias("relationship-value") + public void setRelationshipValue(String relationshipValue) { + this.relationshipValue = 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 b16ddd01c..f51fb9dfd 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,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; 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 index 736a1aa9e..79f5272cb 100644 --- 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 @@ -10,10 +10,12 @@ 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"); + SERVICE_INSTANCE("service-instances", "service-instance-name"), + GENERIC_VNF("generic-vnfs", "vnf-name"), + L3_NETWORK("l3-networks", "network-name"), + VF_MODULE("vf-modules", "vf-module-name"), + INSTANCE_GROUP("instance-groups", "instance-group-name"), + VOLUME_GROUP("volume-groups", "volume-group-name"); private static Map<String, ResourceType> AAI_FORMAT_MAP = Stream .of(ResourceType.values()) diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/Result.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/Result.java index 1eb46be75..cb4dc869c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/Result.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/Result.java @@ -1,7 +1,7 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Created by moriya1 on 15/10/2017. diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceProperties.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceProperties.java index a76bcf8a1..a1962cc53 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceProperties.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceProperties.java @@ -1,8 +1,6 @@ package org.onap.vid.aai.model; import com.fasterxml.jackson.annotation.*; -import org.codehaus.jackson.annotate.JsonIgnoreProperties; -import org.codehaus.jackson.annotate.JsonProperty; import java.util.HashMap; import java.util.Map; @@ -35,70 +33,49 @@ import java.util.Map; public class ServiceProperties { @JsonProperty("service-instance-id") - @com.fasterxml.jackson.annotation.JsonProperty("service-instance-id") public String serviceInstanceId; @JsonProperty("service-instance-name") - @com.fasterxml.jackson.annotation.JsonProperty("service-instance-name") public String serviceInstanceName; @JsonProperty("model-invariant-id") - @com.fasterxml.jackson.annotation.JsonProperty("model-invariant-id") public String modelInvariantId; @JsonProperty("model-version-id") - @com.fasterxml.jackson.annotation.JsonProperty("model-version-id") public String modelVersionId; @JsonProperty("resource-version") - @com.fasterxml.jackson.annotation.JsonProperty("resource-version") public String resourceVersion; @JsonProperty("orchestration-status") - @com.fasterxml.jackson.annotation.JsonProperty("orchestration-status") public String orchestrationStatus; @JsonProperty("global-customer-id") - @com.fasterxml.jackson.annotation.JsonProperty("global-customer-id") public String globalCustomerId; @JsonProperty("subscriber-name") - @com.fasterxml.jackson.annotation.JsonProperty("subscriber-name") public String subscriberName; @JsonProperty("subscriber-type") - @com.fasterxml.jackson.annotation.JsonProperty("subscriber-type") public String subscriberType; @JsonProperty("vnf-id") - @com.fasterxml.jackson.annotation.JsonProperty("vnf-id") public String vnfId; @JsonProperty("vnf-name") - @com.fasterxml.jackson.annotation.JsonProperty("vnf-name") public String vnfName; @JsonProperty("vnf-type") - @com.fasterxml.jackson.annotation.JsonProperty("vnf-type") public String vnfType; @JsonProperty("service-id") - @com.fasterxml.jackson.annotation.JsonProperty("service-id") public String serviceId; @JsonProperty("prov-status") - @com.fasterxml.jackson.annotation.JsonProperty("prov-status") public String provStatus; @JsonProperty("in-maint") - @com.fasterxml.jackson.annotation.JsonProperty("in-maint") public Boolean inMaint; @JsonProperty("is-closed-loop-disabled") - @com.fasterxml.jackson.annotation.JsonProperty("is-closed-loop-disabled") public Boolean isClosedLoopDisabled; @JsonProperty("model-customization-id") - @com.fasterxml.jackson.annotation.JsonProperty("model-customization-id") public String modelCustomizationId; @JsonProperty("nf-type") - @com.fasterxml.jackson.annotation.JsonProperty("nf-type") public String nfType; @JsonProperty("nf-function") - @com.fasterxml.jackson.annotation.JsonProperty("nf-function") public String nfFunction; @JsonProperty("nf-role") - @com.fasterxml.jackson.annotation.JsonProperty("nf-role") public String nfRole; @JsonProperty("nf-naming-code") - @com.fasterxml.jackson.annotation.JsonProperty("nf-naming-code") public String nfNamingCode; @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/model/ServiceRelationships.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceRelationships.java index b8abc8494..eba00356e 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceRelationships.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/ServiceRelationships.java @@ -1,40 +1,31 @@ package org.onap.vid.aai.model; -import org.codehaus.jackson.annotate.JsonProperty; +import com.fasterxml.jackson.annotation.JsonAlias; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +@JsonIgnoreProperties(ignoreUnknown = true) public class ServiceRelationships { - @JsonProperty("service-instance-id") public String serviceInstanceId; - @JsonProperty("service-instance-name") public String serviceInstanceName; - @JsonProperty("service-type") public String serviceType; - @JsonProperty("service-role") public String serviceRole; - @JsonProperty("environment-context") public String environmentContext; - @JsonProperty("workload-context") public String workloadContext; - @JsonProperty("model-invariant-id") public String modelInvariantId; - - @JsonProperty("model-version-id") + public String modelVersionId; - @JsonProperty("resource-version") public String resourceVersion; - - @JsonProperty("orchestration-status") + public String orchestrationStatus; - @JsonProperty("relationship-list") public RelationshipList relationshipList; @@ -42,6 +33,7 @@ public class ServiceRelationships { return serviceInstanceId; } + @JsonAlias("service-instance-id") public void setServiceInstanceId(String serviceInstanceId) { this.serviceInstanceId = serviceInstanceId; } @@ -50,6 +42,7 @@ public class ServiceRelationships { return serviceInstanceName; } + @JsonAlias("service-instance-name") public void setServiceInstanceName(String serviceInstanceName) { this.serviceInstanceName = serviceInstanceName; } @@ -58,6 +51,43 @@ public class ServiceRelationships { return modelInvariantId; } + public String getServiceType() { + return serviceType; + } + + @JsonAlias("service-type") + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } + + public String getServiceRole() { + return serviceRole; + } + + @JsonAlias("service-role") + public void setServiceRole(String serviceRole) { + this.serviceRole = serviceRole; + } + + public String getEnvironmentContext() { + return environmentContext; + } + + @JsonAlias("environment-context") + public void setEnvironmentContext(String environmentContext) { + this.environmentContext = environmentContext; + } + + public String getWorkloadContext() { + return workloadContext; + } + + @JsonAlias("workload-context") + public void setWorkloadContext(String workloadContext) { + this.workloadContext = workloadContext; + } + + @JsonAlias("model-invariant-id") public void setModelInvariantId(String modelInvariantId) { this.modelInvariantId = modelInvariantId; } @@ -66,6 +96,7 @@ public class ServiceRelationships { return modelVersionId; } + @JsonAlias("model-version-id") public void setModelVersionId(String modelVersionId) { this.modelVersionId = modelVersionId; } @@ -74,6 +105,7 @@ public class ServiceRelationships { return resourceVersion; } + @JsonAlias("resource-version") public void setResourceVersion(String resourceVersion) { this.resourceVersion = resourceVersion; } @@ -82,6 +114,7 @@ public class ServiceRelationships { return orchestrationStatus; } + @JsonAlias("orchestration-status") public void setOrchestrationStatus(String orchestrationStatus) { this.orchestrationStatus = orchestrationStatus; } @@ -90,6 +123,7 @@ public class ServiceRelationships { return relationshipList; } + @JsonAlias("relationship-list") public void setRelationshipList(RelationshipList relationshipList) { this.relationshipList = relationshipList; } 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 index b2edfc17e..554449b96 100644 --- 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 @@ -1,85 +1,73 @@ 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 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 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>(); + private Map<String, Object> additionalProperties = new HashMap<>(); - @JsonProperty("id") public String getId() { return id; } @JsonProperty("id") - public void setId(String id) { + public void setJsonId(String id) { this.id = id; } - @JsonProperty("node-type") public String getNodeType() { return nodeType; } @JsonProperty("node-type") - public void setNodeType(String nodeType) { + public void setJsonNodeType(String nodeType) { this.nodeType = nodeType; } - @JsonProperty("url") public String getUrl() { return url; } @JsonProperty("url") - public void setUrl(String url) { + public void setJsonUrl(String url) { this.url = url; } - @JsonProperty("properties") public Properties getProperties() { return properties; } @JsonProperty("properties") - public void setProperties(Properties properties) { + public void setJsonProperties(Properties properties) { this.properties = properties; } - @JsonProperty("related-to") public List<RelatedTo> getRelatedTo() { return relatedTo; } @JsonProperty("related-to") - public void setRelatedTo(List<RelatedTo> relatedTo) { + public void setJsonRelatedTo(List<RelatedTo> relatedTo) { this.relatedTo = relatedTo; } - @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { return this.additionalProperties; } @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { + public void setJsonAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java index e4f22849d..b404a0251 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/VnfResult.java @@ -1,8 +1,6 @@ package org.onap.vid.aai.model; import com.fasterxml.jackson.annotation.*; -import org.codehaus.jackson.annotate.JsonProperty; -import org.onap.vid.RelatedTo; import java.util.HashMap; import java.util.List; @@ -18,10 +16,8 @@ import java.util.Map; "related-to" }) public class VnfResult { - @JsonProperty("id") public String id; - @com.fasterxml.jackson.annotation.JsonProperty("node-type") @JsonProperty("node-type") public String nodeType; @JsonProperty("url") @@ -29,10 +25,34 @@ public class VnfResult { @JsonProperty("properties") public ServiceProperties properties; @JsonProperty("related-to") - @com.fasterxml.jackson.annotation.JsonProperty("related-to") public List<RelatedTo> relatedTo = null; @JsonIgnore - private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + private Map<String, Object> additionalProperties = new HashMap<>(); + + @JsonProperty("id") + public void setJsonId(String id) { + this.id = id; + } + + @JsonProperty("node-type") + public void setJsonNodeType(String nodeType) { + this.nodeType = nodeType; + } + + @JsonProperty("url") + public void setJsonUrl(String url) { + this.url = url; + } + + @JsonProperty("properties") + public void setJsonProperties(ServiceProperties properties) { + this.properties = properties; + } + + @JsonProperty("related-to") + public void setJsonRelatedTo(List<RelatedTo> relatedTo) { + this.relatedTo = relatedTo; + } @JsonAnyGetter public Map<String, Object> getAdditionalProperties() { @@ -40,7 +60,7 @@ public class VnfResult { } @JsonAnySetter - public void setAdditionalProperty(String name, Object value) { + public void setJsonAdditionalProperty(String name, Object value) { this.additionalProperties.put(name, value); } } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/model/interfaces/AaiModelWithRelationships.java b/vid-app-common/src/main/java/org/onap/vid/aai/model/interfaces/AaiModelWithRelationships.java new file mode 100644 index 000000000..77fe4ceac --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/model/interfaces/AaiModelWithRelationships.java @@ -0,0 +1,7 @@ +package org.onap.vid.aai.model.interfaces; + +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.RelationshipList; + +public interface AaiModelWithRelationships { + RelationshipList getRelationshipList(); +} 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 f5625ce21..f4401ab3a 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 @@ -22,12 +22,14 @@ package org.onap.vid.aai.util; import com.att.eelf.configuration.EELFLogger; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.aai.ExceptionWithRequestInfo; import org.onap.vid.aai.ResponseWithRequestInfo; import org.onap.vid.aai.exceptions.InvalidPropertyException; import org.onap.vid.utils.Logging; +import org.onap.vid.utils.Unchecked; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; @@ -37,6 +39,7 @@ import javax.ws.rs.client.Invocation; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.UnsupportedEncodingException; +import java.net.URI; import java.net.URLEncoder; import java.util.Optional; import java.util.UUID; @@ -55,7 +58,6 @@ public class AAIRestInterface { protected final EELFLogger outgoingRequestsLogger = Logging.getRequestsLogger("aai"); - /** The client. */ private Client client = null; @@ -105,9 +107,9 @@ public class AAIRestInterface { return URLEncoder.encode(nodeKey, "UTF-8").replaceAll("\\+", "%20"); } - private void initRestClient() { - initRestClient(false); - } + protected void initRestClient() { + initRestClient(false); + } private void initRestClient(boolean propagateExceptions) { @@ -160,47 +162,61 @@ public class AAIRestInterface { * @param xml the xml * @return the string */ - public ResponseWithRequestInfo RestGet(String fromAppId, String transId, String requestUri, boolean xml) { + public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml) { return RestGet(fromAppId, transId, requestUri, xml, false); } - public ResponseWithRequestInfo RestGet(String fromAppId, String transId, String requestUri, boolean xml, boolean propagateExceptions) { - String methodName = "RestGet"; - String url = systemPropertyHelper.getFullServicePath(requestUri); + public ResponseWithRequestInfo RestGet(String fromAppId, String transId, URI requestUri, boolean xml, boolean propagateExceptions) { + return doRest(fromAppId, transId, requestUri, null, HttpMethod.GET, xml, propagateExceptions); + } + + public ResponseWithRequestInfo doRest(String fromAppId, String transId, URI requestUri, String payload, HttpMethod method, boolean xml, boolean propagateExceptions) { + String url = null; + String methodName = "Rest"+method.name(); try { + + url = systemPropertyHelper.getFullServicePath(requestUri); + initRestClient(propagateExceptions); logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING); logger.debug(EELFLoggerDelegate.debugLogger, url + " for the get REST API"); - Logging.logRequest(outgoingRequestsLogger, HttpMethod.GET, url); + Logging.logRequest(outgoingRequestsLogger, method, url, payload); final Response response; - Invocation.Builder requestBuilder = client.target(url) - .request() - .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) - .header(TRANSACTION_ID_HEADER, transId) - .header(FROM_APP_ID_HEADER, fromAppId) - .header("Content-Type", MediaType.APPLICATION_JSON) - .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId()); - response = systemPropertyHelper.isClientCertEnabled() ? - requestBuilder.get() : authenticateRequest(requestBuilder).get(); - Logging.logResponse(outgoingRequestsLogger, HttpMethod.GET, url, response); - - if (response.getStatusInfo().equals(Response.Status.OK)) { + Invocation.Builder requestBuilder = client.target(url) + .request() + .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) + .header(TRANSACTION_ID_HEADER, transId) + .header(FROM_APP_ID_HEADER, fromAppId) + .header("Content-Type", MediaType.APPLICATION_JSON) + .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId()); + + requestBuilder = systemPropertyHelper.isClientCertEnabled() ? + requestBuilder : authenticateRequest(requestBuilder); + + Invocation restInvocation = StringUtils.isEmpty(payload) ? + requestBuilder.build(method.name()) : + requestBuilder.build(method.name(), Entity.entity(payload, MediaType.APPLICATION_JSON)); + + response = restInvocation.invoke(); + Logging.logResponse(outgoingRequestsLogger, method, url, response); + + if (response.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) { logger.debug(EELFLoggerDelegate.debugLogger, methodName + SUCCESSFUL_API_MESSAGE); logger.info(EELFLoggerDelegate.errorLogger, methodName + SUCCESSFUL_API_MESSAGE); } else { logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response)); } - return new ResponseWithRequestInfo(response, url, HttpMethod.GET); + return new ResponseWithRequestInfo(response, url, method); } catch (Exception e) { logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e)); if (propagateExceptions) { - throw new ExceptionWithRequestInfo(HttpMethod.GET, defaultIfNull(url, requestUri), e); - } else { - return new ResponseWithRequestInfo(null, url, HttpMethod.GET); - } + throw new ExceptionWithRequestInfo(method, defaultIfNull(url, requestUri.toASCIIString()), e); + } else { + return new ResponseWithRequestInfo(null, url, method); + } } } @@ -222,7 +238,7 @@ public class AAIRestInterface { transId += ":" + UUID.randomUUID().toString(); logger.debug(methodName + START_STRING); Boolean response = false; - String url = systemPropertyHelper.getFullServicePath(path);; + String url = systemPropertyHelper.getFullServicePath(path); try { initRestClient(); @@ -263,37 +279,11 @@ public class AAIRestInterface { * @param path the path * @param payload the payload * @param xml the xml + * @param propagateExceptions * @return the string */ - public Response RestPut(String fromAppId, String path, String payload, boolean xml) { - String methodName = "RestPut"; - String url=systemPropertyHelper.getFullServicePath(path); - String transId = UUID.randomUUID().toString(); - logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING); - - Response response = null; - try { - initRestClient(); - Logging.logRequest(outgoingRequestsLogger, HttpMethod.PUT, url, payload); - response = authenticateRequest(client.target(url) - .request() - .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) - .header(TRANSACTION_ID_HEADER, transId) - .header(FROM_APP_ID_HEADER, fromAppId)) - .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId()) - .put(Entity.entity(payload, MediaType.APPLICATION_JSON)); - Logging.logResponse(outgoingRequestsLogger, HttpMethod.PUT, url, response); - - if (response.getStatusInfo().getFamily().equals(Response.Status.Family.SUCCESSFUL)) { - logger.info(EELFLoggerDelegate.errorLogger, getValidResponseLogMessage(methodName)); - logger.debug(EELFLoggerDelegate.debugLogger, getValidResponseLogMessage(methodName)); - } else { - logger.debug(EELFLoggerDelegate.debugLogger, getInvalidResponseLogMessage(url, methodName, response)); - } - } catch (Exception e) { - logger.debug(EELFLoggerDelegate.debugLogger, getFailedResponseLogMessage(url, methodName, e)); - } - return response; + public ResponseWithRequestInfo RestPut(String fromAppId, String path, String payload, boolean xml, boolean propagateExceptions) { + return doRest(fromAppId, UUID.randomUUID().toString(), Unchecked.toURI(path), payload, HttpMethod.PUT, xml, propagateExceptions); } @@ -313,13 +303,13 @@ public class AAIRestInterface { String transId = UUID.randomUUID().toString(); logger.debug(EELFLoggerDelegate.debugLogger, methodName + START_STRING); - Response response = null; + Response response = null; try { initRestClient(); Logging.logRequest(outgoingRequestsLogger, HttpMethod.POST, url, payload); - response = authenticateRequest(client.target(systemPropertyHelper.getServiceBasePath(path)) + response = authenticateRequest(client.target(url) .request() - .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) + .accept(xml ? MediaType.APPLICATION_XML : MediaType.APPLICATION_JSON) .header(TRANSACTION_ID_HEADER, transId) .header(FROM_APP_ID_HEADER, fromAppId)) .header(REQUEST_ID_HEADER_KEY, extractOrGenerateRequestId()) diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java new file mode 100644 index 000000000..8fa6f6c6d --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/AAITreeConverter.java @@ -0,0 +1,89 @@ +package org.onap.vid.aai.util; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vid.model.aaiTree.*; +import org.onap.vid.mso.model.ModelInfo; +import org.onap.vid.services.AAITreeNodeBuilder; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +import static java.util.function.Function.identity; +import static java.util.stream.Collectors.counting; +import static java.util.stream.Collectors.groupingBy; +import static org.onap.vid.asdc.parser.ToscaParserImpl2.Constants.A_LA_CARTE; + +@Component +public class AAITreeConverter { + + public static final String VNF_TYPE = "vnf-type"; + public static final String NETWORK_TYPE = "network-type"; + + public static final String IS_BASE_VF_MODULE = "is-base-vf-module"; + + public enum ModelType { + service, + vnf, + network, + instanceGroup, + vfModule + } + + public ServiceInstance convertTreeToUIModel(AAITreeNode rootNode, String globalCustomerId, String serviceType, String instantiationType) { + ServiceInstance serviceInstance = new ServiceInstance(); + serviceInstance.setInstanceId(rootNode.getId()); + serviceInstance.setInstanceName(rootNode.getName()); + serviceInstance.setOrchStatus(rootNode.getOrchestrationStatus()); + serviceInstance.setGlobalSubscriberId(globalCustomerId); + serviceInstance.setSubscriptionServiceType(serviceType); + serviceInstance.setIsALaCarte(StringUtils.equals(instantiationType, A_LA_CARTE)); + + serviceInstance.setModelInfo(createModelInfo(rootNode, ModelType.service)); + + //set children: vnf, network,group + rootNode.getChildren().forEach(child -> { + if (child.getType().equals(AAITreeNodeBuilder.GENERIC_VNF)) { + serviceInstance.getVnfs().put(child.getUniqueNodeKey(), Vnf.from(child)); + } else if (child.getType().equals(AAITreeNodeBuilder.NETWORK)) { + serviceInstance.getNetworks().put(child.getUniqueNodeKey(), Network.from(child)); + } else if (child.getType().equals(AAITreeNodeBuilder.INSTANCE_GROUP)) { + serviceInstance.getVnfGroups().put(child.getUniqueNodeKey(), VnfGroup.from(child)); + } + }); + + serviceInstance.setExistingVNFCounterMap( + serviceInstance.getVnfs().entrySet().stream() + .map(k -> k.getValue().getModelInfo().getModelVersionId()) + .collect(groupingBy(identity(), counting())) + ); + + serviceInstance.setExistingNetworksCounterMap( + serviceInstance.getNetworks().entrySet().stream() + .map(k -> k.getValue().getModelInfo().getModelVersionId()) + .filter(Objects::nonNull) + .collect(groupingBy(identity(), counting())) + ); + + + serviceInstance.setExistingVnfGroupCounterMap( + serviceInstance.getVnfGroups().entrySet().stream() + .map(k -> k.getValue().getModelInfo().getModelVersionId()) + .filter(Objects::nonNull) + .collect(groupingBy(identity(), counting())) + ); + + return serviceInstance; + } + + private static ModelInfo createModelInfo(AAITreeNode aaiNode, ModelType modelType) { + ModelInfo modelInfo = new ModelInfo(); + modelInfo.setModelType(modelType.name()); + modelInfo.setModelName(aaiNode.getModelName()); + modelInfo.setModelVersion(aaiNode.getModelVersion()); + modelInfo.setModelVersionId(aaiNode.getModelVersionId()); + modelInfo.setModelInvariantId(aaiNode.getModelInvariantId()); + modelInfo.setModelCustomizationId(aaiNode.getModelCustomizationId()); + + return modelInfo; + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheConfig.kt b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheConfig.kt new file mode 100644 index 000000000..0ff604144 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheConfig.kt @@ -0,0 +1,52 @@ +package org.onap.vid.aai.util + +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.kotlin.KotlinModule +import com.google.common.collect.ImmutableMap +import org.springframework.stereotype.Component + +//I use a regular kotlin class because I want that when jackson read +//a json with null values (or missing fields) they would get default values. +//for other cases it's better to use data class for POJO class +//for more information you can read here : +//https://github.com/FasterXML/jackson-module-kotlin/issues/130 +class CacheConfig constructor( + isActive: Boolean?, + expireAfterWriteHours: Long?, + refreshAfterWriteSeconds: Long?) { + val isActive: Boolean = isActive ?: true + val expireAfterWriteHours: Long = expireAfterWriteHours ?: 24L + val refreshAfterWriteSeconds: Long = refreshAfterWriteSeconds ?: 10L + + companion object { + val defaultCacheConfig = CacheConfig(null, null, null) + } + +} + + +interface CacheConfigProvider { + fun getCacheConfig(cacheName:String): CacheConfig +} + +@Component +class CacheConfigProviderImpl() : CacheConfigProvider { + private val mapper = ObjectMapper().apply { registerModule(KotlinModule()) } + + private fun readMapOfCacheConfig(): Map<String, CacheConfig> { + val configInputStream = CacheConfigProviderImpl::class.java.classLoader.getResourceAsStream("cacheConfig.json") + + return if (configInputStream == null) { + ImmutableMap.of() + } else { + mapper.readValue(configInputStream, object : TypeReference<Map<String, CacheConfig>>() {}) + } + } + + override fun getCacheConfig(cacheName: String): CacheConfig { + return readMapOfCacheConfig()[cacheName] ?: CacheConfig.defaultCacheConfig + } +} + + diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProvider.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProvider.java new file mode 100644 index 000000000..63615f492 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProvider.java @@ -0,0 +1,37 @@ +package org.onap.vid.aai.util; + +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; + +public interface CacheProvider { + String KEY_DELIMITER = "!@#'"; + /* + Returns the cache associated with given name; creates one if wasn't any + */ + <K, V> Cache<K, V> aaiClientCacheFor(String name, Function<K, V> loader); + + /* + reset cache if exist. Otherwise do nothing + */ + void resetCache(String name); + + interface Cache<K, V> { + V get(K key); + } + + static String compileKey(List<String> args) { + return compileKey(args.toArray(new String[0])); + } + + static String compileKey(String... args) { + return Stream.of(args).map(arg->defaultIfNull(arg, "")).collect( Collectors.joining( KEY_DELIMITER ) ); + } + + static String[] decompileKey(String key) { + return key.split(KEY_DELIMITER); + } +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProviderWithLoadingCache.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProviderWithLoadingCache.java new file mode 100644 index 000000000..26a3ebf25 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/CacheProviderWithLoadingCache.java @@ -0,0 +1,100 @@ +package org.onap.vid.aai.util; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import com.google.common.util.concurrent.UncheckedExecutionException; +import org.apache.commons.lang3.exception.ExceptionUtils; +import org.jetbrains.annotations.NotNull; +import org.onap.vid.properties.Features; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.togglz.core.manager.FeatureManager; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.function.Function; + +import static org.apache.commons.lang3.ObjectUtils.defaultIfNull; + +@Component +public class CacheProviderWithLoadingCache implements CacheProvider { + + private final ExecutorService cacheReloadPool; + private final FeatureManager featureManager; + private final CacheConfigProvider cacheConfigProvider; + private final ConcurrentHashMap<String, Cache> caches; + + + @Autowired + public CacheProviderWithLoadingCache(FeatureManager featureManager, CacheConfigProvider cacheConfigProvider) { + this.featureManager = featureManager; + this.cacheConfigProvider = cacheConfigProvider; + this.cacheReloadPool = Executors.newFixedThreadPool(3); + this.caches = new ConcurrentHashMap<>(); + } + + /* + Returns the cache associated with given name; creates one if wasn't any + */ + @Override + public <K, V> Cache<K, V> aaiClientCacheFor(String name, Function<K, V> loader) { + return (Cache<K, V>) caches.computeIfAbsent(name, s -> buildAaiClientCacheFrom(loader, name)); + } + + @Override + public void resetCache(String name) { + caches.remove(name); + } + + /* + Creates and returns a Cache that use provided `loader` to fetch values for + search keys, and stores the result for reuse over a certain time. + The cache will not use any stored key if FLAG_1810_AAI_LOCAL_CACHE is turned off. + In that case, `loader` will be invoked for any `get()` request from the cache. The + cache adheres the flag in real-time; so no restart is required. + */ + protected <K, V> Cache<K, V> buildAaiClientCacheFrom(Function<K, V> loader, String name) { + final LoadingCache<K, V> activeCache = buildAaiClientActiveCacheFrom(loader, name); + + // this works because Cache interface has only a single method: "get()" + // can be replaced with new anonimous class; e.g.: + // return new Cache() { ... } + return key -> { + if (featureManager.isActive(Features.FLAG_1810_AAI_LOCAL_CACHE) && + defaultIfNull(cacheConfigProvider.getCacheConfig(name).isActive(), true)) { + try { + return activeCache.getUnchecked(key); + } + catch (UncheckedExecutionException exception) { + return ExceptionUtils.rethrow(exception.getCause()); + } + } else { + activeCache.invalidateAll(); + activeCache.cleanUp(); + return loader.apply(key); + } + }; + } + + private <K, V> LoadingCache<K, V> buildAaiClientActiveCacheFrom(Function<K, V> loader, String name) { + return createCacheBuilder(name).build(createAsyncReloadingCacheLoaderFrom(loader)); + + } + + @NotNull + protected CacheBuilder<Object, Object> createCacheBuilder(String name) { + CacheConfig cacheConfig = cacheConfigProvider.getCacheConfig(name); + return CacheBuilder.newBuilder() + .maximumSize(1000) + .expireAfterWrite(cacheConfig.getExpireAfterWriteHours(), TimeUnit.HOURS) + .refreshAfterWrite(cacheConfig.getRefreshAfterWriteSeconds(), TimeUnit.SECONDS); + } + + private <K, V> CacheLoader<K, V> createAsyncReloadingCacheLoaderFrom(Function<K, V> loader) { + return CacheLoader.asyncReloading(CacheLoader.from(loader::apply), cacheReloadPool); + } + +} 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 15f81439b..489d2f1b6 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 @@ -22,11 +22,16 @@ package org.onap.vid.aai.util; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.HttpUrlConnectorProvider; import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.aai.exceptions.HttpClientBuilderException; +import org.onap.vid.properties.Features; +import org.togglz.core.manager.FeatureManager; +import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @@ -47,16 +52,19 @@ public class HttpsAuthClient { private final SystemPropertyHelper systemPropertyHelper; private final SSLContextProvider sslContextProvider; - public HttpsAuthClient(String certFilePath, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider) { + public HttpsAuthClient(String certFilePath, SystemPropertyHelper systemPropertyHelper, SSLContextProvider sslContextProvider, FeatureManager featureManager) { this.certFilePath = certFilePath; this.systemPropertyHelper = systemPropertyHelper; this.sslContextProvider = sslContextProvider; + this.featureManager = featureManager; } private final String certFilePath; + FeatureManager featureManager; + /** The logger. */ - static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(HttpsAuthClient.class); + static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(org.onap.vid.aai.util.HttpsAuthClient.class); /** @@ -70,7 +78,7 @@ public class HttpsAuthClient { try { setSystemProperties(); - ignoreHostname(); + optionallyVerifyHostname(); return systemPropertyHelper.isClientCertEnabled() ? getTrustedClient(config, getKeystorePath(), systemPropertyHelper.getDecryptedKeystorePassword(), mode) @@ -83,8 +91,8 @@ public class HttpsAuthClient { } - private void ignoreHostname() { - HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true); + private void optionallyVerifyHostname() { + HttpsURLConnection.setDefaultHostnameVerifier(getHostnameVerifier()); } private Client getUntrustedClient(ClientConfig config) { @@ -94,12 +102,20 @@ public class HttpsAuthClient { private Client getTrustedClient(ClientConfig config, String keystorePath, String keystorePassword, HttpClientMode httpClientMode) throws HttpClientBuilderException { return ClientBuilder.newBuilder() .sslContext(sslContextProvider.getSslContext(keystorePath, keystorePassword, httpClientMode)) - .hostnameVerifier((s, sslSession) -> true) + .hostnameVerifier(getHostnameVerifier()) .withConfig(config) .build() .register(CustomJacksonJaxBJsonProvider.class); } + protected HostnameVerifier getHostnameVerifier() { + if(featureManager.isActive(Features.FLAG_EXP_USE_DEFAULT_HOST_NAME_VERIFIER)){ + return new DefaultHostnameVerifier(); + } + + return new NoopHostnameVerifier(); + } + private String getKeystorePath() { return getCertificatesPath() + FileSystems.getDefault().getSeparator() + systemPropertyHelper.getAAIKeystoreFilename(); } 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 deleted file mode 100644 index d1f1cfc86..000000000 --- a/vid-app-common/src/main/java/org/onap/vid/aai/util/HttpsComponentsClient.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.vid.aai.util; - -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.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. - * - * @param certFilePath the cert file path - * @return the client - * @throws KeyManagementException the key management 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); - String keystore_path = certFilePath + AAIProperties.FILESEPARTOR + SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_FILENAME); - String keystore_password = SystemProperties.getProperty(AAIProperties.AAI_KEYSTORE_PASSWD_X); - String decrypted_keystore_password = Password.deobfuscate(keystore_password); - - SSLContextBuilder sslContextB = new SSLContextBuilder(); - - KeyStore ks = KeyStore.getInstance("PKCS12"); - char[] pwd = decrypted_keystore_password.toCharArray(); - - 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"); - char[] pwd1 = decrypted_truststore_password.toCharArray(); - - 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(); - - SSLContext sslcontext = sslContextB.build(); - - SSLConnectionSocketFactory sslFactory = new SSLConnectionSocketFactory( - sslcontext, - new String[] { "TLSv1.1", "TLSv1.2" }, - null, - SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER ); - - httpclient = HttpClients.custom() - .setSSLSocketFactory(sslFactory) - .build(); - - - } 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 cfc56d187..b39c20315 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 @@ -48,8 +48,8 @@ public class JettyObfuscationConversionCommandLineUtil { System.out.println(encoded); } else if (cmd.hasOption("d")) { toProcess = cmd.getOptionValue("d"); - String decoded_str = Password.deobfuscate(toProcess); - System.out.println(decoded_str); + String decodedStr = Password.deobfuscate(toProcess); + System.out.println(decodedStr); } else { usage(); } diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/ServiceInstanceStandardQuery.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/ServiceInstanceStandardQuery.java new file mode 100644 index 000000000..22743bbf9 --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/ServiceInstanceStandardQuery.java @@ -0,0 +1,93 @@ +package org.onap.vid.aai.util; + +import com.google.common.collect.ImmutableMap; +import org.apache.commons.text.StrSubstitutor; +import org.onap.vid.aai.AaiClientInterface; +import org.onap.vid.aai.model.AaiGetNetworkCollectionDetails.*; +import org.onap.vid.aai.model.interfaces.AaiModelWithRelationships; +import org.onap.vid.utils.Multival; +import org.onap.vid.utils.Unchecked; + +import javax.inject.Inject; +import java.net.URI; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.toSet; + +public class ServiceInstanceStandardQuery { + + private static final String SERVICE_INSTANCE_URI_TEMPLATE = "" + + "business/customers/customer/${global-customer-id}" + + "/service-subscriptions/service-subscription/${service-type}" + + "/service-instances/service-instance/${service-instance-id}"; + + private final AaiClientInterface aaiClient; + + @Inject + public ServiceInstanceStandardQuery(AaiClientInterface aaiClient) { + this.aaiClient = aaiClient; + } + + public ServiceInstance fetchServiceInstance(String globalCustomerId, String serviceType, String serviceInstanceId) { + final String serviceInstanceUri = getServiceInstanceUri(globalCustomerId, serviceType, serviceInstanceId); + + return fetchServiceInstance(Unchecked.toURI(serviceInstanceUri)); + } + + ServiceInstance fetchServiceInstance(URI serviceInstanceUri) { + return objectByUri(ServiceInstance.class, serviceInstanceUri); + } + + protected <T> T objectByUri(Class<T> clazz, URI aaiResourceUri) { + return aaiClient.typedAaiGet(aaiResourceUri, clazz); + } + + public Multival<ServiceInstance, Vnf> fetchRelatedVnfs(ServiceInstance serviceInstance) { + return fetchRelated("service", serviceInstance, "generic-vnf", Vnf.class); + } + + public <K extends AaiModelWithRelationships> Multival<K, Network> fetchRelatedL3Networks(String sourceType, K source) { + return fetchRelated(sourceType, source, "l3-network", Network.class); + } + + public Multival<Network, Vlan> fetchRelatedVlanTags(Network network) { + return fetchRelated("network", network, "vlan-tag", Vlan.class); + } + + private String getServiceInstanceUri(String globalCustomerId, String serviceType, String serviceInstanceId) { + return new StrSubstitutor(ImmutableMap.of( + "global-customer-id", globalCustomerId, + "service-type", serviceType, + "service-instance-id", serviceInstanceId + )).replace(SERVICE_INSTANCE_URI_TEMPLATE); + } + + private <K extends AaiModelWithRelationships, V> Multival<K, V> fetchRelated(String sourceType, K source, String destType, Class<V> destClass) { + return Multival.of( + sourceType, + source, + destType, + fetchRelatedInner(source, destType, destClass) + ); + } + + private <K extends AaiModelWithRelationships, V> Set<V> fetchRelatedInner(K source, String destType, Class<V> destClass) { + return getURIsOf(source, relationship -> relatedTo(relationship, destType)) + .map(destUri -> objectByUri(destClass, destUri)) + .collect(toSet()); + } + + protected Stream<URI> getURIsOf(AaiModelWithRelationships aaiModel, Predicate<Relationship> predicate) { + return aaiModel.getRelationshipList().getRelationship().stream() + .filter(predicate) + .map(r -> r.relatedLink) + .map(Unchecked::toURI); + } + + protected static boolean relatedTo(Relationship r, String relationshipName) { + return relationshipName.equals(r.getRelatedTo()); + } + +} diff --git a/vid-app-common/src/main/java/org/onap/vid/aai/util/SystemPropertyHelper.java b/vid-app-common/src/main/java/org/onap/vid/aai/util/SystemPropertyHelper.java index 4d43d3ba2..939bfe5b6 100644 --- a/vid-app-common/src/main/java/org/onap/vid/aai/util/SystemPropertyHelper.java +++ b/vid-app-common/src/main/java/org/onap/vid/aai/util/SystemPropertyHelper.java @@ -23,8 +23,10 @@ package org.onap.vid.aai.util; import org.eclipse.jetty.util.security.Password; import org.onap.portalsdk.core.util.SystemProperties; import org.onap.vid.aai.exceptions.InvalidPropertyException; +import org.onap.vid.utils.Unchecked; import java.io.UnsupportedEncodingException; +import java.net.URI; import java.util.Base64; import java.util.Optional; @@ -74,6 +76,15 @@ public class SystemPropertyHelper { return getAAIServerUrl().orElse("") + path; } + public String getFullServicePath(URI requestUri) { + // resolve() will merge two paths, handling the restiveness: + // Especially if requestUri starts with a '/' -- result will be + // AAI_SERVER_URL host, post, etc., and the path will be just + // requestUri. + return Unchecked.toURI(getAAIServerUrl().orElse("")) + .resolve(requestUri).toASCIIString(); + } + public String getServiceBasePath(String path) { return getAAIServerBaseUrl().orElse("") + path; } |