diff options
Diffstat (limited to 'mso-api-handlers')
16 files changed, 267 insertions, 113 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java index c7692cb2cc..b09d676b57 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java @@ -23,7 +23,12 @@ package org.onap.so.apihandlerinfra; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; import javax.ws.rs.GET; @@ -34,14 +39,13 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.*; +import org.apache.http.HttpStatus; +import org.json.JSONObject; import org.onap.aai.domain.yang.v16.ServiceInstance; -import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; -import org.apache.http.HttpStatus; -import org.json.JSONObject; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.logging.filter.base.ErrorCode; import org.onap.so.apihandler.camundabeans.CamundaResponse; import org.onap.so.apihandler.common.CamundaClient; @@ -53,6 +57,7 @@ import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.CompareModelsRequest; import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceDeleteRequest; import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceRequest; import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2EServiceInstanceScaleRequest; +import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.E2ESliceServiceActivateRequest; import org.onap.so.apihandlerinfra.e2eserviceinstancebeans.GetE2EServiceInstanceResponse; import org.onap.so.apihandlerinfra.exceptions.ApiException; import org.onap.so.apihandlerinfra.exceptions.BPMNFailureException; @@ -380,8 +385,9 @@ public class E2EServiceInstances { // TODO Get the service template model version uuid from AAI. String modelVersionId = null; AAIResourcesClient client = new AAIResourcesClient(); - AAIResourceUri url = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, - e2eActReq.getGlobalSubscriberId(), e2eActReq.getServiceType(), instanceIdMap.get(SERVICE_ID)); + AAIResourceUri url = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(e2eActReq.getGlobalSubscriberId()).serviceSubscription(e2eActReq.getServiceType()) + .serviceInstance(instanceIdMap.get(SERVICE_ID))); Optional<ServiceInstance> serviceInstanceOpt = client.get(ServiceInstance.class, url); if (serviceInstanceOpt.isPresent()) { modelVersionId = serviceInstanceOpt.get().getModelVersionId(); @@ -469,8 +475,9 @@ public class E2EServiceInstances { // TODO Get the service template model version uuid from AAI. String modelVersionId = null; AAIResourcesClient client = new AAIResourcesClient(); - AAIResourceUri url = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, - e2eDelReq.getGlobalSubscriberId(), e2eDelReq.getServiceType(), instanceIdMap.get(SERVICE_ID)); + AAIResourceUri url = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(e2eDelReq.getGlobalSubscriberId()).serviceSubscription(e2eDelReq.getServiceType()) + .serviceInstance(instanceIdMap.get(SERVICE_ID))); Optional<ServiceInstance> serviceInstanceOpt = client.get(ServiceInstance.class, url); if (serviceInstanceOpt.isPresent()) { modelVersionId = serviceInstanceOpt.get().getModelVersionId(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java index e7b96b16a9..3f05c79dad 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java @@ -23,6 +23,11 @@ package org.onap.so.apihandlerinfra; import java.sql.Timestamp; import java.util.HashMap; import java.util.UUID; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.function.Function; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -54,6 +59,7 @@ import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Allocate3gppServ import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.DeAllocate3gppService; import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Modify3gppService; import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.QuerySubnetCapability; +import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.SubnetTypes; import org.onap.so.constants.Status; import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceRecipe; @@ -70,6 +76,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.core.type.TypeReference; import io.swagger.v3.oas.annotations.OpenAPIDefinition; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.info.Info; @@ -238,8 +245,8 @@ public class Onap3gppServiceInstances { public Response getSliceSubnetCapabilities(QuerySubnetCapability request, @PathParam("version") String version) throws ApiException { logger.debug("Request received {}", request); - String subnetType = null; - return getSubnetCapabilities(subnetType, version); + List<SubnetTypes> subnetTypes = request.getSubnetTypes(); + return getSubnetCapabilities(subnetTypes, version); } /** @@ -577,8 +584,28 @@ public class Onap3gppServiceInstances { } // To be implemented for fetching Subnet capabilities - private Response getSubnetCapabilities(String subnetType, String version) throws ApiException { - return null; + private Response getSubnetCapabilities(List<SubnetTypes> subnetTypes, String version) throws ApiException { + ObjectMapper oMapper = new ObjectMapper(); + InputStream inputStream = TypeReference.class.getResourceAsStream("/subnetCapability.json"); + Map<String, Object> subnetCapability = new HashMap<>(); + try { + subnetCapability = oMapper.readValue(inputStream, Map.class); + } catch (Exception e) { + logger.debug("Exception while reading subnet capability value from json", e); + } + Map<String, Object> responseMap = new HashMap<>(); + for (SubnetTypes value : subnetTypes) { + if (subnetCapability.containsKey(value.toString())) { + responseMap.put(value.toString(), subnetCapability.get(value.toString())); + } + } + String response = null; + try { + response = oMapper.writeValueAsString(responseMap); + } catch (JsonProcessingException e) { + logger.debug("Exception while converting subnet capability object to String {}", e); + } + return builder.buildResponse(HttpStatus.SC_OK, null, response, version); } /** 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 87e5a2f23e..60e9c3b30a 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 @@ -518,20 +518,16 @@ public class RequestHandlerUtils extends AbstractRestHandler { } protected String setServiceInstanceId(String requestScope, ServiceInstancesRequest sir) { + String serviceInstanceId = null; if (sir.getServiceInstanceId() != null) { - return sir.getServiceInstanceId(); - } else if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) { - RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList(); - if (relatedInstances != null) { - for (RelatedInstanceList relatedInstanceList : relatedInstances) { - RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); - if (relatedInstance.getModelInfo().getModelType() == ModelType.service) { - return relatedInstance.getInstanceId(); - } - } + serviceInstanceId = sir.getServiceInstanceId(); + } else { + Optional<String> serviceInstanceIdForInstance = getServiceInstanceIdForInstanceGroup(requestScope, sir); + if (serviceInstanceIdForInstance.isPresent()) { + serviceInstanceId = serviceInstanceIdForInstance.get(); } } - return null; + return serviceInstanceId; } private String requestScopeFromUri(String requestUri) { @@ -916,6 +912,30 @@ public class RequestHandlerUtils extends AbstractRestHandler { return null; } + protected Optional<String> getServiceInstanceIdForValidationError(ServiceInstancesRequest sir, + HashMap<String, String> instanceIdMap, String requestScope) { + if (instanceIdMap != null && !instanceIdMap.isEmpty() && instanceIdMap.get("serviceInstanceId") != null) { + return Optional.of(instanceIdMap.get("serviceInstanceId")); + } else { + return getServiceInstanceIdForInstanceGroup(requestScope, sir); + } + } + + protected Optional<String> getServiceInstanceIdForInstanceGroup(String requestScope, ServiceInstancesRequest sir) { + if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) { + RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList(); + if (relatedInstances != null) { + for (RelatedInstanceList relatedInstanceList : relatedInstances) { + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + if (relatedInstance.getModelInfo().getModelType() == ModelType.service) { + return Optional.ofNullable(relatedInstance.getInstanceId()); + } + } + } + } + return Optional.empty(); + } + private RecipeLookupResult getDefaultVnfUri(ServiceInstancesRequest sir, Actions action) { String defaultSource = getDefaultModel(sir); VnfRecipe vnfRecipe = catalogDbClient.getFirstVnfRecipeByNfRoleAndAction(defaultSource, action.toString()); 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 107aa57974..2c8e92633c 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 @@ -829,7 +829,8 @@ public class ServiceInstances extends AbstractRestHandler { requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action); } catch (ApiException e) { msoRequest.createErrorRequestRecord(Status.FAILED, requestId, e.getMessage(), action, requestScope, - requestJSON, sir.getServiceInstanceId()); + requestJSON, requestHandlerUtils + .getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).orElse(null)); throw e; } 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 index 70de94a3ef..d8ad82c17d 100644 --- 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 @@ -1,7 +1,6 @@ package org.onap.so.apihandlerinfra.infra.rest; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -15,14 +14,13 @@ import org.onap.aai.domain.yang.VfModule; import org.onap.aai.domain.yang.VfModules; import org.onap.aai.domain.yang.VolumeGroup; import org.onap.aai.domain.yang.VolumeGroups; -import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound; import org.onap.aaiclient.client.aai.AAIDSLQueryClient; -import org.onap.aaiclient.client.aai.AAIObjectPlurals; -import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.aaiclient.client.graphinventory.entities.DSLQuery; import org.onap.aaiclient.client.graphinventory.entities.DSLQueryBuilder; import org.onap.aaiclient.client.graphinventory.entities.DSLStartNode; @@ -30,6 +28,8 @@ import org.onap.aaiclient.client.graphinventory.entities.Node; import org.onap.aaiclient.client.graphinventory.entities.Start; import org.onap.aaiclient.client.graphinventory.entities.TraversalBuilder; import org.onap.aaiclient.client.graphinventory.entities.__; +import org.onap.so.apihandlerinfra.infra.rest.exception.AAIEntityNotFound; +import org.onap.so.serviceinstancebeans.CloudConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -48,7 +48,7 @@ public class AAIDataRetrieval { public ServiceInstance getServiceInstance(String serviceInstanceId) { return this.getAaiResourcesClient() .get(ServiceInstance.class, - AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId)) + AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId))) .orElseGet(() -> { logger.debug("No Service Instance found in A&AI ServiceInstanceId: {}", serviceInstanceId); return null; @@ -57,7 +57,9 @@ public class AAIDataRetrieval { public VfModule getAAIVfModule(String vnfId, String vfModuleId) { return this.getAaiResourcesClient() - .get(VfModule.class, AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, vnfId, vfModuleId)) + .get(VfModule.class, + AAIUriFactory.createResourceUri( + AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModule(vfModuleId))) .orElseGet(() -> { logger.debug("No Vf Module found in A&AI VnfId: {}" + ", VfModuleId: {}", vnfId, vfModuleId); return null; @@ -66,7 +68,8 @@ public class AAIDataRetrieval { public GenericVnf getGenericVnf(String vnfId) { return this.getAaiResourcesClient() - .get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)) + .get(GenericVnf.class, + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId))) .orElseGet(() -> { logger.debug("No Generic VNF found in A&AI VnfId: {}", vnfId); return null; @@ -74,9 +77,9 @@ public class AAIDataRetrieval { } 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)); + AAIResultWrapper wrapper = this.getAaiResourcesClient() + .get(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId)) + .relatedTo(Types.VOLUME_GROUP.getFragment(volumeGroupId))); Optional<VolumeGroup> volume = wrapper.asBean(VolumeGroup.class); if (volume.isPresent()) { return volume.get(); @@ -88,7 +91,8 @@ public class AAIDataRetrieval { public L3Network getNetwork(String networkId) { return this.getAaiResourcesClient() - .get(L3Network.class, AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId)) + .get(L3Network.class, + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().l3Network(networkId))) .orElseGet(() -> { logger.debug("No Network found in A&AI NetworkId: {}", networkId); return null; @@ -96,51 +100,57 @@ public class AAIDataRetrieval { } - public boolean isVolumeGroupRelatedToVFModule(String volumeGroupId) { - return this.getAaiResourcesClient().exists(AAIUriFactory - .createResourceUri(AAIObjectType.VOLUME_GROUP, volumeGroupId).relatedTo(AAIObjectPlurals.VF_MODULE)); + public boolean isVolumeGroupRelatedToVFModule(CloudConfiguration cloudConfig, String volumeGroupId) { + return this.getAaiResourcesClient() + .exists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure() + .cloudRegion(cloudConfig.getCloudOwner(), cloudConfig.getLcpCloudRegionId()) + .volumeGroup(volumeGroupId)).relatedTo(Types.VF_MODULES.getFragment())); } public boolean isVnfRelatedToVolumes(String vnfId) { - return this.getAaiResourcesClient().exists(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId) - .relatedTo(AAIObjectPlurals.VOLUME_GROUP)); + return this.getAaiResourcesClient() + .exists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId)) + .relatedTo(Types.VOLUME_GROUPS.getFragment())); } public boolean isNetworkRelatedToModules(String networkId) { - return this.getAaiResourcesClient().exists(AAIUriFactory.createResourceUri(AAIObjectType.L3_NETWORK, networkId) - .relatedTo(AAIObjectPlurals.VF_MODULE)); + return this.getAaiResourcesClient() + .exists(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().l3Network(networkId)) + .relatedTo(Types.VF_MODULES.getFragment())); } public boolean isServiceRelatedToNetworks(String serviceInstanceId) { return this.getAaiResourcesClient() - .exists(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) - .relatedTo(AAIObjectPlurals.L3_NETWORK)); + .exists(AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)) + .relatedTo(Types.L3_NETWORKS.getFragment())); } public boolean isServiceRelatedToGenericVnf(String serviceInstanceId) { return this.getAaiResourcesClient() - .exists(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) - .relatedTo(AAIObjectPlurals.GENERIC_VNF)); + .exists(AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)) + .relatedTo(Types.GENERIC_VNFS.getFragment())); } public boolean isServiceRelatedToConfiguration(String serviceInstanceId) { return this.getAaiResourcesClient() - .exists(AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) - .relatedTo(AAIObjectPlurals.CONFIGURATION)); + .exists(AAIUriFactory.createResourceUri(Types.SERVICE_INSTANCE.getFragment(serviceInstanceId)) + .relatedTo(Types.CONFIGURATIONS.getFragment())); } public Service getService(String serviceId) { return this.getAaiResourcesClient() - .get(Service.class, AAIUriFactory.createResourceUri(AAIObjectType.SERVICE, serviceId)).orElseGet(() -> { + .get(Service.class, + AAIUriFactory + .createResourceUri(AAIFluentTypeBuilder.serviceDesignAndCreation().service(serviceId))) + .orElseGet(() -> { logger.debug("No Service found in A&AI ServiceId: {}", serviceId); return null; }); } public Tenant getTenant(String cloudOwner, String cloudRegion, String tenantId) { - return this.getAaiResourcesClient() - .get(Tenant.class, - AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudOwner, cloudRegion, tenantId)) + return this.getAaiResourcesClient().get(Tenant.class, AAIUriFactory.createResourceUri( + AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion(cloudOwner, cloudRegion).tenant(tenantId))) .orElseGet(() -> { logger.debug("No Tenant found in A&AI TenantId: {}", tenantId); return null; @@ -148,9 +158,9 @@ public class AAIDataRetrieval { } public List<LInterface> getLinterfacesOfVnf(String vnfId) { - DSLStartNode startNode = new DSLStartNode(AAIObjectType.GENERIC_VNF, __.key("vnf-id", vnfId)); - DSLQueryBuilder<Start, Node> builder = TraversalBuilder.fragment(startNode) - .to(__.node(AAIObjectType.VSERVER).to(__.node(AAIObjectType.L_INTERFACE).output())); + DSLStartNode startNode = new DSLStartNode(Types.GENERIC_VNF, __.key("vnf-id", vnfId)); + DSLQueryBuilder<Start, Node> builder = + TraversalBuilder.fragment(startNode).to(__.node(Types.VSERVER).to(__.node(Types.L_INTERFACE).output())); List<LInterface> linterfaces = getAAIDSLQueryClient().querySingleResource(new DSLQuery(builder.build()), LInterface.class); return linterfaces; @@ -176,7 +186,8 @@ public class AAIDataRetrieval { public List<VfModule> getVfModulesOfVnf(String vnfId) { List<VfModule> vfModuleList = new ArrayList<VfModule>(); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, vnfId); + AAIPluralResourceUri uri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId).vfModules()); Optional<VfModules> vfModules = getAaiResourcesClient().get(VfModules.class, uri); if (!vfModules.isPresent() || vfModules.get().getVfModule().isEmpty()) { logger.debug("No VfModules attached to Vnf in AAI : {}", vnfId); @@ -198,8 +209,8 @@ public class AAIDataRetrieval { public List<VolumeGroup> getVolumeGroupsOfVnf(String vnfId) { List<VolumeGroup> volumeGroupList = new ArrayList<VolumeGroup>(); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId) - .relatedTo(AAIObjectPlurals.VOLUME_GROUP); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId)) + .relatedTo(Types.VOLUME_GROUPS.getFragment()); Optional<VolumeGroups> volumeGroups = getAaiResourcesClient().get(VolumeGroups.class, uri); if (!volumeGroups.isPresent() || volumeGroups.get().getVolumeGroup().isEmpty()) { logger.debug("No VolumeGroups attached to Vnf in AAI : {}", vnfId); 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 6e7947bb58..edf17f363b 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 @@ -29,9 +29,9 @@ 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.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; 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; @@ -278,13 +278,13 @@ public class BpmnRequestBuilder { String cloudOwner = null; String lcpRegionId = null; if (relationshipsOpt.isPresent()) { - tenantId = relationshipsOpt.get().getRelatedUris(AAIObjectType.TENANT).stream().findFirst() + tenantId = relationshipsOpt.get().getRelatedUris(Types.TENANT).stream().findFirst() .map(item -> item.getURIKeys().get(AAIFluentTypeBuilder.Types.TENANT.getUriParams().tenantId)) .orElse(null); - cloudOwner = relationshipsOpt.get().getRelatedUris(AAIObjectType.TENANT).stream().findFirst().map( + cloudOwner = relationshipsOpt.get().getRelatedUris(Types.TENANT).stream().findFirst().map( item -> item.getURIKeys().get(AAIFluentTypeBuilder.Types.CLOUD_REGION.getUriParams().cloudOwner)) .orElse(null); - lcpRegionId = relationshipsOpt.get().getRelatedUris(AAIObjectType.TENANT).stream().findFirst().map( + lcpRegionId = relationshipsOpt.get().getRelatedUris(Types.TENANT).stream().findFirst().map( item -> item.getURIKeys().get(AAIFluentTypeBuilder.Types.CLOUD_REGION.getUriParams().cloudRegionId)) .orElse(null); } @@ -323,13 +323,13 @@ public class BpmnRequestBuilder { String cloudOwner = null; String lcpRegionId = null; if (relationshipsOpt.isPresent()) { - tenantId = relationshipsOpt.get().getRelatedUris(AAIObjectType.TENANT).stream().findFirst() + tenantId = relationshipsOpt.get().getRelatedUris(Types.TENANT).stream().findFirst() .map(item -> item.getURIKeys().get(AAIFluentTypeBuilder.Types.TENANT.getUriParams().tenantId)) .orElse(null); - cloudOwner = relationshipsOpt.get().getRelatedUris(AAIObjectType.TENANT).stream().findFirst().map( + cloudOwner = relationshipsOpt.get().getRelatedUris(Types.TENANT).stream().findFirst().map( item -> item.getURIKeys().get(AAIFluentTypeBuilder.Types.CLOUD_REGION.getUriParams().cloudOwner)) .orElse(null); - lcpRegionId = relationshipsOpt.get().getRelatedUris(AAIObjectType.TENANT).stream().findFirst().map( + lcpRegionId = relationshipsOpt.get().getRelatedUris(Types.TENANT).stream().findFirst().map( item -> item.getURIKeys().get(AAIFluentTypeBuilder.Types.CLOUD_REGION.getUriParams().cloudRegionId)) .orElse(null); } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java index 550db19af4..3640baa942 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/infra/rest/validators/VolumeGroupDeleteValidator.java @@ -25,7 +25,8 @@ public class VolumeGroupDeleteValidator implements RequestValidator { @Override public Optional<String> validate(Map<String, String> instanceIdMap, ServiceInstancesRequest request, Map<String, String> queryParams, Actions action) { - if (aaiDataRetrieval.isVolumeGroupRelatedToVFModule(instanceIdMap.get("volumeGroupInstanceId"))) { + if (aaiDataRetrieval.isVolumeGroupRelatedToVFModule(request.getRequestDetails().getCloudConfiguration(), + instanceIdMap.get("volumeGroupInstanceId"))) { return Optional.of("Cannot delete volume group it is related to existing vf-modules"); } else { return Optional.empty(); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java index 2e479e1ecb..c66b053609 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java @@ -22,26 +22,26 @@ package org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans; import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; /** * Model class for slice subnet capability query */ public class QuerySubnetCapability { - private SubnetTypes subnetType; + @JsonProperty("subnetTypes") + private List<SubnetTypes> subnetTypes; - public SubnetTypes getSubnetType() { - return subnetType; + public List<SubnetTypes> getSubnetTypes() { + return subnetTypes; } - public void setSubnetType(SubnetTypes subnetType) { - this.subnetType = subnetType; + public void setSubnetTypes(List<SubnetTypes> subnetTypes) { + this.subnetTypes = subnetTypes; } @Override public String toString() { - return "QuerySubnetCapability [subnetType=" + subnetType + "]"; + return "QuerySubnetCapability [subnetType=" + subnetTypes + "]"; } - } - diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java index a28298f859..33fe9d8ae9 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/helpers/AAIClientHelper.java @@ -27,13 +27,13 @@ import java.io.StringWriter; import java.util.Map; import javax.ws.rs.NotFoundException; import org.onap.aai.domain.yang.OperationalEnvironment; -import org.onap.so.apihandlerinfra.tenantisolation.exceptions.AAIClientCallFailed; -import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; import org.onap.aaiclient.client.graphinventory.entities.uri.Depth; +import org.onap.so.apihandlerinfra.tenantisolation.exceptions.AAIClientCallFailed; import org.springframework.stereotype.Component; @@ -50,7 +50,8 @@ public class AAIClientHelper { */ public AAIResultWrapper getAaiOperationalEnvironment(String id) { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, id); + AAIResourceUri uri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().operationalEnvironment(id)); uri.depth(Depth.ZERO); AAIResourcesClient client = this.getClient(); return client.get(uri, NotFoundException.class); @@ -65,7 +66,8 @@ public class AAIClientHelper { */ public void updateAaiOperationalEnvironment(String id, OperationalEnvironment aaiRequest) { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, id); + AAIResourceUri uri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure().operationalEnvironment(id)); AAIResourcesClient client = this.getClient(); client.update(uri, aaiRequest); @@ -75,8 +77,8 @@ public class AAIClientHelper { public void updateAaiOperationalEnvironment(String operationalEnvironmentId, Map<String, String> payload) throws AAIClientCallFailed { try { - AAIResourceUri uri = - AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, operationalEnvironmentId); + AAIResourceUri uri = AAIUriFactory.createResourceUri( + AAIFluentTypeBuilder.cloudInfrastructure().operationalEnvironment(operationalEnvironmentId)); AAIResourcesClient aaiClient = this.getClient(); aaiClient.update(uri, payload); } catch (Exception ex) { @@ -92,8 +94,8 @@ public class AAIClientHelper { */ public void createOperationalEnvironment(OperationalEnvironment operationalEnvironment) { - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, - operationalEnvironment.getOperationalEnvironmentId()); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure() + .operationalEnvironment(operationalEnvironment.getOperationalEnvironmentId())); AAIResourcesClient client = this.getClient(); client.create(uri, operationalEnvironment); } @@ -107,10 +109,10 @@ public class AAIClientHelper { */ public void createRelationship(String managingEcompOperationalEnvironmentId, String vnfOperationalEnvironmentId) { - AAIResourceUri ecompEnvUri = AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, - managingEcompOperationalEnvironmentId); - AAIResourceUri vnfEnvUri = - AAIUriFactory.createResourceUri(AAIObjectType.OPERATIONAL_ENVIRONMENT, vnfOperationalEnvironmentId); + AAIResourceUri ecompEnvUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.cloudInfrastructure() + .operationalEnvironment(managingEcompOperationalEnvironmentId)); + AAIResourceUri vnfEnvUri = AAIUriFactory.createResourceUri( + AAIFluentTypeBuilder.cloudInfrastructure().operationalEnvironment(vnfOperationalEnvironmentId)); AAIResourcesClient client = this.getClient(); client.connect(vnfEnvUri, ecompEnvUri); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java index d4c66f62e4..42d5af7feb 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/tenantisolation/process/ActivateVnfOperationalEnvironment.java @@ -26,11 +26,11 @@ import javax.ws.rs.core.Response; import org.apache.http.HttpStatus; import org.json.JSONObject; import org.onap.aai.domain.yang.OperationalEnvironment; -import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.Relationships; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.logging.filter.base.ErrorCode; import org.onap.so.apihandler.common.ErrorNumbers; import org.onap.so.apihandlerinfra.exceptions.ApiException; @@ -94,8 +94,7 @@ public class ActivateVnfOperationalEnvironment { Optional<Relationships> optRelationships = wrapper.getRelationships(); if (optRelationships.isPresent()) { Relationships relationships = optRelationships.get(); - List<AAIResourceUri> operationalEnvironments = - relationships.getRelatedAAIUris(AAIObjectType.OPERATIONAL_ENVIRONMENT); + List<AAIResourceUri> operationalEnvironments = relationships.getRelatedUris(Types.OPERATIONAL_ENVIRONMENT); if (!operationalEnvironments.isEmpty()) { ecompOperationalEnvironmentId = operationalEnvironments.get(0).getURIKeys().get( AAIFluentTypeBuilder.Types.OPERATIONAL_ENVIRONMENT.getUriParams().operationalEnvironmentId); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/resources/subnetCapability.json b/mso-api-handlers/mso-api-handler-infra/src/main/resources/subnetCapability.json new file mode 100644 index 0000000000..0d5acef64a --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/resources/subnetCapability.json @@ -0,0 +1,25 @@ +{ + "AN": { + "latency": "5", + "maxNumberofUEs": "100", + "maxThroughput": "150", + "terminalDensity": "50" + }, + "CN": { + "latency": "10", + "maxThroughput": "50", + "maxNumberofConns": "100" + }, + "TN_FH": { + "latency": "10", + "maxThroughput": "100" + }, + "TN_MH": { + "latency": "5", + "maxThroughput": "50" + }, + "TN_BH": { + "latency": "10", + "maxThroughput": "100" + } +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java index 503af1bdcb..c3c92be013 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java @@ -49,6 +49,9 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.util.UriComponentsBuilder; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.onap.so.apihandlerinfra.exceptions.ApiException; +import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.QuerySubnetCapability; +import org.springframework.beans.factory.annotation.Autowired; public class Onap3gppServiceInstancesTest extends BaseTest { @@ -56,6 +59,9 @@ public class Onap3gppServiceInstancesTest extends BaseTest { private final ObjectMapper mapper = new ObjectMapper(); + @Autowired + private Onap3gppServiceInstances objUnderTest; + @Before public void init() throws JsonProcessingException { @@ -176,6 +182,17 @@ public class Onap3gppServiceInstancesTest extends BaseTest { assertEquals(expectedResponse, actualResponse); } + @Test + public void getSliceSubnetCapabilitiesTest() throws IOException, ApiException { + String request = "{\"subnetTypes\":[\"AN\"]}"; + QuerySubnetCapability subnetCapabilityRequest = mapper.readValue(request, QuerySubnetCapability.class); + String expectedResponse = + "{\"AN\":{\"latency\":\"5\",\"maxNumberofUEs\":\"100\",\"maxThroughput\":\"150\",\"terminalDensity\":\"50\"}}"; + Response response = objUnderTest.getSliceSubnetCapabilities(subnetCapabilityRequest, "v1"); + String actualResponse = (String) response.getEntity(); + assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + assertEquals(expectedResponse, actualResponse); + } } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java index 7f9ff98b19..2ba646fba0 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java @@ -39,6 +39,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.HashMap; import java.util.List; import javax.ws.rs.core.MediaType; import org.apache.http.HttpStatus; @@ -338,4 +339,34 @@ public class RequestHandlerUtilsTest extends BaseTest { assertEquals(expectedBasicAuth, basicAuth); } + @Test + public void getServiceInstanceIdForValidationErrorTest() { + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + String requestScope = "vnf"; + HashMap<String, String> instanceIdMap = new HashMap<String, String>(); + instanceIdMap.put("serviceInstanceId", "testServiceInstanceId"); + String serviceInstanceId = + requestHandlerUtils.getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).get(); + assertEquals("testServiceInstanceId", serviceInstanceId); + } + + @Test + public void getServiceInstanceIdForValidationErrorInstanceGroupTest() throws Exception { + ServiceInstancesRequest sir = + mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class); + String requestScope = "instanceGroup"; + String serviceInstanceId = + requestHandlerUtils.getServiceInstanceIdForValidationError(sir, null, requestScope).get(); + assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", serviceInstanceId); + } + + @Test + public void getServiceInstanceIdForInstanceGroupTest() throws Exception { + ServiceInstancesRequest sir = + mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class); + String requestScope = "instanceGroup"; + String serviceInstanceId = requestHandlerUtils.getServiceInstanceIdForInstanceGroup(requestScope, sir).get(); + assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", serviceInstanceId); + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrievalTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrievalTest.java index 9d5d80592d..61ac542810 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrievalTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/AAIDataRetrievalTest.java @@ -24,22 +24,20 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.doReturn; import java.util.List; import java.util.Optional; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; -import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.VfModule; import org.onap.aai.domain.yang.VfModules; import org.onap.aai.domain.yang.VolumeGroup; import org.onap.aai.domain.yang.VolumeGroups; -import org.onap.aaiclient.client.aai.AAIObjectPlurals; -import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; @RunWith(MockitoJUnitRunner.class) public class AAIDataRetrievalTest { @@ -52,7 +50,8 @@ public class AAIDataRetrievalTest { @Test public void getVfModulesOfVnfTest() { VfModules vfModules = getVfModules(); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "vnfId"); + AAIPluralResourceUri uri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId").vfModules()); doReturn(Optional.of(vfModules)).when(aaiResourcesClient).get(VfModules.class, uri); List<VfModule> vfModulesList = aaiDataRetrieval.getVfModulesOfVnf("vnfId"); assertEquals("vfm1", vfModulesList.get(0).getVfModuleId()); @@ -64,7 +63,8 @@ public class AAIDataRetrievalTest { @Test public void getVfModulesOfVnfWhenNoneTest() { VfModules vfModules = new VfModules(); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectPlurals.VF_MODULE, "vnfId"); + AAIPluralResourceUri uri = + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId").vfModules()); doReturn(Optional.of(vfModules)).when(aaiResourcesClient).get(VfModules.class, uri); List<VfModule> vfModulesList = aaiDataRetrieval.getVfModulesOfVnf("vnfId"); assertEquals(true, vfModulesList.isEmpty()); @@ -76,8 +76,8 @@ public class AAIDataRetrievalTest { @Test public void getVolumeGroupsOfVnfTest() throws Exception { VolumeGroups volumeGroups = getVolumeGroups(); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId") - .relatedTo(AAIObjectPlurals.VOLUME_GROUP); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId")) + .relatedTo(Types.VOLUME_GROUPS.getFragment()); doReturn(Optional.of(volumeGroups)).when(aaiResourcesClient).get(VolumeGroups.class, uri); List<VolumeGroup> volumeGroupList = aaiDataRetrieval.getVolumeGroupsOfVnf("vnfId"); assertEquals("vg1", volumeGroupList.get(0).getVolumeGroupId()); @@ -88,8 +88,8 @@ public class AAIDataRetrievalTest { @Test public void getVolumeGroupsOfVnfWhenNoneTest() throws Exception { VolumeGroups volumeGroups = new VolumeGroups(); - AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId") - .relatedTo(AAIObjectPlurals.VOLUME_GROUP); + AAIPluralResourceUri uri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId")) + .relatedTo(Types.VOLUME_GROUPS.getFragment()); doReturn(Optional.of(volumeGroups)).when(aaiResourcesClient).get(VolumeGroups.class, uri); List<VolumeGroup> volumeGroupList = aaiDataRetrieval.getVolumeGroupsOfVnf("vnfId"); assertEquals(true, volumeGroupList.isEmpty()); 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 389ff28dbd..912c026203 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 @@ -41,10 +41,11 @@ import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aai.domain.yang.VfModule; import org.onap.aai.domain.yang.VolumeGroup; -import org.onap.aaiclient.client.aai.AAIObjectType; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.entities.AAIResultWrapper; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types; import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider; import org.onap.so.constants.Status; import org.onap.so.db.request.client.RequestsDbClient; @@ -104,7 +105,7 @@ public class BpmnRequestBuilderTest { GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class); doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class, - AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId")); + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId"))); ServiceInstancesRequest expectedRequest = mapper.readValue(new File(RESOURCE_PATH + "ExpectedVnfRequest.json"), ServiceInstancesRequest.class); @@ -117,11 +118,11 @@ public class BpmnRequestBuilderTest { GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class); doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class, - AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId")); + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId"))); VfModule vfModule = provider.getMapper().readValue(new File(RESOURCE_PATH + "VfModule.json"), VfModule.class); - doReturn(Optional.of(vfModule)).when(aaiResourcesClient).get(VfModule.class, - AAIUriFactory.createResourceUri(AAIObjectType.VF_MODULE, "vnfId", "vfModuleId")); + doReturn(Optional.of(vfModule)).when(aaiResourcesClient).get(VfModule.class, AAIUriFactory + .createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId").vfModule("vfModuleId"))); ServiceInstancesRequest expectedRequest = mapper .readValue(new File(RESOURCE_PATH + "ExpectedVfModuleRequest.json"), ServiceInstancesRequest.class); @@ -135,13 +136,13 @@ public class BpmnRequestBuilderTest { GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class); doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class, - AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId")); + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId"))); VolumeGroup volumeGroup = provider.getMapper().readValue(new File(RESOURCE_PATH + "VolumeGroup.json"), VolumeGroup.class); AAIResultWrapper wrapper = new AAIResultWrapper(volumeGroup); doReturn(wrapper).when(aaiResourcesClient) - .get(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, "vnfId") - .relatedTo(AAIObjectType.VOLUME_GROUP, "volumeGroupId")); + .get(AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf("vnfId")) + .relatedTo(Types.VOLUME_GROUP.getFragment("volumeGroupId"))); ServiceInstancesRequest expectedRequest = mapper .readValue(new File(RESOURCE_PATH + "ExpectedVolumeGroupRequest.json"), ServiceInstancesRequest.class); @@ -157,7 +158,7 @@ public class BpmnRequestBuilderTest { GenericVnf vnf = provider.getMapper().readValue(new File(RESOURCE_PATH + "Vnf.json"), GenericVnf.class); doReturn(Optional.of(vnf)).when(aaiResourcesClient).get(GenericVnf.class, - AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)); + AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId))); CloudConfiguration result = reqBuilder.getCloudConfigurationVfModuleReplace(vnfId, vfModuleId); assertEquals("0422ffb57ba042c0800a29dc85ca70f8", result.getTenantId()); diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java index 7aa12a61a6..1023408088 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/infra/rest/validator/VolumeGroupDeleteValidatorTest.java @@ -1,6 +1,8 @@ package org.onap.so.apihandlerinfra.infra.rest.validator; import static org.junit.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; import java.util.HashMap; import java.util.Map; @@ -14,6 +16,8 @@ import org.mockito.junit.MockitoJUnitRunner; import org.onap.so.apihandlerinfra.Action; import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval; import org.onap.so.apihandlerinfra.infra.rest.validators.VolumeGroupDeleteValidator; +import org.onap.so.serviceinstancebeans.CloudConfiguration; +import org.onap.so.serviceinstancebeans.RequestDetails; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; @@ -53,16 +57,24 @@ public class VolumeGroupDeleteValidatorTest { @Test public void validateSuccessTest() { instanceIdMap.put("volumeGroupInstanceId", "1"); - when(aaiDataRetrieval.isVolumeGroupRelatedToVFModule("1")).thenReturn(false); - Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, null, null, null); + ServiceInstancesRequest request = new ServiceInstancesRequest(); + RequestDetails details = new RequestDetails(); + details.setCloudConfiguration(new CloudConfiguration()); + request.setRequestDetails(details); + when(aaiDataRetrieval.isVolumeGroupRelatedToVFModule(any(CloudConfiguration.class), eq("1"))).thenReturn(false); + Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, request, null, null); assertEquals(false, result.isPresent()); } @Test public void validateFailureVnfTest() { instanceIdMap.put("volumeGroupInstanceId", "1"); - when(aaiDataRetrieval.isVolumeGroupRelatedToVFModule("1")).thenReturn(true); - Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, null, null, null); + ServiceInstancesRequest request = new ServiceInstancesRequest(); + RequestDetails details = new RequestDetails(); + details.setCloudConfiguration(new CloudConfiguration()); + request.setRequestDetails(details); + when(aaiDataRetrieval.isVolumeGroupRelatedToVFModule(any(CloudConfiguration.class), eq("1"))).thenReturn(true); + Optional<String> result = volumeGroupDeleteValidator.validate(instanceIdMap, request, null, null); assertEquals(true, result.isPresent()); } |