+ Response resp = doAaiGet("network/logical-links/logical-link/" + link , false);
+ return processAaiResponse(resp, LogicalLinkResponse.class, null);
+ }
+
+ @Override
+ public boolean isNodeTypeExistsByName(String name, ResourceType type) {
+ if (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(),
+ 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));
+ }
+
+ @Override
+ public AaiResponse<AaiGetVnfResponse> getVnfsByParamsForChangeManagement(String subscriberId, String serviceType, @Nullable String nfRole,
+ @Nullable String cloudRegion) {
+ String payloadAsString = "";
+ ResponseWithRequestInfo response;
+ ImmutableMap<String, Serializable> payload = getMapForAAIQueryByParams(subscriberId, serviceType,
+ nfRole, cloudRegion);
+ try {
+ payloadAsString = JACKSON_OBJECT_MAPPER.writeValueAsString(payload);
+ } catch (JsonProcessingException e) {
+ logger.error(e.getMessage());
+ ExceptionUtils.rethrow(e);
+ }
+ response = doAaiPut(QUERY_FORMAT_SIMPLE, payloadAsString, false, false);
+ AaiResponseWithRequestInfo<AaiGetVnfResponse> aaiResponse = processAaiResponse(response, AaiGetVnfResponse.class, false);
+ verifyAaiResponseValidityOrThrowExc(aaiResponse, aaiResponse.getAaiResponse().getHttpCode());
+ return aaiResponse.getAaiResponse();
+ }
+
+ private ImmutableMap<String, Serializable> getMapForAAIQueryByParams(String subscriberId,
+ String serviceType, @Nullable String nfRole, @Nullable String cloudRegion) {
+ // in a case cloudRegion is null using query/vnfs-fromServiceInstance-filter,
+ // otherwise using query/vnfs-fromServiceInstance-filterByCloudRegion
+ if (nfRole != null){
+ if (cloudRegion != null){
+ return ImmutableMap.of(
+ "start", ImmutableList
+ .of("/business/customers/customer/" + encodePathSegment(subscriberId) + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances"),
+ "query", "query/vnfs-fromServiceInstance-filterByCloudRegion?nfRole=" + nfRole + "&cloudRegionID=" + cloudRegion + ""
+ );
+ }else {
+ return ImmutableMap.of(
+ "start", ImmutableList
+ .of("/business/customers/customer/" + encodePathSegment(subscriberId) + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances"),
+ "query", "query/vnfs-fromServiceInstance-filter?nfRole=" + nfRole + ""
+ );
+ }
+ }
+
+ if (cloudRegion != null){
+ return ImmutableMap.of(
+ "start", ImmutableList
+ .of("/business/customers/customer/" + encodePathSegment(subscriberId) + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances"),
+ "query", "query/vnfs-fromServiceInstance-filterByCloudRegion?cloudRegionID=" + cloudRegion + ""
+ );
+ }
+
+ return ImmutableMap.of(
+ "start", ImmutableList
+ .of("/business/customers/customer/" + encodePathSegment(subscriberId) + "/service-subscriptions/service-subscription/" + encodePathSegment(serviceType) + "/service-instances"),
+ "query", "query/vnfs-fromServiceInstance-filter"
+ );
+ }
+
+ 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());
+ }
+ }
+
+ @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);
+ verifyAaiResponseValidityOrThrowExc(aaiResponse, responseWithRequestInfo.getResponse().getStatus());
+ return aaiResponse.getAaiResponse().getT();
+ }
+
+ private void verifyAaiResponseValidityOrThrowExc(AaiResponseWithRequestInfo aaiResponse, int httpCode) {
+ if (aaiResponse.getAaiResponse().getHttpCode() > 399 || aaiResponse.getAaiResponse().getT() == null) {
+ throw new ExceptionWithRequestInfo(aaiResponse.getHttpMethod(),
+ aaiResponse.getRequestedUrl(),
+ aaiResponse.getRawData(),
+ httpCode,
+ new InvalidAAIResponseException(aaiResponse.getAaiResponse()));
+ }