diff options
Diffstat (limited to 'so-etsi-nfvo')
60 files changed, 1391 insertions, 317 deletions
diff --git a/so-etsi-nfvo/pom.xml b/so-etsi-nfvo/pom.xml index fa85460086..6845896fc0 100644 --- a/so-etsi-nfvo/pom.xml +++ b/so-etsi-nfvo/pom.xml @@ -28,6 +28,7 @@ <jaxb-api>2.3.0</jaxb-api> <snakeyaml-version>0.11</snakeyaml-version> <hamcrest-version>2.2</hamcrest-version> + <equalsverifier-version>3.4.1</equalsverifier-version> </properties> <build> diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-api/pom.xml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-api/pom.xml index a541117c93..272ac0c11a 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-api/pom.xml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-api/pom.xml @@ -166,14 +166,8 @@ <version>${okhttp-version}</version> </dependency> <dependency> - <groupId>com.squareup.okhttp</groupId> - <artifactId>logging-interceptor</artifactId> - <version>${okhttp-version}</version> - </dependency> - <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> - <version>${jaxb-api}</version> </dependency> </dependencies> diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/pom.xml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/pom.xml index 1c13ecac25..3178b28502 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/pom.xml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/pom.xml @@ -102,5 +102,11 @@ <version>${hamcrest-version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <version>${equalsverifier-version}</version> + <scope>test</scope> + </dependency> </dependencies> </project>
\ No newline at end of file diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/CamundaVariableNameConstants.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/CamundaVariableNameConstants.java index fd51b1a873..a7acc3ec25 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/CamundaVariableNameConstants.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/CamundaVariableNameConstants.java @@ -32,8 +32,7 @@ public class CamundaVariableNameConstants { public static final String SERVICE_TYPE_PARAM_NAME = "serviceType"; public static final String NS_PACKAGE_MODEL_PARAM_NAME = "NSPackageModel"; - public static final String CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME = - "CreateNsWorkflowProcessingException"; + public static final String NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME = "NsWorkflowProcessingException"; public static final String CREATE_NS_RESPONSE_PARAM_NAME = "createNsResponse"; public static final String INSTANTIATE_NS_REQUEST_PARAM_NAME = "instantiateNsRequest"; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/Constants.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/Constants.java index 14a4f4340b..c6c56c9eb3 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/Constants.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/Constants.java @@ -30,6 +30,7 @@ public class Constants { public static final String CREATE_NS_WORKFLOW_NAME = "CreateNs"; public static final String INSTANTIATE_NS_WORKFLOW_NAME = "InstantiateNs"; public static final String TERMINATE_NS_WORKFLOW_NAME = "TerminateNs"; + public static final String DELETE_NS_WORKFLOW_NAME = "DeleteNs"; public static final String GET_NS_OCCURRENCE_OPERATION_STATUS_NAME = "GetNsOccurrenceOperationStatus"; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/exceptions/NsRequestProcessingException.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/exceptions/NsRequestProcessingException.java index 0dcadfd4d8..0901f077d2 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/exceptions/NsRequestProcessingException.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/exceptions/NsRequestProcessingException.java @@ -31,10 +31,11 @@ import org.springframework.web.bind.annotation.ResponseStatus; public class NsRequestProcessingException extends RuntimeException { private static final long serialVersionUID = 66862444537194516L; - private InlineResponse400 problemDetails; + private final InlineResponse400 problemDetails; public NsRequestProcessingException(final String message) { super(message); + problemDetails = null; } public NsRequestProcessingException(final String message, final InlineResponse400 problemDetails) { diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiServiceProvider.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiServiceProvider.java index 29ed85cbd8..a54a6f41f9 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiServiceProvider.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiServiceProvider.java @@ -43,4 +43,5 @@ public interface AaiServiceProvider { void deleteGenericVnf(final String vnfId); + void deleteServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId); } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiServiceProviderImpl.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiServiceProviderImpl.java index 0da53a09c2..a3b3fa9d66 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiServiceProviderImpl.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/aai/AaiServiceProviderImpl.java @@ -22,7 +22,6 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai; import java.util.Optional; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.ServiceInstance; -import org.onap.aaiclient.client.aai.AAIObjectType; 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; @@ -93,4 +92,15 @@ public class AaiServiceProviderImpl implements AaiServiceProvider { AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId)); aaiClientProvider.getAaiClient().delete(aaiResourceUri); } + + @Override + public void deleteServiceInstance(final String globalCustomerId, final String serviceType, + final String serviceInstanceId) { + logger.info( + "Deleting Service Instance with \nGlobal Customer Id: {}, \nService Type: {}, and \nService Instance Id: {} \nfrom AAI.", + globalCustomerId, serviceType, serviceInstanceId); + final AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business() + .customer(globalCustomerId).serviceSubscription(serviceType).serviceInstance(serviceInstanceId)); + aaiClientProvider.getAaiClient().delete(serviceInstanceUri); + } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java index 75dd7107a7..749e85e3db 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java @@ -25,7 +25,7 @@ import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model. import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.EtsiCatalogManagerRequestFailureException; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; -import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptorParser; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser.NetworkServiceDescriptorParser; import org.onap.so.rest.service.HttpRestServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,9 +66,8 @@ public class EtsiCatalogPackageManagementServiceProviderImpl implements EtsiCata } return Optional.empty(); } catch (final Exception restProcessingException) { - logger.error("Caught exception while getting NS package model for: {}", nsdId, restProcessingException); - throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.", - restProcessingException); + final String message = "Caught exception while getting NS package model for: " + nsdId; + throw new EtsiCatalogManagerRequestFailureException(message, restProcessingException); } } @@ -82,9 +81,8 @@ public class EtsiCatalogPackageManagementServiceProviderImpl implements EtsiCata } return Optional.empty(); } catch (final Exception restProcessingException) { - logger.error("Caught exception while getting VNF package model for: {}", vnfPkgId, restProcessingException); - throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.", - restProcessingException); + final String message = "Caught exception while getting VNF package model for: " + vnfPkgId; + throw new EtsiCatalogManagerRequestFailureException(message, restProcessingException); } } @@ -101,9 +99,8 @@ public class EtsiCatalogPackageManagementServiceProviderImpl implements EtsiCata } return Optional.empty(); } catch (final Exception restProcessingException) { - logger.error("Caught exception while getting NS package content for: {}", nsdId, restProcessingException); - throw new EtsiCatalogManagerRequestFailureException("Internal Server Error Occurred.", - restProcessingException); + final String message = "Caught exception while getting NS package content for: " + nsdId; + throw new EtsiCatalogManagerRequestFailureException(message, restProcessingException); } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java index 8c6ea92428..7adf87adf4 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java @@ -69,11 +69,11 @@ import org.springframework.web.client.RestTemplate; @Configuration public class EtsiCatalogServiceProviderConfiguration { - public static final String ETSI_CATALOG_REST_TEMPLATE_BEAN = "etsiCatalogRestTemplate"; + private static final Logger LOGGER = LoggerFactory.getLogger(EtsiCatalogServiceProviderConfiguration.class); public static final String ETSI_CATALOG_SERVICE_PROVIDER_BEAN = "etsiCatalogServiceProvider"; - private final static Logger LOGGER = LoggerFactory.getLogger(EtsiCatalogServiceProviderConfiguration.class); + public static final String ETSI_CATALOG_REST_TEMPLATE_BEAN = "etsiCatalogRestTemplate"; private final HttpClientConnectionConfiguration clientConnectionConfiguration; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogUrlProvider.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogUrlProvider.java index e3c159c7b0..54f6ad6543 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogUrlProvider.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/etsicatalog/EtsiCatalogUrlProvider.java @@ -33,8 +33,6 @@ public class EtsiCatalogUrlProvider { @Value("${etsi-catalog-manager.base.endpoint}") private String etsiCatalogManagerEndpoint; - public EtsiCatalogUrlProvider() {} - public String getNsPackageUrl(final String nsdId) { return etsiCatalogManagerEndpoint + "/nsd/v1/ns_descriptors/" + nsdId; } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/vnfm/Sol003AdapterConfiguration.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/vnfm/Sol003AdapterConfiguration.java index fe710ec00b..6776d8ba0b 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/vnfm/Sol003AdapterConfiguration.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/vnfm/Sol003AdapterConfiguration.java @@ -73,20 +73,20 @@ public class Sol003AdapterConfiguration { @Value("${rest.http.client.configuration.ssl.trustStorePassword:#{null}}") private String trustStorePassword; - @Value("so.adapters.sol003-adapter.auth:Basic dm5mbTpwYXNzd29yZDEk") + @Value("${so.adapters.sol003-adapter.auth:Basic dm5mbTpwYXNzd29yZDEk}") private String sol003AdapterBasicAuth; @Autowired private GsonProvider gsonProvider; - @Autowired - private HttpComponentsClientConfiguration httpComponentsClientConfiguration; - @Bean @Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN) - public RestTemplate sol003AdapterRestTemplate() { + public RestTemplate sol003AdapterRestTemplate( + @Autowired final HttpComponentsClientConfiguration httpComponentsClientConfiguration) { + final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = httpComponentsClientConfiguration.httpComponentsClientHttpRequestFactory(); + final RestTemplate restTemplate = new RestTemplate(new BufferingClientHttpRequestFactory(clientHttpRequestFactory)); restTemplate.getInterceptors().add(new SOSpringClientFilter()); @@ -114,7 +114,7 @@ public class Sol003AdapterConfiguration { final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient); restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(factory)); - } catch (Exception exception) { + } catch (final Exception exception) { logger.error("Error reading truststore, TLS connection to VNFM will fail.", exception); } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/vnfm/Sol003AdapterServiceProviderImpl.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/vnfm/Sol003AdapterServiceProviderImpl.java index a0798f6e55..df3a0c2e31 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/vnfm/Sol003AdapterServiceProviderImpl.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/extclients/vnfm/Sol003AdapterServiceProviderImpl.java @@ -22,6 +22,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterConfiguration.SOL003_ADAPTER_HTTP_REST_SERVICE_PROVIDER_BEAN; import java.util.Optional; +import org.apache.commons.lang3.StringUtils; import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfRequest; import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse; import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.DeleteVnfResponse; @@ -76,7 +77,7 @@ public class Sol003AdapterServiceProviderImpl implements Sol003AdapterServicePro final CreateVnfResponse createVnfResponse = response.getBody(); - if (createVnfResponse.getJobId() == null || createVnfResponse.getJobId().isEmpty()) { + if (StringUtils.isBlank(createVnfResponse.getJobId())) { LOGGER.error("Received invalid instantiation response: {}", response); return Optional.empty(); } @@ -134,7 +135,7 @@ public class Sol003AdapterServiceProviderImpl implements Sol003AdapterServicePro } final DeleteVnfResponse deleteVnfResponse = response.getBody(); - if (deleteVnfResponse.getJobId() == null || deleteVnfResponse.getJobId().isEmpty()) { + if (StringUtils.isBlank(deleteVnfResponse.getJobId())) { LOGGER.error("Received invalid terminate response: {}", response); return Optional.empty(); } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileEntry.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileEntry.java index 58ca2507bd..cfe5b94859 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileEntry.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileEntry.java @@ -22,6 +22,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.util.Arrays; import java.util.Objects; /** @@ -82,7 +83,7 @@ public class FileEntry { @Override public int hashCode() { - return Objects.hash(isDirectory, filePath, fileContent); + return Objects.hash(isDirectory, filePath) + Arrays.hashCode(fileContent); } @Override @@ -90,7 +91,7 @@ public class FileEntry { if (obj instanceof FileEntry) { final FileEntry other = (FileEntry) obj; return Objects.equals(isDirectory, other.isDirectory) && Objects.equals(filePath, other.filePath) - && Objects.equals(fileContent, other.fileContent); + && Arrays.equals(fileContent, other.fileContent); } return false; } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/FileParser.java index 9df5262302..2a37922e9b 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/FileParser.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/FileParser.java @@ -17,9 +17,10 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; import java.util.Map; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; /** * @author Waqas Ikram (waqas.ikram@est.tech) diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParser.java index 33737f4c17..cc92234750 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParser.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParser.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -31,6 +31,10 @@ import java.util.Optional; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import org.apache.commons.io.IOUtils; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.ToscaMetadata; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.VirtualNetworkFunction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -79,7 +83,7 @@ public class NetworkServiceDescriptorParser { final Map<String, Object> nodeTemplates = getNodeTemplates(topologyTemplates); final Optional<NetworkServiceDescriptor> nsdOptional = - getNetworkServiceDescriptor(topologyTemplates);; + getNetworkServiceDescriptor(topologyTemplates); if (nsdOptional.isPresent()) { final NetworkServiceDescriptor networkServiceDescriptor = nsdOptional.get(); networkServiceDescriptor.setVnfs(getVirtualNetworkFunctions(nodeTemplates)); @@ -91,10 +95,10 @@ public class NetworkServiceDescriptorParser { } + logger.error("Unable to find {} file in {}", TOSCA_META_PATH_FILE_NAME, files); } catch (final Exception exception) { - logger.error("Unable to parser nsd zip content", exception); + logger.error("Unable to parse nsd zip content", exception); } - logger.error("Unable to parser nsd zip content"); return Optional.empty(); } @@ -104,7 +108,7 @@ public class NetworkServiceDescriptorParser { final Map<String, Object> substitutionMappings = (Map<String, Object>) topologyTemplates.get(SUBSTITUTION_MAPPINGS); final Object nodeType = substitutionMappings.get(NODE_TYPE); - if (substitutionMappings != null && nodeType != null && NS_NODE_TYPE.equals(nodeType)) { + if (substitutionMappings != null && NS_NODE_TYPE.equals(nodeType)) { final NetworkServiceDescriptor networkServiceDescriptor = new NetworkServiceDescriptor(); networkServiceDescriptor.setType(nodeType.toString()); networkServiceDescriptor.setProperties((Map<String, Object>) substitutionMappings.get(PROPERTIES)); @@ -191,7 +195,7 @@ public class NetworkServiceDescriptorParser { } return files; } catch (final Exception exception) { - logger.error("Unable to parser nsd zip content", exception); + logger.error("Unable to parse nsd zip content", exception); return Collections.emptyMap(); } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/ToscaMetadataParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/ToscaMetadataParser.java index fe23f5ef8d..746416c8e4 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/ToscaMetadataParser.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/ToscaMetadataParser.java @@ -17,12 +17,15 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.apache.commons.lang3.StringUtils.isNotBlank; import java.util.List; import java.util.Optional; import org.apache.commons.io.IOUtils; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.ToscaMetadata; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @@ -39,7 +42,7 @@ public class ToscaMetadataParser { public Optional<ToscaMetadata> parse(final FileEntry toscaMetaFile) { try { final ToscaMetadata toscaMetadata = new ToscaMetadata(); - final List<String> lines = IOUtils.readLines(toscaMetaFile.getFileContentAsStream(), "utf-8"); + final List<String> lines = IOUtils.readLines(toscaMetaFile.getFileContentAsStream(), UTF_8); for (final String line : lines) { final String trimmedLine = line.trim(); if (!trimmedLine.isEmpty() && trimmedLine.contains(ATTRIBUTE_VALUE_SEPARATOR)) { diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/YamlFileParser.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/YamlFileParser.java index ac8f782a99..eab6974252 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/YamlFileParser.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/YamlFileParser.java @@ -17,9 +17,10 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; import java.util.Map; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; import org.springframework.stereotype.Service; import org.yaml.snakeyaml.Yaml; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java index 31e3011c0e..49118494cf 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/JobExecutorService.java @@ -28,8 +28,10 @@ import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstan import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.SERVICE_TYPE_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.TERMINATE_NS_REQUEST_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.CREATE_NS_WORKFLOW_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.DELETE_NS_WORKFLOW_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.INSTANTIATE_NS_WORKFLOW_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.TERMINATE_NS_WORKFLOW_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction.DELETE; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction.INSTANTIATE; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction.TERMINATE; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.ERROR; @@ -162,7 +164,7 @@ public class JobExecutorService { final LocalDateTime currentDateTime = LocalDateTime.now(); final NsLcmOpOcc newNsLcmOpOcc = new NsLcmOpOcc().id(nsInstanceId).operation(NsLcmOpType.INSTANTIATE) .operationState(OperationStateEnum.PROCESSING).stateEnteredTime(currentDateTime) - .startTime(currentDateTime).nfvoNsInst(getNfvoNsInst(nsInstanceId)).isAutoInnovation(false) + .startTime(currentDateTime).nfvoNsInst(getNfvoNsInst(nsInstanceId)).isAutoInvocation(false) .isCancelPending(false).operationParams(gson.toJson(instantiateNsRequest)); databaseServiceProvider.addNSLcmOpOcc(newNsLcmOpOcc); logger.info("New NSLcmOpOcc created in database :\n{}", newNsLcmOpOcc); @@ -207,7 +209,7 @@ public class JobExecutorService { final LocalDateTime currentDateTime = LocalDateTime.now(); final NsLcmOpOcc nsLcmOpOcc = new NsLcmOpOcc().id(nsInstanceId).operation(NsLcmOpType.TERMINATE) .operationState(OperationStateEnum.PROCESSING).stateEnteredTime(currentDateTime) - .startTime(currentDateTime).nfvoNsInst(getNfvoNsInst(nsInstanceId)).isAutoInnovation(false) + .startTime(currentDateTime).nfvoNsInst(getNfvoNsInst(nsInstanceId)).isAutoInvocation(false) .isCancelPending(false).operationParams(gson.toJson(terminateNsRequest)); databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc); logger.info("New NSLcmOpOcc created in database :\n{}", nsLcmOpOcc); @@ -240,6 +242,46 @@ public class JobExecutorService { throw new NsRequestProcessingException(message); } + public void runDeleteNsJob(final String nsInstanceId) { + final NfvoJob nfvoJob = new NfvoJob().startTime(LocalDateTime.now()).jobType("NS").jobAction(DELETE) + .resourceId(nsInstanceId).status(STARTING).progress(0); + databaseServiceProvider.addJob(nfvoJob); + logger.info("New job created in database :\n{}", nfvoJob); + + workflowExecutorService.executeWorkflow(nfvoJob.getJobId(), DELETE_NS_WORKFLOW_NAME, + getVariables(nsInstanceId, nfvoJob.getJobId())); + + final ImmutablePair<String, JobStatusEnum> immutablePair = + waitForJobToFinish(nfvoJob.getJobId(), JOB_FINISHED_STATES); + + if (immutablePair.getRight() == null) { + final String message = "Failed to Delete NS with id: " + nsInstanceId; + logger.error(message); + throw new NsRequestProcessingException(message); + } + + final JobStatusEnum finalJobStatus = immutablePair.getRight(); + final String processInstanceId = immutablePair.getLeft(); + + if (FINISHED.equals(finalJobStatus)) { + logger.info("Delete Job status: {}", finalJobStatus); + return; + } + + final Optional<InlineResponse400> optional = workflowQueryService.getProblemDetails(processInstanceId); + if (optional.isPresent()) { + final InlineResponse400 problemDetails = optional.get(); + final String message = "Failed to Delete NS with id: " + nsInstanceId + " due to:\n" + problemDetails; + logger.error(message); + throw new NsRequestProcessingException(message, problemDetails); + } + + final String message = + "Received unexpected Job Status: " + finalJobStatus + " Failed to Delete NS with id: " + nsInstanceId; + logger.error(message); + throw new NsRequestProcessingException(message); + } + private void doInitialTerminateChecks(final String nsInstanceId, final TerminateNsRequest terminateNsRequest) { if (isNotImmediateTerminateRequest(terminateNsRequest)) { final String message = "TerminateNsRequest received with terminateTime: " @@ -347,4 +389,11 @@ public class JobExecutorService { variables.put(TERMINATE_NS_REQUEST_PARAM_NAME, terminateNsRequest); return variables; } + + private Map<String, Object> getVariables(final String nsInstanceId, final String jobId) { + final Map<String, Object> variables = new HashMap<>(); + variables.put(NS_INSTANCE_ID_PARAM_NAME, nsInstanceId); + variables.put(JOB_ID_PARAM_NAME, jobId); + return variables; + } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/WorkflowQueryService.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/WorkflowQueryService.java index 297e9c34af..a6180b0e52 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/WorkflowQueryService.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/service/WorkflowQueryService.java @@ -20,7 +20,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.TENANT_ID; import static org.slf4j.LoggerFactory.getLogger; import java.util.Optional; @@ -83,7 +83,7 @@ public class WorkflowQueryService { public Optional<InlineResponse400> getProblemDetails(final String processInstanceId) { try { final HistoricVariableInstance historicVariableInstance = - getVariable(processInstanceId, CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + getVariable(processInstanceId, NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); logger.info("Found HistoricVariableInstance : {}", historicVariableInstance); final Object variableValue = historicVariableInstance.getValue(); @@ -94,7 +94,7 @@ public class WorkflowQueryService { historicVariableInstance.getValue() != null ? variableValue.getClass() : null, variableValue); } catch (final ProcessEngineException processEngineException) { logger.error("Unable to find {} variable using processInstanceId: {}", - CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, processInstanceId, processEngineException); + NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, processInstanceId, processEngineException); } return Optional.empty(); } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/AbstractNetworkServiceTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/AbstractNetworkServiceTask.java index e6905b86fc..e94b3de81e 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/AbstractNetworkServiceTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/AbstractNetworkServiceTask.java @@ -19,7 +19,7 @@ */ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.JOB_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OCC_ID_PARAM_NAME; @@ -33,6 +33,7 @@ import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; import org.slf4j.Logger; @@ -47,10 +48,20 @@ public abstract class AbstractNetworkServiceTask { private final Logger logger = LoggerFactory.getLogger(getClass()); protected final DatabaseServiceProvider databaseServiceProvider; - public AbstractNetworkServiceTask(final DatabaseServiceProvider jobServiceProvider) { + protected AbstractNetworkServiceTask(final DatabaseServiceProvider jobServiceProvider) { this.databaseServiceProvider = jobServiceProvider; } + public void addJobStatus(final DelegateExecution execution, final JobStatusEnum jobStatus, + final String description) { + final NfvoJobStatus nfvoJobStatus = + new NfvoJobStatus().status(jobStatus).description(description).updatedTime(LocalDateTime.now()); + logger.info("Adding NfvoJobStatus {}", nfvoJobStatus); + final NfvoJob nfvoJob = getNfvoJob(execution); + nfvoJob.nfvoJobStatus(nfvoJobStatus); + databaseServiceProvider.addJob(nfvoJob); + } + public void setJobStatus(final DelegateExecution execution, final JobStatusEnum jobStatus, final String description) { logger.info("Setting Job Status to {}", jobStatus); @@ -77,7 +88,7 @@ public abstract class AbstractNetworkServiceTask { final Optional<NfvoJob> optional = databaseServiceProvider.getJob(jobId); if (optional.isPresent()) { final InlineResponse400 problemDetails = - (InlineResponse400) execution.getVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + (InlineResponse400) execution.getVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); final NfvoJob nfvoJob = optional.get(); nfvoJob.status(JobStatusEnum.ERROR).endTime(LocalDateTime.now()); @@ -146,7 +157,7 @@ public abstract class AbstractNetworkServiceTask { protected void abortOperation(final DelegateExecution execution, final String message, final InlineResponse400 problemDetails) { logger.error(message); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, problemDetails); + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, problemDetails); throw new BpmnError("WORKFLOW_FAILED"); } @@ -156,14 +167,20 @@ public abstract class AbstractNetworkServiceTask { if (optional.isEmpty()) { final String message = "Unable to find job using job id: " + jobId; logger.error(message); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, - new InlineResponse400().detail(message)); + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().detail(message)); throw new BpmnError("WORKFLOW_FAILED"); } return optional.get(); } + protected void updateNsInstanceStatus(final DelegateExecution execution, final State nsStatus) { + final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution); + logger.info("Updating NfvoNsInst Status to {} and saving to DB", nsStatus); + nfvoNsInst.setStatus(nsStatus); + databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); + } + protected NfvoNsInst getNfvoNsInst(final DelegateExecution execution) { final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); return getNfvoNsInst(execution, nsInstId); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java index 251e694219..600792acc0 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java @@ -47,6 +47,7 @@ import org.springframework.stereotype.Component; */ @Component public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { + private static final String CREATE_INSTANTIATE_REQUEST_PARAM_NAME = "request"; private static final Logger logger = LoggerFactory.getLogger(CreateInstantiateVnfTask.class); private static final String NF_INST_ID_PARAM_NAME = "NF_INST_ID"; public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse"; @@ -64,10 +65,11 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { public void checkIfNfInstanceExistsInDb(final DelegateExecution execution) { logger.info("Executing checkIfNfInstanceInDb"); - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); logger.info("request: {}", request); - setJobStatus(execution, JobStatusEnum.IN_PROGRESS, "Checking if NF Instance record exists in database for " + addJobStatus(execution, JobStatusEnum.IN_PROGRESS, "Checking if NF Instance record exists in database for " + request.getNsInstId() + " and " + request.getVnfName()); if (!databaseServiceProvider.isNsInstExists(request.getNsInstId(), request.getVnfName())) { abortOperation(execution, @@ -79,10 +81,11 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { public void createNfInstanceInDb(final DelegateExecution execution) { logger.info("Executing createNfInstanceInDb"); - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); logger.info("request: {}", request); - setJobStatus(execution, IN_PROGRESS, "Creating NF Instance record in database for " + request.getVnfName()); + addJobStatus(execution, IN_PROGRESS, "Creating NF Instance record in database for " + request.getVnfName()); final Optional<NfvoNsInst> optional = databaseServiceProvider.getNfvoNsInst(request.getNsInstId()); @@ -104,9 +107,10 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { public void createGenericVnfInAai(final DelegateExecution execution) { logger.info("Executing createGenericVnfInAai"); try { - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); - setJobStatus(execution, IN_PROGRESS, "Creating GenericVnf record in AAI for " + request.getVnfName()); + addJobStatus(execution, IN_PROGRESS, "Creating GenericVnf record in AAI for " + request.getVnfName()); final String nfInstId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME); final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); @@ -140,17 +144,16 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { logger.info("Executing invokeCreateInstantiationRequest"); try { - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); logger.info("request: {}", request); - setJobStatus(execution, IN_PROGRESS, + addJobStatus(execution, IN_PROGRESS, "Invoking SOL003 adapter for creating and instantiating VNF: " + request.getVnfName()); - final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); - final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId); final CreateVnfRequest vnfRequest = new CreateVnfRequest(); vnfRequest.setTenant(request.getTenant()); - vnfRequest.setName(nfvoNsInst.getName() + "." + request.getVnfName()); + vnfRequest.setName(request.getVnfName()); vnfRequest.setPkgId(request.getVnfPkgId()); vnfRequest.setAdditionalParams(request.getAdditionalParams()); final String vnfId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME); @@ -167,7 +170,7 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { logger.info("Vnf instantiation response: {}", vnfResponse); execution.setVariable(CREATE_VNF_RESPONSE_PARAM_NAME, vnfResponse); - setJobStatus(execution, IN_PROGRESS, "Successfully invoked SOL003 adapater creating and instantiating VNF: " + addJobStatus(execution, IN_PROGRESS, "Successfully invoked SOL003 adapater creating and instantiating VNF: " + request.getVnfName() + " CreaetVnfResponse Job Id: " + vnfResponse.getJobId()); logger.debug("Finished executing invokeCreateInstantiationRequest ..."); } catch (final Exception exception) { @@ -182,8 +185,9 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { logger.info("Executing updateNfInstanceStatusToInstantiated"); updateNfInstanceStatus(execution, State.INSTANTIATED); - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); - setJobStatus(execution, FINISHED, "Successfully created and Instantiated VNF: " + request.getVnfName() + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); + addJobStatus(execution, FINISHED, "Successfully created and Instantiated VNF: " + request.getVnfName() + " will set status to " + State.INSTANTIATED); logger.info("Finished executing updateNfInstanceStatusToInstantiated ..."); @@ -194,8 +198,9 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { logger.info("Executing updateNfInstanceStatusToActive"); updateNfInstanceStatus(execution, State.FAILED); - final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); - setJobStatus(execution, ERROR, "Failed to create and instantiate VNF: " + request.getVnfName() + final CreateInstantiateRequest request = + (CreateInstantiateRequest) execution.getVariable(CREATE_INSTANTIATE_REQUEST_PARAM_NAME); + addJobStatus(execution, ERROR, "Failed to create and instantiate VNF: " + request.getVnfName() + " will set status to " + State.FAILED); logger.info("Finished executing updateNfInstanceStatusToInstantiated ..."); @@ -204,14 +209,11 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { private void updateNfInstanceStatus(final DelegateExecution execution, final State vnfStatus) { final String nfInstId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME); - final Optional<NfvoNfInst> optional = databaseServiceProvider.getNfvoNfInst(nfInstId); - if (!optional.isPresent()) { + if (optional.isEmpty()) { final String message = "Unable to find NfvoNfInst record in database using nfInstId: " + nfInstId; logger.error(message); - abortOperation(execution, message); - } final NfvoNfInst nfvoNfInst = optional.get(); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateNsTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateNsTask.java index fa7187b388..2cf68bee14 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateNsTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateNsTask.java @@ -21,7 +21,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_REQUEST_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.GLOBAL_CUSTOMER_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_PACKAGE_MODEL_PARAM_NAME; @@ -102,7 +102,7 @@ public class CreateNsTask extends AbstractNetworkServiceTask { final String message = "Unable to find NS package using NsdId: " + createNsRequest.getNsdId(); logger.error(message); execution.setVariable(DOES_NS_PACKAGE_EXISTS_PARAM_NAME, false); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().detail(message)); } @@ -113,7 +113,7 @@ public class CreateNsTask extends AbstractNetworkServiceTask { execution.setVariable(DOES_NS_PACKAGE_EXISTS_PARAM_NAME, false); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().title(message).detail(message)); } @@ -135,7 +135,7 @@ public class CreateNsTask extends AbstractNetworkServiceTask { final Optional<NfvoNsInst> optional = databaseServiceProvider.getNfvoNsInstByName(createNsRequest.getNsName()); final NfvoNsInst nfvoNsInst = optional.get(); - execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400() + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400() .detail("Ns Instance already exists in database : " + nfvoNsInst.toString())); } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/DeleteNsTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/DeleteNsTask.java new file mode 100644 index 0000000000..cd711fb3e8 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/DeleteNsTask.java @@ -0,0 +1,140 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.etsi.nfvo.ns.lcm.bpmn.flows.tasks; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import java.util.Optional; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.FINISHED; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.IN_PROGRESS; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.STARTED; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.State.NOT_INSTANTIATED; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +@Component +public class DeleteNsTask extends AbstractNetworkServiceTask { + + private static final String NS_INSTANCE_EXISTS_PARAM_NAME = "nsInstanceExists"; + private static final String NS_INSTANCE_IS_IN_NOT_INSTANTIATED_STATE_PARAM_NAME = "isInNotInstantiatedState"; + private static final Logger logger = LoggerFactory.getLogger(DeleteNsTask.class); + private final AaiServiceProvider aaiServiceProvider; + + @Autowired + public DeleteNsTask(final DatabaseServiceProvider databaseServiceProvider, + final AaiServiceProvider aaiServiceProvider) { + super(databaseServiceProvider); + this.aaiServiceProvider = aaiServiceProvider; + } + + public void setJobStatusToStarted(final DelegateExecution execution) { + setJobStatus(execution, STARTED, "Delete NS workflow process started"); + } + + public void setJobStatusToFinished(final DelegateExecution execution) { + setJobStatus(execution, FINISHED, "Delete NS workflow process finished"); + } + + public void setJobStatusInProgress(final DelegateExecution execution, final String message) { + setJobStatus(execution, IN_PROGRESS, message); + } + + public void setJobStatusToError(final DelegateExecution execution) { + setJobStatusToError(execution, "Delete NS workflow process failed"); + } + + public void checkIfNsInstanceExistsInDb(final DelegateExecution execution) { + logger.info("Executing checkIfNsInstanceExistsInDb ..."); + setJobStatusInProgress(execution, "Checking that NS Instance Exists in DB"); + + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstId); + final boolean nsInstanceExists = optionalNfvoNsInst.isPresent(); + logger.info("NS Instance entry with id: {} {} exist in database", nsInstId, + nsInstanceExists ? "does" : "doesn't"); + execution.setVariable(NS_INSTANCE_EXISTS_PARAM_NAME, nsInstanceExists); + + if (!nsInstanceExists) { + final String message = + "NS Instance with id: " + nsInstId + " does not exist in database, so will not be deleted."; + logger.info(message); + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().detail(message)); + } + + logger.info("Finished executing checkIfNsInstanceExistsInDb ..."); + } + + public void checkthatNsInstanceInDbIsInNotInstantiatedState(final DelegateExecution execution) { + logger.info("Executing checkthatNsInstanceInDbIsInNotInstantiatedState ..."); + setJobStatusInProgress(execution, "Checking that NS Instance is in NOT_INSTANTIATED state in Db"); + + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId); + final State nfvoNsInstState = nfvoNsInst.getStatus(); + final boolean nsInstanceIsNotInstantiated = NOT_INSTANTIATED.equals(nfvoNsInstState); + logger.info("Ns Instance entry with nsInstId: {} is in state: {}", nsInstId, nfvoNsInstState); + execution.setVariable(NS_INSTANCE_IS_IN_NOT_INSTANTIATED_STATE_PARAM_NAME, nsInstanceIsNotInstantiated); + + if (!nsInstanceIsNotInstantiated) { + final String message = + "Cannot Delete NS Instance with id: " + nsInstId + " in the state: " + nfvoNsInstState; + logger.info(message); + execution.setVariable(NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400().detail(message)); + } + + logger.info("Finished executing checkthatNsInstanceInDbIsInNotInstantiatedState ..."); + } + + public void deleteNsInstanceFromAai(final DelegateExecution execution) { + logger.info("Executing deleteNsInstanceFromAAI ..."); + setJobStatusInProgress(execution, "Deleting NS Instance from AAI"); + + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId); + final String globalCustomerId = nfvoNsInst.getGlobalCustomerId(); + final String serviceType = nfvoNsInst.getServiceType(); + + aaiServiceProvider.deleteServiceInstance(globalCustomerId, serviceType, nsInstId); + + logger.info("Finished executing deleteNsInstanceFromAAI ..."); + } + + public void deleteNsInstanceFromDb(final DelegateExecution execution) { + logger.info("Executing deleteNsInstanceFromDb ..."); + setJobStatusInProgress(execution, "Deleting NS Instance from Db"); + + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + databaseServiceProvider.deleteNfvoNsInst(nsInstId); + + logger.info("Finished executing deleteNsInstanceFromDb ..."); + } +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java index 6774fad543..a6d35e301e 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/InstantiateNsTask.java @@ -22,17 +22,16 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.INSTANTIATE_NS_REQUEST_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OCC_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.VNF_CREATE_INSTANTIATE_REQUESTS; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.FINISHED; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.IN_PROGRESS; import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.STARTED; import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import org.apache.commons.lang.StringUtils; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.Tenant; import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo; @@ -43,8 +42,6 @@ import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.VirtualNetworkFunction; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest; @@ -144,7 +141,7 @@ public class InstantiateNsTask extends AbstractNetworkServiceTask { final Optional<NetworkServiceDescriptor> optional = etsiCatalogPackageManagementServiceProvider.getNetworkServiceDescriptor(nsPackageId); - if (!optional.isPresent()) { + if (optional.isEmpty()) { final String message = "Unable to parse NSD " + nsPackageId; logger.error(message); abortOperation(execution, message); @@ -172,6 +169,7 @@ public class InstantiateNsTask extends AbstractNetworkServiceTask { final NetworkServiceDescriptor networkServiceDescriptor = (NetworkServiceDescriptor) execution.getVariable(NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME); final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId); final InstantiateNsRequest instantiateNsRequest = (InstantiateNsRequest) execution.getVariable(INSTANTIATE_NS_REQUEST_PARAM_NAME); @@ -195,17 +193,36 @@ public class InstantiateNsTask extends AbstractNetworkServiceTask { abortOperation(execution, message); } - final Optional<Tenant> optional = getTenant(vnfPkgId, additionalParamsForVnfList); - if (!optional.isPresent()) { + final Optional<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> additionalParamsForVnfOptional = + getAdditionalParamsForVnf(vnfdId, additionalParamsForVnfList); + + if (additionalParamsForVnfOptional.isEmpty()) { + final String message = "Unable to find AdditionalParamsForVnf for " + vnfdId + + " in instantiateNsRequest : " + instantiateNsRequest; + abortOperation(execution, message); + } + + final NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf additionalParamsForVnf = + additionalParamsForVnfOptional.get(); + + @SuppressWarnings("unchecked") + final Map<String, String> additionalParams = + (Map<String, String>) additionalParamsForVnf.getAdditionalParams(); + + final Optional<Tenant> optional = getTenant(additionalParams); + if (optional.isEmpty()) { final String message = "Unable to find Tenant information for " + vnfdId + " in instantiateNsRequest : " + instantiateNsRequest; abortOperation(execution, message); } - final Tenant tenant = optional.get(); - final CreateInstantiateRequest createInstantiateRequest = new CreateInstantiateRequest().nsInstId(nsInstId) - .vnfdId(vnfdId).vnfName(vnf.getVnfName()).vnfPkgId(vnfPkgId).nfType(vnfmInfoList.get(0)) - .tenant(tenant).additionalParams(getAdditionalParams(vnfPkgId, additionalParamsForVnfList)); + final String vnfInstanceName = additionalParamsForVnf.getVnfInstanceName(); + final String vnfName = StringUtils.isNotBlank(vnfInstanceName) ? vnfInstanceName + : nfvoNsInst.getName() + "." + vnf.getVnfName(); + + final CreateInstantiateRequest createInstantiateRequest = + new CreateInstantiateRequest().nsInstId(nsInstId).vnfdId(vnfdId).vnfName(vnfName).vnfPkgId(vnfPkgId) + .nfType(vnfmInfoList.get(0)).tenant(optional.get()).additionalParams(additionalParams); logger.info("Adding request to list: {}", createInstantiateRequest); requests.add(createInstantiateRequest); @@ -223,17 +240,25 @@ public class InstantiateNsTask extends AbstractNetworkServiceTask { final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId); - final String nsPackageId = nfvoNsInst.getNsPackageId(); - final NsdInfo nsdInfo = getNsdInfo(execution, nsPackageId); final Map<String, String> vnfdIdToVnfPkgIdMapping = new HashMap<>(); try { + final Optional<NsdInfo> nsdInfoOptional = + etsiCatalogPackageManagementServiceProvider.getNSPackageModel(nsPackageId); + + if (nsdInfoOptional.isEmpty()) { + final String message = "Unable to find NS package using NS package id: " + nsPackageId; + logger.error(message); + abortOperation(execution, message); + } + + final NsdInfo nsdInfo = nsdInfoOptional.get(); for (final String vnfPkgId : nsdInfo.getVnfPkgIds()) { final Optional<VnfPkgInfo> optional = etsiCatalogPackageManagementServiceProvider.getVnfPkgInfo(vnfPkgId); - if (!optional.isPresent()) { + if (optional.isEmpty()) { final String message = "Unable to find VNF package using NS vnfPkgId: " + vnfPkgId; logger.error(message); abortOperation(execution, message); @@ -273,83 +298,31 @@ public class InstantiateNsTask extends AbstractNetworkServiceTask { setJobStatusToError(execution, "Instantiate NS workflow process failed"); } - private NsdInfo getNsdInfo(final DelegateExecution execution, final String nsPackageId) { - try { - final Optional<NsdInfo> optional = - etsiCatalogPackageManagementServiceProvider.getNSPackageModel(nsPackageId); - - if (optional.isPresent()) { - final NsdInfo packageModel = optional.get(); - logger.info("NS Package exists {}", packageModel); - return packageModel; + private Optional<Tenant> getTenant(final Map<String, String> additionalParams) { + final String vimId = additionalParams.get("vim_id"); + if (vimId != null) { + final String[] splitString = vimId.split("_"); + if (splitString.length == 3) { + logger.info("Found Tenant in additionalParams: {}", additionalParams); + return Optional.of( + new Tenant().cloudOwner(splitString[0]).regionName(splitString[1]).tenantId(splitString[2])); } - } catch (final EtsiCatalogManagerRequestFailureException failureException) { - final String message = - "Unexpected exception occured while getting ns package using nsPackageId: " + nsPackageId; - logger.error(message, failureException); - - abortOperation(execution, message); } - - final String message = "Unable to find NS package using NS package id: " + nsPackageId; - logger.error(message); - abortOperation(execution, message); - return null; - - } - - private void updateNsInstanceStatus(final DelegateExecution execution, final State nsStatus) { - final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution); - logger.info("Updating NfvoNsInst Status to {} and saving to DB", nsStatus); - nfvoNsInst.setStatus(nsStatus); - databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); - } - - private Optional<Tenant> getTenant(final String vnfPkgId, - final List<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> additionalParamsForVnfList) { - - final Optional<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> optional = additionalParamsForVnfList - .stream().filter(entry -> vnfPkgId.equals(entry.getVnfProfileId())).findFirst(); - - if (optional.isPresent()) { - final NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf additionalParamsForVnf = optional.get(); - @SuppressWarnings("unchecked") - final Map<String, Object> additionalParams = - (Map<String, Object>) additionalParamsForVnf.getAdditionalParams(); - final String vimId = (String) additionalParams.get("vim_id"); - if (vimId != null) { - final String[] splitString = vimId.split("_"); - if (splitString.length == 3) { - logger.info("Found Tenant in instantiateNsRequest using vnfPkgId: {}", vnfPkgId); - return Optional.of(new Tenant().cloudOwner(splitString[0]).regionName(splitString[1]) - .tenantId(splitString[2])); - } - - } - } - - logger.error("Unable to find Tenant in instantiateNsRequest using vnfPkgId: {}", vnfPkgId); + logger.error("Unable to find Tenant in additionalParams: {}", additionalParams); return Optional.empty(); } - @SuppressWarnings("unchecked") - private Map<String, String> getAdditionalParams(final String vnfPkgId, + private Optional<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> getAdditionalParamsForVnf( + final String vnfdId, final List<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> additionalParamsForVnfList) { - - final Optional<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> optional = additionalParamsForVnfList - .stream().filter(entry -> vnfPkgId.equals(entry.getVnfProfileId())).findFirst(); - + final Optional<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> optional = + additionalParamsForVnfList.stream().filter(entry -> vnfdId.equals(entry.getVnfProfileId())).findFirst(); if (optional.isPresent()) { - final NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf additionalParamsForVnf = optional.get(); - if (additionalParamsForVnf instanceof Map) { - logger.info("Found AdditionalParams in instantiateNsRequest using vnfPkgId: {}", vnfPkgId); - return (Map<String, String>) additionalParamsForVnf.getAdditionalParams(); - } - } - - return Collections.emptyMap(); + logger.info("Found AdditionalParamsForVnf in instantiateNsRequest using vnfdId: {}", vnfdId); + } + return optional; } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/MonitorSol003AdapterNodeTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/MonitorSol003AdapterNodeTask.java index e4dc3d5e07..001c369801 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/MonitorSol003AdapterNodeTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/MonitorSol003AdapterNodeTask.java @@ -37,7 +37,7 @@ public abstract class MonitorSol003AdapterNodeTask extends AbstractNetworkServic private static final Logger LOGGER = LoggerFactory.getLogger(MonitorSol003AdapterNodeTask.class); private final AaiServiceProvider aaiServiceProvider; - public MonitorSol003AdapterNodeTask(final DatabaseServiceProvider databaseServiceProvider, + protected MonitorSol003AdapterNodeTask(final DatabaseServiceProvider databaseServiceProvider, final AaiServiceProvider aaiServiceProvider) { super(databaseServiceProvider); this.aaiServiceProvider = aaiServiceProvider; @@ -56,7 +56,7 @@ public abstract class MonitorSol003AdapterNodeTask extends AbstractNetworkServic LOGGER.debug("Query A&AI for generic VNF using vnfID: {}", vnfId); final Optional<GenericVnf> aaiGenericVnfOptional = aaiServiceProvider.getGenericVnf(vnfId); - if (!aaiGenericVnfOptional.isPresent()) { + if (aaiGenericVnfOptional.isEmpty()) { abortOperation(execution, "Unable to find generic vnf in A&AI using vnfId" + vnfId); } final GenericVnf genericVnf = aaiGenericVnfOptional.get(); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateNsTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateNsTask.java index 972e4d6de8..c0d1df8c50 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateNsTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateNsTask.java @@ -22,7 +22,6 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; import org.slf4j.Logger; @@ -110,34 +109,24 @@ public class TerminateNsTask extends AbstractNetworkServiceTask { final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); final List<NfvoNfInst> nfInstances = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInstId); if (nfInstances != null) { - nfInstances.stream().forEach(instance -> { - logger.info("Current status {} of vnf: {}", instance.getStatus(), instance.getName()); - }); + nfInstances.stream().forEach( + instance -> logger.info("Current status {} of vnf: {}", instance.getStatus(), instance.getName())); } } - private void updateNsInstanceStatus(final DelegateExecution execution, final State nsStatus) { - final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution); - logger.info("Updating NfvoNsInst Status to {} and saving to DB", nsStatus); - nfvoNsInst.setStatus(nsStatus); - databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); - } - private List<String> getNfvoNfInstIds(final DelegateExecution execution) { final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); logger.info("Getting NfvoNfInstList using nsInstId: {}", nsInstId); final List<NfvoNfInst> nfvoNfInstList = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInstId); - if (nfvoNfInstList.size() == 0) { + if (nfvoNfInstList == null || nfvoNfInstList.isEmpty()) { final String message = "Unable to find NF Instances in database using id: " + nsInstId; abortOperation(execution, message); } final List<String> vnfIdsList = new ArrayList<>(); - nfvoNfInstList.stream().forEach(nfvoNfInst -> { - vnfIdsList.add(nfvoNfInst.getNfInstId()); - }); + nfvoNfInstList.stream().forEach(nfvoNfInst -> vnfIdsList.add(nfvoNfInst.getNfInstId())); return vnfIdsList; } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateVnfTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateVnfTask.java index 15eee22dd2..049a6f38b0 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateVnfTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateVnfTask.java @@ -19,6 +19,13 @@ */ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.DELETE_VNF_RESPONSE_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NF_INST_ID_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.TERMINATE_VNF_VNFID_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.ERROR; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.FINISHED; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.IN_PROGRESS; +import java.util.Optional; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.DeleteVnfResponse; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider; @@ -31,13 +38,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import java.util.Optional; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NF_INST_ID_PARAM_NAME; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.DELETE_VNF_RESPONSE_PARAM_NAME; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.TERMINATE_VNF_VNFID_PARAM_NAME; -import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.ERROR; -import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.FINISHED; -import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum.IN_PROGRESS; /** * @author Andrew Lamb (andrew.a.lamb@est.tech) @@ -63,7 +63,7 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { logger.info("vnfId: {}", vnfId); execution.setVariable(NF_INST_ID_PARAM_NAME, vnfId); - setJobStatus(execution, JobStatusEnum.IN_PROGRESS, + addJobStatus(execution, JobStatusEnum.IN_PROGRESS, "Checking if VNF Instance with id: " + vnfId + " exists in database."); if (!databaseServiceProvider.isNfInstExists(vnfId)) { abortOperation(execution, @@ -78,7 +78,7 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { final String vnfId = (String) execution.getVariable(TERMINATE_VNF_VNFID_PARAM_NAME); try { - setJobStatus(execution, IN_PROGRESS, "Invoking SOL003 adapter for terminating VNF with vnfId: " + vnfId); + addJobStatus(execution, IN_PROGRESS, "Invoking SOL003 adapter for terminating VNF with vnfId: " + vnfId); final Optional<DeleteVnfResponse> optional = sol003AdapterServiceProvider.invokeTerminationRequest(vnfId); @@ -92,7 +92,7 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { logger.info("Vnf delete response: {}", vnfResponse); execution.setVariable(DELETE_VNF_RESPONSE_PARAM_NAME, vnfResponse); - setJobStatus(execution, IN_PROGRESS, "Successfully invoked SOL003 adapter terminate VNF with vnfId: " + addJobStatus(execution, IN_PROGRESS, "Successfully invoked SOL003 adapter terminate VNF with vnfId: " + vnfId + " DeleteVnfResponse Job Id: " + vnfResponse.getJobId()); logger.debug("Finished executing invokeTerminateRequest ..."); } catch (final Exception exception) { @@ -108,7 +108,7 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { final String vnfId = (String) execution.getVariable(TERMINATE_VNF_VNFID_PARAM_NAME); try { - setJobStatus(execution, IN_PROGRESS, "Deleting GenericVnf record from AAI for vnfId: " + vnfId); + addJobStatus(execution, IN_PROGRESS, "Deleting GenericVnf record from AAI for vnfId: " + vnfId); aaiServiceProvider.deleteGenericVnf(vnfId); } catch (final Exception exception) { @@ -124,10 +124,10 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { logger.info("Executing deleteNfInstanceFromDb"); final String vnfId = (String) execution.getVariable(TERMINATE_VNF_VNFID_PARAM_NAME); - setJobStatus(execution, IN_PROGRESS, "Deleting NF Instance record from Database for vnfId: " + vnfId); + addJobStatus(execution, IN_PROGRESS, "Deleting NF Instance record from Database for vnfId: " + vnfId); databaseServiceProvider.deleteNfvoNfInst(vnfId); - setJobStatus(execution, FINISHED, "Successfully finished terminating VNF with vnfId: " + vnfId); + addJobStatus(execution, FINISHED, "Successfully finished terminating VNF with vnfId: " + vnfId); logger.info("Finished executing deleteNfInstanceFromDb ..."); } @@ -136,7 +136,7 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { updateNfInstanceStatus(execution, State.TERMINATING); final String vnfId = (String) execution.getVariable(TERMINATE_VNF_VNFID_PARAM_NAME); - setJobStatus(execution, IN_PROGRESS, + addJobStatus(execution, IN_PROGRESS, "Terminating VNF with vnfId: " + vnfId + " will set status to " + State.TERMINATING); logger.info("Finished executing updateNfInstanceStatusToTerminating ..."); @@ -148,7 +148,7 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { updateNfInstanceStatus(execution, State.NOT_INSTANTIATED); final String vnfId = (String) execution.getVariable(TERMINATE_VNF_VNFID_PARAM_NAME); - setJobStatus(execution, IN_PROGRESS, + addJobStatus(execution, IN_PROGRESS, "Successfully terminated VNF with vnfId: " + vnfId + " will set status to " + State.NOT_INSTANTIATED); logger.info("Finished executing updateNfInstanceStatusToInstantiated ..."); @@ -160,7 +160,7 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { updateNfInstanceStatus(execution, State.FAILED); final String vnfId = (String) execution.getVariable(TERMINATE_VNF_VNFID_PARAM_NAME); - setJobStatus(execution, ERROR, + addJobStatus(execution, ERROR, "Failed to terminate VNF with vnfId: " + vnfId + " will set status to " + State.FAILED); logger.info("Finished executing updateNfInstanceStatusToFailed ..."); @@ -174,9 +174,7 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { if (optional.isEmpty()) { final String message = "Unable to find NfvoNfInst record in database using vnfId: " + vnfId; logger.error(message); - abortOperation(execution, message); - } final NfvoNfInst nfvoNfInst = optional.get(); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/utils/LocalDateTimeTypeAdapter.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/utils/LocalDateTimeTypeAdapter.java index 34959ee0f0..9f21d2b449 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/utils/LocalDateTimeTypeAdapter.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/utils/LocalDateTimeTypeAdapter.java @@ -24,6 +24,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import com.google.gson.TypeAdapter; import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonToken; import com.google.gson.stream.JsonWriter; /** @@ -45,14 +46,14 @@ public class LocalDateTimeTypeAdapter extends TypeAdapter<LocalDateTime> { @Override public LocalDateTime read(final JsonReader in) throws IOException { - switch (in.peek()) { - case NULL: - in.nextNull(); - return null; - default: - final String dateTime = in.nextString(); - return LocalDateTime.parse(dateTime, FORMATTER); + if (JsonToken.NULL == in.peek()) { + in.nextNull(); + return null; + } + final String dateTime = in.nextString(); + return LocalDateTime.parse(dateTime, FORMATTER); + } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn index 815b76c907..4c24f91cf9 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1l4zor5" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.0.0"> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1l4zor5" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0"> <bpmn:process id="CreateNs" name=" CreateNs" isExecutable="true"> <bpmn:startEvent id="StartEvent_1" name="Start Process"> <bpmn:outgoing>Flow_1tqn5q5</bpmn:outgoing> @@ -102,7 +102,7 @@ <bpmn:sequenceFlow id="Flow_1rtsvpm" sourceRef="Activity_03ht66t" targetRef="Activity_1r4l8w8" /> </bpmn:process> <bpmn:error id="Error_0s855yd" name="java.lang.Exception" errorCode="java.lang.Exception" /> - <bpmn:error id="Error_0rqvnym" name="CreateNsProcessingException" errorCode="CREATE_NS_PROCESSING_EXCEPTION" /> + <bpmn:error id="Error_0rqvnym" name="NsWorkflowProcessingException" errorCode="CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION" /> <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CreateNs"> <bpmndi:BPMNEdge id="Flow_1rtsvpm_di" bpmnElement="Flow_1rtsvpm"> diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/DeleteNs.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/DeleteNs.bpmn new file mode 100644 index 0000000000..a6bb214440 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/DeleteNs.bpmn @@ -0,0 +1,260 @@ +<?xml version="1.0" encoding="UTF-8"?> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1l4zor5" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.2.0"> + <bpmn:process id="DeleteNs" name="DeleteNs" isExecutable="true"> + <bpmn:startEvent id="StartEvent_1" name="Start Process"> + <bpmn:outgoing>Flow_1tqn5q5</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:endEvent id="EndEvent_1" name="End Process"> + <bpmn:incoming>Flow_0t87ov3</bpmn:incoming> + </bpmn:endEvent> + <bpmn:sequenceFlow id="Flow_1tqn5q5" sourceRef="StartEvent_1" targetRef="Activity_15ksfz6" /> + <bpmn:serviceTask id="Activity_15ksfz6" name="Set Job Status to STARTED" camunda:asyncBefore="true" camunda:expression="${DeleteNsTask.setJobStatusToStarted(execution)}"> + <bpmn:incoming>Flow_1tqn5q5</bpmn:incoming> + <bpmn:outgoing>Flow_0fhodlp</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:serviceTask id="Activity_1r4l8w8" name="Set Job Status to FINISHED" camunda:expression="${DeleteNsTask.setJobStatusToFinished(execution)}"> + <bpmn:incoming>Flow_1rtsvpm</bpmn:incoming> + <bpmn:outgoing>Flow_0t87ov3</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_0t87ov3" sourceRef="Activity_1r4l8w8" targetRef="EndEvent_1" /> + <bpmn:subProcess id="Activity_06ko4e2" name="Error Handling" triggeredByEvent="true"> + <bpmn:startEvent id="Event_1ibvrn2" name="error"> + <bpmn:outgoing>Flow_0554tjv</bpmn:outgoing> + <bpmn:errorEventDefinition id="ErrorEventDefinition_0lc46mh" /> + </bpmn:startEvent> + <bpmn:endEvent id="Event_02f7sr1" name="end"> + <bpmn:incoming>Flow_04xvpee</bpmn:incoming> + </bpmn:endEvent> + <bpmn:sequenceFlow id="Flow_0554tjv" sourceRef="Event_1ibvrn2" targetRef="Activity_1sj0nvr" /> + <bpmn:serviceTask id="Activity_1sj0nvr" name="Set Job Status to ERROR" camunda:asyncBefore="true" camunda:expression="${DeleteNsTask.setJobStatusToError(execution)}"> + <bpmn:incoming>Flow_0554tjv</bpmn:incoming> + <bpmn:outgoing>Flow_04xvpee</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_04xvpee" sourceRef="Activity_1sj0nvr" targetRef="Event_02f7sr1" /> + </bpmn:subProcess> + <bpmn:subProcess id="Activity_1dx9fz6" name="Java Exception Handling" triggeredByEvent="true"> + <bpmn:startEvent id="Event_0zne7ch" name="error"> + <bpmn:outgoing>Flow_0j1otrx</bpmn:outgoing> + <bpmn:errorEventDefinition id="ErrorEventDefinition_1p3h4ta" errorRef="Error_0rqvnym" camunda:errorCodeVariable="BPMN_javaExpCode" camunda:errorMessageVariable="BPMN_javaExpMsg" /> + </bpmn:startEvent> + <bpmn:endEvent id="Event_0bcyh7u"> + <bpmn:incoming>Flow_0oqv7vl</bpmn:incoming> + </bpmn:endEvent> + <bpmn:sequenceFlow id="Flow_0j1otrx" sourceRef="Event_0zne7ch" targetRef="Activity_15uwy90" /> + <bpmn:serviceTask id="Activity_15uwy90" name="Set Job Status to ERROR" camunda:asyncBefore="true" camunda:expression="${DeleteNsTask.setJobStatusToError(execution)}"> + <bpmn:incoming>Flow_0j1otrx</bpmn:incoming> + <bpmn:outgoing>Flow_0oqv7vl</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_0oqv7vl" sourceRef="Activity_15uwy90" targetRef="Event_0bcyh7u" /> + </bpmn:subProcess> + <bpmn:serviceTask id="Activity_0vlb2nk" name="Check NS Instance exists In DB " camunda:expression="${DeleteNsTask.checkIfNsInstanceExistsInDb(execution)}"> + <bpmn:incoming>Flow_0fhodlp</bpmn:incoming> + <bpmn:outgoing>Flow_1duwqzf</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:serviceTask id="Activity_09tqz8x" name="Check that NS Instance in DB is in NOT_INSTANTIATED state" camunda:expression="${DeleteNsTask.checkthatNsInstanceInDbIsInNotInstantiatedState(execution)}"> + <bpmn:incoming>Flow_02g3nbb</bpmn:incoming> + <bpmn:outgoing>Flow_1ihvsfs</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:serviceTask id="Activity_03ht66t" name="Delete NS Instance from DB" camunda:expression="${DeleteNsTask.deleteNsInstanceFromDb(execution)}"> + <bpmn:incoming>Flow_04wub0a</bpmn:incoming> + <bpmn:outgoing>Flow_1rtsvpm</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_1rtsvpm" sourceRef="Activity_03ht66t" targetRef="Activity_1r4l8w8" /> + <bpmn:sequenceFlow id="Flow_0fhodlp" sourceRef="Activity_15ksfz6" targetRef="Activity_0vlb2nk" /> + <bpmn:sequenceFlow id="Flow_1duwqzf" sourceRef="Activity_0vlb2nk" targetRef="Gateway_1tjajb0" /> + <bpmn:sequenceFlow id="Flow_1ihvsfs" sourceRef="Activity_09tqz8x" targetRef="Gateway_1voek52" /> + <bpmn:serviceTask id="Activity_1rrzri0" name="Delete NS Instance from AAI" camunda:expression="${DeleteNsTask.deleteNsInstanceFromAai(execution)}"> + <bpmn:incoming>Flow_1buncqe</bpmn:incoming> + <bpmn:outgoing>Flow_04wub0a</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_04wub0a" sourceRef="Activity_1rrzri0" targetRef="Activity_03ht66t" /> + <bpmn:exclusiveGateway id="Gateway_1tjajb0" name="Does NS Instance Exist?"> + <bpmn:incoming>Flow_1duwqzf</bpmn:incoming> + <bpmn:outgoing>Flow_02g3nbb</bpmn:outgoing> + <bpmn:outgoing>Flow_1swnlzf</bpmn:outgoing> + </bpmn:exclusiveGateway> + <bpmn:sequenceFlow id="Flow_02g3nbb" name="Yes" sourceRef="Gateway_1tjajb0" targetRef="Activity_09tqz8x"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{nsInstanceExists}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:exclusiveGateway id="Gateway_1voek52" name="Is NS Instance in NOT INSTANTIATED State?"> + <bpmn:incoming>Flow_1ihvsfs</bpmn:incoming> + <bpmn:outgoing>Flow_1buncqe</bpmn:outgoing> + <bpmn:outgoing>Flow_1eozcur</bpmn:outgoing> + </bpmn:exclusiveGateway> + <bpmn:sequenceFlow id="Flow_1buncqe" name="Yes" sourceRef="Gateway_1voek52" targetRef="Activity_1rrzri0"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{isInNotInstantiatedState}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:endEvent id="Event_0dqc93c"> + <bpmn:incoming>Flow_1swnlzf</bpmn:incoming> + <bpmn:incoming>Flow_1eozcur</bpmn:incoming> + <bpmn:errorEventDefinition id="ErrorEventDefinition_0pfrgad" errorRef="Error_0rqvnym" /> + </bpmn:endEvent> + <bpmn:sequenceFlow id="Flow_1swnlzf" name="No" sourceRef="Gateway_1tjajb0" targetRef="Event_0dqc93c"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{not nsInstanceExists}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:sequenceFlow id="Flow_1eozcur" name="No" sourceRef="Gateway_1voek52" targetRef="Event_0dqc93c"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{not isInNotInstantiatedState}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + </bpmn:process> + <bpmn:error id="Error_0s855yd" name="java.lang.Exception" errorCode="java.lang.Exception" /> + <bpmn:error id="Error_0rqvnym" name="NsWorkflowProcessingException" errorCode="DELETE_NS_WORKFLOW_PROCESSING_EXCEPTION" /> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="DeleteNs"> + <bpmndi:BPMNEdge id="Flow_1eozcur_di" bpmnElement="Flow_1eozcur"> + <di:waypoint x="830" y="192" /> + <di:waypoint x="830" y="270" /> + <di:waypoint x="708" y="270" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="843" y="228" width="14" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1swnlzf_di" bpmnElement="Flow_1swnlzf"> + <di:waypoint x="550" y="192" /> + <di:waypoint x="550" y="270" /> + <di:waypoint x="672" y="270" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="558" y="228" width="14" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1buncqe_di" bpmnElement="Flow_1buncqe"> + <di:waypoint x="855" y="167" /> + <di:waypoint x="960" y="167" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="890" y="149" width="19" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_02g3nbb_di" bpmnElement="Flow_02g3nbb"> + <di:waypoint x="575" y="167" /> + <di:waypoint x="640" y="167" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="598" y="149" width="19" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_04wub0a_di" bpmnElement="Flow_04wub0a"> + <di:waypoint x="1060" y="167" /> + <di:waypoint x="1100" y="167" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1ihvsfs_di" bpmnElement="Flow_1ihvsfs"> + <di:waypoint x="740" y="167" /> + <di:waypoint x="805" y="167" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1duwqzf_di" bpmnElement="Flow_1duwqzf"> + <di:waypoint x="490" y="167" /> + <di:waypoint x="525" y="167" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0fhodlp_di" bpmnElement="Flow_0fhodlp"> + <di:waypoint x="350" y="167" /> + <di:waypoint x="390" y="167" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1rtsvpm_di" bpmnElement="Flow_1rtsvpm"> + <di:waypoint x="1200" y="167" /> + <di:waypoint x="1240" y="167" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0t87ov3_di" bpmnElement="Flow_0t87ov3"> + <di:waypoint x="1340" y="167" /> + <di:waypoint x="1382" y="167" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1tqn5q5_di" bpmnElement="Flow_1tqn5q5"> + <di:waypoint x="208" y="167" /> + <di:waypoint x="250" y="167" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="172" y="149" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="158" y="192" width="67" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_0db1w1a_di" bpmnElement="EndEvent_1"> + <dc:Bounds x="1382" y="149" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1369" y="192" width="63" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_15ksfz6_di" bpmnElement="Activity_15ksfz6"> + <dc:Bounds x="250" y="127" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1r4l8w8_di" bpmnElement="Activity_1r4l8w8"> + <dc:Bounds x="1240" y="127" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_06ko4e2_di" bpmnElement="Activity_06ko4e2" isExpanded="true"> + <dc:Bounds x="431" y="360" width="438" height="130" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Flow_04xvpee_di" bpmnElement="Flow_04xvpee"> + <di:waypoint x="681" y="423" /> + <di:waypoint x="813" y="423" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0554tjv_di" bpmnElement="Flow_0554tjv"> + <di:waypoint x="489" y="423" /> + <di:waypoint x="581" y="423" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_1ibvrn2_di" bpmnElement="Event_1ibvrn2"> + <dc:Bounds x="453" y="405" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="459" y="448" width="24" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_02f7sr1_di" bpmnElement="Event_02f7sr1"> + <dc:Bounds x="813" y="405" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="823" y="447" width="19" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1sj0nvr_di" bpmnElement="Activity_1sj0nvr"> + <dc:Bounds x="581" y="383" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1dx9fz6_di" bpmnElement="Activity_1dx9fz6" isExpanded="true"> + <dc:Bounds x="431" y="520" width="438" height="130" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Flow_0oqv7vl_di" bpmnElement="Flow_0oqv7vl"> + <di:waypoint x="680" y="583" /> + <di:waypoint x="772" y="583" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0j1otrx_di" bpmnElement="Flow_0j1otrx"> + <di:waypoint x="522" y="583" /> + <di:waypoint x="580" y="583" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_0zne7ch_di" bpmnElement="Event_0zne7ch"> + <dc:Bounds x="486" y="565" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="493" y="608" width="24" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_0bcyh7u_di" bpmnElement="Event_0bcyh7u"> + <dc:Bounds x="772" y="565" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_15uwy90_di" bpmnElement="Activity_15uwy90"> + <dc:Bounds x="580" y="543" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0vlb2nk_di" bpmnElement="Activity_0vlb2nk"> + <dc:Bounds x="390" y="127" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_09tqz8x_di" bpmnElement="Activity_09tqz8x"> + <dc:Bounds x="640" y="127" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_03ht66t_di" bpmnElement="Activity_03ht66t"> + <dc:Bounds x="1100" y="127" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1rrzri0_di" bpmnElement="Activity_1rrzri0"> + <dc:Bounds x="960" y="127" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Gateway_1tjajb0_di" bpmnElement="Gateway_1tjajb0" isMarkerVisible="true"> + <dc:Bounds x="525" y="142" width="50" height="50" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="505" y="106" width="89" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Gateway_1voek52_di" bpmnElement="Gateway_1voek52" isMarkerVisible="true"> + <dc:Bounds x="805" y="142" width="50" height="50" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="791" y="83" width="79" height="53" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_029a1ih_di" bpmnElement="Event_0dqc93c"> + <dc:Bounds x="672" y="252" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="646" y="245" width="88" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + </bpmndi:BPMNPlane> + </bpmndi:BPMNDiagram> +</bpmn:definitions> diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/InstantiateNs.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/InstantiateNs.bpmn index ba9e641d84..bc34c144c9 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/InstantiateNs.bpmn +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/InstantiateNs.bpmn @@ -133,7 +133,7 @@ </bpmn:serviceTask> <bpmn:sequenceFlow id="Flow_1i36dw4" sourceRef="Activity_0gkpdft" targetRef="Activity_1w09i1k" /> </bpmn:process> - <bpmn:error id="Error_0jsct8p" name="InstantiateNsProcessingException" errorCode="INSTANTIATE_NS_PROCESSING_EXCEPTION" /> + <bpmn:error id="Error_0jsct8p" name="NsWorkflowProcessingException" errorCode="INSTANTIATE_NS_WORKFLOW_PROCESSING_EXCEPTION" /> <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="InstantiateNs"> <bpmndi:BPMNEdge id="Flow_1p21p1m_di" bpmnElement="Flow_1p21p1m"> @@ -328,4 +328,4 @@ </bpmndi:BPMNShape> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> -</bpmn:definitions> +</bpmn:definitions>
\ No newline at end of file diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/TerminateNs.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/TerminateNs.bpmn index 36c52c8ad6..e971f6acf0 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/TerminateNs.bpmn +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/TerminateNs.bpmn @@ -123,7 +123,7 @@ </bpmn:serviceTask> <bpmn:sequenceFlow id="Flow_1i36dw4" sourceRef="Activity_0gkpdft" targetRef="Activity_1w09i1k" /> </bpmn:process> - <bpmn:error id="Error_0jsct8p" name="TerminateNsProcessingException" errorCode="TERMINATE_NS_PROCESSING_EXCEPTION" /> + <bpmn:error id="Error_0jsct8p" name="NsWorkflowProcessingException" errorCode="TERMINATE_NS_WORKFLOW_PROCESSING_EXCEPTION" /> <bpmndi:BPMNDiagram id="BPMNDiagram_1"> <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="TerminateNs"> <bpmndi:BPMNEdge id="Flow_1i36dw4_di" bpmnElement="Flow_1i36dw4"> diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java index 86f2879966..b6fd9e407a 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/BaseTest.java @@ -147,4 +147,9 @@ public abstract class BaseTest { return runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult() == null; } + protected String getAaiServiceInstanceEndPoint() { + return "/aai/v[0-9]+/business/customers/customer/" + GLOBAL_CUSTOMER_ID + + "/service-subscriptions/service-subscription/" + SERVICE_TYPE + + "/service-instances/service-instance/.*"; + } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java new file mode 100644 index 0000000000..edfb20afd2 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/PojoClassesTests.java @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.etsi.nfvo.ns.lcm.bpmn.flows; + +import java.util.Arrays; +import java.util.List; +import org.junit.Test; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.FileEntry; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.ToscaMetadata; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.VirtualNetworkFunction; +import org.onap.so.openpojo.rules.ToStringTester; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class PojoClassesTests { + + @Test + public void test_nsd_parser_pojo_classes() throws ClassNotFoundException { + + final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()) + .with(new ToStringTester()).build(); + validator.validate(FileEntry.class.getPackageName(), new FilterPackageInfo()); + } + + + @Test + public void test_nsd_parser_pojo_classes_equalAndHashMethod() throws ClassNotFoundException { + final List<Class<?>> classes = Arrays.asList(FileEntry.class, NetworkServiceDescriptor.class, + ToscaMetadata.class, VirtualNetworkFunction.class); + for (final Class<?> clazz : classes) { + EqualsVerifier.forClass(clazz).suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, + Warning.INHERITED_DIRECTLY_FROM_OBJECT).verify(); + } + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParserTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParserTest.java index 2bebf1c30a..4a8c715e5c 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/NetworkServiceDescriptorParserTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/nsd/parser/NetworkServiceDescriptorParserTest.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd; +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -31,6 +31,8 @@ import java.util.Optional; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.TestApplication; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.parser.NetworkServiceDescriptorParser; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java index 05213a344f..3686cd620d 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/CreateNsTaskTest.java @@ -234,7 +234,7 @@ public class CreateNsTaskTest extends BaseTest { assertNull(nsResponseVariable); final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue(); assertNotNull(problemDetails); @@ -306,7 +306,7 @@ public class CreateNsTaskTest extends BaseTest { mockEtsiCatalogEndpoints(nsdId); - final String modelEndpoint = getAiaServiceInstancelEndPoint(createNsRequest); + final String modelEndpoint = getAaiServiceInstanceEndPoint(); wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(WireMock.serverError())); wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(WireMock.serverError())); @@ -339,18 +339,12 @@ public class CreateNsTaskTest extends BaseTest { } private void mockAAIEndpoints(final CreateNsRequest createNsRequest) { - final String modelEndpoint = getAiaServiceInstancelEndPoint(createNsRequest); + final String modelEndpoint = getAaiServiceInstanceEndPoint(); wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(ok())); wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(notFound())); } - private String getAiaServiceInstancelEndPoint(final CreateNsRequest createNsRequest) { - return "/aai/v[0-9]+/business/customers/customer/" + GLOBAL_CUSTOMER_ID - + "/service-subscriptions/service-subscription/" + SERVICE_TYPE - + "/service-instances/service-instance/.*"; - } - private void mockEtsiCatalogEndpoints(final String nsdId) { mockRestServiceServer.expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId)) .andExpect(method(HttpMethod.GET)) diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java new file mode 100644 index 0000000000..adb8a9e69b --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/DeleteNsTaskTest.java @@ -0,0 +1,185 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.etsi.nfvo.ns.workflow.engine.tasks; + +import com.google.gson.Gson; +import org.camunda.bpm.engine.history.HistoricProcessInstance; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.NsRequestProcessingException; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.springframework.beans.factory.annotation.Autowired; +import java.time.LocalDateTime; +import java.util.Optional; +import java.util.UUID; +import static com.github.tomakehurst.wiremock.client.WireMock.delete; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.ok; +import static com.github.tomakehurst.wiremock.client.WireMock.okJson; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +public class DeleteNsTaskTest extends BaseTest { + + @Autowired + private JobExecutorService objUnderTest; + + @Autowired + private GsonProvider gsonProvider; + + @Rule + public ExpectedException expectedException = ExpectedException.none(); + + private Gson gson; + + @Before + public void before() { + wireMockServer.resetAll(); + gson = gsonProvider.getGson(); + } + + @After + public void after() { + wireMockServer.resetAll(); + } + + @Test + public void testRunDeleteNsJob_nsInstanceIdNotInDatabase_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + assertTrue(databaseServiceProvider.getNfvoNsInst(nsInstanceId).isEmpty()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_nsInstanceStateInstantiated_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.INSTANTIATED); + + final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.INSTANTIATED, optionalNfvoNsInst.get().getStatus()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_nsInstanceStateInstantiating_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.INSTANTIATING); + + final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.INSTANTIATING, optionalNfvoNsInst.get().getStatus()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_nsInstanceStateTerminating_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.TERMINATING); + + final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.TERMINATING, optionalNfvoNsInst.get().getStatus()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_nsInstanceStateFailed_throwsException() { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.FAILED); + + final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.FAILED, optionalNfvoNsInst.get().getStatus()); + + expectedException.expect(NsRequestProcessingException.class); + objUnderTest.runDeleteNsJob(nsInstanceId); + } + + @Test + public void testRunDeleteNsJob_SuccessfulCase() throws InterruptedException { + final String nsInstanceId = UUID.randomUUID().toString(); + addDummyNsToDatabase(nsInstanceId, State.NOT_INSTANTIATED); + mockAaiEndpoints(); + + final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInst.isPresent()); + assertEquals(State.NOT_INSTANTIATED, optionalNfvoNsInst.get().getStatus()); + + objUnderTest.runDeleteNsJob(nsInstanceId); + + final Optional<NfvoJob> optional = getJobByResourceId(nsInstanceId); + assertTrue(optional.isPresent()); + final NfvoJob nfvoJob = optional.get(); + + // Confirm Process finishes in STATE_COMPLETED + assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + + // Confirm NS Instance no longer in database + final Optional<NfvoNsInst> optionalNfvoNsInstance = databaseServiceProvider.getNfvoNsInst(nsInstanceId); + assertTrue(optionalNfvoNsInstance.isEmpty()); + } + + private void addDummyNsToDatabase(final String nsInstanceId, final State state) { + final String nsPackageId = UUID.randomUUID().toString(); + final NfvoNsInst nfvoNsInst = new NfvoNsInst().nsInstId(nsInstanceId).name("nsName").nsPackageId(nsPackageId) + .nsdId("nsdId").nsdInvariantId("nsdId").status(state).statusUpdatedTime(LocalDateTime.now()) + .globalCustomerId(GLOBAL_CUSTOMER_ID).serviceType(SERVICE_TYPE); + databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); + } + + private void mockAaiEndpoints() { + final String modelEndpoint = getAaiServiceInstanceEndPoint(); + final String resourceVersion = "12345"; + + final String body = + "{\"resource-version\": \"" + resourceVersion + "\",\n\"orchestration-status\": \"Assigned\"}"; + wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok()).willReturn(okJson(body))); + + wireMockServer.stubFor( + delete(urlMatching(modelEndpoint + "\\?resource-version=" + resourceVersion)).willReturn(ok())); + } +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/InstantiateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/InstantiateNsTaskTest.java index 00e9433eac..f1373bd4ea 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/InstantiateNsTaskTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/InstantiateNsTaskTest.java @@ -271,7 +271,7 @@ public class InstantiateNsTaskTest extends BaseTest { for (final Entry<String, String> entry : VNFD_ID_TO_VNFPKG_ID_MAPPING.entrySet()) { instantiateNsRequest .addAdditionalParamsForVnfItem(new NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf() - .vnfProfileId(entry.getValue()).additionalParams(additionalParams)); + .vnfProfileId(entry.getKey()).additionalParams(additionalParams)); } return instantiateNsRequest; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java index ff5c2a9105..aa8d8cf10e 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/MonitorSol003AdapterCreateJobTaskTest.java @@ -132,7 +132,7 @@ public class MonitorSol003AdapterCreateJobTaskTest extends BaseTest { assertNull(nsResponseVariable); final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(), - CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue(); assertNotNull(problemDetails); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java index 14e5b1cafc..b821c85edd 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/java/org/onap/so/etsi/nfvo/ns/workflow/engine/tasks/TerminateNsTaskTest.java @@ -75,15 +75,9 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat public class TerminateNsTaskTest extends BaseTest { @Autowired - @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) - private RestTemplate etsiCatalogRestTemplate; - - @Autowired @Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN) private RestTemplate sol003AdapterRestTemplate; - private MockRestServiceServer mockEtsiCatalogRestServiceServer; - private MockRestServiceServer mockSol003AdapterRestServiceServer; @Autowired @@ -101,21 +95,14 @@ public class TerminateNsTaskTest extends BaseTest { public void before() { wireMockServer.resetAll(); gson = gsonProvider.getGson(); - - mockEtsiCatalogRestServiceServer = - MockRestServiceServer.bindTo(etsiCatalogRestTemplate).ignoreExpectOrder(true).build(); mockSol003AdapterRestServiceServer = MockRestServiceServer.bindTo(sol003AdapterRestTemplate).ignoreExpectOrder(true).build(); - - etsiCatalogRestTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); sol003AdapterRestTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); - } @After public void after() { wireMockServer.resetAll(); - mockEtsiCatalogRestServiceServer.reset(); } @Test diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml index e0439073bb..cf852c14b0 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/pom.xml @@ -31,5 +31,17 @@ <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>nl.jqno.equalsverifier</groupId> + <artifactId>equalsverifier</artifactId> + <version>${equalsverifier-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.onap.so</groupId> + <artifactId>common</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> </dependencies> </project>
\ No newline at end of file diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java new file mode 100644 index 0000000000..627250535e --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/CancelModeType.java @@ -0,0 +1,28 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.etsi.nfvo.ns.lcm.database.beans; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +public enum CancelModeType { + GRACEFUL, FORCEFUL; +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJob.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJob.java index 9453caac9e..60b06e1061 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJob.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJob.java @@ -42,24 +42,24 @@ import org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils; public class NfvoJob { @Id - @Column(name = "JOB_ID") + @Column(name = "JOB_ID", nullable = false) private String jobId; - @Column(name = "JOB_TYPE") + @Column(name = "JOB_TYPE", nullable = false) private String jobType; @Enumerated(EnumType.STRING) - @Column(name = "JOB_ACTION") + @Column(name = "JOB_ACTION", nullable = false) private JobAction jobAction; - @Column(name = "RESOURCE_ID") + @Column(name = "RESOURCE_ID", nullable = false) private String resourceId; @Column(name = "RESOURCE_NAME") private String resourceName; @Enumerated(EnumType.STRING) - @Column(name = "STATUS") + @Column(name = "STATUS", nullable = false) private JobStatusEnum status; @Column(name = "START_TIME") @@ -238,14 +238,17 @@ public class NfvoJob { @Override public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; if (obj instanceof NfvoJob) { final NfvoJob other = (NfvoJob) obj; return Objects.equals(jobId, other.jobId) && Objects.equals(processInstanceId, other.processInstanceId) && Objects.equals(jobType, other.jobType) && Objects.equals(jobAction, other.jobAction) && Objects.equals(progress, other.progress) && Objects.equals(status, other.status) && Objects.equals(startTime, other.startTime) && Objects.equals(endTime, other.endTime) - && Objects.equals(status, other.status) && Objects.equals(resourceId, other.resourceId) - && Objects.equals(resourceName, other.resourceName) + && Objects.equals(resourceId, other.resourceId) && Objects.equals(resourceName, other.resourceName) && Utils.isEquals(nfvoJobStatuses, other.nfvoJobStatuses); } return false; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java index 89e07701ed..66ae0e503c 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoJobStatus.java @@ -44,17 +44,17 @@ public class NfvoJobStatus { private int id; @Enumerated(EnumType.STRING) - @Column(name = "STATUS") + @Column(name = "STATUS", nullable = false) private JobStatusEnum status; @Column(name = "DESCRIPTION", columnDefinition = "LONGTEXT") private String description; - @Column(name = "UPDATED_TIME") + @Column(name = "UPDATED_TIME", nullable = false) private LocalDateTime updatedTime; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "JOB_ID") + @JoinColumn(name = "JOB_ID", nullable = false) private NfvoJob nfvoJob; public int getId() { @@ -116,17 +116,21 @@ public class NfvoJobStatus { @Override public int hashCode() { - return Objects.hash(id, status, updatedTime, description, nfvoJob.getJobId()); + return Objects.hash(id, status, updatedTime, description, nfvoJob != null ? nfvoJob.getJobId() : 0); } @Override public boolean equals(final Object obj) { - + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; if (obj instanceof NfvoJobStatus) { final NfvoJobStatus other = (NfvoJobStatus) obj; return Objects.equals(id, other.id) && Objects.equals(status, other.status) && Objects.equals(updatedTime, other.updatedTime) && Objects.equals(description, other.description) - && Objects.equals(nfvoJob.getJobId(), other.nfvoJob.getJobId()); + && (nfvoJob == null ? other.nfvoJob == null + : other.nfvoJob != null && Objects.equals(nfvoJob.getJobId(), other.nfvoJob.getJobId())); } return false; } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNfInst.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNfInst.java index e901e10596..570355fb37 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNfInst.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNfInst.java @@ -41,7 +41,7 @@ import javax.persistence.Table; public class NfvoNfInst { @Id - @Column(name = "NF_INST_ID") + @Column(name = "NF_INST_ID", nullable = false) private String nfInstId; @Column(name = "NAME") @@ -54,11 +54,11 @@ public class NfvoNfInst { private String packageId; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "NS_INST_ID") + @JoinColumn(name = "NS_INST_ID", nullable = false) private NfvoNsInst nsInst; @Enumerated(EnumType.STRING) - @Column(name = "STATUS") + @Column(name = "STATUS", nullable = false) private State status; @Column(name = "CREATE_TIME") @@ -184,13 +184,15 @@ public class NfvoNfInst { final NfvoNfInst that = (NfvoNfInst) object; return Objects.equals(nfInstId, that.nfInstId) && Objects.equals(name, that.name) && Objects.equals(vnfdId, that.vnfdId) && Objects.equals(packageId, that.packageId) - && Objects.equals(nsInst, that.nsInst) && Objects.equals(status, that.status) - && Objects.equals(createTime, that.createTime) && Objects.equals(lastUpdateTime, that.lastUpdateTime); + && (nsInst == null ? that.nsInst == null : that.nsInst != null && Objects.equals(nsInst, that.nsInst)) + && Objects.equals(status, that.status) && Objects.equals(createTime, that.createTime) + && Objects.equals(lastUpdateTime, that.lastUpdateTime); } @Override public int hashCode() { - return Objects.hash(nfInstId, name, vnfdId, packageId, nsInst, status, createTime, lastUpdateTime); + return Objects.hash(nfInstId, name, vnfdId, packageId, nsInst != null ? nsInst.getNsInstId() : 0, status, + createTime, lastUpdateTime); } @Override diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java index dd8448fe56..04f988c2fc 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NfvoNsInst.java @@ -44,29 +44,29 @@ import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndented public class NfvoNsInst { @Id - @Column(name = "NS_INST_ID") + @Column(name = "NS_INST_ID", nullable = false) private String nsInstId; - @Column(name = "NAME") + @Column(name = "NAME", nullable = false) private String name; @Column(name = "NS_PACKAGE_ID") private String nsPackageId; - @Column(name = "NSD_ID") + @Column(name = "NSD_ID", nullable = false) private String nsdId; - @Column(name = "NSD_INVARIANT_ID") + @Column(name = "NSD_INVARIANT_ID", nullable = false) private String nsdInvariantId; @Column(name = "DESCRIPTION", columnDefinition = "LONGTEXT") private String description; @Enumerated(EnumType.STRING) - @Column(name = "STATUS") + @Column(name = "STATUS", nullable = false) private State status; - @Column(name = "STATUS_UPDATED_TIME") + @Column(name = "STATUS_UPDATED_TIME", nullable = false) private LocalDateTime statusUpdatedTime; @Column(name = "GLOBAL_CUSTOMER_ID") @@ -251,6 +251,10 @@ public class NfvoNsInst { @Override public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; if (obj instanceof NfvoNsInst) { final NfvoNsInst other = (NfvoNsInst) obj; return Objects.equals(nsInstId, other.nsInstId) && Objects.equals(name, other.name) diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java index c47bbdbefb..4846e5a361 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/NsLcmOpOcc.java @@ -41,11 +41,11 @@ import javax.persistence.Table; public class NsLcmOpOcc { @Id - @Column(name = "ID") + @Column(name = "ID", nullable = false) private String id; @Enumerated(EnumType.STRING) - @Column(name = "OPERATION_STATE") + @Column(name = "OPERATION_STATE", nullable = false) private OperationStateEnum operationState; @Column(name = "STATE_ENTERED_TIME") @@ -55,22 +55,26 @@ public class NsLcmOpOcc { private LocalDateTime startTime; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "NS_INST_ID") + @JoinColumn(name = "NS_INST_ID", nullable = false) private NfvoNsInst nfvoNsInst; @Enumerated(EnumType.STRING) - @Column(name = "OPERATION") + @Column(name = "OPERATION", nullable = false) private NsLcmOpType operation; - @Column(name = "IS_AUTO_INNOVATION") - private boolean isAutoInnovation; + @Column(name = "IS_AUTO_INVOCATION", nullable = false) + private boolean isAutoInvocation; - @Column(name = "OPERATION_PARAMS", columnDefinition = "LONGTEXT") + @Column(name = "OPERATION_PARAMS", columnDefinition = "LONGTEXT", nullable = false) private String operationParams; - @Column(name = "IS_CANCEL_PENDING") + @Column(name = "IS_CANCEL_PENDING", nullable = false) private boolean isCancelPending; + @Enumerated(EnumType.STRING) + @Column(name = "CANCEL_MODE") + private CancelModeType cancelMode; + public NsLcmOpOcc() { this.id = UUID.randomUUID().toString(); } @@ -153,16 +157,29 @@ public class NsLcmOpOcc { return this; } - public boolean getIsAutoInnovation() { - return isAutoInnovation; + public boolean getIsAutoInvocation() { + return isAutoInvocation; + } + + public void setIsAutoInvocation(final boolean isAutoInvocation) { + this.isAutoInvocation = isAutoInvocation; + } + + public NsLcmOpOcc isAutoInvocation(final boolean isAutoInvocation) { + this.isAutoInvocation = isAutoInvocation; + return this; + } + + public CancelModeType getCancelMode() { + return cancelMode; } - public void setIsAutoInnovation(final boolean isAutoInnovation) { - this.isAutoInnovation = isAutoInnovation; + public void setCancelMode(final CancelModeType cancelMode) { + this.cancelMode = cancelMode; } - public NsLcmOpOcc isAutoInnovation(final boolean isAutoInnovation) { - this.isAutoInnovation = isAutoInnovation; + public NsLcmOpOcc cancelMode(final CancelModeType cancelMode) { + this.cancelMode = cancelMode; return this; } @@ -193,24 +210,26 @@ public class NsLcmOpOcc { } @Override - public boolean equals(final Object object) { - if (this == object) + public boolean equals(final Object obj) { + if (this == obj) return true; - if (object == null || getClass() != object.getClass()) + if (obj == null || getClass() != obj.getClass()) return false; - final NsLcmOpOcc that = (NsLcmOpOcc) object; + final NsLcmOpOcc that = (NsLcmOpOcc) obj; return Objects.equals(id, that.id) && Objects.equals(operationState, that.operationState) && Objects.equals(stateEnteredTime, that.stateEnteredTime) && Objects.equals(startTime, that.startTime) - && Objects.equals(nfvoNsInst, that.nfvoNsInst) && Objects.equals(operation, that.operation) - && Objects.equals(isAutoInnovation, that.isAutoInnovation) + && (nfvoNsInst == null ? that.nfvoNsInst == null + : that.nfvoNsInst != null && Objects.equals(nfvoNsInst, that.nfvoNsInst)) + && Objects.equals(operation, that.operation) && Objects.equals(isAutoInvocation, that.isAutoInvocation) && Objects.equals(operationParams, that.operationParams) - && Objects.equals(isCancelPending, that.isCancelPending); + && Objects.equals(isCancelPending, that.isCancelPending) && Objects.equals(cancelMode, that.cancelMode); } @Override public int hashCode() { - return Objects.hash(id, operationState, stateEnteredTime, startTime, nfvoNsInst, operation, isAutoInnovation, - operationParams, isCancelPending); + return Objects.hash(id, operationState, stateEnteredTime, startTime, + nfvoNsInst != null ? nfvoNsInst.getNsInstId() : 0, operation, isAutoInvocation, operationParams, + isCancelPending, cancelMode); } @Override @@ -224,9 +243,10 @@ public class NsLcmOpOcc { sb.append(" nfvoNsInst: ").append(nfvoNsInst != null ? toIndentedString(nfvoNsInst.getNsInstId()) : null) .append("\n"); sb.append(" operation: ").append(toIndentedString(operation)).append("\n"); - sb.append(" isAutoInnovation: ").append(toIndentedString(isAutoInnovation)).append("\n"); + sb.append(" isAutoInvocation: ").append(toIndentedString(isAutoInvocation)).append("\n"); sb.append(" operationParams: ").append(toIndentedString(operationParams)).append("\n"); sb.append(" isCancelPending: ").append(toIndentedString(isCancelPending)).append("\n"); + sb.append(" cancelMode: ").append(toIndentedString(cancelMode)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/Utils.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/Utils.java index c55ef5728e..b84f95aa50 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/Utils.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/beans/utils/Utils.java @@ -39,10 +39,11 @@ public class Utils { if (first == null) { return second == null; } + if (first.isEmpty()) { return second.isEmpty(); } - if (first.size() == second.size()) { + if ((first != null && second != null) && (first.size() == second.size())) { for (int index = 0; index < first.size(); index++) { if (!Objects.equals(first.get(index), second.get(index))) { return false; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java index 1aaddebc5e..1487b630c7 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java @@ -120,11 +120,6 @@ public class DatabaseServiceProvider { return nfvoNfInstRepository.save(nfvoNfInst) != null; } - public Optional<NfvoNfInst> getNfvoNfInstByNfInstId(final String nfInstId) { - logger.info("Querying database for NfvoNfInst using nfInstId: {}", nfInstId); - return nfvoNfInstRepository.findByNfInstId(nfInstId); - } - public List<NfvoNfInst> getNfvoNfInstByNsInstId(final String nsInstId) { logger.info("Querying database for NfvoNfInst using nsInstId: {}", nsInstId); return nfvoNfInstRepository.findByNsInstNsInstId(nsInstId); @@ -160,5 +155,8 @@ public class DatabaseServiceProvider { return nsLcmOpOccRepository.findById(id); } - + public void deleteNfvoNsInst(final String nsInstId) { + logger.info("Deleting NfvoNsInst with nsInstId: {}", nsInstId); + nfvoNsInstRepository.deleteById(nsInstId); + } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql index f41a8206e0..85a732b83e 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/resources/db/migration/V1_1__create_nfvo_tables.sql @@ -64,9 +64,10 @@ CREATE TABLE IF NOT EXISTS `NS_LCM_OP_OCCS` ( `START_TIME` DATETIME DEFAULT NULL, `NS_INST_ID` varchar(255) NOT NULL, `OPERATION` varchar(255) NOT NULL, - `IS_AUTO_INNOVATION` varchar(255) NOT NULL, + `IS_AUTO_INVOCATION` varchar(255) NOT NULL, `OPERATION_PARAMS` longtext NOT NULL, `IS_CANCEL_PENDING` varchar(255) NOT NULL, + `CANCEL_MODE` varchar(255) DEFAULT NULL, PRIMARY KEY (`ID`), FOREIGN KEY (NS_INST_ID) REFERENCES NS_INST(NS_INST_ID) diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java index 8108749d48..fcf7f9c373 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java @@ -133,7 +133,7 @@ public class DatabaseServiceProviderTest { .status(State.NOT_INSTANTIATED).createTime(CURRENT_DATE_TIME).lastUpdateTime(CURRENT_DATE_TIME); databaseServiceProvider.saveNfvoNfInst(nfInst); - final Optional<NfvoNfInst> actual = databaseServiceProvider.getNfvoNfInstByNfInstId(nfInst.getNfInstId()); + final Optional<NfvoNfInst> actual = databaseServiceProvider.getNfvoNfInst(nfInst.getNfInstId()); final NfvoNfInst actualNfvoNfInst = actual.get(); assertEquals(nsInst.getNsInstId(), actualNfvoNfInst.getNsInst().getNsInstId()); assertEquals(nfInst.getNfInstId(), actualNfvoNfInst.getNfInstId()); @@ -164,7 +164,7 @@ public class DatabaseServiceProviderTest { databaseServiceProvider.saveNfvoNsInst(nsInst); final NsLcmOpOcc nsLcmOpOcc = new NsLcmOpOcc().nfvoNsInst(nsInst).operationState(OperationStateEnum.PROCESSING) - .isCancelPending(false).isAutoInnovation(false).operation(NsLcmOpType.INSTANTIATE) + .isCancelPending(false).isAutoInvocation(false).operation(NsLcmOpType.INSTANTIATE) .startTime(CURRENT_DATE_TIME).stateEnteredTime(CURRENT_DATE_TIME).operationParams(""); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/PojoClassesTests.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/PojoClassesTests.java new file mode 100644 index 0000000000..5f033a2438 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/PojoClassesTests.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.etsi.nfvo.ns.lcm.database; + +import javax.persistence.Entity; +import javax.persistence.Id; +import org.junit.Test; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.openpojo.rules.ToStringTester; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +public class PojoClassesTests { + + @Test + public void test_database_beans() throws ClassNotFoundException { + + final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()) + .with(new ToStringTester()).build(); + validator.validate(NfvoNsInst.class.getPackageName(), new FilterPackageInfo()); + } + + @Test + public void test_database_nfvoJob_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NfvoJob.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoJobStatus.class, new NfvoJobStatus().nfvoJob(new NfvoJob()), + new NfvoJobStatus().nfvoJob(new NfvoJob())) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } + + @Test + public void test_database_nfvoJobStatus_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NfvoJobStatus.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoJob.class, new NfvoJob(), new NfvoJob()) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } + + @Test + public void test_database_nfvoNsInst_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NfvoNsInst.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoNfInst.class, new NfvoNfInst(), new NfvoNfInst()) + .withPrefabValues(NsLcmOpOcc.class, new NsLcmOpOcc(), new NsLcmOpOcc()) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } + + @Test + public void test_database_nfvoNfInst_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NfvoNfInst.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoNsInst.class, new NfvoNsInst(), new NfvoNsInst()) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } + + @Test + public void test_database_nsLcmOpOcc_equalAndHashMethod() throws ClassNotFoundException { + EqualsVerifier.forClass(NsLcmOpOcc.class) + .suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS, Warning.INHERITED_DIRECTLY_FROM_OBJECT) + .withPrefabValues(NfvoNsInst.class, new NfvoNsInst(), new NfvoNsInst()) + .withIgnoredAnnotations(Entity.class, Id.class).verify(); + } +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLcmOperationOccurrenceManager.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLcmOperationOccurrenceManager.java new file mode 100644 index 0000000000..8a5cee6d75 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLcmOperationOccurrenceManager.java @@ -0,0 +1,122 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.etsi.nfvo.ns.lcm.lifecycle; + +import static org.slf4j.LoggerFactory.getLogger; +import org.onap.so.etsi.nfvo.ns.lcm.EtsiSoNsLcmManagerUrlProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstanceLinksSelf; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOccLinks; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import java.util.Optional; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +@Service +public class NsLcmOperationOccurrenceManager { + + private static final Logger logger = getLogger(NsLcmOperationOccurrenceManager.class); + + private final DatabaseServiceProvider databaseServiceProvider; + private final EtsiSoNsLcmManagerUrlProvider etsiSoNsLcmManagerUrlProvider; + + @Autowired + public NsLcmOperationOccurrenceManager(final DatabaseServiceProvider databaseServiceProvider, + final EtsiSoNsLcmManagerUrlProvider etsiSoNsLcmManagerUrlProvider) { + this.databaseServiceProvider = databaseServiceProvider; + this.etsiSoNsLcmManagerUrlProvider = etsiSoNsLcmManagerUrlProvider; + } + + public Optional<NsLcmOpOccsNsLcmOpOcc> getNsLcmOperationOccurrence(final String nsLcmOpOccId) { + logger.info("Getting NS LCM Operation Occurrence Operation for id: {}", nsLcmOpOccId); + final Optional<NsLcmOpOcc> optionalNsLcmOpOcc = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOccId); + + if (optionalNsLcmOpOcc.isEmpty()) { + logger.info("No NS LCM Operation Occurrence found for id: {}", nsLcmOpOccId); + return Optional.empty(); + } + + logger.info("Found NS LCM Operation Occurrence for id: {}", nsLcmOpOccId); + final NsLcmOpOcc nsLcmOpOcc = optionalNsLcmOpOcc.get(); + final NsLcmOpOccsNsLcmOpOcc nsLcmOpOccsNsLcmOpOcc = convertToNsLcmOpOccsNsLcmOpOcc(nsLcmOpOcc); + return Optional.of(nsLcmOpOccsNsLcmOpOcc); + } + + private NsLcmOpOccsNsLcmOpOcc convertToNsLcmOpOccsNsLcmOpOcc(final NsLcmOpOcc nsLcmOpOcc) { + logger.info("Converting Database NsLcmOpOcc to API NsLcmOpOcc... "); + final NsLcmOpOccsNsLcmOpOcc nsLcmOpOccsNsLcmOpOcc = + new NsLcmOpOccsNsLcmOpOcc().id(nsLcmOpOcc.getId()).statusEnteredTime(nsLcmOpOcc.getStateEnteredTime()) + .startTime(nsLcmOpOcc.getStartTime()).isAutomaticInvocation(nsLcmOpOcc.getIsAutoInvocation()) + .isCancelPending(nsLcmOpOcc.getIsCancelPending()); + + if (nsLcmOpOcc.getNfvoNsInst() != null) { + nsLcmOpOccsNsLcmOpOcc.setNsInstanceId(nsLcmOpOcc.getNfvoNsInst().getNsInstId()); + } + + if (nsLcmOpOcc.getOperationState() != null) { + nsLcmOpOccsNsLcmOpOcc.setOperationState( + NsLcmOpOccsNsLcmOpOcc.OperationStateEnum.fromValue(nsLcmOpOcc.getOperationState().toString())); + } + + if (nsLcmOpOcc.getOperation() != null) { + nsLcmOpOccsNsLcmOpOcc.setLcmOperationType( + NsLcmOpOccsNsLcmOpOcc.LcmOperationTypeEnum.fromValue(nsLcmOpOcc.getOperation().toString())); + } + + if (nsLcmOpOcc.getOperationParams() != null) { + nsLcmOpOccsNsLcmOpOcc.setOperationParams(nsLcmOpOcc.getOperationParams()); + } + + if (nsLcmOpOcc.getCancelMode() != null) { + nsLcmOpOccsNsLcmOpOcc.setCancelMode( + NsLcmOpOccsNsLcmOpOcc.CancelModeEnum.fromValue(nsLcmOpOcc.getCancelMode().toString())); + } + + nsLcmOpOccsNsLcmOpOcc.setLinks(generateLinks(nsLcmOpOcc)); + + logger.info("Database NsLcmOpOcc converted to API NsLcmOpOcc successfully... {}", nsLcmOpOccsNsLcmOpOcc); + return nsLcmOpOccsNsLcmOpOcc; + } + + private NsLcmOpOccsNsLcmOpOccLinks generateLinks(final NsLcmOpOcc nsLcmOpOcc) { + logger.info("Generating links..."); + final String nsLcmOpOccId = nsLcmOpOcc.getId(); + final NsInstancesNsInstanceLinksSelf linksSelfNsLcmOpOcc = new NsInstancesNsInstanceLinksSelf() + .href(etsiSoNsLcmManagerUrlProvider.getNsLcmOpOccUri(nsLcmOpOccId).toString()); + final NsLcmOpOccsNsLcmOpOccLinks links = new NsLcmOpOccsNsLcmOpOccLinks().self(linksSelfNsLcmOpOcc); + + if (nsLcmOpOcc.getNfvoNsInst() != null) { + final String nsInstId = nsLcmOpOcc.getNfvoNsInst().getNsInstId(); + final NsInstancesNsInstanceLinksSelf linksSelfNsInst = new NsInstancesNsInstanceLinksSelf() + .href(etsiSoNsLcmManagerUrlProvider.getCreatedNsResourceUri(nsInstId).toString()); + links.setNsInstance(linksSelfNsInst); + } + + return links; + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java index 2ebf55ff7f..ae9f55e1c5 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/lifecycle/NsLifeCycleManager.java @@ -82,4 +82,9 @@ public class NsLifeCycleManager { return etsiSoNsLcmManagerUrlProvider.getNsLcmOpOccUri(nsLcmOpOccId); } + + public void deleteNs(final String nsInstanceId) { + logger.info("Will execute Delete Ns for nsInstanceId: {}", nsInstanceId); + jobExecutorService.runDeleteNsJob(nsInstanceId); + } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesController.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesController.java index ec79ce6329..207f0ff387 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesController.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesController.java @@ -22,20 +22,25 @@ package org.onap.so.etsi.nfvo.ns.lcm.rest; import static org.onap.so.etsi.nfvo.ns.lcm.Constants.NS_LIFE_CYCLE_MANAGEMENT_BASE_URL; import static org.slf4j.LoggerFactory.getLogger; import javax.ws.rs.core.MediaType; +import org.onap.so.etsi.nfvo.ns.lcm.lifecycle.NsLcmOperationOccurrenceManager; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOcc; import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import java.util.Optional; /** * Controller for handling NS lifecycle management operation occurrence requests see clause 6.4.9 and 6.4.10 in * https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/005/02.07.01_60/gs_NFV-SOL005v020701p.pdf * * @author Waqas Ikram (waqas.ikram@est.tech) + * @author Andrew Lamb (andrew.a.lamb@est.tech) * */ @Controller @@ -43,6 +48,12 @@ import org.springframework.web.bind.annotation.RequestMapping; public class NsLcmOperationOccurrencesController { private static final Logger logger = getLogger(NsLcmOperationOccurrencesController.class); + private final NsLcmOperationOccurrenceManager nsLcmOperationOccurrenceManager; + + @Autowired + public NsLcmOperationOccurrencesController(final NsLcmOperationOccurrenceManager nsLcmOperationOccurrenceManager) { + this.nsLcmOperationOccurrenceManager = nsLcmOperationOccurrenceManager; + } /** * The GET method to retrieve status information about a NS lifecycle management operation occurrence by reading an @@ -57,7 +68,18 @@ public class NsLcmOperationOccurrencesController { produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> getOperationStatus(@PathVariable("nsLcmOpOccId") final String nsLcmOpOccId) { logger.info("Received request to retrieve operation status for nsLcmOpOccId: {}", nsLcmOpOccId); - return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet"); + final Optional<NsLcmOpOccsNsLcmOpOcc> optionalNsLcmOpOccs = + nsLcmOperationOccurrenceManager.getNsLcmOperationOccurrence(nsLcmOpOccId); + + if (optionalNsLcmOpOccs.isPresent()) { + final NsLcmOpOccsNsLcmOpOcc nsLcmOpOcc = optionalNsLcmOpOccs.get(); + logger.info("Sending back NsLcmOpOcc: {}", nsLcmOpOcc); + return ResponseEntity.ok().body(nsLcmOpOcc); + } + + final String errorMessage = "Unable to retrieve operation occurrence status for nsLcmOpOccId: " + nsLcmOpOccId; + logger.error(errorMessage); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new InlineResponse400().detail(errorMessage)); } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java index cfda89f3f0..2390cef564 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementController.java @@ -35,7 +35,6 @@ import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance; import org.onap.so.etsi.nfvo.ns.lcm.model.TerminateNsRequest; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.DeleteMapping; @@ -78,7 +77,7 @@ public class NsLifecycleManagementController { */ @PostMapping(value = "/ns_instances", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity<?> createNs( + public ResponseEntity<NsInstancesNsInstance> createNs( @RequestHeader(value = HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME, required = true) final String globalCustomerId, @RequestHeader(value = HTTP_SERVICETYPE_HEADER_PARM_NAME, required = false, @@ -107,9 +106,11 @@ public class NsLifecycleManagementController { */ @DeleteMapping(value = "/ns_instances/{nsInstanceId}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity<?> deleteNs(@PathVariable("nsInstanceId") final String nsInstanceId) { + public ResponseEntity<Void> deleteNs(@PathVariable("nsInstanceId") final String nsInstanceId) { logger.debug("Received delete NS request for nsInstanceId: {}", nsInstanceId); - return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet"); + nsLifeCycleManager.deleteNs(nsInstanceId); + logger.info("Successfully deleted NS for nsInstanceId: {}", nsInstanceId); + return ResponseEntity.noContent().build(); } /** @@ -123,7 +124,7 @@ public class NsLifecycleManagementController { @PostMapping(value = "/ns_instances/{nsInstanceId}/instantiate", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity<?> instantiateNs(@PathVariable("nsInstanceId") final String nsInstanceId, + public ResponseEntity<Void> instantiateNs(@PathVariable("nsInstanceId") final String nsInstanceId, @RequestBody final InstantiateNsRequest instantiateNsRequest) { logger.debug("Received instantiate NS request: {}\n with nsInstanceId: {}", instantiateNsRequest, nsInstanceId); final URI resourceUri = nsLifeCycleManager.instantiateNs(nsInstanceId, instantiateNsRequest); @@ -143,7 +144,7 @@ public class NsLifecycleManagementController { @PostMapping(value = "/ns_instances/{nsInstanceId}/terminate", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) - public ResponseEntity<?> terminateNs(@PathVariable("nsInstanceId") final String nsInstanceId, + public ResponseEntity<Void> terminateNs(@PathVariable("nsInstanceId") final String nsInstanceId, @RequestBody final TerminateNsRequest terminateNsRequest) { logger.debug("Received terminate NS request: {}\n with nsInstanceId: {}", terminateNsRequest, nsInstanceId); final URI resourceUri = nsLifeCycleManager.terminateNs(nsInstanceId, terminateNsRequest); diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesControllerTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesControllerTest.java index 9eace927d6..c5862569f2 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesControllerTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLcmOperationOccurrencesControllerTest.java @@ -20,13 +20,26 @@ package org.onap.so.etsi.nfvo.ns.lcm.rest; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import java.time.LocalDateTime; +import java.util.Optional; import java.util.UUID; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.etsi.nfvo.ns.lcm.Constants; -import org.onap.so.etsi.nfvo.ns.lcm.JSON; import org.onap.so.etsi.nfvo.ns.lcm.TestApplication; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpType; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsLcmOpOccsNsLcmOpOcc; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.client.RestTemplateBuilder; @@ -42,32 +55,75 @@ import org.springframework.test.context.junit4.SpringRunner; import com.google.gson.Gson; /** - * * @author Waqas Ikram (waqas.ikram@est.tech) + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * */ @RunWith(SpringRunner.class) @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") public class NsLcmOperationOccurrencesControllerTest { + + private static final String NS_LCM_OP_OCCS = "/ns_lcm_op_occs/"; + @LocalServerPort private int port; + + @Autowired + private DatabaseServiceProvider databaseServiceProvider; + + @Autowired + private GsonProvider gsonProvider; + private TestRestTemplate testRestTemplate; @Before public void setUp() { - final Gson gson = JSON.createGson().create(); + final Gson gson = gsonProvider.getGson(); testRestTemplate = new TestRestTemplate( new RestTemplateBuilder().additionalMessageConverters(new GsonHttpMessageConverter(gson))); } @Test - public void testGetOperationStatusS_ValidNsLcmOpOccId() { - final String baseUrl = getNsLcmBaseUrl() + "/ns_lcm_op_occs/" + UUID.randomUUID().toString(); + public void testGetOperationStatus_validNsLcmOpOccId_returnsNsLcmOpOcc() { + final String nsLcmOpOccId = addDummyNsLcmOpOccToDatabase(); + final String baseUrl = getNsLcmBaseUrl() + NS_LCM_OP_OCCS + nsLcmOpOccId; final HttpEntity<?> request = new HttpEntity<>(new HttpHeaders()); - final ResponseEntity<Void> responseEntity = - testRestTemplate.exchange(baseUrl, HttpMethod.GET, request, Void.class); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); + final ResponseEntity<NsLcmOpOccsNsLcmOpOcc> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.GET, request, NsLcmOpOccsNsLcmOpOcc.class); + assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); + } + + @Test + public void testGetOperationStatus_nsLcmOpOccIdNotFound_returnsInlineResponse400() { + final String nsLcmOpOccId = UUID.randomUUID().toString(); + final Optional<NsLcmOpOcc> optionalNsLcmOpOcc = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOccId); + assertTrue(optionalNsLcmOpOcc.isEmpty()); + final String baseUrl = getNsLcmBaseUrl() + NS_LCM_OP_OCCS + nsLcmOpOccId; + final HttpEntity<?> request = new HttpEntity<>(new HttpHeaders()); + final ResponseEntity<InlineResponse400> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.GET, request, InlineResponse400.class); + assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); + } + + private String addDummyNsLcmOpOccToDatabase() { + final LocalDateTime currentDateTime = LocalDateTime.now(); + + final NfvoNsInst nsInst = new NfvoNsInst().name("name").nsdId("id").status(State.NOT_INSTANTIATED) + .nsdInvariantId("id").statusUpdatedTime(currentDateTime); + databaseServiceProvider.saveNfvoNsInst(nsInst); + + final NsLcmOpOcc nsLcmOpOcc = new NsLcmOpOcc().nfvoNsInst(nsInst).operationState(OperationStateEnum.PROCESSING) + .isCancelPending(false).isAutoInvocation(false).operation(NsLcmOpType.INSTANTIATE) + .startTime(currentDateTime).stateEnteredTime(currentDateTime).operationParams(""); + databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc); + + return nsLcmOpOcc.getId(); } private String getNsLcmBaseUrl() { diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java index 4b1195244c..585b0e1811 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/rest/NsLifecycleManagementControllerTest.java @@ -19,17 +19,14 @@ */ package org.onap.so.etsi.nfvo.ns.lcm.rest; -/** - * @author Waqas Ikram (waqas.ikram@est.tech) - * - */ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; import java.net.URISyntaxException; -import java.time.LocalDateTime; import java.util.List; import java.util.UUID; import org.junit.Before; @@ -173,11 +170,30 @@ public class NsLifecycleManagementControllerTest { } @Test - public void testCreateNs_ValidDeleteNsRequest() { - final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString(); + public void testDeleteNs_SuccessfulCase() { + final String nsInstId = UUID.randomUUID().toString(); + doNothing().when(mockedJobExecutorService).runDeleteNsJob(eq(nsInstId)); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + nsInstId; final ResponseEntity<Void> responseEntity = testRestTemplate.exchange(baseUrl, HttpMethod.DELETE, null, Void.class); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); + assertEquals(HttpStatus.NO_CONTENT, responseEntity.getStatusCode()); + } + + @Test + public void testDeleteNs_nsRequestProcessingExceptionThrown_returnInlineResponse400() { + final String nsInstId = UUID.randomUUID().toString(); + final String message = "Unable to process request"; + doThrow(new NsRequestProcessingException(message, new InlineResponse400().detail(message))) + .when(mockedJobExecutorService).runDeleteNsJob(eq(nsInstId)); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + nsInstId; + final ResponseEntity<InlineResponse400> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.DELETE, null, InlineResponse400.class); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); } @Test diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml index 44acda20a4..6f2b4d26c5 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml @@ -29,11 +29,13 @@ spring: pool-name: ns-lcm-nfvo-pool registerMbeans: true jpa: + generate-ddl: true hibernate: - ddl-auto: none + ddl-auto: create logging: level: org.reflections.Reflections: ERROR + etsi-catalog-manager: base: - endpoint: http://modeling-etsicatalog.onap:8806/api
\ No newline at end of file + endpoint: http://modeling-etsicatalog.onap:8806/api |