X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=plans%2Fso%2Fintegration-etsi-testing%2Fso-simulators%2Fsdnc-simulator%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Fsdncsimulator%2Fproviders%2FServiceOperationsCacheServiceProviderimpl.java;h=24017b6bd375b49986dee2455389b2ffe20d9047;hb=03a107d9254ca0e1fbbf63f2ab5b7f14f1af63f3;hp=620742abbd10dabaad0cacf6c12451dd94826cb6;hpb=c44a753af3693cc67de62f8fea2c93cf17c070dc;p=integration%2Fcsit.git diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java index 620742ab..24017b6b 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProviderimpl.java @@ -19,34 +19,60 @@ */ package org.onap.so.sdncsimulator.providers; +import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.CREATED; +import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.PENDINGCREATE; +import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE; import static org.onap.so.sdncsimulator.utils.Constants.RESTCONF_CONFIG_END_POINT; +import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_DATA_VNFS_VNF; import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION; import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION_CACHE; +import static org.onap.so.sdncsimulator.utils.Constants.VNF_DATA_VNF_TOPOLOGY; import static org.onap.so.sdncsimulator.utils.Constants.YES; import static org.onap.so.sdncsimulator.utils.ObjectUtils.getString; import static org.onap.so.sdncsimulator.utils.ObjectUtils.getStringOrNull; import static org.onap.so.sdncsimulator.utils.ObjectUtils.isValid; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; import java.util.Optional; +import javax.validation.Valid; import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference; import org.onap.sdnc.northbound.client.model.GenericResourceApiLastActionEnumeration; import org.onap.sdnc.northbound.client.model.GenericResourceApiLastRpcActionEnumeration; import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiOperStatusData; import org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration; -import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestStatusEnumeration; import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiRpcActionEnumeration; import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader; -import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceModelInfrastructure; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServiceData; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfs; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnf; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnfVnfData; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation; import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService; import org.onap.sdnc.northbound.client.model.GenericResourceApiServicestatusServiceStatus; import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyServiceTopology; import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfRequestInput; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure; + +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleTopology; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfTopology; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVfModuleOperationInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleinformationVfModuleInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyVfModuleTopology; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduletopologyidentifierVfModuleTopologyIdentifier; +import org.onap.sdnc.northbound.client.model.GenericResourceApiParam; +import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam; + import org.onap.so.sdncsimulator.models.Output; +import org.onap.so.sdncsimulator.utils.Constants; import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -64,7 +90,9 @@ import org.springframework.stereotype.Service; public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServiceProvider implements ServiceOperationsCacheServiceProvider { - + private static final String HTTP_STATUS_BAD_REQUEST = Integer.toString(HttpStatus.BAD_REQUEST.value()); + private static final String HTTP_STATUS_OK = Integer.toString(HttpStatus.OK.value()); + private static final String EMPTY_STRING = ""; private static final Logger LOGGER = LoggerFactory.getLogger(ServiceOperationsCacheServiceProviderimpl.class); @Autowired @@ -76,54 +104,309 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ public Output putServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) { final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader(); - final String svcRequestId = requestHeader != null ? requestHeader.getSvcRequestId() : null; + final String svcRequestId = getSvcRequestId(requestHeader); final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation(); if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) { - final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); final String serviceInstanceId = serviceInformation.getServiceInstanceId(); - LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}", - serviceInstanceId); - final GenericResourceApiServiceModelInfrastructure serviceModelInfrastructure = - new GenericResourceApiServiceModelInfrastructure(); + if (isServiceOperationInformationNotExists(serviceInstanceId, input)) { + final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); + LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}", + serviceInstanceId); + + final GenericResourceApiServicemodelinfrastructureService service = + getServiceItem(input, serviceInstanceId); + cache.put(serviceInstanceId, service); + + final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus(); + + return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator()) + .responseCode(serviceStatus.getResponseCode()) + .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId) + .serviceResponseInformation(new GenericResourceApiInstanceReference() + .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId))); + } + LOGGER.error("serviceInstanceId: {} already exists", serviceInstanceId); + return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST) + .responseMessage("serviceInstanceId: " + serviceInstanceId + " already exists") + .svcRequestId(svcRequestId); + } - final GenericResourceApiServicemodelinfrastructureService service = getServiceItem(input); - serviceModelInfrastructure.addServiceItem(service); - cache.put(serviceInstanceId, serviceModelInfrastructure); + LOGGER.error( + "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ", + input); + return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST) + .responseMessage("Service instance not found").svcRequestId(svcRequestId); - final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus(); + } - return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator()) - .responseCode(serviceStatus.getResponseCode()).responseMessage(serviceStatus.getResponseMessage()) - .svcRequestId(svcRequestId).serviceResponseInformation(new GenericResourceApiInstanceReference() - .instanceId(serviceInstanceId).objectPath(RESTCONF_CONFIG_END_POINT + serviceInstanceId)); + @Override + public Output deleteServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) { + final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation(); + final String svcRequestId = getSvcRequestId(input.getSdncRequestHeader()); + + if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) { + final String serviceInstanceId = serviceInformation.getServiceInstanceId(); + final Optional optional = + getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId); + if (optional.isPresent()) { + final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); + LOGGER.info("Deleting GenericResourceApiServiceOperationInformation from cache using key: {}", + serviceInstanceId); + cache.evict(serviceInstanceId); + return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_OK) + .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId).serviceResponseInformation( + new GenericResourceApiInstanceReference().instanceId(serviceInstanceId)); + } + LOGGER.error( + "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}", + serviceInstanceId); } - return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString()) - .responseMessage("Service instance not found").svcRequestId(svcRequestId); + LOGGER.error("Unable to remove service instance from cache due to invalid input: {}... ", input); + return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST) + .responseMessage("Unable to remove service").svcRequestId(svcRequestId); } @Override - public Optional getGenericResourceApiServiceModelInfrastructure( + public Optional getGenericResourceApiServicemodelinfrastructureService( final String serviceInstanceId) { final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); - final GenericResourceApiServiceModelInfrastructure value = - cache.get(serviceInstanceId, GenericResourceApiServiceModelInfrastructure.class); + final GenericResourceApiServicemodelinfrastructureService value = + cache.get(serviceInstanceId, GenericResourceApiServicemodelinfrastructureService.class); if (value != null) { + LOGGER.info("Found {} in cahce for service instance id: {}", value, serviceInstanceId); return Optional.of(value); } + LOGGER.error("Unable to find GenericResourceApiServiceModelInfrastructure in cache for service instance id: {}", + serviceInstanceId); return Optional.empty(); } + @Override + public Output putVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) { + + final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation(); + final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation(); + + final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader(); + final String svcRequestId = getSvcRequestId(requestHeader); + + if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null + && isValid(vnfInformation.getVnfId())) { + final String serviceInstanceId = serviceInformation.getServiceInstanceId(); + final String vnfId = vnfInformation.getVnfId(); + final Optional optional = + getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId); + if (optional.isPresent()) { + final GenericResourceApiServicemodelinfrastructureService service = optional.get(); + final GenericResourceApiServicedataServiceData serviceData = service.getServiceData(); + if (serviceData != null) { + final List vnfsList = getVnfs(serviceData); + final GenericResourceApiLastRpcActionEnumeration svcAction = + GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(requestHeader)); + + if (ifVnfNotExists(vnfId, svcAction, vnfsList)) { + vnfsList.add(getGenericResourceApiServicedataVnf(serviceInstanceId, vnfId, input)); + setVnfsData(vnfsList); + final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus(); + + return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator()) + .responseCode(serviceStatus.getResponseCode()) + .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId) + .serviceResponseInformation(new GenericResourceApiInstanceReference() + .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId))) + .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId) + .objectPath(getObjectPath(serviceInstanceId, vnfId))); + } + LOGGER.error("vnfId: {} already exists with SVC Action: {}", vnfId, svcAction); + return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST) + .responseMessage("vnfId: " + vnfId + " already exists").svcRequestId(svcRequestId); + } + } + LOGGER.error( + "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}", + serviceInstanceId); + + } + LOGGER.error( + "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ", + input); + return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST) + .responseMessage("Unable to add vnf").svcRequestId(svcRequestId); + } + + @Override + public Output deleteVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) { + final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation(); + final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation(); + + final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader(); + final String svcRequestId = getSvcRequestId(requestHeader); + + if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null + && isValid(vnfInformation.getVnfId())) { + final String serviceInstanceId = serviceInformation.getServiceInstanceId(); + final String vnfId = vnfInformation.getVnfId(); + final Optional optional = + getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId); + if (optional.isPresent()) { + final GenericResourceApiServicemodelinfrastructureService service = optional.get(); + final GenericResourceApiServicedataServiceData serviceData = service.getServiceData(); + if (serviceData != null) { + final List vnfsList = getVnfs(serviceData); + final Optional vnfInstanceOptional = + getExistingVnf(vnfId, vnfsList); + + if (vnfInstanceOptional.isPresent()) { + vnfsList.removeIf(vnf -> { + final String existingVnfId = vnf.getVnfId(); + if (existingVnfId != null && existingVnfId.equals(vnfId)) { + LOGGER.info("Remove vnf with id: {} ... ", existingVnfId); + return true; + } + return false; + }); + + return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_OK) + .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId) + .serviceResponseInformation( + new GenericResourceApiInstanceReference().instanceId(serviceInstanceId)) + .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId)); + } + + } + } + LOGGER.error( + "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}", + serviceInstanceId); + + } + LOGGER.error("Unable to remove vnf instance from cache due to invalid input: {}... ", input); + return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST) + .responseMessage("Unable to remove vnf").svcRequestId(svcRequestId); + + } + + private String getSvcRequestId(final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader) { + return requestHeader != null ? requestHeader.getSvcRequestId() : null; + } + @Override public void clearAll() { - clearCahce(SERVICE_TOPOLOGY_OPERATION_CACHE); + clearCache(SERVICE_TOPOLOGY_OPERATION_CACHE); + } + + private String getObjectPath(final String serviceInstanceId, final String vnfId) { + return getObjectPath(serviceInstanceId) + SERVICE_DATA_VNFS_VNF + vnfId + VNF_DATA_VNF_TOPOLOGY; + } + + private String getObjectPath(final String serviceInstanceId) { + return RESTCONF_CONFIG_END_POINT + serviceInstanceId; + } + + + private boolean ifVnfNotExists(final String vnfId, final GenericResourceApiLastRpcActionEnumeration svcAction, + final List vnfsList) { + final Optional optional = getExistingVnf(vnfId, vnfsList); + if (optional.isPresent()) { + final GenericResourceApiServicedataServicedataVnfsVnf existingVnf = optional.get(); + final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = existingVnf.getVnfData(); + + if (vnfData != null && vnfData.getVnfLevelOperStatus() != null + && vnfData.getVnfLevelOperStatus().getLastRpcAction() != null) { + final GenericResourceApiLastRpcActionEnumeration existingVnflastRpcAction = + vnfData.getVnfLevelOperStatus().getLastRpcAction(); + if (existingVnflastRpcAction.equals(svcAction)) { + LOGGER.error("Found vnf with id: {} and LastRpcAction: {} same as SvcAction: {}", vnfId, + existingVnflastRpcAction, svcAction); + return false; + } + LOGGER.warn("Will remove and replace existing vnf with id: {} as SvcAction is changed from {} to {}", + vnfId, existingVnflastRpcAction, svcAction); + vnfsList.removeIf(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)); + + } + } + + return true; + } + + private Optional getExistingVnf(final String vnfId, + final List vnfsList) { + return vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst(); + } + + private List getVnfs( + final GenericResourceApiServicedataServiceData serviceData) { + GenericResourceApiServicedataServicedataVnfs vnfs = serviceData.getVnfs(); + if (vnfs == null) { + vnfs = new GenericResourceApiServicedataServicedataVnfs(); + serviceData.setVnfs(vnfs); + } + + List vnfsList = vnfs.getVnf(); + if (vnfsList == null) { + vnfsList = new ArrayList<>(); + vnfs.setVnf(vnfsList); + } + return vnfsList; + } + + private GenericResourceApiServicedataServicedataVnfsVnf getGenericResourceApiServicedataVnf( + final String serviceInstanceId, final String vnfId, final GenericResourceApiVnfOperationInformation input) { + return new GenericResourceApiServicedataServicedataVnfsVnf().vnfId(vnfId).vnfData(getVnfData(input)); + } + + private GenericResourceApiServicedataServicedataVnfsVnfVnfData getVnfData( + final GenericResourceApiVnfOperationInformation input) { + + final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = + new GenericResourceApiServicedataServicedataVnfsVnfVnfData(); + + vnfData.vnfLevelOperStatus( + getServiceLevelOperStatus(PENDINGCREATE, input.getRequestInformation(), input.getSdncRequestHeader())); + vnfData.serviceInformation(input.getServiceInformation()); + vnfData.sdncRequestHeader(input.getSdncRequestHeader()); + vnfData.vnfInformation(input.getVnfInformation()); + vnfData.requestInformation(input.getRequestInformation()); + vnfData.vnfRequestInput(input.getVnfRequestInput()); + + vnfData.vnfTopology(getVnfTopology(input.getVnfInformation(), input.getVnfRequestInput())); + + return vnfData; + } + + private GenericResourceApiVnftopologyVnfTopology getVnfTopology( + final GenericResourceApiVnfinformationVnfInformation vnfInformation, + final GenericResourceApiVnfrequestinputVnfRequestInput vnfRequestInput) { + + final GenericResourceApiVnftopologyVnfTopology apiVnftopologyVnfTopology = + new GenericResourceApiVnftopologyVnfTopology(); + + if (vnfInformation != null) { + apiVnftopologyVnfTopology.onapModelInformation(vnfInformation.getOnapModelInformation()); + apiVnftopologyVnfTopology.vnfTopologyIdentifierStructure(getTopologyIdentifierStructure(vnfInformation)); + } + if (vnfRequestInput != null) { + apiVnftopologyVnfTopology.tenant(vnfRequestInput.getTenant()); + apiVnftopologyVnfTopology.aicClli(vnfRequestInput.getAicClli()); + apiVnftopologyVnfTopology.aicCloudRegion(vnfRequestInput.getAicCloudRegion()); + } + return apiVnftopologyVnfTopology; + } + + private GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure getTopologyIdentifierStructure( + @Valid final GenericResourceApiVnfinformationVnfInformation vnfInformation) { + return new GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure() + .vnfId(vnfInformation.getVnfId()).vnfName(vnfInformation.getVnfName()) + .vnfType(vnfInformation.getVnfType()); } private GenericResourceApiServicemodelinfrastructureService getServiceItem( - final GenericResourceApiServiceOperationInformation input) { + final GenericResourceApiServiceOperationInformation input, final String serviceInstanceId) { final GenericResourceApiServicedataServiceData apiServicedataServiceData = new GenericResourceApiServicedataServiceData(); @@ -136,15 +419,11 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ apiServicedataServiceData.serviceLevelOperStatus(getServiceLevelOperStatus(input)); final GenericResourceApiServicestatusServiceStatus serviceStatus = - getServiceStatus(getSvcAction(input.getSdncRequestHeader()), getAction(input.getRequestInformation()), - HttpStatus.OK.toString()); + getServiceStatus(getSvcAction(input.getSdncRequestHeader()), + getRequestAction(input.getRequestInformation()), HTTP_STATUS_OK); return new GenericResourceApiServicemodelinfrastructureService().serviceData(apiServicedataServiceData) - .serviceStatus(serviceStatus); - } - - private String getAction(final GenericResourceApiRequestinformationRequestInformation input) { - return getString(input.getRequestAction(), ""); + .serviceStatus(serviceStatus).serviceInstanceId(serviceInstanceId); } private String getSvcAction(final GenericResourceApiSdncrequestheaderSdncRequestHeader input) { @@ -156,21 +435,30 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ return new GenericResourceApiServicestatusServiceStatus().finalIndicator(YES) .rpcAction(GenericResourceApiRpcActionEnumeration.fromValue(rpcAction)) .rpcName(SERVICE_TOPOLOGY_OPERATION).responseTimestamp(LocalDateTime.now().toString()) - .responseCode(responseCode).requestStatus(GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE) - .responseMessage("").action(action); + .responseCode(responseCode).requestStatus(SYNCCOMPLETE).responseMessage(EMPTY_STRING).action(action); } private GenericResourceApiOperStatusData getServiceLevelOperStatus( final GenericResourceApiServiceOperationInformation input) { - return new GenericResourceApiOperStatusData().orderStatus(GenericResourceApiOrderStatusEnumeration.CREATED) - .lastAction(GenericResourceApiLastActionEnumeration - .fromValue(getRequestAction(input.getRequestInformation()))) - .lastRpcAction(GenericResourceApiLastRpcActionEnumeration - .fromValue(getSvcAction(input.getSdncRequestHeader()))); + return getServiceLevelOperStatus(CREATED, input.getRequestInformation(), input.getSdncRequestHeader()); + } + + private GenericResourceApiOperStatusData getServiceLevelOperStatus( + final GenericResourceApiOrderStatusEnumeration statusEnumeration, + final GenericResourceApiRequestinformationRequestInformation requestInformation, + final GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader) { + return new GenericResourceApiOperStatusData().orderStatus(statusEnumeration) + .lastAction(GenericResourceApiLastActionEnumeration.fromValue(getRequestAction(requestInformation))) + .lastRpcAction(GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(sdncRequestHeader))); } private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input) { - return input != null ? getStringOrNull(input.getRequestAction()) : null; + return getRequestAction(input, EMPTY_STRING); + } + + private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input, + final String defaultValue) { + return input != null ? getString(input.getRequestAction(), defaultValue) : defaultValue; } private GenericResourceApiServicetopologyServiceTopology getServiceTopology( @@ -202,4 +490,187 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ } + private boolean isServiceOperationInformationNotExists(final String serviceInstanceId, + final GenericResourceApiServiceOperationInformation input) { + final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader(); + final Optional optional = + getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId); + + if (optional.isPresent()) { + final GenericResourceApiServicemodelinfrastructureService existingService = optional.get(); + final GenericResourceApiServicestatusServiceStatus serviceStatus = existingService.getServiceStatus(); + if (serviceStatus != null) { + final GenericResourceApiRpcActionEnumeration rpcAction = serviceStatus.getRpcAction(); + final String svcAction = getSvcAction(requestHeader); + if (rpcAction != null && rpcAction.toString().equals(svcAction)) { + LOGGER.error("Found Service with id: {} and RpcAction: {} same as SvcAction: {}", + serviceInstanceId, rpcAction, svcAction); + return false; + } + + final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE); + LOGGER.info( + "Deleting existing GenericResourceApiServiceOperationInformation from cache using key: {} as SvcAction is changed from {} to {}", + serviceInstanceId, rpcAction, svcAction); + cache.evict(serviceInstanceId); + } + } + return true; + + } + + @Override + public Output putVfModuleOperationInformation( + final GenericResourceApiVfModuleOperationInformation input) { + + final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation(); + final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation(); + final GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation = input.getVfModuleInformation(); + // Call getVfModule to make a vfList for get the vf-module-information while GET reqest + getVfModule(input); + + final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader(); + final String svcRequestId = getSvcRequestId(requestHeader); + + if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null + && isValid(vnfInformation.getVnfId()) && vfModuleInformation !=null && isValid(vfModuleInformation.getVfModuleId())) { + + + final String serviceInstanceId = serviceInformation.getServiceInstanceId(); + final String vnfId = vnfInformation.getVnfId(); + final String vfModuleId = vfModuleInformation.getVfModuleId(); + + final Optional optional = + getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId); + if (optional.isPresent()) { + final GenericResourceApiServicemodelinfrastructureService service = optional.get(); + final GenericResourceApiServicedataServiceData serviceData = service.getServiceData(); + if (serviceData != null) { + + final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus(); + + return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator()) + .responseCode(serviceStatus.getResponseCode()) + .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId) + .serviceResponseInformation(new GenericResourceApiInstanceReference() + .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId))) + .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId) + .objectPath(getObjectPath(serviceInstanceId, vnfId))) + .vfModuleResponseInformation(new GenericResourceApiInstanceReference().instanceId(vfModuleId) + .objectPath(getObjectPath(vnfId, vfModuleId))); + } + } + LOGGER.error( + "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}", + serviceInstanceId); + } + LOGGER.error( + "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ", + input); + return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST) + .responseMessage("Unable to add vfModule").svcRequestId(svcRequestId); + } + + private void getVfModule + (final GenericResourceApiVfModuleOperationInformation input) { + + final GenericResourceApiVfmoduletopologyVfModuleTopology apiVfModuletopologyVfModuleTopology = + new GenericResourceApiVfmoduletopologyVfModuleTopology(); + + final GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData vfModuleData = + new GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfmoduleVfModuleData(); + + final String vfModuleId = input.getVfModuleInformation().getVfModuleId(); + + vfModuleData.setVfModuleInformation(input.getVfModuleInformation()); + vfModuleData.setVfModuleRequestInput(input.getVfModuleRequestInput()); + + final GenericResourceApiVfmoduletopologyVfModuleTopology vfModuleTopology = + new GenericResourceApiVfmoduletopologyVfModuleTopology(); + + vfModuleTopology.setSdncGeneratedCloudResources(true); + final GenericResourceApiParam vfModuleParametersData = new GenericResourceApiParam(); + final List params = new ArrayList(); + final GenericResourceApiParamParam param = new GenericResourceApiParamParam(); + param.setName("k8s-rb-profile-name"); + param.setValue("k8s-rb-profile-value"); + + params.add(param); + vfModuleParametersData.setParam(params); + vfModuleTopology.setVfModuleParameters(vfModuleParametersData); + + vfModuleTopology.setOnapModelInformation(vfModuleData.getVfModuleInformation().getOnapModelInformation()); + vfModuleTopology.setVfModuleParameters(vfModuleData.getVfModuleRequestInput().getVfModuleInputParameters()); + vfModuleTopology.setAicClli(vfModuleData.getVfModuleRequestInput().getAicClli()); + vfModuleTopology.setAicCloudRegion(vfModuleData.getVfModuleRequestInput().getAicCloudRegion()); + vfModuleTopology.setCloudOwner(vfModuleData.getVfModuleRequestInput().getCloudOwner()); + + apiVfModuletopologyVfModuleTopology.vfModuleTopologyIdentifier(getVfModuleTopologyIdentifierStructure(input)); + + vfModuleTopology.setVfModuleTopologyIdentifier(apiVfModuletopologyVfModuleTopology.getVfModuleTopologyIdentifier()); + vfModuleTopology.setTenant(vfModuleData.getVfModuleRequestInput().getTenant()); + + final GenericResourceApiVfModuleTopology genericResourceApiVfModuleTopology = new GenericResourceApiVfModuleTopology(); + genericResourceApiVfModuleTopology.setVfModuleTopology(vfModuleTopology); + + final Cache cache = getCache(Constants.SERVICE_TOPOLOGY_OPERATION_CACHE); + cache.put(vfModuleId, genericResourceApiVfModuleTopology); + } + + @Override + public Optional getGenericResourceApiVfModuleTopology(final String vfModueId) { + LOGGER.info("getting GenericResourceApiVfModuleTopology from cache using key: {}", vfModueId); + final Cache cache = getCache(Constants.SERVICE_TOPOLOGY_OPERATION_CACHE); + final GenericResourceApiVfModuleTopology value = + cache.get(vfModueId, GenericResourceApiVfModuleTopology.class); + if (value != null) { + return Optional.of(value); + } + LOGGER.error("Unable to find GenericResourceApiVfModuleTopology ..."); + return Optional.empty(); + } + + private GenericResourceApiVfmoduletopologyidentifierVfModuleTopologyIdentifier getVfModuleTopologyIdentifierStructure( + @Valid final GenericResourceApiVfModuleOperationInformation input) { + + final GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation = input.getVfModuleInformation(); + return new GenericResourceApiVfmoduletopologyidentifierVfModuleTopologyIdentifier() + .vfModuleId(vfModuleInformation.getVfModuleId()).vfModuleType(vfModuleInformation.getVfModuleType()).vfModuleName(input.getVfModuleRequestInput().getVfModuleName()); + } + + + public void setVnfsData(List vnfsList) { + + final GenericResourceApiVnftopologyVnfTopology vnfTopology = new GenericResourceApiVnftopologyVnfTopology(); + LOGGER.info(String.valueOf(vnfsList)); + final String vnfId = vnfsList.get(0).getVnfId(); + vnfTopology.setOnapModelInformation(vnfsList.get(0).getVnfData().getVnfInformation().getOnapModelInformation()); + vnfTopology.setAicClli(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getAicClli())); + vnfTopology.setAicCloudRegion(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getAicCloudRegion())); + vnfTopology.setCloudOwner(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getCloudOwner())); + vnfTopology.setTenant(String.valueOf(vnfsList.get(0).getVnfData().getVnfRequestInput().getTenant())); + vnfTopology.setVnfResourceAssignments(vnfsList.get(0).getVnfData().getVnfTopology().getVnfResourceAssignments()); + vnfTopology.setVnfTopologyIdentifierStructure(vnfsList.get(0).getVnfData().getVnfTopology().getVnfTopologyIdentifierStructure()); + vnfTopology.setVnfParametersData(vnfsList.get(0).getVnfData().getVnfTopology().getVnfParametersData()); + vnfTopology.setSdncGeneratedCloudResources(vnfsList.get(0).getVnfData().getVnfTopology().getSdncGeneratedCloudResources()); + + final GenericResourceApiVnfTopology genericResourceApiVnfTopology = new GenericResourceApiVnfTopology(); + genericResourceApiVnfTopology.setVnfTopology(vnfTopology); + + final Cache cache = getCache(Constants.SERVICE_TOPOLOGY_OPERATION_CACHE); + cache.put(vnfId, genericResourceApiVnfTopology); + } + + @Override + public Optional getGenericResourceApiVnfTopology(final String vnfId) { + LOGGER.info("getting GenericResourceApiVnfTopology from cache using key: {}", vnfId); + final Cache cache = getCache(Constants.SERVICE_TOPOLOGY_OPERATION_CACHE); + final GenericResourceApiVnfTopology value = + cache.get(vnfId, GenericResourceApiVnfTopology.class); + if (value != null) { + return Optional.of(value); + } + LOGGER.error("Unable to find GenericResourceApiVnfTopology ..."); + return Optional.empty(); + } }