diff options
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/sdnc-simulator')
10 files changed, 495 insertions, 67 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java index 00740298..2d901c42 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/controller/OperationsController.java @@ -23,6 +23,7 @@ import static org.onap.so.sdncsimulator.utils.Constants.OPERATIONS_URL; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation; import org.onap.so.sdncsimulator.models.InputRequest; import org.onap.so.sdncsimulator.models.Output; import org.onap.so.sdncsimulator.models.OutputRequest; @@ -55,15 +56,17 @@ public class OperationsController { } @PostMapping(value = "/GENERIC-RESOURCE-API:service-topology-operation/", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> postServiceOperationInformation( @RequestBody final InputRequest<GenericResourceApiServiceOperationInformation> inputRequest, final HttpServletRequest request) { - LOGGER.info("Request Received {} ...", inputRequest); + LOGGER.info("Request Received: {} ...", inputRequest); final GenericResourceApiServiceOperationInformation apiServiceOperationInformation = inputRequest.getInput(); if (apiServiceOperationInformation == null) { + LOGGER.error("Invalid input request: {}", inputRequest); return ResponseEntity.badRequest().build(); } @@ -71,9 +74,37 @@ public class OperationsController { final OutputRequest outputRequest = new OutputRequest(output); if (output.getResponseCode().equals(HttpStatus.OK.toString())) { + LOGGER.info("Sucessfully added service in cache sending response: {}", outputRequest); + return ResponseEntity.ok(outputRequest); + } + LOGGER.error("Unable to add input request: {}, will send OutputRequest: {}", inputRequest, outputRequest); + return ResponseEntity.badRequest().body(outputRequest); + + } + + @PostMapping(value = "/GENERIC-RESOURCE-API:vnf-topology-operation/", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> postVnfOperationInformation( + @RequestBody final InputRequest<GenericResourceApiVnfOperationInformation> inputRequest, + final HttpServletRequest request) { + LOGGER.info("Request Received: {} ...", inputRequest); + + final GenericResourceApiVnfOperationInformation apiVnfOperationInformation = inputRequest.getInput(); + if (apiVnfOperationInformation == null) { + LOGGER.error("Invalid input request: {}", inputRequest); + return ResponseEntity.badRequest().build(); + } + + final Output output = cacheServiceProvider.putVnfOperationInformation(apiVnfOperationInformation); + final OutputRequest outputRequest = new OutputRequest(output); + + if (output.getResponseCode().equals(HttpStatus.OK.toString())) { + LOGGER.info("Sucessfully added vnf in cache sending response: {}", outputRequest); return ResponseEntity.ok(outputRequest); } + LOGGER.error("Unable to add input request: {}, will send OutputRequest: {}", inputRequest, outputRequest); return ResponseEntity.badRequest().body(outputRequest); } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/InputRequest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/InputRequest.java index d4e83fce..3d415202 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/InputRequest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/InputRequest.java @@ -19,13 +19,16 @@ */ package org.onap.so.sdncsimulator.models; +import java.io.Serializable; import com.fasterxml.jackson.annotation.JsonIgnore; /** * @author Waqas Ikram (waqas.ikram@est.tech) * */ -public class InputRequest<T> { +public class InputRequest<T> implements Serializable { + + private static final long serialVersionUID = -3408332422970506740L; private T input; @@ -46,7 +49,11 @@ public class InputRequest<T> { @JsonIgnore @Override public String toString() { - return "Input [input=" + input + "]"; + final StringBuilder sb = new StringBuilder(); + sb.append("class InputRequest {\n"); + sb.append(" input: ").append(input).append("\n"); + sb.append("}"); + return sb.toString(); } } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/Output.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/Output.java index 554989db..d64b0b0c 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/Output.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/Output.java @@ -19,6 +19,7 @@ */ package org.onap.so.sdncsimulator.models; +import java.io.Serializable; import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; @@ -27,7 +28,9 @@ import com.fasterxml.jackson.annotation.JsonProperty; * @author Waqas Ikram (waqas.ikram@est.tech) * */ -public class Output { +public class Output implements Serializable { + + private static final long serialVersionUID = 3838047042980836468L; @JsonProperty("response-message") private String responseMessage; @@ -44,6 +47,9 @@ public class Output { @JsonProperty("service-response-information") private GenericResourceApiInstanceReference serviceResponseInformation = null; + @JsonProperty("vnf-response-information") + private GenericResourceApiInstanceReference vnfResponseInformation = null; + /** * @return the responseMessage */ @@ -114,6 +120,21 @@ public class Output { this.serviceResponseInformation = serviceResponseInformation; } + /** + * @return the vnfResponseInformation + */ + public GenericResourceApiInstanceReference getVnfResponseInformation() { + return vnfResponseInformation; + } + + /** + * @param vnfResponseInformation the vnfResponseInformation to set + */ + public void setVnfResponseInformation(final GenericResourceApiInstanceReference vnfResponseInformation) { + this.vnfResponseInformation = vnfResponseInformation; + } + + public Output responseMessage(final String responseMessage) { this.responseMessage = responseMessage; return this; @@ -139,13 +160,25 @@ public class Output { return this; } + public Output vnfResponseInformation(final GenericResourceApiInstanceReference vnfResponseInformation) { + this.vnfResponseInformation = vnfResponseInformation; + return this; + + } @JsonIgnore @Override public String toString() { - return "OutputRequest [responseMessage=" + responseMessage + ", ackFinalIndicator=" + ackFinalIndicator - + ", svcRequestId=" + svcRequestId + ", responseCode=" + responseCode + ", serviceResponseInformation=" - + serviceResponseInformation + "]"; + final StringBuilder sb = new StringBuilder(); + sb.append("class OutputRequest {\n"); + sb.append(" responseMessage: ").append(responseMessage).append("\n"); + sb.append(" ackFinalIndicator: ").append(ackFinalIndicator).append("\n"); + sb.append(" svcRequestId: ").append(svcRequestId).append("\n"); + sb.append(" responseCode: ").append(responseCode).append("\n"); + sb.append(" serviceResponseInformation: ").append(serviceResponseInformation).append("\n"); + sb.append(" vnfResponseInformation: ").append(vnfResponseInformation).append("\n"); + sb.append("}"); + return sb.toString(); } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/OutputRequest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/OutputRequest.java index 97d20568..1dcd427d 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/OutputRequest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/models/OutputRequest.java @@ -19,14 +19,17 @@ */ package org.onap.so.sdncsimulator.models; +import java.io.Serializable; import com.fasterxml.jackson.annotation.JsonProperty; /** * @author Waqas Ikram (waqas.ikram@est.tech) * */ +public class OutputRequest implements Serializable { + + private static final long serialVersionUID = -6702076913290110397L; -public class OutputRequest { @JsonProperty("output") private Output output; @@ -47,7 +50,11 @@ public class OutputRequest { @Override public String toString() { - return "OutputRequest [output=" + output + "]"; + final StringBuilder sb = new StringBuilder(); + sb.append("class OutputRequest {\n"); + sb.append(" output: ").append(output).append("\n"); + sb.append("}"); + return sb.toString(); } } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java index a0116c48..97dc7b11 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/providers/ServiceOperationsCacheServiceProvider.java @@ -20,8 +20,9 @@ package org.onap.so.sdncsimulator.providers; import java.util.Optional; -import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceModelInfrastructure; import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService; +import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation; import org.onap.so.sdncsimulator.models.Output; /** @@ -33,10 +34,11 @@ public interface ServiceOperationsCacheServiceProvider { Output putServiceOperationInformation( final GenericResourceApiServiceOperationInformation apiServiceOperationInformation); - Optional<GenericResourceApiServiceModelInfrastructure> getGenericResourceApiServiceModelInfrastructure( + Optional<GenericResourceApiServicemodelinfrastructureService> getGenericResourceApiServicemodelinfrastructureService( final String serviceInstanceId); - void clearAll(); + Output putVnfOperationInformation(final GenericResourceApiVnfOperationInformation apiVnfOperationInformation); + void clearAll(); } 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..2281d0ab 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,33 +19,47 @@ */ 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.so.sdncsimulator.models.Output; import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; @@ -64,7 +78,6 @@ import org.springframework.stereotype.Service; public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServiceProvider implements ServiceOperationsCacheServiceProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(ServiceOperationsCacheServiceProviderimpl.class); @Autowired @@ -85,45 +98,181 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}", serviceInstanceId); - final GenericResourceApiServiceModelInfrastructure serviceModelInfrastructure = - new GenericResourceApiServiceModelInfrastructure(); - - final GenericResourceApiServicemodelinfrastructureService service = getServiceItem(input); - serviceModelInfrastructure.addServiceItem(service); - cache.put(serviceInstanceId, serviceModelInfrastructure); + 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(RESTCONF_CONFIG_END_POINT + serviceInstanceId)); + .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId))); } + LOGGER.error( + "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ", + input); return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString()) .responseMessage("Service instance not found").svcRequestId(svcRequestId); } @Override - public Optional<GenericResourceApiServiceModelInfrastructure> getGenericResourceApiServiceModelInfrastructure( + public Optional<GenericResourceApiServicemodelinfrastructureService> 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 = requestHeader != null ? requestHeader.getSvcRequestId() : null; + + if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null + && isValid(vnfInformation.getVnfId())) { + final String serviceInstanceId = serviceInformation.getServiceInstanceId(); + final String vnfId = vnfInformation.getVnfId(); + final Optional<GenericResourceApiServicemodelinfrastructureService> optional = + getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId); + if (optional.isPresent()) { + final GenericResourceApiServicemodelinfrastructureService service = optional.get(); + final GenericResourceApiServicedataServiceData serviceData = service.getServiceData(); + if (serviceData != null) { + final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData); + if (ifVnfNotExists(vnfId, vnfsList)) { + + vnfsList.add(getGenericResourceApiServicedataVnf(serviceInstanceId, vnfId, input)); + + 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", vnfId); + return new Output().ackFinalIndicator(YES).responseCode(HttpStatus.BAD_REQUEST.toString()) + .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(HttpStatus.BAD_REQUEST.toString()) + .responseMessage("Unable to add vnf").svcRequestId(svcRequestId); + } + + @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 List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) { + final Optional<GenericResourceApiServicedataServicedataVnfsVnf> optional = + vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst(); + return !optional.isPresent(); + } + + private List<GenericResourceApiServicedataServicedataVnfsVnf> getVnfs( + final GenericResourceApiServicedataServiceData serviceData) { + GenericResourceApiServicedataServicedataVnfs vnfs = serviceData.getVnfs(); + if (vnfs == null) { + vnfs = new GenericResourceApiServicedataServicedataVnfs(); + serviceData.setVnfs(vnfs); + } + + List<GenericResourceApiServicedataServicedataVnfsVnf> 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(); @@ -140,7 +289,7 @@ public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServ HttpStatus.OK.toString()); return new GenericResourceApiServicemodelinfrastructureService().serviceData(apiServicedataServiceData) - .serviceStatus(serviceStatus); + .serviceStatus(serviceStatus).serviceInstanceId(serviceInstanceId); } private String getAction(final GenericResourceApiRequestinformationRequestInformation input) { @@ -156,17 +305,21 @@ 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("").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) { diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/Constants.java index 2d774edd..21d0d7a2 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/Constants.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/main/java/org/onap/so/sdncsimulator/utils/Constants.java @@ -39,5 +39,9 @@ public class Constants { public static final String RESTCONF_CONFIG_END_POINT = "restconf/config/GENERIC-RESOURCE-API:services/service/"; + public static final String VNF_DATA_VNF_TOPOLOGY = "/vnf-data/vnf-topology/"; + + public static final String SERVICE_DATA_VNFS_VNF = "/service-data/vnfs/vnf/"; + private Constants() {} } diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java index af46ab40..18d478eb 100644 --- a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/OperationsControllerTest.java @@ -22,15 +22,16 @@ package org.onap.so.sdncsimulator.controller; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Base64; +import static org.onap.so.sdncsimulator.controller.TestUtils.getInvalidRequestInput; +import static org.onap.so.sdncsimulator.controller.TestUtils.getRequestInput; +import static org.onap.so.sdncsimulator.controller.TestUtils.getVnfRequestInput; +import java.util.Optional; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnf; +import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService; import org.onap.so.sdncsimulator.models.InputRequest; import org.onap.so.sdncsimulator.models.Output; import org.onap.so.sdncsimulator.models.OutputRequest; @@ -43,12 +44,10 @@ import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -65,11 +64,15 @@ public class OperationsControllerTest { private static final String SVC_REQUEST_ID = "04fc9f50-87b8-430d-a232-ef24bd6c4150"; + private static final String VNF_SVC_REQUEST_ID = "8fd2622b-01fc-424d-bfc8-f48bcd64e546"; + private static final String SERVICE_INSTANCE_ID = "ccece8fe-13da-456a-baf6-41b3a4a2bc2b"; private static final String SERVICE_TOPOLOGY_OPERATION_URL = "/GENERIC-RESOURCE-API:service-topology-operation/"; - private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; + private static final String VNF_TOPOLOGY_OPERATION_URL = "/GENERIC-RESOURCE-API:vnf-topology-operation/"; + + private static final String VNF_INSTANCE_ID = "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701"; @LocalServerPort private int port; @@ -108,8 +111,16 @@ public class OperationsControllerTest { final GenericResourceApiInstanceReference acutalReference = actualObject.getServiceResponseInformation(); assertEquals(Constants.RESTCONF_CONFIG_END_POINT + SERVICE_INSTANCE_ID, acutalReference.getObjectPath()); assertEquals(SERVICE_INSTANCE_ID, acutalReference.getInstanceId()); - assertTrue( - cacheServiceProvider.getGenericResourceApiServiceModelInfrastructure(SERVICE_INSTANCE_ID).isPresent()); + final Optional<GenericResourceApiServicemodelinfrastructureService> optional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(optional.isPresent()); + + final GenericResourceApiServicemodelinfrastructureService service = optional.get(); + assertNotNull(service.getServiceInstanceId()); + assertEquals(SERVICE_INSTANCE_ID, service.getServiceInstanceId()); + assertNotNull(service.getServiceData()); + assertNotNull(service.getServiceStatus()); + } @Test @@ -143,39 +154,101 @@ public class OperationsControllerTest { } - private HttpHeaders getHttpHeaders() { - return getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); - } + @Test + public void test_postVnfOperationInformation_successfullyAddToExistingServiceInCache() throws Exception { + final HttpEntity<?> httpEntity = new HttpEntity<>(getRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseEntity = + restTemplate.exchange(getUrl(), HttpMethod.POST, httpEntity, OutputRequest.class); - private String getUrl() { - return "http://localhost:" + port + Constants.OPERATIONS_URL + SERVICE_TOPOLOGY_OPERATION_URL; - } + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); - private String getRequestInput() throws IOException { - return getFileAsString(getFile("test-data/input.json").toPath()); - } + final HttpEntity<?> httpVnfEntity = new HttpEntity<>(getVnfRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseVnfEntity = + restTemplate.exchange(getVnfUrl(), HttpMethod.POST, httpVnfEntity, OutputRequest.class); + assertEquals(HttpStatus.OK, responseVnfEntity.getStatusCode()); + assertTrue(responseVnfEntity.hasBody()); + + final OutputRequest actualOutputRequest = responseVnfEntity.getBody(); + assertNotNull(actualOutputRequest); + assertNotNull(actualOutputRequest.getOutput()); + + final Output actualObject = actualOutputRequest.getOutput(); + + assertEquals(HttpStatus.OK.toString(), actualObject.getResponseCode()); + assertEquals(Constants.YES, actualObject.getAckFinalIndicator()); + assertEquals(VNF_SVC_REQUEST_ID, actualObject.getSvcRequestId()); + assertNotNull(actualObject.getServiceResponseInformation()); - private String getInvalidRequestInput() throws IOException { - return getFileAsString(getFile("test-data/InvalidInput.json").toPath()); + final GenericResourceApiInstanceReference acutalReference = actualObject.getServiceResponseInformation(); + assertEquals(Constants.RESTCONF_CONFIG_END_POINT + SERVICE_INSTANCE_ID, acutalReference.getObjectPath()); + assertEquals(SERVICE_INSTANCE_ID, acutalReference.getInstanceId()); + final Optional<GenericResourceApiServicemodelinfrastructureService> optional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(optional.isPresent()); + + final GenericResourceApiInstanceReference actualvnfInformation = actualObject.getVnfResponseInformation(); + assertEquals(VNF_INSTANCE_ID, actualvnfInformation.getInstanceId()); + + final Optional<GenericResourceApiServicemodelinfrastructureService> serviceOptional = + cacheServiceProvider.getGenericResourceApiServicemodelinfrastructureService(SERVICE_INSTANCE_ID); + assertTrue(serviceOptional.isPresent()); + + final GenericResourceApiServicemodelinfrastructureService service = serviceOptional.get(); + assertNotNull(service.getServiceInstanceId()); + assertNotNull(service.getServiceData().getVnfs().getVnf()); + assertNotNull(service.getServiceData()); + assertNotNull(service.getServiceData().getVnfs()); + assertNotNull(service.getServiceData().getVnfs().getVnf()); + assertEquals(1, service.getServiceData().getVnfs().getVnf().size()); + final GenericResourceApiServicedataServicedataVnfsVnf vnf = service.getServiceData().getVnfs().getVnf().get(0); + assertNotNull(vnf.getVnfId()); + assertEquals(VNF_INSTANCE_ID, vnf.getVnfId()); + assertNotNull(vnf.getVnfData()); } - private String getFileAsString(final Path path) throws IOException { - return new String(Files.readAllBytes(path)); + @Test + public void test_postSameVnfOperationInformationTwice_ShouldReturnbadRequest() throws Exception { + + final HttpEntity<?> httpEntity = new HttpEntity<>(getRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseEntity = + restTemplate.exchange(getUrl(), HttpMethod.POST, httpEntity, OutputRequest.class); + + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + + final HttpEntity<?> httpVnfEntity = new HttpEntity<>(getVnfRequestInput(), getHttpHeaders()); + final ResponseEntity<OutputRequest> responseVnfEntity = + restTemplate.exchange(getVnfUrl(), HttpMethod.POST, httpVnfEntity, OutputRequest.class); + assertEquals(HttpStatus.OK, responseVnfEntity.getStatusCode()); + assertTrue(responseVnfEntity.hasBody()); + + final OutputRequest actualOutputRequest = responseVnfEntity.getBody(); + assertNotNull(actualOutputRequest); + assertNotNull(actualOutputRequest.getOutput()); + + final ResponseEntity<OutputRequest> badResponse = + restTemplate.exchange(getVnfUrl(), HttpMethod.POST, httpVnfEntity, OutputRequest.class); + + final OutputRequest badOutputRequest = badResponse.getBody(); + assertNotNull(badOutputRequest); + + final Output actualObject = badOutputRequest.getOutput(); + assertNotNull(actualObject); + assertEquals(HttpStatus.BAD_REQUEST.toString(), actualObject.getResponseCode()); + assertEquals(VNF_SVC_REQUEST_ID, actualObject.getSvcRequestId()); + assertEquals(Constants.YES, actualObject.getAckFinalIndicator()); + } - private File getFile(final String file) throws IOException { - return new ClassPathResource(file).getFile(); + private HttpHeaders getHttpHeaders() { + return TestUtils.getHttpHeaders(userCredentials.getUsers().iterator().next().getUsername()); } - private HttpHeaders getHttpHeaders(final String username) { - final HttpHeaders requestHeaders = new HttpHeaders(); - requestHeaders.add("Authorization", getBasicAuth(username)); - requestHeaders.setContentType(MediaType.APPLICATION_JSON); - return requestHeaders; + private String getUrl() { + return "http://localhost:" + port + Constants.OPERATIONS_URL + SERVICE_TOPOLOGY_OPERATION_URL; } - private String getBasicAuth(final String username) { - return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); + private String getVnfUrl() { + return "http://localhost:" + port + Constants.OPERATIONS_URL + VNF_TOPOLOGY_OPERATION_URL; } @After diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java new file mode 100644 index 00000000..a6814b69 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/java/org/onap/so/sdncsimulator/controller/TestUtils.java @@ -0,0 +1,72 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.sdncsimulator.controller; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Base64; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class TestUtils { + private static final String PASSWORD = "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"; + + + private TestUtils() {} + + public static String getRequestInput() throws IOException { + return getFileAsString(getFile("test-data/input.json").toPath()); + } + + public static String getVnfRequestInput() throws IOException { + return getFileAsString(getFile("test-data/vnfInput.json").toPath()); + } + + public static String getInvalidRequestInput() throws IOException { + return getFileAsString(getFile("test-data/InvalidInput.json").toPath()); + } + + public static String getFileAsString(final Path path) throws IOException { + return new String(Files.readAllBytes(path)); + } + + public static File getFile(final String file) throws IOException { + return new ClassPathResource(file).getFile(); + } + + public static HttpHeaders getHttpHeaders(final String username) { + final HttpHeaders requestHeaders = new HttpHeaders(); + requestHeaders.add("Authorization", getBasicAuth(username)); + requestHeaders.setContentType(MediaType.APPLICATION_JSON); + return requestHeaders; + } + + public static String getBasicAuth(final String username) { + return "Basic " + new String(Base64.getEncoder().encodeToString((username + ":" + PASSWORD).getBytes())); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/vnfInput.json b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/vnfInput.json new file mode 100644 index 00000000..01a28617 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/sdnc-simulator/src/test/resources/test-data/vnfInput.json @@ -0,0 +1,46 @@ +{ + "input": { + "request-information": { + "request-action": "CreateVnfInstance", + "source": "MSO", + "request-id": "1a545ea9-2a5e-4df9-9c73-529b1d0b2012" + }, + "sdnc-request-header": { + "svc-request-id": "8fd2622b-01fc-424d-bfc8-f48bcd64e546", + "svc-notification-url": "http://so-bpmn-infra.onap:8081/mso/WorkflowMessage/SDNCCallback/fd40ea09-3245-476a-b6ff-58cb042edb9d", + "svc-action": "assign" + }, + "service-information": { + "onap-model-information": { + "model-name": "Sol004Zip4Service", + "model-version": "1.0", + "model-uuid": "99d59273-4450-4034-9141-027f0c1a807a", + "model-invariant-uuid": "51672777-9b8d-4e5e-b488-5f9092e03a82" + }, + "subscription-service-type": "vCPE", + "service-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b", + "global-customer-id": "NordixDemoCustomer", + "service-instance-id": "ccece8fe-13da-456a-baf6-41b3a4a2bc2b" + }, + "vnf-information": { + "onap-model-information": { + "model-name": "Sol004Zip3VSP", + "model-version": "1.0", + "model-customization-uuid": "50a90cd7-a84e-4ee1-b5ba-bfa5a26f5e15", + "model-uuid": "84b9649a-4eb9-4967-9abe-e8702f55518b", + "model-invariant-uuid": "b0f14066-2b65-40d2-b5a4-c8f2116fb5fc" + }, + "vnf-id": "dfd02fb5-d7fb-4aac-b3c4-cd6b60058701", + "vnf-name": "EsyVnfInstantiationTest2", + "vnf-type": "Sol004Zip4Service/Sol004Zip3VSP 0" + }, + "vnf-request-input": { + "aic-cloud-region": "nordixcloud", + "cloud-owner": "CloudOwner", + "tenant": "693c7729b2364a26a3ca602e6f66187d", + "vnf-network-instance-group-ids": [], + "vnf-input-parameters": {}, + "vnf-name": "EsyVnfInstantiationTest2" + } + } +}
\ No newline at end of file |