diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src')
17 files changed, 333 insertions, 136 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java index 451fa64585..e56eb422d8 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/CamundaRequestHandler.java @@ -115,7 +115,7 @@ public class CamundaRequestHandler { List<HistoricProcessInstanceEntity> historicProcessInstanceList = response.getBody(); - if (historicProcessInstanceList != null) { + if (historicProcessInstanceList != null && !historicProcessInstanceList.isEmpty()) { Collections.reverse(historicProcessInstanceList); processInstanceId = historicProcessInstanceList.get(0).getId(); } else { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java index 6f36fb2aff..a5ccb1b29b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/OrchestrationRequests.java @@ -42,6 +42,7 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.EnumUtils; import org.apache.http.HttpStatus; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandler.common.ResponseBuilder; @@ -411,7 +412,11 @@ public class OrchestrationRequests { protected String mapRequestStatusToRequest(InfraActiveRequests iar, String format) { if (iar.getRequestStatus() != null) { - if (!StringUtils.isBlank(format) && OrchestrationRequestFormat.DETAIL.toString().equalsIgnoreCase(format)) { + boolean requestFormat = false; + if (format != null) { + requestFormat = EnumUtils.isValidEnum(OrchestrationRequestFormat.class, format.toUpperCase()); + } + if (requestFormat) { return iar.getRequestStatus(); } else { if (Status.ABORTED.toString().equalsIgnoreCase(iar.getRequestStatus()) diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java index b6f3f82ab1..2fddfd9a95 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java @@ -479,24 +479,11 @@ public class RequestHandlerUtils extends AbstractRestHandler { boolean isAlaCarte, Actions action) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.setSerializationInclusion(Include.NON_NULL); - if (msoRawRequest != null) { - ServiceInstancesRequest sir = mapper.readValue(msoRawRequest, ServiceInstancesRequest.class); - if (serviceInstRequest != null && serviceInstRequest.getRequestDetails() != null - && serviceInstRequest.getRequestDetails().getRequestParameters() != null) { - if (!isAlaCarte && Action.createInstance.equals(action)) { - sir.getRequestDetails() - .setCloudConfiguration(serviceInstRequest.getRequestDetails().getCloudConfiguration()); - sir.getRequestDetails().getRequestParameters().setUserParams( - serviceInstRequest.getRequestDetails().getRequestParameters().getUserParams()); - } - sir.getRequestDetails().getRequestParameters() - .setUsePreload(serviceInstRequest.getRequestDetails().getRequestParameters().getUsePreload()); - } - - logger.debug("Value as string: {}", mapper.writeValueAsString(sir)); - return mapper.writeValueAsString(sir); + if (serviceInstRequest != null) { + return mapper.writeValueAsString(serviceInstRequest); + } else { + return msoRawRequest; } - return null; } public Optional<String> retrieveModelName(RequestParameters requestParams) { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index 5b827d9cf8..b1d38983ec 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -51,6 +51,7 @@ import org.onap.so.apihandlerinfra.exceptions.RecipeNotFoundException; import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException; import org.onap.so.apihandlerinfra.exceptions.ValidateException; import org.onap.so.apihandlerinfra.infra.rest.handler.AbstractRestHandler; +import org.onap.so.apihandlerinfra.infra.rest.validators.RequestValidatorListenerRunner; import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; import org.onap.so.constants.Status; import org.onap.so.db.catalog.beans.NetworkResource; @@ -124,6 +125,9 @@ public class ServiceInstances extends AbstractRestHandler { @Autowired private RequestHandlerUtils requestHandlerUtils; + @Autowired + private RequestValidatorListenerRunner requestValidatorListenerRunner; + @POST @Path("/{version:[vV][5-7]}/serviceInstances") @Consumes(MediaType.APPLICATION_JSON) @@ -764,6 +768,13 @@ public class ServiceInstances extends AbstractRestHandler { public Response serviceInstances(String requestJSON, Actions action, HashMap<String, String> instanceIdMap, String version, String requestId, String requestUri) throws ApiException { + return serviceInstances(requestJSON, action, instanceIdMap, version, requestId, requestUri, null); + + } + + public Response serviceInstances(String requestJSON, Actions action, HashMap<String, String> instanceIdMap, + String version, String requestId, String requestUri, HashMap<String, String> queryParams) + throws ApiException { String serviceInstanceId; Boolean aLaCarte = null; ServiceInstancesRequest sir; @@ -771,6 +782,8 @@ public class ServiceInstances extends AbstractRestHandler { sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri); action = handleReplaceInstance(action, sir); + requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams); + String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri); InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java new file mode 100644 index 0000000000..344e5438c9 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrieval.java @@ -0,0 +1,85 @@ +package org.onap.so.apihandlerinfra.infra.rest; + +import java.util.Optional; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.L3Network; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.aai.domain.yang.VfModule; +import org.onap.aai.domain.yang.VolumeGroup; +import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.AAIResultWrapper; +import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class AAIDataRetrieval { + + private static final String VF_MODULE_NOT_FOUND_IN_INVENTORY_VNF_ID = "VF Module Not Found In Inventory, VnfId: "; + + private AAIResourcesClient aaiResourcesClient; + + private static final Logger logger = LoggerFactory.getLogger(AAIDataRetrieval.class); + + public ServiceInstance getServiceInstance(String serviceInstanceId) { + return this.getAaiResourcesClient() + .get(ServiceInstance.class, + AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)) + .orElseGet(() -> { + logger.debug("No Service Instance found in A&AI ServiceInstanceId: {}", serviceInstanceId); + return null; + }); + } + + + public VfModule getAAIVfModule(String vnfId, String vfModuleId) { + return this.getAaiResourcesClient() + .get(VfModule.class, AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId)) + .orElseGet(() -> { + logger.debug("No Vf Module found in A&AI VnfId: {}" + ", VfModuleId: {}", vnfId, vfModuleId); + return null; + }); + } + + public GenericVnf getGenericVnf(String vnfId) { + return this.getAaiResourcesClient() + .get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)) + .orElseGet(() -> { + logger.debug("No Generic VNF found in A&AI VnfId: {}", vnfId); + return null; + }); + } + + public VolumeGroup getVolumeGroup(String vnfId, String volumeGroupId) throws AAIEntityNotFound { + AAIResultWrapper wrapper = + this.getAaiResourcesClient().get(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId) + .relatedTo(AAIObjectType.VOLUME_GROUP, volumeGroupId)); + Optional<VolumeGroup> volume = wrapper.asBean(VolumeGroup.class); + if (volume.isPresent()) { + return volume.get(); + } else { + logger.debug("No VolumeGroup in A&AI found: {}", vnfId); + return null; + } + } + + public L3Network getNetwork(String networkId) { + return this.getAaiResourcesClient() + .get(L3Network.class, AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId)) + .orElseGet(() -> { + logger.debug("No Network found in A&AI NetworkId: {}", networkId); + return null; + }); + } + + protected AAIResourcesClient getAaiResourcesClient() { + if (aaiResourcesClient == null) { + aaiResourcesClient = new AAIResourcesClient(); + } + return aaiResourcesClient; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilder.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilder.java index bb5b4edfe4..ee2bb586cf 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilder.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilder.java @@ -33,10 +33,7 @@ import org.onap.logging.ref.slf4j.ONAPLogConstants; import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound; import org.onap.so.apihandlerinfra.infra.rest.exception.CloudConfigurationNotFoundException; import org.onap.so.client.aai.AAIObjectType; -import org.onap.so.client.aai.AAIResourcesClient; import org.onap.so.client.aai.entities.AAIResultWrapper; -import org.onap.so.client.aai.entities.uri.AAIResourceUri; -import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.constants.Status; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.client.RequestsDbClient; @@ -75,17 +72,19 @@ public class BpmnRequestBuilder { @Autowired private RequestsDbClient infraActiveRequestsClient; + @Autowired + private AAIDataRetrieval aaiDataRet; + private ObjectMapper mapper = new ObjectMapper(); - private AAIResourcesClient aaiResourcesClient; public ServiceInstancesRequest buildVFModuleDeleteRequest(String vnfId, String vfModuleId, ModelType modelType) throws AAIEntityNotFound { - GenericVnf vnf = getGenericVnf(vnfId); + GenericVnf vnf = aaiDataRet.getGenericVnf(vnfId); if (vnf == null) { throw new AAIEntityNotFound(GENERIC_VNF_NOT_FOUND_IN_INVENTORY_VNF_ID + vnfId); } - VfModule vfModule = getAAIVfModule(vnfId, vfModuleId); + VfModule vfModule = aaiDataRet.getAAIVfModule(vnfId, vfModuleId); if (vfModule == null) { throw new AAIEntityNotFound(VF_MODULE_NOT_FOUND_IN_INVENTORY_VNF_ID + vnfId + " vfModuleId: " + vfModuleId); } @@ -94,11 +93,11 @@ public class BpmnRequestBuilder { public ServiceInstancesRequest buildVolumeGroupDeleteRequest(String vnfId, String volumeGroupId) throws AAIEntityNotFound { - GenericVnf vnf = getGenericVnf(vnfId); + GenericVnf vnf = aaiDataRet.getGenericVnf(vnfId); if (vnf == null) { throw new AAIEntityNotFound(GENERIC_VNF_NOT_FOUND_IN_INVENTORY_VNF_ID + vnfId); } - VolumeGroup volumeGroup = getVolumeGroup(vnfId, volumeGroupId); + VolumeGroup volumeGroup = aaiDataRet.getVolumeGroup(vnfId, volumeGroupId); if (volumeGroup == null) { throw new AAIEntityNotFound( VF_MODULE_NOT_FOUND_IN_INVENTORY_VNF_ID + vnfId + " volumeGroupId: " + volumeGroupId); @@ -107,7 +106,7 @@ public class BpmnRequestBuilder { } public ServiceInstancesRequest buildServiceDeleteRequest(String serviceInstanceId) throws AAIEntityNotFound { - ServiceInstance serviceInstance = getServiceInstance(serviceInstanceId); + ServiceInstance serviceInstance = aaiDataRet.getServiceInstance(serviceInstanceId); if (serviceInstance == null) { throw new AAIEntityNotFound( "ServiceInstance Not Found In Inventory, ServiceInstanceId: " + serviceInstanceId); @@ -116,7 +115,7 @@ public class BpmnRequestBuilder { } public ServiceInstancesRequest buildVnfDeleteRequest(String vnfId) throws AAIEntityNotFound { - GenericVnf vnf = getGenericVnf(vnfId); + GenericVnf vnf = aaiDataRet.getGenericVnf(vnfId); if (vnf == null) { throw new AAIEntityNotFound(GENERIC_VNF_NOT_FOUND_IN_INVENTORY_VNF_ID + vnfId); } @@ -124,7 +123,7 @@ public class BpmnRequestBuilder { } public ServiceInstancesRequest buildNetworkDeleteRequest(String networkId) throws AAIEntityNotFound { - L3Network network = getNetwork(networkId); + L3Network network = aaiDataRet.getNetwork(networkId); if (network == null) { throw new AAIEntityNotFound("Network Not Found In Inventory, NetworkId: " + networkId); } @@ -407,72 +406,5 @@ public class BpmnRequestBuilder { return requestParams; } - public VfModule getAAIVfModule(String vnfId, String vfModuleId) { - return this.getAaiResourcesClient() - .get(VfModule.class, AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId)) - .orElseGet(() -> { - logger.debug("No Vf Module found in A&AI VnfId: {}" + ", VfModuleId: {}", vnfId, vfModuleId); - return null; - }); - } - - public GenericVnf getGenericVnf(String vnfId) { - return this.getAaiResourcesClient() - .get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)) - .orElseGet(() -> { - logger.debug("No Generic VNF found in A&AI VnfId: {}", vnfId); - return null; - }); - } - - public VolumeGroup getVolumeGroup(String vnfId, String volumeGroupId) throws AAIEntityNotFound { - GenericVnf vnf = getGenericVnf(vnfId); - AAIResultWrapper wrapper = new AAIResultWrapper(vnf); - List<AAIResourceUri> listVserverWrapper; - Optional<AAIResourceUri> volumeGroupURI; - if (wrapper.getRelationships().isPresent()) { - listVserverWrapper = wrapper.getRelationships().get().getRelatedUris(AAIObjectType.VOLUME_GROUP); - volumeGroupURI = listVserverWrapper.stream() - .filter(resourceURI -> resourceURI.getURIKeys().get("volume-group-id").equals(volumeGroupId)) - .findFirst(); - } else { - throw new AAIEntityNotFound( - VF_MODULE_NOT_FOUND_IN_INVENTORY_VNF_ID + vnfId + " volumeGroupId: " + volumeGroupId); - } - return this.getAaiResourcesClient().get(VolumeGroup.class, volumeGroupURI.get()).orElseGet(() -> { - logger.debug("No VolumeGroup in A&AI found: {}", vnfId); - return null; - }); - } - - public ServiceInstance getServiceInstance(String serviceInstanceId) { - return this.getAaiResourcesClient() - .get(ServiceInstance.class, - AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)) - .orElseGet(() -> { - logger.debug("No Service Instance found in A&AI ServiceInstanceId: {}", serviceInstanceId); - return null; - }); - } - - public L3Network getNetwork(String networkId) { - return this.getAaiResourcesClient() - .get(L3Network.class, AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId)) - .orElseGet(() -> { - logger.debug("No Network found in A&AI NetworkId: {}", networkId); - return null; - }); - } - - public AAIResourcesClient getAaiResourcesClient() { - if (aaiResourcesClient == null) { - aaiResourcesClient = new AAIResourcesClient(); - } - return aaiResourcesClient; - } - - public void setAaiResourcesClient(AAIResourcesClient aaiResourcesClient) { - this.aaiResourcesClient = aaiResourcesClient; - } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java new file mode 100644 index 0000000000..4aa60152dd --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidator.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.so.apihandlerinfra.infra.rest.validators; + +import java.util.Map; +import java.util.Optional; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; + +public interface RequestValidator { + + + /** + * Should this validator run for given request + * + * @return + */ + public boolean shouldRunFor(String uri, ServiceInstancesRequest request); + + + public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request, + Map<String, String> queryParams); +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java new file mode 100644 index 0000000000..d689c6b7a5 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/RequestValidatorListenerRunner.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2019 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.so.apihandlerinfra.infra.rest.validators; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; +import javax.annotation.PostConstruct; +import org.javatuples.Pair; +import org.onap.so.apihandlerinfra.exceptions.ApiException; +import org.onap.so.apihandlerinfra.exceptions.ValidateException; +import org.onap.so.listener.ListenerRunner; +import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class RequestValidatorListenerRunner extends ListenerRunner { + + private static Logger logger = LoggerFactory.getLogger(RequestValidatorListenerRunner.class); + + protected List<RequestValidator> requestValidators; + + @PostConstruct + protected void init() { + requestValidators = new ArrayList<>( + Optional.ofNullable(context.getBeansOfType(RequestValidator.class)).orElse(new HashMap<>()).values()); + } + + public boolean runValidations(String requestURI, Map<String, String> instanceIdMap, ServiceInstancesRequest request, + Map<String, String> queryParams) throws ApiException { + logger.info("Running local validations"); + List<Pair<String, Optional<String>>> results = + runValidations(requestValidators, instanceIdMap, request, queryParams, requestURI); + if (!results.isEmpty()) { + throw new ValidateException("Failed Validations:\n" + + results.stream().map(item -> String.format("%s: %s", item.getValue0(), item.getValue1().get())) + .collect(Collectors.joining("\n")), + 400); + } + + return true; + } + + protected List<Pair<String, Optional<String>>> runValidations(List<? extends RequestValidator> validators, + Map<String, String> instanceIdMap, ServiceInstancesRequest request, Map<String, String> queryParams, + String requestURI) { + + List<? extends RequestValidator> filtered = + filterListeners(validators, (item -> item.shouldRunFor(requestURI, request))); + + List<Pair<String, Optional<String>>> results = new ArrayList<>(); + filtered.forEach(item -> results + .add(new Pair<>(item.getClass().getName(), item.validate(instanceIdMap, request, queryParams)))); + + return results.stream().filter(item -> item.getValue1().isPresent()).collect(Collectors.toList()); + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/PlatformLOBValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/PlatformLOBValidation.java index 71405b0f63..20be2b5a8b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/PlatformLOBValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/PlatformLOBValidation.java @@ -43,7 +43,8 @@ public class PlatformLOBValidation implements ValidationRule { platform = info.getSir().getRequestDetails().getPlatform(); lineOfBusiness = info.getSir().getRequestDetails().getLineOfBusiness(); - if (reqVersion >= 5 && requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.createInstance) { + if (reqVersion >= 5 && requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.createInstance + && !info.getReqParameters().getEnforceValidNfValues()) { if (reqVersion > 5 && platform == null) { throw new ValidationException("platform"); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ProjectOwningEntityValidation.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ProjectOwningEntityValidation.java index 584269715a..cebbd6389c 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ProjectOwningEntityValidation.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/validation/ProjectOwningEntityValidation.java @@ -41,10 +41,12 @@ public class ProjectOwningEntityValidation implements ValidationRule { String requestScope = info.getRequestScope(); Actions action = info.getAction(); + project = info.getSir().getRequestDetails().getProject(); owningEntity = info.getSir().getRequestDetails().getOwningEntity(); if (reqVersion >= 5 && requestScope.equalsIgnoreCase(ModelType.service.name()) - && action == Action.createInstance || action == Action.assignInstance) { + && !info.getReqParameters().getEnforceValidNfValues() && action == Action.createInstance + || action == Action.assignInstance) { if (reqVersion > 5 && owningEntity == null) { throw new ValidationException("owningEntity"); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/CamundaRequestHandlerTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/CamundaRequestHandlerTest.java index e6b5163f59..830f38f98b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/CamundaRequestHandlerTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/CamundaRequestHandlerTest.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import org.camunda.bpm.engine.impl.persistence.entity.HistoricActivityInstanceEntity; import org.camunda.bpm.engine.impl.persistence.entity.HistoricProcessInstanceEntity; @@ -119,7 +120,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getActivityNameTest() throws IOException { + public void getActivityNameTest() { String expectedActivityName = "Last task executed: BB to Execute"; String actualActivityName = camundaRequestHandler.getActivityName(activityInstanceList); @@ -127,7 +128,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getActivityNameNullActivityNameTest() throws IOException { + public void getActivityNameNullActivityNameTest() { String expectedActivityName = "Task name is null."; HistoricActivityInstanceEntity activityInstance = new HistoricActivityInstanceEntity(); List<HistoricActivityInstanceEntity> activityInstanceList = new ArrayList<>(); @@ -139,7 +140,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getActivityNameNullListTest() throws IOException { + public void getActivityNameNullListTest() { String expectedActivityName = "No results returned on activityInstance history lookup."; List<HistoricActivityInstanceEntity> activityInstanceList = null; String actualActivityName = camundaRequestHandler.getActivityName(activityInstanceList); @@ -148,7 +149,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getActivityNameEmptyListTest() throws IOException { + public void getActivityNameEmptyListTest() { String expectedActivityName = "No results returned on activityInstance history lookup."; List<HistoricActivityInstanceEntity> activityInstanceList = new ArrayList<>(); String actualActivityName = camundaRequestHandler.getActivityName(activityInstanceList); @@ -157,7 +158,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getTaskNameTest() throws IOException, ContactCamundaException { + public void getTaskNameTest() throws ContactCamundaException { doReturn(processInstanceResponse).when(camundaRequestHandler).getCamundaProcessInstanceHistory(REQUEST_ID); doReturn(activityInstanceResponse).when(camundaRequestHandler) .getCamundaActivityHistory("c4c6b647-a26e-11e9-b144-0242ac14000b", REQUEST_ID); @@ -170,7 +171,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getTaskNameNullProcessInstanceListTest() throws IOException, ContactCamundaException { + public void getTaskNameNullProcessInstanceListTest() throws ContactCamundaException { ResponseEntity<List<HistoricProcessInstanceEntity>> response = new ResponseEntity<>(null, HttpStatus.OK); doReturn(response).when(camundaRequestHandler).getCamundaProcessInstanceHistory(REQUEST_ID); String expected = "No processInstances returned for requestId: " + REQUEST_ID; @@ -181,7 +182,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getTaskNameNullProcessInstanceIdTest() throws IOException, ContactCamundaException { + public void getTaskNameNullProcessInstanceIdTest() throws ContactCamundaException { HistoricProcessInstanceEntity processInstance = new HistoricProcessInstanceEntity(); List<HistoricProcessInstanceEntity> processInstanceList = new ArrayList<>(); processInstanceList.add(processInstance); @@ -196,7 +197,19 @@ public class CamundaRequestHandlerTest { } @Test - public void getTaskNameProcessInstanceLookupFailureTest() throws IOException, ContactCamundaException { + public void getTaskNameEmptyProcessInstanceListTest() throws ContactCamundaException { + ResponseEntity<List<HistoricProcessInstanceEntity>> response = + new ResponseEntity<>(Collections.emptyList(), HttpStatus.OK); + doReturn(response).when(camundaRequestHandler).getCamundaProcessInstanceHistory(REQUEST_ID); + String expected = "No processInstances returned for requestId: " + REQUEST_ID; + + String actual = camundaRequestHandler.getTaskName(REQUEST_ID); + + assertEquals(expected, actual); + } + + @Test + public void getTaskNameProcessInstanceLookupFailureTest() throws ContactCamundaException { doThrow(HttpClientErrorException.class).when(camundaRequestHandler) .getCamundaProcessInstanceHistory(REQUEST_ID); @@ -205,7 +218,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getCamundaActivityHistoryTest() throws IOException, ContactCamundaException { + public void getCamundaActivityHistoryTest() throws ContactCamundaException { HttpHeaders headers = setHeaders(); HttpEntity<?> requestEntity = new HttpEntity<>(headers); String targetUrl = "http://localhost:8089/sobpmnengine/history/activity-instance?processInstanceId=" @@ -239,7 +252,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getCamundaProccesInstanceHistoryTest() throws IOException, ContactCamundaException { + public void getCamundaProccesInstanceHistoryTest() { HttpHeaders headers = setHeaders(); HttpEntity<?> requestEntity = new HttpEntity<>(headers); String targetUrl = @@ -292,7 +305,7 @@ public class CamundaRequestHandlerTest { } @Test - public void getCamundaProccesInstanceHistoryFailThenSuccessTest() throws IOException, ContactCamundaException { + public void getCamundaProccesInstanceHistoryFailThenSuccessTest() { HttpHeaders headers = setHeaders(); HttpEntity<?> requestEntity = new HttpEntity<>(headers); String targetUrl = @@ -310,7 +323,7 @@ public class CamundaRequestHandlerTest { } @Test - public void setCamundaHeadersTest() throws ContactCamundaException, RequestDbFailureException { + public void setCamundaHeadersTest() { String encryptedAuth = "015E7ACF706C6BBF85F2079378BDD2896E226E09D13DC2784BA309E27D59AB9FAD3A5E039DF0BB8408"; // user:password String key = "07a7159d3bf51a0e53be7a8f89699be7"; diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java index 5023155768..f672648a6b 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/OrchestrationRequestsUnitTest.java @@ -295,6 +295,14 @@ public class OrchestrationRequestsUnitTest { assertEquals(Status.ABORTED.toString(), result); } + @Test + public void mapRequestStatusToRequestForFormatStatusDetailTest() throws ApiException { + iar.setRequestStatus(Status.ABORTED.toString()); + String result = orchestrationRequests.mapRequestStatusToRequest(iar, "statusDetail"); + + assertEquals(Status.ABORTED.toString(), result); + } + @Test public void mapRequestStatusToRequestForFormatEmptyStringTest() throws ApiException { diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index e28e36d307..a79aeb2bd7 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -2934,15 +2934,5 @@ public class ServiceInstancesTest extends BaseTest { Actions action = servInstances.handleReplaceInstance(Action.replaceInstance, sir); assertEquals(Action.replaceInstanceRetainAssignments, action); } - /* - * @Test public void buildSelfLinkUrlTest() throws Exception { // v - version String incomingUrl = - * "http://localhost:8080/onap/infra/so/serviceInstantiation/v7/serviceInstances"; String expectedSelfLink = - * "http://localhost:8080/orchestrationRequests/v7/efce3167-5e45-4666-9d4d-22e23648e5d1"; String requestId = - * "efce3167-5e45-4666-9d4d-22e23648e5d1"; Optional<URL> actualSelfLinkUrl = buildSelfLinkUrl(incomingUrl, - * requestId); assertEquals(expectedSelfLink, actualSelfLinkUrl.get().toString()); // V - Version String - * incomingUrlV = "http://localhost:8080/onap/infra/so/serviceInstantiation/V7/serviceInstances"; String - * expectedSelfLinkV = "http://localhost:8080/orchestrationRequests/V7/efce3167-5e45-4666-9d4d-22e23648e5d1"; - * Optional<URL> actualSelfLinkUrlV = buildSelfLinkUrl(incomingUrlV, requestId); assertEquals(expectedSelfLinkV, - * actualSelfLinkUrlV.get().toString()); } - */ } + diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilderTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilderTest.java index 3644dd8e7f..f73da49e0d 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilderTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/BpmnRequestBuilderTest.java @@ -23,6 +23,7 @@ package org.onap.so.apihandlerinfra.infra.rest; import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; import java.io.File; import java.util.Optional; import org.junit.Before; @@ -32,7 +33,6 @@ import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ServiceInstance; @@ -40,6 +40,7 @@ import org.onap.aai.domain.yang.VfModule; import org.onap.aai.domain.yang.VolumeGroup; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.entities.AAIResultWrapper; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider; import org.onap.so.db.request.client.RequestsDbClient; @@ -55,15 +56,19 @@ public class BpmnRequestBuilderTest { @Rule public ExpectedException exceptionRule = ExpectedException.none(); + + @Mock + private AAIResourcesClient aaiResourcesClient; + @InjectMocks - @Spy - BpmnRequestBuilder reqBuilder; + private AAIDataRetrieval aaiData = spy(AAIDataRetrieval.class); @Mock private RequestsDbClient requestDBClient; - @Mock - private AAIResourcesClient aaiResourcesClient; + @InjectMocks + private BpmnRequestBuilder reqBuilder = spy(BpmnRequestBuilder.class); + private ObjectMapper mapper = new ObjectMapper(); @@ -71,8 +76,7 @@ public class BpmnRequestBuilderTest { @Before public void setup() { - reqBuilder.setAaiResourcesClient(aaiResourcesClient); - + // aaiData.setAaiResourcesClient(aaiResourcesClient); } @Test @@ -80,11 +84,11 @@ public class BpmnRequestBuilderTest { ServiceInstance service = provider.getMapper().readValue(new File(RESOURCE_PATH + "ServiceInstance.json"), ServiceInstance.class); - doReturn(service).when(reqBuilder).getServiceInstance("serviceId"); + doReturn(service).when(aaiData).getServiceInstance("serviceId"); ServiceInstancesRequest expectedRequest = mapper .readValue(new File(RESOURCE_PATH + "ExpectedServiceRequest.json"), ServiceInstancesRequest.class); - expectedRequest.getRequestDetails().getModelInfo().setModelId(null); - // bad getter/setter setting multiple fields + expectedRequest.getRequestDetails().getModelInfo().setModelId(null); // bad getter/setter setting multiple + // fields ServiceInstancesRequest actualRequest = reqBuilder.buildServiceDeleteRequest("serviceId"); assertThat(actualRequest, sameBeanAs(expectedRequest)); } @@ -128,13 +132,16 @@ public class BpmnRequestBuilderTest { AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId")); VolumeGroup volumeGroup = provider.getMapper().readValue(new File(RESOURCE_PATH + "VolumeGroup.json"), VolumeGroup.class); - - doReturn(Optional.of(volumeGroup)).when(aaiResourcesClient).get(VolumeGroup.class, AAIUriFactory - .createResourceUri(AAIObjectType.VOLUME_GROUP, "cloudOwner", "regionOne", "volumeGroupId")); + AAIResultWrapper wrapper = new AAIResultWrapper(volumeGroup); + doReturn(wrapper).when(aaiResourcesClient) + .get(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId") + .relatedTo(AAIObjectType.VOLUME_GROUP, "volumeGroupId")); ServiceInstancesRequest expectedRequest = mapper .readValue(new File(RESOURCE_PATH + "ExpectedVolumeGroupRequest.json"), ServiceInstancesRequest.class); ServiceInstancesRequest actualRequest = reqBuilder.buildVolumeGroupDeleteRequest("vnfId", "volumeGroupId"); assertThat(actualRequest, sameBeanAs(expectedRequest)); } + } + diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ServiceInstanceNoOE.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ServiceInstanceNoOE.json new file mode 100644 index 0000000000..a6aa3e1c25 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/ServiceInstanceTest/ServiceInstanceNoOE.json @@ -0,0 +1,33 @@ +{ + "serviceInstanceId":"1882939", + "vnfInstanceId":"1882938", + "networkInstanceId":"1882937", + "volumeGroupInstanceId":"1882935", + "vfModuleInstanceId":"1882934", + "requestDetails": { + "requestInfo": { + "source": "VID", + "requestorId": "xxxxxx", + "instanceName": "testService9" + }, + "requestParameters": { + "aLaCarte": true, + "autoBuildVfModules": false, + "subscriptionServiceType": "test", + "disableOwningEntityProject": true + }, + "modelInfo":{ + "modelInvariantId": "f7ce78bb-423b-11e7-93f8-0050569a7965", + "modelVersion":"1", + "modelVersionId":"10", + "modelType":"service", + "modelName":"serviceModel", + "modelInstanceName":"modelInstanceName", + "modelCustomizationId":"f7ce78bb-423b-11e7-93f8-0050569a796" + }, + "subscriberInfo": { + "globalSubscriberId": "someTestId", + "subscriberName": "someTestId" + } + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/infra/Vnf.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/infra/Vnf.json index 09f6d81da3..0b03f56caa 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/infra/Vnf.json +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/infra/Vnf.json @@ -101,7 +101,7 @@ }, { "relationship-key": "volume-group.volume-group-id", - "relationship-value": "18b220c8-af84-4b82-a8c0-41bbea6328a6" + "relationship-value": "volumeGroupId" } ] }, diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql b/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql index 731d2bec4d..ee53e491a4 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/schema.sql @@ -1111,6 +1111,7 @@ CREATE TABLE `vnf_resource_customization` ( `CREATION_TIMESTAMP` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, `VNF_RESOURCE_MODEL_UUID` varchar(200) NOT NULL, `SERVICE_MODEL_UUID` varchar(200) NOT NULL, + `NF_DATA_VALID` tinyint(1) DEFAULT '0', `VNFCINSTANCEGROUP_ORDER` varchar(200) default NULL, PRIMARY KEY (`ID`), UNIQUE KEY `UK_vnf_resource_customization` (`MODEL_CUSTOMIZATION_UUID`,`SERVICE_MODEL_UUID`), |