diff options
210 files changed, 11172 insertions, 7460 deletions
diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/pom.xml b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/pom.xml index 8359fd3829..6ed9afcc75 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/pom.xml +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/pom.xml @@ -105,5 +105,10 @@ <artifactId>junit</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>org.onap.so.adapters</groupId> + <artifactId>etsi-sol003-pkgm-adapter</artifactId> + <version>${project.version}</version> + </dependency> </dependencies> </project> diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/SdcPackageProvider.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/EtsiPackageProvider.java index 497de2874c..c5164c1833 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/SdcPackageProvider.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/EtsiPackageProvider.java @@ -24,38 +24,25 @@ package org.onap.so.adapters.etsisol003adapter.lcm.extclients; import static com.google.common.base.Splitter.on; import static com.google.common.collect.Iterables.filter; -import static com.google.common.io.ByteStreams.toByteArray; -import static java.lang.String.format; -import static org.apache.http.HttpHeaders.ACCEPT; -import static org.apache.http.HttpHeaders.AUTHORIZATION; import static org.onap.so.adapters.etsisol003adapter.lcm.NvfmAdapterUtils.abortOperation; import static org.onap.so.adapters.etsisol003adapter.lcm.NvfmAdapterUtils.child; import static org.onap.so.adapters.etsisol003adapter.lcm.NvfmAdapterUtils.childElement; import static org.onap.so.adapters.etsisol003adapter.lcm.NvfmAdapterUtils.children; import static org.slf4j.LoggerFactory.getLogger; -import static org.springframework.http.MediaType.APPLICATION_OCTET_STREAM_VALUE; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.util.HashSet; -import java.util.Iterator; -import java.util.List; import java.util.NoSuchElementException; +import java.util.Optional; import java.util.Set; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import javax.net.ssl.SSLContext; -import org.apache.commons.codec.binary.Base64; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.onap.so.utils.CryptoUtils; +import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.EtsiCatalogServiceProviderImpl; +import org.onap.so.adapters.etsisol003adapter.pkgm.rest.exceptions.EtsiCatalogManagerRequestFailureException; import org.slf4j.Logger; -import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.yaml.snakeyaml.Yaml; import com.google.common.io.ByteStreams; @@ -63,21 +50,13 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; @Component -public class SdcPackageProvider { - private static final String GET_PACKAGE_URL = "%s/sdc/v1/catalog/resources/%s/toscaModel"; - @Value("${sdc.toscametapath:TOSCA-Metadata/TOSCA.meta}") - private List<String> toscaMetaPaths; +public class EtsiPackageProvider { + private static final String TOCSA_METADATA_FILE_PATH = "TOSCA-Metadata/TOSCA.meta"; private static final String TOSCA_VNFD_KEY = "Entry-Definitions"; - private static Logger logger = getLogger(SdcPackageProvider.class); + private static Logger logger = getLogger(EtsiPackageProvider.class); - @Value("${sdc.username}") - private String sdcUsername; - @Value("${sdc.password}") - private String sdcPassword; - @Value("${sdc.key}") - private String sdcKey; - @Value("${sdc.endpoint}") - private String baseUrl; + @Autowired + private EtsiCatalogServiceProviderImpl etsiCatalogServiceProviderImpl; public String getVnfdId(final String csarId) { return getVnfNodeProperty(csarId, "descriptor_id"); @@ -133,35 +112,25 @@ public class SdcPackageProvider { } private byte[] getPackage(final String csarId) { - final String SERVICE_NAME = "vnfm-adapter"; - try (CloseableHttpClient client = HttpClients.custom().setSSLContext(SSLContext.getDefault()).build()) { - final HttpGet httpget = new HttpGet(format(GET_PACKAGE_URL, baseUrl, csarId)); - httpget.setHeader(ACCEPT, APPLICATION_OCTET_STREAM_VALUE); - httpget.setHeader("X-ECOMP-InstanceID", SERVICE_NAME); - httpget.setHeader("X-FromAppId", SERVICE_NAME); - final String auth = sdcUsername + ":" + CryptoUtils.decrypt(sdcPassword, sdcKey); - final byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.ISO_8859_1)); - final String authHeader = "Basic " + new String(encodedAuth); - httpget.setHeader(AUTHORIZATION, authHeader); - logger.debug("Fetching from SDC: " + httpget); - final CloseableHttpResponse response = client.execute(httpget); - final HttpEntity entity = response.getEntity(); - final InputStream is = entity.getContent(); - return toByteArray(is); - } catch (final Exception e) { - throw abortOperation("Unable to download " + csarId + " package from SDC", e); + try { + final Optional<byte[]> optional = etsiCatalogServiceProviderImpl.getVnfPackageContent(csarId); + if (optional.isPresent()) { + return optional.get(); + } + } catch (final Exception exception) { + logger.error("Unable to retrieve package from ETSI Catalog Manager using pkgId: {}", csarId); + throw new EtsiCatalogManagerRequestFailureException("Value is not present", exception); } + logger.error("Unable to retrieve package from ETSI Catalog Manager using pkgId: {}", csarId); + throw new EtsiCatalogManagerRequestFailureException("Value is not present"); } private String getVnfdLocation(final InputStream stream) throws IOException { - final Iterator<String> pathIterator = toscaMetaPaths.iterator(); - while (pathIterator.hasNext()) { - final String toscaMetadata = new String(getFileInZip(stream, pathIterator.next()).toByteArray()); - if (!toscaMetadata.isEmpty()) { - final String toscaVnfdLine = - filter(on("\n").split(toscaMetadata), line -> line.contains(TOSCA_VNFD_KEY)).iterator().next(); - return toscaVnfdLine.replace(TOSCA_VNFD_KEY + ":", "").trim(); - } + final String toscaMetadata = new String(getFileInZip(stream, TOCSA_METADATA_FILE_PATH).toByteArray()); + if (!toscaMetadata.isEmpty()) { + final String toscaVnfdLine = + filter(on("\n").split(toscaMetadata), line -> line.contains(TOSCA_VNFD_KEY)).iterator().next(); + return toscaVnfdLine.replace(TOSCA_VNFD_KEY + ":", "").trim(); } throw abortOperation("Unable to find valid Tosca Path"); } diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmRestTemplateConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmRestTemplateConfiguration.java new file mode 100644 index 0000000000..2c7ddd1d49 --- /dev/null +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmRestTemplateConfiguration.java @@ -0,0 +1,56 @@ +/*- + * ============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.adapters.etsisol003adapter.lcm.extclients.vnfm; + +import org.onap.logging.filter.spring.SpringClientPayloadFilter; +import org.onap.so.configuration.rest.HttpComponentsClientConfiguration; +import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +public class VnfmRestTemplateConfiguration { + + public static final String SOL003_LCM_REST_TEMPLATE = "Sol003LcmRestTemplate"; + + @Autowired + private HttpComponentsClientConfiguration httpComponentsClientConfiguration; + + @Bean + @Qualifier(SOL003_LCM_REST_TEMPLATE) + public RestTemplate sol003LcmRestTemplate() { + final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = + httpComponentsClientConfiguration.httpComponentsClientHttpRequestFactory(); + final RestTemplate restTemplate = + new RestTemplate(new BufferingClientHttpRequestFactory(clientHttpRequestFactory)); + restTemplate.getInterceptors().add(new SOSpringClientFilter()); + restTemplate.getInterceptors().add((new SpringClientPayloadFilter())); + return restTemplate; + } +} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java index da727b395a..1ed3ec9ff2 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java @@ -20,7 +20,6 @@ package org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; import java.io.IOException; import java.security.KeyManagementException; import java.security.KeyStore; @@ -83,7 +82,7 @@ public class VnfmServiceProviderConfiguration extends AbstractServiceProviderCon @Value("${vnfmadapter.temp.vnfm.oauth.endpoint:#{null}}") private String oauthEndpoint; - @Qualifier(CONFIGURABLE_REST_TEMPLATE) + @Qualifier(VnfmRestTemplateConfiguration.SOL003_LCM_REST_TEMPLATE) @Autowired private RestTemplate defaultRestTemplate; diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/lifecycle/LifecycleManager.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/lifecycle/LifecycleManager.java index 8ba56c5051..a2af1a4580 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/lifecycle/LifecycleManager.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/lifecycle/LifecycleManager.java @@ -24,7 +24,7 @@ import java.util.Map; import org.onap.aai.domain.yang.EsrVnfm; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Relationship; -import org.onap.so.adapters.etsisol003adapter.lcm.extclients.SdcPackageProvider; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.EtsiPackageProvider; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.AaiHelper; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.AaiServiceProvider; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.aai.OamIpAddressSource; @@ -48,6 +48,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import com.google.common.base.Optional; +import static org.apache.commons.lang3.StringUtils.isNotBlank; /** * Manages lifecycle operations towards the VNFMs. @@ -60,12 +61,12 @@ public class LifecycleManager { private final AaiHelper aaiHelper; private final VnfmHelper vnfmHelper; private final JobManager jobManager; - private final SdcPackageProvider packageProvider; + private final EtsiPackageProvider packageProvider; @Autowired LifecycleManager(final AaiServiceProvider aaiServiceProvider, final AaiHelper aaiHelper, final VnfmHelper vnfmHelper, final VnfmServiceProvider vnfmServiceProvider, final JobManager jobManager, - final SdcPackageProvider packageProvider) { + final EtsiPackageProvider packageProvider) { this.aaiServiceProvider = aaiServiceProvider; this.vnfmServiceProvider = vnfmServiceProvider; this.aaiHelper = aaiHelper; @@ -152,15 +153,16 @@ public class LifecycleManager { } } - private InlineResponse201 sendCreateRequestToVnfm(final CreateVnfRequest aaiRequest, final GenericVnf genericVnf, - final String vnfIdInAai, final EsrVnfm vnfm) { - logger.debug("Sending a create request to SVNFM " + aaiRequest); + private InlineResponse201 sendCreateRequestToVnfm(final CreateVnfRequest createVnfRequest, + final GenericVnf genericVnf, final String vnfIdInAai, final EsrVnfm vnfm) { + logger.debug("Sending a create request to SVNFM {}", createVnfRequest); final org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.CreateVnfRequest vnfmRequest = new org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.CreateVnfRequest(); - final String vnfdId = packageProvider.getVnfdId(genericVnf.getModelVersionId()); + final String pkgId = getPackageId(createVnfRequest, genericVnf); + final String vnfdId = packageProvider.getVnfdId(pkgId); vnfmRequest.setVnfdId(vnfdId); - vnfmRequest.setVnfInstanceName(aaiRequest.getName().replaceAll(" ", "_")); + vnfmRequest.setVnfInstanceName(createVnfRequest.getName().replaceAll(" ", "_")); vnfmRequest.setVnfInstanceDescription(vnfIdInAai); final Optional<InlineResponse201> optionalResponse = vnfmServiceProvider.createVnf(vnfm, vnfmRequest); @@ -174,6 +176,15 @@ public class LifecycleManager { } } + private String getPackageId(final CreateVnfRequest createVnfRequest, final GenericVnf genericVnf) { + if (isNotBlank(createVnfRequest.getPkgId())) { + logger.info("Found createVnfRequest pkgId: {}", createVnfRequest.getPkgId()); + return createVnfRequest.getPkgId(); + } + logger.info("Found genericVnf modelVersionId: {}", genericVnf.getModelVersionId()); + return genericVnf.getModelVersionId(); + } + private void createNotificationSubscription(final EsrVnfm vnfm, final String vnfId) { try { final LccnSubscriptionRequest subscriptionRequest = vnfmHelper.createNotificationSubscriptionRequest(vnfId); diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/EtsiSol003AdapterControllerTest.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/EtsiSol003AdapterControllerTest.java index eaf40b546f..9aed675324 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/EtsiSol003AdapterControllerTest.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/EtsiSol003AdapterControllerTest.java @@ -27,7 +27,7 @@ import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.VnfmRestTemplateConfiguration; import static org.springframework.test.web.client.match.MockRestRequestMatchers.content; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withBadRequest; @@ -54,7 +54,8 @@ import org.onap.aai.domain.yang.RelationshipList; import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.AAIVersion; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; -import org.onap.so.adapters.etsisol003adapter.lcm.extclients.SdcPackageProvider; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.EtsiPackageProvider; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.VnfmRestTemplateConfiguration; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse200; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse2001; import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.model.InlineResponse201; @@ -106,7 +107,7 @@ public class EtsiSol003AdapterControllerTest { @LocalServerPort private int port; @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) + @Qualifier(VnfmRestTemplateConfiguration.SOL003_LCM_REST_TEMPLATE) private RestTemplate testRestTemplate; private MockRestServiceServer mockRestServer; @@ -114,7 +115,7 @@ public class EtsiSol003AdapterControllerTest { AAIResourcesClient aaiResourcesClient; @MockBean - SdcPackageProvider sdcPackageProvider; + EtsiPackageProvider etsiPackageProvider; @Autowired EtsiSol003AdapterController controller; diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/Sol003LcnControllerTest.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/Sol003LcnControllerTest.java index ab6ae83896..86eda0abfa 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/Sol003LcnControllerTest.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/test/java/org/onap/so/adapters/etsisol003adapter/lcm/rest/Sol003LcnControllerTest.java @@ -26,7 +26,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyZeroInteractions; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import org.onap.so.adapters.etsisol003adapter.lcm.extclients.vnfm.VnfmRestTemplateConfiguration; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; @@ -99,7 +99,7 @@ public class Sol003LcnControllerTest { @LocalServerPort private int port; @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) + @Qualifier(VnfmRestTemplateConfiguration.SOL003_LCM_REST_TEMPLATE) private RestTemplate testRestTemplate; private MockRestServiceServer mockRestServer; diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-api/src/main/resources/etsisol003adapter.yaml b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-api/src/main/resources/etsisol003adapter.yaml index 9d0a5283af..578708ded8 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-api/src/main/resources/etsisol003adapter.yaml +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-api/src/main/resources/etsisol003adapter.yaml @@ -168,6 +168,9 @@ definitions: description: The name to be applied to the VNF. tenant: $ref: '#/definitions/Tenant' + pkgId: + type: string + description: An identifier for the vnf package. additionalParams: type: object description: >- @@ -519,4 +522,4 @@ definitions: description: > Type of the resource in the scope of the VIM or the resource provider. - type: string
\ No newline at end of file + type: string diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerRequestFailureException.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerRequestFailureException.java index a07732f3fa..110826a6d3 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerRequestFailureException.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/rest/exceptions/EtsiCatalogManagerRequestFailureException.java @@ -36,6 +36,10 @@ public class EtsiCatalogManagerRequestFailureException extends RuntimeException super(message); } + public EtsiCatalogManagerRequestFailureException(final String message, final Throwable cause) { + super(message, cause); + } + @Override public synchronized Throwable fillInStackTrace() { return this; diff --git a/adapters/mso-adapter-utils/pom.xml b/adapters/mso-adapter-utils/pom.xml index 6346983f96..2453c18f1a 100644 --- a/adapters/mso-adapter-utils/pom.xml +++ b/adapters/mso-adapter-utils/pom.xml @@ -103,11 +103,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.onap.so</groupId> - <artifactId>cloudify-client</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <scope>provided</scope> diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfo.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfo.java deleted file mode 100644 index 42b77baeeb..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfo.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2018 Nokia. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.beans; - -import java.util.Map; - -/* - * This Java bean class relays Heat stack status information to ActiveVOS processes. - * - * This bean is returned by all Heat-specific adapter operations (create, query, delete) - */ - -public final class DeploymentInfo { - - private final String id; - private final DeploymentStatus status; - private final Map<String, Object> outputs; - private final Map<String, Object> inputs; - private final String lastAction; - private final String actionStatus; - private final String errorMessage; - - DeploymentInfo(String id, DeploymentStatus deploymentStatus, Map<String, Object> deploymentOutputs, - Map<String, Object> deploymentInputs, String lastAction, String actionStatus, String errorMessage) { - - this.id = id; - this.status = deploymentStatus; - this.outputs = deploymentOutputs; - this.inputs = deploymentInputs; - this.lastAction = lastAction; - this.actionStatus = actionStatus; - this.errorMessage = errorMessage; - } - - public String getId() { - return id; - } - - public DeploymentStatus getStatus() { - return status; - } - - public Map<String, Object> getOutputs() { - return outputs; - } - - public Map<String, Object> getInputs() { - return inputs; - } - - public String getLastAction() { - return lastAction; - } - - public String getActionStatus() { - return actionStatus; - } - - public String getErrorMessage() { - return errorMessage; - } - - @Override - public String toString() { - return "DeploymentInfo {" + "id='" + id + '\'' + ", inputs='" + inputs + '\'' + ", outputs='" + outputs + '\'' - + ", lastAction='" + lastAction + '\'' + ", status='" + status + '\'' + ", errorMessage='" - + errorMessage + '\'' + '}'; - } - -} - diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java deleted file mode 100644 index 072bf404e7..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentInfoBuilder.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * ============LICENSE_START======================================================= ONAP : SO - * ================================================================================ Copyright (C) 2018 Nokia. - * ============================================================================= Licensed under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.so.cloudify.beans; - -import java.util.HashMap; -import java.util.Map; -import org.onap.so.cloudify.v3.model.Execution; - -public final class DeploymentInfoBuilder { - - private String id = ""; - private DeploymentStatus deploymentStatus = DeploymentStatus.NOTFOUND; - private Map<String, Object> deploymentOutputs = new HashMap<>(); - private Map<String, Object> deploymentInputs = new HashMap<>(); - private String lastAction; - private String actionStatus; - private String errorMessage; - - public DeploymentInfoBuilder withId(String id) { - this.id = id; - return this; - } - - public DeploymentInfoBuilder withStatus(DeploymentStatus deploymentStatus) { - this.deploymentStatus = deploymentStatus; - return this; - } - - public DeploymentInfoBuilder withDeploymentOutputs(Map<String, Object> deploymentOutputs) { - if (deploymentOutputs != null) { - this.deploymentOutputs = deploymentOutputs; - } - return this; - } - - public DeploymentInfoBuilder withDeploymentInputs(Map<String, Object> deploymentInputs) { - this.deploymentInputs = deploymentInputs; - return this; - } - - public DeploymentInfoBuilder withLastAction(String lastAction) { - this.lastAction = lastAction; - return this; - } - - public DeploymentInfoBuilder withActionStatus(String actionStatus) { - this.actionStatus = actionStatus; - return this; - } - - public DeploymentInfoBuilder withErrorMessage(String errorMessage) { - this.errorMessage = errorMessage; - return this; - } - - public DeploymentInfoBuilder fromExecution(Execution execution) { - if (execution != null) { - this.lastAction = execution.getWorkflowId(); - this.actionStatus = execution.getStatus(); - this.errorMessage = execution.getError(); - - // Compute the status based on the last workflow - if (("install").equals(lastAction)) { - if (("terminated").equals(actionStatus)) { - this.deploymentStatus = DeploymentStatus.INSTALLED; - } else if (("failed").equals(actionStatus)) { - this.deploymentStatus = DeploymentStatus.FAILED; - } else if (("started").equals(actionStatus) || ("pending").equals(actionStatus)) { - this.deploymentStatus = DeploymentStatus.INSTALLING; - } else { - this.deploymentStatus = DeploymentStatus.UNKNOWN; - } - } else if (("uninstall").equals(lastAction)) { - if (("terminated").equals(actionStatus)) { - this.deploymentStatus = DeploymentStatus.CREATED; - } else if (("failed").equals(actionStatus)) { - this.deploymentStatus = DeploymentStatus.FAILED; - } else if (("started").equals(actionStatus) || ("pending").equals(actionStatus)) { - this.deploymentStatus = DeploymentStatus.UNINSTALLING; - } else { - this.deploymentStatus = DeploymentStatus.UNKNOWN; - } - } else { - // Could have more cases in the future for different actions. - this.deploymentStatus = DeploymentStatus.UNKNOWN; - } - } else { - this.deploymentStatus = DeploymentStatus.CREATED; - } - - return this; - } - - public DeploymentInfo build() { - return new DeploymentInfo(id, deploymentStatus, deploymentOutputs, deploymentInputs, lastAction, actionStatus, - errorMessage); - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoBlueprintAlreadyExists.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoBlueprintAlreadyExists.java deleted file mode 100644 index 95912994bc..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoBlueprintAlreadyExists.java +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.exceptions; - -public class MsoBlueprintAlreadyExists extends MsoCloudifyException { - - private static final long serialVersionUID = 1L; - - // Constructor to create a new MsoCloudifyException instance - public MsoBlueprintAlreadyExists(String blueprintId, String cloud) { - // Set the detailed error as the Exception 'message' - super(409, "Conflict", - "Blueprint " + blueprintId + " already exists in Cloudify Manager supporting cloud site + " + cloud); - } - -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyException.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyException.java deleted file mode 100644 index 441bd4dc07..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyException.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.exceptions; - -import org.onap.so.openstack.exceptions.MsoException; -import org.onap.so.openstack.exceptions.MsoExceptionCategory; - -/** - * OpenStack exception. - */ -public class MsoCloudifyException extends MsoException { - - /** - * Serialization id. - */ - private static final long serialVersionUID = 3313636124141766495L; - - private int statusCode; - private String statusMessage; - private String errorDetail; - private boolean pendingWorkflow; - - /** - * Constructor to create a new MsoOpenstackException instance - * - * @param code the error code - * @param message the error message - * @param detail error details - */ - public MsoCloudifyException(int code, String message, String detail) { - // Set the detailed error as the Exception 'message' - super(detail); - super.category = MsoExceptionCategory.OPENSTACK; - - this.statusCode = code; - this.statusMessage = message; - this.errorDetail = detail; - this.pendingWorkflow = false; - } - - /** - * Constructor to propagate the caught exception (mostly for stack trace) - * - * @param code the error code - * @param message the error message - * @param detail error details - * @param e the cause - */ - public MsoCloudifyException(int code, String message, String detail, Exception e) { - // Set the detailed error as the Exception 'message' - super(detail, e); - super.category = MsoExceptionCategory.OPENSTACK; - - this.statusCode = code; - this.statusMessage = message; - this.errorDetail = detail; - this.pendingWorkflow = false; - } - - public void setPendingWorkflow(boolean pendingWorkflow) { - this.pendingWorkflow = pendingWorkflow; - } - - @Override - public String toString() { - String error = "" + statusCode + " " + statusMessage + ": " + errorDetail - + (pendingWorkflow ? " [workflow pending]" : ""); - return error; - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyTimeout.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyTimeout.java deleted file mode 100644 index 99b6ade326..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyTimeout.java +++ /dev/null @@ -1,66 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.exceptions; - -import org.onap.so.cloudify.v3.model.Execution; -import org.onap.so.openstack.exceptions.MsoException; -import org.onap.so.openstack.exceptions.MsoExceptionCategory; - -/** - * MSO Exception when a Cloudify workflow execution times out waiting for completion. Exception includes the last known - * state of the workflow execution. - */ -public class MsoCloudifyTimeout extends MsoException { - - /** - * Serialization id. - */ - private static final long serialVersionUID = 3313636124141766495L; - - private Execution execution; - - /** - * Constructor to create a new MsoOpenstackException instance - * - * @param code the error code - * @param message the error message - * @param detail error details - */ - public MsoCloudifyTimeout(Execution execution) { - // Set the detailed error as the Exception 'message' - super("Cloudify Workflow Timeout for workflow " + execution.getWorkflowId() + " on deployment " - + execution.getDeploymentId()); - super.category = MsoExceptionCategory.OPENSTACK; - - this.execution = execution; - } - - public Execution getExecution() { - return this.execution; - } - - @Override - public String toString() { - String error = "Workflow timeout: workflow=" + execution.getWorkflowId() + ",deployment=" - + execution.getDeploymentId(); - return error; - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowException.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowException.java deleted file mode 100644 index 2251575671..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowException.java +++ /dev/null @@ -1,54 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.exceptions; - -/** - * Reports an error with a Cloudify Workflow execution. - * - * @author JC1348 - * - */ -public class MsoCloudifyWorkflowException extends MsoCloudifyException { - - private static final long serialVersionUID = 1L; - - private String workflowStatus; - private boolean workflowStillRunning = false; - - // Constructor to create a new MsoCloudifyException instance - public MsoCloudifyWorkflowException(String message, String deploymentId, String workflowId, String workflowStatus) { - super(0, "Workflow Exception", - "Workflow " + workflowId + " failed on deployment " + deploymentId + ": " + message); - this.workflowStatus = workflowStatus; - if (("pending").equals(workflowStatus) || ("started").equals(workflowStatus) - || ("cancelling").equals(workflowStatus) || ("force_cancelling").equals(workflowStatus)) { - workflowStillRunning = true; - } - } - - public String getWorkflowStatus() { - return workflowStatus; - } - - public boolean isWorkflowStillRunning() { - return workflowStillRunning; - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java deleted file mode 100644 index 446c725e48..0000000000 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java +++ /dev/null @@ -1,1356 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2018 Nokia. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.utils; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.zip.ZipEntry; -import java.util.zip.ZipOutputStream; -import org.onap.so.adapters.vdu.CloudInfo; -import org.onap.so.adapters.vdu.PluginAction; -import org.onap.so.adapters.vdu.VduArtifact; -import org.onap.so.adapters.vdu.VduArtifact.ArtifactType; -import org.onap.so.adapters.vdu.VduException; -import org.onap.so.adapters.vdu.VduInstance; -import org.onap.so.adapters.vdu.VduModelInfo; -import org.onap.so.adapters.vdu.VduPlugin; -import org.onap.so.adapters.vdu.VduStateType; -import org.onap.so.adapters.vdu.VduStatus; -import org.onap.so.cloud.CloudConfig; -import org.onap.so.cloudify.base.client.CloudifyBaseException; -import org.onap.so.cloudify.base.client.CloudifyClientTokenProvider; -import org.onap.so.cloudify.base.client.CloudifyConnectException; -import org.onap.so.cloudify.base.client.CloudifyRequest; -import org.onap.so.cloudify.base.client.CloudifyResponseException; -import org.onap.so.cloudify.beans.DeploymentInfo; -import org.onap.so.cloudify.beans.DeploymentInfoBuilder; -import org.onap.so.cloudify.beans.DeploymentStatus; -import org.onap.so.cloudify.exceptions.MsoCloudifyException; -import org.onap.so.cloudify.exceptions.MsoCloudifyManagerNotFound; -import org.onap.so.cloudify.exceptions.MsoDeploymentAlreadyExists; -import org.onap.so.cloudify.v3.client.BlueprintsResource.GetBlueprint; -import org.onap.so.cloudify.v3.client.BlueprintsResource.UploadBlueprint; -import org.onap.so.cloudify.v3.client.Cloudify; -import org.onap.so.cloudify.v3.client.DeploymentsResource.CreateDeployment; -import org.onap.so.cloudify.v3.client.DeploymentsResource.DeleteDeployment; -import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeployment; -import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeploymentOutputs; -import org.onap.so.cloudify.v3.client.ExecutionsResource.CancelExecution; -import org.onap.so.cloudify.v3.client.ExecutionsResource.GetExecution; -import org.onap.so.cloudify.v3.client.ExecutionsResource.ListExecutions; -import org.onap.so.cloudify.v3.client.ExecutionsResource.StartExecution; -import org.onap.so.cloudify.v3.model.AzureConfig; -import org.onap.so.cloudify.v3.model.Blueprint; -import org.onap.so.cloudify.v3.model.CancelExecutionParams; -import org.onap.so.cloudify.v3.model.CloudifyError; -import org.onap.so.cloudify.v3.model.CreateDeploymentParams; -import org.onap.so.cloudify.v3.model.Deployment; -import org.onap.so.cloudify.v3.model.DeploymentOutputs; -import org.onap.so.cloudify.v3.model.Execution; -import org.onap.so.cloudify.v3.model.Executions; -import org.onap.so.cloudify.v3.model.OpenstackConfig; -import org.onap.so.cloudify.v3.model.StartExecutionParams; -import org.onap.so.config.beans.PoConfig; -import org.onap.so.db.catalog.beans.CloudSite; -import org.onap.so.db.catalog.beans.CloudifyManager; -import org.onap.so.db.catalog.beans.HeatTemplateParam; -import org.onap.logging.filter.base.ErrorCode; -import org.onap.so.logger.MessageEnum; -import org.onap.so.openstack.exceptions.MsoAdapterException; -import org.onap.so.openstack.exceptions.MsoCloudSiteNotFound; -import org.onap.so.openstack.exceptions.MsoException; -import org.onap.so.openstack.exceptions.MsoExceptionCategory; -import org.onap.so.openstack.exceptions.MsoIOException; -import org.onap.so.openstack.exceptions.MsoOpenstackException; -import org.onap.so.openstack.utils.MsoCommonUtils; -import org.onap.so.utils.CryptoUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.env.Environment; -import org.springframework.stereotype.Component; - -@Component -public class MsoCloudifyUtils extends MsoCommonUtils implements VduPlugin { - - private static final String CLOUDIFY = "Cloudify"; - private static final String CREATE_DEPLOYMENT = "CreateDeployment"; - private static final String DELETE_DEPLOYMENT = "DeleteDeployment"; - private static final String TERMINATED = "terminated"; - private static final String CANCELLED = "cancelled"; - private static final String UNINSTALL = "uninstall"; - private static final String UPLOAD_BLUEPRINT = "UPLOAD_BLUEPRINT"; - - // Fetch cloud configuration each time (may be cached in CloudConfig class) - @Autowired - protected CloudConfig cloudConfig; - - @Autowired - private Environment environment; - - @Autowired - private PoConfig poConfig; - - private static final Logger logger = LoggerFactory.getLogger(MsoCloudifyUtils.class); - - // Properties names and variables (with default values) - protected String createPollIntervalProp = "org.onap.so.adapters.po.pollInterval"; - private String deletePollIntervalProp = "org.onap.so.adapters.po.pollInterval"; - - protected String createPollIntervalDefault = "15"; - private String deletePollIntervalDefault = "15"; - - private static final ObjectMapper JSON_MAPPER = new ObjectMapper(); - - /** - * Create a new Deployment from a specified blueprint, and install it in the specified cloud location and tenant. - * The blueprint identifier and parameter map are passed in as arguments, along with the cloud access credentials. - * The blueprint should have been previously uploaded to Cloudify. - * - * It is expected that parameters have been validated and contain at minimum the required parameters for the given - * template with no extra (undefined) parameters.. - * - * The deployment ID supplied by the caller must be unique in the scope of the Cloudify tenant (not the Openstack - * tenant). However, it should also be globally unique, as it will be the identifier for the resource going forward - * in Inventory. This latter is managed by the higher levels invoking this function. - * - * This function executes the "install" workflow on the newly created workflow. Cloudify will be polled for - * completion unless the client requests otherwise. - * - * An error will be thrown if the requested Deployment already exists in the specified Cloudify instance. - * - * @param cloudSiteId The cloud (may be a region) in which to create the stack. - * @param tenantId The Openstack ID of the tenant in which to create the Stack - * @param deploymentId The identifier (name) of the deployment to create - * @param blueprintId The blueprint from which to create the deployment. - * @param inputs A map of key/value inputs - * @param pollForCompletion Indicator that polling should be handled in Java vs. in the client - * @param timeoutMinutes Timeout after which the "install" will be cancelled - * @param backout Flag to delete deployment on install Failure - defaulted to True - * @return A DeploymentInfo object - * @throws MsoCloudifyException Thrown if the Cloudify API call returns an exception. - * @throws MsoIOException Thrown on Cloudify connection errors. - */ - - public DeploymentInfo createAndInstallDeployment(String cloudSiteId, String tenantId, String deploymentId, - String blueprintId, Map<String, ? extends Object> inputs, boolean pollForCompletion, int timeoutMinutes, - boolean backout) throws MsoException { - // Obtain the cloud site information where we will create the stack - Optional<CloudSite> cloudSite = cloudConfig.getCloudSite(cloudSiteId); - if (!cloudSite.isPresent()) { - throw new MsoCloudSiteNotFound(cloudSiteId); - } - - Cloudify cloudify = getCloudifyClient(cloudSite.get()); - - logger.debug("Ready to Create Deployment ({}) with input params: {}", deploymentId, inputs); - - // Build up the inputs, including: - // - from provided "environment" file - // - passed in by caller - // - special input for cloud-specific Credentials - Map<String, Object> expandedInputs = new HashMap<>(inputs); - - String platform = cloudSite.get().getPlatform(); - if (platform == null || platform.isEmpty() || ("OPENSTACK").equalsIgnoreCase(platform)) { - // Create the Cloudify OpenstackConfig with the credentials - OpenstackConfig openstackConfig = getOpenstackConfig(cloudSite.get(), tenantId); - expandedInputs.put("openstack_config", openstackConfig); - } else if (("AZURE").equalsIgnoreCase(platform)) { - // Create Cloudify AzureConfig with the credentials - AzureConfig azureConfig = getAzureConfig(cloudSite.get(), tenantId); - expandedInputs.put("azure_config", azureConfig); - } - - // Build up the parameters to create a new deployment - CreateDeploymentParams deploymentParams = new CreateDeploymentParams(); - deploymentParams.setBlueprintId(blueprintId); - deploymentParams.setInputs(expandedInputs); - - Deployment deployment = null; - try { - CreateDeployment createDeploymentRequest = cloudify.deployments().create(deploymentId, deploymentParams); - logger.debug(createDeploymentRequest.toString()); - - deployment = executeAndRecordCloudifyRequest(createDeploymentRequest); - } catch (CloudifyResponseException e) { - // Since this came on the 'Create Deployment' command, nothing was changed - // in the cloud. Return the error as an exception. - if (e.getStatus() == 409) { - // Deployment already exists. Return a specific error for this case - MsoException me = new MsoDeploymentAlreadyExists(deploymentId, cloudSiteId); - me.addContext(CREATE_DEPLOYMENT); - throw me; - } else { - // Convert the CloudifyResponseException to an MsoException - logger.debug("ERROR STATUS = {},\n{}\n{}", e.getStatus(), e.getMessage(), e.getLocalizedMessage()); - MsoException me = cloudifyExceptionToMsoException(e, CREATE_DEPLOYMENT); - me.setCategory(MsoExceptionCategory.OPENSTACK); - throw me; - } - } catch (CloudifyConnectException e) { - // Error connecting to Cloudify instance. Convert to an MsoException - throw cloudifyExceptionToMsoException(e, CREATE_DEPLOYMENT); - } catch (RuntimeException e) { - // Catch-all - throw runtimeExceptionToMsoException(e, CREATE_DEPLOYMENT); - } - - /* - * It can take some time for Cloudify to be ready to execute a workflow on the deployment. Sleep 30 seconds - * based on observation of behavior in a Cloudify VM instance (delay due to "create_deployment_environment"). - */ - sleep(30000); - - /* - * Next execute the "install" workflow. Note - this assumes there are no additional parameters required for the - * workflow. - */ - int createPollInterval = - Integer.parseInt(this.environment.getProperty(createPollIntervalProp, createPollIntervalDefault)); - int pollTimeout = (timeoutMinutes * 60) + createPollInterval; - - Execution installWorkflow = null; - - try { - installWorkflow = executeWorkflow(cloudify, deploymentId, "install", null, pollForCompletion, pollTimeout, - createPollInterval); - - if (installWorkflow.getStatus().equals(TERMINATED)) { - // Success! - // Create and return a DeploymentInfo structure. Include the Runtime outputs - return new DeploymentInfoBuilder().withId(deployment.getId()) - .withDeploymentInputs(deployment.getInputs()) - .withDeploymentOutputs(getDeploymentOutputs(cloudify, deploymentId).get()) - .fromExecution(installWorkflow).build(); - } else { - // The workflow completed with errors. Must try to back it out. - if (!backout) { - logger.warn("{} Deployment installation failed, backout deletion suppressed {} {}", - MessageEnum.RA_CREATE_STACK_ERR, ErrorCode.BusinessProcessError.getValue(), - "Exception in Deployment Installation, backout suppressed"); - } else { - // Poll on delete if we rollback - use same values for now - int deletePollInterval = createPollInterval; - int deletePollTimeout = pollTimeout; - - try { - // Run the uninstall to undo the install - Execution uninstallWorkflow = executeWorkflow(cloudify, deploymentId, UNINSTALL, null, - pollForCompletion, deletePollTimeout, deletePollInterval); - - if (uninstallWorkflow.getStatus().equals(TERMINATED)) { - // The uninstall completed. Delete the deployment itself - DeleteDeployment deleteRequest = cloudify.deployments().deleteByName(deploymentId); - executeAndRecordCloudifyRequest(deleteRequest); - } else { - // Didn't uninstall successfully. Log this error - logger.error("{} Create Deployment: Cloudify error rolling back deployment install: {} {}", - MessageEnum.RA_CREATE_STACK_ERR, installWorkflow.getError(), - ErrorCode.BusinessProcessError.getValue()); - } - } catch (Exception e) { - // Catch-all for backout errors trying to uninstall/delete - // Log this error, and return the original exception - logger.error("{} Create Stack: Nested exception rolling back deployment install: {}", - MessageEnum.RA_CREATE_STACK_ERR, ErrorCode.BusinessProcessError.getValue(), e); - } - } - - MsoCloudifyException me = - new MsoCloudifyException(0, "Workflow Execution Failed", installWorkflow.getError()); - me.addContext(CREATE_DEPLOYMENT); - - throw me; - } - } catch (MsoException me) { - // Install failed. Unless requested otherwise, back out the deployment - - if (!backout) { - logger.warn("{} Deployment installation failed, backout deletion suppressed {}", - MessageEnum.RA_CREATE_STACK_ERR, ErrorCode.BusinessProcessError.getValue()); - } else { - // Poll on delete if we rollback - use same values for now - int deletePollInterval = createPollInterval; - int deletePollTimeout = pollTimeout; - - try { - // Run the uninstall to undo the install. - // Always try to run it, as it should be idempotent - executeWorkflow(cloudify, deploymentId, UNINSTALL, null, pollForCompletion, deletePollTimeout, - deletePollInterval); - - // Delete the deployment itself - DeleteDeployment deleteRequest = cloudify.deployments().deleteByName(deploymentId); - executeAndRecordCloudifyRequest(deleteRequest); - } catch (Exception e) { - // Catch-all for backout errors trying to uninstall/delete - // Log this error, and return the original exception - logger.error("{} Create Stack: Nested exception rolling back deployment install: {} ", - MessageEnum.RA_CREATE_STACK_ERR, ErrorCode.BusinessProcessError.getValue(), e); - } - } - - // Propagate the original exception from Stack Query. - me.addContext(CREATE_DEPLOYMENT); - - throw me; - } - } - - - /* - * Get the runtime Outputs of a deployment. Return the Map of tag/value outputs. - */ - private Optional<Map<String, Object>> getDeploymentOutputs(Cloudify cloudify, String deploymentId) - throws MsoException { - // Build and send the Cloudify request - DeploymentOutputs deploymentOutputs; - try { - GetDeploymentOutputs queryDeploymentOutputs = cloudify.deployments().outputsById(deploymentId); - logger.debug(queryDeploymentOutputs.toString()); - - deploymentOutputs = executeAndRecordCloudifyRequest(queryDeploymentOutputs); - if (deploymentOutputs != null) { - return Optional.ofNullable(deploymentOutputs.getOutputs()); - } else { - return Optional.empty(); - } - } catch (CloudifyConnectException ce) { - // Couldn't connect to Cloudify - logger.error("{} QueryDeploymentOutputs: Cloudify connection failure: {} ", MessageEnum.RA_CREATE_STACK_ERR, - ErrorCode.BusinessProcessError.getValue(), ce); - throw new MsoIOException(ce.getMessage(), ce); - } catch (CloudifyResponseException re) { - if (re.getStatus() == 404) { - // No Outputs - return Optional.empty(); - } - throw new MsoCloudifyException(re.getStatus(), re.getMessage(), re.getLocalizedMessage(), re); - } catch (Exception e) { - // Catch-all - throw new MsoAdapterException(e.getMessage(), e); - } - } - - /* - * Execute a workflow on a deployment. Handle polling for completion with timeout. Return the final Execution object - * with status. Throw an exception on Errors. Question - how does the client know whether rollback needs to be done? - */ - private Execution executeWorkflow(Cloudify cloudify, String deploymentId, String workflowId, - Map<String, Object> workflowParams, boolean pollForCompletion, int timeout, int pollInterval) - throws MsoCloudifyException { - logger.debug("Executing '{}' workflow on deployment '{}'", workflowId, deploymentId); - - StartExecutionParams executeParams = new StartExecutionParams(); - executeParams.setWorkflowId(workflowId); - executeParams.setDeploymentId(deploymentId); - executeParams.setParameters(workflowParams); - - Execution execution = null; - String executionId = null; - String command = "start"; - Exception savedException = null; - - try { - StartExecution executionRequest = cloudify.executions().start(executeParams); - logger.debug(executionRequest.toString()); - execution = executeAndRecordCloudifyRequest(executionRequest); - executionId = execution.getId(); - - if (!pollForCompletion) { - // Client did not request polling, so just return the Execution object - return execution; - } - - // Enter polling loop - boolean timedOut = false; - int pollTimeout = timeout; - - String status = execution.getStatus(); - - // Create a reusable cloudify query request - GetExecution queryExecution = cloudify.executions().byId(executionId); - command = "query"; - - while (!timedOut && !(status.equals(TERMINATED) || ("failed").equals(status) || status.equals(CANCELLED))) { - // workflow is still running; check for timeout - if (pollTimeout <= 0) { - logger.debug("workflow {} timed out on deployment {}", execution.getWorkflowId(), - execution.getDeploymentId()); - timedOut = true; - continue; - } - - sleep(pollInterval * 1000L); - - pollTimeout -= pollInterval; - logger.debug("pollTimeout remaining: " + pollTimeout); - - execution = queryExecution.execute(); - if (execution != null) { - status = execution.getStatus(); - } else { - status = TERMINATED; - } - } - - // Broke the loop. Check again for a terminal state - if (status.equals(TERMINATED)) { - // Success! - logger.debug("Workflow '{}' completed successfully on deployment '{}'", workflowId, deploymentId); - return execution; - } else if (("failed").equals(status)) { - // Workflow failed. Log it and return the execution object (don't throw exception here) - logger.error("{} Cloudify workflow failure: {} {} Execute Workflow: Failed: {}", - MessageEnum.RA_CREATE_STACK_ERR, execution.getError(), - ErrorCode.BusinessProcessError.getValue(), execution.getError()); - return execution; - } else if (status.equals(CANCELLED)) { - // Workflow was cancelled, leaving the deployment in an indeterminate state. Log it and return the - // execution object (don't throw exception here) - logger.error("{} Cloudify workflow cancelled. Deployment is in an indeterminate state {} {} {}", - MessageEnum.RA_CREATE_STACK_ERR, ErrorCode.BusinessProcessError.getValue(), - "Execute Workflow cancelled: ", workflowId); - return execution; - } else { - // Can only get here after a timeout - logger.error("{} Cloudify workflow timeout {} Execute Workflow: Timed Out", - MessageEnum.RA_CREATE_STACK_ERR, ErrorCode.BusinessProcessError.getValue()); - } - } catch (CloudifyConnectException ce) { - logger.error("{} {} Execute Workflow ({} {}): Cloudify connection failure {} ", - MessageEnum.RA_CREATE_STACK_ERR, ErrorCode.BusinessProcessError.getValue(), command, ce); - savedException = ce; - } catch (CloudifyResponseException re) { - logger.error("{} {} Execute Workflow ({}): Cloudify response error {} ", MessageEnum.RA_CREATE_STACK_ERR, - ErrorCode.BusinessProcessError.getValue(), command, re.getMessage(), re); - savedException = re; - } catch (RuntimeException e) { - // Catch-all - logger.error("{} {} Execute Workflow ({}): Internal error {}", MessageEnum.RA_CREATE_STACK_ERR, - ErrorCode.BusinessProcessError.getValue(), command, e.getMessage(), e); - savedException = e; - } - - // Get to this point ONLY on an error or timeout - // The cloudify execution is still running (we've not received a terminal status), - // so try to Cancel it. - CancelExecutionParams cancelParams = new CancelExecutionParams(); - cancelParams.setAction("cancel"); - // TODO: Use force_cancel? - - Execution cancelExecution = null; - - try { - CancelExecution cancelRequest = cloudify.executions().cancel(executionId, cancelParams); - logger.debug(cancelRequest.toString()); - cancelExecution = cancelRequest.execute(); - - // Enter polling loop - boolean timedOut = false; - int cancelTimeout = timeout; // TODO: For now, just use same timeout - - String status = null; - if (cancelExecution != null) { - status = cancelExecution.getStatus(); - } - // Poll for completion. Create a reusable cloudify query request - GetExecution queryExecution = cloudify.executions().byId(executionId); - - while (!timedOut && !CANCELLED.equals(status)) { - // workflow is still running; check for timeout - if (cancelTimeout <= 0) { - logger.debug("Cancel timeout for workflow {} on deployment {}", workflowId, deploymentId); - timedOut = true; - continue; - } - - sleep(pollInterval * 1000L); - - cancelTimeout -= pollInterval; - logger.debug("pollTimeout remaining: {}", cancelTimeout); - - execution = queryExecution.execute(); - if (execution != null) { - status = execution.getStatus(); - } - } - - // Broke the loop. Check again for a terminal state - if (CANCELLED.equals(status)) { - // Finished cancelling. Return the original exception - logger.debug("Cancel workflow {} completed on deployment {}", workflowId, deploymentId); - throw new MsoCloudifyException(-1, "", "", savedException); - } else { - // Can only get here after a timeout - logger.debug("Cancel workflow {} timeout out on deployment {}", workflowId, deploymentId); - MsoCloudifyException exception = new MsoCloudifyException(-1, "", "", savedException); - exception.setPendingWorkflow(true); - throw exception; - } - } catch (Exception e) { - // Catch-all. Log the message and throw the original exception - logger.debug("Cancel workflow {} failed for deployment {} :", workflowId, deploymentId, e); - MsoCloudifyException exception = new MsoCloudifyException(-1, "", "", savedException); - exception.setPendingWorkflow(true); - throw exception; - } - } - - - - /** - * Query for a Cloudify Deployment (by Name). This call will always return a DeploymentInfo object. If the - * deployment does not exist, an "empty" DeploymentInfo will be returned - containing only the deployment ID and a - * special status of NOTFOUND. - * - * @param tenantId The Openstack ID of the tenant in which to query - * @param cloudSiteId The cloud identifier (may be a region) in which to query - * @return A StackInfo object - * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception. - */ - public DeploymentInfo queryDeployment(String cloudSiteId, String tenantId, String deploymentId) - throws MsoException { - logger.debug("Query Cloudify Deployment: {} in tenant {}", deploymentId, tenantId); - - // Obtain the cloud site information where we will create the stack - Optional<CloudSite> cloudSite = cloudConfig.getCloudSite(cloudSiteId); - if (!cloudSite.isPresent()) { - throw new MsoCloudSiteNotFound(cloudSiteId); - } - - Cloudify cloudify = getCloudifyClient(cloudSite.get()); - - // Build and send the Cloudify request - Deployment deployment = new Deployment(); - try { - GetDeployment queryDeployment = cloudify.deployments().byId(deploymentId); - logger.debug(queryDeployment.toString()); - deployment = executeAndRecordCloudifyRequest(queryDeployment); - - // Next look for the latest execution - ListExecutions listExecutions = - cloudify.executions().listFiltered("deployment_id=" + deploymentId, "-created_at"); - Executions executions = listExecutions.execute(); - - // If no executions, does this give NOT_FOUND or empty set? - if (executions == null || executions.getItems().isEmpty()) { - return new DeploymentInfoBuilder().withId(deployment.getId()) - .withDeploymentInputs(deployment.getInputs()).build(); - } else { - return new DeploymentInfoBuilder().withId(deployment.getId()) - .withDeploymentInputs(deployment.getInputs()) - .withDeploymentOutputs(getDeploymentOutputs(cloudify, deploymentId).get()) - .fromExecution(executions.getItems().get(0)).build(); - } - } catch (CloudifyConnectException ce) { - // Couldn't connect to Cloudify - logger.error("{} QueryDeployment: Cloudify connection failure: {} ", MessageEnum.RA_CREATE_STACK_ERR, - ErrorCode.BusinessProcessError.getValue(), ce); - throw new MsoIOException(ce.getMessage(), ce); - } catch (CloudifyResponseException re) { - if (re.getStatus() == 404) { - // Got a NOT FOUND error. React differently based on deployment vs. execution - if (deployment != null) { - // Got NOT_FOUND on the executions. Assume this is a valid "empty" set - return new DeploymentInfoBuilder().withId(deployment.getId()) - .withDeploymentInputs(deployment.getInputs()) - .withDeploymentOutputs(getDeploymentOutputs(cloudify, deploymentId).get()).build(); - } else { - // Deployment not found. Default status of a DeploymentInfo object is NOTFOUND - return new DeploymentInfoBuilder().withId(deploymentId).build(); - } - } - throw new MsoCloudifyException(re.getStatus(), re.getMessage(), re.getLocalizedMessage(), re); - } catch (Exception e) { - // Catch-all - throw new MsoAdapterException(e.getMessage(), e); - } - } - - - /** - * Delete a Cloudify deployment (by ID). If the deployment is not found, it will be considered a successful - * deletion. The return value is a DeploymentInfo object which contains the last deployment status. - * - * There is no rollback from a successful deletion. A deletion failure will also result in an undefined deployment - * state - the components may or may not have been all or partially deleted, so the resulting deployment must be - * considered invalid. - * - * @param tenantId The Openstack ID of the tenant in which to perform the delete - * @param cloudSiteId The cloud identifier (may be a region) from which to delete the stack. - * @return A StackInfo object - * @throws MsoOpenstackException Thrown if the Openstack API call returns an exception. - * @throws MsoCloudSiteNotFound - */ - public DeploymentInfo uninstallAndDeleteDeployment(String cloudSiteId, String tenantId, String deploymentId, - int timeoutMinutes) throws MsoException { - // Obtain the cloud site information where we will create the stack - Optional<CloudSite> cloudSite = cloudConfig.getCloudSite(cloudSiteId); - if (!cloudSite.isPresent()) { - throw new MsoCloudSiteNotFound(cloudSiteId); - } - - Cloudify cloudify = getCloudifyClient(cloudSite.get()); - - logger.debug("Ready to Uninstall/Delete Deployment ({})", deploymentId); - - // Query first to save the trouble if deployment not found - try { - GetDeployment queryDeploymentRequest = cloudify.deployments().byId(deploymentId); - logger.debug(queryDeploymentRequest.toString()); - - // deployment = executeAndRecordCloudifyRequest (queryDeploymentRequest); - } catch (CloudifyResponseException e) { - // Since this came on the 'Create Deployment' command, nothing was changed - // in the cloud. Return the error as an exception. - if (e.getStatus() == 404) { - // Deployment doesn't exist. Return a "NOTFOUND" DeploymentInfo object - // TODO: Should return NULL? - logger.debug("Deployment requested for deletion does not exist: {}", deploymentId); - return new DeploymentInfoBuilder().withId(deploymentId).withStatus(DeploymentStatus.NOTFOUND).build(); - } else { - // Convert the CloudifyResponseException to an MsoOpenstackException - logger.debug("ERROR STATUS = {}, \n {}\n {}\n {}", e.getStatus(), e.getMessage(), - e.getLocalizedMessage(), e); - MsoException me = cloudifyExceptionToMsoException(e, DELETE_DEPLOYMENT); - me.setCategory(MsoExceptionCategory.INTERNAL); - throw me; - } - } catch (CloudifyConnectException e) { - // Error connecting to Cloudify instance. Convert to an MsoException - throw cloudifyExceptionToMsoException(e, DELETE_DEPLOYMENT); - } catch (RuntimeException e) { - // Catch-all - throw runtimeExceptionToMsoException(e, DELETE_DEPLOYMENT); - } - - /* - * Query the outputs before deleting so they can be returned as well - */ - // DeploymentOutputs outputs = getDeploymentOutputs (cloudify, deploymentId); - - /* - * Next execute the "uninstall" workflow. Note - this assumes there are no additional parameters required for - * the workflow. - */ - // TODO: No deletePollInterval that I'm aware of. Use the create interval - int deletePollInterval = - Integer.parseInt(this.environment.getProperty(deletePollIntervalProp, deletePollIntervalDefault)); - int pollTimeout = (timeoutMinutes * 60) + deletePollInterval; - - Execution uninstallWorkflow = null; - - try { - uninstallWorkflow = - executeWorkflow(cloudify, deploymentId, UNINSTALL, null, true, pollTimeout, deletePollInterval); - - if (uninstallWorkflow.getStatus().equals(TERMINATED)) { - // Successful uninstall. - logger.debug("Uninstall successful for deployment {}", deploymentId); - } else { - // The uninstall workflow completed with an error. Must fail the request, but will - // leave the deployment in an indeterminate state, as cloud resources may still exist. - MsoCloudifyException me = - new MsoCloudifyException(0, "Uninstall Workflow Failed", uninstallWorkflow.getError()); - me.addContext(DELETE_DEPLOYMENT); - - throw me; - } - } catch (MsoException me) { - // Uninstall workflow has failed. - // Must fail the deletion... may leave the deployment in an inconclusive state - me.addContext(DELETE_DEPLOYMENT); - - throw me; - } - - // At this point, the deployment has been successfully uninstalled. - // Next step is to delete the deployment itself - Deployment deployment; - try { - DeleteDeployment deleteRequest = cloudify.deployments().deleteByName(deploymentId); - logger.debug(deleteRequest.toString()); - - // The delete request returns the deleted deployment - deployment = deleteRequest.execute(); - - } catch (CloudifyConnectException ce) { - // Failed to delete. Must fail the request, but will leave the (uninstalled) - // deployment in Cloudify DB. - MsoCloudifyException me = new MsoCloudifyException(0, "Deployment Delete Failed", ce.getMessage(), ce); - me.addContext(DELETE_DEPLOYMENT); - - throw me; - } catch (CloudifyResponseException re) { - // Failed to delete. Must fail the request, but will leave the (uninstalled) - // deployment in the Cloudify DB. - MsoCloudifyException me = new MsoCloudifyException(re.getStatus(), re.getMessage(), re.getMessage(), re); - me.addContext(DELETE_DEPLOYMENT); - - throw me; - } catch (Exception e) { - // Catch-all - MsoAdapterException ae = new MsoAdapterException(e.getMessage(), e); - ae.addContext(DELETE_DEPLOYMENT); - - throw ae; - } - - // Return the deleted deployment info (with runtime outputs) along with the completed uninstall workflow status - return new DeploymentInfoBuilder().withId(deployment.getId()).withDeploymentInputs(deployment.getInputs()) - .withDeploymentOutputs(getDeploymentOutputs(cloudify, deploymentId).get()) - .fromExecution(uninstallWorkflow).build(); - } - - - /** - * Check if a blueprint is available for use at a targeted cloud site. This requires checking the Cloudify Manager - * which is servicing that cloud site to see if the specified blueprint has been loaded. - * - * @param cloudSiteId The cloud site where the blueprint is needed - * @param blueprintId The ID for the blueprint in Cloudify - */ - public boolean isBlueprintLoaded(String cloudSiteId, String blueprintId) throws MsoException { - // Obtain the cloud site information where we will load the blueprint - Optional<CloudSite> cloudSite = cloudConfig.getCloudSite(cloudSiteId); - if (!cloudSite.isPresent()) { - throw new MsoCloudSiteNotFound(cloudSiteId); - } - - Cloudify cloudify = getCloudifyClient(cloudSite.get()); - - GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); - try { - Blueprint bp = getRequest.execute(); - if (bp != null) { - logger.debug("Blueprint exists: {}", bp.getId()); - return true; - } else { - logger.debug("Null blueprint!"); - return false; - } - } catch (CloudifyResponseException ce) { - if (ce.getStatus() == 404) { - return false; - } else { - throw ce; - } - } - } - - /** - * Upload a blueprint to the Cloudify Manager that is servicing a Cloud Site. The blueprint currently must be - * structured as a single directory with all of the required files. One of those files is designated the "main file" - * for the blueprint. Files are provided as byte arrays, though expect only text files will be distributed from ASDC - * and stored by MSO. - * - * Cloudify requires a single root directory in its blueprint zip files. The requested blueprint ID will also be - * used as the directory. All of the files will be added to this directory in the zip file. - */ - public void uploadBlueprint(String cloudSiteId, String blueprintId, String mainFileName, - Map<String, byte[]> blueprintFiles, boolean failIfExists) throws MsoException { - // Obtain the cloud site information where we will load the blueprint - Optional<CloudSite> cloudSite = cloudConfig.getCloudSite(cloudSiteId); - if (!cloudSite.isPresent()) { - throw new MsoCloudSiteNotFound(cloudSiteId); - } - - Cloudify cloudify = getCloudifyClient(cloudSite.get()); - - boolean blueprintUploaded = uploadBlueprint(cloudify, blueprintId, mainFileName, blueprintFiles); - - if (!blueprintUploaded && failIfExists) { - throw new MsoAdapterException("Blueprint already exists"); - } - } - - /* - * Common method to load a blueprint. May be called from - */ - protected boolean uploadBlueprint(Cloudify cloudify, String blueprintId, String mainFileName, - Map<String, byte[]> blueprintFiles) throws MsoException { - // Check if it already exists. If so, return false. - GetBlueprint getRequest = cloudify.blueprints().getMetadataById(blueprintId); - try { - Blueprint bp = getRequest.execute(); - if (bp != null) { - logger.debug("Blueprint {} already exists.", bp.getId()); - return false; - } else { - logger.debug("Null blueprint!"); - } - } catch (CloudifyResponseException ce) { - if (ce.getStatus() == 404) { - // This is the expected result. - logger.debug("Verified that Blueprint doesn't exist yet"); - } else { - throw ce; - } - } - - // Create a blueprint ZIP file in memory - ByteArrayOutputStream zipBuffer = new ByteArrayOutputStream(); - ZipOutputStream zipOut = new ZipOutputStream(zipBuffer); - - try { - // Put the root directory - String rootDir = blueprintId + (blueprintId.endsWith("/") ? "" : "/"); - zipOut.putNextEntry(new ZipEntry(rootDir)); - zipOut.closeEntry(); - - for (String fileName : blueprintFiles.keySet()) { - ZipEntry ze = new ZipEntry(rootDir + fileName); - zipOut.putNextEntry(ze); - zipOut.write(blueprintFiles.get(fileName)); - zipOut.closeEntry(); - } - zipOut.close(); - } catch (IOException e) { - // Since we're writing to a byte array, this should never happen - } - logger.debug("Blueprint zip file size: {}", zipBuffer.size()); - - // Ready to upload the blueprint zip - - try (InputStream blueprintStream = new ByteArrayInputStream(zipBuffer.toByteArray())) { - UploadBlueprint uploadRequest = - cloudify.blueprints().uploadFromStream(blueprintId, mainFileName, blueprintStream); - Blueprint blueprint = uploadRequest.execute(); - logger.debug("Successfully uploaded blueprint {}", blueprint.getId()); - } catch (CloudifyResponseException | CloudifyConnectException e) { - throw cloudifyExceptionToMsoException(e, UPLOAD_BLUEPRINT); - } catch (RuntimeException e) { - // Catch-all - throw runtimeExceptionToMsoException(e, UPLOAD_BLUEPRINT); - } catch (IOException e) { - // for try-with-resources - throw ioExceptionToMsoException(e, UPLOAD_BLUEPRINT); - } - - return true; - } - - - - // --------------------------------------------------------------- - // PRIVATE FUNCTIONS FOR USE WITHIN THIS CLASS - - /** - * Get a Cloudify client for the specified cloud site. Everything that is required can be found in the Cloud Config. - * - * @param cloudSite - * @return a Cloudify object - */ - public Cloudify getCloudifyClient(CloudSite cloudSite) throws MsoException { - CloudifyManager cloudifyConfig = cloudConfig.getCloudifyManager(cloudSite.getCloudifyId()); - if (cloudifyConfig == null) { - throw new MsoCloudifyManagerNotFound(cloudSite.getId()); - } - - // Get a Cloudify client - // Set a Token Provider to fetch tokens from Cloudify itself. - String cloudifyUrl = cloudifyConfig.getCloudifyUrl(); - Cloudify cloudify = new Cloudify(cloudifyUrl); - cloudify.setTokenProvider(new CloudifyClientTokenProvider(cloudifyUrl, cloudifyConfig.getUsername(), - CryptoUtils.decryptCloudConfigPassword(cloudifyConfig.getPassword()))); - - return cloudify; - } - - - /* - * Query for a Cloudify Deployment. This function is needed in several places, so a common method is useful. This - * method takes an authenticated CloudifyClient (which internally identifies the cloud & tenant to search), and - * returns a Deployment object if found, Null if not found, or an MsoCloudifyException if the Cloudify API call - * fails. - * - * @param cloudifyClient an authenticated Cloudify client - * - * @param deploymentId the deployment to query - * - * @return a Deployment object or null if the requested deployment doesn't exist. - * - * @throws MsoCloudifyException Thrown if the Cloudify API call returns an exception - */ - protected Deployment queryDeployment(Cloudify cloudify, String deploymentId) throws MsoException { - if (deploymentId == null) { - return null; - } - try { - GetDeployment request = cloudify.deployments().byId(deploymentId); - return executeAndRecordCloudifyRequest(request); - } catch (CloudifyResponseException e) { - if (e.getStatus() == 404) { - logger.debug("queryDeployment - not found: {}", deploymentId); - return null; - } else { - // Convert the CloudifyResponseException to an MsoCloudifyException - throw cloudifyExceptionToMsoException(e, "QueryDeployment"); - } - } catch (CloudifyConnectException e) { - // Connection to Openstack failed - throw cloudifyExceptionToMsoException(e, "QueryDeployment"); - } - } - - - public void copyStringOutputsToInputs(Map<String, String> inputs, Map<String, Object> otherStackOutputs, - boolean overWrite) { - if (inputs == null || otherStackOutputs == null) - return; - - for (Map.Entry<String, Object> entry : otherStackOutputs.entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); - - if (value instanceof JsonNode) { - // This is a bit of mess - but I think it's the least impacting - // let's convert it BACK to a string - then it will get converted back later - try { - inputs.put(key, this.convertNode((JsonNode) value)); - } catch (Exception e) { - logger.debug("WARNING: unable to convert JsonNode output value for {}", key); - // effect here is this value will not have been copied to the inputs - and therefore will error out - // downstream - } - } else if (value instanceof java.util.LinkedHashMap) { - logger.debug("LinkedHashMap - this is showing up as a LinkedHashMap instead of JsonNode"); - try { - inputs.put(key, JSON_MAPPER.writeValueAsString(value)); - } catch (Exception e) { - logger.debug("WARNING: unable to convert LinkedHashMap output value for {}", key); - } - } else { - // just try to cast it - could be an integer or some such - try { - inputs.put(key, (String) value); - } catch (Exception e) { - logger.debug("WARNING: unable to convert output value for {}", key); - // effect here is this value will not have been copied to the inputs - and therefore will error out - // downstream - } - } - } - return; - } - - /* - * Normalize an input value to an Object, based on the target parameter type. If the type is not recognized, it will - * just be returned unchanged (as a string). - */ - public Object convertInputValue(Object inputValue, HeatTemplateParam templateParam) { - String type = templateParam.getParamType(); - logger.debug("Parameter: {} is of type {}", templateParam.getParamName(), type); - - if (("number").equalsIgnoreCase(type)) { - try { - return Integer.valueOf(inputValue.toString()); - } catch (Exception e) { - logger.debug("Unable to convert {} to an integer!", inputValue); - return null; - } - } else if (("json").equalsIgnoreCase(type)) { - try { - if (inputValue instanceof String) { - return JSON_MAPPER.readTree(inputValue.toString()); - } - // will already marshal to json without intervention - return inputValue; - } catch (Exception e) { - logger.debug("Unable to convert {} to a JsonNode!", inputValue); - return null; - } - } else if (("boolean").equalsIgnoreCase(type)) { - return Boolean.valueOf(inputValue.toString()); - } - - // Nothing else matched. Return the original string - return inputValue; - } - - - private String convertNode(final JsonNode node) { - try { - final Object obj = JSON_MAPPER.treeToValue(node, Object.class); - return JSON_MAPPER.writeValueAsString(obj); - } catch (JsonParseException jpe) { - logger.debug("Error converting json to string {}", jpe); - } catch (Exception e) { - logger.debug("Error converting json to string {}", e); - } - return "[Error converting json to string]"; - } - - - /* - * Method to execute a Cloudify command and track its execution time. For the metrics log, a category of "Cloudify" - * is used along with a sub-category that identifies the specific call (using the real cloudify-client classname of - * the CloudifyRequest<T> parameter). - */ - - - protected <T> T executeAndRecordCloudifyRequest(CloudifyRequest<T> request) { - - String requestType; - if (request.getClass().getEnclosingClass() != null) { - requestType = - request.getClass().getEnclosingClass().getSimpleName() + "." + request.getClass().getSimpleName(); - } else { - requestType = request.getClass().getSimpleName(); - } - - int retryDelay = poConfig.getRetryDelay(); - int retryCount = poConfig.getRetryCount(); - String retryCodes = poConfig.getRetryCodes(); - - // Run the actual command. All exceptions will be propagated - while (true) { - try { - return request.execute(); - } catch (CloudifyResponseException e) { - boolean retry = false; - if (retryCodes != null) { - int code = e.getStatus(); - logger.debug("Config values RetryDelay: {} RetryCount:{} RetryCodes:{} ResponseCode:{}", retryDelay, - retryCount, retryCodes, code); - for (String rCode : retryCodes.split(",")) { - try { - if (retryCount > 0 && code == Integer.parseInt(rCode)) { - retryCount--; - retry = true; - logger.debug( - "CloudifyResponseException ResponseCode:{} request:{} Retry indicated. Attempts remaining:{}", - code, requestType, retryCount); - break; - } - } catch (NumberFormatException e1) { - logger.error("{} No retries. Exception in parsing retry code in config:{} {}", - MessageEnum.RA_CONFIG_EXC, rCode, ErrorCode.SchemaError.getValue()); - throw e; - } - } - } - if (retry) { - sleep(retryDelay * 1000L); - } else - throw e; // exceeded retryCount or code is not retryable - } catch (CloudifyConnectException e) { - // Connection to Cloudify failed - if (retryCount > 0) { - retryCount--; - logger.debug(" request: {} Retry indicated. Attempts remaining:{}", requestType, retryCount); - sleep(retryDelay * 1000L); - } else - throw e; - - } - } - } - - /* - * Convert an Exception on a Cloudify call to an MsoCloudifyException. This method supports - * CloudifyResponseException and CloudifyConnectException. - */ - protected MsoException cloudifyExceptionToMsoException(CloudifyBaseException e, String context) { - MsoException me = null; - - if (e instanceof CloudifyResponseException) { - CloudifyResponseException re = (CloudifyResponseException) e; - - try { - // Failed Cloudify calls return an error entity body. - CloudifyError error = re.getResponse().getErrorEntity(CloudifyError.class); - logger.error("{} {} {} Exception - Cloudify Error on {}: {}", MessageEnum.RA_CONNECTION_EXCEPTION, - CLOUDIFY, ErrorCode.DataError.getValue(), context, error.getErrorCode()); - String fullError = error.getErrorCode() + ": " + error.getMessage(); - logger.debug(fullError); - me = new MsoCloudifyException(re.getStatus(), re.getMessage(), fullError); - } catch (Exception e2) { - // Couldn't parse the body as a "CloudifyError". Report the original HTTP error. - logger.error("{} {} {} Exception - HTTP Error on {}: {}, {} ", MessageEnum.RA_CONNECTION_EXCEPTION, - CLOUDIFY, ErrorCode.DataError.getValue(), context, re.getStatus(), e.getMessage(), e2); - me = new MsoCloudifyException(re.getStatus(), re.getMessage(), ""); - } - - // Add the context of the error - me.addContext(context); - - // Generate an alarm for 5XX and higher errors. - if (re.getStatus() >= 500) { - - } - } else if (e instanceof CloudifyConnectException) { - CloudifyConnectException ce = (CloudifyConnectException) e; - - me = new MsoIOException(ce.getMessage()); - me.addContext(context); - - // Generate an alarm for all connection errors. - - logger.error("{} {} {} Cloudify connection error on {}: ", MessageEnum.RA_CONNECTION_EXCEPTION, CLOUDIFY, - ErrorCode.DataError.getValue(), context, e); - } - - return me; - } - - - - /******************************************************************************* - * - * Methods (and associated utilities) to implement the VduPlugin interface - * - *******************************************************************************/ - - /** - * VduPlugin interface for instantiate function. - * - * This one is a bit more complex, in that it will first upload the blueprint if needed, then create the Cloudify - * deployment and execute the install workflow. - * - * This implementation also merges any parameters defined in the ENV file with the other other input parameters for - * any undefined parameters). The basic MsoCloudifyUtils separates blueprint management from deploument actions, but - * the VduPlugin does not declare blueprint management operations. - */ - @Override - public VduInstance instantiateVdu(CloudInfo cloudInfo, String instanceName, Map<String, Object> inputs, - VduModelInfo vduModel, boolean rollbackOnFailure) throws VduException { - String cloudSiteId = cloudInfo.getCloudSiteId(); - String tenantId = cloudInfo.getTenantId(); - - // Translate the VDU ModelInformation structure to that which is needed for - // creating and uploading a blueprint. Use the model customization UUID as - // the blueprint identifier. - - String blueprintId = vduModel.getModelCustomizationUUID(); - - try { - - if (!isBlueprintLoaded(cloudSiteId, blueprintId)) { - logger.debug("Blueprint {} is not loaded. Will upload it now.", blueprintId); - - // Prepare the blueprint inputs. Need the set of blueprint templates and files, - // plus the main blueprint name. - Map<String, byte[]> blueprintFiles = new HashMap<>(); - String mainTemplate = ""; - - // Add all of the blueprint artifacts from the VDU model - List<VduArtifact> vduArtifacts = vduModel.getArtifacts(); - for (VduArtifact vduArtifact : vduArtifacts) { - // Add all artifacts to the blueprint, with one exception. - // ENVIRONMENT files will be processed later as additional parameters. - - ArtifactType artifactType = vduArtifact.getType(); - if (artifactType != ArtifactType.ENVIRONMENT) { - blueprintFiles.put(vduArtifact.getName(), vduArtifact.getContent()); - - if (artifactType == ArtifactType.MAIN_TEMPLATE) { - mainTemplate = vduArtifact.getName(); - } - } - } - - // Upload the blueprint package - uploadBlueprint(cloudSiteId, blueprintId, mainTemplate, blueprintFiles, false); - } - } catch (Exception e) { - throw new VduException("CloudifyUtils (instantiateVDU): blueprint Exception", e); - } - - - // Next, create and install a new deployment based on the blueprint. - // For Cloudify, the deploymentId is specified by the client. Just use the instance name - // as the ID. - - try { - // Query the Cloudify Deployment object and populate a VduInstance - DeploymentInfo deployment = - createAndInstallDeployment(cloudSiteId, tenantId, instanceName, blueprintId, inputs, true, // (poll - // for - // completion) - vduModel.getTimeoutMinutes(), rollbackOnFailure); - - return deploymentInfoToVduInstance(deployment); - } catch (Exception e) { - throw new VduException("CloudifyUtils (instantiateVDU): Create-and-install-deployment Exception", e); - } - } - - - /** - * VduPlugin interface for query function. - */ - @Override - public VduInstance queryVdu(CloudInfo cloudInfo, String instanceId) throws VduException { - String cloudSiteId = cloudInfo.getCloudSiteId(); - String tenantId = cloudInfo.getTenantId(); - - try { - // Query the Cloudify Deployment object and populate a VduInstance - DeploymentInfo deployment = queryDeployment(cloudSiteId, tenantId, instanceId); - - return deploymentInfoToVduInstance(deployment); - } catch (Exception e) { - throw new VduException("Query VDU Exception", e); - } - } - - - /** - * VduPlugin interface for delete function. - */ - @Override - public VduInstance deleteVdu(CloudInfo cloudInfo, String instanceId, int timeoutMinutes) throws VduException { - String cloudSiteId = cloudInfo.getCloudSiteId(); - String tenantId = cloudInfo.getTenantId(); - - try { - // Uninstall and delete the Cloudify Deployment - DeploymentInfo deployment = uninstallAndDeleteDeployment(cloudSiteId, tenantId, instanceId, timeoutMinutes); - - // Populate a VduInstance based on the deleted Cloudify Deployment object - return deploymentInfoToVduInstance(deployment); - } catch (Exception e) { - throw new VduException("Delete VDU Exception", e); - } - } - - - /** - * VduPlugin interface for update function. - * - * Update is currently not supported in the MsoCloudifyUtils implementation. Just return a VduException. - * - */ - @Override - public VduInstance updateVdu(CloudInfo cloudInfo, String instanceId, Map<String, Object> inputs, - VduModelInfo vduModel, boolean rollbackOnFailure) throws VduException { - throw new VduException("CloudifyUtils: updateVDU interface not supported"); - } - - - /* - * Convert the local DeploymentInfo object (Cloudify-specific) to a generic VduInstance object - */ - protected VduInstance deploymentInfoToVduInstance(DeploymentInfo deployment) { - VduInstance vduInstance = new VduInstance(); - - // only one ID in Cloudify, use for both VDU name and ID - vduInstance.setVduInstanceId(deployment.getId()); - vduInstance.setVduInstanceName(deployment.getId()); - - // Copy inputs and outputs - vduInstance.setInputs(deployment.getInputs()); - vduInstance.setOutputs(deployment.getOutputs()); - - // Translate the status elements - vduInstance.setStatus(deploymentStatusToVduStatus(deployment)); - - return vduInstance; - } - - protected VduStatus deploymentStatusToVduStatus(DeploymentInfo deployment) { - VduStatus vduStatus = new VduStatus(); - - // Determine the status based on last action & status - // DeploymentInfo object should be enhanced to report a better status internally. - DeploymentStatus status = deployment.getStatus(); - - if (status == null) { - vduStatus.setState(VduStateType.UNKNOWN); - } else if (status == DeploymentStatus.NOTFOUND) { - vduStatus.setState(VduStateType.NOTFOUND); - } else if (status == DeploymentStatus.INSTALLED) { - vduStatus.setState(VduStateType.INSTANTIATED); - } else if (status == DeploymentStatus.CREATED) { - // Deployment exists but is not installed. This shouldn't really happen, - // since create + install or uninstall + delete are always done together. - // But account for it anyway, assuming the operation is still in progress. - String lastAction = deployment.getLastAction(); - if (lastAction == null) - vduStatus.setState(VduStateType.INSTANTIATING); - else - vduStatus.setState(VduStateType.DELETING); - } else if (status == DeploymentStatus.FAILED) { - vduStatus.setState(VduStateType.FAILED); - } else { - vduStatus.setState(VduStateType.UNKNOWN); - } - - vduStatus.setErrorMessage(deployment.getErrorMessage()); - vduStatus.setLastAction(new PluginAction(deployment.getLastAction(), deployment.getActionStatus(), - deployment.getErrorMessage())); - - return vduStatus; - } - - /* - * Return an OpenstackConfig object as expected by Cloudify Openstack Plug-in. Base the values on the CloudSite - * definition. - */ - protected OpenstackConfig getOpenstackConfig(CloudSite cloudSite, String tenantId) { - OpenstackConfig openstackConfig = new OpenstackConfig(); - openstackConfig.setRegion(cloudSite.getRegionId()); - openstackConfig.setAuthUrl(cloudSite.getIdentityService().getIdentityUrl()); - openstackConfig.setUsername(cloudSite.getIdentityService().getMsoId()); - openstackConfig - .setPassword(CryptoUtils.decryptCloudConfigPassword(cloudSite.getIdentityService().getMsoPass())); - openstackConfig.setTenantName(tenantId); - return openstackConfig; - } - - /* - * Return an Azure object as expected by Cloudify Azure Plug-in. Base the values on the CloudSite definition. - */ - protected AzureConfig getAzureConfig(CloudSite cloudSite, String tenantId) { - AzureConfig azureConfig = new AzureConfig(); - // TODO: Use adminTenant for now, instead of adding another element - azureConfig.setSubscriptionId(cloudSite.getIdentityService().getAdminTenant()); - azureConfig.setTenantId(tenantId); - azureConfig.setClientId(cloudSite.getIdentityService().getMsoId()); - azureConfig.setClientSecret(cloudSite.getIdentityService().getMsoPass()); - return azureConfig; - } - - private void sleep(long time) { - try { - Thread.sleep(time); - } catch (InterruptedException e) { - logger.debug("Thread interrupted while sleeping!", e); - Thread.currentThread().interrupt(); - } - } -} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateHeatResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateHeatResponse.java index 16671bbe50..6eb7e3d56d 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateHeatResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateHeatResponse.java @@ -22,11 +22,11 @@ package org.onap.so.openstack.utils; import java.io.Serializable; import java.util.List; +import org.apache.commons.lang3.builder.ToStringBuilder; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({"id", "links"}) diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateLinkResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateLinkResponse.java index 1f55aa92a2..f9a8093de6 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateLinkResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateLinkResponse.java @@ -21,11 +21,11 @@ package org.onap.so.openstack.utils; import java.io.Serializable; +import org.apache.commons.lang3.builder.ToStringBuilder; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; -import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateResponse.java index 9fa4557a45..dcc4f50b45 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudCreateResponse.java @@ -21,13 +21,13 @@ package org.onap.so.openstack.utils; import java.io.Serializable; +import org.apache.commons.lang3.builder.ToStringBuilder; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.JsonNode; -import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonIgnoreProperties(ignoreUnknown = true) diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java index c575304ade..ba5e449034 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudQueryResponse.java @@ -21,12 +21,12 @@ package org.onap.so.openstack.utils; import java.io.Serializable; +import org.apache.commons.lang3.builder.ToStringBuilder; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.JsonNode; -import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({"template_type", "workload_id", "workload_status", "workload_status_reason"}) diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java index 95dd48caa6..d679b0303e 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java +++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MulticloudRequest.java @@ -21,12 +21,12 @@ package org.onap.so.openstack.utils; import java.io.Serializable; +import org.apache.commons.lang3.builder.ToStringBuilder; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.JsonNode; import com.woorea.openstack.heat.model.CreateStackParam; -import org.apache.commons.lang.builder.ToStringBuilder; @JsonInclude(JsonInclude.Include.NON_NULL) @JsonPropertyOrder({"generic-vnf-id", "vf-module-id", "vf-module-model-invariant-id", "vf-module-model-version-id", diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoBuilderTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoBuilderTest.java deleted file mode 100644 index 9fbb45a2c3..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/beans/DeploymentInfoBuilderTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * ============LICENSE_START======================================================= ONAP : SO - * ================================================================================ Copyright (C) 2018 Nokia. - * ============================================================================= Licensed under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.so.cloudify.beans; - -import static org.assertj.core.api.Assertions.assertThat; -import com.google.common.collect.ImmutableMap; -import org.junit.Test; -import org.onap.so.cloudify.v3.model.Execution; - -public class DeploymentInfoBuilderTest { - - private static final String ERROR_MESSAGE = "something went wrong"; - private static final String INSTALL_WORKFLOW_ID = "install"; - private static final String UNINSTALL_WORKFLOW_ID = "uninstall"; - - @Test - public void shouldConstructDeploymentInfo_withBasicValues() { - DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().withId("id").withStatus(DeploymentStatus.CREATED) - .withDeploymentOutputs(ImmutableMap.of()).withDeploymentInputs(ImmutableMap.of()) - .withActionStatus("started").withLastAction(INSTALL_WORKFLOW_ID).withErrorMessage(ERROR_MESSAGE) - .build(); - - assertThat(deploymentInfo.getId()).isEqualTo("id"); - assertThat(deploymentInfo.getStatus()).isEqualTo(DeploymentStatus.CREATED); - assertThat(deploymentInfo.getOutputs()).isEqualTo(ImmutableMap.of()); - assertThat(deploymentInfo.getInputs()).isEqualTo(ImmutableMap.of()); - assertThat(deploymentInfo.getActionStatus()).isEqualTo("started"); - assertThat(deploymentInfo.getLastAction()).isEqualTo(INSTALL_WORKFLOW_ID); - assertThat(deploymentInfo.getErrorMessage()).isEqualTo(ERROR_MESSAGE); - } - - @Test - public void shouldConstructDeploymentInfo_withCreateDeploymentStatus_fromNullExecution() { - DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().fromExecution(null).build(); - - assertThat(deploymentInfo.getStatus()).isEqualTo(DeploymentStatus.CREATED); - } - - @Test - public void shouldConstructDeploymentInfo_withInstalledDeploymentStatus_fromTerminatedExecution() { - String workflowIdLastAction = INSTALL_WORKFLOW_ID; - String status = "terminated"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLED; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withFailedDeploymentStatus_fromFailedInstallExecution() { - String workflowIdLastAction = INSTALL_WORKFLOW_ID; - String status = "failed"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.FAILED; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withInstallingDeploymentStatus_fromStartedExecution() { - String workflowIdLastAction = INSTALL_WORKFLOW_ID; - String status = "started"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLING; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withInstallingDeploymentStatus_fromPendingExecution() { - String workflowIdLastAction = INSTALL_WORKFLOW_ID; - String status = "pending"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.INSTALLING; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_fromUnmappableExecution() { - String workflowIdLastAction = INSTALL_WORKFLOW_ID; - String status = "strangeStatus"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withCreatedDeploymentStatus_fromTerminatedExecution() { - String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; - String status = "terminated"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.CREATED; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withFailedDeploymentStatus_fromFailedUninstallExecution() { - String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; - String status = "failed"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.FAILED; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withUninstallingDeploymentStatus_fromStartedUninstallExecution() { - String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; - String status = "started"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNINSTALLING; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withUninstallingDeploymentStatus_fromPendingUninstallExecution() { - String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; - String status = "pending"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNINSTALLING; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_fromUnmappableUninstallExecution() { - String workflowIdLastAction = UNINSTALL_WORKFLOW_ID; - String status = "strangeStatus"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldConstructDeploymentInfo_withUnknownDeploymentStatus_forUnknownExecutionWorkflowId() { - String workflowIdLastAction = "strangeWorkflowIdLastAction"; - String status = "strangeStatus"; - DeploymentStatus expectedDeploymentStatus = DeploymentStatus.UNKNOWN; - verifyDeploymentInfoConstruction(workflowIdLastAction, status, expectedDeploymentStatus); - } - - @Test - public void shouldSetEmptyOutputsMapWhenInputIsNull() { - DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().withDeploymentOutputs(null).build(); - assertThat(deploymentInfo.getOutputs()).isEmpty(); - } - - private void verifyDeploymentInfoConstruction(String workflowIdLastAction, String actionStatus, - DeploymentStatus expectedDeploymentStatus) { - - Execution execution = new Execution(); - execution.setWorkflowId(workflowIdLastAction); - execution.setStatus(actionStatus); - execution.setError(ERROR_MESSAGE); - DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().fromExecution(execution).build(); - - assertThat(deploymentInfo.getLastAction()).isEqualTo(workflowIdLastAction); - assertThat(deploymentInfo.getActionStatus()).isEqualTo(actionStatus); - assertThat(deploymentInfo.getErrorMessage()).isEqualTo(ERROR_MESSAGE); - assertThat(deploymentInfo.getStatus()).isEqualTo(expectedDeploymentStatus); - } -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyExceptionTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyExceptionTest.java deleted file mode 100644 index 1506fda817..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyExceptionTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * ============LICENSE_START======================================================= ONAP : SO - * ================================================================================ Copyright (C) 2018 TechMahindra - * ================================================================================ Licensed under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.exceptions; - -import static org.junit.Assert.*; -import org.junit.Test; - -public class MsoCloudifyExceptionTest { - - @Test - public void test() { - Exception e = null; - boolean pendingWorkflow = true; - MsoCloudifyException mce = new MsoCloudifyException(200, "message", "detail"); - MsoCloudifyException mcl = new MsoCloudifyException(200, "message", "detail", e); - mce.setPendingWorkflow(pendingWorkflow); - assert (mcl.toString() != null); - assertNotNull(mce); - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTest.java deleted file mode 100644 index 25dcae3c2c..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * ============LICENSE_START======================================================= ONAP : SO - * ================================================================================ Copyright (C) 2018 TechMahindra - * ================================================================================ Licensed under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.so.cloudify.exceptions; - -import static org.junit.Assert.*; -import org.junit.Test; - -public class MsoCloudifyTest { - - @Test - public void test() { - MsoBlueprintAlreadyExists mbae = new MsoBlueprintAlreadyExists("blueprintId", "cloud"); - MsoCloudifyManagerNotFound mcm = new MsoCloudifyManagerNotFound("cloudSiteId"); - MsoDeploymentAlreadyExists mdae = new MsoDeploymentAlreadyExists("deploymentId", "cloud"); - assertNotNull((mbae)); - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTimeoutTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTimeoutTest.java deleted file mode 100644 index dc74d83d04..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyTimeoutTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * ============LICENSE_START======================================================= ONAP : SO - * ================================================================================ Copyright (C) 2018 TechMahindra - * ================================================================================ Licensed under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.so.cloudify.exceptions; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import org.junit.Test; -import org.onap.so.cloudify.v3.model.Execution; - -public class MsoCloudifyTimeoutTest { - - @Test - public void test() { - Execution execution = mock(Execution.class); - MsoCloudifyTimeout mct = new MsoCloudifyTimeout(execution); - mct.getExecution(); - assert (mct.toString() != null); - assertNotNull(mct); - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowExceptionTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowExceptionTest.java deleted file mode 100644 index b8b2c97a65..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/exceptions/MsoCloudifyWorkflowExceptionTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * ============LICENSE_START======================================================= ONAP : SO - * ================================================================================ Copyright (C) 2018 TechMahindra - * ================================================================================ Licensed under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.so.cloudify.exceptions; - -import static org.junit.Assert.*; -import org.junit.Test; - -public class MsoCloudifyWorkflowExceptionTest { - - @Test - public void test() { - MsoCloudifyWorkflowException mcw = - new MsoCloudifyWorkflowException("message", "id", "workflowId", "workflowStatus"); - mcw.getWorkflowStatus(); - assertFalse(mcw.isWorkflowStillRunning()); - - } - -} diff --git a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java b/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java deleted file mode 100644 index d14115971c..0000000000 --- a/adapters/mso-adapter-utils/src/test/java/org/onap/so/cloudify/utils/MsoCloudifyUtilsTest.java +++ /dev/null @@ -1,336 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2018 Nokia. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.so.cloudify.utils; - -import static com.shazam.shazamcrest.MatcherAssert.assertThat; -import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mockito; -import org.onap.so.adapters.vdu.CloudInfo; -import org.onap.so.adapters.vdu.PluginAction; -import org.onap.so.adapters.vdu.VduArtifact; -import org.onap.so.adapters.vdu.VduArtifact.ArtifactType; -import org.onap.so.adapters.vdu.VduInstance; -import org.onap.so.adapters.vdu.VduModelInfo; -import org.onap.so.adapters.vdu.VduStateType; -import org.onap.so.adapters.vdu.VduStatus; -import org.onap.so.cloud.CloudConfig; -import org.onap.so.cloudify.beans.DeploymentInfo; -import org.onap.so.cloudify.beans.DeploymentInfoBuilder; -import org.onap.so.cloudify.beans.DeploymentStatus; -import org.onap.so.cloudify.v3.client.Cloudify; -import org.onap.so.cloudify.v3.model.AzureConfig; -import org.onap.so.db.catalog.beans.CloudIdentity; -import org.onap.so.db.catalog.beans.CloudSite; -import org.onap.so.db.catalog.beans.CloudifyManager; -import org.onap.so.db.catalog.beans.HeatTemplateParam; -import org.onap.so.openstack.exceptions.MsoAdapterException; -import org.onap.so.openstack.exceptions.MsoException; -import org.skyscreamer.jsonassert.JSONAssert; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class MsoCloudifyUtilsTest { - - private static final String CLOUD_SITE_ID = "cloudSiteIdTest"; - private static final String BLUEPRINT_ID = "bluePrintIdTest"; - private static final String FILE_NAME = "fileName"; - - @Test - public void instantiateVduTest() throws MsoException { - VduInstance expected = new VduInstance(); - expected.setVduInstanceId("id"); - expected.setVduInstanceName("id"); - VduStatus status = new VduStatus(); - status.setState(VduStateType.INSTANTIATED); - status.setLastAction(new PluginAction(null, null, null)); - expected.setStatus(status); - - MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); - CloudSite site = new CloudSite(); - Optional<CloudSite> opSite = Optional.ofNullable(site); - CloudConfig config = Mockito.mock(CloudConfig.class); - cloudify.cloudConfig = config; - Cloudify cloudifyClient = new Cloudify("cloudSite"); - CloudInfo cloudInfo = new CloudInfo(); - cloudInfo.setCloudSiteId("cloudSiteId"); - cloudInfo.setTenantId("tenantId"); - VduModelInfo vduModel = new VduModelInfo(); - vduModel.setModelCustomizationUUID("blueprintId"); - vduModel.setTimeoutMinutes(1); - VduArtifact artifact = new VduArtifact(); - artifact.setName("name"); - artifact.setType(ArtifactType.MAIN_TEMPLATE); - byte[] content = new byte[1]; - artifact.setContent(content); - List<VduArtifact> artifacts = new ArrayList<>(); - artifacts.add(artifact); - vduModel.setArtifacts(artifacts); - DeploymentInfo deployment = - new DeploymentInfoBuilder().withId("id").withStatus(DeploymentStatus.INSTALLED).build(); - Map<String, byte[]> blueprintFiles = new HashMap<>(); - blueprintFiles.put(artifact.getName(), artifact.getContent()); - String instanceName = "instanceName"; - Map<String, Object> inputs = new HashMap<>(); - boolean rollbackOnFailure = true; - - when(config.getCloudSite(cloudInfo.getCloudSiteId())).thenReturn(opSite); - doReturn(false).when(cloudify).isBlueprintLoaded(cloudInfo.getCloudSiteId(), - vduModel.getModelCustomizationUUID()); - doReturn(cloudifyClient).when(cloudify).getCloudifyClient(site); - doReturn(true).when(cloudify).uploadBlueprint(cloudifyClient, vduModel.getModelCustomizationUUID(), - artifact.getName(), blueprintFiles); - doReturn(deployment).when(cloudify).createAndInstallDeployment(cloudInfo.getCloudSiteId(), - cloudInfo.getTenantId(), instanceName, vduModel.getModelCustomizationUUID(), inputs, true, - vduModel.getTimeoutMinutes(), rollbackOnFailure); - - VduInstance actual = cloudify.instantiateVdu(cloudInfo, instanceName, inputs, vduModel, rollbackOnFailure); - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void queryVduTest() throws MsoException { - VduInstance expected = new VduInstance(); - expected.setVduInstanceId("id"); - expected.setVduInstanceName("id"); - VduStatus status = new VduStatus(); - status.setState(VduStateType.INSTANTIATED); - status.setLastAction(new PluginAction(null, null, null)); - expected.setStatus(status); - - CloudInfo cloudInfo = new CloudInfo(); - cloudInfo.setCloudSiteId("cloudSiteId"); - cloudInfo.setTenantId("tenantId"); - DeploymentInfo deployment = - new DeploymentInfoBuilder().withId("id").withStatus(DeploymentStatus.INSTALLED).build(); - String instanceId = "instanceId"; - - MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); - - doReturn(deployment).when(cloudify).queryDeployment(cloudInfo.getCloudSiteId(), cloudInfo.getTenantId(), - instanceId); - - VduInstance actual = cloudify.queryVdu(cloudInfo, instanceId); - - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void deleteVduTest() throws MsoException { - VduInstance expected = new VduInstance(); - expected.setVduInstanceId("id"); - expected.setVduInstanceName("id"); - VduStatus status = new VduStatus(); - status.setState(VduStateType.DELETING); - status.setLastAction(new PluginAction("deleting", null, null)); - expected.setStatus(status); - - CloudInfo cloudInfo = new CloudInfo(); - cloudInfo.setCloudSiteId("cloudSiteId"); - cloudInfo.setTenantId("tenantId"); - String instanceId = "instanceId"; - int timeoutMinutes = 1; - DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().withId("id").withStatus(DeploymentStatus.CREATED) - .withLastAction("deleting").build(); - MsoCloudifyUtils cloudify = Mockito.spy(MsoCloudifyUtils.class); - doReturn(deploymentInfo).when(cloudify).uninstallAndDeleteDeployment(cloudInfo.getCloudSiteId(), - cloudInfo.getTenantId(), instanceId, timeoutMinutes); - - VduInstance actual = cloudify.deleteVdu(cloudInfo, instanceId, timeoutMinutes); - - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void deploymentInfoToVduInstanceTest() { - VduInstance expected = new VduInstance(); - expected.setVduInstanceId("id"); - expected.setVduInstanceName("id"); - VduStatus status = new VduStatus(); - status.setState(VduStateType.DELETING); - status.setLastAction(new PluginAction("deleting", null, null)); - expected.setStatus(status); - - DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().withId("id").withStatus(DeploymentStatus.CREATED) - .withLastAction("deleting").build(); - - MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); - - VduInstance actual = cloudify.deploymentInfoToVduInstance(deploymentInfo); - - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void deploymentStatusToVduStatusTest() { - VduStatus expected = new VduStatus(); - expected.setState(VduStateType.DELETING); - expected.setLastAction(new PluginAction("deleting", null, null)); - - DeploymentInfo deploymentInfo = new DeploymentInfoBuilder().withId("id").withStatus(DeploymentStatus.CREATED) - .withLastAction("deleting").build(); - - MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); - - VduStatus actual = cloudify.deploymentStatusToVduStatus(deploymentInfo); - - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void getAzureConfigTest() { - AzureConfig expected = new AzureConfig(); - expected.setSubscriptionId("subscriptionId"); - expected.setTenantId("tenantId"); - expected.setClientId("msoId"); - expected.setClientSecret("msoPass"); - - MsoCloudifyUtils cloudify = new MsoCloudifyUtils(); - CloudSite cloudSite = Mockito.mock(CloudSite.class); - CloudIdentity cloudIdentity = Mockito.mock(CloudIdentity.class); - when(cloudSite.getIdentityService()).thenReturn(cloudIdentity); - when(cloudIdentity.getAdminTenant()).thenReturn("subscriptionId"); - when(cloudIdentity.getMsoId()).thenReturn("msoId"); - when(cloudIdentity.getMsoPass()).thenReturn("msoPass"); - String tenantId = "tenantId"; - AzureConfig actual = cloudify.getAzureConfig(cloudSite, tenantId); - - assertThat(actual, sameBeanAs(expected)); - } - - @Test - public void uploadBlueprintSuccessful() throws MsoException { - // given - MsoCloudifyUtils testedObjectSpy = spy(MsoCloudifyUtils.class); - testedObjectSpy.cloudConfig = mock(CloudConfig.class); - Map<String, byte[]> blueprints = new HashMap<>(); - - mockCloudConfig(testedObjectSpy); - doReturn(true).when(testedObjectSpy).uploadBlueprint(any(Cloudify.class), eq(BLUEPRINT_ID), eq(FILE_NAME), - eq(blueprints)); - // when - testedObjectSpy.uploadBlueprint(CLOUD_SITE_ID, BLUEPRINT_ID, FILE_NAME, blueprints, true); - // then - verify(testedObjectSpy).uploadBlueprint(any(Cloudify.class), eq(BLUEPRINT_ID), eq(FILE_NAME), eq(blueprints)); - } - - @Test - public void uploadBlueprint_exceptionThrown_blueprintExists() throws MsoException { - // given - MsoCloudifyUtils testedObjectSpy = spy(MsoCloudifyUtils.class); - testedObjectSpy.cloudConfig = mock(CloudConfig.class); - Map<String, byte[]> blueprints = new HashMap<>(); - - mockCloudConfig(testedObjectSpy); - doReturn(false).when(testedObjectSpy).uploadBlueprint(any(Cloudify.class), eq(BLUEPRINT_ID), eq(FILE_NAME), - eq(blueprints)); - // when - try { - testedObjectSpy.uploadBlueprint(CLOUD_SITE_ID, BLUEPRINT_ID, FILE_NAME, blueprints, true); - // then - fail("MsoAdapterException should be thrown"); - } catch (MsoAdapterException e) { - Assert.assertEquals(e.getMessage(), "Blueprint already exists"); - } - verify(testedObjectSpy).uploadBlueprint(any(Cloudify.class), eq(BLUEPRINT_ID), eq(FILE_NAME), eq(blueprints)); - } - - @Test - public void convertInputValueTest() throws JsonParseException, JsonMappingException, IOException { - MsoCloudifyUtils utils = new MsoCloudifyUtils(); - ObjectMapper mapper = new ObjectMapper(); - HeatTemplateParam paramNum = new HeatTemplateParam(); - paramNum.setParamType("number"); - paramNum.setParamName("my-number"); - - HeatTemplateParam paramString = new HeatTemplateParam(); - paramString.setParamType("string"); - paramString.setParamName("my-string"); - - HeatTemplateParam paramJson = new HeatTemplateParam(); - paramJson.setParamType("json"); - paramJson.setParamName("my-json"); - - HeatTemplateParam paramJsonEscaped = new HeatTemplateParam(); - paramJsonEscaped.setParamType("json"); - paramJsonEscaped.setParamName("my-json-escaped"); - - Map<String, Object> jsonMap = - mapper.readValue(getJson("free-form.json"), new TypeReference<Map<String, Object>>() {}); - - assertEquals(3, utils.convertInputValue("3", paramNum)); - assertEquals("hello", utils.convertInputValue("hello", paramString)); - assertTrue("expect no change in type", utils.convertInputValue(jsonMap, paramJson) instanceof Map); - assertTrue("expect string to become jsonNode", - utils.convertInputValue(getJson("free-form.json"), paramJsonEscaped) instanceof JsonNode); - - JSONAssert.assertEquals(getJson("free-form.json"), - mapper.writeValueAsString(utils.convertInputValue(getJson("free-form.json"), paramJsonEscaped)), false); - - } - - private String getJson(String filename) throws IOException { - return new String(Files.readAllBytes(Paths.get("src/test/resources/__files/MsoHeatUtils/" + filename))); - } - - private void mockCloudConfig(MsoCloudifyUtils testedObjectSpy) { - CloudifyManager cloudifyManager = createCloudifyManager(); - when(testedObjectSpy.cloudConfig.getCloudSite(CLOUD_SITE_ID)).thenReturn(Optional.of(createCloudSite())); - when(testedObjectSpy.cloudConfig.getCloudifyManager(CLOUD_SITE_ID)).thenReturn(cloudifyManager); - } - - private CloudifyManager createCloudifyManager() { - CloudifyManager cloudifyManager = new CloudifyManager(); - cloudifyManager.setCloudifyUrl("cloudUrlTest"); - cloudifyManager.setPassword("546573746F736973546573746F736973"); - return cloudifyManager; - } - - private CloudSite createCloudSite() { - CloudSite cloudSite = new CloudSite(); - cloudSite.setCloudifyId(CLOUD_SITE_ID); - return cloudSite; - } - -} diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V1.1__Initial_Recipe_Setup.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V1.1__Initial_Recipe_Setup.sql index 388d3c8b49..c5a3701a82 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V1.1__Initial_Recipe_Setup.sql +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V1.1__Initial_Recipe_Setup.sql @@ -45,6 +45,16 @@ INSERT INTO `service` (`MODEL_UUID`, `MODEL_NAME`, `MODEL_INVARIANT_UUID`, `MODE INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (11,'createInstance','1','Custom recipe to create E2E service-instance if no custom BPMN flow is found','/mso/async/services/CreateCustomE2EServiceInstance',NULL,180,NULL,'2017-10-05 18:52:03','dfcd7471-16c7-444e-8268-d4c50d90593a'); INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (12,'deleteInstance','1','Custom recipe to delete E2E service-instance if no custom BPMN flow is found','/mso/async/services/DeleteCustomE2EServiceInstance',NULL,180,NULL,'2017-10-05 18:52:03','dfcd7471-16c7-444e-8268-d4c50d90593a'); +-- Recipe for onap3gppServiceInstances + +INSERT INTO `service` (`MODEL_UUID`, `MODEL_NAME`, `MODEL_INVARIANT_UUID`, `MODEL_VERSION`, `DESCRIPTION`, `CREATION_TIMESTAMP`, `TOSCA_CSAR_ARTIFACT_UUID`) VALUES ('3d30a774-e149-11ea-87d0-0242ac130003','COMMON_SS_DEFAULT','3d30a774-e149-11ea-87d0-0242ac130003','1.0','Default service for common NSSMF','2020-08-18 17:40:03',NULL); + +INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (17,'createInstance','1','Custom recipe to allocate 3gpp service-instance if no custom BPMN flow is found','/mso/async/services/AllocateSliceSubnet',NULL,180,NULL,'2020-08-18 17:40:03','3d30a774-e149-11ea-87d0-0242ac130003'); +INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (18,'deleteInstance','1','Custom recipe to deallocate 3gpp service-instance if no custom BPMN flow is found','/mso/async/services/DeAllocateSliceSubnet',NULL,180,NULL,'2020-08-18 18:40:03','3d30a774-e149-11ea-87d0-0242ac130003'); +INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (19,'updateInstance','1','Custom recipe to modify 3gpp service-instance if no custom BPMN flow is found','/mso/async/services/ModifySliceSubnet',NULL,180,NULL,'2020-08-18 18:40:03','3d30a774-e149-11ea-87d0-0242ac130003'); +INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (20,'activateInstance','1','Custom recipe to activate/deactivate 3gpp service-instance if no custom BPMN flow is found','/mso/async/services/ActivateSliceSubnet',NULL,180,NULL,'2020-08-18 18:40:03','3d30a774-e149-11ea-87d0-0242ac130003'); +INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (21,'deactivateInstance','1','Custom recipe to activate/deactivate 3gpp service-instance if no custom BPMN flow is found','/mso/async/services/ActivateSliceSubnet',NULL,180,NULL,'2020-08-18 18:40:03','3d30a774-e149-11ea-87d0-0242ac130003'); + -- Recipe for E2E service update (R2 just support adding/deleting network service) INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (15,'updateInstance','1','Custom recipe to update E2E service-instance if no custom BPMN flow is found','/mso/async/services/UpdateCustomE2EServiceInstance',NULL,180,NULL,'2018-03-05 10:52:03','dfcd7471-16c7-444e-8268-d4c50d90593a'); INSERT INTO `service_recipe` (`id`, `ACTION`, `VERSION_STR`, `DESCRIPTION`, `ORCHESTRATION_URI`, `SERVICE_PARAM_XSD`, `RECIPE_TIMEOUT`, `SERVICE_TIMEOUT_INTERIM`, `CREATION_TIMESTAMP`, `SERVICE_MODEL_UUID`) VALUES (16,'scaleInstance','1','Custom recipe to scale E2E service-instance if no custom BPMN flow is found','/mso/async/services/ScaleCustomE2EServiceInstance',NULL,180,NULL,'2018-05-15 18:52:03','dfcd7471-16c7-444e-8268-d4c50d90593a'); diff --git a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java index ef979a660f..bc7a3d0bb7 100644 --- a/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java +++ b/adapters/mso-nssmf-adapter/src/main/java/org/onap/so/adapters/nssmf/manager/impl/external/ExternalAnNssmfManager.java @@ -33,12 +33,15 @@ import org.onap.so.beans.nsmf.NssmfAdapterNBIRequest; import org.onap.so.db.request.beans.ResourceOperationStatus; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.marshal; import static org.onap.so.adapters.nssmf.util.NssmfAdapterUtil.unMarshal; public class ExternalAnNssmfManager extends ExternalNssmfManager { + private Map<String, String> bodyParams = new HashMap<>(); // request body params + @Override protected String doWrapExtAllocateReqBody(NssmfAdapterNBIRequest nbiRequest) throws ApplicationException { Map<String, Object> request = new HashMap<>(); @@ -49,13 +52,17 @@ public class ExternalAnNssmfManager extends ExternalNssmfManager { @Override protected void doAfterRequest() throws ApplicationException { if (ActionType.ALLOCATE.equals(actionType) || ActionType.DEALLOCATE.equals(actionType)) { - @SuppressWarnings("unchecked") - Map<String, String> response = unMarshal(restResponse.getResponseContent(), Map.class); - - String nssiId = response.get("nSSId"); + String nssiId; + if (ActionType.ALLOCATE.equals(actionType)) { + @SuppressWarnings("unchecked") + Map<String, String> response = unMarshal(restResponse.getResponseContent(), Map.class); + nssiId = response.get("href"); + } else { + nssiId = this.bodyParams.get("nssiId"); + } NssiResponse resp = new NssiResponse(); - resp.setJobId(nssiId); + resp.setJobId(UUID.randomUUID().toString()); resp.setNssiId(nssiId); RestResponse returnRsp = new RestResponse(); @@ -82,6 +89,9 @@ public class ExternalAnNssmfManager extends ExternalNssmfManager { @Override protected String doWrapDeAllocateReqBody(DeAllocateNssi deAllocateNssi) throws ApplicationException { + this.bodyParams.clear(); + this.bodyParams.put("nssiId", deAllocateNssi.getNssiId()); + Map<String, String> request = new HashMap<>(); request.put("nSSId", deAllocateNssi.getNssiId()); return marshal(request); diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java index 10f39f717f..7e25ed600f 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/heatbridge/HeatBridgeImpl.java @@ -508,13 +508,14 @@ public class HeatBridgeImpl implements HeatBridgeApi { } } - private void updateLInterfaceIps(final Port port, final LInterface lIf) { + protected void updateLInterfaceIps(final Port port, final LInterface lIf) { for (IP ip : port.getFixedIps()) { String ipAddress = ip.getIpAddress(); if (InetAddressValidator.getInstance().isValidInet4Address(ipAddress)) { Subnet subnet = osClient.getSubnetById(ip.getSubnetId()); IPAddressString cidr = new IPAddressString(subnet.getCidr()); L3InterfaceIpv4AddressList lInterfaceIp = new L3InterfaceIpv4AddressList(); + lInterfaceIp.setIsFloating(false); lInterfaceIp.setL3InterfaceIpv4Address(ipAddress); lInterfaceIp.setNeutronNetworkId(port.getNetworkId()); lInterfaceIp.setNeutronSubnetId(ip.getSubnetId()); @@ -529,6 +530,7 @@ public class HeatBridgeImpl implements HeatBridgeApi { Subnet subnet = osClient.getSubnetById(ip.getSubnetId()); IPAddressString cidr = new IPAddressString(subnet.getCidr()); L3InterfaceIpv6AddressList ipv6 = new L3InterfaceIpv6AddressList(); + ipv6.setIsFloating(false); ipv6.setL3InterfaceIpv6Address(ipAddress); ipv6.setNeutronNetworkId(port.getNetworkId()); ipv6.setNeutronSubnetId(ip.getSubnetId()); diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java index 03f6c737f3..18348f19d7 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/heatbridge/HeatBridgeImplTest.java @@ -32,9 +32,12 @@ */ package org.onap.so.heatbridge; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; @@ -65,6 +68,7 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.MockitoJUnitRunner; +import org.onap.aai.domain.yang.L3InterfaceIpv6AddressList; import org.onap.aai.domain.yang.LInterface; import org.onap.aai.domain.yang.PInterface; import org.onap.aai.domain.yang.SriovPf; @@ -73,6 +77,8 @@ import org.onap.aaiclient.client.aai.AAIResourcesClient; import org.onap.aaiclient.client.aai.AAISingleTransactionClient; import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; +import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder; +import org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider; import org.onap.aaiclient.client.graphinventory.exceptions.BulkProcessFailed; import org.onap.so.db.catalog.beans.CloudIdentity; import org.onap.so.heatbridge.constants.HeatBridgeConstants; @@ -93,8 +99,11 @@ import org.openstack4j.model.network.Subnet; import org.openstack4j.openstack.heat.domain.HeatResource; import org.openstack4j.openstack.heat.domain.HeatResource.Resources; import org.springframework.core.env.Environment; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; +import inet.ipaddr.IPAddressString; @RunWith(MockitoJUnitRunner.class) @@ -529,6 +538,54 @@ public class HeatBridgeImplTest { } @Test + public void testUpdateLInterfaceIps() + throws HeatBridgeException, JsonParseException, JsonMappingException, IOException { + + Port port = mock(Port.class); + when(port.getNetworkId()).thenReturn("890a203a-23gg-56jh-df67-731656a8f13a"); + when(port.getDeviceId()).thenReturn("test-device-id"); + + IP ip = mock(IP.class); + + Set<IP> ipSet = new HashSet<>(); + ipSet.add(ip); + when(ip.getIpAddress()).thenReturn("2606:ae00:2e60:100::226"); + when(ip.getSubnetId()).thenReturn("testSubnetId"); + when(port.getFixedIps()).thenAnswer(x -> ipSet); + + Subnet subnet = mock(Subnet.class); + when(subnet.getCidr()).thenReturn("169.254.100.0/24"); + when(osClient.getSubnetById("testSubnetId")).thenReturn(subnet); + + LInterface lIf = new LInterface(); + lIf.setInterfaceName("test-port-name"); + + // Act + heatbridge.updateLInterfaceIps(port, lIf); + + L3InterfaceIpv6AddressList ipv6 = new L3InterfaceIpv6AddressList(); + ipv6.setIsFloating(false); + ipv6.setL3InterfaceIpv6Address("2606:ae00:2e60:100::226"); + ipv6.setNeutronNetworkId(port.getNetworkId()); + ipv6.setNeutronSubnetId(ip.getSubnetId()); + ipv6.setL3InterfaceIpv6PrefixLength(Long.parseLong("24")); + + ArgumentCaptor<Optional> argument = ArgumentCaptor.forClass(Optional.class); + + // Assert + verify(transaction).createIfNotExists( + eq(AAIUriFactory.createResourceUri( + AAIFluentTypeBuilder.cloudInfrastructure().cloudRegion("CloudOwner", "RegionOne") + .tenant("7320ec4a5b9d4589ba7c4412ccfd290f").vserver("test-device-id") + .lInterface("test-port-name").l3InterfaceIpv6AddressList("2606:ae00:2e60:100::226"))), + argument.capture()); + + assertTrue(argument.getValue().isPresent()); + + assertThat((L3InterfaceIpv6AddressList) argument.getValue().get(), sameBeanAs(ipv6)); + } + + @Test public void testUpdateVserverLInterfacesToAai_skipVlans() throws HeatBridgeException { // Arrange List<Resource> stackResources = (List<Resource>) extractTestStackResources(); diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java index ad96e1be4b..61c0cdbf2e 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/client/ASDCController.java @@ -754,6 +754,12 @@ public class ASDCController { } // process NsstResource this.processNsstNotification(iNotif, toscaResourceStructure); + + if (iNotif.getResources().isEmpty()) { + logger.error("Service Model contains no resources."); + return; + } + for (IResourceInstance resource : iNotif.getResources()) { String resourceType = resource.getResourceType(); diff --git a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/aaiL3NetworkInputWithSubnets.json b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/aaiL3NetworkInputWithSubnets.json index 9b32a4c446..8e4e3632e9 100644 --- a/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/aaiL3NetworkInputWithSubnets.json +++ b/bpmn/MSOCommonBPMN/src/test/resources/__files/ExecuteBuildingBlock/aaiL3NetworkInputWithSubnets.json @@ -72,7 +72,7 @@ "aggregateRoutes": { "aggregateRoute": [ { - "routeId": "routeId", + "aggRouteId": "routeId", "networkStartAddress": "10.80.12.0", "cidrMask": "23", "ipVersion": "4" diff --git a/cloudify-client/.gitignore b/cloudify-client/.gitignore deleted file mode 100644 index ae3c172604..0000000000 --- a/cloudify-client/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/bin/ diff --git a/cloudify-client/pom.xml b/cloudify-client/pom.xml deleted file mode 100644 index ccf2c4270e..0000000000 --- a/cloudify-client/pom.xml +++ /dev/null @@ -1,50 +0,0 @@ -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.onap.so</groupId> - <artifactId>so</artifactId> - <version>1.7.1-SNAPSHOT</version> - </parent> - - <groupId>org.onap.so</groupId> - <artifactId>cloudify-client</artifactId> - <packaging>jar</packaging> - <name>Cloudify Rest Client</name> - <description>Java client for Cloudify REST interface</description> - - <build> - <finalName>${project.artifactId}-${project.version}</finalName> - <plugins> - <plugin> - <artifactId>maven-jar-plugin</artifactId> - <!--<version>2.6</version>--> - <version>3.0.2</version> - <configuration> - <classesDirectory>target/classes</classesDirectory> - </configuration> - </plugin> - </plugins> - </build> - - <dependencies> - <dependency> - <groupId>org.onap.so</groupId> - <artifactId>common</artifactId> - <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpcore</artifactId> - </dependency> - <dependency> - <groupId>org.apache.httpcomponents</groupId> - <artifactId>httpclient</artifactId> - </dependency> - <dependency> - <groupId>commons-lang</groupId> - <artifactId>commons-lang</artifactId> - <version>2.6</version> - </dependency> - </dependencies> -</project> diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClient.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClient.java deleted file mode 100644 index d15fbf9322..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClient.java +++ /dev/null @@ -1,141 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.base.client; - -import java.util.Properties; -import org.onap.so.cloudify.connector.http.HttpClientConnector; - -public class CloudifyClient { - - protected String managerEndpoint; - protected String tenant = "default_tenant"; // Note - only default_tenant supported in community edition - - protected CloudifyTokenProvider tokenProvider; - - protected static int AUTHENTICATION_RETRIES = 1; - - protected CloudifyClientConnector connector; - - protected Properties properties = new Properties(); - - public CloudifyClient(String managerEndpoint) { - this.managerEndpoint = managerEndpoint; - this.connector = new HttpClientConnector(); - } - - public CloudifyClient(String managerEndpoint, String tenant) { - this.managerEndpoint = managerEndpoint; - this.tenant = tenant; - this.connector = new HttpClientConnector(); - } - - public CloudifyClient(String managerEndpoint, CloudifyClientConnector connector) { - this.managerEndpoint = managerEndpoint; - this.connector = connector; - } - - /** - * Execute a Cloudify request by making the REST API call. Return the complete CloudifyResponse structure, which - * includes the complete HTTP response. - * - * @param request a CloudifyRequest object - * @return a CloudifyResponse object - */ - public <T> CloudifyResponse request(CloudifyRequest<T> request) { - CloudifyResponseException authException = null; - - for (int i = 0; i <= AUTHENTICATION_RETRIES; i++) { - request.endpoint(managerEndpoint); - request.header("Tenant", tenant); - if (tokenProvider != null) - request.header("Authentication-Token", tokenProvider.getToken()); - - try { - return connector.request(request); - } catch (CloudifyResponseException e) { - if (e.getStatus() != CloudifyResponseStatus.NOT_AUTHORIZED || tokenProvider == null) { - throw e; - } - authException = e; - tokenProvider.expireToken(); - } - } - - if (authException != null) { - throw authException; - } - - return null; - } - - /** - * Execute a CloudifyRequest by sending the REST API call to the Cloudify Manager endpoint. The return type is a - * JSON POJO object containing the response body entity. - * - * @param request - * @return a JSON POJO object specific to the request type - */ - public <T> T execute(CloudifyRequest<T> request) { - CloudifyResponse response = request(request); - - if (null == response) { - return null; - } - - return (request.returnType() != null && request.returnType() != Void.class) - ? response.getEntity(request.returnType()) - : null; - } - - public void property(String property, String value) { - properties.put(property, value); - } - - /** - * Set a Token Provider. This class should be able to produce an authentication token on-demand. - * - * @param tokenProvider - */ - public void setTokenProvider(CloudifyTokenProvider tokenProvider) { - this.tokenProvider = tokenProvider; - } - - /** - * Manually set the authentication token to use for this client. - * - * @param token - */ - public void setToken(String token) { - setTokenProvider(new CloudifySimpleTokenProvider(token)); - } - - /** - * Perform a simple GET request with no request message body - * - * @param path - * @param returnType - * @return An object of Class <R> - */ - public <R> CloudifyRequest<R> get(String path, Class<R> returnType) { - return new CloudifyRequest<>(this, HttpMethod.GET, path, null, returnType); - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProvider.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProvider.java deleted file mode 100644 index c4dcc89d0b..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProvider.java +++ /dev/null @@ -1,84 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.base.client; - -import java.util.Date; -import org.apache.commons.lang.time.DateUtils; -import org.onap.so.cloudify.v3.client.Cloudify; -import org.onap.so.cloudify.v3.client.TokensResource.GetToken; -import org.onap.so.cloudify.v3.model.Token; - -/** - * Cloudify Token Provider that uses the Cloudify client API itself to obtain a token - * - * @author JC1348 - * - */ -public class CloudifyClientTokenProvider implements CloudifyTokenProvider { - - String user; - String password; - String token; - Date expiration; - Cloudify cloudify = null; - - public CloudifyClientTokenProvider(String cloudifyEndpoint, String user, String password) { - this.user = user; - this.password = password; - - cloudify = new Cloudify(cloudifyEndpoint); - } - - @Override - public String getToken() { - Date now = new Date(); - if (token != null && expiration != null && expiration.after(now)) { - return token; - } - - // Create a "Get Token" request. Force basic authentication to acquire the token itself. - GetToken tokenRequest = cloudify.tokens().token(); - tokenRequest.setBasicAuthentication(user, password); - Token newToken = tokenRequest.execute(); - - if (newToken != null) { - token = newToken.getValue(); - } - - if (expiration == null) { - expiration = new Date(); - } - // TODO: Make this property driven (or see if it comes back somehow in response) - expiration = DateUtils.addMinutes(expiration, 10); - - return token; - } - - @Override - /** - * This doesn't actually expire the token in Cloudify. It just prevents this token provider from using it. - */ - public void expireToken() { - expiration = null; - token = null; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyRequest.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyRequest.java deleted file mode 100644 index 006768f2f1..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyRequest.java +++ /dev/null @@ -1,190 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.base.client; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.ArrayList; -import java.util.Map; - -public class CloudifyRequest<R> { - - private CloudifyClient client; - - private String endpoint; - - private HttpMethod method; - - private StringBuilder path = new StringBuilder(); - - private Map<String, List<Object>> headers = new HashMap<>(); - - private Entity<?> entity; - - private Class<R> returnType; - - private boolean basicAuth = false; - private String user = null; - private String password = null; - - public CloudifyRequest() { - - } - - public CloudifyRequest(CloudifyClient client, HttpMethod method, CharSequence path, Entity<?> entity, - Class<R> returnType) { - this.client = client; - this.method = method; - this.path = new StringBuilder(path); - this.entity = entity; - this.returnType = returnType; - header("Accept", "application/json"); - } - - public CloudifyRequest<R> endpoint(String endpoint) { - this.endpoint = endpoint; - return this; - } - - public String endpoint() { - return endpoint; - } - - public CloudifyRequest<R> method(HttpMethod method) { - this.method = method; - return this; - } - - public HttpMethod method() { - return method; - } - - public CloudifyRequest<R> path(String path) { - this.path.append(path); - return this; - } - - public String path() { - return path.toString(); - } - - public CloudifyRequest<R> header(String name, Object value) { - if (value != null) { - headers.put(name, Arrays.asList(value)); - } - return this; - } - - public Map<String, List<Object>> headers() { - return headers; - } - - public <T> Entity<T> entity(T entity, String contentType) { - return new Entity<>(entity, contentType); - } - - public Entity<?> entity() { - return entity; - } - - public <T> Entity<T> json(T entity) { - return entity(entity, "application/json"); - } - - public void returnType(Class<R> returnType) { - this.returnType = returnType; - } - - public Class<R> returnType() { - return returnType; - } - - /* - * Use Basic Authentication for this request. If not set, the client will use Token authentication if a token - * provider is defined. Otherwise, no authentication will be applied. - */ - public void setBasicAuthentication(String user, String password) { - this.basicAuth = true; - this.user = user; - this.password = password; - } - - public boolean isBasicAuth() { - return this.basicAuth; - } - - public String getUser() { - return user; - } - - public String getPassword() { - return password; - } - - public R execute() { - return client.execute(this); - } - - public CloudifyResponse request() { - return client.request(this); - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override - public String toString() { - return "CloudifyRequest [endpoint=" + endpoint + ", method=" + method + ", path=" + path + ", headers=" - + headers + ", entity=" + entity + ", returnType=" + returnType + "]"; - } - - private Map<String, List<Object>> queryParams = new LinkedHashMap<>(); - - public Map<String, List<Object>> queryParams() { - return queryParams; - } - - public CloudifyRequest<R> queryParam(String key, Object value) { - if (queryParams.containsKey(key)) { - List<Object> values = queryParams.get(key); - values.add(value); - } else { - List<Object> values = new ArrayList<>(); - values.add(value); - queryParams.put(key, values); - } - - return this; - } - - protected static String buildPath(String... elements) { - StringBuilder stringBuilder = new StringBuilder(); - for (String element : elements) { - stringBuilder.append(element); - } - - return stringBuilder.toString(); - } -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseException.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseException.java deleted file mode 100644 index 0ca3212238..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseException.java +++ /dev/null @@ -1,61 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.base.client; - -import org.onap.so.cloudify.v3.model.CloudifyError; - -public class CloudifyResponseException extends CloudifyBaseException { - - private static final long serialVersionUID = 7294957362769575271L; - - private final String message; - private final int status; - - // Make the response available for exception handling (includes body) - private final CloudifyResponse response; - - public CloudifyResponseException(String message, int status) { - this.message = message; - this.status = status; - this.response = null; - } - - // Include the response message itself. The body is a CloudifyError JSON structure. - public CloudifyResponseException(String message, int status, CloudifyResponse response) { - CloudifyError error = response.getErrorEntity(CloudifyError.class); - this.message = message + ": " + error.getErrorCode(); - this.status = status; - this.response = response; - } - - public String getMessage() { - return message; - } - - public int getStatus() { - return status; - } - - public CloudifyResponse getResponse() { - return response; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/Entity.java b/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/Entity.java deleted file mode 100644 index 095582fa51..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/Entity.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.base.client; - -public class Entity<T> { - - private T entity; - - private String contentType; - - public static <T> Entity<T> json(T entity) { - return new Entity<T>(entity, "application/json"); - } - - public static <T> Entity<T> stream(T entity) { - return new Entity<T>(entity, "application/octet-stream"); - } - - public Entity(T entity, String contentType) { - super(); - this.entity = entity; - this.contentType = contentType; - } - - /** - * @return the entity - */ - public T getEntity() { - return entity; - } - - /** - * @param entity the entity to set - */ - public void setEntity(T entity) { - this.entity = entity; - } - - /** - * @return the contentType - */ - public String getContentType() { - return contentType; - } - - /** - * @param contentType the contentType to set - */ - public void setContentType(String contentType) { - this.contentType = contentType; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientConnector.java b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientConnector.java deleted file mode 100644 index 54519bac72..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientConnector.java +++ /dev/null @@ -1,246 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.connector.http; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URISyntaxException; -import java.net.UnknownHostException; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import org.apache.http.HttpEntity; -import org.apache.http.HttpStatus; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.HttpResponseException; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.utils.URIBuilder; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.InputStreamEntity; -import org.apache.http.entity.StringEntity; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.onap.so.cloudify.base.client.CloudifyClientConnector; -import org.onap.so.cloudify.base.client.CloudifyConnectException; -import org.onap.so.cloudify.base.client.CloudifyRequest; -import org.onap.so.cloudify.base.client.CloudifyResponse; -import org.onap.so.cloudify.base.client.CloudifyResponseException; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonRootName; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HttpClientConnector implements CloudifyClientConnector { - - private static ObjectMapper DEFAULT_MAPPER; - private static ObjectMapper WRAPPED_MAPPER; - - private static Logger logger = LoggerFactory.getLogger(HttpClientConnector.class); - - static { - DEFAULT_MAPPER = new ObjectMapper(); - - DEFAULT_MAPPER.setSerializationInclusion(Include.NON_NULL); - DEFAULT_MAPPER.disable(SerializationFeature.INDENT_OUTPUT); - DEFAULT_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); - DEFAULT_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - - WRAPPED_MAPPER = new ObjectMapper(); - - WRAPPED_MAPPER.setSerializationInclusion(Include.NON_NULL); - WRAPPED_MAPPER.disable(SerializationFeature.INDENT_OUTPUT); - WRAPPED_MAPPER.enable(SerializationFeature.WRAP_ROOT_VALUE); - WRAPPED_MAPPER.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); - WRAPPED_MAPPER.enable(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY); - WRAPPED_MAPPER.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - } - - protected static <T> ObjectMapper getObjectMapper(Class<T> type) { - return type.getAnnotation(JsonRootName.class) == null ? DEFAULT_MAPPER : WRAPPED_MAPPER; - } - - public <T> CloudifyResponse request(CloudifyRequest<T> request) { - - CloseableHttpClient httpClient = null; - - if (request.isBasicAuth()) { - // Use Basic Auth for this request. - CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); - credentialsProvider.setCredentials(AuthScope.ANY, - new UsernamePasswordCredentials(request.getUser(), request.getPassword())); - - httpClient = HttpClients.custom().setRedirectStrategy(new HttpClientRedirectStrategy()) - .setDefaultCredentialsProvider(credentialsProvider).build(); - } else { - // Don't use basic authentication. The Client will attempt Token-based authentication - httpClient = HttpClients.custom().setRedirectStrategy(new HttpClientRedirectStrategy()).build(); - } - - URI uri = null; - - // Build the URI with query params - try { - URIBuilder uriBuilder = new URIBuilder(request.endpoint() + request.path()); - - for (Map.Entry<String, List<Object>> entry : request.queryParams().entrySet()) { - for (Object o : entry.getValue()) { - uriBuilder.setParameter(entry.getKey(), String.valueOf(o)); - } - } - - uri = uriBuilder.build(); - } catch (URISyntaxException e) { - throw new HttpClientException(e); - } - - HttpEntity entity = null; - if (request.entity() != null) { - // Special handling for streaming input - if (request.entity().getEntity() instanceof InputStream) { - // Entity is an InputStream - entity = new InputStreamEntity((InputStream) request.entity().getEntity()); - } else { - // Assume to be JSON. Flatten the entity to a Json string - try { - // Get appropriate mapper, based on existence of a root element in Entity class - ObjectMapper mapper = getObjectMapper(request.entity().getEntity().getClass()); - - String entityJson = mapper.writeValueAsString(request.entity().getEntity()); - entity = new StringEntity(entityJson, ContentType.create(request.entity().getContentType())); - - logger.debug("Request JSON Body: {}", - entityJson.replaceAll("\"password\":\"[^\"]*\"", "\"password\":\"***\"")); - - } catch (JsonProcessingException e) { - throw new HttpClientException("Json processing error on request entity", e); - } catch (IOException e) { - throw new HttpClientException("Json IO error on request entity", e); - } - } - } - - // Determine the HttpRequest class based on the method - HttpUriRequest httpRequest; - - switch (request.method()) { - case POST: - HttpPost post = new HttpPost(uri); - post.setEntity(entity); - httpRequest = post; - break; - - case GET: - httpRequest = new HttpGet(uri); - break; - - case PUT: - HttpPut put = new HttpPut(uri); - put.setEntity(entity); - httpRequest = put; - break; - - case DELETE: - httpRequest = new HttpDelete(uri); - break; - - default: - throw new HttpClientException("Unrecognized HTTP Method: " + request.method()); - } - - for (Entry<String, List<Object>> h : request.headers().entrySet()) { - StringBuilder sb = new StringBuilder(); - for (Object v : h.getValue()) { - sb.append(String.valueOf(v)); - } - httpRequest.addHeader(h.getKey(), sb.toString()); - } - - // Get the Response. But don't get the body entity yet, as this response - // will be wrapped in an HttpClientResponse. The HttpClientResponse - // buffers the body in constructor, so can close the response here. - HttpClientResponse httpClientResponse = null; - CloseableHttpResponse httpResponse = null; - - // Catch known HttpClient exceptions, and wrap them in OpenStack Client Exceptions - // so calling functions can distinguish. Only RuntimeExceptions are allowed. - try { - httpResponse = httpClient.execute(httpRequest); - - logger.debug("Response status: {}", httpResponse.getStatusLine().getStatusCode()); - - httpClientResponse = new HttpClientResponse(httpResponse); - - int status = httpResponse.getStatusLine().getStatusCode(); - if (status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT - || status == HttpStatus.SC_ACCEPTED) { - return httpClientResponse; - } - } catch (HttpResponseException e) { - // What exactly does this mean? It does not appear to get thrown for - // non-2XX responses as documented. - logger.error("Client HttpResponseException", e); - throw new CloudifyResponseException(e.getMessage(), e.getStatusCode()); - } catch (UnknownHostException e) { - logger.error("Client UnknownHostException", e); - throw new CloudifyConnectException("Unknown Host: " + e.getMessage()); - } catch (IOException e) { - // Catch all other IOExceptions and throw as OpenStackConnectException - logger.error("Client IOException", e); - throw new CloudifyConnectException(e.getMessage()); - } catch (Exception e) { - // Catchall for anything else, must throw as a RuntimeException - logger.error("Client exception", e); - throw new RuntimeException("Unexpected client exception", e); - } finally { - // Have the body. Close the stream - if (httpResponse != null) - try { - httpResponse.close(); - } catch (IOException e) { - logger.debug("Unable to close HTTP Response: ", e); - } - } - - // Get here on an error response (4XX-5XX) - if (httpResponse != null) { - throw new CloudifyResponseException(httpResponse.getStatusLine().getReasonPhrase(), - httpResponse.getStatusLine().getStatusCode(), httpClientResponse); - } else { - throw new CloudifyResponseException("Null httpResponse", 0, httpClientResponse); - } - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientException.java b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientException.java deleted file mode 100644 index 6f170baef5..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientException.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.connector.http; - -/* - * Declare a RuntimeException since the Interface does not declare any throwables. Any caught exception will be wrapped - * in HttpClientException - */ -public class HttpClientException extends RuntimeException { - - private static final long serialVersionUID = 1L; - - public HttpClientException(String s) { - super(s); - } - - public HttpClientException(Exception e) { - super("Caught nested exception in HttpClient", e); - } - - public HttpClientException(String s, Exception e) { - super(s, e); - } -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategy.java b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategy.java deleted file mode 100644 index b8b4a5b018..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategy.java +++ /dev/null @@ -1,95 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.connector.http; - -import java.net.URI; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.ProtocolException; -import org.apache.http.annotation.Immutable; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpHead; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.client.methods.RequestBuilder; -import org.apache.http.impl.client.DefaultRedirectStrategy; -import org.apache.http.protocol.HttpContext; - -/** - * Custom {@link org.apache.http.client.RedirectStrategy} implementation that automatically redirects all HEAD, GET and - * DELETE requests. The {@link org.apache.http.client.DefaultRedirectStrategy} only redirects GET and HEAD - * automatically, per the HTTP specification (POST and PUT typically have bodies and thus cannot be redirected). - * - * A custom strategy is needed for the Openstack API, which can also send 302 on a DELETE (by name) request, expecting - * the client to follow the redirect to perform the actual deletion. - */ -@Immutable -public class HttpClientRedirectStrategy extends DefaultRedirectStrategy { - - /** - * Redirectable methods. - */ - private static final String[] REDIRECT_METHODS = - new String[] {HttpGet.METHOD_NAME, HttpDelete.METHOD_NAME, HttpHead.METHOD_NAME}; - - /** - * Determine if the request should be redirected. This may not actually be needed, since the REDIRECT_METHODS array - * has been updated with the DELETE. - */ - @Override - protected boolean isRedirectable(final String method) { - for (final String m : REDIRECT_METHODS) { - if (m.equalsIgnoreCase(method)) { - return true; - } - } - return false; - } - - /** - * Override the default redirect handling method. As implemented in HttpClient, it does not preserve the method on - * 301 or 302 responses, always redirecting to a GET. - */ - @Override - public HttpUriRequest getRedirect(final HttpRequest request, final HttpResponse response, final HttpContext context) - throws ProtocolException { - - final URI uri = getLocationURI(request, response, context); - final String method = request.getRequestLine().getMethod(); - if (method.equalsIgnoreCase(HttpHead.METHOD_NAME)) { - return new HttpHead(uri); - } else if (method.equalsIgnoreCase(HttpGet.METHOD_NAME)) { - return new HttpGet(uri); - } else { - - final int status = response.getStatusLine().getStatusCode(); - - HttpUriRequest newRequest = null; - if (status == HttpStatus.SC_TEMPORARY_REDIRECT || status == HttpStatus.SC_MOVED_TEMPORARILY) { - newRequest = RequestBuilder.copy(request).setUri(uri).build(); - } else { - newRequest = new HttpGet(uri); - } - return newRequest; - } - } -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientResponse.java b/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientResponse.java deleted file mode 100644 index f1aa06cb39..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/connector/http/HttpClientResponse.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright (c) 2019 Samsung - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.connector.http; - -import org.apache.http.Header; -import org.apache.http.HttpResponse; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.onap.so.cloudify.base.client.CloudifyResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; - -public class HttpClientResponse implements CloudifyResponse { - - private static Logger logger = LoggerFactory.getLogger(HttpClientResponse.class); - - private transient HttpResponse response = null; - private String entityBody = null; - - public HttpClientResponse(HttpResponse response) { - this.response = response; - - // Read the body so InputStream can be closed - if (response.getEntity() == null) { - // No body - logger.debug("No Response Body"); - return; - } - - ByteArrayOutputStream responseBody = new ByteArrayOutputStream(); - try { - response.getEntity().writeTo(responseBody); - } catch (IOException e) { - throw new HttpClientException("Error Reading Response Body", e); - } - entityBody = responseBody.toString(); - logger.debug(entityBody); - } - - - @Override - public <T> T getEntity(Class<T> returnType) { - // Get appropriate mapper, based on existence of a root element - ObjectMapper mapper = HttpClientConnector.getObjectMapper(returnType); - - T resp = null; - try { - resp = mapper.readValue(entityBody, returnType); - } catch (Exception e) { - throw new HttpClientException("Caught exception in getEntity", e); - } - return resp; - } - - @Override - public <T> T getErrorEntity(Class<T> returnType) { - return getEntity(returnType); - } - - @Override - public InputStream getInputStream() { - return new ByteArrayInputStream(entityBody.getBytes()); - } - - @Override - public String getHeader(String name) { - return response.getFirstHeader(name).getValue(); - } - - @Override - public Map<String, String> headers() { - Map<String, String> headers = new HashMap<>(); - - Header responseHeaders[] = response.getAllHeaders(); - for (Header h : responseHeaders) { - headers.put(h.getName(), h.getValue()); - } - - return headers; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/BlueprintsResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/BlueprintsResource.java deleted file mode 100644 index 9877eb9f43..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/BlueprintsResource.java +++ /dev/null @@ -1,103 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import java.io.InputStream; -import org.onap.so.cloudify.v3.model.Blueprint; -import org.onap.so.cloudify.v3.model.Blueprints; -import org.onap.so.cloudify.base.client.Entity; -import org.onap.so.cloudify.base.client.HttpMethod; -import org.onap.so.cloudify.base.client.CloudifyClient; -import org.onap.so.cloudify.base.client.CloudifyRequest; - -public class BlueprintsResource { - - private final CloudifyClient client; - private static final String BLUEPRINTS_PATH = "/api/v3/blueprints/"; - - public BlueprintsResource(CloudifyClient client) { - this.client = client; - } - - /* - * Upload a blueprint package directly. The blueprint must be a ZIP archive. However, this method will not validate - * this. - */ - public UploadBlueprint uploadFromStream(String blueprintId, String mainFileName, InputStream blueprint) { - return new UploadBlueprint(blueprintId, mainFileName, blueprint, null); - } - - public UploadBlueprint uploadFromUrl(String blueprintId, String mainFileName, String blueprintUrl) { - return new UploadBlueprint(blueprintId, mainFileName, null, blueprintUrl); - } - - public ListBlueprints list() { - return new ListBlueprints(); - } - - public GetBlueprint getById(String id) { - return new GetBlueprint(id, ""); - } - - // Return all of the metadata, but not the plan - public GetBlueprint getMetadataById(String id) { - return new GetBlueprint(id, "?_include=id,main_file_name,description,tenant_name,created_at,updated_at"); - } - - public DeleteBlueprint deleteById(String id) { - return new DeleteBlueprint(id); - } - - public class UploadBlueprint extends CloudifyRequest<Blueprint> { - public UploadBlueprint(String blueprintId, String mainFileName, InputStream blueprint, String blueprintUrl) { - // Initialize the request elements dynamically. - // Either a blueprint input stream or a URL will be provided. - // If a URL is provided, add it to the query string - // If a Stream is provided, set it as the Entity body - super(client, HttpMethod.PUT, - BLUEPRINTS_PATH + blueprintId + "?application_file_name=" + mainFileName - + ((blueprintUrl != null) ? "&blueprint_archive=" + blueprintUrl : ""), - ((blueprint != null) ? Entity.stream(blueprint) : null), Blueprint.class); - } - } - - public class DeleteBlueprint extends CloudifyRequest<Blueprint> { - public DeleteBlueprint(String blueprintId) { - super(client, HttpMethod.DELETE, BLUEPRINTS_PATH + blueprintId, null, Blueprint.class); - } - } - - public class GetBlueprint extends CloudifyRequest<Blueprint> { - public GetBlueprint(String id, String queryArgs) { - super(client, HttpMethod.GET, BLUEPRINTS_PATH + id + queryArgs, null, Blueprint.class); - } - } - - public class ListBlueprints extends CloudifyRequest<Blueprints> { - public ListBlueprints() { - super(client, HttpMethod.GET, "/api/v3/blueprints", null, Blueprints.class); - } - } - - // TODO: DownloadBlueprint is not supported, as it needs to return an input stream - // containing the full blueprint ZIP. - // For a full client library, this will require returning an open stream as the entity... -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/Cloudify.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/Cloudify.java deleted file mode 100644 index 2fdd61ce48..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/Cloudify.java +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import org.onap.so.cloudify.base.client.CloudifyClient; -import org.onap.so.cloudify.base.client.CloudifyClientConnector; - -/** - * Reference: http://docs.getcloudify.org/api/v3/ - */ -public class Cloudify extends CloudifyClient { - - private final DeploymentsResource deployments; - private final BlueprintsResource blueprints; - private final TokensResource tokens; - private final NodeInstancesResource nodeInstances; - private final ExecutionsResource executions; - - /* - * Not supporting dynamic connectors public Cloudify(String endpoint, CloudifyClientConnector connector) { - * super(endpoint, connector); deployments = new DeploymentsResource(this); blueprints = new - * BlueprintsResource(this); nodeInstances = new NodeInstancesResource(this); tokens = new TokensResource(this); } - */ - public Cloudify(String endpoint, String tenant) { - super(endpoint, tenant); - deployments = new DeploymentsResource(this); - blueprints = new BlueprintsResource(this); - nodeInstances = new NodeInstancesResource(this); - executions = new ExecutionsResource(this); - tokens = new TokensResource(this); - } - - public Cloudify(String endpoint) { - super(endpoint); - deployments = new DeploymentsResource(this); - blueprints = new BlueprintsResource(this); - nodeInstances = new NodeInstancesResource(this); - executions = new ExecutionsResource(this); - tokens = new TokensResource(this); - } - - public DeploymentsResource deployments() { - return this.deployments; - } - - public BlueprintsResource blueprints() { - return this.blueprints; - } - - public NodeInstancesResource nodeInstances() { - return this.nodeInstances; - } - - public ExecutionsResource executions() { - return this.executions; - } - - public TokensResource tokens() { - return this.tokens; - } -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/DeploymentsResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/DeploymentsResource.java deleted file mode 100644 index 335f6b1697..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/DeploymentsResource.java +++ /dev/null @@ -1,91 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import org.onap.so.cloudify.v3.model.CreateDeploymentParams; -import org.onap.so.cloudify.v3.model.Deployment; -import org.onap.so.cloudify.v3.model.DeploymentOutputs; -import org.onap.so.cloudify.v3.model.Deployments; -import org.onap.so.cloudify.base.client.Entity; -import org.onap.so.cloudify.base.client.HttpMethod; -import org.onap.so.cloudify.base.client.CloudifyClient; -import org.onap.so.cloudify.base.client.CloudifyRequest; - -public class DeploymentsResource { - - private final CloudifyClient client; - private static final String DEPLOYMENT_PATH = "/api/v3/deployments/"; - - public DeploymentsResource(CloudifyClient client) { - this.client = client; - } - - public CreateDeployment create(String deploymentId, CreateDeploymentParams body) { - return new CreateDeployment(deploymentId, body); - } - - public ListDeployments list() { - return new ListDeployments(); - } - - public GetDeployment byId(String id) { - return new GetDeployment(id); - } - - public GetDeploymentOutputs outputsById(String id) { - return new GetDeploymentOutputs(id); - } - - public DeleteDeployment deleteByName(String name) { - return new DeleteDeployment(name); - } - - public class CreateDeployment extends CloudifyRequest<Deployment> { - public CreateDeployment(String deploymentId, CreateDeploymentParams body) { - super(client, HttpMethod.PUT, DEPLOYMENT_PATH + deploymentId, Entity.json(body), Deployment.class); - } - } - - public class DeleteDeployment extends CloudifyRequest<Deployment> { - public DeleteDeployment(String deploymentId) { - super(client, HttpMethod.DELETE, DEPLOYMENT_PATH + deploymentId, null, Deployment.class); - } - } - - public class GetDeployment extends CloudifyRequest<Deployment> { - public GetDeployment(String id) { - super(client, HttpMethod.GET, DEPLOYMENT_PATH + id, null, Deployment.class); - } - } - - public class GetDeploymentOutputs extends CloudifyRequest<DeploymentOutputs> { - public GetDeploymentOutputs(String id) { - super(client, HttpMethod.GET, DEPLOYMENT_PATH + id + "/outputs", null, DeploymentOutputs.class); - } - } - - public class ListDeployments extends CloudifyRequest<Deployments> { - public ListDeployments() { - super(client, HttpMethod.GET, "/api/v3/deployments", null, Deployments.class); - } - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/ExecutionsResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/ExecutionsResource.java deleted file mode 100644 index 34251bfe52..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/ExecutionsResource.java +++ /dev/null @@ -1,109 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import org.onap.so.cloudify.v3.model.CancelExecutionParams; -import org.onap.so.cloudify.v3.model.Execution; -import org.onap.so.cloudify.v3.model.Executions; -import org.onap.so.cloudify.v3.model.StartExecutionParams; -import org.onap.so.cloudify.v3.model.UpdateExecutionParams; -import org.onap.so.cloudify.base.client.Entity; -import org.onap.so.cloudify.base.client.HttpMethod; -import org.onap.so.cloudify.base.client.CloudifyClient; -import org.onap.so.cloudify.base.client.CloudifyRequest; - -public class ExecutionsResource { - - private final CloudifyClient client; - private static final String EXECUTIONS_PATH = "/api/v3/executions/"; - - public ExecutionsResource(CloudifyClient client) { - this.client = client; - } - - public ListExecutions list() { - return new ListExecutions(null); - } - - public ListExecutions listSorted(String sortBy) { - return new ListExecutions("?_sort=" + sortBy); - } - - // Return a filtered list. - // The filter parameter should be a query string of filter criteria (without leading "?") - public ListExecutions listFiltered(String filter, String sortBy) { - String listParams = "?" + filter; - if (sortBy != null) - listParams += "&_sort=" + sortBy; - return new ListExecutions(listParams); - } - - public GetExecution byId(String id) { - return new GetExecution(id); - } - - public StartExecution start(StartExecutionParams params) { - return new StartExecution(params); - } - - public UpdateExecution updateStatus(String id, String status) { - UpdateExecutionParams params = new UpdateExecutionParams(); - params.setStatus(status); - return new UpdateExecution(id, params); - } - - public CancelExecution cancel(String executionId, CancelExecutionParams params) { - return new CancelExecution(executionId, params); - } - - - public class GetExecution extends CloudifyRequest<Execution> { - public GetExecution(String id) { - super(client, HttpMethod.GET, EXECUTIONS_PATH + id, null, Execution.class); - } - } - - public class ListExecutions extends CloudifyRequest<Executions> { - public ListExecutions(String listParams) { - super(client, HttpMethod.GET, "/api/v3/executions" + ((listParams != null) ? listParams : ""), null, - Executions.class); - } - } - - public class StartExecution extends CloudifyRequest<Execution> { - public StartExecution(StartExecutionParams body) { - super(client, HttpMethod.POST, "/api/v3/executions", Entity.json(body), Execution.class); - } - } - - public class UpdateExecution extends CloudifyRequest<Execution> { - public UpdateExecution(String executionId, UpdateExecutionParams body) { - super(client, HttpMethod.PATCH, EXECUTIONS_PATH + executionId, Entity.json(body), Execution.class); - } - } - - public class CancelExecution extends CloudifyRequest<Execution> { - public CancelExecution(String executionId, CancelExecutionParams body) { - super(client, HttpMethod.POST, EXECUTIONS_PATH + executionId, Entity.json(body), Execution.class); - } - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/NodeInstancesResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/NodeInstancesResource.java deleted file mode 100644 index bc82c77026..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/NodeInstancesResource.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import org.onap.so.cloudify.v3.model.UpdateNodeInstanceParams; -import org.onap.so.cloudify.v3.model.NodeInstance; -import org.onap.so.cloudify.v3.model.NodeInstances; -import org.onap.so.cloudify.base.client.Entity; -import org.onap.so.cloudify.base.client.HttpMethod; -import org.onap.so.cloudify.base.client.CloudifyClient; -import org.onap.so.cloudify.base.client.CloudifyRequest; - -public class NodeInstancesResource { - - private final CloudifyClient client; - - public NodeInstancesResource(CloudifyClient client) { - this.client = client; - } - - public ListNodeInstances list() { - return new ListNodeInstances(); - } - - public GetNodeInstance byId(String id) { - return new GetNodeInstance(id); - } - - public UpdateNodeInstance update(String id, UpdateNodeInstanceParams params) { - return new UpdateNodeInstance(id, params); - } - - - public class GetNodeInstance extends CloudifyRequest<NodeInstance> { - public GetNodeInstance(String id) { - super(client, HttpMethod.GET, "/api/v3/node-instances/" + id, null, NodeInstance.class); - } - } - - public class ListNodeInstances extends CloudifyRequest<NodeInstances> { - public ListNodeInstances() { - super(client, HttpMethod.GET, "/api/v3/node-instances", null, NodeInstances.class); - } - } - - public class UpdateNodeInstance extends CloudifyRequest<NodeInstance> { - public UpdateNodeInstance(String nodeInstanceId, UpdateNodeInstanceParams body) { - super(client, HttpMethod.PATCH, "/api/v3/node-instances/" + nodeInstanceId, Entity.json(body), - NodeInstance.class); - } - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/TokensResource.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/TokensResource.java deleted file mode 100644 index 417d7c6eda..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/client/TokensResource.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import org.onap.so.cloudify.v3.model.Token; -import org.onap.so.cloudify.base.client.HttpMethod; -import org.onap.so.cloudify.base.client.CloudifyClient; -import org.onap.so.cloudify.base.client.CloudifyRequest; - -public class TokensResource { - - private final CloudifyClient client; - - public TokensResource(CloudifyClient client) { - this.client = client; - } - - /* - * Get a new token for a user TODO: User ID/Password logic need to be in the Client. Results of a token query should - * also be able to add to the Client - */ - public GetToken token() { - return new GetToken(); - } - - public class GetToken extends CloudifyRequest<Token> { - public GetToken() { - super(client, HttpMethod.GET, "/api/v3/tokens", null, Token.class); - } - } -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/AzureConfig.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/AzureConfig.java deleted file mode 100644 index 8fd6b7c9c0..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/AzureConfig.java +++ /dev/null @@ -1,74 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class AzureConfig implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("subscription_id") - String subscriptionId; - - @JsonProperty("tenant_id") - String tenantId; - - @JsonProperty("client_id") - String clientId; - - @JsonProperty("client_secret") - String clientSecret; - - public String getSubscriptionId() { - return subscriptionId; - } - - public void setSubscriptionId(String subscriptionId) { - this.subscriptionId = subscriptionId; - } - - public String getTenantId() { - return tenantId; - } - - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - - public String getClientId() { - return clientId; - } - - public void setClientId(String clientId) { - this.clientId = clientId; - } - - public String getClientSecret() { - return clientSecret; - } - - public void setClientSecret(String clientSecret) { - this.clientSecret = clientSecret; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprint.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprint.java deleted file mode 100644 index 873816d121..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprint.java +++ /dev/null @@ -1,153 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.IOException; -import java.io.Serializable; -import java.util.Date; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; - -@JsonIgnoreProperties(ignoreUnknown = true) -// @JsonRootName("blueprint") -public class Blueprint implements Serializable { - - - /** - * - */ - private static final long serialVersionUID = 938604986548763151L; - - @JsonProperty("created_at") - private Date createdAt; - - @JsonProperty("description") - private String description; - - @JsonProperty("id") - private String id; - - @JsonProperty("main_file_name") - private String mainFileName; - - @JsonProperty("plan") - private Map<String, Object> plan = null; - - @JsonProperty("tenant_name") - private String tenantName; - - @JsonProperty("updated_at") - private Date updatedAt; - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getMainFileName() { - return mainFileName; - } - - public void setMainFileName(String mainFileName) { - this.mainFileName = mainFileName; - } - - public Map<String, Object> getPlan() { - return this.plan; - } - - public void setPlan(Map<String, Object> plan) { - this.plan = plan; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - - /* - * Return an output as a Json-mapped Object of the provided type. This is useful for json-object outputs. - */ - public <T> T getMapValue(Map<String, Object> map, String key, Class<T> type) { - - ObjectMapper mapper = new ObjectMapper(); - - if (map.containsKey(key)) { - try { - String s = mapper.writeValueAsString(map.get(key)); - return (mapper.readValue(s, type)); - } catch (IOException e) { - return null; - } - } - return null; - } - - @Override - public String toString() { - return "Deployment{" + "id='" + id + '\'' + ", description='" + description + '\'' + ", createdAt=" + createdAt - + ", updatedAt=" + updatedAt + ", mainFileName='" + mainFileName + '\'' + ", tenantName='" + tenantName - + '\'' + '}'; - } - - /* - * Add a definition of the Cloudify "plan" attribute once we know what it is. - * - * @JsonIgnoreProperties(ignoreUnknown=true) public static final class Plan { } - * - */ - - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprints.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprints.java deleted file mode 100644 index aebf1e5daa..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Blueprints.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import java.util.List; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Blueprints implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("items") - private List<Blueprint> items; - - @JsonProperty("metadata") - private Metadata metadata; - - public List<Blueprint> getItems() { - return items; - } - - public void setItems(List<Blueprint> items) { - this.items = items; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CancelExecutionParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CancelExecutionParams.java deleted file mode 100644 index 7f96b8f7c6..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CancelExecutionParams.java +++ /dev/null @@ -1,50 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class CancelExecutionParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("action") - private String action; - - public static final String CANCEL_ACTION = "cancel"; - public static final String FORCE_CANCEL_ACTION = "force-cancel"; - - public String getAction() { - return action; - } - - public void setAction(String action) { - this.action = action; - } - - - @Override - public String toString() { - return "CancelExecutionParams{" + "action='" + action + '\'' + '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CloudifyError.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CloudifyError.java deleted file mode 100644 index 1638199ce9..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CloudifyError.java +++ /dev/null @@ -1,68 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import com.fasterxml.jackson.annotation.JsonProperty; - -/** - * This class represents a generic Cloudify error response body. These responses have a common format: { "message": - * "<error message>", "error_code": "<cloudify error id string>". "server_traceback": "<Python traceback>" } - * - * @author jc1348 - */ -public class CloudifyError implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("message") - private String message; - - @JsonProperty("error_code") - private String errorCode; - - @JsonProperty("server_traceback") - private String serverTraceback; - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public String getErrorCode() { - return errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getServerTraceback() { - return serverTraceback; - } - - public void setServerTraceback(String serverTraceback) { - this.serverTraceback = serverTraceback; - } -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CreateDeploymentParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CreateDeploymentParams.java deleted file mode 100644 index 66e9b61d27..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/CreateDeploymentParams.java +++ /dev/null @@ -1,58 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.io.Serializable; -import java.util.Map; - -public class CreateDeploymentParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("blueprint_id") - private String blueprintId; - - @JsonProperty("inputs") - private Map<String, Object> inputs; - - public String getBlueprintId() { - return blueprintId; - } - - public void setBlueprintId(String blueprintId) { - this.blueprintId = blueprintId; - } - - public Map<String, Object> getInputs() { - return inputs; - } - - public void setInputs(Map<String, Object> inputs) { - this.inputs = inputs; - } - - @Override - public String toString() { - return "CreateDeploymentBody{" + "blueprintId='" + blueprintId + '\'' + ", inputs=" + inputs + '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployment.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployment.java deleted file mode 100644 index 86a2b5f1bb..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployment.java +++ /dev/null @@ -1,358 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.IOException; -import java.io.Serializable; -import java.util.Date; -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; - -@JsonIgnoreProperties(ignoreUnknown = true) -// @JsonRootName("deployment") -public class Deployment implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("blueprint_id") - private String blueprintId; - - @JsonProperty("created_at") - private Date createdAt; - - @JsonProperty("created_by") - private String createdBy; - - @JsonProperty("description") - private String description; - - @JsonProperty("groups") - private Map<String, Group> groups = null; - - @JsonProperty("id") - private String id; - - @JsonProperty("inputs") - private Map<String, Object> inputs = null; - - // TODO: Expand the definition of a PolicyTrigger - @JsonProperty("policy_triggers") - private List<Object> policyTriggers; - - // TODO: Expand the definition of a PolicyType - @JsonProperty("policy_types") - private List<Object> policyTypes; - - @JsonProperty("scaling_groups") - private Map<String, ScalingGroup> scalingGroups = null; - - @JsonProperty("tenant_name") - private String tenantName; - - @JsonProperty("updated_at") - private Date updatedAt; - - @JsonProperty("workflows") - private List<Workflow> workflows; - - public List<Object> getPolicyTriggers() { - return policyTriggers; - } - - public void setPolicyTriggers(List<Object> policyTriggers) { - this.policyTriggers = policyTriggers; - } - - public List<Object> getPolicyTypes() { - return policyTypes; - } - - public void setPolicyTypes(List<Object> policyTypes) { - this.policyTypes = policyTypes; - } - - public String getBlueprintId() { - return blueprintId; - } - - public void setBlueprintId(String blueprintId) { - this.blueprintId = blueprintId; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public String getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Map<String, Group> getGroups() { - return this.groups; - } - - public void setGroups(Map<String, Group> groups) { - this.groups = groups; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Map<String, Object> getInputs() { - return this.inputs; - } - - public void setInputs(Map<String, Object> inputs) { - this.inputs = inputs; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public Map<String, ScalingGroup> getScalingGroups() { - return scalingGroups; - } - - public void setScalingGroups(Map<String, ScalingGroup> scalingGroups) { - this.scalingGroups = scalingGroups; - } - - public Date getUpdatedAt() { - return updatedAt; - } - - public void setUpdatedAt(Date updatedAt) { - this.updatedAt = updatedAt; - } - - public List<Workflow> getWorkflows() { - return workflows; - } - - public void setWorkflows(List<Workflow> workflows) { - this.workflows = workflows; - } - - /* - * Nested subclasses for Group definitions - */ - public static final class Group { - @JsonProperty("policies") - Object policies; - - @JsonProperty("members") - List<String> members; - - public Object getPolicies() { - return policies; - } - - public void setPolicies(Object policies) { - this.policies = policies; - } - - public List<String> getMembers() { - return members; - } - - public void setMembers(List<String> members) { - this.members = members; - } - } - - /* - * Nested subclasses for Scaling Group definitions - */ - public static final class ScalingGroup { - @JsonProperty("properties") - ScalingGroupProperties properties; - - @JsonProperty("members") - List<String> members; - - public ScalingGroupProperties getProperties() { - return properties; - } - - public void setProperties(ScalingGroupProperties properties) { - this.properties = properties; - } - - public List<String> getMembers() { - return members; - } - - public void setMembers(List<String> members) { - this.members = members; - } - } - - public static final class ScalingGroupProperties { - @JsonProperty("current_instances") - int currentInstances; - - @JsonProperty("default_instances") - int defaultInstances; - - @JsonProperty("max_instances") - int maxInstances; - - @JsonProperty("min_instances") - int minInstances; - - @JsonProperty("planned_instances") - int plannedInstances; - - public int getCurrentInstances() { - return currentInstances; - } - - public void setCurrentInstances(int currentInstances) { - this.currentInstances = currentInstances; - } - - public int getDefaultInstances() { - return defaultInstances; - } - - public void setDefaultInstances(int defaultInstances) { - this.defaultInstances = defaultInstances; - } - - public int getMaxInstances() { - return maxInstances; - } - - public void setMaxInstances(int maxInstances) { - this.maxInstances = maxInstances; - } - - public int getMinInstances() { - return minInstances; - } - - public void setMinInstances(int minInstances) { - this.minInstances = minInstances; - } - - public int getPlannedInstances() { - return plannedInstances; - } - - public void setPlannedInstances(int plannedInstances) { - this.plannedInstances = plannedInstances; - } - } - - /* - * Nested subclass for Deployment Workflow entities. Note that Blueprint class also contains a slightly different - * Workflow structure. - */ - public static final class Workflow { - @JsonProperty("name") - private String name; - @JsonProperty("created_at") - private Date createdAt; - @JsonProperty("parameters") - private Map<String, ParameterDefinition> parameters; - - public Workflow() {} - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public Map<String, ParameterDefinition> getParameters() { - return parameters; - } - - public void setParameters(Map<String, ParameterDefinition> parameters) { - this.parameters = parameters; - } - } - - /* - * Return an output as a Json-mapped Object of the provided type. This is useful for json-object outputs. - */ - public <T> T getMapValue(Map<String, Object> map, String key, Class<T> type) { - - ObjectMapper mapper = new ObjectMapper(); - if (map.containsKey(key)) { - try { - String s = mapper.writeValueAsString(map.get(key)); - return (mapper.readValue(s, type)); - } catch (IOException e) { - return null; - } - } - return null; - } - - @Override - public String toString() { - return "Deployment{" + "id='" + id + '\'' + ", description='" + description + '\'' + ", blueprintId='" - + blueprintId + '\'' + ", createdBy='" + createdBy + '\'' + ", tenantName='" + tenantName + '\'' - + ", createdAt=" + createdAt + ", updatedAt=" + updatedAt + ", inputs='" + inputs + '\'' - + ", workflows=" + workflows + ", groups=" + groups + '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/DeploymentOutputs.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/DeploymentOutputs.java deleted file mode 100644 index 1f34534a15..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/DeploymentOutputs.java +++ /dev/null @@ -1,81 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.IOException; -import java.io.Serializable; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.ObjectMapper; - -@JsonIgnoreProperties(ignoreUnknown = true) -// @JsonRootName("outputs") -public class DeploymentOutputs implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("deployment_id") - private String deploymentId; - - @JsonProperty("outputs") - private Map<String, Object> outputs = null; - - public Map<String, Object> getOutputs() { - return this.outputs; - } - - public void setOutputs(Map<String, Object> outputs) { - this.outputs = outputs; - } - - public String getDeploymentId() { - return deploymentId; - } - - public void setDeploymentId(String deploymentId) { - this.deploymentId = deploymentId; - } - - /* - * Return an output as a Json-mapped Object of the provided type. This is useful for json-object outputs. - */ - public <T> T getMapValue(Map<String, Object> map, String key, Class<T> type) { - - ObjectMapper mapper = new ObjectMapper(); - - if (map.containsKey(key)) { - try { - String s = mapper.writeValueAsString(map.get(key)); - return (mapper.readValue(s, type)); - } catch (IOException e) { - return null; - } - } - return null; - } - - @Override - public String toString() { - return "DeploymentOutputs{" + "deploymentId='" + deploymentId + '\'' + ", outputs='" + outputs + '\'' + '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployments.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployments.java deleted file mode 100644 index b97164f528..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Deployments.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.io.Serializable; -import java.util.List; - -public class Deployments implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("items") - private List<Deployment> items; - - @JsonProperty("metadata") - private Metadata metadata; - - public List<Deployment> getItems() { - return items; - } - - public void setItems(List<Deployment> items) { - this.items = items; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Execution.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Execution.java deleted file mode 100644 index 258d8e525a..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Execution.java +++ /dev/null @@ -1,165 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import java.util.Date; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties(ignoreUnknown = true) -// @JsonRootName("execution") -public class Execution implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("blueprint_id") - private String blueprintId; - - @JsonProperty("created_at") - private Date createdAt; - - @JsonProperty("created_by") - private String createdBy; - - @JsonProperty("deployment_id") - private String deploymentId; - - @JsonProperty("error") - private String error; - - @JsonProperty("id") - private String id; - - @JsonProperty("is_system_workflow") - private boolean isSystemWorkflow; - - @JsonProperty("parameters") - private Map<String, Object> parameters; - - @JsonProperty("status") - private String status; - - @JsonProperty("tenant_name") - private String tenantName; - - @JsonProperty("workflow_id") - private String workflowId; - - public String getBlueprintId() { - return blueprintId; - } - - public void setBlueprintId(String blueprintId) { - this.blueprintId = blueprintId; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public String getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - public String getDeploymentId() { - return deploymentId; - } - - public void setDeploymentId(String deploymentId) { - this.deploymentId = deploymentId; - } - - public String getError() { - return error; - } - - public void setError(String error) { - this.error = error; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public boolean isSystemWorkflow() { - return isSystemWorkflow; - } - - public void setSystemWorkflow(boolean isSystemWorkflow) { - this.isSystemWorkflow = isSystemWorkflow; - } - - public Map<String, Object> getParameters() { - return parameters; - } - - public void setParameters(Map<String, Object> parameters) { - this.parameters = parameters; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public String getWorkflowId() { - return workflowId; - } - - public void setWorkflowId(String workflowId) { - this.workflowId = workflowId; - } - - @Override - public String toString() { - return "Execution{" + "id='" + id + '\'' + ", blueprintId='" + blueprintId + '\'' + ", createdBy='" + createdBy - + '\'' + ", createdAt=" + createdAt + ", deploymentId='" + deploymentId + '\'' + ", error=" + error - + ", isSystemWorkflow=" + isSystemWorkflow + ", status=" + status + ", tenantName='" + tenantName + '\'' - + ", parameters=" + parameters + '}'; - } - - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Executions.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Executions.java deleted file mode 100644 index e238bc7fee..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Executions.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.io.Serializable; -import java.util.List; - -public class Executions implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("items") - private List<Execution> items; - - @JsonProperty("metadata") - private Metadata metadata; - - public List<Execution> getItems() { - return items; - } - - public void setItems(List<Execution> items) { - this.items = items; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Metadata.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Metadata.java deleted file mode 100644 index 269ed9db8a..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Metadata.java +++ /dev/null @@ -1,49 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.io.Serializable; - -/** - * This class represents a generic Cloudify response to a GET command. These responses have a common format: { "items": - * [ List of objects of the requested type ], "metadata": { } } - * - * @author jc1348 - * - */ -public class Metadata implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("pagination") - private Pagination pagination; - - - public Pagination getPagination() { - return pagination; - } - - public void setPagination(Pagination pagination) { - this.pagination = pagination; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstance.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstance.java deleted file mode 100644 index 4d7f8fb749..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstance.java +++ /dev/null @@ -1,197 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import java.util.List; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonRootName; - -@JsonIgnoreProperties(ignoreUnknown = true) -@JsonRootName("node_instance") -public class NodeInstance implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("created_by") - private String createdBy; - - @JsonProperty("deployment_id") - private String deploymentId; - - @JsonProperty("host_id") - private String hostId; - - @JsonProperty("id") - private String id; - - @JsonProperty("node_id") - private String nodeId; - - @JsonProperty("relationships") - private List<Object> relationships = null; - - @JsonProperty("runtime_properties") - private Map<String, Object> runtimeProperties = null; - - @JsonProperty("scaling_groups") - private List<ScalingGroupIdentifier> scalingGroups; - - @JsonProperty("state") - private String state; - - @JsonProperty("tenant_name") - private String tenantName; - - @JsonProperty("version") - private String version; - - public String getCreatedBy() { - return createdBy; - } - - public void setCreatedBy(String createdBy) { - this.createdBy = createdBy; - } - - public String getDeploymentId() { - return deploymentId; - } - - public void setDeploymentId(String deploymentId) { - this.deploymentId = deploymentId; - } - - public String getHostId() { - return hostId; - } - - public void setHostId(String hostId) { - this.hostId = hostId; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getNodeId() { - return nodeId; - } - - public void setNodeId(String nodeId) { - this.nodeId = nodeId; - } - - public List<Object> getRelationships() { - return relationships; - } - - public void setRelationships(List<Object> relationships) { - this.relationships = relationships; - } - - public Map<String, Object> getRuntimeProperties() { - return runtimeProperties; - } - - public void setRuntimeProperties(Map<String, Object> runtimeProperties) { - this.runtimeProperties = runtimeProperties; - } - - public List<ScalingGroupIdentifier> getScalingGroups() { - return scalingGroups; - } - - public void setScalingGroups(List<ScalingGroupIdentifier> scalingGroups) { - this.scalingGroups = scalingGroups; - } - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - /* - * Nested structure representing scaling groups in which this node is a member - */ - public static final class ScalingGroupIdentifier { - @JsonProperty("name") - private String name; - - @JsonProperty("id") - private String id; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String toString() { - return "Scaling Group{ name=" + name + ", id=" + id + "}"; - } - } - - @Override - public String toString() { - return "Deployment{" + "id='" + id + '\'' + "nodeId='" + nodeId + '\'' + ", createdBy='" + createdBy + '\'' - + ", tenantName='" + tenantName + '\'' + ", state=" + state + ", deploymentId=" + deploymentId - + ", hostId='" + hostId + '\'' + ", version='" + version + '\'' + ", relationships=" + relationships - + ", runtimeProperties=" + runtimeProperties + ", scalingGroups=" + scalingGroups + '}'; - } - - // TODO: Need an object structure for Relationships -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstances.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstances.java deleted file mode 100644 index 8dd30d9696..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/NodeInstances.java +++ /dev/null @@ -1,53 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.io.Serializable; -import java.util.List; - -public class NodeInstances implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("items") - private List<NodeInstance> items; - - @JsonProperty("metadata") - private Metadata metadata; - - public List<NodeInstance> getItems() { - return items; - } - - public void setItems(List<NodeInstance> items) { - this.items = items; - } - - public Metadata getMetadata() { - return metadata; - } - - public void setMetadata(Metadata metadata) { - this.metadata = metadata; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/OpenstackConfig.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/OpenstackConfig.java deleted file mode 100644 index 8914a83a55..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/OpenstackConfig.java +++ /dev/null @@ -1,88 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class OpenstackConfig implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("username") - String username; - - @JsonProperty("password") - String password; - - @JsonProperty("tenant_name") - String tenantName; - - @JsonProperty("auth_url") - String authUrl; - - @JsonProperty("region") - String region; - - // NOTE: Not supporting "custom_configuration" - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getTenantName() { - return tenantName; - } - - public void setTenantName(String tenantName) { - this.tenantName = tenantName; - } - - public String getAuthUrl() { - return authUrl; - } - - public void setAuthUrl(String authUrl) { - this.authUrl = authUrl; - } - - public String getRegion() { - return region; - } - - public void setRegion(String region) { - this.region = region; - } - - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Pagination.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Pagination.java deleted file mode 100644 index a292b13881..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Pagination.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; - -public class Pagination { - @JsonProperty("total") - private int total; - @JsonProperty("offset") - private int offset; - @JsonProperty("size") - private int size; - - public int getTotal() { - return total; - } - - public void setTotal(int total) { - this.total = total; - } - - public int getOffset() { - return offset; - } - - public void setOffset(int offset) { - this.offset = offset; - } - - public int getSize() { - return size; - } - - public void setSize(int size) { - this.size = size; - } -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/ParameterDefinition.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/ParameterDefinition.java deleted file mode 100644 index 1ff70b68d6..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/ParameterDefinition.java +++ /dev/null @@ -1,62 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties(ignoreUnknown = true) -public class ParameterDefinition implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("type") - private String type; - @JsonProperty("description") - private String description; - @JsonProperty("default") - private Object defaultValue; - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public Object getDefaultValue() { - return defaultValue; - } - - public void setDefaultValue(Object defaultValue) { - this.defaultValue = defaultValue; - } -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/StartExecutionParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/StartExecutionParams.java deleted file mode 100644 index e12b7d094c..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/StartExecutionParams.java +++ /dev/null @@ -1,93 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import java.util.Map; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class StartExecutionParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("workflow_id") - private String workflowId; - - @JsonProperty("deployment_id") - private String deploymentId; - - @JsonProperty("allow_custom_parameters") - private boolean allowCustomParameters; - - @JsonProperty("force") - private boolean force; - - @JsonProperty("parameters") - private Map<String, Object> parameters; - - public String getWorkflowId() { - return workflowId; - } - - public void setWorkflowId(String workflowId) { - this.workflowId = workflowId; - } - - public String getDeploymentId() { - return deploymentId; - } - - public void setDeploymentId(String deploymentId) { - this.deploymentId = deploymentId; - } - - public boolean isAllowCustomParameters() { - return allowCustomParameters; - } - - public void setAllowCustomParameters(boolean allowCustomParameters) { - this.allowCustomParameters = allowCustomParameters; - } - - public boolean isForce() { - return force; - } - - public void setForce(boolean force) { - this.force = force; - } - - public Map<String, Object> getParameters() { - return parameters; - } - - public void setParameters(Map<String, Object> parameters) { - this.parameters = parameters; - } - - @Override - public String toString() { - return "UpdateExecutionParams{" + "workflowId='" + workflowId + '\'' + "deploymentId='" + deploymentId + '\'' - + "allowCustomParameters='" + allowCustomParameters + '\'' + "force='" + force + '\'' + "parameters='" - + parameters + '\'' + '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Token.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Token.java deleted file mode 100644 index c5809d4a32..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/Token.java +++ /dev/null @@ -1,63 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; - -@JsonIgnoreProperties(ignoreUnknown = true) -// @JsonRootName("token") -// The Token object is returned without a root element -public class Token implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("role") - private String role; - - @JsonProperty("value") - private String value; - - // Any expiration? Maybe something in the Headers? - - public String getRole() { - return role; - } - - public void setRole(String role) { - this.role = role; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - - @Override - public String toString() { - return "Token{" + "role='" + role + '\'' + ", value='" + value + '\'' + '}'; - } -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateExecutionParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateExecutionParams.java deleted file mode 100644 index 3f49b90626..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateExecutionParams.java +++ /dev/null @@ -1,47 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import java.io.Serializable; -import com.fasterxml.jackson.annotation.JsonProperty; - -public class UpdateExecutionParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("status") - private String status; - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - - @Override - public String toString() { - return "UpdateExecutionParams{" + "status='" + status + '\'' + '}'; - } - -} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateNodeInstanceParams.java b/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateNodeInstanceParams.java deleted file mode 100644 index fabb70a49a..0000000000 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/v3/model/UpdateNodeInstanceParams.java +++ /dev/null @@ -1,72 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import java.io.Serializable; -import java.util.Map; - -public class UpdateNodeInstanceParams implements Serializable { - - private static final long serialVersionUID = 1L; - - @JsonProperty("state") - private String state; - - @JsonProperty("version") - private String version; - - @JsonProperty("runtime_properties") - private Map<String, Object> runtimeProperties; - - - public String getState() { - return state; - } - - public void setState(String state) { - this.state = state; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public Map<String, Object> getRuntimeProperties() { - return runtimeProperties; - } - - public void setRuntimeProperties(Map<String, Object> runtimeProperties) { - this.runtimeProperties = runtimeProperties; - } - - - @Override - public String toString() { - return "UpdateNodeInstanceParams{" + "state='" + state + '\'' + "version='" + version + '\'' - + ", runtimeProperties=" + runtimeProperties + '}'; - } - -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java deleted file mode 100644 index 4028b71109..0000000000 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/BeanMultiTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify; - -import org.junit.Before; -import org.junit.Test; -import com.openpojo.reflection.PojoClass; -import com.openpojo.reflection.PojoClassFilter; -import com.openpojo.reflection.filters.FilterEnum; -import com.openpojo.reflection.impl.PojoClassFactory; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.rule.impl.GetterMustExistRule; -import com.openpojo.validation.rule.impl.SetterMustExistRule; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - -public class BeanMultiTest { - - Validator validator; - PojoClassFilter enumFilter; - private PojoClassFilter filterTestClasses = new FilterTestClasses(); - - @Before - public void setup() { - enumFilter = new FilterEnum(); - validator = ValidatorBuilder.create().with(new SetterMustExistRule(), new GetterMustExistRule()) - .with(new SetterTester(), new GetterTester()).build(); - } - - @Test - public void validateBeansMsoApihandlerBeans() { - - validator.validate("org.onap.so.cloudify.v3.model", enumFilter); - } - - private static class FilterTestClasses implements PojoClassFilter { - public boolean include(PojoClass pojoClass) { - return !pojoClass.getSourcePath().contains("/src/test/java"); - } - } -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java deleted file mode 100644 index 88974acb11..0000000000 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.base.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.so.cloudify.v3.model.Execution; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class CloudifyClientTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void clientCreate() { - wireMockRule.stubFor( - get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClient cc = new CloudifyClient("http://localhost:" + port); - cc.setToken("token"); - CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void clientCreateWithBadConnector() { - thrown.expect(CloudifyResponseException.class); - wireMockRule.stubFor( - get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClientConnector ccc = new CloudifyClientConnector() { - @Override - public <T> CloudifyResponse request(CloudifyRequest<T> request) { - throw new CloudifyResponseException("test case", 401); - } - }; - CloudifyClient cc = new CloudifyClient("http://localhost:" + port, ccc); - // cc.setToken("token"); - CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - } - - @Test - public void clientCreateWithBadConnectorAndToken() { - thrown.expect(CloudifyResponseException.class); - wireMockRule.stubFor( - get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClientConnector ccc = new CloudifyClientConnector() { - @Override - public <T> CloudifyResponse request(CloudifyRequest<T> request) { - throw new CloudifyResponseException("test case", 401); - } - }; - CloudifyClient cc = new CloudifyClient("http://localhost:" + port, ccc); - cc.setToken("token"); - CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - } - - @Test - public void clientCreateWithTenant() { - wireMockRule.stubFor( - get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"id\": \"123\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - CloudifyClient cc = new CloudifyClient("http://localhost:" + port, "other_tenant"); - cc.setToken("token"); - cc.property("property", "value"); - CloudifyRequest<Execution> crx = cc.get("/testUrl", Execution.class); - Execution x = crx.execute(); - assertEquals("123", x.getId()); - } - -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java deleted file mode 100644 index 77152a2dd0..0000000000 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/base/client/CloudifyClientTokenProviderTest.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.base.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class CloudifyClientTokenProviderTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void createTokenProvider() { - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl/api/v3/tokens")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"role\": \"user\", \"value\": \"tokenVal\"}").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - - CloudifyClientTokenProvider cctp = - new CloudifyClientTokenProvider("http://localhost:" + port + "/testUrl", "user", "pswd"); - String token = cctp.getToken(); - assertEquals("tokenVal", token); - token = cctp.getToken(); - assertEquals("tokenVal", token); - cctp.expireToken(); - } -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java deleted file mode 100644 index c85b88f7f3..0000000000 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientConnectorTest.java +++ /dev/null @@ -1,255 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.connector.http; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import com.github.tomakehurst.wiremock.http.Fault; -import com.github.tomakehurst.wiremock.junit.WireMockRule; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.delete; -import static com.github.tomakehurst.wiremock.client.WireMock.put; -import static com.github.tomakehurst.wiremock.client.WireMock.equalTo; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static com.github.tomakehurst.wiremock.client.WireMock.postRequestedFor; -import static com.github.tomakehurst.wiremock.client.WireMock.verify; -import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; -import static com.github.tomakehurst.wiremock.client.WireMock.putRequestedFor; -import static com.github.tomakehurst.wiremock.client.WireMock.deleteRequestedFor; -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.assertEquals; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import org.onap.so.cloudify.base.client.CloudifyConnectException; -import org.onap.so.cloudify.base.client.CloudifyRequest; -import org.onap.so.cloudify.base.client.CloudifyResponseException; -import org.onap.so.cloudify.base.client.Entity; -import org.onap.so.cloudify.base.client.HttpMethod; -import org.onap.so.cloudify.v3.model.Deployment; - -public class HttpClientConnectorTest { - - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void sunnyDay_POST() { - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - Deployment deployment = new Deployment(); - deployment.setId("id"); - request.entity(deployment, "application/json"); - request.endpoint("http://localhost:" + port + "/testUrl"); - request.setBasicAuthentication("USER", "PASSWORD"); - request.header("Content-Type", "application/json"); - request.method(HttpMethod.POST); - conector.request(request); - verify(postRequestedFor(urlEqualTo("/testUrl"))); - } - - - @Test - public void sunnyDay_GET() { - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:" + port + "/testUrl"); - request.setBasicAuthentication("USER", "PASSWORD"); - request.method(HttpMethod.GET); - conector.request(request); - verify(getRequestedFor(urlEqualTo("/testUrl"))); - } - - @Test - public void sunnyDay_PUT() { - wireMockRule.stubFor(put(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:" + port + "/testUrl"); - request.setBasicAuthentication("USER", "PASSWORD"); - request.method(HttpMethod.PUT); - conector.request(request); - verify(putRequestedFor(urlEqualTo("/testUrl"))); - } - - - @Test - public void sunnyDay_DELETE() { - wireMockRule.stubFor(delete(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:" + port + "/testUrl"); - request.setBasicAuthentication("USER", "PASSWORD"); - request.method(HttpMethod.DELETE); - conector.request(request); - verify(deleteRequestedFor(urlEqualTo("/testUrl"))); - } - - - @Test - public void rainyDay_PATCH() { - thrown.expect(HttpClientException.class); - thrown.expectMessage("Unrecognized HTTP Method: PATCH"); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:123123/testUrl"); - request.setBasicAuthentication("USER", "PASSWORD"); - request.method(HttpMethod.PATCH); - conector.request(request); - - } - - @Test - public void rainyDayRunTimeException() { - wireMockRule.stubFor(post(urlEqualTo("/503")) - .willReturn(aResponse().withStatus(503).withHeader("Content-Type", "text/plain").withBody("failure"))); - thrown.expect(RuntimeException.class); - thrown.expectMessage("Unexpected client exception"); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:123123/503"); - request.setBasicAuthentication("USER", "PASSWORD"); - request.method(HttpMethod.POST); - conector.request(request); - - } - - @Test - public void rainyDayBadUri() { - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - thrown.expect(HttpClientException.class); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - Deployment deployment = new Deployment(); - deployment.setId("id"); - request.entity(deployment, "application/json"); - request.endpoint("(@#$@(#*$&asfasdf"); - request.setBasicAuthentication("USER", "PASSWORD"); - request.header("Content-Type", "application/json"); - request.method(HttpMethod.POST); - conector.request(request); - } - - @Test - public void sunnyDayWithJsonEntity_POST() { - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - - Deployment deployment = new Deployment(); - deployment.setId("id"); - - CloudifyRequest<Deployment> request = - new CloudifyRequest<Deployment>(null, HttpMethod.POST, "/", Entity.json(deployment), null); - - request.endpoint("http://localhost:" + port); - request.path("testUrl"); - request.header("Content-Type", "application/json"); - request.header("Content-Type", null); - - request.returnType(Deployment.class); - assertEquals(Deployment.class, request.returnType()); - - Entity<Deployment> t = request.json(deployment); - assertEquals(t.getEntity().getId(), "id"); - - request.queryParam("test", "one").queryParam("test", "two"); - - conector.request(request); - - verify(postRequestedFor(urlEqualTo("/testUrl?test=two"))); - } - - @Test - public void sunnyDayWithStreamEntity_POST() { - wireMockRule.stubFor(post(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_OK))); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - - InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); - - CloudifyRequest<Deployment> request = - new CloudifyRequest<Deployment>(null, HttpMethod.POST, "/testUrl", Entity.stream(is), null); - - request.endpoint("http://localhost:" + port); - request.setBasicAuthentication("USER", "PASSWORD"); - request.header("Content-Type", "application/json"); - - conector.request(request); - verify(postRequestedFor(urlEqualTo("/testUrl"))); - } - - @Test - public void rainyDayGarbageData() { - wireMockRule.stubFor( - get(urlPathEqualTo("/testUrl")).willReturn(aResponse().withFault(Fault.RANDOM_DATA_THEN_CLOSE))); - thrown.expect(CloudifyConnectException.class); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:" + port + "/testUrl"); - request.setBasicAuthentication("USER", "PASSWORD"); - request.method(HttpMethod.GET); - conector.request(request); - } - - @Test - public void rainyDayEmptyResponse() { - wireMockRule.stubFor(get(urlPathEqualTo("/testUrl")).willReturn(aResponse() - .withHeader("Content-Type", "application/json").withBody("TEST").withStatus(HttpStatus.SC_NOT_FOUND))); - - thrown.expect(HttpClientException.class); - int port = wireMockRule.port(); - HttpClientConnector conector = new HttpClientConnector(); - CloudifyRequest<Deployment> request = new CloudifyRequest<Deployment>(); - request.endpoint("http://localhost:" + port + "/testUrl"); - request.setBasicAuthentication("USER", "PASSWORD"); - request.method(HttpMethod.GET); - conector.request(request); // gets down to "Get here on an error response (4XX-5XX)", then tries to throw a - // CloudifyResponseException, which calls getEntity, which tries to parse an HTML - // error page as a JSON, which causes the HttpClientException. - } - - -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java deleted file mode 100644 index 6010726669..0000000000 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/connector/http/HttpClientRedirectStrategyTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * ============LICENSE_START======================================================= ONAP : SO - * ================================================================================ Copyright (C) 2018 Nokia. - * ============================================================================= Licensed under the Apache License, - * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy - * of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * ============LICENSE_END========================================================= - */ -package org.onap.so.cloudify.connector.http; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; -import static org.mockito.Mockito.mock; -import java.net.URI; -import java.net.URISyntaxException; -import org.apache.http.HttpRequest; -import org.apache.http.HttpResponse; -import org.apache.http.HttpStatus; -import org.apache.http.ProtocolException; -import org.apache.http.client.methods.HttpDelete; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpHead; -import org.apache.http.client.methods.HttpOptions; -import org.apache.http.client.methods.HttpPatch; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.client.methods.HttpPut; -import org.apache.http.client.methods.HttpTrace; -import org.apache.http.client.methods.HttpUriRequest; -import org.apache.http.protocol.HttpContext; -import org.junit.Test; - -public class HttpClientRedirectStrategyTest { - - private HttpClientRedirectStrategy httpClientRedirectStrategy = new HttpClientRedirectStrategy(); - - @Test - public void isRedirectable_shouldReturnFalse_forNonRedirectableHttpMethods() { - assertThat(httpClientRedirectStrategy.isRedirectable(HttpPost.METHOD_NAME)).isFalse(); - assertThat(httpClientRedirectStrategy.isRedirectable(HttpPatch.METHOD_NAME)).isFalse(); - assertThat(httpClientRedirectStrategy.isRedirectable(HttpPut.METHOD_NAME)).isFalse(); - assertThat(httpClientRedirectStrategy.isRedirectable(HttpOptions.METHOD_NAME)).isFalse(); - assertThat(httpClientRedirectStrategy.isRedirectable(HttpTrace.METHOD_NAME)).isFalse(); - } - - @Test - public void isRedirectable_shouldReturnTrue_forRedirectableHttpMethods() { - assertThat(httpClientRedirectStrategy.isRedirectable(HttpGet.METHOD_NAME)).isTrue(); - assertThat(httpClientRedirectStrategy.isRedirectable(HttpDelete.METHOD_NAME)).isTrue(); - assertThat(httpClientRedirectStrategy.isRedirectable(HttpHead.METHOD_NAME)).isTrue(); - } - - @Test - public void getRedirect_shouldReturnHttpHeadUriRequest() throws URISyntaxException, ProtocolException { - assertHttpUriRequestFor(HttpHead.METHOD_NAME, HttpHead.class); - } - - @Test - public void getRedirect_shouldReturnHttpGetUriRequest() throws URISyntaxException, ProtocolException { - assertHttpUriRequestFor(HttpGet.METHOD_NAME, HttpGet.class); - } - - private void assertHttpUriRequestFor(String methodName, Class<? extends HttpUriRequest> expectedHttpMethodClass) - throws URISyntaxException, ProtocolException { - // GIVEN - HttpRequest request = mock(HttpRequest.class, RETURNS_DEEP_STUBS); - given(request.getRequestLine().getMethod()).willReturn(methodName); - HttpResponse response = null; - HttpContext context = null; - URI expectedUri = new URI("http://localhost/host"); - // WHEN - HttpUriRequest httpUriRequest = - new TestableHttpClientRedirectStrategy(expectedUri).getRedirect(request, response, context); - // THEN - assertThat(httpUriRequest).isInstanceOf(expectedHttpMethodClass); - assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri); - } - - @Test - public void getRedirect_shouldReturnHttpGetUri_byDefault() throws URISyntaxException, ProtocolException { - // GIVEN - HttpRequest request = mock(HttpRequest.class, RETURNS_DEEP_STUBS); - given(request.getRequestLine().getMethod()).willReturn(HttpPost.METHOD_NAME); - HttpResponse response = mock(HttpResponse.class, RETURNS_DEEP_STUBS); - given(response.getStatusLine().getStatusCode()).willReturn(HttpStatus.SC_ACCEPTED); - URI expectedUri = new URI("http://localhost/host"); - HttpContext context = null; - // WHEN - HttpUriRequest httpUriRequest = - new TestableHttpClientRedirectStrategy(expectedUri).getRedirect(request, response, context); - // THEN - assertThat(httpUriRequest).isInstanceOf(HttpGet.class); - assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri); - } - - @Test - public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forMovedTemporarilyStatus() - throws URISyntaxException, ProtocolException { - assertHttpRequestIsCopied(HttpStatus.SC_MOVED_TEMPORARILY); - } - - @Test - public void getRedirect_shouldCopyHttpRequestAndSetNewUri_forTemporaryRedirectStatus() - throws URISyntaxException, ProtocolException { - assertHttpRequestIsCopied(HttpStatus.SC_TEMPORARY_REDIRECT); - } - - private void assertHttpRequestIsCopied(int expectedHttpStatus) throws URISyntaxException, ProtocolException { - // GIVEN - HttpRequest request = mock(HttpRequest.class, RETURNS_DEEP_STUBS); - given(request.getRequestLine().getMethod()).willReturn(HttpGet.METHOD_NAME); - given(request.getRequestLine().getUri()).willReturn("http://hostname"); - HttpResponse response = mock(HttpResponse.class, RETURNS_DEEP_STUBS); - given(response.getStatusLine().getStatusCode()).willReturn(expectedHttpStatus); - URI expectedUri = new URI("http://localhost/host"); - HttpContext context = null; - // WHEN - HttpUriRequest httpUriRequest = - new TestableHttpClientRedirectStrategy(expectedUri).getRedirect(request, response, context); - // THEN - assertThat(httpUriRequest).isInstanceOf(HttpGet.class); - assertThat(httpUriRequest.getURI()).isEqualTo(expectedUri); - } - - private static class TestableHttpClientRedirectStrategy extends HttpClientRedirectStrategy { - - private final URI expectedUri; - - public TestableHttpClientRedirectStrategy(URI expectedUri) { - this.expectedUri = expectedUri; - } - - @Override - public URI getLocationURI(HttpRequest request, HttpResponse response, HttpContext context) { - return expectedUri; - } - } -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java deleted file mode 100644 index cba3bf8fdc..0000000000 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/BlueprintsResourceTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -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.put; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.so.cloudify.v3.client.BlueprintsResource.DeleteBlueprint; -import org.onap.so.cloudify.v3.client.BlueprintsResource.GetBlueprint; -import org.onap.so.cloudify.v3.client.BlueprintsResource.ListBlueprints; -import org.onap.so.cloudify.v3.client.BlueprintsResource.UploadBlueprint; -import org.onap.so.cloudify.v3.model.Blueprint; -import org.onap.so.cloudify.v3.model.Blueprints; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class BlueprintsResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void cloudifyClientBlueprintFromStream() { - wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - BlueprintsResource br = c.blueprints(); - InputStream is = new ByteArrayInputStream("{}".getBytes(StandardCharsets.UTF_8)); - UploadBlueprint ub = br.uploadFromStream("123", "blueprint.json", is); - Blueprint b = ub.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintFromUrl() { - wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/blueprints/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - BlueprintsResource br = c.blueprints(); - UploadBlueprint ub = br.uploadFromUrl("123", "blueprint.json", "http://localhost:" + port + "/blueprint"); - Blueprint b = ub.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintDelete() { - wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/blueprints/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - BlueprintsResource br = c.blueprints(); - DeleteBlueprint db = br.deleteById("123"); - Blueprint b = db.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintList() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{\"items\": [{\"id\": \"123\"}]}").withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - BlueprintsResource br = c.blueprints(); - ListBlueprints lb = br.list(); - Blueprints b = lb.execute(); - assertEquals("123", b.getItems().get(0).getId()); - } - - @Test - public void cloudifyClientBlueprintGetById() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - BlueprintsResource br = c.blueprints(); - GetBlueprint gb = br.getById("123"); - Blueprint b = gb.execute(); - assertEquals("123", b.getId()); - } - - @Test - public void cloudifyClientBlueprintGetMetadataById() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/blueprints/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{\"id\": \"123\"}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - BlueprintsResource br = c.blueprints(); - GetBlueprint gb = br.getMetadataById("123"); - Blueprint b = gb.execute(); - assertEquals("123", b.getId()); - } - - -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java deleted file mode 100644 index 2acd4ba5a3..0000000000 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/DeploymentsResourceTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -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.put; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import java.util.HashMap; -import java.util.Map; -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.so.cloudify.v3.client.DeploymentsResource.CreateDeployment; -import org.onap.so.cloudify.v3.client.DeploymentsResource.DeleteDeployment; -import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeployment; -import org.onap.so.cloudify.v3.client.DeploymentsResource.GetDeploymentOutputs; -import org.onap.so.cloudify.v3.client.DeploymentsResource.ListDeployments; -import org.onap.so.cloudify.v3.model.CreateDeploymentParams; -import org.onap.so.cloudify.v3.model.Deployment; -import org.onap.so.cloudify.v3.model.Deployments; -import org.onap.so.cloudify.v3.model.DeploymentOutputs; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class DeploymentsResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void cloudifyDeploymentsCreate() { - wireMockRule.stubFor(put(urlPathEqualTo("/api/v3/deployments/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - DeploymentsResource br = c.deployments(); - - CreateDeploymentParams cdp = new CreateDeploymentParams(); - cdp.setBlueprintId("123"); - Map<String, Object> inputs = new HashMap<String, Object>(); - cdp.setInputs(inputs); - CreateDeployment cd = br.create("123", cdp); - Deployment d = cd.execute(); - assertEquals("123", d.getId()); - } - - @Test - public void cloudifyDeploymentsList() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"items\": {\"id\": \"123\" } } ").withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - DeploymentsResource br = c.deployments(); - ListDeployments ld = br.list(); - Deployments d = ld.execute(); - assertEquals("123", d.getItems().get(0).getId()); - } - - @Test - public void cloudifyDeploymentsGet() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - DeploymentsResource br = c.deployments(); - GetDeployment gd = br.byId("123"); - Deployment d = gd.execute(); - assertEquals("123", d.getId()); - } - - @Test - public void cloudifyDeploymentsGetOutputs() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/deployments/123/outputs")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"deployment_id\": \"123\" }").withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - DeploymentsResource br = c.deployments(); - GetDeploymentOutputs gdo = br.outputsById("123"); - DeploymentOutputs d = gdo.execute(); - assertEquals("123", d.getDeploymentId()); - - Map<String, Object> map = new HashMap<String, Object>(); - map.put("test", "answer"); - assertEquals("answer", d.getMapValue(map, "test", String.class)); - - Integer i = d.getMapValue(map, "nil", Integer.class); - assertNull(i); - - i = d.getMapValue(map, "test", Integer.class); - assertNull(i); - } - - @Test - public void cloudifyDeploymentsDelete() { - wireMockRule.stubFor(delete(urlPathEqualTo("/api/v3/deployments/name")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - DeploymentsResource br = c.deployments(); - DeleteDeployment cd = br.deleteByName("name"); - Deployment d = cd.execute(); - assertEquals("123", d.getId()); - } - -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java deleted file mode 100644 index 7b63c6eecb..0000000000 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/ExecutionsResourceTest.java +++ /dev/null @@ -1,174 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.patch; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.so.cloudify.connector.http.HttpClientException; -import org.onap.so.cloudify.v3.client.ExecutionsResource.CancelExecution; -import org.onap.so.cloudify.v3.client.ExecutionsResource.GetExecution; -import org.onap.so.cloudify.v3.client.ExecutionsResource.ListExecutions; -import org.onap.so.cloudify.v3.client.ExecutionsResource.StartExecution; -import org.onap.so.cloudify.v3.client.ExecutionsResource.UpdateExecution; -import org.onap.so.cloudify.v3.model.CancelExecutionParams; -import org.onap.so.cloudify.v3.model.Execution; -import org.onap.so.cloudify.v3.model.Executions; -import org.onap.so.cloudify.v3.model.StartExecutionParams; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class ExecutionsResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void cloudifyClientExecutions() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - "{\"items\": [{ \"id\": \"345\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - ExecutionsResource xr = c.executions(); - ListExecutions lx = xr.list(); - Executions x = lx.execute(); - assertEquals("123", x.getItems().get(1).getId()); - } - - @Test - public void cloudifyClientExecutionsSorted() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - "{\"items\": [{ \"id\": \"123\" }, { \"id\": \"345\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - ExecutionsResource xr = c.executions(); - ListExecutions lx = xr.listSorted("id"); - Executions x = lx.execute(); - assertEquals("345", x.getItems().get(1).getId()); - } - - @Test - public void cloudifyClientExecutionsFilter() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions")).willReturn(aResponse() - .withHeader("Content-Type", "application/json") - .withBody( - "{\"items\": [{ \"id\": \"121\" }, { \"id\": \"123\" }], \"metadata\": {\"pagination\": {\"total\": 100, \"offset\": 0, \"size\": 25}}}") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - ExecutionsResource xr = c.executions(); - ListExecutions lx = xr.listFiltered("a=b", "id"); - Executions x = lx.execute(); - assertEquals("123", x.getItems().get(1).getId()); - } - - @Test - public void cloudifyClientExecutionById() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/executions/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - ExecutionsResource xr = c.executions(); - GetExecution gx = xr.byId("123"); - Execution x = gx.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void cloudifyClientStartExecution() { - wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - ExecutionsResource xr = c.executions(); - - StartExecutionParams params = new StartExecutionParams(); - StartExecution sx = xr.start(params); - Execution x = sx.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void cloudifyClientUpdateExecution() { - thrown.expect(HttpClientException.class); - thrown.expectMessage("Unrecognized HTTP Method: PATCH"); - - wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/executions")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - ExecutionsResource xr = c.executions(); - - UpdateExecution ux = xr.updateStatus("123", "good"); - Execution x = ux.execute(); - assertEquals("123", x.getId()); - } - - @Test - public void cloudifyClientCancelExecution() { - wireMockRule.stubFor(post(urlPathEqualTo("/api/v3/executions/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json").withBody("{ \"id\": \"123\" }") - .withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - ExecutionsResource xr = c.executions(); - - CancelExecutionParams params = new CancelExecutionParams(); - CancelExecution cx = xr.cancel("123", params); - Execution x = cx.execute(); - assertEquals("123", x.getId()); - } - - - -} diff --git a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java b/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java deleted file mode 100644 index d38d0401c3..0000000000 --- a/cloudify-client/src/test/java/org/onap/so/cloudify/v3/client/NodeInstancesResourceTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.so.cloudify.v3.client; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.get; -import static com.github.tomakehurst.wiremock.client.WireMock.patch; -import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; -import static org.junit.Assert.assertEquals; -import org.apache.http.HttpStatus; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.onap.so.cloudify.connector.http.HttpClientException; -import org.onap.so.cloudify.v3.client.NodeInstancesResource.GetNodeInstance; -import org.onap.so.cloudify.v3.client.NodeInstancesResource.ListNodeInstances; -import org.onap.so.cloudify.v3.client.NodeInstancesResource.UpdateNodeInstance; -import org.onap.so.cloudify.v3.model.NodeInstance; -import org.onap.so.cloudify.v3.model.NodeInstances; -import org.onap.so.cloudify.v3.model.UpdateNodeInstanceParams; -import com.github.tomakehurst.wiremock.junit.WireMockRule; - -public class NodeInstancesResourceTest { - @Rule - public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void nodeInstanceGet() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances/123")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"node_instance\": { \"id\": \"123\" } }").withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - NodeInstancesResource nir = c.nodeInstances(); - GetNodeInstance gni = nir.byId("123"); - NodeInstance ni = gni.execute(); - assertEquals("123", ni.getId()); - } - - @Test - public void nodeInstanceList() { - wireMockRule.stubFor(get(urlPathEqualTo("/api/v3/node-instances")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - // .withBody(" { \"items\": [ { \"node_instance\": { \"id\": \"123\" } } ] } ") - .withBody(" { \"items\": [ { \"id\": \"123\" } ] } ").withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - NodeInstancesResource nir = c.nodeInstances(); - ListNodeInstances lni = nir.list(); - NodeInstances ni = lni.execute(); - assertEquals("123", ni.getItems().get(0).getId()); - } - - @Test - public void nodeInstanceUpdate() { - wireMockRule.stubFor(patch(urlPathEqualTo("/api/v3/node-instances/")) - .willReturn(aResponse().withHeader("Content-Type", "application/json") - .withBody("{ \"node_instance\": { \"id\": \"123\" } }").withStatus(HttpStatus.SC_OK))); - - int port = wireMockRule.port(); - - Cloudify c = new Cloudify("http://localhost:" + port, "tenant"); - NodeInstancesResource nir = c.nodeInstances(); - UpdateNodeInstanceParams params = new UpdateNodeInstanceParams(); - - UpdateNodeInstance uni = nir.update("123", params); - thrown.expect(HttpClientException.class); /// ??????? - NodeInstance ni = uni.execute(); - } -} diff --git a/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java b/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java index 26c3c0012a..83675da5f0 100644 --- a/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java +++ b/common/src/main/java/org/onap/so/beans/nsmf/AnSliceProfile.java @@ -21,6 +21,7 @@ package org.onap.so.beans.nsmf; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import lombok.Data; import java.util.List; @@ -28,24 +29,33 @@ import java.util.List; @Data public class AnSliceProfile { - private List<String> sNSSAIList; - + @JsonProperty(value = "sliceProfileId", required = true) private String sliceProfileId; - private List<Integer> coverageAreaTAList; - - @JsonInclude(JsonInclude.Include.NON_DEFAULT) - private int latency; + @JsonProperty(value = "sNSSAIList", required = true) + private List<String> sNSSAIList; + @JsonProperty(value = "pLMNIdList", required = true) private List<String> pLMNIdList; + @JsonProperty(value = "perfReq", required = true) private AnPerfReq perfReq; @JsonInclude(JsonInclude.Include.NON_DEFAULT) + @JsonProperty(value = "maxNumberofUEs") private long maxNumberofUEs; + @JsonProperty(value = "coverageAreaTAList") + private List<Integer> coverageAreaTAList; + + @JsonInclude(JsonInclude.Include.NON_DEFAULT) + @JsonProperty(value = "latency") + private int latency; + + @JsonProperty(value = "uEMobilityLevel") private UeMobilityLevel uEMobilityLevel; + @JsonProperty(value = "resourceSharingLevel") private ResourceSharingLevel resourceSharingLevel; } diff --git a/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java index fff82ea5bc..33958a7850 100644 --- a/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java +++ b/common/src/main/java/org/onap/so/utils/ExternalTaskServiceUtils.java @@ -1,8 +1,10 @@ package org.onap.so.utils; import java.security.GeneralSecurityException; +import java.util.List; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; import org.camunda.bpm.client.ExternalTaskClient; import org.camunda.bpm.client.interceptor.ClientRequestInterceptor; import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider; @@ -75,7 +77,20 @@ public class ExternalTaskServiceUtils { @ScheduledLogging @Scheduled(fixedDelay = 30000) public void checkAllClientsActive() { - getClients().stream().filter(client -> !client.isActive()).forEach(ExternalTaskClient::start); + try { + logger.debug("Executing scheduled task to check and restart external task clients"); // TODO remove + // eventually + List<ExternalTaskClient> inactiveClients = + getClients().stream().filter(client -> !client.isActive()).collect(Collectors.toList()); + + inactiveClients.forEach(c -> { + logger.debug("External Task Client found to be inactive. Restarting Client."); + c.start(); + }); + } catch (Exception e) { + logger.error("Exception occured in checkAllClientsActive", e); + } + } protected Set<ExternalTaskClient> getClients() { diff --git a/docs/developer_info/mso_adapter_restinterface.rst b/docs/developer_info/mso_adapter_restinterface.rst new file mode 100644 index 0000000000..49a9cadba4 --- /dev/null +++ b/docs/developer_info/mso_adapter_restinterface.rst @@ -0,0 +1,288 @@ +Mso-adapters-rest-interface +--------------------------- +.. image:: ../images/module_structure.png + +It mainly contains the payload that is provided to different rest calls in SO + +Network +-------- +# 1. Network contain beans( classes with multiple attributes and thier setters and getters) and their corresponding mappers which will be used by the network adapter of SO. Contrail networking is used for cloud network automation + +Beans +----- + # a. ContrailPolicyRef : this class has following attribute + private ContrailPolicyRefSeq seq; + + Usage: adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java- while creating network in openstack, network stack is created depending on stackParams. So if pFqdns(FQDN address object is used in order to use DNS names in firewall policies) are there in the inputrequest to createNetwork, then mergePolicyRefs method is called, where for each input pFqdns, a new ContrailPolicyRef is created and appended to a list. Then this is added as value to stackParams with policy_refsdata as key. + + # b. ContrailPolicyRefSeq : Attributes are + private String major; + + private String minor ; + + Usage: adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java- As this is an attribute to the ContrailPolicyRef explained above. So when a new ContrailPolicyRef() is created in mergePolicyRefs method, correspondingly a new ContrailPolicyRefSeq should be created. + + # c. ContrailSubnet – Its a subnetwork having attributes + private ContrailSubnetIp subnet = new ContrailSubnetIp(); + + private String defaultGateway; + + private String subnetName; + + private Boolean enableDhcp(dynamic host config); + + private Boolean addrFromStart = true; + + private List<ContrailSubnetPool> allocationPools = new ArrayList<>(); + + private ContrailSubnetHostRoutes hostRoutes = new ContrailSubnetHostRoutes(); + + Usage : adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java- While creating network mergeSubnetsAIC3 is called if a list of subnets are present. The subnets are mapped to ContrailSubnet using ContrailSubnetMapper, and then are added to the heat template and stackparams which are used for network creation in openstack. + + # d. ContrailSubnetHostRoute : This is an attribute defined in contrailsubnet and has following attributes + private String prefix; + + private String nextHop; + + Usage : This is an attribute of ContrailSubnetHostRoutes , which is used within the contrailSubnet and thus is used in network creation and updation. + + # e. ContrailSubnetHostRoutes : This class is used to store an list of ContrailSubnetHostRoute + + private List<ContrailSubnetHostRoute> hostRoutes = new ArrayList<>(); + + Usage : attribute of contrailSubnet + + # f. ContrailSubnetIp : attributes are + private String ipPrefix; + + private String ipPrefixLen; + + This class is used to store the cidr value , which is used as a interrouting table, taking as ipaddress/total no . Eg : 10.0.0.0/24 means starting ip is 10.0.0.0, and total no of ip address possible here is 256 (2^(32-24)), the last address being 10.0.0.255. + + Usage : important attribute of contrailSubnet + + # g. ContrailSubnetPool : attributes are starting and ending ip address of the subnet + private String start; + + private String end; + + Usage: a list of ContrailSubnetPool forms an important attribute of contrailSubnet + +Mappers +------- + + # a. ContrailSubnetMapper : It is used to map the inputsubnet to a contrailSubnet + public ContrailSubnetMapper(Subnet inputSubnet) { + this.inputSubnet = inputSubnet; + + } + + The map method within is used for the mapping. Here first a contrailSubnet is created, and depending on whether the subnet has name or id, the contrailSubnet’s name is initialized, then if it has cidr , then a contrailSubnetIp is created, and is added into it, which is then added to contrailSubnet created before. Depending on whether input has allocationpool or hostroutes, these are casted into ContrailSubnetPool and ContrailSubnetHostRoute using ContrailSubnetPoolMapper and ContrailSubnetPoolMapper respectively. + + Usage: adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/network/MsoNetworkAdapterImpl.java :The subnets are mapped to ContrailSubnet using ContrailSubnetMapper, and then are added to the heat template and stackparams which are used for network creation + + # b. ContrailSubnetPoolMapper : It is used to map the pool within the subnets to contrailSubnetPool. Used within contrailSubnetMapper. Here, the particular pool is added only if it has both the start and end ip address. + + # c. ContrailSubnetHostRoute : It is used to map the host routes within the subnets to contrailSubnetHostRoute. Used within contrailSubnetMapper. Here, the particular host route is added if either of the next hop or ip prefix is defined. + +Network request +--------------- + +#2. Network request : It contains the payloads for different types of network requests + + # a. ContrailNetwork : + private String shared = "false"; + + private String external = "false"; + + private List<RouteTarget> routeTargets; + + private List<String> policyFqdns; + + private List<String> routeTableFqdns; + + Usage: contrailNetwork is an important attribute of CreateNetworkRequest, So is to be used where all the request to createNetwork is required. + + # 1. adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/orchestration/StackService.java : Here the input to createNetwork requires contrailNetwork parameter, so here it checks whether contrailNetwork is already present, if not a new is created. + + # 2.bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java : Here in createNetworkRequestMapper, createNetworkRequest is formed where in buildContrailNetwork, a new contrailNetwork is created and initialized. This request is used to create a network and set the corresponding execution variable + + # b. CreateNetworkError: It extends NetworkExceptionResponse. And is used when an error occurs during network creation + + # c. NetworkExceptionResponse : it extends NetworkResponseCommon. Attributes are + private String message; + + private MsoExceptionCategory category; + + private Boolean rolledBack; + + # d. NetworkResponseCommon: Attribute is + private String messageId; + + # e. CreateNetworkRequest: extends NetworkRequestCommon + private String cloudSiteId; + + private String tenantId; + + private String networkId; + + private String networkName; + + private String networkType; + + private String networkTypeVersion; + + private String modelCustomizationUuid; + + private String networkTechnology = "NEUTRON"; + + private List<Subnet> subnets; + + private ProviderVlanNetwork providerVlanNetwork; + + private ContrailNetwork contrailNetwork; + + private Boolean failIfExists = false; + + private Boolean backout = true; + + private Map<String, String> networkParams = new HashMap<>(); + + private MsoRequest msoRequest = new MsoRequest(); + + private boolean contrailRequest; + + Usage : + #1) bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIQueryTasks.java: Here in getNetworkVpnBinding, where VPN Binding data from AAI result is extracted. There in routeTargets is got, and is updated in the execution variable(“createNetworkRequest”). + + #2)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java – Here in createnetwork returns a CreateNetworkRequest which is updated in execution variable(“networkAdapterRequest”) + + #3)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetwork.java - + Here in createnetwork returns a CreateNetworkRequest which is updated in execution variable(“createNetworkRequest”) + + #4) bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClientImpl.java -Here createNetwork request is processed as a restclient post process with CreateNetworkRequest as input. + + # f. CreateNetworkResponse : extends NetworkResponseCommon + private String networkId; + + private String neutronNetworkId; + + private String networkStackId; + + private String networkFqdn; + + private Boolean networkCreated; + + private Map<String, String> subnetMap; + + private NetworkRollback rollback = new NetworkRollback(); + + Usage: + #1)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java :here after the network is created, the l3 network is updated with those parameters which come from execution variable("createNetworkResponse") + + #2)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterCreateTasks.java – depending on variable networkCreated of response, networkAdapterCreateRollback is set to true. + + #3)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClientImpl.java -Here createNetwork request is processed as a restclient post process with CreateNetworkRequest as input and CreateNetworkResponse as output + + # g.DeleteNetworkError : extends NetworkExceptionResponse + + # h. DeleteNetworkRequest:extends NetworkRequestCommon + private String cloudSiteId; + + private String tenantId; + + private String networkId; + + private String networkStackId; + + private String networkType; + + private String modelCustomizationUuid; + + private MsoRequest msoRequest = new MsoRequest(); + + Usage: + #1)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/network/tasks/NetworkAdapterDeleteTasks.java – deleteNetworkRequestMapper returns a DeleteNetworkRequest, which is set to the execution variable(“networkAdapterRequest”) + + #2)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/NetworkAdapterClientImpl.java - Here deleteNetwork request is processed as a restclient delete process with DeleteNetworkRequest as input. + + #3)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/network/mapper/NetworkAdapterObjectMapper.java – Here the deleteNetworkRequestMapper forms DeleteNetworkRequest object + + Similarly others are also implemented and used + +.. image:: ../images/nwrest.png + +Sdnc request +------------ + +#3. Sdnc request -These are required by the mso-sdnc-adapter + + # a. RequestInformation – This is an important parameter of SDNCServiceRequest. Thud is used during the conversion of SDNCServiceRequest to XMLstring. + + # b. ServiceInformation – This stores the important information like serviceId, servicetype and SubscriberName. Its parameter of SDNCServiceRequest. + + # c. SDNCErrorCommon – it extends SDNCResponseCommon . + + Usage : adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnector.java – catching exception if any happens during request creation and a new SDNCErrorCommon is created. + + # d. SDNCRequestCommon – SDNCServiceRequest extends SDNCRequestCommon. It has some attributes like bpNotificationUrl(Endpoint on which BPMN can receive notifications from the SDNC adapter), bpTimeout ans sdncrequestId. + + # e. SDNCServiceRequest + Usage: adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestTask.java – Here the runRequest is happening, where we are posting this request using a restclient call with SDNCServiceRequest as input. + + # f. SDNCServiceResponse and SDNCServiceError + Usage:adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestTask.java – Here if the above runRequest returns a 2xx response code then a corresponding SDNCServiceResponse is created and returned or else SDNCServiceError is created and returned + +Tenant request +--------------- + +#4. These provide classes to be used by the so-adapters.tenant. + +The operator of a cloud can present unchangeable networks to the users, or give users the option to create, delete, connect and generally manipulate networks. The latter type of networks is called “tenant networks”. + +Used in adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tenant/TenantAdapterRest.java + +The implementation and usage is similiar to the above classes + +.. image:: ../images/tenantrest.png + +VDU +--- + +#5. Vdu – these are used for the deployment and management of (cloud-agnostic) VDU . The abstract classes for instantiation of vdu, query vdu, delete vdu, update vdu are defined in here. + +These are implemented in adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/utils/MsoCloudifyUtils.java and adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java + +Vnfrest +------- + +#6. Vnfrest – These are used to manage vnfs and vgs. +These are used in the project similiar to networkrest +Foreg : Usage of DeleteVfModuleRequest: + +1)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnf/tasks/VnfAdapterDeleteTasks.java – Here in deleteVfModuleRequestMapper creates a new DeleteVfModuleRequest, and is set to the execution variable(“VNFREST_REQUEST” ) and “deleteVfModuleRequest” execution variable is set true + +2)bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/vnf/VnfAdapterClientImpl.java - Here a delete rest request is send + +.. image:: ../images/vnfrest.png + + +OPENSTACK +--------- +Openstack is classified into beans, exceptions, and mappers + +MAPPERS +------- + # 1) JAXBContext: It is used to convert a object to xml(marshalling) and to convert xml to object (unmarshalling) . These marshalling and unmarshalling are overriden in the map adapters in mappers. + + # 2)NetworkInfoMapper – used to Capture the data from a Neutron Network object and cast it into a networkInfo( present in beans of openstack). Here in vlan information is located depending on network.getProviderNetworkType() , and if not then the segments within the network is iterated and is checked for the same. + Usage: It is used in adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoNeutronUtils.java , where on createNetwork, queryNetwork and updateNetwork , the network is mapped by NetworkInfoMapper into networkInfo and returned. + + # 3) StackInfoMapper – used to Capture the data from a Stack object and cast it into a stackInfo( present in beans of openstack). + Usage: It is used in adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils , where all createStack, queryStack, updateStack, deleteStack is done, a new instance of stackInfo is returned + +Exceptions +---------- +These are set of msoexceptions provided, and would be used depending on what exception needs to be handled + +.. image:: ../images/msoexception.png diff --git a/docs/images/module_structure.png b/docs/images/module_structure.png Binary files differnew file mode 100644 index 0000000000..c25441bd8e --- /dev/null +++ b/docs/images/module_structure.png diff --git a/docs/images/msoexception.png b/docs/images/msoexception.png Binary files differnew file mode 100644 index 0000000000..b9d2dfd5da --- /dev/null +++ b/docs/images/msoexception.png diff --git a/docs/images/nwrest.png b/docs/images/nwrest.png Binary files differnew file mode 100644 index 0000000000..58b66d59e0 --- /dev/null +++ b/docs/images/nwrest.png diff --git a/docs/images/tenantrest.png b/docs/images/tenantrest.png Binary files differnew file mode 100644 index 0000000000..ec1c77e61b --- /dev/null +++ b/docs/images/tenantrest.png diff --git a/docs/images/vnfrest.png b/docs/images/vnfrest.png Binary files differnew file mode 100644 index 0000000000..f61720708d --- /dev/null +++ b/docs/images/vnfrest.png diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java index 665fa547cc..c7692cb2cc 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/E2EServiceInstances.java @@ -396,7 +396,8 @@ public class E2EServiceInstances { ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, - "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON); + "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON, + null); logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -408,7 +409,7 @@ public class E2EServiceInstances { ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Recipe does not exist in catalog DB", action, - ModelType.service.name(), requestJSON); + ModelType.service.name(), requestJSON, null); logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -484,7 +485,8 @@ public class E2EServiceInstances { ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, - "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON); + "Exception while communciate with " + "Catalog DB", action, ModelType.service.name(), requestJSON, + null); logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -496,7 +498,7 @@ public class E2EServiceInstances { ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "Recipe does not exist in catalog DB", action, - ModelType.service.name(), requestJSON); + ModelType.service.name(), requestJSON, null); logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -715,7 +717,8 @@ public class E2EServiceInstances { ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, - "No communication to catalog DB " + e.getMessage(), action, ModelType.service.name(), requestJSON); + "No communication to catalog DB " + e.getMessage(), action, ModelType.service.name(), requestJSON, + null); logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -727,7 +730,7 @@ public class E2EServiceInstances { MsoException.ServiceException, "Recipe does not exist in catalog DB", ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, "No recipe found in DB", action, - ModelType.service.name(), requestJSON); + ModelType.service.name(), requestJSON, null); logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); return response; } @@ -948,7 +951,7 @@ public class E2EServiceInstances { ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build(); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, validateException.getMessage(), action, - ModelType.service.name(), requestJSON); + ModelType.service.name(), requestJSON, null); throw validateException; } diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java index 168f82bdf3..d69c395f96 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/JerseyConfiguration.java @@ -64,6 +64,7 @@ public class JerseyConfiguration extends ResourceConfig { register(GlobalHealthcheckHandler.class); register(NodeHealthcheckHandler.class); register(ServiceInstances.class); + register(Onap3gppServiceInstances.class); register(TasksHandler.class); register(CloudOrchestration.class); register(CloudResourcesOrchestration.class); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java index 4ac8b73698..bf76cd3174 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/MsoRequest.java @@ -451,7 +451,7 @@ public class MsoRequest { } public void createErrorRequestRecord(Status status, String requestId, String errorMessage, Actions action, - String requestScope, String requestJSON) { + String requestScope, String requestJSON, String serviceInstanceId) { try { InfraActiveRequests request = new InfraActiveRequests(requestId); Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis()); @@ -463,6 +463,9 @@ public class MsoRequest { request.setRequestAction(action.toString()); request.setRequestScope(requestScope); request.setRequestBody(requestJSON); + if (serviceInstanceId != null) { + request.setServiceInstanceId(serviceInstanceId); + } Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); request.setEndTime(endTimeStamp); request.setRequestUrl(MDC.get(LogConstants.HTTP_URL)); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java new file mode 100644 index 0000000000..e7b96b16a9 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstances.java @@ -0,0 +1,732 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra; + +import java.sql.Timestamp; +import java.util.HashMap; +import java.util.UUID; +import java.util.function.Function; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.container.ContainerRequestContext; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.apache.http.HttpStatus; +import org.onap.logging.filter.base.ErrorCode; +import org.onap.so.apihandler.camundabeans.CamundaResponse; +import org.onap.so.apihandler.common.CamundaClient; +import org.onap.so.apihandler.common.ErrorNumbers; +import org.onap.so.apihandler.common.RequestClientParameter; +import org.onap.so.apihandler.common.ResponseBuilder; +import org.onap.so.apihandler.common.ResponseHandler; +import org.onap.so.apihandlerinfra.exceptions.ApiException; +import org.onap.so.apihandlerinfra.exceptions.BPMNFailureException; +import org.onap.so.apihandlerinfra.exceptions.RequestDbFailureException; +import org.onap.so.apihandlerinfra.exceptions.ValidateException; +import org.onap.so.apihandlerinfra.logging.ErrorLoggerInfo; +import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.ActivateOrDeactivate3gppService; +import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Allocate3gppService; +import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.DeAllocate3gppService; +import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.Modify3gppService; +import org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans.QuerySubnetCapability; +import org.onap.so.constants.Status; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.ServiceRecipe; +import org.onap.so.db.catalog.client.CatalogDbClient; +import org.onap.so.logger.LogConstants; +import org.onap.so.logger.LoggingAnchor; +import org.onap.so.logger.MessageEnum; +import org.onap.so.serviceinstancebeans.ModelType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.MDC; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.info.Info; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.client.RequestsDbClient; + +@Component +@Path("/onap/so/infra/onap3gppServiceInstances") +@OpenAPIDefinition(info = @Info(title = "/onap/so/infra/onap3gppServiceInstances", + description = "API Requests for 3GPP Service Instances")) +public class Onap3gppServiceInstances { + + private static final Logger logger = LoggerFactory.getLogger(Onap3gppServiceInstances.class); + + private static final String MSO_PROP_APIHANDLER_INFRA = "MSO_PROP_APIHANDLER_INFRA"; + + private static final String END_OF_THE_TRANSACTION = "End of the transaction, the final response is: "; + + private static final String SAVE_TO_DB = "save instance to db"; + + private static String uriPrefix = "/onap3gppServiceInstances/"; + + @Autowired + private MsoRequest msoRequest; + + @Autowired + private CatalogDbClient catalogDbClient; + + @Autowired + private RequestsDbClient requestsDbClient; + + @Autowired + private RequestHandlerUtils requestHandlerUtils; + + @Autowired + private ResponseBuilder builder; + + @Autowired + private CamundaClient camundaClient; + + @Autowired + private ResponseHandler responseHandler; + + /** + * POST Requests for 3GPP Service create Instance on a version provided + * + * @throws ApiException + */ + + @POST + @Path("/{version:[vV][1]}/allocate") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Create a 3GPP Service Instance on a version provided", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + public Response createServiceInstance(Allocate3gppService request, @PathParam("version") String version, + @Context ContainerRequestContext requestContext) throws ApiException { + String requestId = requestHandlerUtils.getRequestId(requestContext); + return processServiceInstanceRequest(request, Action.createInstance, version, requestId, null, + requestHandlerUtils.getRequestUri(requestContext, uriPrefix)); + } + + /** + * PUT Requests for 3GPP Service update Instance on a version provided + * + * @throws ApiException + */ + + @PUT + @Path("/{version:[vV][1]}/modify") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Modify a 3GPP Service Instance on a version provided", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + public Response updateServiceInstance(Modify3gppService request, @PathParam("version") String version, + @Context ContainerRequestContext requestContext) throws ApiException { + String requestId = requestHandlerUtils.getRequestId(requestContext); + HashMap<String, String> instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", request.getServiceInstanceID()); + return updateServiceInstances(request, Action.updateInstance, version, requestId, instanceIdMap, + requestHandlerUtils.getRequestUri(requestContext, uriPrefix)); + } + + /** + * DELETE Requests for 3GPP Service delete Instance on a specified version + * + * @throws ApiException + */ + + @DELETE + @Path("/{version:[vV][1]}/deAllocate") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Terminate/Deallocate a 3GPP Service Instance on a version provided", + responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + public Response deleteServiceInstance(DeAllocate3gppService request, @PathParam("version") String version, + @Context ContainerRequestContext requestContext) throws ApiException { + String requestId = requestHandlerUtils.getRequestId(requestContext); + HashMap<String, String> instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", request.getServiceInstanceID()); + return deleteServiceInstances(request, Action.deleteInstance, version, requestId, instanceIdMap, + requestHandlerUtils.getRequestUri(requestContext, uriPrefix)); + } + + /** + * POST Requests for 3GPP Service Activate on a specified version + * + * @throws ApiException + */ + + @POST + @Path("/{version:[vV][1]}/activate") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Activate a 3GPP Service Instance on a version provided", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + public Response activateServiceInstance(ActivateOrDeactivate3gppService request, + @PathParam("version") String version, @Context ContainerRequestContext requestContext) throws ApiException { + String requestId = requestHandlerUtils.getRequestId(requestContext); + HashMap<String, String> instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", request.getServiceInstanceID()); + return activateOrDeactivateServiceInstances(request, Action.activateInstance, version, requestId, instanceIdMap, + requestHandlerUtils.getRequestUri(requestContext, uriPrefix)); + } + + /** + * POST Requests for 3GPP Service DeActivate on a specified version + * + * @throws ApiException + */ + + @POST + @Path("/{version:[vV][1]}/deActivate") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Deactivate a 3GPP Service Instance on a version provided", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + public Response deActivateServiceInstance(ActivateOrDeactivate3gppService request, + @PathParam("version") String version, @Context ContainerRequestContext requestContext) throws ApiException { + String requestId = requestHandlerUtils.getRequestId(requestContext); + HashMap<String, String> instanceIdMap = new HashMap<>(); + instanceIdMap.put("serviceInstanceId", request.getServiceInstanceID()); + return activateOrDeactivateServiceInstances(request, Action.deactivateInstance, version, requestId, + instanceIdMap, requestHandlerUtils.getRequestUri(requestContext, uriPrefix)); + } + + /** + * + * GET requests for slice subnet capabilities on a specified version + * + * @param version + * @return + * @throws ApiException + */ + @GET + @Path("/{version:[vV][1]}/subnetCapabilityQuery") + @Operation(description = "Provides subnet capability based on subnet types", responses = @ApiResponse( + content = @Content(array = @ArraySchema(schema = @Schema(implementation = Response.class))))) + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response getSliceSubnetCapabilities(QuerySubnetCapability request, @PathParam("version") String version) + throws ApiException { + logger.debug("Request received {}", request); + String subnetType = null; + return getSubnetCapabilities(subnetType, version); + } + + /** + * Process allocate service request and send request to corresponding workflow + * + * @param request + * @param action + * @param version + * @return + * @throws ApiException + */ + private Response processServiceInstanceRequest(Allocate3gppService request, Action action, String version, + String requestId, HashMap<String, String> instanceIdMap, String requestUri) throws ApiException { + String defaultServiceModelName = "COMMON_SS_DEFAULT"; + String requestScope = ModelType.service.name(); + String apiVersion = version.substring(1); + String serviceRequestJson = toString.apply(request); + if (serviceRequestJson != null) { + InfraActiveRequests currentActiveReq = createRequestObject(request, action, requestId, Status.IN_PROGRESS, + requestScope, serviceRequestJson); + String instanceName = request.getName(); + requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, + instanceName); + try { + requestsDbClient.save(currentActiveReq); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e) + .errorInfo(errorLoggerInfo).build(); + } + + RecipeLookupResult recipeLookupResult; + try { + recipeLookupResult = + getServiceInstanceOrchestrationURI(request.getModelUuid(), action, defaultServiceModelName); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + if (recipeLookupResult == null) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), + MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB"); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "Recipe does not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + String serviceInstanceType = request.getSubscriptionServiceType(); + RequestClientParameter parameter; + try { + parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false) + .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()) + .setServiceInstanceId(null).setServiceType(serviceInstanceType) + .setRequestDetails(serviceRequestJson).setApiVersion(version).setALaCarte(false) + .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).setApiVersion(apiVersion).build(); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo) + .build(); + } + return postBPELRequest(currentActiveReq, parameter, recipeLookupResult.getOrchestrationURI(), requestScope); + } else { + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, "JsonProcessingException occurred - serviceRequestJson is null", + ErrorNumbers.SVC_BAD_PARAMETER, null, version); + return response; + } + } + + /** + * process modify service request and call corresponding workflow + * + * @param request + * @param action + * @param version + * @return + * @throws ApiException + */ + private Response updateServiceInstances(Modify3gppService request, Action action, String version, String requestId, + HashMap<String, String> instanceIdMap, String requestUri) throws ApiException { + String defaultServiceModelName = "COMMON_SS_DEFAULT"; + String requestScope = ModelType.service.name(); + String apiVersion = version.substring(1); + String serviceRequestJson = toString.apply(request); + if (serviceRequestJson != null) { + InfraActiveRequests currentActiveReq = createRequestObject(request, action, requestId, Status.IN_PROGRESS, + requestScope, serviceRequestJson); + String instanceName = request.getName(); + requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, + instanceName); + try { + requestsDbClient.save(currentActiveReq); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e) + .errorInfo(errorLoggerInfo).build(); + } + + RecipeLookupResult recipeLookupResult; + try { + recipeLookupResult = getServiceInstanceOrchestrationURI(null, action, defaultServiceModelName); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + if (recipeLookupResult == null) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), + MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB"); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "Recipe does not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + String serviceInstanceType = request.getSubscriptionServiceType(); + String serviceInstanceId = request.getServiceInstanceID(); + RequestClientParameter parameter; + try { + parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false) + .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()) + .setServiceInstanceId(serviceInstanceId).setServiceType(serviceInstanceType) + .setRequestDetails(serviceRequestJson).setApiVersion(version).setALaCarte(false) + .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).setApiVersion(apiVersion).build(); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo) + .build(); + } + return postBPELRequest(currentActiveReq, parameter, recipeLookupResult.getOrchestrationURI(), requestScope); + + } else { + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, "JsonProcessingException occurred - serviceRequestJson is null", + ErrorNumbers.SVC_BAD_PARAMETER, null, version); + return response; + } + } + + /** + * process delete service instance request and call corresponding workflow + * + * @param request + * @param action + * @param version + * @return + * @throws ApiException + */ + private Response deleteServiceInstances(DeAllocate3gppService request, Action action, String version, + String requestId, HashMap<String, String> instanceIdMap, String requestUri) throws ApiException { + String defaultServiceModelName = "COMMON_SS_DEFAULT"; + String requestScope = ModelType.service.name(); + String apiVersion = version.substring(1); + String serviceRequestJson = toString.apply(request); + if (serviceRequestJson != null) { + InfraActiveRequests currentActiveReq = createRequestObject(request, action, requestId, Status.IN_PROGRESS, + requestScope, serviceRequestJson); + requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, null); + try { + requestsDbClient.save(currentActiveReq); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e) + .errorInfo(errorLoggerInfo).build(); + } + RecipeLookupResult recipeLookupResult; + try { + recipeLookupResult = getServiceInstanceOrchestrationURI(null, action, defaultServiceModelName); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + if (recipeLookupResult == null) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), + MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB"); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "Recipe does not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + String serviceInstanceType = request.getSubscriptionServiceType(); + String serviceInstanceId = request.getServiceInstanceID(); + RequestClientParameter parameter; + try { + parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false) + .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()) + .setServiceInstanceId(serviceInstanceId).setServiceType(serviceInstanceType) + .setRequestDetails(serviceRequestJson).setApiVersion(version).setALaCarte(false) + .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).setApiVersion(apiVersion).build(); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo) + .build(); + } + return postBPELRequest(currentActiveReq, parameter, recipeLookupResult.getOrchestrationURI(), requestScope); + } else { + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, "JsonProcessingException occurred - serviceRequestJson is null", + ErrorNumbers.SVC_BAD_PARAMETER, null, version); + return response; + } + } + + /** + * process activate/deactivate service request and call corresponding workflow + * + * @param request the request object for activate/deactivate service + * @param action the action for the service + * @param version + * @return + * @throws ApiException + */ + private Response activateOrDeactivateServiceInstances(ActivateOrDeactivate3gppService request, Action action, + String version, String requestId, HashMap<String, String> instanceIdMap, String requestUri) + throws ApiException { + String defaultServiceModelName = "COMMON_SS_DEFAULT"; + String requestScope = ModelType.service.name(); + String apiVersion = version.substring(1); + String serviceRequestJson = toString.apply(request); + if (serviceRequestJson != null) { + InfraActiveRequests currentActiveReq = createRequestObject(request, action, requestId, Status.IN_PROGRESS, + requestScope, serviceRequestJson); + if (action == Action.activateInstance) { + requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, + request.getServiceInstanceID()); + } else { + requestHandlerUtils.checkForDuplicateRequests(action, instanceIdMap, requestScope, currentActiveReq, + null); + } + try { + requestsDbClient.save(currentActiveReq); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_DB_ACCESS_EXC, ErrorCode.DataError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new RequestDbFailureException.Builder(SAVE_TO_DB, e.toString(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).cause(e) + .errorInfo(errorLoggerInfo).build(); + } + RecipeLookupResult recipeLookupResult; + try { + recipeLookupResult = getServiceInstanceOrchestrationURI(null, action, defaultServiceModelName); + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ACCESS_EXC.toString(), MSO_PROP_APIHANDLER_INFRA, + ErrorCode.AvailabilityError.getValue(), "Exception while communciate with Catalog DB", e); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "No communication to catalog DB " + e.getMessage(), + ErrorNumbers.SVC_NO_SERVER_RESOURCES, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + if (recipeLookupResult == null) { + logger.error(LoggingAnchor.FOUR, MessageEnum.APIH_DB_ATTRIBUTE_NOT_FOUND.toString(), + MSO_PROP_APIHANDLER_INFRA, ErrorCode.DataError.getValue(), "No recipe found in DB"); + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_NOT_FOUND, + MsoException.ServiceException, "Recipe does not exist in catalog DB", + ErrorNumbers.SVC_GENERAL_SERVICE_ERROR, null, version); + logger.debug(END_OF_THE_TRANSACTION + response.getEntity()); + return response; + } + + String serviceInstanceType = request.getSubscriptionServiceType(); + String serviceInstanceId = request.getServiceInstanceID(); + RequestClientParameter parameter; + try { + parameter = new RequestClientParameter.Builder().setRequestId(requestId).setBaseVfModule(false) + .setRecipeTimeout(recipeLookupResult.getRecipeTimeout()).setRequestAction(action.name()) + .setServiceInstanceId(serviceInstanceId).setServiceType(serviceInstanceType) + .setRequestDetails(serviceRequestJson).setApiVersion(version).setALaCarte(false) + .setRecipeParamXsd(recipeLookupResult.getRecipeParamXsd()).setApiVersion(apiVersion).build(); + } catch (Exception e) { + logger.error("Exception occurred", e); + ErrorLoggerInfo errorLoggerInfo = + new ErrorLoggerInfo.Builder(MessageEnum.APIH_BPEL_RESPONSE_ERROR, ErrorCode.SchemaError) + .errorSource(Constants.MSO_PROP_APIHANDLER_INFRA).build(); + throw new ValidateException.Builder("Unable to generate RequestClientParamter object" + e.getMessage(), + HttpStatus.SC_INTERNAL_SERVER_ERROR, ErrorNumbers.SVC_BAD_PARAMETER).errorInfo(errorLoggerInfo) + .build(); + } + return postBPELRequest(currentActiveReq, parameter, recipeLookupResult.getOrchestrationURI(), requestScope); + } else { + Response response = msoRequest.buildServiceErrorResponse(HttpStatus.SC_INTERNAL_SERVER_ERROR, + MsoException.ServiceException, "JsonProcessingException occurred - serviceRequestJson is null", + ErrorNumbers.SVC_BAD_PARAMETER, null, version); + return response; + } + } + + // To be implemented for fetching Subnet capabilities + private Response getSubnetCapabilities(String subnetType, String version) throws ApiException { + return null; + } + + /** + * Getting recipes from catalogDb + * + * @param serviceModelUUID the service model version uuid + * @param action the action for the service + * @param defaultServiceModelName default service name + * @return the service recipe result + */ + private RecipeLookupResult getServiceInstanceOrchestrationURI(String serviceModelUUID, Action action, + String defaultServiceModelName) { + + RecipeLookupResult recipeLookupResult = getServiceURI(serviceModelUUID, action, defaultServiceModelName); + + if (recipeLookupResult != null) { + logger.debug("Orchestration URI is: " + recipeLookupResult.getOrchestrationURI() + ", recipe Timeout is: " + + Integer.toString(recipeLookupResult.getRecipeTimeout())); + } else { + logger.debug("No matching recipe record found"); + } + return recipeLookupResult; + } + + /** + * Getting recipes from catalogDb If Service recipe is not set, use default recipe, if set , use special recipe. + * + * @param serviceModelUUID the service version uuid + * @param action the action of the service. + * @param defaultServiceModelName default service name + * @return the service recipe result. + */ + private RecipeLookupResult getServiceURI(String serviceModelUUID, Action action, String defaultServiceModelName) { + + Service defaultServiceRecord = + catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName); + // set recipe as default generic recipe + ServiceRecipe recipe = + catalogDbClient.getFirstByServiceModelUUIDAndAction(defaultServiceRecord.getModelUUID(), action.name()); + // check the service special recipe + if (null != serviceModelUUID && !serviceModelUUID.isEmpty()) { + ServiceRecipe serviceSpecialRecipe = + catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceModelUUID, action.name()); + if (null != serviceSpecialRecipe) { + // set service special recipe. + recipe = serviceSpecialRecipe; + } + } + + if (recipe == null) { + return null; + } + return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout(), recipe.getParamXsd()); + + } + + Function<Object, String> toString = serviceRequest -> { + ObjectMapper mapper = new ObjectMapper(); + String requestAsString = null; + try { + requestAsString = mapper.writeValueAsString(serviceRequest); + } catch (JsonProcessingException e) { + logger.debug("Exception while converting service request object to String {}", e); + } + return requestAsString; + }; + + public InfraActiveRequests createRequestObject(Object request, Action action, String requestId, Status status, + String requestScope, String requestJson) { + InfraActiveRequests aq = new InfraActiveRequests(); + try { + String networkType = null; + String serviceInstanceName = null; + String serviceInstanceId = null; + if (action.name().equals("createInstance")) { + networkType = ((Allocate3gppService) request).getNetworkType(); + serviceInstanceName = ((Allocate3gppService) request).getName(); + aq.setServiceInstanceName(serviceInstanceName); + } else if (action.name().equals("updateInstance")) { + networkType = ((Modify3gppService) request).getNetworkType(); + serviceInstanceName = ((Modify3gppService) request).getName(); + serviceInstanceId = ((Modify3gppService) request).getServiceInstanceID(); + aq.setServiceInstanceName(serviceInstanceName); + aq.setServiceInstanceId(serviceInstanceId); + } else if (action.name().equals("deleteInstance")) { + networkType = ((DeAllocate3gppService) request).getNetworkType(); + serviceInstanceId = ((DeAllocate3gppService) request).getServiceInstanceID(); + aq.setServiceInstanceId(serviceInstanceId); + } else if (action.name().equals("activateInstance")) { + networkType = ((ActivateOrDeactivate3gppService) request).getNetworkType(); + serviceInstanceId = ((ActivateOrDeactivate3gppService) request).getServiceInstanceID(); + aq.setServiceInstanceName(serviceInstanceId); // setting serviceInstanceId as serviceInstanceName + // -->serviceInstanceName shouldn't be null for action - + // activateInstance duplicateRequests check + aq.setServiceInstanceId(serviceInstanceId); + } else if (action.name().equals("deactivateInstance")) { + networkType = ((ActivateOrDeactivate3gppService) request).getNetworkType(); + serviceInstanceId = ((ActivateOrDeactivate3gppService) request).getServiceInstanceID(); + aq.setServiceInstanceId(serviceInstanceId); + } + + aq.setRequestId(requestId); + aq.setRequestAction(action.toString()); + aq.setRequestUrl(MDC.get(LogConstants.HTTP_URL)); + Timestamp startTimeStamp = new Timestamp(System.currentTimeMillis()); + aq.setStartTime(startTimeStamp); + aq.setRequestScope(requestScope); + aq.setRequestBody(requestJson); + aq.setRequestStatus(status.toString()); + aq.setLastModifiedBy(Constants.MODIFIED_BY_APIHANDLER); + aq.setNetworkType(networkType); + } catch (Exception e) { + logger.error("Exception when creation record request", e); + + if (!status.equals(Status.FAILED)) { + throw e; + } + } + return aq; + } + + private Response postBPELRequest(InfraActiveRequests currentActiveReq, RequestClientParameter parameter, + String orchestrationURI, String requestScope) throws ApiException { + ResponseEntity<String> response = + requestHandlerUtils.postRequest(currentActiveReq, parameter, orchestrationURI); + logger.debug("BPEL response : " + response); + int bpelStatus = responseHandler.setStatus(response.getStatusCodeValue()); + String jsonResponse; + try { + responseHandler.acceptedResponse(response); + CamundaResponse camundaResponse = responseHandler.getCamundaResponse(response); + String responseBody = camundaResponse.getResponse(); + if ("Success".equalsIgnoreCase(camundaResponse.getMessage())) { + jsonResponse = responseBody; + } else { + BPMNFailureException bpmnException = + new BPMNFailureException.Builder(String.valueOf(bpelStatus) + responseBody, bpelStatus, + ErrorNumbers.SVC_DETAILED_SERVICE_ERROR).build(); + requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, bpmnException.getMessage()); + throw bpmnException; + } + } catch (ApiException e) { + requestHandlerUtils.updateStatus(currentActiveReq, Status.FAILED, e.getMessage()); + throw e; + } + return builder.buildResponse(HttpStatus.SC_ACCEPTED, parameter.getRequestId(), jsonResponse, + parameter.getApiVersion()); + } +} + + diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java index a68309f199..60e9c3b30a 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/RequestHandlerUtils.java @@ -326,7 +326,7 @@ public class RequestHandlerUtils extends AbstractRestHandler { String requestScope = requestScopeFromUri(requestUri); msoRequest.createErrorRequestRecord(Status.FAILED, requestId, validateException.getMessage(), action, - requestScope, requestJSON); + requestScope, requestJSON, null); throw validateException; } @@ -518,20 +518,16 @@ public class RequestHandlerUtils extends AbstractRestHandler { } protected String setServiceInstanceId(String requestScope, ServiceInstancesRequest sir) { + String serviceInstanceId = null; if (sir.getServiceInstanceId() != null) { - return sir.getServiceInstanceId(); - } else if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) { - RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList(); - if (relatedInstances != null) { - for (RelatedInstanceList relatedInstanceList : relatedInstances) { - RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); - if (relatedInstance.getModelInfo().getModelType() == ModelType.service) { - return relatedInstance.getInstanceId(); - } - } + serviceInstanceId = sir.getServiceInstanceId(); + } else { + Optional<String> serviceInstanceIdForInstance = getServiceInstanceIdForInstanceGroup(requestScope, sir); + if (serviceInstanceIdForInstance.isPresent()) { + serviceInstanceId = serviceInstanceIdForInstance.get(); } } - return null; + return serviceInstanceId; } private String requestScopeFromUri(String requestUri) { @@ -916,6 +912,30 @@ public class RequestHandlerUtils extends AbstractRestHandler { return null; } + protected Optional<String> getServiceInstanceIdForValidationError(ServiceInstancesRequest sir, + HashMap<String, String> instanceIdMap, String requestScope) { + if (instanceIdMap != null && !instanceIdMap.isEmpty() && instanceIdMap.get("serviceInstanceId") != null) { + return Optional.of(instanceIdMap.get("serviceInstanceId")); + } else { + return getServiceInstanceIdForInstanceGroup(requestScope, sir); + } + } + + protected Optional<String> getServiceInstanceIdForInstanceGroup(String requestScope, ServiceInstancesRequest sir) { + if (requestScope.equalsIgnoreCase(ModelType.instanceGroup.toString())) { + RelatedInstanceList[] relatedInstances = sir.getRequestDetails().getRelatedInstanceList(); + if (relatedInstances != null) { + for (RelatedInstanceList relatedInstanceList : relatedInstances) { + RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance(); + if (relatedInstance.getModelInfo().getModelType() == ModelType.service) { + return Optional.ofNullable(relatedInstance.getInstanceId()); + } + } + } + } + return Optional.empty(); + } + private RecipeLookupResult getDefaultVnfUri(ServiceInstancesRequest sir, Actions action) { String defaultSource = getDefaultModel(sir); VnfRecipe vnfRecipe = catalogDbClient.getFirstVnfRecipeByNfRoleAndAction(defaultSource, action.toString()); diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java index 418ba05abf..2c8e92633c 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/ServiceInstances.java @@ -823,9 +823,17 @@ public class ServiceInstances extends AbstractRestHandler { sir = requestHandlerUtils.convertJsonToServiceInstanceRequest(requestJSON, action, requestId, requestUri); action = handleReplaceInstance(action, sir); - requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action); String requestScope = requestHandlerUtils.deriveRequestScope(action, sir, requestUri); + try { + requestValidatorListenerRunner.runValidations(requestUri, instanceIdMap, sir, queryParams, action); + } catch (ApiException e) { + msoRequest.createErrorRequestRecord(Status.FAILED, requestId, e.getMessage(), action, requestScope, + requestJSON, requestHandlerUtils + .getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).orElse(null)); + throw e; + } + InfraActiveRequests currentActiveReq = msoRequest.createRequestObject(sir, action, requestId, Status.IN_PROGRESS, requestJSON, requestScope); if (sir.getRequestDetails().getRequestParameters() != null) { diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/ActivateOrDeactivate3gppService.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/ActivateOrDeactivate3gppService.java new file mode 100644 index 0000000000..3f094a8cc9 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/ActivateOrDeactivate3gppService.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model class for 3GPP service instance Activate request + */ + +public class ActivateOrDeactivate3gppService { + + @JsonProperty("serviceInstanceID") + private String serviceInstanceID; + + @JsonProperty("globalSubscriberId") + private String globalSubscriberId; + + @JsonProperty("subscriptionServiceType") + private String subscriptionServiceType; + + @JsonProperty("networkType") + private String networkType; + + @JsonProperty("additionalProperties") + private Map<String, Object> additionalProperties = new HashMap<>(); + + public String getServiceInstanceID() { + return serviceInstanceID; + } + + public void setServiceInstanceID(String serviceInstanceID) { + this.serviceInstanceID = serviceInstanceID; + } + + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + public String getNetworkType() { + return networkType; + } + + public void setNetworkType(String networkType) { + this.networkType = networkType; + } + + public Map<String, Object> getAdditionalProperties() { + return additionalProperties; + } + + public void setAdditionalProperties(Map<String, Object> additionalProperties) { + this.additionalProperties = additionalProperties; + } + + + @Override + public String toString() { + return "ActivateOrDeactivate3gppService [serviceInstanceID=" + serviceInstanceID + ", globalSubscriberId=" + + globalSubscriberId + ", subscriptionServiceType=" + subscriptionServiceType + ", networkType=" + + networkType + ", additionalProperties=" + additionalProperties + "]"; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/Allocate3gppService.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/Allocate3gppService.java new file mode 100644 index 0000000000..0444e66842 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/Allocate3gppService.java @@ -0,0 +1,117 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model class for 3GPP service instance create request + */ +public class Allocate3gppService { + + @JsonProperty("name") + private String name; + + @JsonProperty("modelInvariantUuid") + private String modelInvariantUuid; + + @JsonProperty("modelUuid") + private String modelUuid; + + @JsonProperty("globalSubscriberId") + private String globalSubscriberId; + + @JsonProperty("subscriptionServiceType") + private String subscriptionServiceType; + + @JsonProperty("networkType") + private String networkType; + + @JsonProperty("additionalProperties") + private Map<String, Object> additionalProperties = new HashMap<>(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getModelInvariantUuid() { + return modelInvariantUuid; + } + + public void setModelInvariantUuid(String modelInvariantUuid) { + this.modelInvariantUuid = modelInvariantUuid; + } + + public String getModelUuid() { + return modelUuid; + } + + public void setModelUuid(String modelUuid) { + this.modelUuid = modelUuid; + } + + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + public String getNetworkType() { + return networkType; + } + + public void setNetworkType(String networkType) { + this.networkType = networkType; + } + + public Map<String, Object> getAdditionalProperties() { + return additionalProperties; + } + + public void setAdditionalProperties(Map<String, Object> additionalProperties) { + this.additionalProperties = additionalProperties; + } + + @Override + public String toString() { + return "Allocate3gppService [name=" + name + ", modelInvariantUuid=" + modelInvariantUuid + ", modelUuid=" + + modelUuid + ", globalSubscriberId=" + globalSubscriberId + ", subscriptionServiceType=" + + subscriptionServiceType + ", networkType=" + networkType + ", additionalProperties=" + + additionalProperties + "]"; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/DeAllocate3gppService.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/DeAllocate3gppService.java new file mode 100644 index 0000000000..24ebb6b410 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/DeAllocate3gppService.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model class for 3GPP service instance terminate request + */ +public class DeAllocate3gppService { + + @JsonProperty("serviceInstanceID") + private String serviceInstanceID; + + @JsonProperty("globalSubscriberId") + private String globalSubscriberId; + + @JsonProperty("subscriptionServiceType") + private String subscriptionServiceType; + + @JsonProperty("networkType") + private String networkType; + + @JsonProperty("additionalProperties") + private Map<String, Object> additionalProperties = new HashMap<>(); + + public String getServiceInstanceID() { + return serviceInstanceID; + } + + public void setServiceInstanceID(String serviceInstanceID) { + this.serviceInstanceID = serviceInstanceID; + } + + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + public String getNetworkType() { + return networkType; + } + + public void setNetworkType(String networkType) { + this.networkType = networkType; + } + + public Map<String, Object> getAdditionalProperties() { + return additionalProperties; + } + + public void setAdditionalProperties(Map<String, Object> additionalProperties) { + this.additionalProperties = additionalProperties; + } + + @Override + public String toString() { + return "DeAllocate3gppService [serviceInstanceID=" + serviceInstanceID + ", globalSubscriberId=" + + globalSubscriberId + ", subscriptionServiceType=" + subscriptionServiceType + ", networkType=" + + networkType + ", additionalProperties=" + additionalProperties + "]"; + } + +} diff --git a/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/Modify3gppService.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/Modify3gppService.java new file mode 100644 index 0000000000..ffe76c06ef --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/Modify3gppService.java @@ -0,0 +1,105 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * Model class for 3GPP service instance Update request + */ +public class Modify3gppService { + + @JsonProperty("name") + private String name; + + @JsonProperty("serviceInstanceID") + private String serviceInstanceID; + + @JsonProperty("globalSubscriberId") + private String globalSubscriberId; + + @JsonProperty("subscriptionServiceType") + private String subscriptionServiceType; + + @JsonProperty("networkType") + private String networkType; + + @JsonProperty("additionalProperties") + private Map<String, Object> additionalProperties = new HashMap<>(); + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getServiceInstanceID() { + return serviceInstanceID; + } + + public void setServiceInstanceID(String serviceInstanceID) { + this.serviceInstanceID = serviceInstanceID; + } + + public String getGlobalSubscriberId() { + return globalSubscriberId; + } + + public void setGlobalSubscriberId(String globalSubscriberId) { + this.globalSubscriberId = globalSubscriberId; + } + + public String getSubscriptionServiceType() { + return subscriptionServiceType; + } + + public void setSubscriptionServiceType(String subscriptionServiceType) { + this.subscriptionServiceType = subscriptionServiceType; + } + + public String getNetworkType() { + return networkType; + } + + public void setNetworkType(String networkType) { + this.networkType = networkType; + } + + public Map<String, Object> getAdditionalProperties() { + return additionalProperties; + } + + public void setAdditionalProperties(Map<String, Object> additionalProperties) { + this.additionalProperties = additionalProperties; + } + + @Override + public String toString() { + return "Modify3gppService [name=" + name + ", serviceInstanceID=" + serviceInstanceID + ", globalSubscriberId=" + + globalSubscriberId + ", subscriptionServiceType=" + subscriptionServiceType + ", networkType=" + + networkType + ", additionalProperties=" + additionalProperties + "]"; + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifySimpleTokenProvider.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java index 0c1e42d0e8..2e479e1ecb 100644 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifySimpleTokenProvider.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/QuerySubnetCapability.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020 Wipro Limited. * ================================================================================ * 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. @@ -18,22 +18,30 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.cloudify.base.client; +package org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans; -public class CloudifySimpleTokenProvider implements CloudifyTokenProvider { - String token; +import java.util.List; - public CloudifySimpleTokenProvider(String token) { - this.token = token; +/** + * Model class for slice subnet capability query + */ +public class QuerySubnetCapability { + + private SubnetTypes subnetType; + + public SubnetTypes getSubnetType() { + return subnetType; } - @Override - public String getToken() { - return this.token; + public void setSubnetType(SubnetTypes subnetType) { + this.subnetType = subnetType; } @Override - public void expireToken() {} + public String toString() { + return "QuerySubnetCapability [subnetType=" + subnetType + "]"; + } } + diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/HttpMethod.java b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/SubnetTypes.java index 2c5097f1ad..5d6deb7158 100644 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/HttpMethod.java +++ b/mso-api-handlers/mso-api-handler-infra/src/main/java/org/onap/so/apihandlerinfra/onap3gppserviceinstancebeans/SubnetTypes.java @@ -2,14 +2,14 @@ * ============LICENSE_START======================================================= * ONAP - SO * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2020 Wipro Limited. * ================================================================================ * 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. @@ -18,8 +18,8 @@ * ============LICENSE_END========================================================= */ -package org.onap.so.cloudify.base.client; +package org.onap.so.apihandlerinfra.onap3gppserviceinstancebeans; -public enum HttpMethod { - HEAD, GET, POST, PUT, PATCH, DELETE, OPTIONS, TRACE +public enum SubnetTypes { + AN, AN_NF, CN, TN_FH, TN_MH, TN_BH } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java new file mode 100644 index 0000000000..503af1bdcb --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/Onap3gppServiceInstancesTest.java @@ -0,0 +1,181 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.apihandlerinfra; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo; +import static org.junit.Assert.assertEquals; +import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_PARTNER_NAME; +import static org.onap.logging.filter.base.Constants.HttpHeaders.ONAP_REQUEST_ID; +import static org.onap.logging.filter.base.Constants.HttpHeaders.TRANSACTION_ID; +import static org.onap.so.logger.HttpHeadersConstants.REQUESTOR_ID; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.apache.http.HttpStatus; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.logging.ref.slf4j.ONAPLogConstants; +import org.onap.so.db.catalog.beans.Service; +import org.onap.so.db.catalog.beans.ServiceRecipe; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.web.util.UriComponentsBuilder; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +public class Onap3gppServiceInstancesTest extends BaseTest { + + private String onap3gppServicesUri = "/onap/so/infra/onap3gppServiceInstances/"; + + private final ObjectMapper mapper = new ObjectMapper(); + + @Before + public void init() throws JsonProcessingException { + + Service defaultService = new Service(); + defaultService.setModelUUID("d88da85c-d9e8-4f73-b837-3a72a431622a"); + ServiceRecipe serviceRecipe = new ServiceRecipe(); + serviceRecipe.setServiceModelUUID(defaultService.getModelUUID()); + serviceRecipe.setRecipeTimeout(180); + serviceRecipe.setOrchestrationUri("/mso/async/services/commonNssmfTest"); + + wireMockServer.stubFor(get(urlPathEqualTo("/service/search/findFirstByModelNameOrderByModelVersionDesc")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); + + wireMockServer.stubFor(get(urlPathEqualTo("/serviceRecipe/search/findFirstByServiceModelUUIDAndAction")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(post(urlMatching(".*/infraActiveRequests/")).willReturn(aResponse() + .withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).withStatus(HttpStatus.SC_OK))); + Mockito.doReturn(null).when(requestsDbClient).getInfraActiveRequestbyRequestId(Mockito.any()); + } + + public String inputStream(String JsonInput) throws IOException { + JsonInput = "src/test/resources/Onap3gppServiceInstancesTest" + JsonInput; + return new String(Files.readAllBytes(Paths.get(JsonInput))); + } + + public ResponseEntity<String> sendRequest(String requestJson, String uriPath, HttpMethod reqMethod) { + HttpHeaders headers = new HttpHeaders(); + headers.set("Accept", MediaType.APPLICATION_JSON); + headers.set("Content-Type", MediaType.APPLICATION_JSON); + headers.set(ONAPLogConstants.Headers.PARTNER_NAME, "test_name"); + headers.set(TRANSACTION_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(ONAP_REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(ONAPLogConstants.MDCs.REQUEST_ID, "32807a28-1a14-4b88-b7b3-2950918aa76d"); + headers.set(ONAP_PARTNER_NAME, "VID"); + headers.set(REQUESTOR_ID, "xxxxxx"); + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(createURLWithPort(uriPath)); + HttpEntity<String> request = new HttpEntity<>(requestJson, headers); + + return restTemplate.exchange(builder.toUriString(), reqMethod, request, String.class); + } + + @Test + public void createServiceInstanceTest() throws IOException { + String uri = onap3gppServicesUri + "v1/allocate"; + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json") + .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED))); + + String expectedResponse = + "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}"; + ResponseEntity<String> response = sendRequest(inputStream("/allocateRequest.json"), uri, HttpMethod.POST); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + String actualResponse = response.getBody(); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void updateServiceInstanceTest() throws IOException { + String uri = onap3gppServicesUri + "v1/modify"; + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json") + .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED))); + + String expectedResponse = + "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}"; + ResponseEntity<String> response = sendRequest(inputStream("/modifyRequest.json"), uri, HttpMethod.PUT); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + String actualResponse = response.getBody(); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void deleteServiceInstanceTest() throws IOException { + String uri = onap3gppServicesUri + "v1/deAllocate"; + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json") + .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED))); + String expectedResponse = + "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}"; + ResponseEntity<String> response = sendRequest(inputStream("/deAllocate.json"), uri, HttpMethod.DELETE); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + String actualResponse = response.getBody(); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void activateServiceInstanceTest() throws IOException { + String uri = onap3gppServicesUri + "v1/activate"; + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json") + .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED))); + String expectedResponse = + "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}"; + ResponseEntity<String> response = sendRequest(inputStream("/activateRequest.json"), uri, HttpMethod.POST); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + String actualResponse = response.getBody(); + assertEquals(expectedResponse, actualResponse); + } + + @Test + public void deActivateServiceInstance() throws IOException { + String uri = onap3gppServicesUri + "v1/deActivate"; + wireMockServer.stubFor(post(urlPathEqualTo("/mso/async/services/commonNssmfTest")).willReturn( + aResponse().withHeader("Content-Type", "application/json").withBodyFile("Camunda/BPMN_response.json") + .withStatus(org.apache.http.HttpStatus.SC_ACCEPTED))); + String expectedResponse = + "{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}"; + ResponseEntity<String> response = sendRequest(inputStream("/deActivateRequest.json"), uri, HttpMethod.POST); + + assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatusCode().value()); + String actualResponse = response.getBody(); + assertEquals(expectedResponse, actualResponse); + } + +} + + diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java index 7f9ff98b19..2ba646fba0 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/RequestHandlerUtilsTest.java @@ -39,6 +39,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.HashMap; import java.util.List; import javax.ws.rs.core.MediaType; import org.apache.http.HttpStatus; @@ -338,4 +339,34 @@ public class RequestHandlerUtilsTest extends BaseTest { assertEquals(expectedBasicAuth, basicAuth); } + @Test + public void getServiceInstanceIdForValidationErrorTest() { + ServiceInstancesRequest sir = new ServiceInstancesRequest(); + String requestScope = "vnf"; + HashMap<String, String> instanceIdMap = new HashMap<String, String>(); + instanceIdMap.put("serviceInstanceId", "testServiceInstanceId"); + String serviceInstanceId = + requestHandlerUtils.getServiceInstanceIdForValidationError(sir, instanceIdMap, requestScope).get(); + assertEquals("testServiceInstanceId", serviceInstanceId); + } + + @Test + public void getServiceInstanceIdForValidationErrorInstanceGroupTest() throws Exception { + ServiceInstancesRequest sir = + mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class); + String requestScope = "instanceGroup"; + String serviceInstanceId = + requestHandlerUtils.getServiceInstanceIdForValidationError(sir, null, requestScope).get(); + assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", serviceInstanceId); + } + + @Test + public void getServiceInstanceIdForInstanceGroupTest() throws Exception { + ServiceInstancesRequest sir = + mapper.readValue(inputStream("/CreateInstanceGroup.json"), ServiceInstancesRequest.class); + String requestScope = "instanceGroup"; + String serviceInstanceId = requestHandlerUtils.getServiceInstanceIdForInstanceGroup(requestScope, sir).get(); + assertEquals("ddcbbf3d-f2c1-4ca0-8852-76a807285efc", serviceInstanceId); + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/activateRequest.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/activateRequest.json new file mode 100644 index 0000000000..e67809c80e --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/activateRequest.json @@ -0,0 +1,9 @@ +{ + "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX", + "networkType": "an/cn/tn", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "additionalProperties": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX" + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/allocateRequest.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/allocateRequest.json new file mode 100644 index 0000000000..24cea593b9 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/allocateRequest.json @@ -0,0 +1,55 @@ +{ + "name": "eMBB-001", + "modelInvariantUuid": "NSST-C-001-HDBNJ-NSSMF-01-A-ZX", + "modelUuid": "NSST-C-001-HDBNJ-NSSMF-01-A-ZX-UUID", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "networkType": "an/cn/tn", + "additionalProperties": { + "sliceProfile": { + "snssaiList": [ + "001-100001" + ], + "sliceProfileId": "ab9af40f13f721b5f13539d87484098", + "plmnIdList": [ + "460-00", + "460-01" + ], + "perfReq": { + "perfReqEmbbList ": [ + { + "activityFactor": 50 + } + ] + }, + "maxNumberofUEs": 200, + "coverageAreaTAList": [ + "1", + "2", + "3", + "4" + ], + "latency": 2, + "resourceSharingLevel": "non-shared" + }, + "endPoints": [ + { + "nodeId": "", + "additionalInfo": { + "xxx": "xxx" + } + }, + { + "nodeId": "", + "additionalInfo": { + "xxx": "xxx" + } + } + ], + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + "scriptName": "AN1" + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deActivateRequest.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deActivateRequest.json new file mode 100644 index 0000000000..e67809c80e --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deActivateRequest.json @@ -0,0 +1,9 @@ +{ + "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX", + "networkType": "an/cn/tn", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "additionalProperties": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX" + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deAllocate.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deAllocate.json new file mode 100644 index 0000000000..50729317e3 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/deAllocate.json @@ -0,0 +1,13 @@ +{ + "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX ", + "networkType": "an/cn/tn", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "additionalProperties": { + "snssaiList": [ + "001-100001" + ], + "scriptName": "AN1", + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX" + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/modifyRequest.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/modifyRequest.json new file mode 100644 index 0000000000..6a7db0165b --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/Onap3gppServiceInstancesTest/modifyRequest.json @@ -0,0 +1,18 @@ +{ + "name": "eMBB-001", + "globalSubscriberId": "5GCustomer", + "subscriptionServiceType": "5G", + "networkType": "an/cn/tn", + "serviceInstanceID": "NSSI-C-001-HDBNJ-NSSMF-01-A-ZX", + "additionalProperties": { + "modifyAction": "allocate/deallocate", + "snssaiList": [ + "001-100001" + ], + "nsiInfo": { + "nsiId": "NSI-M-001-HDBNJ-NSMF-01-A-ZX", + "nsiName": "eMBB-001" + }, + "scriptName": "AN1" + } +}
\ No newline at end of file diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/BPMN_response.json b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/BPMN_response.json new file mode 100644 index 0000000000..b2c29ac4c6 --- /dev/null +++ b/mso-api-handlers/mso-api-handler-infra/src/test/resources/__files/Camunda/BPMN_response.json @@ -0,0 +1,7 @@ +{ + "response":"{\"jobId\":\"db245365e79c47ed88fcd60caa8f6549\",\"status\":\"\",\"statusDescription\":{}}", + "message":"Success", + "processInstanceID":"8878ccf8-1efc-11e8-b332-0050569a141e", + "variables":null, + "messageCode":202 +} diff --git a/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml b/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml index dd14091daf..e4be7094df 100644 --- a/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml +++ b/packages/docker/src/main/docker/docker-files/configs/logging/logback-spring.xml @@ -56,6 +56,12 @@ \t%thread \t%n" /> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>${errorPattern}</pattern> + </encoder> + </appender> + <appender name="Audit" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> <evaluator class="ch.qos.logback.classic.boolex.OnMarkerEvaluator"> @@ -186,11 +192,12 @@ <appender-ref ref="asyncMetric" /> </logger> - <root level="WARN"> + <root level="INFO"> <appender-ref ref="asyncDebug" /> <appender-ref ref="asyncError" /> <appender-ref ref="asyncAudit" /> <appender-ref ref="asyncMetric" /> + <appender-ref ref="STDOUT" /> </root> </configuration>
\ No newline at end of file @@ -32,7 +32,6 @@ <module>so-optimization-clients</module> <module>so-sdn-clients</module> <module>bpmn</module> - <module>cloudify-client</module> <module>cxf-logging</module> <module>so-monitoring</module> <module>so-simulator</module> @@ -963,7 +962,7 @@ <dependency> <groupId>org.onap.aai.schema-service</groupId> <artifactId>aai-schema</artifactId> - <version>1.7.2</version> + <version>1.7.8</version> </dependency> </dependencies> </dependencyManagement> diff --git a/so-etsi-nfvo/pom.xml b/so-etsi-nfvo/pom.xml index 8048f0c7d3..fa85460086 100644 --- a/so-etsi-nfvo/pom.xml +++ b/so-etsi-nfvo/pom.xml @@ -26,6 +26,8 @@ <okhttp-version>2.7.5</okhttp-version> <okio-version>1.13.0</okio-version> <jaxb-api>2.3.0</jaxb-api> + <snakeyaml-version>0.11</snakeyaml-version> + <hamcrest-version>2.2</hamcrest-version> </properties> <build> diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/Application.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/Application.java index 24c09d489e..12f3bfc119 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/Application.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/Application.java @@ -1,19 +1,19 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. + * 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========================================================= */ diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/AsyncThreadExecutorConfiguration.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/AsyncThreadExecutorConfiguration.java index 2eaa710191..4427e1ac2f 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/AsyncThreadExecutorConfiguration.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/AsyncThreadExecutorConfiguration.java @@ -1,19 +1,19 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. + * 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========================================================= */ diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/DefaultToShortClassNameBeanNameGenerator.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/DefaultToShortClassNameBeanNameGenerator.java index 13649ac80c..2546c9c23f 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/DefaultToShortClassNameBeanNameGenerator.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/app/DefaultToShortClassNameBeanNameGenerator.java @@ -1,23 +1,22 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. + * 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.app; import org.springframework.beans.factory.config.BeanDefinition; diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/resources/application.yaml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/resources/application.yaml index 457e956f71..7f0fd93c8d 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/resources/application.yaml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-application/src/main/resources/application.yaml @@ -11,6 +11,19 @@ # 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. +aai: + auth: 2A11B07DB6214A839394AA1EC5844695F5114FC407FF5422625FB00175A3DCB8A1FF745F22867EFA72D5369D599BBD88DA8BED4233CF5586 + version: v19 + endpoint: https://aai.onap:8443 +camunda: + bpm: + admin-user: + id: admin + password: admin + history-level: full + job-execution: + max-pool-size: 30 + core-pool-size: 3 spring: security: usercredentials: @@ -22,7 +35,35 @@ spring: preferred-json-mapper: gson main: allow-bean-definition-overriding: true + datasource: + hikari: + camunda: + jdbcUrl: jdbc:mariadb://${DB_HOST}:${DB_PORT}/camundabpmn + username: ${DB_USERNAME} + password: ${DB_PASSWORD} + driver-class-name: org.mariadb.jdbc.Driver + pool-name: bpmn-pool + registerMbeans: true + nfvo: + jdbcUrl: jdbc:mariadb://${DB_HOST}:${DB_PORT}/nfvo + username: ${NFVO_USERNAME} + password: ${NFVO_PASSWORD} + driver-class-name: org.mariadb.jdbc.Driver + pool-name: nfvo-pool + registerMbeans: true server: port: 9095 tomcat: - max-threads: 50
\ No newline at end of file + max-threads: 50 +mso: + key: 07a7159d3bf51a0e53be7a8f89699be7 +so: + adapters: + sol003-adapter: + url: https://so-vnfm-adapter.onap:9092/so/vnfm-adapter/v1 + auth: Basic dm5mbTpwYXNzd29yZDEk +etsi-catalog-manager: + base: + endpoint: http://modeling-etsicatalog.onap:8806/api +so-etsi-nfvo-ns-lcm: + endpoint: http://so-etsi-nfvo-ns-lcm.onap:9095
\ No newline at end of file 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 734d4e071e..1c13ecac25 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 @@ -8,4 +8,99 @@ </parent> <artifactId>so-etsi-nfvo-ns-lcm-bpmn-flows</artifactId> <name>SO ETSI NFVO NS LCM BPMN Flows</name> + + <build> + <plugins> + <plugin> + <groupId>org.jacoco</groupId> + <artifactId>jacoco-maven-plugin</artifactId> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <systemPropertyVariables> + <so.log.level>DEBUG</so.log.level> + </systemPropertyVariables> + <rerunFailingTestsCount>2</rerunFailingTestsCount> + <parallel>suites</parallel> + <useUnlimitedThreads>false</useUnlimitedThreads> + <threadCount>1</threadCount> + </configuration> + </plugin> + </plugins> + </build> + + <dependencies> + <dependency> + <groupId>org.onap.so.etsi.nfvo</groupId> + <artifactId>so-etsi-nfvo-ns-lcm-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.so.etsi.nfvo</groupId> + <artifactId>so-etsi-nfvo-ns-lcm-database-service</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.so.adapters</groupId> + <artifactId>etsi-sol003-pkgm-ext-clients</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.so.adapters</groupId> + <artifactId>etsi-sol003-lcm-api</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.onap.so</groupId> + <artifactId>aai-client</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.camunda.bpm.springboot</groupId> + <artifactId>camunda-bpm-spring-boot-starter-rest</artifactId> + <version>${camunda.springboot.version}</version> + <exclusions> + <exclusion> + <groupId>org.camunda.bpmn</groupId> + <artifactId>camunda-engine-rest-core</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.yaml</groupId> + <artifactId>snakeyaml</artifactId> + </dependency> + <dependency> + <groupId>com.shazam</groupId> + <artifactId>shazamcrest</artifactId> + <version>${snakeyaml-version}</version> + <exclusions> + <exclusion> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </exclusion> + <exclusion> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + </exclusion> + <exclusion> + <groupId>com.vaadin.external.google</groupId> + <artifactId>android-json</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.hamcrest</groupId> + <artifactId>hamcrest</artifactId> + <version>${hamcrest-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/CamundaCustomConfiguration.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/CamundaCustomConfiguration.java new file mode 100644 index 0000000000..33923f400e --- /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/CamundaCustomConfiguration.java @@ -0,0 +1,49 @@ +/*- + * ============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 static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.NS_WORKFLOW_ENGINE; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.TENANT_ID; +import static org.slf4j.LoggerFactory.getLogger; +import org.camunda.bpm.engine.spring.SpringProcessEngineConfiguration; +import org.camunda.bpm.spring.boot.starter.configuration.Ordering; +import org.camunda.bpm.spring.boot.starter.configuration.impl.AbstractCamundaConfiguration; +import org.slf4j.Logger; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Component +@Order(Ordering.DEFAULT_ORDER + 1) +public class CamundaCustomConfiguration extends AbstractCamundaConfiguration { + private static final Logger logger = getLogger(CamundaCustomConfiguration.class); + + @Override + public void preInit(final SpringProcessEngineConfiguration processEngineConfiguration) { + logger.info("Setting DeploymentTenantId to {} and DeploymentName to {}", TENANT_ID, NS_WORKFLOW_ENGINE); + processEngineConfiguration.setDeploymentTenantId(TENANT_ID); + processEngineConfiguration.setDeploymentName(NS_WORKFLOW_ENGINE); + super.preInit(processEngineConfiguration); + } + +} 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/CamundaDatabaseConfiguration.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/CamundaDatabaseConfiguration.java new file mode 100644 index 0000000000..946bd38cbe --- /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/CamundaDatabaseConfiguration.java @@ -0,0 +1,69 @@ +/*- + * ============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 static org.slf4j.LoggerFactory.getLogger; +import javax.sql.DataSource; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.context.annotation.Profile; +import org.springframework.jmx.export.MBeanExporter; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +@EnableTransactionManagement +@Profile({"!test"}) +public class CamundaDatabaseConfiguration { + + private static final Logger logger = getLogger(CamundaDatabaseConfiguration.class); + + @Autowired(required = false) + private MBeanExporter mBeanExporter; + + @Bean + @ConfigurationProperties(prefix = "spring.datasource.hikari.camunda") + public HikariConfig camundaDbConfig() { + logger.debug("Creating HikariConfig bean ... "); + return new HikariConfig(); + } + + @Primary + @Bean(name = "dataSource") + public DataSource dataSource() { + if (mBeanExporter != null) { + mBeanExporter.addExcludedBean("dataSource"); + } + logger.debug("Creating HikariDataSource bean ... "); + final HikariConfig hikariConfig = this.camundaDbConfig(); + return new HikariDataSource(hikariConfig); + } + +} 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 new file mode 100644 index 0000000000..e90391d51a --- /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/CamundaVariableNameConstants.java @@ -0,0 +1,52 @@ +/*- + * ============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; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class CamundaVariableNameConstants { + + public static final String JOB_ID_PARAM_NAME = "jobId"; + public static final String JOB_BUSINESS_KEY_PARAM_NAME = "jobBusinessKey"; + public static final String CREATE_NS_REQUEST_PARAM_NAME = "createNsRequest"; + public static final String GLOBAL_CUSTOMER_ID_PARAM_NAME = "globalCustomerId"; + 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 CREATE_NS_RESPONSE_PARAM_NAME = "createNsResponse"; + + public static final String INSTANTIATE_NS_REQUEST_PARAM_NAME = "instantiateNsRequest"; + public static final String OCC_ID_PARAM_NAME = "occId"; + public static final String NS_INSTANCE_ID_PARAM_NAME = "NsInstanceId"; + public static final String NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME = "NetworkServiceDescriptor"; + public static final String VNF_CREATE_INSTANTIATE_REQUESTS = "vnfCreateInstantiateRequests"; + + public static final String NF_INST_ID_PARAM_NAME = "NF_INST_ID"; + public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse"; + public static final String OPERATION_STATUS_PARAM_NAME = "operationStatus"; + + private CamundaVariableNameConstants() {} + +} 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 new file mode 100644 index 0000000000..a2128fc2af --- /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/Constants.java @@ -0,0 +1,37 @@ +/*- + * ============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; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class Constants { + + public static final String TENANT_ID = "ns-workflow-engine-tenant"; + public static final String NS_WORKFLOW_ENGINE = "NS-WORKFLOW-ENGINE"; + public static final String CREATE_NS_WORKFLOW_NAME = "CreateNs"; + public static final String INSTANTIATE_NS_WORKFLOW_NAME = "InstantiateNs"; + public static final String GET_NS_OCCURRENCE_OPERATION_STATUS_NAME = "GetNsOccurrenceOperationStatus"; + + + private Constants() {} + +} 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/GsonProvider.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/GsonProvider.java new file mode 100644 index 0000000000..31961d5b86 --- /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/GsonProvider.java @@ -0,0 +1,44 @@ +/*- + * ============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.time.LocalDateTime; +import org.onap.so.etsi.nfvo.ns.lcm.JSON; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.utils.LocalDateTimeTypeAdapter; +import org.springframework.stereotype.Component; +import org.threeten.bp.OffsetDateTime; +import com.google.gson.Gson; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Component +public class GsonProvider { + + private final JSON.OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new JSON.OffsetDateTimeTypeAdapter(); + + public Gson getGson() { + return JSON.createGson().registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter) + .registerTypeAdapter(LocalDateTime.class, new LocalDateTimeTypeAdapter()).create(); + } + + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyConnectException.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/EtsiCatalogManagerRequestFailureException.java index 5bcc27bafc..553d2f1cf8 100644 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyConnectException.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/EtsiCatalogManagerRequestFailureException.java @@ -1,38 +1,41 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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.exceptions; -package org.onap.so.cloudify.base.client; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; /** - * Custom RuntimeException to report connection errors to Openstack endpoints. Must be a RuntimeException to conform - * with OpenstackClient interface, which does not declare specific Exceptions. + * @author Waqas Ikram (waqas.ikram@est.tech) + * */ -public class CloudifyConnectException extends CloudifyBaseException { +@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) +public class EtsiCatalogManagerRequestFailureException extends RuntimeException { - private static final long serialVersionUID = 7294957362769575271L; + private static final long serialVersionUID = 66862444537194516L; - public CloudifyConnectException(String message) { + public EtsiCatalogManagerRequestFailureException(final String message) { super(message); } - public CloudifyConnectException(String message, Throwable cause) { + public EtsiCatalogManagerRequestFailureException(final String message, final Throwable cause) { super(message, cause); } } 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 new file mode 100644 index 0000000000..0dcadfd4d8 --- /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/exceptions/NsRequestProcessingException.java @@ -0,0 +1,53 @@ +/*- + * ============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.exceptions; + +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +/** + * + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +@ResponseStatus(code = HttpStatus.INTERNAL_SERVER_ERROR) +public class NsRequestProcessingException extends RuntimeException { + + private static final long serialVersionUID = 66862444537194516L; + private InlineResponse400 problemDetails; + + public NsRequestProcessingException(final String message) { + super(message); + } + + public NsRequestProcessingException(final String message, final InlineResponse400 problemDetails) { + super(message); + this.problemDetails = problemDetails; + } + + @Override + public synchronized Throwable fillInStackTrace() { + return this; + } + + public InlineResponse400 getProblemDetails() { + return 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/AaiClientProvider.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/AaiClientProvider.java new file mode 100644 index 0000000000..673662aae8 --- /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/extclients/aai/AaiClientProvider.java @@ -0,0 +1,34 @@ +/*- + * ============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.extclients.aai; + +import org.onap.aaiclient.client.aai.AAIResourcesClient; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class AaiClientProvider { + + @Bean + public AAIResourcesClient getAaiClient() { + return new AAIResourcesClient(); + } +} 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/AaiPropertiesImpl.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/AaiPropertiesImpl.java new file mode 100644 index 0000000000..3df3580907 --- /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/extclients/aai/AaiPropertiesImpl.java @@ -0,0 +1,76 @@ +/*- + * ============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.extclients.aai; + +import org.onap.aaiclient.client.aai.AAIProperties; +import org.onap.aaiclient.client.aai.AAIVersion; +import org.onap.so.spring.SpringContextHelper; +import org.springframework.context.ApplicationContext; +import java.net.MalformedURLException; +import java.net.URL; + +public class AaiPropertiesImpl implements AAIProperties { + + private final String endpoint; + private final String encryptedBasicAuth; + private final String encryptionKey; + private final String aaiVersion; + + public AaiPropertiesImpl() { + + final ApplicationContext context = SpringContextHelper.getAppContext(); + this.endpoint = context.getEnvironment().getProperty("aai.endpoint"); + this.encryptedBasicAuth = context.getEnvironment().getProperty("aai.auth"); + this.encryptionKey = context.getEnvironment().getProperty("mso.key"); + this.aaiVersion = context.getEnvironment().getProperty("aai.version"); + } + + @Override + public URL getEndpoint() throws MalformedURLException { + return new URL(endpoint); + } + + @Override + public String getSystemName() { + return "MSO"; + } + + @Override + public AAIVersion getDefaultVersion() { + for (final AAIVersion version : AAIVersion.values()) { + if (version.toString().equalsIgnoreCase(this.aaiVersion)) { + return version; + } ; + + } + return AAIVersion.LATEST; + } + + @Override + public String getAuth() { + return encryptedBasicAuth; + } + + @Override + public String getKey() { + return encryptionKey; + } +} 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 new file mode 100644 index 0000000000..53062395cf --- /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/extclients/aai/AaiServiceProvider.java @@ -0,0 +1,44 @@ +/*- + * ============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.extclients.aai; + +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.ServiceInstance; +import java.util.Optional; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface AaiServiceProvider { + + void createServiceInstance(final String globalCustomerId, final String serviceType, + final ServiceInstance aaiServiceInstance); + + void createGenericVnfAndConnectServiceInstance(final String serviceInstanceId, final String vnfId, + final GenericVnf genericVnf); + + void connectGenericVnfToTenant(final String vnfId, final String cloudOwner, final String cloudRegion, + final String tenantId); + + Optional<GenericVnf> getGenericVnf(final String vnfId); + +} 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 new file mode 100644 index 0000000000..049746c6ab --- /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/extclients/aai/AaiServiceProviderImpl.java @@ -0,0 +1,83 @@ +/*- + * ============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.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.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +@Service +public class AaiServiceProviderImpl implements AaiServiceProvider { + private static final Logger logger = LoggerFactory.getLogger(AaiServiceProviderImpl.class); + private final AaiClientProvider aaiClientProvider; + + @Autowired + public AaiServiceProviderImpl(final AaiClientProvider aaiClientProvider) { + this.aaiClientProvider = aaiClientProvider; + } + + @Override + public void createServiceInstance(final String globalCustomerId, final String serviceType, + final ServiceInstance aaiServiceInstance) { + logger.info("Creating service instance in AAI: {}", aaiServiceInstance); + final AAIResourceUri serviceInstanceURI = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, + globalCustomerId, serviceType, aaiServiceInstance.getServiceInstanceId()); + aaiClientProvider.getAaiClient().createIfNotExists(serviceInstanceURI, Optional.of(aaiServiceInstance)); + + } + + @Override + public void createGenericVnfAndConnectServiceInstance(final String serviceInstanceId, final String vnfId, + final GenericVnf genericVnf) { + logger.info("Creating GenericVnf in AAI: {}", genericVnf); + final AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId); + final AAIResourceUri serviceInstanceURI = + AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId); + aaiClientProvider.getAaiClient().createIfNotExists(genericVnfURI, Optional.of(genericVnf)) + .connect(genericVnfURI, serviceInstanceURI); + + } + + @Override + public void connectGenericVnfToTenant(final String vnfId, final String cloudOwner, final String cloudRegion, + final String tenantId) { + logger.info("Connecting GenericVnf {} to {}/{}/{} in AAI", vnfId, cloudOwner, cloudRegion, tenantId); + final AAIResourceUri tenantURI = + AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudOwner, cloudRegion, tenantId); + final AAIResourceUri genericVnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId); + aaiClientProvider.getAaiClient().connect(tenantURI, genericVnfURI); + } + + @Override + public Optional<GenericVnf> getGenericVnf(final String vnfId) { + return aaiClientProvider.getAaiClient().get(GenericVnf.class, + AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)); + } +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyBaseException.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/EtsiCatalogPackageManagementServiceProvider.java index b8006cb45f..65d982c6cc 100644 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyBaseException.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/EtsiCatalogPackageManagementServiceProvider.java @@ -1,42 +1,39 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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.extclients.etsicatalog; -package org.onap.so.cloudify.base.client; +import java.util.Optional; +import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo; +import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.nsd.NetworkServiceDescriptor; /** - * A common abstract parent of all Openstack Exception types, allowing calling classes the choice to catch all error - * exceptions together. + * @author Waqas Ikram (waqas.ikram@est.tech) + * */ -public abstract class CloudifyBaseException extends RuntimeException { - private static final long serialVersionUID = 1L; +public interface EtsiCatalogPackageManagementServiceProvider { + + Optional<NsdInfo> getNSPackageModel(final String nsdId); - /* - * Implement only the basic constructors - */ - public CloudifyBaseException() {} + Optional<VnfPkgInfo> getVnfPkgInfo(final String vnfPkgId); - public CloudifyBaseException(String message) { - super(message); - } + Optional<NetworkServiceDescriptor> getNetworkServiceDescriptor(final String nsdId); - public CloudifyBaseException(String message, Throwable cause) { - super(message, cause); - } } 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 new file mode 100644 index 0000000000..75dd7107a7 --- /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/extclients/etsicatalog/EtsiCatalogPackageManagementServiceProviderImpl.java @@ -0,0 +1,110 @@ +/*- + * ============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.extclients.etsicatalog; + +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_SERVICE_PROVIDER_BEAN; +import java.util.Optional; +import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo; +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.rest.service.HttpRestServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class EtsiCatalogPackageManagementServiceProviderImpl implements EtsiCatalogPackageManagementServiceProvider { + + private static final Logger logger = LoggerFactory.getLogger(EtsiCatalogPackageManagementServiceProviderImpl.class); + + private final HttpRestServiceProvider httpServiceProvider; + private final EtsiCatalogUrlProvider etsiCatalogUrlProvider; + private final NetworkServiceDescriptorParser networkServiceDescriptorParser; + + @Autowired + public EtsiCatalogPackageManagementServiceProviderImpl(final EtsiCatalogUrlProvider etsiCatalogUrlProvider, + @Qualifier(ETSI_CATALOG_SERVICE_PROVIDER_BEAN) final HttpRestServiceProvider httpServiceProvider, + final NetworkServiceDescriptorParser networkServiceDescriptorParser) { + this.etsiCatalogUrlProvider = etsiCatalogUrlProvider; + this.httpServiceProvider = httpServiceProvider; + this.networkServiceDescriptorParser = networkServiceDescriptorParser; + } + + @Override + public Optional<NsdInfo> getNSPackageModel(final String nsdId) { + try { + final ResponseEntity<NsdInfo> response = + httpServiceProvider.getHttpResponse(etsiCatalogUrlProvider.getNsPackageUrl(nsdId), NsdInfo.class); + if (response.getStatusCode().is2xxSuccessful()) { + return Optional.ofNullable(response.getBody()); + } + 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); + } + } + + @Override + public Optional<VnfPkgInfo> getVnfPkgInfo(final String vnfPkgId) { + try { + final ResponseEntity<VnfPkgInfo> response = httpServiceProvider + .getHttpResponse(etsiCatalogUrlProvider.getVnfPackageUrl(vnfPkgId), VnfPkgInfo.class); + if (response.getStatusCode().is2xxSuccessful()) { + return Optional.ofNullable(response.getBody()); + } + 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); + } + } + + @Override + public Optional<NetworkServiceDescriptor> getNetworkServiceDescriptor(final String nsdId) { + try { + final ResponseEntity<byte[]> response = httpServiceProvider + .getHttpResponse(etsiCatalogUrlProvider.getNsPackageContentUrl(nsdId), byte[].class); + if (response.getStatusCode().is2xxSuccessful()) { + if (response.hasBody()) { + return networkServiceDescriptorParser.parse(response.getBody()); + } + logger.error("Received response without body ..."); + } + 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); + } + } + +} 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 new file mode 100644 index 0000000000..8c6ea92428 --- /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/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java @@ -0,0 +1,188 @@ +/*- + * ============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.extclients.etsicatalog; + +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.util.Iterator; +import java.util.concurrent.TimeUnit; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.ssl.SSLContextBuilder; +import org.onap.logging.filter.spring.SpringClientPayloadFilter; +import org.onap.so.configuration.rest.BasicHttpHeadersProvider; +import org.onap.so.configuration.rest.HttpClientConnectionConfiguration; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; +import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; +import org.onap.so.rest.service.HttpRestServiceProvider; +import org.onap.so.rest.service.HttpRestServiceProviderImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.GsonHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +/** + * Configures the HttpRestServiceProvider to make REST calls to the ETSI Catalog Manager + * + * @author gareth.roper@est.tech + */ + +@Configuration +public class EtsiCatalogServiceProviderConfiguration { + public static final String ETSI_CATALOG_REST_TEMPLATE_BEAN = "etsiCatalogRestTemplate"; + + public static final String ETSI_CATALOG_SERVICE_PROVIDER_BEAN = "etsiCatalogServiceProvider"; + + private final static Logger LOGGER = LoggerFactory.getLogger(EtsiCatalogServiceProviderConfiguration.class); + + private final HttpClientConnectionConfiguration clientConnectionConfiguration; + + @Value("${etsi-catalog-manager.http.client.ssl.trust-store:#{null}}") + private Resource trustStore; + @Value("${etsi-catalog-manager.http.client.ssl.trust-store-password:#{null}}") + private String trustStorePassword; + + private final GsonProvider gsonProvider; + + @Autowired + public EtsiCatalogServiceProviderConfiguration( + final HttpClientConnectionConfiguration clientConnectionConfiguration, final GsonProvider gsonProvider) { + this.clientConnectionConfiguration = clientConnectionConfiguration; + this.gsonProvider = gsonProvider; + } + + @Bean + @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) + public RestTemplate etsiCatalogRestTemplate() { + final RestTemplate restTemplate = new RestTemplate(); + restTemplate.getInterceptors().add(new SOSpringClientFilter()); + restTemplate.getInterceptors().add((new SpringClientPayloadFilter())); + return restTemplate; + } + + @Bean + @Qualifier(ETSI_CATALOG_SERVICE_PROVIDER_BEAN) + public HttpRestServiceProvider etsiCatalogHttpRestServiceProvider( + @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) final RestTemplate restTemplate) { + setGsonMessageConverter(restTemplate); + + final HttpClientBuilder httpClientBuilder = getHttpClientBuilder(); + if (trustStore != null) { + try { + LOGGER.debug("Setting up HttpComponentsClientHttpRequestFactory with SSL Context"); + LOGGER.debug("Setting client trust-store: {}", trustStore.getURL()); + LOGGER.debug("Creating SSLConnectionSocketFactory with AllowAllHostsVerifier ... "); + final SSLContext sslContext = new SSLContextBuilder() + .loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()).build(); + final SSLConnectionSocketFactory sslConnectionSocketFactory = + new SSLConnectionSocketFactory(sslContext, AllowAllHostsVerifier.INSTANCE); + httpClientBuilder.setSSLSocketFactory(sslConnectionSocketFactory); + final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder + .<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE) + .register("https", sslConnectionSocketFactory).build(); + + httpClientBuilder.setConnectionManager(getConnectionManager(socketFactoryRegistry)); + } catch (final KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException + | IOException exception) { + LOGGER.error("Error reading truststore, TLS connection will fail.", exception); + } + + } else { + LOGGER.debug("Setting connection manager without SSL ConnectionSocketFactory ..."); + httpClientBuilder.setConnectionManager(getConnectionManager()); + } + + final HttpComponentsClientHttpRequestFactory factory = + new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build()); + restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(factory)); + + return new HttpRestServiceProviderImpl(restTemplate, new BasicHttpHeadersProvider().getHttpHeaders()); + } + + private PoolingHttpClientConnectionManager getConnectionManager( + final Registry<ConnectionSocketFactory> socketFactoryRegistry) { + return new PoolingHttpClientConnectionManager(socketFactoryRegistry, null, null, null, + clientConnectionConfiguration.getTimeToLiveInMins(), TimeUnit.MINUTES); + } + + private PoolingHttpClientConnectionManager getConnectionManager() { + return new PoolingHttpClientConnectionManager(clientConnectionConfiguration.getTimeToLiveInMins(), + TimeUnit.MINUTES); + } + + private HttpClientBuilder getHttpClientBuilder() { + return HttpClientBuilder.create().setMaxConnPerRoute(clientConnectionConfiguration.getMaxConnectionsPerRoute()) + .setMaxConnTotal(clientConnectionConfiguration.getMaxConnections()) + .setDefaultRequestConfig(getRequestConfig()); + } + + private RequestConfig getRequestConfig() { + return RequestConfig.custom().setSocketTimeout(clientConnectionConfiguration.getSocketTimeOutInMiliSeconds()) + .setConnectTimeout(clientConnectionConfiguration.getConnectionTimeOutInMilliSeconds()).build(); + } + + private static final class AllowAllHostsVerifier implements HostnameVerifier { + + private static final AllowAllHostsVerifier INSTANCE = new AllowAllHostsVerifier(); + + @Override + public boolean verify(final String hostname, final SSLSession session) { + LOGGER.debug("Skipping hostname verification ..."); + return true; + } + + } + + public void setGsonMessageConverter(final RestTemplate restTemplate) { + final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator(); + while (iterator.hasNext()) { + if (iterator.next() instanceof MappingJackson2HttpMessageConverter) { + iterator.remove(); + } + } + restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gsonProvider.getGson())); + } + + + +} 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 new file mode 100644 index 0000000000..e3c159c7b0 --- /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/extclients/etsicatalog/EtsiCatalogUrlProvider.java @@ -0,0 +1,51 @@ +/*- + * ============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.extclients.etsicatalog; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +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; + } + + public String getNsPackageContentUrl(final String nsdId) { + return etsiCatalogManagerEndpoint + "/nsd/v1/ns_descriptors/" + nsdId + "/nsd_content"; + } + + public String getVnfPackageUrl(final String vnfPkgId) { + return etsiCatalogManagerEndpoint + "/vnfpkgm/v1/vnf_packages/" + vnfPkgId; + } + + +} 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 new file mode 100644 index 0000000000..fe710ec00b --- /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/extclients/vnfm/Sol003AdapterConfiguration.java @@ -0,0 +1,148 @@ +/*- + * ============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.extclients.vnfm; + +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.util.Iterator; +import javax.net.ssl.SSLContext; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContextBuilder; +import org.onap.logging.filter.spring.SpringClientPayloadFilter; +import org.onap.so.configuration.rest.BasicHttpHeadersProvider; +import org.onap.so.configuration.rest.HttpComponentsClientConfiguration; +import org.onap.so.configuration.rest.HttpHeadersProvider; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; +import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; +import org.onap.so.rest.service.HttpRestServiceProvider; +import org.onap.so.rest.service.HttpRestServiceProviderImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.GsonHttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; +import org.springframework.web.client.RestTemplate; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +public class Sol003AdapterConfiguration { + + private static final Logger logger = LoggerFactory.getLogger(Sol003AdapterConfiguration.class); + + public static final String SOL003_ADAPTER_REST_TEMPLATE_BEAN = "Sol003AdapterRestTemplateBean"; + public static final String SOL003_ADAPTER_HTTP_REST_SERVICE_PROVIDER_BEAN = + "Sol003AdapterHttpRestServiceProviderBean"; + + @Value("${rest.http.client.configuration.ssl.trustStore:#{null}}") + private Resource trustStore; + + @Value("${rest.http.client.configuration.ssl.trustStorePassword:#{null}}") + private String trustStorePassword; + + @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() { + final HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = + httpComponentsClientConfiguration.httpComponentsClientHttpRequestFactory(); + final RestTemplate restTemplate = + new RestTemplate(new BufferingClientHttpRequestFactory(clientHttpRequestFactory)); + restTemplate.getInterceptors().add(new SOSpringClientFilter()); + restTemplate.getInterceptors().add((new SpringClientPayloadFilter())); + return restTemplate; + + } + + @Bean + @Qualifier(SOL003_ADAPTER_HTTP_REST_SERVICE_PROVIDER_BEAN) + public HttpRestServiceProvider sol003AdapaterHttpRestServiceProvider( + @Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN) @Autowired final RestTemplate restTemplate) { + + if (trustStore != null) { + setTrustStore(restTemplate); + } + setGsonMessageConverter(restTemplate); + return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider(sol003AdapterBasicAuth)); + } + + private void setTrustStore(final RestTemplate restTemplate) { + try { + final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(getSSLContext()); + final HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build(); + final HttpComponentsClientHttpRequestFactory factory = + new HttpComponentsClientHttpRequestFactory(httpClient); + restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(factory)); + } catch (Exception exception) { + logger.error("Error reading truststore, TLS connection to VNFM will fail.", exception); + } + } + + private SSLContext getSSLContext() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, + CertificateException, IOException { + if (trustStore != null) { + logger.info("Setting truststore: {}", trustStore.getURL()); + return new SSLContextBuilder().loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()) + .build(); + } + logger.info("Setting Default SSL ..."); + return SSLContext.getDefault(); + + } + + private HttpRestServiceProvider getHttpRestServiceProvider(final RestTemplate restTemplate, + final HttpHeadersProvider httpHeadersProvider) { + return new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider.getHttpHeaders()); + } + + private void setGsonMessageConverter(final RestTemplate restTemplate) { + final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator(); + while (iterator.hasNext()) { + if (iterator.next() instanceof MappingJackson2HttpMessageConverter) { + iterator.remove(); + } + } + restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gsonProvider.getGson())); + } +} 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/Sol003AdapterServiceProvider.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/Sol003AdapterServiceProvider.java new file mode 100644 index 0000000000..c053ba94f1 --- /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/extclients/vnfm/Sol003AdapterServiceProvider.java @@ -0,0 +1,34 @@ +/*- + * ============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.extclients.vnfm; + +import java.util.Optional; +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.QueryJobResponse; + +public interface Sol003AdapterServiceProvider { + + Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, final CreateVnfRequest request); + + Optional<QueryJobResponse> getInstantiateOperationJobStatus(final String jobId); + +} 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 new file mode 100644 index 0000000000..09fecc64ae --- /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/extclients/vnfm/Sol003AdapterServiceProviderImpl.java @@ -0,0 +1,117 @@ +/*- + * ============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.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.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.QueryJobResponse; +import org.onap.so.rest.exceptions.HttpResouceNotFoundException; +import org.onap.so.rest.exceptions.InvalidRestRequestException; +import org.onap.so.rest.exceptions.RestProcessingException; +import org.onap.so.rest.service.HttpRestServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +@Service +public class Sol003AdapterServiceProviderImpl implements Sol003AdapterServiceProvider { + + private static final Logger LOGGER = LoggerFactory.getLogger(Sol003AdapterServiceProviderImpl.class); + public static final String RECEIVED_RESPONSE_WITHOUT_BODY = "Received response without body: {}"; + + private final Sol003AdapterUrlProvider urlProvider; + private final HttpRestServiceProvider httpServiceProvider; + + @Autowired + public Sol003AdapterServiceProviderImpl(final Sol003AdapterUrlProvider urlProvider, + @Qualifier(SOL003_ADAPTER_HTTP_REST_SERVICE_PROVIDER_BEAN) final HttpRestServiceProvider httpServiceProvider) { + this.urlProvider = urlProvider; + this.httpServiceProvider = httpServiceProvider; + } + + @Override + public Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, + final CreateVnfRequest request) { + try { + final String url = urlProvider.getCreateInstantiateUrl(vnfId); + + final ResponseEntity<CreateVnfResponse> response = + httpServiceProvider.postHttpRequest(request, url, CreateVnfResponse.class); + + final HttpStatus httpStatus = response.getStatusCode(); + if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) { + LOGGER.error("Unable to invoke HTTP POST using URL: {}, Response Code: {}", url, httpStatus.value()); + return Optional.empty(); + } + + if (!response.hasBody()) { + LOGGER.error(RECEIVED_RESPONSE_WITHOUT_BODY, response); + return Optional.empty(); + } + + final CreateVnfResponse createVnfResponse = response.getBody(); + + if (createVnfResponse.getJobId() == null || createVnfResponse.getJobId().isEmpty()) { + LOGGER.error("Received invalid instantiation response: {}", response); + return Optional.empty(); + } + + return Optional.of(createVnfResponse); + } catch (final RestProcessingException | InvalidRestRequestException + | HttpResouceNotFoundException httpInvocationException) { + LOGGER.error("Unexpected error while processing create and instantiation request", httpInvocationException); + return Optional.empty(); + } + + } + + @Override + public Optional<QueryJobResponse> getInstantiateOperationJobStatus(final String jobId) { + try { + final String url = urlProvider.getJobStatusUrl(jobId); + + final ResponseEntity<QueryJobResponse> response = + httpServiceProvider.getHttpResponse(url, QueryJobResponse.class); + + final HttpStatus httpStatus = response.getStatusCode(); + + if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) { + LOGGER.error("Unable to invoke HTTP GET using URL: {}, Response Code: ", url, httpStatus.value()); + return Optional.empty(); + } + + if (!response.hasBody()) { + LOGGER.error(RECEIVED_RESPONSE_WITHOUT_BODY, response); + return Optional.empty(); + } + return Optional.of(response.getBody()); + } catch (final RestProcessingException | InvalidRestRequestException | HttpResouceNotFoundException exception) { + LOGGER.error("Unexpected error while processing job request", exception); + throw 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/Sol003AdapterUrlProvider.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/Sol003AdapterUrlProvider.java new file mode 100644 index 0000000000..351d4bf88c --- /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/extclients/vnfm/Sol003AdapterUrlProvider.java @@ -0,0 +1,64 @@ +/*- + * ============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.extclients.vnfm; + +import java.net.URI; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.web.util.UriComponentsBuilder; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class Sol003AdapterUrlProvider { + + private final URI baseUri; + + @Autowired + public Sol003AdapterUrlProvider( + @Value("${so.adapters.sol003-adapter.url:https://so-vnfm-adapter.onap:9092/so/vnfm-adapter/v1/}") final String sol003AdapterUrl) { + this.baseUri = UriComponentsBuilder.fromHttpUrl(sol003AdapterUrl).build().toUri(); + } + + /** + * Get VNFM create and instantiate URL + * + * @param vnfId The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in AAI. + * @return VNFM create and instantiate URL + */ + public String getCreateInstantiateUrl(final String vnfId) { + return UriComponentsBuilder.fromUri(baseUri).pathSegment("vnfs").pathSegment(vnfId).build().toString(); + } + + /** + * Get job status URL + * + * @param jobId The instantiation job identifier + * @return job status URL + */ + public String getJobStatusUrl(final String jobId) { + return UriComponentsBuilder.fromUri(baseUri).pathSegment("jobs").pathSegment(jobId).build().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/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 new file mode 100644 index 0000000000..58ca2507bd --- /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/nsd/FileEntry.java @@ -0,0 +1,111 @@ +/*- + * ============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.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.Objects; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class FileEntry { + + private boolean isDirectory; + private String filePath; + private byte[] fileContent; + + public boolean isDirectory() { + return isDirectory; + } + + public void setDirectory(final boolean isDirectory) { + this.isDirectory = isDirectory; + } + + public FileEntry isDirectory(final boolean isDirectory) { + this.isDirectory = isDirectory; + return this; + } + + public String getFilePath() { + return filePath; + } + + public void setFilename(final String filePath) { + this.filePath = filePath; + } + + public FileEntry filePath(final String filePath) { + this.filePath = filePath; + return this; + } + + public byte[] getFileContent() { + return fileContent; + } + + public void setFileContent(final byte[] fileContent) { + this.fileContent = fileContent; + } + + public FileEntry fileContent(final byte[] fileContent) { + this.fileContent = fileContent; + return this; + } + + public InputStream getFileContentAsStream() { + if (fileContent == null || fileContent.length == 0) { + return null; + } + return new ByteArrayInputStream(fileContent); + } + + @Override + public int hashCode() { + return Objects.hash(isDirectory, filePath, fileContent); + } + + @Override + public boolean equals(final Object obj) { + 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); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class FileEntry {\n"); + sb.append(" isDirectory: ").append(toIndentedString(isDirectory)).append("\n"); + sb.append(" filePath: ").append(toIndentedString(filePath)).append("\n"); + sb.append(" fileContent size: ").append(toIndentedString(fileContent != null ? fileContent.length : 0)) + .append("\n"); + sb.append("}"); + return sb.toString(); + } + + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientConnector.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/FileParser.java index 652df6ff0d..9df5262302 100644 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyClientConnector.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/FileParser.java @@ -1,8 +1,6 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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. @@ -15,14 +13,20 @@ * 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.nsd; -package org.onap.so.cloudify.base.client; +import java.util.Map; -@FunctionalInterface -public interface CloudifyClientConnector { +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface FileParser { - public <T> CloudifyResponse request(CloudifyRequest<T> request); + Map<String, Object> getFileContent(final FileEntry entryDefinitionFileEntry); } 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/NetworkServiceDescriptor.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/NetworkServiceDescriptor.java new file mode 100644 index 0000000000..6b4fee7151 --- /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/nsd/NetworkServiceDescriptor.java @@ -0,0 +1,121 @@ +/*- + * ============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.nsd; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class NetworkServiceDescriptor implements Serializable { + + private static final long serialVersionUID = -1739293595041180242L; + + private String type; + + private Map<String, Object> properties = new HashMap<>(); + + private List<VirtualNetworkFunction> vnfs = new ArrayList<>(); + + public String getType() { + return type; + } + + public void setType(final String type) { + this.type = type; + } + + public NetworkServiceDescriptor type(final String type) { + this.type = type; + return this; + } + + public Map<String, Object> getProperties() { + return properties; + } + + public void setProperties(final Map<String, Object> properties) { + this.properties = properties; + } + + public NetworkServiceDescriptor properties(final Map<String, Object> properties) { + this.properties = properties; + return this; + } + + public List<VirtualNetworkFunction> getVnfs() { + return vnfs; + } + + public void setVnfs(final List<VirtualNetworkFunction> vnfs) { + if (vnfs != null) { + this.vnfs = vnfs; + } else { + this.vnfs = new ArrayList<>(); + } + } + + public NetworkServiceDescriptor addVnfPkgIdsItem(final VirtualNetworkFunction vnf) { + if (this.vnfs == null) { + this.vnfs = new ArrayList<>(); + } + this.vnfs.add(vnf); + return this; + } + + public NetworkServiceDescriptor vnfs(final List<VirtualNetworkFunction> vnfs) { + this.vnfs = vnfs; + return this; + } + + @Override + public int hashCode() { + return Objects.hash(type, properties, vnfs); + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof NetworkServiceDescriptor) { + final NetworkServiceDescriptor other = (NetworkServiceDescriptor) obj; + return Objects.equals(type, other.type) && Objects.equals(properties, other.properties) + && Objects.equals(vnfs, other.vnfs); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NetworkServiceDescriptor {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); + sb.append(" vnfs: ").append(toIndentedString(vnfs)).append("\n"); + sb.append("}"); + return sb.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/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/NetworkServiceDescriptorParser.java new file mode 100644 index 0000000000..33737f4c17 --- /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/nsd/NetworkServiceDescriptorParser.java @@ -0,0 +1,209 @@ +/*- + * ============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.nsd; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class NetworkServiceDescriptorParser { + public static final String NS_NODE_TYPE = "tosca.nodes.nfv.NS"; + private static final String NODE_TYPE = "node_type"; + private static final String SUBSTITUTION_MAPPINGS = "substitution_mappings"; + private static final Logger logger = LoggerFactory.getLogger(NetworkServiceDescriptorParser.class); + private static final String VNF_TYPE = "tosca.nodes.nfv.VNF"; + private static final String PROPERTIES = "properties"; + private static final String TYPE = "type"; + private static final String NODE_TEMPLATES = "node_templates"; + private static final String TOPOLOGY_TEMPLATE = "topology_template"; + private static final String ENTRY_DEFINITIONS = "Entry-Definitions"; + private static final String TOSCA_META_PATH_FILE_NAME = "TOSCA-Metadata/TOSCA.meta"; + private final ToscaMetadataParser toscaMetadataParser; + private final FileParser fileParser; + + @Autowired + public NetworkServiceDescriptorParser(final ToscaMetadataParser toscaMetadataParser, final FileParser fileParser) { + this.toscaMetadataParser = toscaMetadataParser; + this.fileParser = fileParser; + } + + public Optional<NetworkServiceDescriptor> parse(final byte[] zipBytes) { + try { + final Map<String, FileEntry> files = getZipContent(zipBytes); + if (isMetaFilePresent(files)) { + final Optional<ToscaMetadata> optional = + toscaMetadataParser.parse(files.get(TOSCA_META_PATH_FILE_NAME)); + if (optional.isPresent()) { + final ToscaMetadata toscaMetadata = optional.get(); + logger.info("Parsed ToscaMetadata {}", toscaMetadata); + final String entryDefinitionFile = toscaMetadata.getEntry(ENTRY_DEFINITIONS); + if (entryDefinitionFile != null && files.containsKey(entryDefinitionFile)) { + final Map<String, Object> fileContent = + fileParser.getFileContent(files.get(entryDefinitionFile)); + final Map<String, Object> topologyTemplates = getTopologyTemplates(fileContent); + final Map<String, Object> nodeTemplates = getNodeTemplates(topologyTemplates); + + final Optional<NetworkServiceDescriptor> nsdOptional = + getNetworkServiceDescriptor(topologyTemplates);; + if (nsdOptional.isPresent()) { + final NetworkServiceDescriptor networkServiceDescriptor = nsdOptional.get(); + networkServiceDescriptor.setVnfs(getVirtualNetworkFunctions(nodeTemplates)); + return Optional.of(networkServiceDescriptor); + } + + } + } + + } + + } catch (final Exception exception) { + logger.error("Unable to parser nsd zip content", exception); + } + logger.error("Unable to parser nsd zip content"); + return Optional.empty(); + } + + @SuppressWarnings("unchecked") + private Optional<NetworkServiceDescriptor> getNetworkServiceDescriptor( + final Map<String, Object> topologyTemplates) { + 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)) { + final NetworkServiceDescriptor networkServiceDescriptor = new NetworkServiceDescriptor(); + networkServiceDescriptor.setType(nodeType.toString()); + networkServiceDescriptor.setProperties((Map<String, Object>) substitutionMappings.get(PROPERTIES)); + return Optional.of(networkServiceDescriptor); + } + logger.error("No {} found in fileContent: {}", SUBSTITUTION_MAPPINGS, topologyTemplates); + + return Optional.empty(); + } + + private List<VirtualNetworkFunction> getVirtualNetworkFunctions(final Map<String, Object> nodeTemplates) { + final List<VirtualNetworkFunction> vnfs = new ArrayList<>(); + for (final Entry<String, Object> entry : nodeTemplates.entrySet()) { + @SuppressWarnings("unchecked") + final Map<String, Object> entryValue = (Map<String, Object>) entry.getValue(); + final Object type = entryValue.get(TYPE); + if (type != null && type.equals(VNF_TYPE)) { + @SuppressWarnings("unchecked") + final Map<String, Object> vnfProperties = (Map<String, Object>) entryValue.get(PROPERTIES); + final VirtualNetworkFunction vnf = new VirtualNetworkFunction(); + vnf.setVnfName(entry.getKey()); + + if (vnfProperties != null && !vnfProperties.isEmpty()) { + final Object vnfDescriptorId = vnfProperties.get("descriptor_id"); + @SuppressWarnings("unchecked") + final List<String> vnfmInfoList = (List<String>) vnfProperties.get("vnfm_info"); + if (vnfDescriptorId != null && vnfmInfoList != null) { + vnf.setVnfmInfoList(vnfmInfoList); + vnf.setVnfdId(vnfDescriptorId.toString()); + vnf.setProperties(vnfProperties); + vnfs.add(vnf); + } else { + logger.warn("descriptor_id missing {}", entryValue); + } + } + } + + } + return vnfs; + } + + private Map<String, Object> getNodeTemplates(final Map<String, Object> topologyTemplates) { + @SuppressWarnings("unchecked") + final Map<String, Object> nodeTemplates = (Map<String, Object>) topologyTemplates.get(NODE_TEMPLATES); + if (nodeTemplates != null) { + logger.debug("Found nodeTemplates: {}", topologyTemplates); + return nodeTemplates; + } + logger.error("No {} found in fileContent: {}", NODE_TEMPLATES, topologyTemplates); + return Collections.emptyMap(); + } + + private Map<String, Object> getTopologyTemplates(final Map<String, Object> fileContent) { + @SuppressWarnings("unchecked") + final Map<String, Object> topologyTemplates = (Map<String, Object>) fileContent.get(TOPOLOGY_TEMPLATE); + if (topologyTemplates != null) { + logger.debug("Found {}: {}", TOPOLOGY_TEMPLATE, topologyTemplates); + + return topologyTemplates; + } + logger.error("No {} found in fileContent: {}", TOPOLOGY_TEMPLATE, fileContent); + return Collections.emptyMap(); + } + + private boolean isMetaFilePresent(final Map<String, FileEntry> files) { + return files.containsKey(TOSCA_META_PATH_FILE_NAME); + } + + private Map<String, FileEntry> getZipContent(final byte[] zipBytes) { + final Map<String, FileEntry> files = new HashMap<>(); + try (final ZipInputStream inputZipStream = new ZipInputStream(new ByteArrayInputStream(zipBytes));) { + ZipEntry zipEntry; + while ((zipEntry = inputZipStream.getNextEntry()) != null) { + logger.info("{} : {}", zipEntry.getName(), zipEntry.isDirectory()); + if (files.get(zipEntry.getName()) != null) { + logger.warn("{} File entry already exists ...", zipEntry.getName()); + } else { + final FileEntry fileEntry = new FileEntry().filePath(zipEntry.getName()) + .fileContent(getBytes(inputZipStream)).isDirectory(zipEntry.isDirectory()); + files.put(zipEntry.getName(), fileEntry); + + } + + } + return files; + } catch (final Exception exception) { + logger.error("Unable to parser nsd zip content", exception); + return Collections.emptyMap(); + } + } + + private byte[] getBytes(final ZipInputStream inputZipStream) throws IOException { + try { + return IOUtils.toByteArray(inputZipStream); + } catch (final IOException exception) { + logger.error("Could not read bytes from file", exception); + throw 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/nsd/ToscaMetadata.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/ToscaMetadata.java new file mode 100644 index 0000000000..c07a55c459 --- /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/nsd/ToscaMetadata.java @@ -0,0 +1,75 @@ +/*- + * ============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.nsd; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class ToscaMetadata { + + private Map<String, String> entries = new HashMap<>(); + + public Map<String, String> getEntries() { + return entries; + } + + public void addEntry(final String name, final String value) { + this.entries.put(name, value); + } + + public boolean hasEntry(final String name) { + return this.entries.containsKey(name); + } + + public String getEntry(final String name) { + return this.entries.get(name); + } + + @Override + public int hashCode() { + return Objects.hash(entries); + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof ToscaMetadata) { + final ToscaMetadata other = (ToscaMetadata) obj; + return Objects.equals(entries, other.entries); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class ToscaMetadata {\n"); + sb.append(" entries: ").append(toIndentedString(entries)).append("\n"); + sb.append("}"); + return sb.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/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/ToscaMetadataParser.java new file mode 100644 index 0000000000..fe23f5ef8d --- /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/nsd/ToscaMetadataParser.java @@ -0,0 +1,67 @@ +/*- + * ============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.nsd; + +import static org.apache.commons.lang3.StringUtils.isNotBlank; +import java.util.List; +import java.util.Optional; +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class ToscaMetadataParser { + private static final String ATTRIBUTE_VALUE_SEPARATOR = ":"; + private static final Logger logger = LoggerFactory.getLogger(ToscaMetadataParser.class); + + public Optional<ToscaMetadata> parse(final FileEntry toscaMetaFile) { + try { + final ToscaMetadata toscaMetadata = new ToscaMetadata(); + 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)) { + final String[] entry = trimmedLine.split(ATTRIBUTE_VALUE_SEPARATOR); + if (entry.length >= 2 && isNotBlank(entry[0]) && isNotBlank(entry[1])) { + toscaMetadata.addEntry(entry[0].trim(), entry[1].trim()); + } else { + logger.warn("Unexpected line in metadata file: {}", line); + } + } else { + logger.warn("Unexpected line does not contain valid separator {} in metadata file: {}", + ATTRIBUTE_VALUE_SEPARATOR, line); + } + + } + return Optional.of(toscaMetadata); + + } catch (final Exception exception) { + logger.error("Unable to parser metadata file content", exception); + } + 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/VirtualNetworkFunction.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/VirtualNetworkFunction.java new file mode 100644 index 0000000000..f4c3632589 --- /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/nsd/VirtualNetworkFunction.java @@ -0,0 +1,123 @@ +/*- + * ============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.nsd; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.io.Serializable; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class VirtualNetworkFunction implements Serializable { + + private static final long serialVersionUID = 3164293220359211834L; + + private String vnfdId; + private String vnfName; + private List<String> vnfmInfoList; + private Map<String, Object> properties = new HashMap<>(); + + public String getVnfdId() { + return vnfdId; + } + + public void setVnfdId(final String vnfdId) { + this.vnfdId = vnfdId; + } + + public VirtualNetworkFunction vnfdId(final String vnfdId) { + this.vnfdId = vnfdId; + return this; + } + + public String getVnfName() { + return vnfName; + } + + public void setVnfName(final String vnfName) { + this.vnfName = vnfName; + } + + public VirtualNetworkFunction vnfName(final String vnfName) { + this.vnfName = vnfName; + return this; + } + + public List<String> getVnfmInfoList() { + return vnfmInfoList; + } + + public void setVnfmInfoList(final List<String> vnfmInfoList) { + this.vnfmInfoList = vnfmInfoList; + } + + public VirtualNetworkFunction vnfmInfoList(final List<String> vnfmInfoList) { + this.vnfmInfoList = vnfmInfoList; + return this; + } + + public Map<String, Object> getProperties() { + return properties; + } + + public void setProperties(final Map<String, Object> properties) { + this.properties = properties; + } + + public VirtualNetworkFunction properties(final Map<String, Object> properties) { + this.properties = properties; + return this; + } + + @Override + public int hashCode() { + return Objects.hash(vnfdId, vnfName, vnfmInfoList, properties); + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof VirtualNetworkFunction) { + final VirtualNetworkFunction other = (VirtualNetworkFunction) obj; + return Objects.equals(vnfdId, other.vnfdId) && Objects.equals(vnfName, other.vnfName) + && Objects.equals(vnfmInfoList, other.vnfmInfoList) && Objects.equals(properties, other.properties); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class VirtualNetworkFunction {\n"); + sb.append(" vnfdId: ").append(toIndentedString(vnfdId)).append("\n"); + sb.append(" vnfName: ").append(toIndentedString(vnfName)).append("\n"); + sb.append(" vnfmInfo: ").append(toIndentedString(vnfmInfoList)).append("\n"); + sb.append(" properties: ").append(toIndentedString(properties)).append("\n"); + + sb.append("}"); + return sb.toString(); + } + + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponse.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/YamlFileParser.java index 6b70e5fa95..ac8f782a99 100644 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponse.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/YamlFileParser.java @@ -1,39 +1,39 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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.nsd; -package org.onap.so.cloudify.base.client; - -import java.io.InputStream; -import java.io.Serializable; import java.util.Map; +import org.springframework.stereotype.Service; +import org.yaml.snakeyaml.Yaml; -public interface CloudifyResponse extends Serializable { - - public <T> T getEntity(Class<T> returnType); - - public <T> T getErrorEntity(Class<T> returnType); - - public InputStream getInputStream(); - - public String getHeader(String name); - - public Map<String, String> headers(); +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class YamlFileParser implements FileParser { + + @Override + public Map<String, Object> getFileContent(final FileEntry entryDefinitionFileEntry) { + final Yaml yaml = new Yaml(); + return yaml.load(entryDefinitionFileEntry.getFileContentAsStream()); + } } 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 new file mode 100644 index 0000000000..f3c38e537f --- /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/service/JobExecutorService.java @@ -0,0 +1,252 @@ +/*- + * ============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.service; + +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.GLOBAL_CUSTOMER_ID_PARAM_NAME; +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.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; +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.Constants.CREATE_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.database.beans.JobAction.INSTANTIATE; +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.FINISHED_WITH_ERROR; +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.STARTING; +import static org.slf4j.LoggerFactory.getLogger; +import java.time.Instant; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.tuple.ImmutablePair; +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.database.beans.JobAction; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +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.service.DatabaseServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import com.google.common.collect.ImmutableSet; +import com.google.gson.Gson; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class JobExecutorService { + + private static final Logger logger = getLogger(JobExecutorService.class); + + private static final ImmutableSet<JobStatusEnum> JOB_FINISHED_STATES = + ImmutableSet.of(FINISHED, ERROR, FINISHED_WITH_ERROR); + + private static final int SLEEP_TIME_IN_SECONDS = 5; + + @Value("${so-etsi-ns-lcm-workflow-engine.requesttimeout.timeoutInSeconds:300}") + private int timeOutInSeconds; + + private final DatabaseServiceProvider databaseServiceProvider; + private final WorkflowExecutorService workflowExecutorService; + private final WorkflowQueryService workflowQueryService; + private Gson gson; + + @Autowired + public JobExecutorService(final DatabaseServiceProvider databaseServiceProvider, + final WorkflowExecutorService workflowExecutorService, final WorkflowQueryService workflowQueryService, + final GsonProvider gsonProvider) { + this.databaseServiceProvider = databaseServiceProvider; + this.workflowExecutorService = workflowExecutorService; + this.workflowQueryService = workflowQueryService; + gson = gsonProvider.getGson(); + } + + public NsInstancesNsInstance runCreateNsJob(final CreateNsRequest createNsRequest, final String globalCustomerId, + final String serviceType) { + logger.info("Starting 'Create NS' workflow job for request:\n{}", createNsRequest); + final NfvoJob newJob = new NfvoJob().startTime(LocalDateTime.now()).jobType("NS").jobAction(JobAction.CREATE) + .resourceId(createNsRequest.getNsdId()).resourceName(createNsRequest.getNsName()) + .status(JobStatusEnum.STARTING).progress(5); + databaseServiceProvider.addJob(newJob); + + logger.info("New job created in database :\n{}", newJob); + + workflowExecutorService.executeWorkflow(newJob.getJobId(), CREATE_NS_WORKFLOW_NAME, + getVariables(newJob.getJobId(), createNsRequest, globalCustomerId, serviceType)); + + final ImmutablePair<String, JobStatusEnum> immutablePair = + waitForJobToFinish(newJob.getJobId(), JOB_FINISHED_STATES); + + if (immutablePair.getRight() == null) { + final String message = "Failed to create NS for request: \n" + createNsRequest; + logger.error(message); + throw new NsRequestProcessingException(message); + } + final JobStatusEnum finalJobStatus = immutablePair.getRight(); + final String processInstanceId = immutablePair.getLeft(); + + if (!FINISHED.equals(finalJobStatus)) { + + final Optional<InlineResponse400> optional = workflowQueryService.getProblemDetails(processInstanceId); + if (optional.isPresent()) { + final InlineResponse400 problemDetails = optional.get(); + final String message = + "Failed to create NS for request: \n" + createNsRequest + " due to \n" + problemDetails; + logger.error(message); + throw new NsRequestProcessingException(message, problemDetails); + } + + final String message = "Received unexpected Job Status: " + finalJobStatus + + " Failed to Create NS for request: \n" + createNsRequest; + logger.error(message); + throw new NsRequestProcessingException(message); + } + + logger.debug("Will query for CreateNsResponse using processInstanceId:{}", processInstanceId); + final Optional<NsInstancesNsInstance> optional = workflowQueryService.getCreateNsResponse(processInstanceId); + if (optional.isEmpty()) { + final String message = + "Unable to find CreateNsReponse in Camunda History for process instance: " + processInstanceId; + logger.error(message); + throw new NsRequestProcessingException(message); + } + return optional.get(); + } + + public String runInstantiateNsJob(final String nsInstanceId, final InstantiateNsRequest instantiateNsRequest) { + + final NfvoJob newJob = new NfvoJob().startTime(LocalDateTime.now()).jobType("NS").jobAction(INSTANTIATE) + .resourceId(nsInstanceId).status(STARTING).progress(0); + databaseServiceProvider.addJob(newJob); + logger.info("New job created in database :\n{}", newJob); + + final LocalDateTime currentDateTime = LocalDateTime.now(); + final NsLcmOpOcc newNsLcmOpOcc = new NsLcmOpOcc().id(nsInstanceId).operation(NsLcmOpType.INSTANTIATE) + .operationState(OperationStateEnum.PROCESSING).stateEnteredTime(currentDateTime) + .startTime(currentDateTime).isAutoInnovation(false).isCancelPending(false) + .operationParams(gson.toJson(instantiateNsRequest)); + databaseServiceProvider.addNSLcmOpOcc(newNsLcmOpOcc); + logger.info("New NSLcmOpOcc created in database :\n{}", newNsLcmOpOcc); + + workflowExecutorService.executeWorkflow(newJob.getJobId(), INSTANTIATE_NS_WORKFLOW_NAME, + getVariables(nsInstanceId, newJob.getJobId(), newNsLcmOpOcc.getId(), instantiateNsRequest)); + + final ImmutableSet<JobStatusEnum> jobFinishedStates = + ImmutableSet.of(FINISHED, ERROR, FINISHED_WITH_ERROR, IN_PROGRESS); + final ImmutablePair<String, JobStatusEnum> immutablePair = + waitForJobToFinish(newJob.getJobId(), jobFinishedStates); + + if (immutablePair.getRight() == null) { + final String message = "Failed to Instantiate NS for request: \n" + instantiateNsRequest; + logger.error(message); + throw new NsRequestProcessingException(message); + } + + final JobStatusEnum finalJobStatus = immutablePair.getRight(); + + if (IN_PROGRESS.equals(finalJobStatus) || FINISHED.equals(finalJobStatus)) { + logger.info("Instantiation Job status: {}", finalJobStatus); + + + return newNsLcmOpOcc.getId(); + } + + final String message = "Received unexpected Job Status: " + finalJobStatus + + " Failed to instantiate NS for request: \n" + instantiateNsRequest; + logger.error(message); + throw new NsRequestProcessingException(message); + } + + private ImmutablePair<String, JobStatusEnum> waitForJobToFinish(final String jobId, + final ImmutableSet<JobStatusEnum> jobFinishedStates) { + try { + final long startTimeInMillis = System.currentTimeMillis(); + final long timeOutTime = startTimeInMillis + TimeUnit.SECONDS.toMillis(timeOutInSeconds); + + logger.info("Will wait till {} for {} job to finish", Instant.ofEpochMilli(timeOutTime).toString(), jobId); + JobStatusEnum currentJobStatus = null; + while (timeOutTime > System.currentTimeMillis()) { + + final Optional<NfvoJob> optional = databaseServiceProvider.getJob(jobId); + + if (optional.isEmpty()) { + logger.error("Unable to find Job using jobId: {}", jobId); + return ImmutablePair.nullPair(); + } + + final NfvoJob nfvoJob = optional.get(); + currentJobStatus = nfvoJob.getStatus(); + logger.debug("Received job status response: \n ", nfvoJob); + if (jobFinishedStates.contains(nfvoJob.getStatus())) { + logger.info("Job finished \n {}", currentJobStatus); + return ImmutablePair.of(nfvoJob.getProcessInstanceId(), currentJobStatus); + } + + logger.debug("Haven't received one of finish state {} yet, will try again in {} seconds", + jobFinishedStates, SLEEP_TIME_IN_SECONDS); + TimeUnit.SECONDS.sleep(SLEEP_TIME_IN_SECONDS); + + } + logger.warn("Timeout current job status: {}", currentJobStatus); + return ImmutablePair.nullPair(); + } catch (final InterruptedException interruptedException) { + Thread.currentThread().interrupt(); + logger.error("Sleep was interrupted", interruptedException); + return ImmutablePair.nullPair(); + } + } + + private Map<String, Object> getVariables(final String jobId, final CreateNsRequest createNsRequest, + final String globalCustomerId, final String serviceType) { + final Map<String, Object> variables = new HashMap<>(); + variables.put(JOB_ID_PARAM_NAME, jobId); + variables.put(CREATE_NS_REQUEST_PARAM_NAME, createNsRequest); + variables.put(GLOBAL_CUSTOMER_ID_PARAM_NAME, globalCustomerId); + variables.put(SERVICE_TYPE_PARAM_NAME, serviceType); + return variables; + } + + private Map<String, Object> getVariables(final String nsInstanceId, final String jobId, final String occId, + final InstantiateNsRequest instantiateNsRequest) { + final Map<String, Object> variables = new HashMap<>(); + variables.put(NS_INSTANCE_ID_PARAM_NAME, nsInstanceId); + variables.put(JOB_ID_PARAM_NAME, jobId); + variables.put(OCC_ID_PARAM_NAME, occId); + variables.put(INSTANTIATE_NS_REQUEST_PARAM_NAME, instantiateNsRequest); + 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/WorkflowExecutorService.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/WorkflowExecutorService.java new file mode 100644 index 0000000000..fa2b8d5507 --- /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/service/WorkflowExecutorService.java @@ -0,0 +1,59 @@ +/*- + * ============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.service; + +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.Constants.TENANT_ID; +import static org.slf4j.LoggerFactory.getLogger; +import java.util.Map; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class WorkflowExecutorService { + + private static final Logger logger = getLogger(WorkflowExecutorService.class); + + private final RuntimeService runtimeService; + + @Autowired + public WorkflowExecutorService(final RuntimeService runtimeService) { + this.runtimeService = runtimeService; + } + + @Async + public void executeWorkflow(final String jobId, final String processDefinitionKey, + final Map<String, Object> variables) { + logger.info("Executing {} workflow with business key: {}", processDefinitionKey, jobId); + final ProcessInstance processInstance = runtimeService.createProcessInstanceByKey(processDefinitionKey) + .businessKey(jobId).setVariables(variables).processDefinitionTenantId(TENANT_ID).execute(); + + logger.info("Workflow running with processInstanceId: {} and business key: {}", + processInstance.getProcessInstanceId(), processInstance.getBusinessKey()); + } + +} 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 new file mode 100644 index 0000000000..297e9c34af --- /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/service/WorkflowQueryService.java @@ -0,0 +1,108 @@ +/*- + * ============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.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.Constants.TENANT_ID; +import static org.slf4j.LoggerFactory.getLogger; +import java.util.Optional; +import org.camunda.bpm.engine.HistoryService; +import org.camunda.bpm.engine.ProcessEngineException; +import org.camunda.bpm.engine.history.HistoricVariableInstance; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.google.common.base.Strings; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class WorkflowQueryService { + + private static final Logger logger = getLogger(WorkflowQueryService.class); + + private final HistoryService camundaHistoryService; + + @Autowired + public WorkflowQueryService(final HistoryService camundaHistoryService) { + this.camundaHistoryService = camundaHistoryService; + } + + public Optional<NsInstancesNsInstance> getCreateNsResponse(final String processInstanceId) { + try { + + if (Strings.isNullOrEmpty(processInstanceId)) { + logger.error("Invalid processInstanceId: {}", processInstanceId); + return Optional.empty(); + } + + final HistoricVariableInstance historicVariableInstance = + getVariable(processInstanceId, CREATE_NS_RESPONSE_PARAM_NAME); + + if (historicVariableInstance != null) { + logger.info("Found HistoricVariableInstance : {}", historicVariableInstance); + final Object variableValue = historicVariableInstance.getValue(); + if (variableValue instanceof NsInstancesNsInstance) { + return Optional.ofNullable((NsInstancesNsInstance) variableValue); + } + logger.error("Unknown CreateNsResponse object type {} received value: {}", + historicVariableInstance.getValue() != null ? variableValue.getClass() : null, variableValue); + } + } catch (final ProcessEngineException processEngineException) { + logger.error("Unable to find {} variable using processInstanceId: {}", CREATE_NS_RESPONSE_PARAM_NAME, + processInstanceId, processEngineException); + } + logger.error("Unable to find {} variable using processInstanceId: {}", CREATE_NS_RESPONSE_PARAM_NAME, + processInstanceId); + return Optional.empty(); + + } + + public Optional<InlineResponse400> getProblemDetails(final String processInstanceId) { + try { + final HistoricVariableInstance historicVariableInstance = + getVariable(processInstanceId, CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + + logger.info("Found HistoricVariableInstance : {}", historicVariableInstance); + final Object variableValue = historicVariableInstance.getValue(); + if (variableValue instanceof InlineResponse400) { + return Optional.ofNullable((InlineResponse400) variableValue); + } + logger.error("Unknown ProblemDetails object type {} received value: {}", + 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); + } + return Optional.empty(); + } + + + private HistoricVariableInstance getVariable(final String processInstanceId, final String name) { + return camundaHistoryService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId) + .variableName(name).tenantIdIn(TENANT_ID).singleResult(); + } + +} 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 new file mode 100644 index 0000000000..99116dacad --- /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/AbstractNetworkServiceTask.java @@ -0,0 +1,117 @@ +/*- + * ============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 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.JOB_ID_PARAM_NAME; +import java.time.LocalDateTime; +import java.util.Optional; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; +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.service.DatabaseServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public abstract class AbstractNetworkServiceTask { + private final Logger logger = LoggerFactory.getLogger(getClass()); + protected final DatabaseServiceProvider databaseServiceProvider; + + public AbstractNetworkServiceTask(final DatabaseServiceProvider jobServiceProvider) { + this.databaseServiceProvider = jobServiceProvider; + } + + public void setJobStatus(final DelegateExecution execution, final JobStatusEnum jobStatus, + final String description) { + logger.info("Setting Job Status to {}", jobStatus); + final NfvoJob nfvoJob = getNfvoJob(execution); + nfvoJob.status(jobStatus); + if (JobStatusEnum.STARTED.equals(jobStatus)) { + nfvoJob.processInstanceId(execution.getProcessInstanceId()); + } + + if (JobStatusEnum.FINISHED.equals(jobStatus)) { + nfvoJob.endTime(LocalDateTime.now()); + } + + nfvoJob.nfvoJobStatus( + new NfvoJobStatus().status(jobStatus).description(description).updatedTime(LocalDateTime.now())); + databaseServiceProvider.addJob(nfvoJob); + + } + + public void setJobStatusToError(final DelegateExecution execution, final String description) { + logger.info("Setting Job Status to {}", JobStatusEnum.ERROR); + + final String jobId = (String) execution.getVariable(JOB_ID_PARAM_NAME); + final Optional<NfvoJob> optional = databaseServiceProvider.getJob(jobId); + if (optional.isPresent()) { + final InlineResponse400 problemDetails = + (InlineResponse400) execution.getVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + + final NfvoJob nfvoJob = optional.get(); + nfvoJob.status(JobStatusEnum.ERROR).endTime(LocalDateTime.now()); + + if (problemDetails != null) { + logger.error("Found failed reason: {}", problemDetails); + nfvoJob.nfvoJobStatus(new NfvoJobStatus().status(JobStatusEnum.ERROR) + .description(problemDetails.getDetail()).updatedTime(LocalDateTime.now())); + } + nfvoJob.nfvoJobStatus(new NfvoJobStatus().status(JobStatusEnum.ERROR).description(description) + .updatedTime(LocalDateTime.now())); + + databaseServiceProvider.addJob(nfvoJob); + } + logger.info("Finished setting Job Status to {}", JobStatusEnum.ERROR); + + } + + protected void abortOperation(final DelegateExecution execution, final String message) { + abortOperation(execution, message, new InlineResponse400().detail(message)); + } + + 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); + throw new BpmnError("WORKFLOW_FAILED"); + } + + private NfvoJob getNfvoJob(final DelegateExecution execution) { + final String jobId = (String) execution.getVariable(JOB_ID_PARAM_NAME); + final Optional<NfvoJob> optional = databaseServiceProvider.getJob(jobId); + if (!optional.isPresent()) { + 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)); + throw new BpmnError("WORKFLOW_FAILED"); + + } + return 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/CreateInstantiateRequest.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/CreateInstantiateRequest.java new file mode 100644 index 0000000000..569d9b3352 --- /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/CreateInstantiateRequest.java @@ -0,0 +1,167 @@ +/*- + * ============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 static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.io.Serializable; +import java.util.Map; +import java.util.Objects; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.Tenant; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class CreateInstantiateRequest implements Serializable { + private static final long serialVersionUID = -4371264952509580468L; + private String nsInstId; + private String vnfdId; + private String vnfName; + private String vnfPkgId; + private String nfType; + private Tenant tenant; + private Map<String, String> additionalParams; + + public String getNsInstId() { + return nsInstId; + } + + public void setNsInstId(final String nsInstId) { + this.nsInstId = nsInstId; + } + + public CreateInstantiateRequest nsInstId(final String nsInstId) { + this.nsInstId = nsInstId; + return this; + } + + public final String getVnfdId() { + return vnfdId; + } + + public final void setVnfdId(final String vnfdId) { + this.vnfdId = vnfdId; + } + + public CreateInstantiateRequest vnfdId(final String vnfdId) { + this.vnfdId = vnfdId; + return this; + } + + public final String getVnfName() { + return vnfName; + } + + public final void setVnfName(final String vnfName) { + this.vnfName = vnfName; + } + + public CreateInstantiateRequest vnfName(final String vnfName) { + this.vnfName = vnfName; + return this; + } + + public final String getVnfPkgId() { + return vnfPkgId; + } + + public final void setVnfPkgId(final String vnfPkgId) { + this.vnfPkgId = vnfPkgId; + } + + public CreateInstantiateRequest vnfPkgId(final String vnfPkgId) { + this.vnfPkgId = vnfPkgId; + return this; + } + + public final String getNfType() { + return nfType; + } + + public final void setNfType(final String nfType) { + this.nfType = nfType; + } + + public CreateInstantiateRequest nfType(final String nfType) { + this.nfType = nfType; + return this; + } + + public final Tenant getTenant() { + return tenant; + } + + public final void setTenant(final Tenant tenant) { + this.tenant = tenant; + } + + public CreateInstantiateRequest tenant(final Tenant tenant) { + this.tenant = tenant; + return this; + } + + public final Map<String, String> getAdditionalParams() { + return additionalParams; + } + + public final void setAdditionalParams(final Map<String, String> additionalParams) { + this.additionalParams = additionalParams; + } + + public CreateInstantiateRequest additionalParams(final Map<String, String> additionalParams) { + this.additionalParams = additionalParams; + return this; + } + + @Override + public int hashCode() { + return Objects.hash(nsInstId, vnfdId, vnfName, vnfPkgId, nfType, tenant, additionalParams); + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof CreateInstantiateRequest) { + final CreateInstantiateRequest other = (CreateInstantiateRequest) obj; + return Objects.equals(nsInstId, other.nsInstId) && Objects.equals(vnfdId, other.vnfdId) + && Objects.equals(vnfName, other.vnfName) && Objects.equals(vnfPkgId, other.vnfPkgId) + && Objects.equals(nfType, other.nfType) && Objects.equals(tenant, other.tenant) + && Objects.equals(additionalParams, other.additionalParams); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class CreateInstantiateRequest {\n"); + sb.append(" nsInstId: ").append(toIndentedString(nsInstId)).append("\n"); + sb.append(" vnfdId: ").append(toIndentedString(vnfdId)).append("\n"); + sb.append(" vnfName: ").append(toIndentedString(vnfName)).append("\n"); + sb.append(" vnfPkgId: ").append(toIndentedString(vnfPkgId)).append("\n"); + sb.append(" nfType: ").append(toIndentedString(nfType)).append("\n"); + sb.append(" tenant: ").append(toIndentedString(tenant)).append("\n"); + sb.append(" additionalParams: ").append(toIndentedString(additionalParams)).append("\n"); + + sb.append("}"); + return sb.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/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 new file mode 100644 index 0000000000..c33c67e540 --- /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/CreateInstantiateVnfTask.java @@ -0,0 +1,234 @@ +/*- + * ============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 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.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.time.LocalDateTime; +import java.util.Optional; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.aai.domain.yang.GenericVnf; +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.Tenant; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; +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; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + */ +@Component +public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { + 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"; + private final AaiServiceProvider aaiServiceProvider; + private final Sol003AdapterServiceProvider sol003AdapterServiceProvider; + + @Autowired + public CreateInstantiateVnfTask(final DatabaseServiceProvider databaseServiceProvider, + final AaiServiceProvider aaiServiceProvider, + final Sol003AdapterServiceProvider sol003AdapterServiceProvider) { + super(databaseServiceProvider); + this.aaiServiceProvider = aaiServiceProvider; + this.sol003AdapterServiceProvider = sol003AdapterServiceProvider; + } + + public void checkIfNfInstanceExistsInDb(final DelegateExecution execution) { + logger.info("Executing checkIfNfInstanceInDb"); + final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + logger.info("request: {}", request); + + setJobStatus(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, + request.getNsInstId() + " " + request.getVnfName() + " VNF instance already exists"); + } + logger.info("Finished executing checkIfNfInstanceInDb ..."); + + } + + public void createNfInstanceInDb(final DelegateExecution execution) { + logger.info("Executing createNfInstanceInDb"); + final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + logger.info("request: {}", request); + + setJobStatus(execution, IN_PROGRESS, "Creating NF Instance record in database for " + request.getVnfName()); + + final Optional<NfvoNsInst> optional = databaseServiceProvider.getNfvoNsInst(request.getNsInstId()); + + if (optional.isEmpty()) { + abortOperation(execution, "NfvoNsInst: " + request.getNsInstId() + "not founda"); + } + + final NfvoNsInst nfvoNsInst = optional.get(); + final LocalDateTime now = LocalDateTime.now(); + final NfvoNfInst nfvoNfInst = new NfvoNfInst().status(State.NOT_INSTANTIATED).createTime(now) + .lastUpdateTime(now).name(request.getVnfName()).vnfdId(request.getVnfdId()) + .packageId(request.getVnfPkgId()).nfvoNsInst(nfvoNsInst); + databaseServiceProvider.saveNfvoNfInst(nfvoNfInst); + execution.setVariable(NF_INST_ID_PARAM_NAME, nfvoNfInst.getNfInstId()); + logger.info("Finished executing createNfInstanceInDb ..."); + + } + + public void createGenericVnfInAai(final DelegateExecution execution) { + logger.info("Executing createGenericVnfInAai"); + try { + final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + + setJobStatus(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); + final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution, nsInstId); + + final GenericVnf genericVnf = new GenericVnf(); + genericVnf.setVnfId(nfInstId); + genericVnf.setVnfName(request.getVnfName()); + genericVnf.setVnfType(nfvoNsInst.getName() + "/" + request.getVnfName()); + genericVnf.setServiceId(request.getNsInstId()); + genericVnf.setNfType(request.getNfType()); + genericVnf.setOperationalStatus("Created"); + genericVnf.setIsClosedLoopDisabled(false); + + aaiServiceProvider.createGenericVnfAndConnectServiceInstance(nsInstId, nfInstId, genericVnf); + + final Tenant tenant = request.getTenant(); + aaiServiceProvider.connectGenericVnfToTenant(nfInstId, tenant.getCloudOwner(), tenant.getRegionName(), + tenant.getTenantId()); + + } catch (final Exception exception) { + final String message = "Unable to Create GenericVnf in AAI"; + logger.error(message, exception); + abortOperation(execution, message); + } + + logger.info("Finished executing createGenericVnfInAai ..."); + } + + public void invokeCreateInstantiationRequest(final DelegateExecution execution) { + logger.info("Executing invokeCreateInstantiationRequest"); + + try { + final CreateInstantiateRequest request = (CreateInstantiateRequest) execution.getVariable("request"); + logger.info("request: {}", request); + + setJobStatus(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.setPkgId(request.getVnfPkgId()); + vnfRequest.setAdditionalParams(request.getAdditionalParams()); + final String vnfId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME); + final Optional<CreateVnfResponse> optional = + sol003AdapterServiceProvider.invokeCreateInstantiationRequest(vnfId, vnfRequest); + + if (!optional.isPresent()) { + final String errorMessage = "Unexpected error while processing create and instantiation request"; + logger.error(errorMessage); + abortOperation(execution, errorMessage); + } + + final CreateVnfResponse vnfResponse = optional.get(); + + 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: " + + request.getVnfName() + " CreaetVnfResponse Job Id: " + vnfResponse.getJobId()); + logger.debug("Finished executing invokeCreateInstantiationRequest ..."); + } catch (final Exception exception) { + final String message = "Unable to invoke create and instantiation request"; + logger.error(message, exception); + abortOperation(execution, message); + } + + } + + public void updateNfInstanceStatusToInstantiated(final DelegateExecution execution) { + 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() + + " will set status to " + State.INSTANTIATED); + + logger.info("Finished executing updateNfInstanceStatusToInstantiated ..."); + + } + + public void updateNfInstanceStatusToFailed(final DelegateExecution execution) { + 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() + + " will set status to " + State.FAILED); + + logger.info("Finished executing updateNfInstanceStatusToInstantiated ..."); + + } + + 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()) { + final String message = "Unable to find NfvoNfInst record in database using nfInstId: " + nfInstId; + logger.error(message); + + abortOperation(execution, message); + + } + + final NfvoNfInst nfvoNfInst = optional.get(); + nfvoNfInst.setStatus(vnfStatus); + databaseServiceProvider.saveNfvoNfInst(nfvoNfInst); + } + + private NfvoNsInst getNfvoNsInst(final DelegateExecution execution, final String nsInstId) { + logger.info("Getting NfvoNsInst to update with nsInstId: {}", nsInstId); + final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstId); + + if (!optionalNfvoNsInst.isPresent()) { + final String message = "Unable to find NS Instance in datababse using id: " + nsInstId; + abortOperation(execution, message); + } + + return optionalNfvoNsInst.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 new file mode 100644 index 0000000000..fa7187b388 --- /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/CreateNsTask.java @@ -0,0 +1,221 @@ +/*- + * ============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 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.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; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.SERVICE_TYPE_PARAM_NAME; +import java.time.LocalDateTime; +import java.util.Optional; +import java.util.UUID; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.EtsiCatalogManagerRequestFailureException; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.etsicatalog.EtsiCatalogPackageManagementServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; +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.CreateNsRequest; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance.NsStateEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Component +public class CreateNsTask extends AbstractNetworkServiceTask { + private static final String NETWORK_SERVICE_NAME = "NetworkService"; + private static final String NETWORK_SERVICE_ROLE = "NetworkService"; + private static final String DOES_NS_PACKAGE_EXISTS_PARAM_NAME = "doesNsPackageExists"; + private static final String DOES_NS_INSTANCE_EXISTS_PARAM_NAME = "doesNsInstanceExists"; + private static final Logger logger = LoggerFactory.getLogger(CreateNsTask.class); + private final EtsiCatalogPackageManagementServiceProvider etsiCatalogPackageManagementServiceProvider; + private final AaiServiceProvider aaiServiceProvider; + + @Autowired + public CreateNsTask(final DatabaseServiceProvider databaseServiceProvider, + final AaiServiceProvider aaiServiceProvider, + final EtsiCatalogPackageManagementServiceProvider etsiCatalogPackageManagementServiceProvider) { + super(databaseServiceProvider); + this.aaiServiceProvider = aaiServiceProvider; + this.etsiCatalogPackageManagementServiceProvider = etsiCatalogPackageManagementServiceProvider; + } + + public void setJobStatusToStarted(final DelegateExecution execution) { + setJobStatus(execution, JobStatusEnum.STARTED, "Create NS workflow process started"); + } + + public void setJobStatusToFinished(final DelegateExecution execution) { + setJobStatus(execution, JobStatusEnum.FINISHED, "Create NS workflow process finished"); + } + + public void setJobStatusToError(final DelegateExecution execution) { + setJobStatusToError(execution, "Create NS workflow process failed"); + } + + public void getNsPackage(final DelegateExecution execution) { + logger.info("Retrieving NS package from ETSI Catalog Manager ..."); + setJobStatus(execution, JobStatusEnum.IN_PROGRESS, "Retrieving NS package from ETSI Catalog Manager"); + + final CreateNsRequest createNsRequest = (CreateNsRequest) execution.getVariable(CREATE_NS_REQUEST_PARAM_NAME); + + try { + final Optional<NsdInfo> optional = + etsiCatalogPackageManagementServiceProvider.getNSPackageModel(createNsRequest.getNsdId()); + + if (optional.isPresent()) { + final NsdInfo packageModel = optional.get(); + logger.info("NS Package exists {}", packageModel); + execution.setVariable(NS_PACKAGE_MODEL_PARAM_NAME, packageModel); + execution.setVariable(DOES_NS_PACKAGE_EXISTS_PARAM_NAME, true); + } else { + 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, + new InlineResponse400().detail(message)); + } + + } catch (final EtsiCatalogManagerRequestFailureException failureException) { + final String message = + "Unexpected exception occured while getting ns package using nsdId: " + createNsRequest.getNsdId(); + logger.error(message, failureException); + + execution.setVariable(DOES_NS_PACKAGE_EXISTS_PARAM_NAME, false); + + execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, + new InlineResponse400().title(message).detail(message)); + } + + } + + public void doesNsInstanceExistsInDb(final DelegateExecution execution) { + logger.info("Executing doesNsInstanceExistsInDb ..."); + + setJobStatus(execution, JobStatusEnum.IN_PROGRESS, "Checking if NS package exists in database"); + + final CreateNsRequest createNsRequest = + (CreateNsRequest) execution.getVariables().get(CREATE_NS_REQUEST_PARAM_NAME); + + final boolean exists = databaseServiceProvider.isNsInstExists(createNsRequest.getNsName()); + logger.info("Ns Instance entry {} exists in database", exists ? "does" : "doesn't"); + execution.setVariable(DOES_NS_INSTANCE_EXISTS_PARAM_NAME, exists); + + if (exists) { + final Optional<NfvoNsInst> optional = + databaseServiceProvider.getNfvoNsInstByName(createNsRequest.getNsName()); + final NfvoNsInst nfvoNsInst = optional.get(); + execution.setVariable(CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME, new InlineResponse400() + .detail("Ns Instance already exists in database : " + nfvoNsInst.toString())); + } + + logger.info("Finished executing doesNsInstanceExistsInDb ..."); + + } + + public void createNsInstanceInDb(final DelegateExecution execution) { + logger.info("Executing createNsInstanceInDb ..."); + + setJobStatus(execution, JobStatusEnum.IN_PROGRESS, "Checking if NS package exists"); + + final CreateNsRequest createNsRequest = (CreateNsRequest) execution.getVariable(CREATE_NS_REQUEST_PARAM_NAME); + final NsdInfo packageMode = (NsdInfo) execution.getVariable(NS_PACKAGE_MODEL_PARAM_NAME); + + final String globalCustomerId = (String) execution.getVariable(GLOBAL_CUSTOMER_ID_PARAM_NAME); + final String serviceType = (String) execution.getVariable(SERVICE_TYPE_PARAM_NAME); + + final String nsInstId = UUID.randomUUID().toString(); + execution.setVariable(NS_INSTANCE_ID_PARAM_NAME, nsInstId); + + databaseServiceProvider.saveNfvoNsInst(new NfvoNsInst().nsInstId(nsInstId).name(createNsRequest.getNsName()) + .nsPackageId(packageMode.getId()).nsdId(packageMode.getNsdId()) + .nsdInvariantId(packageMode.getNsdInvariantId()).description(createNsRequest.getNsDescription()) + .status(State.NOT_INSTANTIATED).statusUpdatedTime(LocalDateTime.now()) + .globalCustomerId(globalCustomerId).serviceType(serviceType)); + logger.info("Finished executing createNsInstanceInDb ..."); + + } + + + public void createNsInstanceInAai(final DelegateExecution execution) { + logger.info("Executing createNsInstanceInAai ..."); + try { + setJobStatus(execution, JobStatusEnum.IN_PROGRESS, "Creating NS Instance in AAI"); + + final CreateNsRequest createNsRequest = + (CreateNsRequest) execution.getVariable(CREATE_NS_REQUEST_PARAM_NAME); + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + + final String globalCustomerId = (String) execution.getVariable(GLOBAL_CUSTOMER_ID_PARAM_NAME); + final String serviceType = (String) execution.getVariable(SERVICE_TYPE_PARAM_NAME); + + final ServiceInstance aaiServiceInstance = new ServiceInstance(); + aaiServiceInstance.setServiceInstanceId(nsInstId); + aaiServiceInstance.setServiceInstanceName(createNsRequest.getNsName()); + aaiServiceInstance.setServiceType(NETWORK_SERVICE_NAME); + aaiServiceInstance.setServiceRole(NETWORK_SERVICE_ROLE); + + aaiServiceProvider.createServiceInstance(globalCustomerId, serviceType, aaiServiceInstance); + } catch (final Exception exception) { + final String message = "Unable to Create Service Instance in AAI"; + logger.error(message, exception); + abortOperation(execution, message, new InlineResponse400().detail(message)); + } + logger.info("Finished executing createNsInstanceInAai ..."); + + } + + public void setCreateNsResponse(final DelegateExecution execution) { + logger.info("Executing setCreateNsResponse ..."); + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + final Optional<NfvoNsInst> optional = databaseServiceProvider.getNfvoNsInst(nsInstId); + + if (optional.isPresent()) { + final NfvoNsInst nfvoNsInst = optional.get(); + final NsInstancesNsInstance response = new NsInstancesNsInstance().id(nfvoNsInst.getNsInstId()) + .nsInstanceName(nfvoNsInst.getName()).nsdId(nfvoNsInst.getNsdId()) + .nsdInfoId(nfvoNsInst.getNsPackageId()).nsInstanceDescription(nfvoNsInst.getDescription()) + .nsState(NsStateEnum.fromValue(nfvoNsInst.getStatus().toString())); + logger.info("Saving CreateNsResponse: {} in Execution ...", response); + execution.setVariable(CREATE_NS_RESPONSE_PARAM_NAME, response); + } else { + final String message = "Unable to find NS Instance in datababse using id: " + nsInstId; + logger.error(message); + abortOperation(execution, message); + } + + logger.info("Finished executing setCreateNsResponse ..."); + + } + +} 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 new file mode 100644 index 0000000000..8d212045ad --- /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/InstantiateNsTask.java @@ -0,0 +1,416 @@ +/*- + * ============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 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.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; +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.extclients.etsicatalog.EtsiCatalogPackageManagementServiceProvider; +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; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * + */ +@Component +public class InstantiateNsTask extends AbstractNetworkServiceTask { + + private static final String IS_NS_INSTANTIATION_SUCCESSFUL_PARAM_NAME = "isNsInstantiationSuccessful"; + private static final String VNFD_ID_TO_VNF_PKG_ID_MAPPING_PARAM_NAME = "vnfdIdToVnfPkgIdMapping"; + private static final Logger logger = LoggerFactory.getLogger(InstantiateNsTask.class); + private final EtsiCatalogPackageManagementServiceProvider etsiCatalogPackageManagementServiceProvider; + + @Autowired + public InstantiateNsTask(final DatabaseServiceProvider databaseServiceProvider, + final EtsiCatalogPackageManagementServiceProvider etsiCatalogPackageManagementServiceProvider) { + super(databaseServiceProvider); + this.etsiCatalogPackageManagementServiceProvider = etsiCatalogPackageManagementServiceProvider; + + } + + public void setJobStatusToStarted(final DelegateExecution execution) { + setJobStatus(execution, STARTED, "Instantiate NS workflow process started"); + } + + public void setJobStatusToFinished(final DelegateExecution execution) { + setJobStatus(execution, FINISHED, "Instantiate NS workflow process finished"); + } + + public void updateNsInstanceStatusToInstantiating(final DelegateExecution execution) { + logger.info("Executing updateNsInstanceStatusToInstantiating"); + setJobStatus(execution, IN_PROGRESS, "Updating NfvoNsInst Status to " + State.INSTANTIATING); + updateNsInstanceStatus(execution, State.INSTANTIATING); + + logger.info("Finished executing updateNsInstanceStatusToInstantiating ..."); + } + + + public void checkIfVnfInstantiationWasSuccessful(final DelegateExecution execution) { + logger.info("Executing checkIfVnfInstantiationWasSuccessful"); + + @SuppressWarnings("unchecked") + final List<CreateInstantiateRequest> requests = + (List<CreateInstantiateRequest>) execution.getVariable(VNF_CREATE_INSTANTIATE_REQUESTS); + + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + final List<NfvoNfInst> nfInstances = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInstId); + + if (nfInstances == null || nfInstances.isEmpty()) { + final String message = "Found empty nf instances"; + abortOperation(execution, message); + } + + if (requests.size() != nfInstances.size()) { + final String message = "Missing nf Instance. Request triggered: " + requests.size() + + " Nf Instace reqeust found in database " + nfInstances.size(); + abortOperation(execution, message); + } + + execution.setVariable(IS_NS_INSTANTIATION_SUCCESSFUL_PARAM_NAME, true); + + nfInstances.stream().forEach(instance -> { + if (!State.INSTANTIATED.equals(instance.getStatus())) { + logger.error("VNF : {} {} instantiation failed", instance.getNfInstId(), instance.getName()); + execution.setVariable(IS_NS_INSTANTIATION_SUCCESSFUL_PARAM_NAME, false); + } + }); + + logger.info("Finished executing checkIfVnfInstantiationWasSuccessful ..."); + } + + public void updateNsInstanceStatusToInstantiated(final DelegateExecution execution) { + logger.info("Executing updateNsInstanceStatusToInstantiated"); + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + setJobStatus(execution, FINISHED, "Successfully " + State.INSTANTIATED + " NS: " + nsInstId); + + updateNsInstanceStatus(execution, State.INSTANTIATED); + logger.info("Finished executing updateNsInstanceStatusToInstantiated ..."); + } + + public void getAndParseNsdFromEtsiCatalog(final DelegateExecution execution) { + logger.info("Executing getAndParseNsdFromEtsiCatalog"); + setJobStatus(execution, IN_PROGRESS, "Retrieving and parsing NSD from ETSI Catalog Manager"); + final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution); + final String nsPackageId = nfvoNsInst.getNsPackageId(); + + try { + final Optional<NetworkServiceDescriptor> optional = + etsiCatalogPackageManagementServiceProvider.getNetworkServiceDescriptor(nsPackageId); + + if (!optional.isPresent()) { + final String message = "Unable to parse NSD " + nsPackageId; + logger.error(message); + abortOperation(execution, message); + } + + final NetworkServiceDescriptor networkServiceDescriptor = optional.get(); + logger.info("Found {}", networkServiceDescriptor); + execution.setVariable(NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME, networkServiceDescriptor); + + } catch (final EtsiCatalogManagerRequestFailureException failureException) { + final String message = + "Unexpected exception occured while getting nsd content using nsPackageId: " + nsPackageId; + logger.error(message, failureException); + + abortOperation(execution, message); + } + + logger.info("Finished executing getAndParseNsdFromEtsiCatalog ..."); + + } + + public void prepareCreateInstantiateRequests(final DelegateExecution execution) { + logger.info("Executing prepareCreateInstantiateRequests ..."); + setJobStatus(execution, IN_PROGRESS, "Preparing VNF CreateInstantiate requests"); + final NetworkServiceDescriptor networkServiceDescriptor = + (NetworkServiceDescriptor) execution.getVariable(NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME); + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + + final InstantiateNsRequest instantiateNsRequest = + (InstantiateNsRequest) execution.getVariable(INSTANTIATE_NS_REQUEST_PARAM_NAME); + + final List<NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf> additionalParamsForVnfList = + instantiateNsRequest.getAdditionalParamsForVnf(); + + @SuppressWarnings("unchecked") + final Map<String, String> vnfdIdToVnfPkgIdMapping = + (Map<String, String>) execution.getVariable(VNFD_ID_TO_VNF_PKG_ID_MAPPING_PARAM_NAME); + + final List<CreateInstantiateRequest> requests = new ArrayList<>(); + + for (final VirtualNetworkFunction vnf : networkServiceDescriptor.getVnfs()) { + final List<String> vnfmInfoList = vnf.getVnfmInfoList(); + + final String vnfdId = vnf.getVnfdId(); + final String vnfPkgId = vnfdIdToVnfPkgIdMapping.get(vnfdId); + if (vnfdId == null || vnfmInfoList.isEmpty() || vnfPkgId == null) { + final String message = "Unable to find VnfdId/vnfmInfo/VnfPkgId for vnf: " + vnf; + abortOperation(execution, message); + } + + final Optional<Tenant> optional = getTenant(vnfPkgId, additionalParamsForVnfList); + if (!optional.isPresent()) { + 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)); + + logger.info("Adding request to list: {}", createInstantiateRequest); + requests.add(createInstantiateRequest); + + } + execution.setVariable(VNF_CREATE_INSTANTIATE_REQUESTS, requests); + + logger.info("Finished executing prepareCreateInstantiateRequests ..."); + } + + public void getVnfPkgIdForEachVnfdId(final DelegateExecution execution) { + logger.info("Executing getVnfPkgIdForEachVnfdId ..."); + + setJobStatus(execution, IN_PROGRESS, "Getting VnfPkgId for each VnfdId"); + + 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 { + for (final String vnfPkgId : nsdInfo.getVnfPkgIds()) { + final Optional<VnfPkgInfo> optional = + etsiCatalogPackageManagementServiceProvider.getVnfPkgInfo(vnfPkgId); + + if (!optional.isPresent()) { + final String message = "Unable to find VNF package using NS vnfPkgId: " + vnfPkgId; + logger.error(message); + abortOperation(execution, message); + } + final VnfPkgInfo vnfPkgInfo = optional.get(); + vnfdIdToVnfPkgIdMapping.put(vnfPkgInfo.getVnfdId(), vnfPkgId); + + } + logger.info("vnfdIdToVnfPkgIdMapping: {}", vnfdIdToVnfPkgIdMapping); + execution.setVariable(VNFD_ID_TO_VNF_PKG_ID_MAPPING_PARAM_NAME, vnfdIdToVnfPkgIdMapping); + + } catch (final EtsiCatalogManagerRequestFailureException failureException) { + final String message = + "Unexpected exception occured while getting VNF package using nsPackageId: " + nsPackageId; + logger.error(message, failureException); + + abortOperation(execution, message); + } + + logger.info("Finished executing getVnfPkgIdForEachVnfdId ..."); + + } + + public void logTimeOut(final DelegateExecution execution) { + logger.error("Vnf instantiation timedOut ..."); + 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()); + }); + } + } + + public void setJobStatusToError(final DelegateExecution execution) { + updateNsInstanceStatus(execution, State.FAILED); + setJobStatusToError(execution, "Instantiate NS workflow process failed"); + } + + + public void updateNsLcmOpOccStatusToCompleted(final DelegateExecution execution) { + logger.info("Executing updateNsLcmOpOccStatusToCompleted ..."); + final String occId = (String) execution.getVariable(OCC_ID_PARAM_NAME); + + final Optional<NsLcmOpOcc> optional = databaseServiceProvider.getNsLcmOpOcc(occId); + + if (!optional.isPresent()) { + final String message = "Unable to find record for NSLcmOpOcc in database using id: " + occId; + logger.error(message); + abortOperation(execution, message); + } + + final NsLcmOpOcc nsLcmOpOcc = optional.get(); + final OperationStateEnum operationStateCompleted = OperationStateEnum.COMPLETED; + logger.info("Setting operation state to {} for id: {}", operationStateCompleted, occId); + nsLcmOpOcc.setOperationState(operationStateCompleted); + databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc); + + logger.info("Finished executing updateNsLcmOpOccStatusToCompleted ..."); + + } + + public void updateNsLcmOpOccStatusToFailed(final DelegateExecution execution) { + logger.info("Executing updateNsLcmOpOccStatusToFailed ..."); + final String occId = (String) execution.getVariable(OCC_ID_PARAM_NAME); + + final Optional<NsLcmOpOcc> optional = databaseServiceProvider.getNsLcmOpOcc(occId); + + if (optional.isPresent()) { + final NsLcmOpOcc nsLcmOpOcc = optional.get(); + final OperationStateEnum operationStateFailed = OperationStateEnum.FAILED; + logger.info("Setting operation state to {} for id: {}", operationStateFailed, occId); + nsLcmOpOcc.setOperationState(operationStateFailed); + + databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc); + } else { + logger.error("Unable to find record for NSLcmOpOcc in database using id: {}", occId); + } + + logger.info("Finished executing updateNsLcmOpOccStatusToFailed ..."); + + } + + 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; + } + + } 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); + return Optional.empty(); + } + + @SuppressWarnings("unchecked") + private Map<String, String> getAdditionalParams(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(); + if (additionalParamsForVnf instanceof Map) { + logger.info("Found AdditionalParams in instantiateNsRequest using vnfPkgId: {}", vnfPkgId); + return (Map<String, String>) additionalParamsForVnf.getAdditionalParams(); + } + } + + return Collections.emptyMap(); + + } + + private NfvoNsInst getNfvoNsInst(final DelegateExecution execution) { + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + return getNfvoNsInst(execution, nsInstId); + } + + private NfvoNsInst getNfvoNsInst(final DelegateExecution execution, final String nsInstId) { + logger.info("Getting NfvoNsInst to update with nsInstId: {}", nsInstId); + final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsInstId); + + if (!optionalNfvoNsInst.isPresent()) { + final String message = "Unable to find NS Instance in database using id: " + nsInstId; + abortOperation(execution, message); + } + + return optionalNfvoNsInst.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/MonitorInstantiateSol003AdapterNodeTask.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/MonitorInstantiateSol003AdapterNodeTask.java new file mode 100644 index 0000000000..51fa6b9381 --- /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/MonitorInstantiateSol003AdapterNodeTask.java @@ -0,0 +1,52 @@ +/*- + * ============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.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Component +public class MonitorInstantiateSol003AdapterNodeTask extends MonitorSol003AdapterNodeTask { + public static final String CREATE_VNF_NODE_STATUS = "createVnfNodeStatus"; + public static final String VNF_CREATED = "Created"; + + @Autowired + public MonitorInstantiateSol003AdapterNodeTask(final DatabaseServiceProvider databaseServiceProvider, + final AaiServiceProvider aaiServiceProvider) { + super(databaseServiceProvider, aaiServiceProvider); + } + + @Override + public String getNodeStatusVariableName() { + return CREATE_VNF_NODE_STATUS; + } + + @Override + public boolean isOrchestrationStatusValid(final String orchestrationStatus) { + return VNF_CREATED.equalsIgnoreCase(orchestrationStatus); + } + +} 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/MonitorSol003AdapterCreateJobTask.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/MonitorSol003AdapterCreateJobTask.java new file mode 100644 index 0000000000..3c91598dfb --- /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/MonitorSol003AdapterCreateJobTask.java @@ -0,0 +1,105 @@ +/*- + * ============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 static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.CREATE_VNF_RESPONSE_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Component +public class MonitorSol003AdapterCreateJobTask extends MonitorSol003AdapterJobTask { + + private static final Logger LOGGER = LoggerFactory.getLogger(MonitorSol003AdapterCreateJobTask.class); + + @Autowired + public MonitorSol003AdapterCreateJobTask(final Sol003AdapterServiceProvider sol003AdapterServiceProvider, + final DatabaseServiceProvider databaseServiceProvider) { + super(sol003AdapterServiceProvider, databaseServiceProvider); + } + + public void getCurrentOperationStatus(final DelegateExecution execution) { + try { + LOGGER.debug("Executing getCurrentOperationStatus ..."); + final CreateVnfResponse vnfInstantiateResponse = + (CreateVnfResponse) execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME); + execution.setVariable(OPERATION_STATUS_PARAM_NAME, + getOperationStatus(execution, vnfInstantiateResponse.getJobId())); + LOGGER.debug("Finished executing getCurrentOperationStatus ..."); + } catch (final Exception exception) { + final String message = "Unable to invoke get current Operation status"; + LOGGER.error(message, exception); + abortOperation(execution, message); + + } + } + + /** + * Log and throw exception on timeout for job status + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void timeOutLogFailue(final DelegateExecution execution) { + final String message = "Instantiation operation time out"; + LOGGER.error(message); + abortOperation(execution, message); + } + + /** + * Check the final status of instantiation throw exception if not completed successfully + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void checkIfOperationWasSuccessful(final DelegateExecution execution) { + LOGGER.debug("Executing checkIfOperationWasSuccessful ..."); + final OperationStateEnum operationStatus = + (OperationStateEnum) execution.getVariable(OPERATION_STATUS_PARAM_NAME); + final CreateVnfResponse vnfInstantiateResponse = + (CreateVnfResponse) execution.getVariable(CREATE_VNF_RESPONSE_PARAM_NAME); + + if (operationStatus == null) { + final String message = "Unable to instantiate jobId: " + + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null") + + "Unable to retrieve OperationStatus"; + LOGGER.error(message); + abortOperation(execution, message); + } + if (operationStatus != OperationStateEnum.COMPLETED) { + final String message = "Unable to instantiate jobId: " + + (vnfInstantiateResponse != null ? vnfInstantiateResponse.getJobId() : "null") + + " OperationStatus: " + operationStatus; + LOGGER.error(message); + abortOperation(execution, message); + } + + LOGGER.debug("Successfully completed instatiation of job {}", vnfInstantiateResponse); + } +} 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/MonitorSol003AdapterJobTask.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/MonitorSol003AdapterJobTask.java new file mode 100644 index 0000000000..bac79dfa3e --- /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/MonitorSol003AdapterJobTask.java @@ -0,0 +1,96 @@ +/*- + * ============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 static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME; +import java.util.Optional; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStatusRetrievalStatusEnum; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.google.common.collect.ImmutableSet; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Component +public class MonitorSol003AdapterJobTask extends AbstractNetworkServiceTask { + + private static final Logger LOGGER = LoggerFactory.getLogger(MonitorSol003AdapterJobTask.class); + public static final ImmutableSet<OperationStateEnum> OPERATION_FINISHED_STATES = + ImmutableSet.of(OperationStateEnum.COMPLETED, OperationStateEnum.FAILED, OperationStateEnum.ROLLED_BACK); + public static final ImmutableSet<OperationStatusRetrievalStatusEnum> OPERATION_RETRIEVAL_STATES = ImmutableSet + .of(OperationStatusRetrievalStatusEnum.STATUS_FOUND, OperationStatusRetrievalStatusEnum.WAITING_FOR_STATUS); + protected final Sol003AdapterServiceProvider sol003AdapterServiceProvider; + + @Autowired + public MonitorSol003AdapterJobTask(final Sol003AdapterServiceProvider sol003AdapterServiceProvider, + final DatabaseServiceProvider databaseServiceProvider) { + super(databaseServiceProvider); + this.sol003AdapterServiceProvider = sol003AdapterServiceProvider; + } + + public boolean hasOperationFinished(final DelegateExecution execution) { + LOGGER.debug("Executing hasOperationFinished ..."); + + final OperationStateEnum operationStatus = + (OperationStateEnum) execution.getVariable(OPERATION_STATUS_PARAM_NAME); + if (operationStatus != null) { + return OPERATION_FINISHED_STATES.contains(operationStatus); + } + LOGGER.debug("OperationStatus is not present yet... "); + LOGGER.debug("Finished executing hasOperationFinished ..."); + return false; + } + + protected OperationStateEnum getOperationStatus(final DelegateExecution execution, final String jobId) { + + final Optional<QueryJobResponse> instantiateOperationJobStatus = + sol003AdapterServiceProvider.getInstantiateOperationJobStatus(jobId); + + if (instantiateOperationJobStatus.isPresent()) { + final QueryJobResponse queryJobResponse = instantiateOperationJobStatus.get(); + + if (!OPERATION_RETRIEVAL_STATES.contains(queryJobResponse.getOperationStatusRetrievalStatus())) { + final String message = "Received invalid operation retrieval state: " + + queryJobResponse.getOperationStatusRetrievalStatus(); + LOGGER.error(message); + abortOperation(execution, message); + } + if (queryJobResponse.getOperationState() != null) { + final OperationStateEnum operationStatus = queryJobResponse.getOperationState(); + LOGGER.debug("Operation {} with {} and operation retrieval status : {}", queryJobResponse.getId(), + operationStatus, queryJobResponse.getOperationStatusRetrievalStatus()); + return queryJobResponse.getOperationState(); + } + + LOGGER.debug("Operation {} without operationStatus and operation retrieval status :{}", + queryJobResponse.getId(), queryJobResponse.getOperationStatusRetrievalStatus()); + } + return null; + } +} 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 new file mode 100644 index 0000000000..e27e0c1579 --- /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/MonitorSol003AdapterNodeTask.java @@ -0,0 +1,92 @@ +/*- + * ============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 static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NF_INST_ID_PARAM_NAME; +import java.util.Optional; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.onap.aai.domain.yang.GenericVnf; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public abstract class MonitorSol003AdapterNodeTask extends AbstractNetworkServiceTask { + + private static final Logger LOGGER = LoggerFactory.getLogger(MonitorSol003AdapterNodeTask.class); + private final AaiServiceProvider aaiServiceProvider; + + public MonitorSol003AdapterNodeTask(final DatabaseServiceProvider databaseServiceProvider, + final AaiServiceProvider aaiServiceProvider) { + super(databaseServiceProvider); + this.aaiServiceProvider = aaiServiceProvider; + } + + /** + * Check the final status of vnf in A&AI + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void getNodeStatus(final DelegateExecution execution) { + try { + LOGGER.debug("Executing getNodeStatus ..."); + final String vnfId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME); + + LOGGER.debug("Query A&AI for generic VNF using vnfID: {}", vnfId); + final Optional<GenericVnf> aaiGenericVnfOptional = aaiServiceProvider.getGenericVnf(vnfId); + + if (!aaiGenericVnfOptional.isPresent()) { + abortOperation(execution, "Unable to invoke Sol003 adapter for create and instantiate vnfId" + vnfId); + } + final GenericVnf genericVnf = aaiGenericVnfOptional.get(); + final String orchestrationStatus = genericVnf.getOrchestrationStatus(); + LOGGER.debug("Found generic vnf with orchestration status : {}", orchestrationStatus); + + execution.setVariable(getNodeStatusVariableName(), isOrchestrationStatusValid(orchestrationStatus)); + + } catch (final Exception exception) { + LOGGER.error("Unable to get vnf from AAI", exception); + abortOperation(execution, "Unable to get vnf from AAI"); + } + } + + /** + * Get variable to store in execution context + * + * @return the variable name + */ + public abstract String getNodeStatusVariableName(); + + /** + * @param orchestrationStatus the orchestration status from A&AI + * @return true if valid + */ + public abstract boolean isOrchestrationStatusValid(final String orchestrationStatus); + + public void timeOutLogFailue(final DelegateExecution execution) { + final String message = "Node operation time out"; + LOGGER.error(message); + abortOperation(execution, message); + } +} 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 new file mode 100644 index 0000000000..34959ee0f0 --- /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/utils/LocalDateTimeTypeAdapter.java @@ -0,0 +1,58 @@ +/*- + * ============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.utils; + +import java.io.IOException; +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.JsonWriter; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class LocalDateTimeTypeAdapter extends TypeAdapter<LocalDateTime> { + + private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + + @Override + public void write(final JsonWriter out, final LocalDateTime localDateTime) throws IOException { + if (localDateTime == null) { + out.nullValue(); + } else { + out.value(FORMATTER.format(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); + } + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateInstantiateVnf.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateInstantiateVnf.bpmn new file mode 100644 index 0000000000..025faa4128 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateInstantiateVnf.bpmn @@ -0,0 +1,159 @@ +<?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" id="Definitions_1uf6nd9" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.0.0"> + <bpmn:process id="CreateInstantiateVnf" name="CreateInstantiateVnf" isExecutable="true"> + <bpmn:startEvent id="StartEvent_1"> + <bpmn:outgoing>Flow_02bjz2v</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:serviceTask id="Activity_19rmtjr" name="Create NF Instance (VNF) record in DB" camunda:expression="${CreateInstantiateVnfTask.createNfInstanceInDb(execution)}"> + <bpmn:incoming>Flow_123uagz</bpmn:incoming> + <bpmn:outgoing>Flow_03p6ifi</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_02bjz2v" sourceRef="StartEvent_1" targetRef="Activity_1cluqgp" /> + <bpmn:endEvent id="Event_14qdixj"> + <bpmn:incoming>Flow_0srinh7</bpmn:incoming> + </bpmn:endEvent> + <bpmn:sequenceFlow id="Flow_03p6ifi" sourceRef="Activity_19rmtjr" targetRef="Activity_0rto3n3" /> + <bpmn:serviceTask id="Activity_0rto3n3" name="Create Generic VNF and Connect to Service Instance in AAI" camunda:expression="${CreateInstantiateVnfTask.createGenericVnfInAai(execution)}"> + <bpmn:incoming>Flow_03p6ifi</bpmn:incoming> + <bpmn:outgoing>Flow_1c3kc4e</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_1c3kc4e" sourceRef="Activity_0rto3n3" targetRef="ServiceTask_0iry5yw" /> + <bpmn:serviceTask id="Activity_1cluqgp" name="Check If NF Instance (VNF) exists in DB" camunda:expression="${CreateInstantiateVnfTask.checkIfNfInstanceExistsInDb(execution)}"> + <bpmn:incoming>Flow_02bjz2v</bpmn:incoming> + <bpmn:outgoing>Flow_123uagz</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_123uagz" sourceRef="Activity_1cluqgp" targetRef="Activity_19rmtjr" /> + <bpmn:serviceTask id="ServiceTask_0iry5yw" name=" Invoke VNFM Adaptor " camunda:asyncAfter="true" camunda:expression="${CreateInstantiateVnfTask.invokeCreateInstantiationRequest(execution)}"> + <bpmn:incoming>Flow_1c3kc4e</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0xzptc2</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:callActivity id="CallActivity_1yilxx3" name="Monitor Sol003 adapter Instantiation Job" calledElement="MonitorSol003AdapterCreateJob"> + <bpmn:extensionElements> + <camunda:in source="createVnfResponse" target="createVnfResponse" /> + <camunda:in source="jobId" target="jobId" /> + </bpmn:extensionElements> + <bpmn:incoming>SequenceFlow_0xzptc2</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_053tvct</bpmn:outgoing> + </bpmn:callActivity> + <bpmn:callActivity id="CallActivity_0p84lpt" name="Monitor Sol003 adapter Create Node Status" calledElement="MonitorSol003AdapterCreateNodeStatus"> + <bpmn:extensionElements> + <camunda:in source="NF_INST_ID" target="NF_INST_ID" /> + <camunda:in source="createVnfResponse" target="createVnfResponse" /> + </bpmn:extensionElements> + <bpmn:incoming>SequenceFlow_053tvct</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0h7yluk</bpmn:outgoing> + </bpmn:callActivity> + <bpmn:sequenceFlow id="SequenceFlow_0xzptc2" sourceRef="ServiceTask_0iry5yw" targetRef="CallActivity_1yilxx3" /> + <bpmn:sequenceFlow id="SequenceFlow_053tvct" sourceRef="CallActivity_1yilxx3" targetRef="CallActivity_0p84lpt" /> + <bpmn:sequenceFlow id="SequenceFlow_0h7yluk" sourceRef="CallActivity_0p84lpt" targetRef="Activity_0g3dip7" /> + <bpmn:serviceTask id="Activity_0g3dip7" name="Update NF Instance (VNF) Status to INSTANTIATED" camunda:expression="${CreateInstantiateVnfTask.updateNfInstanceStatusToInstantiated(execution)}"> + <bpmn:incoming>SequenceFlow_0h7yluk</bpmn:incoming> + <bpmn:outgoing>Flow_0srinh7</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_0srinh7" sourceRef="Activity_0g3dip7" targetRef="Event_14qdixj" /> + <bpmn:subProcess id="Activity_0qtgdm9" name="Error Handling" triggeredByEvent="true"> + <bpmn:startEvent id="Event_08zcwc2" name="error"> + <bpmn:outgoing>Flow_06q1m6i</bpmn:outgoing> + <bpmn:errorEventDefinition id="ErrorEventDefinition_1ppvn77" /> + </bpmn:startEvent> + <bpmn:endEvent id="Event_1wkm29u" name="end"> + <bpmn:incoming>Flow_0anjylz</bpmn:incoming> + </bpmn:endEvent> + <bpmn:serviceTask id="Activity_0ltxcii" name="Update NF Instance (VNF) Status to FAILED" camunda:asyncBefore="true" camunda:expression="${CreateInstantiateVnfTask.updateNfInstanceStatusToFailed(execution)}"> + <bpmn:incoming>Flow_06q1m6i</bpmn:incoming> + <bpmn:outgoing>Flow_0anjylz</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_06q1m6i" sourceRef="Event_08zcwc2" targetRef="Activity_0ltxcii" /> + <bpmn:sequenceFlow id="Flow_0anjylz" sourceRef="Activity_0ltxcii" targetRef="Event_1wkm29u" /> + </bpmn:subProcess> + </bpmn:process> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CreateInstantiateVnf"> + <bpmndi:BPMNEdge id="SequenceFlow_0h7yluk_di" bpmnElement="SequenceFlow_0h7yluk"> + <di:waypoint x="1030" y="117" /> + <di:waypoint x="1080" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_053tvct_di" bpmnElement="SequenceFlow_053tvct"> + <di:waypoint x="880" y="117" /> + <di:waypoint x="930" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0xzptc2_di" bpmnElement="SequenceFlow_0xzptc2"> + <di:waypoint x="740" y="117" /> + <di:waypoint x="780" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_123uagz_di" bpmnElement="Flow_123uagz"> + <di:waypoint x="350" y="117" /> + <di:waypoint x="380" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1c3kc4e_di" bpmnElement="Flow_1c3kc4e"> + <di:waypoint x="610" y="117" /> + <di:waypoint x="640" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_03p6ifi_di" bpmnElement="Flow_03p6ifi"> + <di:waypoint x="480" y="117" /> + <di:waypoint x="510" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_02bjz2v_di" bpmnElement="Flow_02bjz2v"> + <di:waypoint x="215" y="117" /> + <di:waypoint x="250" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0srinh7_di" bpmnElement="Flow_0srinh7"> + <di:waypoint x="1180" y="117" /> + <di:waypoint x="1232" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="179" y="99" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_19rmtjr_di" bpmnElement="Activity_19rmtjr"> + <dc:Bounds x="380" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0rto3n3_di" bpmnElement="Activity_0rto3n3"> + <dc:Bounds x="510" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1cluqgp_di" bpmnElement="Activity_1cluqgp"> + <dc:Bounds x="250" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ServiceTask_0iry5yw_di" bpmnElement="ServiceTask_0iry5yw"> + <dc:Bounds x="640" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="CallActivity_1yilxx3_di" bpmnElement="CallActivity_1yilxx3"> + <dc:Bounds x="780" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="CallActivity_0p84lpt_di" bpmnElement="CallActivity_0p84lpt"> + <dc:Bounds x="930" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_14qdixj_di" bpmnElement="Event_14qdixj"> + <dc:Bounds x="1232" y="99" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0g3dip7_di" bpmnElement="Activity_0g3dip7"> + <dc:Bounds x="1080" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0qtgdm9_di" bpmnElement="Activity_0qtgdm9" isExpanded="true"> + <dc:Bounds x="430" y="270" width="438" height="130" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Flow_06q1m6i_di" bpmnElement="Flow_06q1m6i"> + <di:waypoint x="488" y="333" /> + <di:waypoint x="580" y="333" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0anjylz_di" bpmnElement="Flow_0anjylz"> + <di:waypoint x="680" y="333" /> + <di:waypoint x="812" y="333" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_08zcwc2_di" bpmnElement="Event_08zcwc2"> + <dc:Bounds x="452" y="315" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="458" y="358" width="24" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_1wkm29u_di" bpmnElement="Event_1wkm29u"> + <dc:Bounds x="812" y="315" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="822" y="357" width="19" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0ltxcii_di" bpmnElement="Activity_0ltxcii"> + <dc:Bounds x="580" y="293" width="100" height="80" /> + </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/CreateNs.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn new file mode 100644 index 0000000000..815b76c907 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/CreateNs.bpmn @@ -0,0 +1,266 @@ +<?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:process id="CreateNs" name=" CreateNs" 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="${CreateNsTask.setJobStatusToStarted(execution)}"> + <bpmn:incoming>Flow_1tqn5q5</bpmn:incoming> + <bpmn:outgoing>Flow_0y07mxe</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_0y07mxe" sourceRef="Activity_15ksfz6" targetRef="Activity_12yonzp" /> + <bpmn:serviceTask id="Activity_1r4l8w8" name="Set Job Status to FINISHED" camunda:expression="${CreateNsTask.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:exclusiveGateway id="Gateway_0fuwzjj" name="Does Ns Package exists?"> + <bpmn:incoming>Flow_09582uw</bpmn:incoming> + <bpmn:outgoing>Flow_1f4vi10</bpmn:outgoing> + <bpmn:outgoing>Flow_0qabgp7</bpmn:outgoing> + </bpmn:exclusiveGateway> + <bpmn:serviceTask id="Activity_12yonzp" name="Get Ns Package from ETSI Catalog Manager" camunda:expression="${CreateNsTask.getNsPackage(execution)}"> + <bpmn:incoming>Flow_0y07mxe</bpmn:incoming> + <bpmn:outgoing>Flow_09582uw</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_09582uw" sourceRef="Activity_12yonzp" targetRef="Gateway_0fuwzjj" /> + <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="${CreateNsTask.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_0s855yd" 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="${CreateNsTask.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:sequenceFlow id="Flow_1f4vi10" name="No" sourceRef="Gateway_0fuwzjj" targetRef="Event_016q8gu"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{not doesNsPackageExists}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:endEvent id="Event_016q8gu"> + <bpmn:incoming>Flow_1f4vi10</bpmn:incoming> + <bpmn:incoming>Flow_1yql1cm</bpmn:incoming> + <bpmn:errorEventDefinition id="ErrorEventDefinition_1ugx52k" errorRef="Error_0rqvnym" /> + </bpmn:endEvent> + <bpmn:sequenceFlow id="Flow_0qabgp7" name="Yes" sourceRef="Gateway_0fuwzjj" targetRef="Activity_0vlb2nk"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{doesNsPackageExists}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:serviceTask id="Activity_0vlb2nk" name="Check NS Instance exists In DB " camunda:expression="${CreateNsTask.doesNsInstanceExistsInDb(execution)}"> + <bpmn:incoming>Flow_0qabgp7</bpmn:incoming> + <bpmn:outgoing>Flow_1exrj2b</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_1exrj2b" sourceRef="Activity_0vlb2nk" targetRef="Gateway_0d7n517" /> + <bpmn:exclusiveGateway id="Gateway_0d7n517"> + <bpmn:incoming>Flow_1exrj2b</bpmn:incoming> + <bpmn:outgoing>Flow_1rkg44s</bpmn:outgoing> + <bpmn:outgoing>Flow_1yql1cm</bpmn:outgoing> + </bpmn:exclusiveGateway> + <bpmn:sequenceFlow id="Flow_1rkg44s" name="No" sourceRef="Gateway_0d7n517" targetRef="Activity_09tqz8x"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{not doesNsInstanceExists}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:sequenceFlow id="Flow_1yql1cm" name="Yes" sourceRef="Gateway_0d7n517" targetRef="Event_016q8gu"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{doesNsInstanceExists}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:serviceTask id="Activity_09tqz8x" name="Create NS Instance record in DB" camunda:expression="${CreateNsTask.createNsInstanceInDb(execution)}"> + <bpmn:incoming>Flow_1rkg44s</bpmn:incoming> + <bpmn:outgoing>Flow_1jvfwd2</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_1jvfwd2" sourceRef="Activity_09tqz8x" targetRef="Activity_1akc79d" /> + <bpmn:serviceTask id="Activity_1akc79d" name="Create NS Instance in AAI" camunda:expression="${CreateNsTask.createNsInstanceInAai(execution)}"> + <bpmn:incoming>Flow_1jvfwd2</bpmn:incoming> + <bpmn:outgoing>Flow_0e5hvno</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_0e5hvno" sourceRef="Activity_1akc79d" targetRef="Activity_03ht66t" /> + <bpmn:serviceTask id="Activity_03ht66t" name="Set Create NS Response" camunda:expression="${CreateNsTask.setCreateNsResponse(execution)}"> + <bpmn:incoming>Flow_0e5hvno</bpmn:incoming> + <bpmn:outgoing>Flow_1rtsvpm</bpmn:outgoing> + </bpmn:serviceTask> + <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" /> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="CreateNs"> + <bpmndi:BPMNEdge id="Flow_1rtsvpm_di" bpmnElement="Flow_1rtsvpm"> + <di:waypoint x="1160" y="157" /> + <di:waypoint x="1160" y="230" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0e5hvno_di" bpmnElement="Flow_0e5hvno"> + <di:waypoint x="1070" y="117" /> + <di:waypoint x="1110" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1jvfwd2_di" bpmnElement="Flow_1jvfwd2"> + <di:waypoint x="930" y="117" /> + <di:waypoint x="970" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1yql1cm_di" bpmnElement="Flow_1yql1cm"> + <di:waypoint x="760" y="142" /> + <di:waypoint x="760" y="230" /> + <di:waypoint x="668" y="230" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="766" y="183" width="19" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1rkg44s_di" bpmnElement="Flow_1rkg44s"> + <di:waypoint x="785" y="117" /> + <di:waypoint x="830" y="117" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="799" y="99" width="14" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1exrj2b_di" bpmnElement="Flow_1exrj2b"> + <di:waypoint x="700" y="117" /> + <di:waypoint x="735" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0qabgp7_di" bpmnElement="Flow_0qabgp7"> + <di:waypoint x="565" y="117" /> + <di:waypoint x="600" y="117" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="579" y="99" width="19" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1f4vi10_di" bpmnElement="Flow_1f4vi10"> + <di:waypoint x="540" y="142" /> + <di:waypoint x="540" y="230" /> + <di:waypoint x="632" y="230" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="548" y="183" width="14" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_09582uw_di" bpmnElement="Flow_09582uw"> + <di:waypoint x="480" y="117" /> + <di:waypoint x="515" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0t87ov3_di" bpmnElement="Flow_0t87ov3"> + <di:waypoint x="1160" y="310" /> + <di:waypoint x="1160" y="357" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0y07mxe_di" bpmnElement="Flow_0y07mxe"> + <di:waypoint x="350" y="117" /> + <di:waypoint x="380" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1tqn5q5_di" bpmnElement="Flow_1tqn5q5"> + <di:waypoint x="208" y="117" /> + <di:waypoint x="250" y="117" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="172" y="99" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="158" y="142" width="67" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_0db1w1a_di" bpmnElement="EndEvent_1"> + <dc:Bounds x="1142" y="357" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1129" y="400" width="63" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_15ksfz6_di" bpmnElement="Activity_15ksfz6"> + <dc:Bounds x="250" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1r4l8w8_di" bpmnElement="Activity_1r4l8w8"> + <dc:Bounds x="1110" y="230" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Gateway_0fuwzjj_di" bpmnElement="Gateway_0fuwzjj" isMarkerVisible="true"> + <dc:Bounds x="515" y="92" width="50" height="50" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="498" y="62" width="88" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_12yonzp_di" bpmnElement="Activity_12yonzp"> + <dc:Bounds x="380" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_06ko4e2_di" bpmnElement="Activity_06ko4e2" isExpanded="true"> + <dc:Bounds x="431" y="310" width="438" height="130" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Flow_04xvpee_di" bpmnElement="Flow_04xvpee"> + <di:waypoint x="681" y="373" /> + <di:waypoint x="813" y="373" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0554tjv_di" bpmnElement="Flow_0554tjv"> + <di:waypoint x="489" y="373" /> + <di:waypoint x="581" y="373" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_1ibvrn2_di" bpmnElement="Event_1ibvrn2"> + <dc:Bounds x="453" y="355" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="459" y="398" width="24" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_02f7sr1_di" bpmnElement="Event_02f7sr1"> + <dc:Bounds x="813" y="355" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="823" y="397" width="19" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1sj0nvr_di" bpmnElement="Activity_1sj0nvr"> + <dc:Bounds x="581" y="333" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1dx9fz6_di" bpmnElement="Activity_1dx9fz6" isExpanded="true"> + <dc:Bounds x="431" y="470" width="438" height="130" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Flow_0oqv7vl_di" bpmnElement="Flow_0oqv7vl"> + <di:waypoint x="680" y="533" /> + <di:waypoint x="772" y="533" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0j1otrx_di" bpmnElement="Flow_0j1otrx"> + <di:waypoint x="522" y="533" /> + <di:waypoint x="580" y="533" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_0zne7ch_di" bpmnElement="Event_0zne7ch"> + <dc:Bounds x="486" y="515" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="493" y="558" width="24" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_0bcyh7u_di" bpmnElement="Event_0bcyh7u"> + <dc:Bounds x="772" y="515" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_15uwy90_di" bpmnElement="Activity_15uwy90"> + <dc:Bounds x="580" y="493" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_0spfqz1_di" bpmnElement="Event_016q8gu"> + <dc:Bounds x="632" y="212" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0vlb2nk_di" bpmnElement="Activity_0vlb2nk"> + <dc:Bounds x="600" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Gateway_0d7n517_di" bpmnElement="Gateway_0d7n517" isMarkerVisible="true"> + <dc:Bounds x="735" y="92" width="50" height="50" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_09tqz8x_di" bpmnElement="Activity_09tqz8x"> + <dc:Bounds x="830" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1akc79d_di" bpmnElement="Activity_1akc79d"> + <dc:Bounds x="970" y="77" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_03ht66t_di" bpmnElement="Activity_03ht66t"> + <dc:Bounds x="1110" y="77" width="100" height="80" /> + </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 new file mode 100644 index 0000000000..ba9e641d84 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/InstantiateNs.bpmn @@ -0,0 +1,331 @@ +<?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_0mdda96" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="4.0.0"> + <bpmn:process id="InstantiateNs" name="InstantiateNs" isExecutable="true"> + <bpmn:startEvent id="StartEvent_1" name="Start Process"> + <bpmn:outgoing>SequenceFlow_16k0f61</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:sequenceFlow id="SequenceFlow_16k0f61" sourceRef="StartEvent_1" targetRef="Activity_194tqy0" /> + <bpmn:serviceTask id="Task_0opnwx0" name="Update NS Instance status to INSTANTIATING" camunda:expression="${InstantiateNsTask.updateNsInstanceStatusToInstantiating(execution)}"> + <bpmn:incoming>Flow_04pxtdd</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0bdznyp</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:endEvent id="EndEvent_0szswbo" name="End Process"> + <bpmn:incoming>Flow_1pcu8aa</bpmn:incoming> + </bpmn:endEvent> + <bpmn:sequenceFlow id="SequenceFlow_0bdznyp" sourceRef="Task_0opnwx0" targetRef="Activity_1jrym1e" /> + <bpmn:serviceTask id="Activity_194tqy0" name="Set Job Status to STARTED" camunda:asyncBefore="true" camunda:expression="${InstantiateNsTask.setJobStatusToStarted(execution)}"> + <bpmn:incoming>SequenceFlow_16k0f61</bpmn:incoming> + <bpmn:outgoing>Flow_04pxtdd</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_04pxtdd" sourceRef="Activity_194tqy0" targetRef="Task_0opnwx0" /> + <bpmn:subProcess id="Activity_0pjxszh" name="Error Handling" triggeredByEvent="true"> + <bpmn:startEvent id="Event_1rpzcl3" name="error"> + <bpmn:outgoing>Flow_07bh7l7</bpmn:outgoing> + <bpmn:errorEventDefinition id="ErrorEventDefinition_0m2e0oa" /> + </bpmn:startEvent> + <bpmn:endEvent id="Event_1fcw3ei" name="end"> + <bpmn:incoming>Flow_1wa1jpl</bpmn:incoming> + </bpmn:endEvent> + <bpmn:serviceTask id="Activity_0ddja9m" name="Set Job Status to ERROR" camunda:asyncBefore="true" camunda:expression="${InstantiateNsTask.setJobStatusToError(execution)}"> + <bpmn:incoming>Flow_0n3dai5</bpmn:incoming> + <bpmn:outgoing>Flow_1wa1jpl</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_1wa1jpl" sourceRef="Activity_0ddja9m" targetRef="Event_1fcw3ei" /> + <bpmn:sequenceFlow id="Flow_07bh7l7" sourceRef="Event_1rpzcl3" targetRef="Activity_1miy3hw" /> + <bpmn:serviceTask id="Activity_1miy3hw" name="Update NSLcmOpOcc operation status to FAILED" camunda:asyncBefore="true" camunda:expression="${InstantiateNsTask.updateNsLcmOpOccStatusToFailed(execution)}"> + <bpmn:incoming>Flow_07bh7l7</bpmn:incoming> + <bpmn:outgoing>Flow_0n3dai5</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_0n3dai5" sourceRef="Activity_1miy3hw" targetRef="Activity_0ddja9m" /> + </bpmn:subProcess> + <bpmn:subProcess id="Activity_0mtscwq" name="Java Exception Handling" triggeredByEvent="true"> + <bpmn:startEvent id="Event_0lqr6al" name="error"> + <bpmn:outgoing>Flow_05lo00r</bpmn:outgoing> + <bpmn:errorEventDefinition id="ErrorEventDefinition_02lwl19" errorRef="Error_0jsct8p" camunda:errorCodeVariable="BPMN_javaExpCode" camunda:errorMessageVariable="BPMN_javaExpMsg" /> + </bpmn:startEvent> + <bpmn:endEvent id="Event_05ty7c4"> + <bpmn:incoming>Flow_16aryg5</bpmn:incoming> + </bpmn:endEvent> + <bpmn:serviceTask id="Activity_1ezu7d4" name="Set Job Status to ERROR" camunda:asyncBefore="true" camunda:expression="${InstantiateNsTask.setJobStatusToError(execution)}"> + <bpmn:incoming>Flow_09zcw2a</bpmn:incoming> + <bpmn:outgoing>Flow_16aryg5</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_16aryg5" sourceRef="Activity_1ezu7d4" targetRef="Event_05ty7c4" /> + <bpmn:sequenceFlow id="Flow_05lo00r" sourceRef="Event_0lqr6al" targetRef="Activity_17leldb" /> + <bpmn:serviceTask id="Activity_17leldb" name="Update NSLcmOpOcc operation status to FAILED" camunda:asyncBefore="true" camunda:expression="${InstantiateNsTask.updateNsLcmOpOccStatusToFailed(execution)}"> + <bpmn:incoming>Flow_05lo00r</bpmn:incoming> + <bpmn:outgoing>Flow_09zcw2a</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_09zcw2a" sourceRef="Activity_17leldb" targetRef="Activity_1ezu7d4" /> + </bpmn:subProcess> + <bpmn:serviceTask id="Activity_1w09i1k" name="Set Job Status to FINISHED" camunda:expression="${InstantiateNsTask.setJobStatusToFinished(execution)}"> + <bpmn:incoming>Flow_1i36dw4</bpmn:incoming> + <bpmn:outgoing>Flow_1pcu8aa</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_1pcu8aa" sourceRef="Activity_1w09i1k" targetRef="EndEvent_0szswbo" /> + <bpmn:serviceTask id="Activity_1jrym1e" name="Get and parse NSD from ETSI Catalog" camunda:expression="${InstantiateNsTask.getAndParseNsdFromEtsiCatalog(execution)}"> + <bpmn:incoming>SequenceFlow_0bdznyp</bpmn:incoming> + <bpmn:outgoing>Flow_10zjw0w</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_10zjw0w" sourceRef="Activity_1jrym1e" targetRef="Activity_1kikjaf" /> + <bpmn:callActivity id="Activity_1b2s2wr" name="Create and Instantiate each Vnf" calledElement="CreateInstantiateVnf"> + <bpmn:extensionElements> + <camunda:in source="request" target="request" /> + <camunda:in source="jobId" target="jobId" /> + <camunda:in source="NsInstanceId" target="NsInstanceId" /> + </bpmn:extensionElements> + <bpmn:incoming>Flow_1irbp9b</bpmn:incoming> + <bpmn:outgoing>Flow_0mi4nqa</bpmn:outgoing> + <bpmn:multiInstanceLoopCharacteristics camunda:asyncAfter="true" camunda:collection="${vnfCreateInstantiateRequests}" camunda:elementVariable="request" /> + </bpmn:callActivity> + <bpmn:boundaryEvent id="Event_0rbb817" name="Overall Wait" attachedToRef="Activity_1b2s2wr"> + <bpmn:outgoing>Flow_17zn7we</bpmn:outgoing> + <bpmn:timerEventDefinition id="TimerEventDefinition_13ud1f4"> + <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT3H</bpmn:timeDuration> + </bpmn:timerEventDefinition> + </bpmn:boundaryEvent> + <bpmn:sequenceFlow id="Flow_17zn7we" sourceRef="Event_0rbb817" targetRef="Activity_16z66xm" /> + <bpmn:serviceTask id="Activity_0eou3y4" name="Prepare Create Instantiate requests" camunda:expression="${InstantiateNsTask.prepareCreateInstantiateRequests(execution)}"> + <bpmn:incoming>Flow_01ju1mj</bpmn:incoming> + <bpmn:outgoing>Flow_1irbp9b</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_1irbp9b" sourceRef="Activity_0eou3y4" targetRef="Activity_1b2s2wr" /> + <bpmn:serviceTask id="Activity_1kikjaf" name="Get Vnf Pkg ID for each VNFD ID" camunda:expression="${InstantiateNsTask.getVnfPkgIdForEachVnfdId(execution)}"> + <bpmn:incoming>Flow_10zjw0w</bpmn:incoming> + <bpmn:outgoing>Flow_01ju1mj</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_01ju1mj" sourceRef="Activity_1kikjaf" targetRef="Activity_0eou3y4" /> + <bpmn:serviceTask id="Activity_16cvdbw" name="Update NS Instance status to INSTANTIATED" camunda:expression="${InstantiateNsTask.updateNsInstanceStatusToInstantiated(execution)}"> + <bpmn:incoming>Flow_1nieng0</bpmn:incoming> + <bpmn:outgoing>Flow_0xptc0r</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_0xptc0r" sourceRef="Activity_16cvdbw" targetRef="Activity_0gkpdft" /> + <bpmn:endEvent id="Event_1e4bwip"> + <bpmn:incoming>Flow_10oprxr</bpmn:incoming> + <bpmn:incoming>Flow_1p21p1m</bpmn:incoming> + <bpmn:errorEventDefinition id="ErrorEventDefinition_0vg6v5r" errorRef="Error_0jsct8p" /> + </bpmn:endEvent> + <bpmn:exclusiveGateway id="Gateway_0nxf0rv" name="is Successful?"> + <bpmn:incoming>Flow_15m4nm1</bpmn:incoming> + <bpmn:outgoing>Flow_1nieng0</bpmn:outgoing> + <bpmn:outgoing>Flow_10oprxr</bpmn:outgoing> + </bpmn:exclusiveGateway> + <bpmn:sequenceFlow id="Flow_1nieng0" name="Yes" sourceRef="Gateway_0nxf0rv" targetRef="Activity_16cvdbw"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{isNsInstantiationSuccessful}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:serviceTask id="Activity_14iwa8x" name="Check if VNF Instantiation was Successful" camunda:expression="${InstantiateNsTask.checkIfVnfInstantiationWasSuccessful(execution)}"> + <bpmn:incoming>Flow_0mi4nqa</bpmn:incoming> + <bpmn:outgoing>Flow_15m4nm1</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_0mi4nqa" sourceRef="Activity_1b2s2wr" targetRef="Activity_14iwa8x" /> + <bpmn:sequenceFlow id="Flow_15m4nm1" sourceRef="Activity_14iwa8x" targetRef="Gateway_0nxf0rv" /> + <bpmn:serviceTask id="Activity_16z66xm" name="Log TimeOut" camunda:expression="${InstantiateNsTask.logTimeOut(execution)}"> + <bpmn:incoming>Flow_17zn7we</bpmn:incoming> + <bpmn:outgoing>Flow_1p21p1m</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="Flow_10oprxr" name="No" sourceRef="Gateway_0nxf0rv" targetRef="Event_1e4bwip"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">#{not isNsInstantiationSuccessful}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:sequenceFlow id="Flow_1p21p1m" sourceRef="Activity_16z66xm" targetRef="Event_1e4bwip" /> + <bpmn:serviceTask id="Activity_0gkpdft" name="Update NSLcmOpOcc operation status to COMPLETED" camunda:expression="${InstantiateNsTask.updateNsLcmOpOccStatusToCompleted(execution)}"> + <bpmn:incoming>Flow_0xptc0r</bpmn:incoming> + <bpmn:outgoing>Flow_1i36dw4</bpmn:outgoing> + </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" /> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="InstantiateNs"> + <bpmndi:BPMNEdge id="Flow_1p21p1m_di" bpmnElement="Flow_1p21p1m"> + <di:waypoint x="1250" y="270" /> + <di:waypoint x="1332" y="270" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_10oprxr_di" bpmnElement="Flow_10oprxr"> + <di:waypoint x="1350" y="146" /> + <di:waypoint x="1350" y="252" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1358" y="196" width="14" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_15m4nm1_di" bpmnElement="Flow_15m4nm1"> + <di:waypoint x="1250" y="121" /> + <di:waypoint x="1325" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0mi4nqa_di" bpmnElement="Flow_0mi4nqa"> + <di:waypoint x="1090" y="121" /> + <di:waypoint x="1150" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1nieng0_di" bpmnElement="Flow_1nieng0"> + <di:waypoint x="1375" y="121" /> + <di:waypoint x="1430" y="121" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1393" y="103" width="19" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0xptc0r_di" bpmnElement="Flow_0xptc0r"> + <di:waypoint x="1530" y="121" /> + <di:waypoint x="1580" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_01ju1mj_di" bpmnElement="Flow_01ju1mj"> + <di:waypoint x="800" y="121" /> + <di:waypoint x="850" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1irbp9b_di" bpmnElement="Flow_1irbp9b"> + <di:waypoint x="950" y="121" /> + <di:waypoint x="990" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_17zn7we_di" bpmnElement="Flow_17zn7we"> + <di:waypoint x="1070" y="179" /> + <di:waypoint x="1070" y="270" /> + <di:waypoint x="1150" y="270" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_10zjw0w_di" bpmnElement="Flow_10zjw0w"> + <di:waypoint x="649" y="121" /> + <di:waypoint x="700" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1pcu8aa_di" bpmnElement="Flow_1pcu8aa"> + <di:waypoint x="1820" y="121" /> + <di:waypoint x="1862" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_04pxtdd_di" bpmnElement="Flow_04pxtdd"> + <di:waypoint x="360" y="121" /> + <di:waypoint x="400" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0bdznyp_di" bpmnElement="SequenceFlow_0bdznyp"> + <di:waypoint x="500" y="121" /> + <di:waypoint x="549" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_16k0f61_di" bpmnElement="SequenceFlow_16k0f61"> + <di:waypoint x="208" y="121" /> + <di:waypoint x="260" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1i36dw4_di" bpmnElement="Flow_1i36dw4"> + <di:waypoint x="1680" y="121" /> + <di:waypoint x="1720" y="121" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="172" y="103" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="157" y="146" width="67" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ServiceTask_1y7xfqt_di" bpmnElement="Task_0opnwx0"> + <dc:Bounds x="400" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_194tqy0_di" bpmnElement="Activity_194tqy0"> + <dc:Bounds x="260" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_0szswbo_di" bpmnElement="EndEvent_0szswbo"> + <dc:Bounds x="1862" y="103" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1848" y="79" width="63" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1w09i1k_di" bpmnElement="Activity_1w09i1k"> + <dc:Bounds x="1720" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0gkpdft_di" bpmnElement="Activity_0gkpdft"> + <dc:Bounds x="1580" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0pjxszh_di" bpmnElement="Activity_0pjxszh" isExpanded="true"> + <dc:Bounds x="380" y="270" width="510" height="130" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Flow_07bh7l7_di" bpmnElement="Flow_07bh7l7"> + <di:waypoint x="438" y="333" /> + <di:waypoint x="500" y="333" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_1wa1jpl_di" bpmnElement="Flow_1wa1jpl"> + <di:waypoint x="760" y="333" /> + <di:waypoint x="822" y="333" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_0n3dai5_di" bpmnElement="Flow_0n3dai5"> + <di:waypoint x="600" y="333" /> + <di:waypoint x="660" y="333" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_1rpzcl3_di" bpmnElement="Event_1rpzcl3"> + <dc:Bounds x="402" y="315" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="408" y="358" width="24" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1miy3hw_di" bpmnElement="Activity_1miy3hw"> + <dc:Bounds x="500" y="293" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0ddja9m_di" bpmnElement="Activity_0ddja9m"> + <dc:Bounds x="660" y="293" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_1fcw3ei_di" bpmnElement="Event_1fcw3ei"> + <dc:Bounds x="822" y="315" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="832" y="357" width="19" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0mtscwq_di" bpmnElement="Activity_0mtscwq" isExpanded="true"> + <dc:Bounds x="380" y="430" width="510" height="130" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="Flow_05lo00r_di" bpmnElement="Flow_05lo00r"> + <di:waypoint x="438" y="493" /> + <di:waypoint x="500" y="493" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_16aryg5_di" bpmnElement="Flow_16aryg5"> + <di:waypoint x="760" y="493" /> + <di:waypoint x="822" y="493" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="Flow_09zcw2a_di" bpmnElement="Flow_09zcw2a"> + <di:waypoint x="600" y="493" /> + <di:waypoint x="660" y="493" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="Event_0lqr6al_di" bpmnElement="Event_0lqr6al"> + <dc:Bounds x="402" y="475" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="409" y="518" width="24" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_17leldb_di" bpmnElement="Activity_17leldb"> + <dc:Bounds x="500" y="453" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1ezu7d4_di" bpmnElement="Activity_1ezu7d4"> + <dc:Bounds x="660" y="453" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_05ty7c4_di" bpmnElement="Event_05ty7c4"> + <dc:Bounds x="822" y="475" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1jrym1e_di" bpmnElement="Activity_1jrym1e"> + <dc:Bounds x="549" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1xjmizv_di" bpmnElement="Activity_1b2s2wr"> + <dc:Bounds x="990" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_0eou3y4_di" bpmnElement="Activity_0eou3y4"> + <dc:Bounds x="850" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_1kikjaf_di" bpmnElement="Activity_1kikjaf"> + <dc:Bounds x="700" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_16cvdbw_di" bpmnElement="Activity_16cvdbw"> + <dc:Bounds x="1430" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_16umj30_di" bpmnElement="Event_1e4bwip"> + <dc:Bounds x="1332" y="252" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Gateway_0nxf0rv_di" bpmnElement="Gateway_0nxf0rv" isMarkerVisible="true"> + <dc:Bounds x="1325" y="96" width="50" height="50" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1320" y="66" width="71" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_14iwa8x_di" bpmnElement="Activity_14iwa8x"> + <dc:Bounds x="1150" y="81" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Activity_16z66xm_di" bpmnElement="Activity_16z66xm"> + <dc:Bounds x="1150" y="230" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="Event_0rbb817_di" bpmnElement="Event_0rbb817"> + <dc:Bounds x="1052" y="143" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1000" y="183" width="60" height="14" /> + </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/META-INF/services/org.onap.so.client.RestProperties b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/META-INF/services/org.onap.so.client.RestProperties new file mode 100644 index 0000000000..9d9ba7371a --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/META-INF/services/org.onap.so.client.RestProperties @@ -0,0 +1 @@ +org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiPropertiesImpl
\ 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/MonitorSol003AdapterCreateJob.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/MonitorSol003AdapterCreateJob.bpmn new file mode 100644 index 0000000000..a9204ec442 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/MonitorSol003AdapterCreateJob.bpmn @@ -0,0 +1,160 @@ +<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_12gnsyw" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.4.1"> + <bpmn:process id="MonitorSol003AdapterCreateJob" name="MonitorSol003AdapterCreateJob" isExecutable="true"> + <bpmn:startEvent id="StartEvent_1"> + <bpmn:outgoing>SequenceFlow_1x3tbl0</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:endEvent id="EndEvent_0rf1gde"> + <bpmn:incoming>SequenceFlow_1543qy7</bpmn:incoming> + </bpmn:endEvent> + <bpmn:subProcess id="SubProcess_19j0v63"> + <bpmn:incoming>SequenceFlow_1x3tbl0</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1v4yr3f</bpmn:outgoing> + <bpmn:startEvent id="StartEvent_01r97z2"> + <bpmn:outgoing>SequenceFlow_0s1plu9</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:exclusiveGateway id="ExclusiveGateway_1hkl6yy" default="SequenceFlow_1vmxw9g"> + <bpmn:incoming>SequenceFlow_153a3kp</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1vmxw9g</bpmn:outgoing> + <bpmn:outgoing>SequenceFlow_0is7myf</bpmn:outgoing> + </bpmn:exclusiveGateway> + <bpmn:intermediateCatchEvent id="IntermediateCatchEvent_1besn3n" name="Wait between checks" camunda:asyncAfter="true"> + <bpmn:incoming>SequenceFlow_1vmxw9g</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0etw572</bpmn:outgoing> + <bpmn:timerEventDefinition id="TimerEventDefinition_0qgh11t"> + <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT15S</bpmn:timeDuration> + </bpmn:timerEventDefinition> + </bpmn:intermediateCatchEvent> + <bpmn:endEvent id="EndEvent_1ohsce9"> + <bpmn:incoming>SequenceFlow_0is7myf</bpmn:incoming> + </bpmn:endEvent> + <bpmn:sequenceFlow id="SequenceFlow_0s1plu9" sourceRef="StartEvent_01r97z2" targetRef="ServiceTask_17jlnng" /> + <bpmn:sequenceFlow id="SequenceFlow_0etw572" sourceRef="IntermediateCatchEvent_1besn3n" targetRef="ServiceTask_17jlnng" /> + <bpmn:serviceTask id="ServiceTask_17jlnng" name=" Get Current Operation Status " camunda:asyncAfter="true" camunda:expression="${MonitorSol003AdapterCreateJobTask.getCurrentOperationStatus(execution)}"> + <bpmn:incoming>SequenceFlow_0etw572</bpmn:incoming> + <bpmn:incoming>SequenceFlow_0s1plu9</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_153a3kp</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="SequenceFlow_1vmxw9g" sourceRef="ExclusiveGateway_1hkl6yy" targetRef="IntermediateCatchEvent_1besn3n" /> + <bpmn:sequenceFlow id="SequenceFlow_0is7myf" sourceRef="ExclusiveGateway_1hkl6yy" targetRef="EndEvent_1ohsce9"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${MonitorSol003AdapterCreateJobTask.hasOperationFinished(execution)}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:sequenceFlow id="SequenceFlow_153a3kp" sourceRef="ServiceTask_17jlnng" targetRef="ExclusiveGateway_1hkl6yy" /> + </bpmn:subProcess> + <bpmn:endEvent id="EndEvent_1w3t3t0" name="Timeout Exception"> + <bpmn:incoming>SequenceFlow_0bcgtzj</bpmn:incoming> + <bpmn:terminateEventDefinition id="TerminateEventDefinition_0fjecl3" /> + </bpmn:endEvent> + <bpmn:boundaryEvent id="BoundaryEvent_0xiabzp" name="Overall Wait" attachedToRef="SubProcess_19j0v63"> + <bpmn:outgoing>SequenceFlow_1i1o9sh</bpmn:outgoing> + <bpmn:timerEventDefinition id="TimerEventDefinition_10kqw61"> + <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT3H</bpmn:timeDuration> + </bpmn:timerEventDefinition> + </bpmn:boundaryEvent> + <bpmn:sequenceFlow id="SequenceFlow_1v4yr3f" sourceRef="SubProcess_19j0v63" targetRef="ServiceTask_1gms128" /> + <bpmn:sequenceFlow id="SequenceFlow_1i1o9sh" sourceRef="BoundaryEvent_0xiabzp" targetRef="ServiceTask_1s87b92" /> + <bpmn:sequenceFlow id="SequenceFlow_1x3tbl0" sourceRef="StartEvent_1" targetRef="SubProcess_19j0v63" /> + <bpmn:serviceTask id="ServiceTask_1s87b92" name=" Time Out Log Failure " camunda:asyncAfter="true" camunda:expression="${MonitorSol003AdapterCreateJobTask.timeOutLogFailue(execution)}"> + <bpmn:incoming>SequenceFlow_1i1o9sh</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0bcgtzj</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="SequenceFlow_0bcgtzj" sourceRef="ServiceTask_1s87b92" targetRef="EndEvent_1w3t3t0" /> + <bpmn:serviceTask id="ServiceTask_1gms128" name=" Check if operation was successful " camunda:asyncAfter="true" camunda:expression="${MonitorSol003AdapterCreateJobTask.checkIfOperationWasSuccessful(execution)}"> + <bpmn:incoming>SequenceFlow_1v4yr3f</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1543qy7</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="SequenceFlow_1543qy7" sourceRef="ServiceTask_1gms128" targetRef="EndEvent_0rf1gde" /> + </bpmn:process> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="MonitorSol003AdapterCreateJob"> + <bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1"> + <dc:Bounds x="161" y="330" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_0rf1gde_di" bpmnElement="EndEvent_0rf1gde"> + <dc:Bounds x="1102" y="100" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="SubProcess_19j0v63_di" bpmnElement="SubProcess_19j0v63" isExpanded="true"> + <dc:Bounds x="301" y="248" width="523" height="200" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_1w3t3t0_di" bpmnElement="EndEvent_1w3t3t0"> + <dc:Bounds x="1102" y="322" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1095" y="282" width="49" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="BoundaryEvent_0xiabzp_di" bpmnElement="BoundaryEvent_0xiabzp"> + <dc:Bounds x="806" y="322" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="794" y="361" width="61" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1v4yr3f_di" bpmnElement="SequenceFlow_1v4yr3f"> + <di:waypoint x="563" y="248" /> + <di:waypoint x="563" y="118" /> + <di:waypoint x="923" y="118" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_1i1o9sh_di" bpmnElement="SequenceFlow_1i1o9sh"> + <di:waypoint x="842" y="340" /> + <di:waypoint x="923" y="340" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="StartEvent_01r97z2_di" bpmnElement="StartEvent_01r97z2"> + <dc:Bounds x="330" y="306" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ExclusiveGateway_1hkl6yy_di" bpmnElement="ExclusiveGateway_1hkl6yy" isMarkerVisible="true"> + <dc:Bounds x="609" y="299" width="50" height="50" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="IntermediateCatchEvent_1besn3n_di" bpmnElement="IntermediateCatchEvent_1besn3n"> + <dc:Bounds x="550" y="378" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="537" y="421" width="66" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_1ohsce9_di" bpmnElement="EndEvent_1ohsce9"> + <dc:Bounds x="722" y="306" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1x3tbl0_di" bpmnElement="SequenceFlow_1x3tbl0"> + <di:waypoint x="197" y="348" /> + <di:waypoint x="301" y="348" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ServiceTask_17jlnng_di" bpmnElement="ServiceTask_17jlnng"> + <dc:Bounds x="425" y="284" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_0s1plu9_di" bpmnElement="SequenceFlow_0s1plu9"> + <di:waypoint x="366" y="324" /> + <di:waypoint x="425" y="324" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0etw572_di" bpmnElement="SequenceFlow_0etw572"> + <di:waypoint x="550" y="396" /> + <di:waypoint x="486" y="396" /> + <di:waypoint x="486" y="367" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_1vmxw9g_di" bpmnElement="SequenceFlow_1vmxw9g"> + <di:waypoint x="634" y="349" /> + <di:waypoint x="634" y="396" /> + <di:waypoint x="586" y="396" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0is7myf_di" bpmnElement="SequenceFlow_0is7myf"> + <di:waypoint x="659" y="324" /> + <di:waypoint x="722" y="324" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_153a3kp_di" bpmnElement="SequenceFlow_153a3kp"> + <di:waypoint x="525" y="324" /> + <di:waypoint x="609" y="324" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ServiceTask_1s87b92_di" bpmnElement="ServiceTask_1s87b92"> + <dc:Bounds x="923" y="300" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_0bcgtzj_di" bpmnElement="SequenceFlow_0bcgtzj"> + <di:waypoint x="1023" y="340" /> + <di:waypoint x="1102" y="340" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="ServiceTask_1gms128_di" bpmnElement="ServiceTask_1gms128"> + <dc:Bounds x="923" y="78" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1543qy7_di" bpmnElement="SequenceFlow_1543qy7"> + <di:waypoint x="1023" y="118" /> + <di:waypoint x="1102" y="118" /> + </bpmndi:BPMNEdge> + </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/MonitorSol003AdapterCreateNodeStatus.bpmn b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/MonitorSol003AdapterCreateNodeStatus.bpmn new file mode 100644 index 0000000000..c0de5e0352 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/resources/MonitorSol003AdapterCreateNodeStatus.bpmn @@ -0,0 +1,138 @@ +<?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:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1ko0frn" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.4.1"> + <bpmn:process id="MonitorSol003AdapterCreateNodeStatus" name="MonitorSol003AdapterCreateNodeStatus" isExecutable="true"> + <bpmn:startEvent id="StartEvent_0k0qfjb"> + <bpmn:outgoing>SequenceFlow_1miob62</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:subProcess id="SubProcess_10wotbc"> + <bpmn:incoming>SequenceFlow_1miob62</bpmn:incoming> + <bpmn:startEvent id="StartEvent_0r9qf43"> + <bpmn:outgoing>SequenceFlow_1moaz0q</bpmn:outgoing> + </bpmn:startEvent> + <bpmn:exclusiveGateway id="ExclusiveGateway_00xtlfj" default="SequenceFlow_1luu31f"> + <bpmn:incoming>SequenceFlow_0qvy3sn</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_1rxbeqi</bpmn:outgoing> + <bpmn:outgoing>SequenceFlow_1luu31f</bpmn:outgoing> + </bpmn:exclusiveGateway> + <bpmn:intermediateCatchEvent id="IntermediateCatchEvent_0xuznv9" name="Wait between checks" camunda:asyncAfter="true"> + <bpmn:incoming>SequenceFlow_1luu31f</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_09t51ao</bpmn:outgoing> + <bpmn:timerEventDefinition id="TimerEventDefinition_0vrbrge"> + <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT15S</bpmn:timeDuration> + </bpmn:timerEventDefinition> + </bpmn:intermediateCatchEvent> + <bpmn:endEvent id="EndEvent_0tei3i9"> + <bpmn:incoming>SequenceFlow_1rxbeqi</bpmn:incoming> + </bpmn:endEvent> + <bpmn:serviceTask id="ServiceTask_0y71su8" name=" Get node status " camunda:asyncAfter="true" camunda:expression="${MonitorInstantiateSol003AdapterNodeTask.getNodeStatus(execution)}"> + <bpmn:incoming>SequenceFlow_1moaz0q</bpmn:incoming> + <bpmn:incoming>SequenceFlow_09t51ao</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0qvy3sn</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:sequenceFlow id="SequenceFlow_1rxbeqi" name=" create vnf success " sourceRef="ExclusiveGateway_00xtlfj" targetRef="EndEvent_0tei3i9"> + <bpmn:conditionExpression xsi:type="bpmn:tFormalExpression">${execution.getVariable("createVnfNodeStatus")}</bpmn:conditionExpression> + </bpmn:sequenceFlow> + <bpmn:sequenceFlow id="SequenceFlow_1luu31f" sourceRef="ExclusiveGateway_00xtlfj" targetRef="IntermediateCatchEvent_0xuznv9" /> + <bpmn:sequenceFlow id="SequenceFlow_1moaz0q" sourceRef="StartEvent_0r9qf43" targetRef="ServiceTask_0y71su8" /> + <bpmn:sequenceFlow id="SequenceFlow_0qvy3sn" sourceRef="ServiceTask_0y71su8" targetRef="ExclusiveGateway_00xtlfj" /> + <bpmn:sequenceFlow id="SequenceFlow_09t51ao" sourceRef="IntermediateCatchEvent_0xuznv9" targetRef="ServiceTask_0y71su8" /> + </bpmn:subProcess> + <bpmn:endEvent id="EndEvent_1b83rci" name="Timeout Exception"> + <bpmn:incoming>SequenceFlow_0uiqnl8</bpmn:incoming> + <bpmn:terminateEventDefinition id="TerminateEventDefinition_12rjfva" /> + </bpmn:endEvent> + <bpmn:serviceTask id="ServiceTask_12qp0ty" name=" Time Out Log Failure " camunda:asyncAfter="true" camunda:expression="${MonitorSol003AdapterNodeTask.timeOutLogFailue(execution)}"> + <bpmn:incoming>SequenceFlow_0qcc5x4</bpmn:incoming> + <bpmn:outgoing>SequenceFlow_0uiqnl8</bpmn:outgoing> + </bpmn:serviceTask> + <bpmn:boundaryEvent id="BoundaryEvent_1f5o5i9" name="Overall Wait" attachedToRef="SubProcess_10wotbc"> + <bpmn:outgoing>SequenceFlow_0qcc5x4</bpmn:outgoing> + <bpmn:timerEventDefinition id="TimerEventDefinition_1t3ya63"> + <bpmn:timeDuration xsi:type="bpmn:tFormalExpression">PT3H</bpmn:timeDuration> + </bpmn:timerEventDefinition> + </bpmn:boundaryEvent> + <bpmn:sequenceFlow id="SequenceFlow_1miob62" sourceRef="StartEvent_0k0qfjb" targetRef="SubProcess_10wotbc" /> + <bpmn:sequenceFlow id="SequenceFlow_0uiqnl8" sourceRef="ServiceTask_12qp0ty" targetRef="EndEvent_1b83rci" /> + <bpmn:sequenceFlow id="SequenceFlow_0qcc5x4" sourceRef="BoundaryEvent_1f5o5i9" targetRef="ServiceTask_12qp0ty" /> + </bpmn:process> + <bpmndi:BPMNDiagram id="BPMNDiagram_1"> + <bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="MonitorSol003AdapterCreateNodeStatus"> + <bpmndi:BPMNShape id="StartEvent_0k0qfjb_di" bpmnElement="StartEvent_0k0qfjb"> + <dc:Bounds x="155" y="159" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="SubProcess_10wotbc_di" bpmnElement="SubProcess_10wotbc" isExpanded="true"> + <dc:Bounds x="293" y="77" width="523" height="200" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_1b83rci_di" bpmnElement="EndEvent_1b83rci"> + <dc:Bounds x="1096" y="151" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="1089" y="111" width="49" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ServiceTask_12qp0ty_di" bpmnElement="ServiceTask_12qp0ty"> + <dc:Bounds x="917" y="129" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="BoundaryEvent_1f5o5i9_di" bpmnElement="BoundaryEvent_1f5o5i9"> + <dc:Bounds x="800" y="151" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="788" y="190" width="61" height="14" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1miob62_di" bpmnElement="SequenceFlow_1miob62"> + <di:waypoint x="191" y="177" /> + <di:waypoint x="293" y="177" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0uiqnl8_di" bpmnElement="SequenceFlow_0uiqnl8"> + <di:waypoint x="1017" y="169" /> + <di:waypoint x="1096" y="169" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0qcc5x4_di" bpmnElement="SequenceFlow_0qcc5x4"> + <di:waypoint x="836" y="169" /> + <di:waypoint x="917" y="169" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNShape id="StartEvent_0r9qf43_di" bpmnElement="StartEvent_0r9qf43"> + <dc:Bounds x="324" y="135" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ExclusiveGateway_00xtlfj_di" bpmnElement="ExclusiveGateway_00xtlfj" isMarkerVisible="true"> + <dc:Bounds x="603" y="128" width="50" height="50" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="IntermediateCatchEvent_0xuznv9_di" bpmnElement="IntermediateCatchEvent_0xuznv9"> + <dc:Bounds x="544" y="207" width="36" height="36" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="532" y="250" width="66" height="27" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="EndEvent_0tei3i9_di" bpmnElement="EndEvent_0tei3i9"> + <dc:Bounds x="716" y="135" width="36" height="36" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNShape id="ServiceTask_0y71su8_di" bpmnElement="ServiceTask_0y71su8"> + <dc:Bounds x="412" y="113" width="100" height="80" /> + </bpmndi:BPMNShape> + <bpmndi:BPMNEdge id="SequenceFlow_1rxbeqi_di" bpmnElement="SequenceFlow_1rxbeqi"> + <di:waypoint x="653" y="153" /> + <di:waypoint x="716" y="153" /> + <bpmndi:BPMNLabel> + <dc:Bounds x="660" y="135" width="50" height="80" /> + </bpmndi:BPMNLabel> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_1luu31f_di" bpmnElement="SequenceFlow_1luu31f"> + <di:waypoint x="628" y="178" /> + <di:waypoint x="628" y="225" /> + <di:waypoint x="580" y="225" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_1moaz0q_di" bpmnElement="SequenceFlow_1moaz0q"> + <di:waypoint x="360" y="153" /> + <di:waypoint x="412" y="153" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_0qvy3sn_di" bpmnElement="SequenceFlow_0qvy3sn"> + <di:waypoint x="512" y="153" /> + <di:waypoint x="603" y="153" /> + </bpmndi:BPMNEdge> + <bpmndi:BPMNEdge id="SequenceFlow_09t51ao_di" bpmnElement="SequenceFlow_09t51ao"> + <di:waypoint x="544" y="225" /> + <di:waypoint x="451" y="225" /> + <di:waypoint x="452" y="193" /> + </bpmndi:BPMNEdge> + </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/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 new file mode 100644 index 0000000000..fc9f2a2195 --- /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/BaseTest.java @@ -0,0 +1,142 @@ +/*- + * ============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 static org.slf4j.LoggerFactory.getLogger; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.camunda.bpm.engine.HistoryService; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.history.HistoricProcessInstance; +import org.camunda.bpm.engine.history.HistoricVariableInstance; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.runner.RunWith; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import com.github.tomakehurst.wiremock.WireMockServer; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +@ContextConfiguration +@AutoConfigureWireMock(port = 0) +public abstract class BaseTest { + protected static final String ETSI_CATALOG_URL = "http://modeling-etsicatalog.onap:8806/api"; + protected static final String SOL003_ADAPTER_ENDPOINT_URL = "https://so-vnfm-adapter.onap:9092/so/vnfm-adapter/v1"; + protected static final String GLOBAL_CUSTOMER_ID = UUID.randomUUID().toString(); + protected static final String NSD_INVARIANT_ID = UUID.randomUUID().toString(); + protected static final String SERVICE_TYPE = "NetworkService"; + protected static final String UUID_REGEX = + "[0-9a-zA-Z]{8}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{12}"; + protected static final String RANDOM_JOB_ID = UUID.randomUUID().toString(); + + protected static final Logger logger = getLogger(BaseTest.class); + + private static final long TIME_OUT_IN_SECONDS = 60; + private static final int SLEEP_TIME_IN_SECONDS = 5; + + @Autowired + private HistoryService historyService; + + @Autowired + private RuntimeService runtimeService; + + @Autowired + protected DatabaseServiceProvider databaseServiceProvider; + + @Autowired + protected WireMockServer wireMockServer; + + public NfvoJob createNewNfvoJob(final String jobAction, final String nsdId, final String nsName) { + final NfvoJob newJob = new NfvoJob().startTime(LocalDateTime.now()).jobType("NS").jobAction(JobAction.CREATE) + .status(JobStatusEnum.STARTING).resourceId(nsdId).resourceName(nsName); + databaseServiceProvider.addJob(newJob); + return newJob; + } + + public Optional<NfvoJob> getNfvoJob(final String jobId) { + return databaseServiceProvider.getJob(jobId); + } + + public Optional<NfvoJob> getJobByResourceId(final String resourceId) { + return databaseServiceProvider.getJobByResourceId(resourceId); + } + + public ProcessInstance executeWorkflow(final String processDefinitionKey, final String businessKey, + final Map<String, Object> variables) { + return runtimeService.startProcessInstanceByKey(processDefinitionKey, businessKey, variables); + } + + public HistoricProcessInstance getHistoricProcessInstance(final String processInstanceId) { + return historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult(); + } + + public HistoricVariableInstance getVariable(final String processInstanceId, final String name) { + return historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId) + .variableName(name).singleResult(); + } + + public List<HistoricVariableInstance> getVariables(final String processInstanceId) { + return historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list(); + } + + public boolean waitForProcessInstanceToFinish(final String processInstanceId) throws InterruptedException { + final long startTimeInMillis = System.currentTimeMillis(); + final long timeOutTime = startTimeInMillis + TimeUnit.SECONDS.toMillis(TIME_OUT_IN_SECONDS); + while (timeOutTime > System.currentTimeMillis()) { + + if (isProcessEndedByProcessInstanceId(processInstanceId)) { + logger.info("processInstanceId: {} is finished", processInstanceId); + return true; + } + logger.info("processInstanceId: {} is still running", processInstanceId); + logger.info("Process instance {} not finished yet, will try again in {} seconds", processInstanceId, + SLEEP_TIME_IN_SECONDS); + TimeUnit.SECONDS.sleep(SLEEP_TIME_IN_SECONDS); + } + logger.warn("Timeout {} process didn't finished ", processInstanceId); + return false; + } + + + public boolean isProcessEndedByProcessInstanceId(final String processInstanceId) { + final HistoricProcessInstance processInstance = getHistoricProcessInstance(processInstanceId); + return processInstance != null + && !HistoricProcessInstance.STATE_ACTIVE.equalsIgnoreCase(processInstance.getState()); + } + +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyManagerNotFound.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/DefaultToShortClassNameBeanNameGenerator.java index bc6fd6204c..f91cf9d0c3 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoCloudifyManagerNotFound.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/DefaultToShortClassNameBeanNameGenerator.java @@ -1,33 +1,37 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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.cloudify.exceptions; +package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows; -public class MsoCloudifyManagerNotFound extends MsoCloudifyException { +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.AnnotationBeanNameGenerator; +import org.springframework.util.ClassUtils; - private static final long serialVersionUID = 1L; +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class DefaultToShortClassNameBeanNameGenerator extends AnnotationBeanNameGenerator { - // Constructor to create a new MsoCloudifyException instance - public MsoCloudifyManagerNotFound(String cloudSiteId) { - // Set the detailed error as the Exception 'message' - super(0, "Cloudify Manager Not Found", "No Cloudify Manager configured for cloud site " + cloudSiteId); + @Override + protected String buildDefaultBeanName(final BeanDefinition definition) { + return ClassUtils.getShortName(definition.getBeanClassName()); } - } 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/TestApplication.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/TestApplication.java new file mode 100644 index 0000000000..18d601930c --- /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/TestApplication.java @@ -0,0 +1,45 @@ +/*- + * ============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 org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.ComponentScan.Filter; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@SpringBootApplication(scanBasePackages = {"org.onap.so"}) +@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class}) +@ComponentScan(basePackages = {"org.onap"}, nameGenerator = DefaultToShortClassNameBeanNameGenerator.class, + excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)}) +public class TestApplication { + + public static void main(final String[] args) { + new SpringApplication(TestApplication.class).run(args); + } + +} 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/NetworkServiceDescriptorParserTest.java new file mode 100644 index 0000000000..2bebf1c30a --- /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/nsd/NetworkServiceDescriptorParserTest.java @@ -0,0 +1,87 @@ +/*- + * ============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.nsd; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.Map; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class NetworkServiceDescriptorParserTest { + + private static final String VALID_ETSI_NSD_FILE = "src/test/resources/ns.csar"; + private static final String INVALID_ETSI_NSD_FILE = "src/test/resources/invalid_ns.csar"; + + @Autowired + private NetworkServiceDescriptorParser objUnderTest; + + @Test + public void testValidEtsiNsd_ableToParseIt() throws IOException { + final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(VALID_ETSI_NSD_FILE))); + final Optional<NetworkServiceDescriptor> optional = objUnderTest.parse(zipBytes); + assertTrue(optional.isPresent()); + final NetworkServiceDescriptor actualNsd = optional.get(); + assertEquals(NetworkServiceDescriptorParser.NS_NODE_TYPE, actualNsd.getType()); + assertFalse(actualNsd.getProperties().isEmpty()); + + final Map<String, Object> actualNsdProperties = actualNsd.getProperties(); + assertEquals(5, actualNsdProperties.size()); + assertEquals("ffdddc5d-a44b-45ae-8fc3-e6551cce350f", actualNsdProperties.get("descriptor_id")); + assertEquals(5, actualNsd.getVnfs().size()); + + } + + @Test + public void testEmptyEtsiNsd_returnEmptyOptional() throws IOException { + assertFalse(objUnderTest.parse(new byte[] {}).isPresent()); + } + + @Test + public void testInvalidEtsiNsd_returnEmptyOptional() throws IOException { + final byte[] zipBytes = Files.readAllBytes(Paths.get(getAbsolutePath(INVALID_ETSI_NSD_FILE))); + assertFalse(objUnderTest.parse(zipBytes).isPresent()); + } + + private String getAbsolutePath(final String path) { + final File file = new File(path); + return file.getAbsolutePath(); + } + +} 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 new file mode 100644 index 0000000000..05213a344f --- /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/CreateNsTaskTest.java @@ -0,0 +1,387 @@ +/*- + * ============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 static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.notFound; +import static com.github.tomakehurst.wiremock.client.WireMock.ok; +import static com.github.tomakehurst.wiremock.client.WireMock.put; +import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_REST_TEMPLATE_BEAN; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; +import java.time.LocalDateTime; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import org.camunda.bpm.engine.history.HistoricProcessInstance; +import org.camunda.bpm.engine.history.HistoricVariableInstance; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants; +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.bpmn.flows.service.WorkflowQueryService; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; +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.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance.NsStateEnum; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.GsonHttpMessageConverter; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.web.client.RestTemplate; +import com.github.tomakehurst.wiremock.client.WireMock; +import com.google.gson.Gson; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class CreateNsTaskTest extends BaseTest { + private static final String NSD_ID = UUID.randomUUID().toString(); + private static final String NS_NAME = "CreateNetworkService-" + NSD_ID; + private static final String CREATE_NS_WORKFLOW_NAME = "CreateNs"; + + @Autowired + @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) + private RestTemplate restTemplate; + + @Autowired + private GsonProvider gsonProvider; + + @Autowired + private JobExecutorService objUnderTest; + + @Autowired + private WorkflowQueryService workflowQueryService; + + private MockRestServiceServer mockRestServiceServer; + + private Gson gson; + + @Before + public void before() { + wireMockServer.resetAll(); + final MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(restTemplate); + builder.ignoreExpectOrder(true); + mockRestServiceServer = builder.build(); + gson = gsonProvider.getGson(); + restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); + } + + @After + public void after() { + wireMockServer.resetAll(); + mockRestServiceServer.reset(); + } + + @Test + public void testCreateNsWorkflow_SuccessfullCase() throws InterruptedException { + final CreateNsRequest createNsRequest = getCreateNsRequest(); + + mockEtsiCatalogEndpoints(); + mockAAIEndpoints(createNsRequest); + + final NsInstancesNsInstance nsResponse = + objUnderTest.runCreateNsJob(createNsRequest, GLOBAL_CUSTOMER_ID, SERVICE_TYPE); + assertNotNull(nsResponse); + assertNotNull(nsResponse.getId()); + + final Optional<NfvoJob> optional = getJobByResourceId(createNsRequest.getNsdId()); + assertTrue(optional.isPresent()); + final NfvoJob nfvoJob = optional.get(); + + assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); + + mockRestServiceServer.verify(); + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + assertTrue(databaseServiceProvider.isNsInstExists(createNsRequest.getNsName())); + + final NfvoJob actualJob = optional.get(); + assertEquals(JobStatusEnum.FINISHED, actualJob.getStatus()); + + assertEquals(NS_NAME, nsResponse.getNsInstanceName()); + assertEquals(NsStateEnum.NOT_INSTANTIATED, nsResponse.getNsState()); + + final HistoricVariableInstance doesNsPackageExistsVar = + getVariable(nfvoJob.getProcessInstanceId(), "doesNsPackageExists"); + assertNotNull(doesNsPackageExistsVar); + assertTrue((boolean) doesNsPackageExistsVar.getValue()); + + final HistoricVariableInstance doesNsInstanceExistsVar = + getVariable(nfvoJob.getProcessInstanceId(), "doesNsInstanceExists"); + assertNotNull(doesNsInstanceExistsVar); + assertFalse((boolean) doesNsInstanceExistsVar.getValue()); + + } + + @Test + public void testCreateNsWorkflow_FailsToGetNsPackage() throws InterruptedException { + final String nsdId = UUID.randomUUID().toString(); + final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); + final CreateNsRequest createNsRequest = getCreateNsRequest(nsdId, nsdName); + + mockRestServiceServer.expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId)) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND)); + + try { + objUnderTest.runCreateNsJob(createNsRequest, GLOBAL_CUSTOMER_ID, SERVICE_TYPE); + fail("runCreateNsJob should throw exception"); + } catch (final Exception exception) { + assertEquals(NsRequestProcessingException.class, exception.getClass()); + } + + final Optional<NfvoJob> optional = getJobByResourceId(createNsRequest.getNsdId()); + assertTrue(optional.isPresent()); + final NfvoJob nfvoJob = optional.get(); + assertEquals(JobStatusEnum.ERROR, nfvoJob.getStatus()); + + assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); + + mockRestServiceServer.verify(); + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + + + final HistoricVariableInstance nsResponseVariable = + getVariable(nfvoJob.getProcessInstanceId(), CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME); + assertNull(nsResponseVariable); + + final Optional<InlineResponse400> problemDetailsOptional = + workflowQueryService.getProblemDetails(nfvoJob.getProcessInstanceId()); + assertTrue(problemDetailsOptional.isPresent()); + + final InlineResponse400 problemDetails = problemDetailsOptional.get(); + assertNotNull(problemDetails); + assertNotNull(problemDetails.getDetail()); + + final HistoricVariableInstance doesNsPackageExistsVar = + getVariable(nfvoJob.getProcessInstanceId(), "doesNsPackageExists"); + assertNotNull(doesNsPackageExistsVar); + assertFalse((boolean) doesNsPackageExistsVar.getValue()); + assertEquals("Unexpected exception occured while getting ns package using nsdId: " + nsdId, + problemDetails.getDetail()); + } + + @Test + public void testCreateNsWorkflow_FailsToFindJobUsingJobId() throws InterruptedException { + final String nsdId = UUID.randomUUID().toString(); + final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); + final CreateNsRequest createNsRequest = getCreateNsRequest(nsdId, nsdName); + + final String randomJobId = UUID.randomUUID().toString(); + final ProcessInstance processInstance = + executeWorkflow(CREATE_NS_WORKFLOW_NAME, randomJobId, getVariables(randomJobId, createNsRequest)); + assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); + + mockRestServiceServer.verify(); + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(processInstance.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + + final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), + CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME); + + assertNull(nsResponseVariable); + + final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(), + CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + + final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue(); + assertNotNull(problemDetails); + assertNotNull(problemDetails.getDetail()); + assertEquals("Unable to find job using job id: " + randomJobId, problemDetails.getDetail()); + + } + + @Test + public void testCreateNsWorkflow_NsInstanceExistsInDb() throws InterruptedException { + final String nsdId = UUID.randomUUID().toString(); + final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); + final CreateNsRequest createNsRequest = getCreateNsRequest(nsdId, nsdName); + + databaseServiceProvider.saveNfvoNsInst(new NfvoNsInst().nsInstId(nsdId).name(createNsRequest.getNsName()) + .nsPackageId(UUID.randomUUID().toString()).nsdId(nsdId).nsdInvariantId(nsdId) + .description(createNsRequest.getNsDescription()).status(State.INSTANTIATED) + .statusUpdatedTime(LocalDateTime.now()).globalCustomerId(GLOBAL_CUSTOMER_ID).serviceType(SERVICE_TYPE)); + + mockEtsiCatalogEndpoints(nsdId); + + try { + objUnderTest.runCreateNsJob(createNsRequest, GLOBAL_CUSTOMER_ID, SERVICE_TYPE); + fail("runCreateNsJob should throw exception"); + } catch (final Exception exception) { + assertEquals(NsRequestProcessingException.class, exception.getClass()); + } + + final Optional<NfvoJob> optional = getJobByResourceId(createNsRequest.getNsdId()); + assertTrue(optional.isPresent()); + final NfvoJob nfvoJob = optional.get(); + assertEquals(JobStatusEnum.ERROR, nfvoJob.getStatus()); + + assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); + + mockRestServiceServer.verify(); + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + assertTrue(databaseServiceProvider.isNsInstExists(createNsRequest.getNsName())); + + final HistoricVariableInstance historicVariableInstance = + getVariable(nfvoJob.getProcessInstanceId(), CamundaVariableNameConstants.CREATE_NS_RESPONSE_PARAM_NAME); + + assertNull(historicVariableInstance); + + final Optional<InlineResponse400> problemDetailsOptional = + workflowQueryService.getProblemDetails(nfvoJob.getProcessInstanceId()); + + final InlineResponse400 problemDetails = problemDetailsOptional.get(); + assertNotNull(problemDetails); + assertNotNull(problemDetails.getDetail()); + assertTrue(problemDetails.getDetail().startsWith("Ns Instance already exists in database")); + + final HistoricVariableInstance doesNsInstanceExistsVar = + getVariable(nfvoJob.getProcessInstanceId(), "doesNsInstanceExists"); + assertNotNull(doesNsInstanceExistsVar); + assertTrue((boolean) doesNsInstanceExistsVar.getValue()); + + } + + @Test + public void testCreateNsWorkflow_FailToCreateResouceInAai() throws InterruptedException { + final String nsdId = UUID.randomUUID().toString(); + final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); + final CreateNsRequest createNsRequest = getCreateNsRequest(nsdId, nsdName); + + mockEtsiCatalogEndpoints(nsdId); + + final String modelEndpoint = getAiaServiceInstancelEndPoint(createNsRequest); + wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(WireMock.serverError())); + wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(WireMock.serverError())); + + try { + objUnderTest.runCreateNsJob(createNsRequest, GLOBAL_CUSTOMER_ID, SERVICE_TYPE); + fail("runCreateNsJob should throw exception"); + } catch (final Exception exception) { + assertEquals(NsRequestProcessingException.class, exception.getClass()); + } + final Optional<NfvoJob> optional = getJobByResourceId(createNsRequest.getNsdId()); + assertTrue(optional.isPresent()); + final NfvoJob nfvoJob = optional.get(); + assertEquals(JobStatusEnum.ERROR, nfvoJob.getStatus()); + + mockRestServiceServer.verify(); + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + assertTrue(databaseServiceProvider.isNsInstExists(createNsRequest.getNsName())); + + final Optional<InlineResponse400> problemDetailsOptional = + workflowQueryService.getProblemDetails(nfvoJob.getProcessInstanceId()); + + final InlineResponse400 problemDetails = problemDetailsOptional.get(); + assertNotNull(problemDetails); + assertEquals("Unable to Create Service Instance in AAI", problemDetails.getDetail()); + + } + + private void mockAAIEndpoints(final CreateNsRequest createNsRequest) { + final String modelEndpoint = getAiaServiceInstancelEndPoint(createNsRequest); + + 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)) + .andRespond(withSuccess(gson.toJson(getNSPackageModel(NSD_ID)), MediaType.APPLICATION_JSON)); + } + + private void mockEtsiCatalogEndpoints() { + mockEtsiCatalogEndpoints(NSD_ID);; + } + + private NsdInfo getNSPackageModel(final String nsdId) { + return new NsdInfo().id(nsdId).nsdId(nsdId).nsdInvariantId(NSD_INVARIANT_ID).nsdName("vcpe").nsdDesigner("ONAP") + .vnfPkgIds(Arrays.asList(GLOBAL_CUSTOMER_ID)); + } + + private CreateNsRequest getCreateNsRequest() { + return getCreateNsRequest(NSD_ID, NS_NAME); + } + + private CreateNsRequest getCreateNsRequest(final String nsdId, final String nsName) { + return new CreateNsRequest().nsdId(nsdId).nsName(nsName); + } + + private Map<String, Object> getVariables(final String jobId, final CreateNsRequest createNsRequest) { + final Map<String, Object> variables = new HashMap<>(); + variables.put(CamundaVariableNameConstants.JOB_ID_PARAM_NAME, jobId); + variables.put(CamundaVariableNameConstants.CREATE_NS_REQUEST_PARAM_NAME, createNsRequest); + variables.put(CamundaVariableNameConstants.GLOBAL_CUSTOMER_ID_PARAM_NAME, GLOBAL_CUSTOMER_ID); + variables.put(CamundaVariableNameConstants.SERVICE_TYPE_PARAM_NAME, SERVICE_TYPE); + + return variables; + } + +} 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 new file mode 100644 index 0000000000..bfccddcbcc --- /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/InstantiateNsTaskTest.java @@ -0,0 +1,319 @@ +/*- + * ============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 static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.notFound; +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.put; +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; +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.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_REST_TEMPLATE_BEAN; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterConfiguration.SOL003_ADAPTER_REST_TEMPLATE_BEAN; +import static org.springframework.test.web.client.ExpectedCount.times; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Optional; +import java.util.UUID; +import java.util.stream.Collectors; +import org.camunda.bpm.engine.history.HistoricProcessInstance; +import org.camunda.bpm.engine.history.HistoricVariableInstance; +import org.hamcrest.text.MatchesPattern; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStatusRetrievalStatusEnum; +import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.NsdInfo; +import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.etsicatalog.model.VnfPkgInfo; +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.nsd.NetworkServiceDescriptor; +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.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; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.GsonHttpMessageConverter; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.web.client.RestTemplate; +import com.google.gson.Gson; + +/** + * @author Andrew Lamb (andrew.a.lamb@est.tech) + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class InstantiateNsTaskTest extends BaseTest { + + private static final String TENANT_ID = "6ca8680feba04dad9254f423c6e28e1c"; + private static final String CLOUD_REGION = "regionOne"; + private static final String CLOUD_OWNER = "CloudOwner"; + private static final String UUID_REGEX = + "[0-9a-zA-Z]{8}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{4}\\-[0-9a-zA-Z]{12}"; + private static final String VCPE_VBRGEMU_VNFD_ID = "b1bb0ce7-2222-4fa7-95ed-4840d70a1102"; + private static final String VCPE_VBNG = "b1bb0ce7-2222-4fa7-95ed-4840d70a1101"; + private static final String VCPE_INFRA_VNFD_ID = "b1bb0ce7-2222-4fa7-95ed-4840d70a1100"; + private static final String VGMUX_VNFD_ID = "0408f076-e6c0-4c82-9940-272fddbb82de"; + private static final String VGW_VNFD_ID = "3fca3543-07f5-492f-812c-ed462e4f94f4"; + private static final String[] VCPE_VNFDS = + new String[] {VGW_VNFD_ID, VGMUX_VNFD_ID, VCPE_INFRA_VNFD_ID, VCPE_VBNG, VCPE_VBRGEMU_VNFD_ID}; + private static final String SAMPLE_NSD_FILE = "src/test/resources/ns.csar"; + private static final String NS_NAME = "InstantiateNetworkService"; + + @Autowired + private DatabaseServiceProvider databaseServiceProvider; + + @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 + private JobExecutorService objUnderTest; + + @Autowired + private GsonProvider gsonProvider; + + private Gson gson; + + private static final Map<String, String> VNFD_ID_TO_VNFPKG_ID_MAPPING = new HashMap<>(); + static { + for (final String vnfd : VCPE_VNFDS) { + VNFD_ID_TO_VNFPKG_ID_MAPPING.put(vnfd, UUID.randomUUID().toString()); + } + } + + @Before + 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 + public void testInstantiateNsWorkflow_JustUpdateStatus_SuccessfullCase() throws InterruptedException, IOException { + final String nsdId = UUID.randomUUID().toString(); + final String nsdName = NS_NAME + "-" + System.currentTimeMillis(); + + final NfvoNsInst newNfvoNsInst = new NfvoNsInst().nsInstId(nsdId).name(nsdName) + .nsPackageId(UUID.randomUUID().toString()).nsPackageId(nsdId).nsdId(nsdId).nsdInvariantId(nsdId) + .status(State.NOT_INSTANTIATED).statusUpdatedTime(LocalDateTime.now()); + + databaseServiceProvider.saveNfvoNsInst(newNfvoNsInst); + + mockSol003AdapterEndpoints(); + mockAAIEndpoints(nsdId); + mockEtsiCatalogEndpoints(nsdId); + + final String nsLcmOpOccId = + objUnderTest.runInstantiateNsJob(newNfvoNsInst.getNsInstId(), getInstantiateNsRequest()); + + final Optional<NfvoJob> optional = getJobByResourceId(newNfvoNsInst.getNsInstId()); + assertTrue(optional.isPresent()); + final NfvoJob nfvoJob = optional.get(); + + assertTrue(waitForProcessInstanceToFinish(nfvoJob.getProcessInstanceId())); + + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(nfvoJob.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + + // check if value in database has updated + final Optional<NfvoNsInst> optionalNfvoNsInst = databaseServiceProvider.getNfvoNsInst(nsdId); + final NfvoNsInst nfvoNsInst = optionalNfvoNsInst.get(); + assertEquals(State.INSTANTIATED, nfvoNsInst.getStatus()); + + final HistoricVariableInstance historicVariableInstance = + getVariable(nfvoJob.getProcessInstanceId(), NETWORK_SERVICE_DESCRIPTOR_PARAM_NAME); + assertNotNull(historicVariableInstance); + final NetworkServiceDescriptor nsd = (NetworkServiceDescriptor) historicVariableInstance.getValue(); + assertNotNull(nsd); + + assertEquals(VNFD_ID_TO_VNFPKG_ID_MAPPING.size(), nsd.getVnfs().size()); + + final List<NfvoNfInst> nfvoNfInsts = databaseServiceProvider.getNfvoNfInstByNsInstId(nsdId); + assertNotNull(nsd); + assertEquals(VNFD_ID_TO_VNFPKG_ID_MAPPING.size(), nfvoNfInsts.size()); + + final Optional<NsLcmOpOcc> optionalNsLcmOpOcc = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOccId); + assertTrue(optionalNsLcmOpOcc.isPresent()); + + assertEquals(OperationStateEnum.COMPLETED, optionalNsLcmOpOcc.get().getOperationState()); + + final Map<String, NfvoNfInst> nfvoNfInstsMap = + nfvoNfInsts.stream().collect(Collectors.toMap(NfvoNfInst::getVnfdId, nfvoNfInst -> nfvoNfInst)); + + for (final Entry<String, String> entry : VNFD_ID_TO_VNFPKG_ID_MAPPING.entrySet()) { + assertTrue(nfvoNfInstsMap.containsKey(entry.getKey())); + assertEquals(State.INSTANTIATED, nfvoNfInstsMap.get(entry.getKey()).getStatus()); + + } + + } + + private void mockSol003AdapterEndpoints() { + mockSol003AdapterRestServiceServer + .expect(times(VNFD_ID_TO_VNFPKG_ID_MAPPING.size()), + requestTo(MatchesPattern.matchesPattern(SOL003_ADAPTER_ENDPOINT_URL + "/vnfs/.*"))) + .andExpect(method(HttpMethod.POST)) + .andRespond(withSuccess(gson.toJson(new CreateVnfResponse().jobId(UUID.randomUUID().toString())), + MediaType.APPLICATION_JSON)); + + mockSol003AdapterRestServiceServer + .expect(times(VNFD_ID_TO_VNFPKG_ID_MAPPING.size()), + requestTo(MatchesPattern.matchesPattern(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/.*"))) + .andExpect(method(HttpMethod.GET)) + .andRespond(withSuccess(gson.toJson( + new org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse().operationState( + org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum.COMPLETED) + .operationStatusRetrievalStatus(OperationStatusRetrievalStatusEnum.STATUS_FOUND)), + MediaType.APPLICATION_JSON)); + } + + private void mockEtsiCatalogEndpoints(final String nsdId) throws IOException { + mockEtsiCatalogRestServiceServer.expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId)) + .andExpect(method(HttpMethod.GET)) + .andRespond(withSuccess(gson.toJson(getNSPackageModel(nsdId)), MediaType.APPLICATION_JSON)); + mockEtsiCatalogRestServiceServer + .expect(requestTo(ETSI_CATALOG_URL + "/nsd/v1/ns_descriptors/" + nsdId + "/nsd_content")) + .andExpect(method(HttpMethod.GET)).andRespond(withSuccess( + getFileContent(getAbsolutePath(SAMPLE_NSD_FILE)), MediaType.APPLICATION_OCTET_STREAM)); + + for (final Entry<String, String> entry : VNFD_ID_TO_VNFPKG_ID_MAPPING.entrySet()) { + mockEtsiCatalogRestServiceServer + .expect(requestTo(ETSI_CATALOG_URL + "/vnfpkgm/v1/vnf_packages/" + entry.getValue())) + .andExpect(method(HttpMethod.GET)).andRespond(withSuccess( + gson.toJson(getVnfPkgInfo(entry.getKey(), entry.getValue())), MediaType.APPLICATION_JSON)); + } + + } + + private VnfPkgInfo getVnfPkgInfo(final String vnfdId, final String vnfPkgId) { + return new VnfPkgInfo().id(vnfPkgId).vnfdId(vnfdId); + } + + private InstantiateNsRequest getInstantiateNsRequest() { + final Map<String, Object> additionalParams = new HashMap<>(); + additionalParams.put("vim_id", CLOUD_OWNER + "_" + CLOUD_REGION + "_" + TENANT_ID); + + final InstantiateNsRequest instantiateNsRequest = new InstantiateNsRequest().nsFlavourId("default"); + + for (final Entry<String, String> entry : VNFD_ID_TO_VNFPKG_ID_MAPPING.entrySet()) { + instantiateNsRequest + .addAdditionalParamsForVnfItem(new NsInstancesnsInstanceIdinstantiateAdditionalParamsForVnf() + .vnfProfileId(entry.getValue()).additionalParams(additionalParams)); + } + + return instantiateNsRequest; + } + + private NsdInfo getNSPackageModel(final String nsdId) { + return new NsdInfo().id(nsdId).nsdId(nsdId).nsdInvariantId(NSD_INVARIANT_ID).nsdName("vcpe").nsdDesigner("ONAP") + .vnfPkgIds(new ArrayList<>(VNFD_ID_TO_VNFPKG_ID_MAPPING.values())); + } + + private byte[] getFileContent(final String path) throws IOException { + return Files.readAllBytes(Paths.get(path)); + } + + + private String getAbsolutePath(final String path) { + return new File(path).getAbsolutePath(); + } + + private void mockAAIEndpoints(final String nsdId) { + final String modelEndpoint = "/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + UUID_REGEX; + wireMockServer.stubFor( + get(urlMatching(modelEndpoint + "\\?resultIndex=0&resultSize=1&format=count")).willReturn(notFound())); + + wireMockServer.stubFor(put(urlMatching(modelEndpoint)).willReturn(ok())); + wireMockServer.stubFor(put(urlMatching(modelEndpoint + "/relationship-list/relationship")).willReturn(ok())); + + wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok()) + .willReturn(okJson("{\"orchestration-status\": \"Created\"}"))); + + final String resourceType = "service-instance"; + final String resourceLink = "/aai/v20/business/customers/customer/" + GLOBAL_CUSTOMER_ID + + "/service-subscriptions/service-subscription/NetworkService/service-instances/service-instance/" + + nsdId; + + final String body = "{\n" + " \"results\": [{\n" + " \"resource-type\": \"" + resourceType + "\",\n" + + " \"resource-link\": \"" + resourceLink + "\"\n" + " }]\n" + "}"; + + wireMockServer.stubFor( + get(urlMatching("/aai/v[0-9]+/nodes/service-instances/service-instance/" + nsdId + "\\?format=pathed")) + .willReturn(okJson(body))); + + wireMockServer + .stubFor(put(urlMatching("/aai/v[0-9]+/cloud-infrastructure/cloud-regions/cloud-region/" + CLOUD_OWNER + + "/" + CLOUD_REGION + "/tenants/tenant/" + TENANT_ID + "/relationship-list/relationship")) + .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/MonitorInstantiateSol003AdapterNodeTaskTest.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/MonitorInstantiateSol003AdapterNodeTaskTest.java new file mode 100644 index 0000000000..ea720cd73b --- /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/MonitorInstantiateSol003AdapterNodeTaskTest.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.workflow.engine.tasks; + +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; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import org.camunda.bpm.engine.history.HistoricProcessInstance; +import org.camunda.bpm.engine.history.HistoricVariableInstance; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks.MonitorInstantiateSol003AdapterNodeTask; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class MonitorInstantiateSol003AdapterNodeTaskTest extends BaseTest { + + private static final String RANDOWM_GENERIC_VNF_ID = UUID.randomUUID().toString(); + private static final String MONITOR_SOL003_ADAPTER_CREATE_NODE_STATUS_WORKFLOW = + "MonitorSol003AdapterCreateNodeStatus"; + + @Before + public void before() { + wireMockServer.resetAll(); + } + + @Test + public void testMonitorSol003AdapterCreateNodeStatus_SuccessfullCase() throws InterruptedException { + + final String modelEndpoint = "/aai/v[0-9]+/network/generic-vnfs/generic-vnf/" + UUID_REGEX; + + wireMockServer.stubFor(get(urlMatching(modelEndpoint)).willReturn(ok()) + .willReturn(okJson("{\"orchestration-status\": \"Created\"}"))); + + + final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_CREATE_NODE_STATUS_WORKFLOW, + RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, RANDOWM_GENERIC_VNF_ID)); + + assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); + + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(processInstance.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + + final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), + MonitorInstantiateSol003AdapterNodeTask.CREATE_VNF_NODE_STATUS); + + assertNotNull(nsResponseVariable); + assertTrue((boolean) nsResponseVariable.getValue()); + + } + + private Map<String, Object> getVariables(final String jobId, final String vnfId) { + final Map<String, Object> variables = new HashMap<>(); + variables.put(CamundaVariableNameConstants.JOB_ID_PARAM_NAME, jobId); + variables.put(CamundaVariableNameConstants.NF_INST_ID_PARAM_NAME, vnfId); + + return variables; + } + + +} 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 new file mode 100644 index 0000000000..ff5c2a9105 --- /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/MonitorSol003AdapterCreateJobTaskTest.java @@ -0,0 +1,156 @@ +/*- + * ============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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStateEnum.COMPLETED; +import static org.onap.so.adapters.etsisol003adapter.lcm.v1.model.OperationStatusRetrievalStatusEnum.STATUS_FOUND; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterConfiguration.SOL003_ADAPTER_REST_TEMPLATE_BEAN; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; +import java.util.HashMap; +import java.util.Map; +import org.camunda.bpm.engine.history.HistoricProcessInstance; +import org.camunda.bpm.engine.history.HistoricVariableInstance; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Before; +import org.junit.Test; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.CreateVnfResponse; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.QueryJobResponse; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.BaseTest; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.GsonProvider; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.converter.json.GsonHttpMessageConverter; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.web.client.RestTemplate; +import com.google.gson.Gson; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class MonitorSol003AdapterCreateJobTaskTest extends BaseTest { + + private static final String MONITOR_SOL003_ADAPTER_CREATE_JOB_WORKFLOW = "MonitorSol003AdapterCreateJob"; + + @Autowired + @Qualifier(SOL003_ADAPTER_REST_TEMPLATE_BEAN) + private RestTemplate restTemplate; + + @Autowired + private GsonProvider gsonProvider; + + private MockRestServiceServer mockRestServiceServer; + private Gson gson; + + @Before + public void before() { + wireMockServer.resetAll(); + final MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(restTemplate); + builder.ignoreExpectOrder(true); + mockRestServiceServer = builder.build(); + + gson = gsonProvider.getGson(); + restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); + } + + + @Test + public void testMonitorSol003AdapterCreateJobTaskWorkflow_SuccessfullCase() throws InterruptedException { + + mockRestServiceServer.expect(requestTo(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/" + RANDOM_JOB_ID)) + .andExpect(method(HttpMethod.GET)) + .andRespond(withSuccess(gson.toJson(getQueryJobResponse()), MediaType.APPLICATION_JSON)); + + final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_CREATE_JOB_WORKFLOW, + RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, new CreateVnfResponse().jobId(RANDOM_JOB_ID))); + + assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); + + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(processInstance.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + + final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), + CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME); + + assertNotNull(nsResponseVariable); + assertEquals(COMPLETED, nsResponseVariable.getValue()); + + } + + @Test + public void testMonitorSol003AdapterCreateJobTaskWorkflow_FailurelCase() throws InterruptedException { + + mockRestServiceServer.expect(requestTo(SOL003_ADAPTER_ENDPOINT_URL + "/jobs/" + RANDOM_JOB_ID)) + .andExpect(method(HttpMethod.GET)).andRespond(withStatus(HttpStatus.NOT_FOUND)); + + final ProcessInstance processInstance = executeWorkflow(MONITOR_SOL003_ADAPTER_CREATE_JOB_WORKFLOW, + RANDOM_JOB_ID, getVariables(RANDOM_JOB_ID, new CreateVnfResponse().jobId(RANDOM_JOB_ID))); + + assertTrue(waitForProcessInstanceToFinish(processInstance.getProcessInstanceId())); + + final HistoricProcessInstance historicProcessInstance = + getHistoricProcessInstance(processInstance.getProcessInstanceId()); + assertNotNull(historicProcessInstance); + + assertEquals(HistoricProcessInstance.STATE_COMPLETED, historicProcessInstance.getState()); + + final HistoricVariableInstance nsResponseVariable = getVariable(processInstance.getProcessInstanceId(), + CamundaVariableNameConstants.OPERATION_STATUS_PARAM_NAME); + + assertNull(nsResponseVariable); + + final HistoricVariableInstance workflowExceptionVariable = getVariable(processInstance.getProcessInstanceId(), + CamundaVariableNameConstants.CREATE_NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME); + + final InlineResponse400 problemDetails = (InlineResponse400) workflowExceptionVariable.getValue(); + assertNotNull(problemDetails); + assertNotNull(problemDetails.getDetail()); + } + + + private QueryJobResponse getQueryJobResponse() { + return new QueryJobResponse().id(RANDOM_JOB_ID).operationState(COMPLETED) + .operationStatusRetrievalStatus(STATUS_FOUND); + } + + private Map<String, Object> getVariables(final String jobId, final CreateVnfResponse createVnfResponse) { + final Map<String, Object> variables = new HashMap<>(); + variables.put(CamundaVariableNameConstants.JOB_ID_PARAM_NAME, jobId); + variables.put(CamundaVariableNameConstants.CREATE_VNF_RESPONSE_PARAM_NAME, createVnfResponse); + + return variables; + } + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/application.yaml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/application.yaml new file mode 100644 index 0000000000..b17a5f2370 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/application.yaml @@ -0,0 +1,49 @@ +# Copyright © 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. +spring: + main: + allow-bean-definition-overriding: true + datasource: + hikari: + camunda: + jdbcUrl: jdbc:h2:mem:example-simple;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + driver-class-name: org.h2.Driver + pool-name: ns-lcm-bpmn-pool + registerMbeans: true + nfvo: + jdbcUrl: jdbc:h2:mem:nfvo;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS nfvo; + driver-class-name: org.h2.Driver + pool-name: ns-lcm-bpmn-pool + registerMbeans: true + jpa: + generate-ddl: true + hibernate: + ddl-auto: create +hibernate: + dialect: org.hibernate.dialect.H2Dialect + hbm2ddl: + auto: create +aai: + version: v19 + endpoint: http://localhost:${wiremock.server.port} +etsi-catalog-manager: + base: + endpoint: http://modeling-etsicatalog.onap:8806/api +so-etsi-ns-lcm-workflow-engine: + requesttimeout: + timeoutInSeconds: 10 + +logging: + level: + org.reflections.Reflections: ERROR
\ 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/test/resources/invalid_ns.csar b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/invalid_ns.csar Binary files differnew file mode 100644 index 0000000000..63bad965b7 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/invalid_ns.csar diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/ns.csar b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/ns.csar Binary files differnew file mode 100644 index 0000000000..eb19c762ae --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/test/resources/ns.csar 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 8e1fba43f0..e0439073bb 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 @@ -8,4 +8,28 @@ </parent> <artifactId>so-etsi-nfvo-ns-lcm-database-service</artifactId> <name>SO ETSI NFVO NS LCM Database Service</name> + <dependencies> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>org.mariadb.jdbc</groupId> + <artifactId>mariadb-java-client</artifactId> + </dependency> + <dependency> + <groupId>org.flywaydb</groupId> + <artifactId>flyway-core</artifactId> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-starter-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> </project>
\ No newline at end of file diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyTokenProvider.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/JobAction.java index 7c31d9288f..8a22689f8a 100644 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyTokenProvider.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/JobAction.java @@ -1,29 +1,29 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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; -package org.onap.so.cloudify.base.client; - -public interface CloudifyTokenProvider { - - String getToken(); - - void expireToken(); +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum JobAction { + CREATE, INSTANTIATE, TERMINATE, DELETE; } diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentStatus.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/JobStatusEnum.java index f7d6a9d214..c67a3cc692 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/beans/DeploymentStatus.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/JobStatusEnum.java @@ -1,31 +1,29 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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; -package org.onap.so.cloudify.beans; - - -/* - * Enum status values to capture the state of a deployment, based on last known workflow (assume only INSTALL and - * UNINSTALL at this point). +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * */ -public enum DeploymentStatus { - NOTFOUND, CREATED, INSTALLED, FAILED, INSTALLING, UNINSTALLING, UNKNOWN -} +public enum JobStatusEnum { + STARTING, STARTED, IN_PROGRESS, ERROR, FINISHED, FINISHED_WITH_ERROR; +} 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 new file mode 100644 index 0000000000..9453caac9e --- /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/NfvoJob.java @@ -0,0 +1,274 @@ +/*- + * ============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; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils; + + +@Entity +@Table(name = "JOB") +public class NfvoJob { + + @Id + @Column(name = "JOB_ID") + private String jobId; + + @Column(name = "JOB_TYPE") + private String jobType; + + @Enumerated(EnumType.STRING) + @Column(name = "JOB_ACTION") + private JobAction jobAction; + + @Column(name = "RESOURCE_ID") + private String resourceId; + + @Column(name = "RESOURCE_NAME") + private String resourceName; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS") + private JobStatusEnum status; + + @Column(name = "START_TIME") + private LocalDateTime startTime; + + @Column(name = "END_TIME") + private LocalDateTime endTime; + + @Column(name = "PROGRESS") + private int progress; + + @Column(name = "PROCESS_INSTANCE_ID") + private String processInstanceId; + + @OneToMany(mappedBy = "nfvoJob", cascade = CascadeType.ALL, fetch = FetchType.EAGER) + private List<NfvoJobStatus> nfvoJobStatuses = new ArrayList<>(); + + public NfvoJob() { + this.jobId = UUID.randomUUID().toString(); + } + + public void setJobId(final String jobId) { + this.jobId = jobId; + } + + public String getJobId() { + return jobId; + } + + public NfvoJob jobId(final String jobId) { + this.jobId = jobId; + return this; + } + + public String getJobType() { + return jobType; + } + + public void setJobType(final String jobType) { + this.jobType = jobType; + } + + public NfvoJob jobType(final String jobType) { + this.jobType = jobType; + return this; + } + + public JobAction getJobAction() { + return jobAction; + } + + public void setJobAction(final JobAction jobAction) { + this.jobAction = jobAction; + } + + public NfvoJob jobAction(final JobAction jobAction) { + this.jobAction = jobAction; + return this; + } + + public String getResourceId() { + return resourceId; + } + + public void setResourceId(final String resourceId) { + this.resourceId = resourceId; + } + + public NfvoJob resourceId(final String resourceId) { + this.resourceId = resourceId; + return this; + } + + public JobStatusEnum getStatus() { + return status; + } + + public void setStatus(final JobStatusEnum status) { + this.status = status; + } + + public NfvoJob status(final JobStatusEnum status) { + this.status = status; + return this; + } + + public LocalDateTime getStartTime() { + return startTime; + } + + public void setStartTime(final LocalDateTime startTime) { + this.startTime = startTime; + } + + public NfvoJob startTime(final LocalDateTime startTime) { + this.startTime = startTime; + return this; + } + + public LocalDateTime getEndTime() { + return endTime; + } + + public void setEndTime(final LocalDateTime endTime) { + this.endTime = endTime; + } + + public NfvoJob endTime(final LocalDateTime endTime) { + this.endTime = endTime; + return this; + } + + public int getProgress() { + return progress; + } + + public void setProgress(final int progress) { + this.progress = progress; + } + + public NfvoJob progress(final int progress) { + this.progress = progress; + return this; + } + + public String getProcessInstanceId() { + return processInstanceId; + } + + public void setProcessInstanceId(final String processInstanceId) { + this.processInstanceId = processInstanceId; + } + + public NfvoJob processInstanceId(final String processInstanceId) { + this.processInstanceId = processInstanceId; + return this; + } + + public String getResourceName() { + return resourceName; + } + + public void setResourceName(final String resourceName) { + this.resourceName = resourceName; + } + + public NfvoJob resourceName(final String resourceName) { + this.resourceName = resourceName; + return this; + } + + public List<NfvoJobStatus> getNfvoJobStatuses() { + return nfvoJobStatuses; + } + + public void setJobStatuses(final List<NfvoJobStatus> nfvoJobStatuses) { + this.nfvoJobStatuses = nfvoJobStatuses; + } + + public NfvoJob nfvoJobStatuses(final List<NfvoJobStatus> nfvoJobStatuses) { + this.nfvoJobStatuses = nfvoJobStatuses; + return this; + } + + public NfvoJob nfvoJobStatus(final NfvoJobStatus nfvoJobStatus) { + nfvoJobStatus.setNfvoJob(this); + this.nfvoJobStatuses.add(nfvoJobStatus); + return this; + } + + @Override + public int hashCode() { + return Objects.hash(jobId, processInstanceId, jobType, jobAction, startTime, endTime, status, progress, + resourceId, resourceName, nfvoJobStatuses); + } + + @Override + public boolean equals(final Object obj) { + 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) + && Utils.isEquals(nfvoJobStatuses, other.nfvoJobStatuses); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoJob {\n"); + sb.append(" jobId: ").append(toIndentedString(jobId)).append("\n"); + sb.append(" processInstanceId: ").append(toIndentedString(processInstanceId)).append("\n"); + sb.append(" jobType: ").append(toIndentedString(jobType)).append("\n"); + sb.append(" jobAction: ").append(toIndentedString(jobAction)).append("\n"); + sb.append(" progress: ").append(toIndentedString(progress)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" startTime: ").append(toIndentedString(startTime)).append("\n"); + sb.append(" endTime: ").append(toIndentedString(endTime)).append("\n"); + sb.append(" resId: ").append(toIndentedString(resourceId)).append("\n"); + sb.append(" resName: ").append(toIndentedString(resourceName)).append("\n"); + sb.append(" nfvoJobStatuses: ").append(toIndentedString(nfvoJobStatuses)).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/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 new file mode 100644 index 0000000000..89e07701ed --- /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/NfvoJobStatus.java @@ -0,0 +1,147 @@ +/*- + * ============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; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.time.LocalDateTime; +import java.util.Objects; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "JOB_STATUS") +public class NfvoJobStatus { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ID") + private int id; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS") + private JobStatusEnum status; + + @Column(name = "DESCRIPTION", columnDefinition = "LONGTEXT") + private String description; + + @Column(name = "UPDATED_TIME") + private LocalDateTime updatedTime; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "JOB_ID") + private NfvoJob nfvoJob; + + public int getId() { + return id; + } + + public JobStatusEnum getStatus() { + return status; + } + + public void setStatus(final JobStatusEnum status) { + this.status = status; + } + + public NfvoJobStatus status(final JobStatusEnum status) { + this.status = status; + return this; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public NfvoJobStatus description(final String description) { + this.description = description; + return this; + } + + public LocalDateTime getUpdatedTime() { + return updatedTime; + } + + public void setUpdatedTime(final LocalDateTime updatedTime) { + this.updatedTime = updatedTime; + } + + public NfvoJobStatus updatedTime(final LocalDateTime addTime) { + this.updatedTime = addTime; + return this; + } + + public NfvoJob getNfvoJob() { + return nfvoJob; + } + + public void setNfvoJob(final NfvoJob nfvoJob) { + this.nfvoJob = nfvoJob; + } + + public NfvoJobStatus nfvoJob(final NfvoJob nfvoJob) { + this.nfvoJob = nfvoJob; + return this; + } + + + @Override + public int hashCode() { + return Objects.hash(id, status, updatedTime, description, nfvoJob.getJobId()); + } + + @Override + public boolean equals(final Object obj) { + + 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()); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoJobStatus {\n"); + sb.append(" Id: ").append(toIndentedString(id)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" descp: ").append(toIndentedString(description)).append("\n"); + sb.append(" updatedTime: ").append(toIndentedString(updatedTime)).append("\n"); + sb.append(" jobId: ").append(nfvoJob != null ? toIndentedString(nfvoJob.getJobId()) : "").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/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 new file mode 100644 index 0000000000..e901e10596 --- /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/NfvoNfInst.java @@ -0,0 +1,213 @@ +/*- + * ============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; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.time.LocalDateTime; +import java.util.Objects; +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +/** + * @author mukeshsharma (mukeshsharma@est.tech) + */ +@Entity +@Table(name = "NF_INST") +public class NfvoNfInst { + + @Id + @Column(name = "NF_INST_ID") + private String nfInstId; + + @Column(name = "NAME") + private String name; + + @Column(name = "VNFD_ID") + private String vnfdId; + + @Column(name = "PACKAGE_ID") + private String packageId; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "NS_INST_ID") + private NfvoNsInst nsInst; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS") + private State status; + + @Column(name = "CREATE_TIME") + private LocalDateTime createTime; + + @Column(name = "LAST_UPDATE_TIME") + private LocalDateTime lastUpdateTime; + + public NfvoNfInst() { + this.nfInstId = UUID.randomUUID().toString(); + } + + public String getNfInstId() { + return nfInstId; + } + + public void setNfInstId(final String nfInstId) { + this.nfInstId = nfInstId; + } + + public NfvoNfInst nfInstId(final String nfInstId) { + this.nfInstId = nfInstId; + return this; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public NfvoNfInst name(final String name) { + this.name = name; + return this; + } + + public String getVnfdId() { + return vnfdId; + } + + public void setVnfdId(final String vnfdId) { + this.vnfdId = vnfdId; + } + + public NfvoNfInst vnfdId(final String vnfdId) { + this.vnfdId = vnfdId; + return this; + } + + public String getPackageId() { + return packageId; + } + + public void setPackageId(final String packageId) { + this.packageId = packageId; + } + + public NfvoNfInst packageId(final String packageId) { + this.packageId = packageId; + return this; + } + + public NfvoNsInst getNsInst() { + return nsInst; + } + + public void setNsInst(final NfvoNsInst nsInst) { + this.nsInst = nsInst; + } + + public NfvoNfInst nfvoNsInst(final NfvoNsInst nfvoNsInst) { + this.nsInst = nfvoNsInst; + return this; + } + + public State getStatus() { + return status; + } + + public void setStatus(final State status) { + this.status = status; + } + + public NfvoNfInst status(final State status) { + this.status = status; + return this; + } + + public LocalDateTime getCreateTime() { + return createTime; + } + + public void setCreateTime(final LocalDateTime createTime) { + this.createTime = createTime; + } + + public NfvoNfInst createTime(final LocalDateTime createTime) { + this.createTime = createTime; + return this; + } + + public LocalDateTime getLastUpdateTime() { + return lastUpdateTime; + } + + public void setLastUpdateTime(final LocalDateTime lastUpdateTime) { + this.lastUpdateTime = lastUpdateTime; + } + + public NfvoNfInst lastUpdateTime(final LocalDateTime lastUpdateTime) { + this.lastUpdateTime = lastUpdateTime; + return this; + } + + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null || getClass() != object.getClass()) + return false; + 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); + } + + @Override + public int hashCode() { + return Objects.hash(nfInstId, name, vnfdId, packageId, nsInst, status, createTime, lastUpdateTime); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoNfInst {\n"); + sb.append(" nfInstId: ").append(toIndentedString(nfInstId)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" vnfdId: ").append(toIndentedString(vnfdId)).append("\n"); + sb.append(" packageId: ").append(toIndentedString(packageId)).append("\n"); + sb.append(" nsInst: ").append(nsInst != null ? toIndentedString(nsInst.getNsInstId()) : null).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" createTime: ").append(toIndentedString(createTime)).append("\n"); + sb.append(" lastUpdateTime: ").append(toIndentedString(lastUpdateTime)).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/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 new file mode 100644 index 0000000000..dd8448fe56 --- /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/NfvoNsInst.java @@ -0,0 +1,289 @@ +/*- + * ============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; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.UUID; +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Entity +@Table(name = "NS_INST") +public class NfvoNsInst { + + @Id + @Column(name = "NS_INST_ID") + private String nsInstId; + + @Column(name = "NAME") + private String name; + + @Column(name = "NS_PACKAGE_ID") + private String nsPackageId; + + @Column(name = "NSD_ID") + private String nsdId; + + @Column(name = "NSD_INVARIANT_ID") + private String nsdInvariantId; + + @Column(name = "DESCRIPTION", columnDefinition = "LONGTEXT") + private String description; + + @Enumerated(EnumType.STRING) + @Column(name = "STATUS") + private State status; + + @Column(name = "STATUS_UPDATED_TIME") + private LocalDateTime statusUpdatedTime; + + @Column(name = "GLOBAL_CUSTOMER_ID") + private String globalCustomerId; + + @Column(name = "SERVICE_TYPE") + private String serviceType; + + @OneToMany(mappedBy = "nsInst", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List<NfvoNfInst> nfvoNfInsts = new ArrayList<>(); + + @OneToMany(mappedBy = "nfvoNsInst", cascade = CascadeType.ALL, fetch = FetchType.LAZY) + private List<NsLcmOpOcc> nsLcmOpOccs = new ArrayList<>(); + + public NfvoNsInst() { + this.nsInstId = UUID.randomUUID().toString(); + } + + public String getNsInstId() { + return nsInstId; + } + + public void setNsInstId(final String nsInstId) { + this.nsInstId = nsInstId; + } + + public NfvoNsInst nsInstId(final String nsInstId) { + this.nsInstId = nsInstId; + return this; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public NfvoNsInst name(final String name) { + this.name = name; + return this; + } + + public String getNsPackageId() { + return nsPackageId; + } + + public void setNsPackageId(final String nsPackageId) { + this.nsPackageId = nsPackageId; + } + + public NfvoNsInst nsPackageId(final String nsPackageId) { + this.nsPackageId = nsPackageId; + return this; + } + + public String getNsdId() { + return nsdId; + } + + public void setNsdId(final String nsdId) { + this.nsdId = nsdId; + } + + public NfvoNsInst nsdId(final String nsdId) { + this.nsdId = nsdId; + return this; + } + + public String getNsdInvariantId() { + return nsdInvariantId; + } + + public void setNsdInvariantId(final String nsdInvariantId) { + this.nsdInvariantId = nsdInvariantId; + } + + public NfvoNsInst nsdInvariantId(final String nsdInvariantId) { + this.nsdInvariantId = nsdInvariantId; + return this; + } + + public String getDescription() { + return description; + } + + public void setDescription(final String description) { + this.description = description; + } + + public NfvoNsInst description(final String description) { + this.description = description; + return this; + } + + public State getStatus() { + return status; + } + + public void setStatus(final State status) { + this.status = status; + } + + public NfvoNsInst status(final State status) { + this.status = status; + return this; + } + + public LocalDateTime getStatusUpdatedTime() { + return statusUpdatedTime; + } + + public void setStatusUpdatedTime(final LocalDateTime statusUpdatedTime) { + this.statusUpdatedTime = statusUpdatedTime; + } + + public NfvoNsInst statusUpdatedTime(final LocalDateTime statusUpdatedTime) { + this.statusUpdatedTime = statusUpdatedTime; + return this; + } + + public String getGlobalCustomerId() { + return globalCustomerId; + } + + public void setGlobalCustomerId(final String globalCustomerId) { + this.globalCustomerId = globalCustomerId; + } + + public NfvoNsInst globalCustomerId(final String globalCustomerId) { + this.globalCustomerId = globalCustomerId; + return this; + } + + public String getServiceType() { + return serviceType; + } + + public void setServiceType(final String serviceType) { + this.serviceType = serviceType; + } + + public NfvoNsInst serviceType(final String serviceType) { + this.serviceType = serviceType; + return this; + } + + public List<NfvoNfInst> getNfvoNfInsts() { + return nfvoNfInsts; + } + + public void setNfvoNfInsts(final List<NfvoNfInst> nfvoNfInsts) { + this.nfvoNfInsts = nfvoNfInsts; + } + + public NfvoNsInst nfvoNfInsts(final NfvoNfInst nfvoNfInsts) { + nfvoNfInsts.nfvoNsInst(this); + this.nfvoNfInsts.add(nfvoNfInsts); + return this; + } + + public List<NsLcmOpOcc> getNsLcmOpOccs() { + return nsLcmOpOccs; + } + + public void setNsLcmOpOccs(final List<NsLcmOpOcc> nsLcmOpOccs) { + this.nsLcmOpOccs = nsLcmOpOccs; + } + + public NfvoNsInst nsLcmOpOccs(final NsLcmOpOcc nsLcmOpOcc) { + nsLcmOpOcc.nfvoNsInst(this); + this.nsLcmOpOccs.add(nsLcmOpOcc); + return this; + } + + @Override + public int hashCode() { + return Objects.hash(nsInstId, name, nsPackageId, nsdId, nsdInvariantId, description, status, statusUpdatedTime, + globalCustomerId, serviceType, nfvoNfInsts, nsLcmOpOccs); + } + + @Override + public boolean equals(final Object obj) { + if (obj instanceof NfvoNsInst) { + final NfvoNsInst other = (NfvoNsInst) obj; + return Objects.equals(nsInstId, other.nsInstId) && Objects.equals(name, other.name) + && Objects.equals(nsPackageId, other.nsPackageId) && Objects.equals(nsdId, other.nsdId) + && Objects.equals(nsdInvariantId, other.nsdInvariantId) + && Objects.equals(description, other.description) && Objects.equals(status, other.status) + && Objects.equals(statusUpdatedTime, other.statusUpdatedTime) + && Objects.equals(globalCustomerId, other.globalCustomerId) + && Objects.equals(serviceType, other.serviceType) && Objects.equals(nfvoNfInsts, other.nfvoNfInsts) + && Objects.equals(nsLcmOpOccs, other.nsLcmOpOccs); + } + return false; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoNsInst {\n"); + sb.append(" nsInstId: ").append(toIndentedString(nsInstId)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" nsPackageId: ").append(toIndentedString(nsPackageId)).append("\n"); + sb.append(" nsdId: ").append(toIndentedString(nsdId)).append("\n"); + sb.append(" nsdInvariantId: ").append(toIndentedString(nsdInvariantId)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" statusUpdatedTime: ").append(toIndentedString(statusUpdatedTime)).append("\n"); + sb.append(" globalCustomerId: ").append(toIndentedString(globalCustomerId)).append("\n"); + sb.append(" serviceType: ").append(toIndentedString(serviceType)).append("\n"); + sb.append(" nfvoNfInsts: ").append(toIndentedString(nfvoNfInsts)).append("\n"); + sb.append(" nsLcmOpOccs: ").append(toIndentedString(nsLcmOpOccs)).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/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 new file mode 100644 index 0000000000..cb8f92070a --- /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/NsLcmOpOcc.java @@ -0,0 +1,233 @@ +/*- + * ============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; + +import static org.onap.so.etsi.nfvo.ns.lcm.database.beans.utils.Utils.toIndentedString; +import java.time.LocalDateTime; +import java.util.Objects; +import java.util.UUID; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.FetchType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +/** + * @author mukeshsharma(mukeshsharma@est.tech) + */ +@Entity +@Table(name = "NS_LCM_OP_OCCS") +public class NsLcmOpOcc { + + @Id + @Column(name = "ID") + private String id; + + @Enumerated(EnumType.STRING) + @Column(name = "OPERATION_STATE") + private OperationStateEnum operationState; + + @Column(name = "STATE_ENTERED_TIME") + private LocalDateTime stateEnteredTime; + + @Column(name = "START_TIME") + private LocalDateTime startTime; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "NS_INST_ID") + private NfvoNsInst nfvoNsInst; + + @Enumerated(EnumType.STRING) + @Column(name = "OPERATION") + private NsLcmOpType operation; + + @Column(name = "IS_AUTO_INNOVATION") + private boolean isAutoInnovation; + + @Column(name = "OPERATION_PARAMS", columnDefinition = "LONGTEXT") + private String operationParams; + + @Column(name = "IS_CANCEL_PENDING") + private boolean isCancelPending; + + public NsLcmOpOcc() { + this.id = UUID.randomUUID().toString(); + } + + public String getId() { + return id; + } + + public void setId(final String id) { + this.id = id; + } + + public NsLcmOpOcc id(final String id) { + this.id = id; + return this; + } + + public OperationStateEnum getOperationState() { + return operationState; + } + + public void setOperationState(final OperationStateEnum operationState) { + this.operationState = operationState; + } + + public NsLcmOpOcc operationState(final OperationStateEnum operationState) { + this.operationState = operationState; + return this; + } + + public LocalDateTime getStateEnteredTime() { + return stateEnteredTime; + } + + public void setStateEnteredTime(final LocalDateTime stateEnteredTime) { + this.stateEnteredTime = stateEnteredTime; + } + + public NsLcmOpOcc stateEnteredTime(final LocalDateTime stateEnteredTime) { + this.stateEnteredTime = stateEnteredTime; + return this; + } + + public LocalDateTime getStartTime() { + return startTime; + } + + public void setStartTime(final LocalDateTime startTime) { + this.startTime = startTime; + } + + public NsLcmOpOcc startTime(final LocalDateTime startTime) { + this.startTime = startTime; + return this; + } + + public NfvoNsInst getNfvoNsInst() { + return nfvoNsInst; + } + + public void setNfvoNsInst(final NfvoNsInst nfvoNsInst) { + this.nfvoNsInst = nfvoNsInst; + } + + public NsLcmOpOcc nfvoNsInst(final NfvoNsInst nfvoNsInst) { + this.nfvoNsInst = nfvoNsInst; + return this; + } + + public NsLcmOpType getOperation() { + return operation; + } + + public void setOperation(final NsLcmOpType operation) { + this.operation = operation; + } + + public NsLcmOpOcc operation(final NsLcmOpType operation) { + this.operation = operation; + return this; + } + + public boolean getIsAutoInnovation() { + return isAutoInnovation; + } + + public void setIsAutoInnovation(final boolean isAutoInnovation) { + this.isAutoInnovation = isAutoInnovation; + } + + public NsLcmOpOcc isAutoInnovation(final boolean isAutoInnovation) { + this.isAutoInnovation = isAutoInnovation; + return this; + } + + public String getOperationParams() { + return operationParams; + } + + public void setOperationParams(final String operationParams) { + this.operationParams = operationParams; + } + + public NsLcmOpOcc operationParams(final String operationParams) { + this.operationParams = operationParams; + return this; + } + + public boolean getIsCancelPending() { + return isCancelPending; + } + + public void setIsCancelPending(final boolean isCancelPending) { + this.isCancelPending = isCancelPending; + } + + public NsLcmOpOcc isCancelPending(final boolean isCancelPending) { + this.isCancelPending = isCancelPending; + return this; + } + + @Override + public boolean equals(final Object object) { + if (this == object) + return true; + if (object == null || getClass() != object.getClass()) + return false; + final NsLcmOpOcc that = (NsLcmOpOcc) object; + 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) + && Objects.equals(operationParams, that.operationParams) + && Objects.equals(isCancelPending, that.isCancelPending); + } + + @Override + public int hashCode() { + return Objects.hash(id, operationState, stateEnteredTime, startTime, nfvoNsInst, operation, isAutoInnovation, + operationParams, isCancelPending); + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("class NfvoNsInst {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" operationState: ").append(toIndentedString(operationState)).append("\n"); + sb.append(" stateEnteredTime: ").append(toIndentedString(stateEnteredTime)).append("\n"); + sb.append(" startTime: ").append(toIndentedString(startTime)).append("\n"); + 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(" operationParams: ").append(toIndentedString(operationParams)).append("\n"); + sb.append(" isCancelPending: ").append(toIndentedString(isCancelPending)).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/NsLcmOpType.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/NsLcmOpType.java new file mode 100644 index 0000000000..351f9611c5 --- /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/NsLcmOpType.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 Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum NsLcmOpType { + INSTANTIATE, TERMINATE, SCALE, UPDATE, HEAL; +} 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/OperationStateEnum.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/OperationStateEnum.java new file mode 100644 index 0000000000..236652e027 --- /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/OperationStateEnum.java @@ -0,0 +1,29 @@ +/*- + * ============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 Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum OperationStateEnum { + PROCESSING, COMPLETED, PARTIALLY_COMPLETED, FAILED_TEMP, FAILED, ROLLING_BACK, ROLLED_BACK; + +} 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/State.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/State.java new file mode 100644 index 0000000000..390c7fd776 --- /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/State.java @@ -0,0 +1,29 @@ +/*- + * ============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 Waqas Ikram (waqas.ikram@est.tech) + * + */ +public enum State { + NOT_INSTANTIATED, INSTANTIATING, INSTANTIATED, FAILED; + +} 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 new file mode 100644 index 0000000000..c55ef5728e --- /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/utils/Utils.java @@ -0,0 +1,58 @@ +/*- + * ============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.utils; + +import java.util.List; +import java.util.Objects; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class Utils { + + private Utils() {} + + public static final String toIndentedString(final Object object) { + return object == null ? "null" : object.toString().replace("\n", "\n "); + } + + + public static boolean isEquals(final List<?> first, List<?> second) { + if (first == null) { + return second == null; + } + if (first.isEmpty()) { + return second.isEmpty(); + } + if (first.size() == second.size()) { + for (int index = 0; index < first.size(); index++) { + if (!Objects.equals(first.get(index), second.get(index))) { + return false; + } + } + return true; + + } + 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/config/NfvoDatabaseConfiguration.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/config/NfvoDatabaseConfiguration.java new file mode 100644 index 0000000000..8f146e5378 --- /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/config/NfvoDatabaseConfiguration.java @@ -0,0 +1,87 @@ +/*- + * ============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.config; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jmx.export.MBeanExporter; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +@EnableTransactionManagement +@EnableJpaRepositories(entityManagerFactoryRef = "entityManagerFactory", + basePackages = {"org.onap.so.etsi.nfvo.ns.lcm.database.repository"}) +public class NfvoDatabaseConfiguration { + + private static final String PERSISTENCE_UNIT = "nfvo"; + private static final String NFVO_DATA_SOURCE_QUALIFIER = "nfvoDataSource"; + + @Autowired(required = false) + private MBeanExporter mBeanExporter; + + @Bean + @ConfigurationProperties(prefix = "spring.datasource.hikari.nfvo") + public HikariConfig nfvoDbConfig() { + return new HikariConfig(); + } + + @Bean(name = NFVO_DATA_SOURCE_QUALIFIER) + public DataSource dataSource() { + if (mBeanExporter != null) { + mBeanExporter.addExcludedBean(NFVO_DATA_SOURCE_QUALIFIER); + } + final HikariConfig hikariConfig = this.nfvoDbConfig(); + return new HikariDataSource(hikariConfig); + } + + @Primary + @Bean(name = "entityManagerFactory") + public LocalContainerEntityManagerFactoryBean entityManagerFactory(final EntityManagerFactoryBuilder builder, + @Qualifier(NFVO_DATA_SOURCE_QUALIFIER) final DataSource dataSource) { + return builder.dataSource(dataSource).packages(NfvoJob.class.getPackage().getName()) + .persistenceUnit(PERSISTENCE_UNIT).build(); + } + + @Primary + @Bean(name = "transactionManager") + public PlatformTransactionManager transactionManager( + @Qualifier("entityManagerFactory") final EntityManagerFactory entityManagerFactory) { + return new JpaTransactionManager(entityManagerFactory); + } + +} diff --git a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseStatus.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/repository/NSLcmOpOccRepository.java index ccdd7a4168..696c7be5dd 100644 --- a/cloudify-client/src/main/java/org/onap/so/cloudify/base/client/CloudifyResponseStatus.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/repository/NSLcmOpOccRepository.java @@ -1,37 +1,33 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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.repository; -package org.onap.so.cloudify.base.client; - -public class CloudifyResponseStatus { - - public static final int OK = 200; - - public static final int ACCEPTED = 201; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.springframework.data.repository.CrudRepository; +import java.util.Optional; - public static final int BAD_REQUEST = 400; - - public static final int NOT_AUTHORIZED = 401; - - public static final int NOT_FOUND = 404; - - public static final int CONFLICT = 409; +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * @author mukeshsharma(mukeshsharma@est.tech) + */ +public interface NSLcmOpOccRepository extends CrudRepository<NsLcmOpOcc, String> { + Optional<NsLcmOpOcc> findById(final String id); } 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/repository/NfvoJobRepository.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/repository/NfvoJobRepository.java new file mode 100644 index 0000000000..844f60827e --- /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/repository/NfvoJobRepository.java @@ -0,0 +1,35 @@ +/*- + * ============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.repository; + +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface NfvoJobRepository extends CrudRepository<NfvoJob, String> { + + Optional<NfvoJob> findByResourceId(final String resourceId); + + +} 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/repository/NfvoJobStatusRepository.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/repository/NfvoJobStatusRepository.java new file mode 100644 index 0000000000..c3fe469ff6 --- /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/repository/NfvoJobStatusRepository.java @@ -0,0 +1,30 @@ +/*- + * ============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.repository; + +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface NfvoJobStatusRepository extends CrudRepository<NfvoJobStatus, Integer> { +} diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoDeploymentAlreadyExists.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/repository/NfvoNfInstRepository.java index 62112f4feb..de14d43de4 100644 --- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/cloudify/exceptions/MsoDeploymentAlreadyExists.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/repository/NfvoNfInstRepository.java @@ -1,34 +1,38 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * 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.repository; -package org.onap.so.cloudify.exceptions; +import java.util.List; +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; +import org.springframework.data.repository.CrudRepository; -public class MsoDeploymentAlreadyExists extends MsoCloudifyException { +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * @author mukeshsharma(mukeshsharma@est.tech) + */ +public interface NfvoNfInstRepository extends CrudRepository<NfvoNfInst, String> { - private static final long serialVersionUID = 1L; + Optional<NfvoNfInst> findByNfInstId(final String nfInstId); - // Constructor to create a new MsoCloudifyException instance - public MsoDeploymentAlreadyExists(String deploymentId, String cloud) { - // Set the detailed error as the Exception 'message' - super(409, "Conflict", - "Deployment " + deploymentId + " already exists in Cloudify Manager suppporting cloud " + cloud); - } + List<NfvoNfInst> findByNsInstNsInstId(final String nsInstId); + List<NfvoNfInst> findByNsInstNsInstIdAndName(final String nsInstId, final String 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/repository/NfvoNsInstRepository.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/repository/NfvoNsInstRepository.java new file mode 100644 index 0000000000..beeeacf8cf --- /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/repository/NfvoNsInstRepository.java @@ -0,0 +1,39 @@ +/*- + * ============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.repository; + +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.springframework.data.repository.CrudRepository; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface NfvoNsInstRepository extends CrudRepository<NfvoNsInst, String> { + + Optional<NfvoNsInst> findByName(final String name); + + Optional<NfvoNsInst> findByNsInstId(final String nsInstId); + + boolean existsNfvoNsInstByName(final String 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/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 new file mode 100644 index 0000000000..368242515b --- /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/service/DatabaseServiceProvider.java @@ -0,0 +1,141 @@ +/*- + * ============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.service; + +import java.util.List; +import java.util.Optional; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; +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.repository.NSLcmOpOccRepository; +import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoJobRepository; +import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoNfInstRepository; +import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoNsInstRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ + +@Service +public class DatabaseServiceProvider { + private static final Logger logger = LoggerFactory.getLogger(DatabaseServiceProvider.class); + + private final NfvoJobRepository nfvoJobRepository; + + private final NfvoNsInstRepository nfvoNsInstRepository; + + private final NfvoNfInstRepository nfvoNfInstRepository; + + private final NSLcmOpOccRepository nsLcmOpOccRepository; + + @Autowired + public DatabaseServiceProvider(final NfvoJobRepository nfvoJobRepository, + final NfvoNsInstRepository nfvoNsInstRepository, final NfvoNfInstRepository nfvoNfInstRepository, + final NSLcmOpOccRepository nsLcmOpOccRepository) { + this.nfvoJobRepository = nfvoJobRepository; + this.nfvoNsInstRepository = nfvoNsInstRepository; + this.nfvoNfInstRepository = nfvoNfInstRepository; + this.nsLcmOpOccRepository = nsLcmOpOccRepository; + } + + public boolean addJob(final NfvoJob job) { + logger.info("Adding NfvoJob: {} to database", job); + return nfvoJobRepository.save(job) != null; + } + + public Optional<NfvoJob> getJob(final String jobId) { + logger.info("Querying database for NfvoJob using jobId: {}", jobId); + return nfvoJobRepository.findById(jobId); + } + + public Optional<NfvoJob> getJobByResourceId(final String resourceId) { + logger.info("Querying database for NfvoJob using resourceId: {}", resourceId); + return nfvoJobRepository.findByResourceId(resourceId); + } + + public boolean isNsInstExists(final String name) { + logger.info("Checking if NfvoNsInst entry exists in database using name: {}", name); + return nfvoNsInstRepository.existsNfvoNsInstByName(name); + } + + public boolean isNsInstExists(final String nsInstId, final String nfName) { + logger.info("Checking if NfvoNfInst entry exists in database using nsInstId: {} and nfName: {}", nsInstId, + nfName); + return nfvoNfInstRepository.findByNsInstNsInstIdAndName(nsInstId, nfName).isEmpty(); + } + + public boolean saveNfvoNsInst(final NfvoNsInst nfvoNsInst) { + logger.info("Saving NfvoNsInst: {} to database", nfvoNsInst); + return nfvoNsInstRepository.save(nfvoNsInst) != null; + } + + public Optional<NfvoNsInst> getNfvoNsInst(final String nsInstId) { + logger.info("Querying database for NfvoNsInst using nsInstId: {}", nsInstId); + return nfvoNsInstRepository.findById(nsInstId); + } + + public Optional<NfvoNsInst> getNfvoNsInstByName(final String name) { + logger.info("Querying database for NfvoNsInst using name: {}", name); + return nfvoNsInstRepository.findByName(name); + } + + public boolean saveNfvoNfInst(final NfvoNfInst nfvoNfInst) { + logger.info("Saving NfvoNfInst: {} to database", nfvoNfInst); + 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); + } + + public List<NfvoNfInst> getNfvoNfInstByNsInstIdAndNfName(final String nsInstId, final String name) { + logger.info("Querying database for NfvoNfInst using nsInstId: {} and name : {} ", nsInstId, name); + return nfvoNfInstRepository.findByNsInstNsInstIdAndName(nsInstId, name); + } + + public Optional<NfvoNfInst> getNfvoNfInst(final String nfInstId) { + logger.info("Querying database for NfvoNfInst using nfInstId: {}", nfInstId); + return nfvoNfInstRepository.findByNfInstId(nfInstId); + } + + public boolean addNSLcmOpOcc(final NsLcmOpOcc nsLcmOpOcc) { + logger.info("Adding NSLcmOpOcc: {} to database", nsLcmOpOcc); + return nsLcmOpOccRepository.save(nsLcmOpOcc) != null; + } + + public Optional<NsLcmOpOcc> getNsLcmOpOcc(final String id) { + logger.info("Querying database for NsLcmOpOcc using id: {}", id); + return nsLcmOpOccRepository.findById(id); + } + + +} 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 new file mode 100644 index 0000000000..f41a8206e0 --- /dev/null +++ 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 @@ -0,0 +1,74 @@ +use nfvo; + +CREATE TABLE IF NOT EXISTS `JOB` ( + `JOB_ID` varchar(255) NOT NULL, + `JOB_TYPE` varchar(255) NOT NULL, + `JOB_ACTION` varchar(255) NOT NULL, + `RESOURCE_ID` varchar(255) NOT NULL, + `RESOURCE_NAME` varchar(255) DEFAULT NULL, + `STATUS` varchar(255) NOT NULL, + `START_TIME` DATETIME DEFAULT NULL, + `END_TIME` DATETIME DEFAULT NULL, + `PROGRESS` int(11) DEFAULT NULL, + `PROCESS_INSTANCE_ID` varchar(255) DEFAULT NULL, + PRIMARY KEY (`JOB_ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + + + +CREATE TABLE IF NOT EXISTS `JOB_STATUS` ( + `ID` INT NOT NULL AUTO_INCREMENT, + `UPDATED_TIME` DATETIME NOT NULL, + `DESCRIPTION` longtext DEFAULT NULL, + `STATUS` varchar(255) NOT NULL, + `JOB_ID` varchar(255) NOT NULL, + PRIMARY KEY (`ID`), + FOREIGN KEY (JOB_ID) + REFERENCES JOB(JOB_ID) + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `NS_INST` ( + `NS_INST_ID` varchar(255) NOT NULL, + `NAME` varchar(255) NOT NULL, + `NS_PACKAGE_ID` varchar(255) DEFAULT NULL, + `NSD_ID` varchar(255) NOT NULL, + `NSD_INVARIANT_ID` varchar(255) NOT NULL, + `DESCRIPTION` longtext DEFAULT NULL, + `STATUS` varchar(255) NOT NULL, + `STATUS_UPDATED_TIME` DATETIME NOT NULL, + `GLOBAL_CUSTOMER_ID` varchar(255) DEFAULT NULL, + `SERVICE_TYPE` varchar(255) DEFAULT NULL, + PRIMARY KEY (`NS_INST_ID`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `NF_INST` ( + `NF_INST_ID` varchar(255) NOT NULL, + `NAME` varchar(255) DEFAULT NULL, + `VNFD_ID` varchar(255) DEFAULT NULL, + `PACKAGE_ID` varchar(255) DEFAULT NULL, + `NS_INST_ID` varchar(255) NOT NULL, + `STATUS` varchar(255) NOT NULL, + `CREATE_TIME` DATETIME DEFAULT NULL, + `LAST_UPDATE_TIME` DATETIME DEFAULT NULL, + PRIMARY KEY (`NF_INST_ID`), + FOREIGN KEY (NS_INST_ID) + REFERENCES NS_INST(NS_INST_ID) + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `NS_LCM_OP_OCCS` ( + `ID` varchar(255) NOT NULL, + `OPERATION_STATE` varchar(255) NOT NULL, + `STATE_ENTERED_TIME` DATETIME DEFAULT NULL, + `START_TIME` DATETIME DEFAULT NULL, + `NS_INST_ID` varchar(255) NOT NULL, + `OPERATION` varchar(255) NOT NULL, + `IS_AUTO_INNOVATION` varchar(255) NOT NULL, + `OPERATION_PARAMS` longtext NOT NULL, + `IS_CANCEL_PENDING` varchar(255) NOT NULL, + PRIMARY KEY (`ID`), + FOREIGN KEY (NS_INST_ID) + REFERENCES NS_INST(NS_INST_ID) + ON UPDATE CASCADE ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; 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 new file mode 100644 index 0000000000..42579fd5e8 --- /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/DatabaseServiceProviderTest.java @@ -0,0 +1,176 @@ +/*- + * ============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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Optional; +import java.util.UUID; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobAction; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; +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.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.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class DatabaseServiceProviderTest { + + private static final String RANDOM_ID = UUID.randomUUID().toString(); + private static final String DUMMY_NAME = "NAME"; + private static final LocalDateTime CURRENT_DATE_TIME = LocalDateTime.now(); + @Autowired + private DatabaseServiceProvider databaseServiceProvider; + + @Test + public void testAddJob_StoredInDatabase() { + final NfvoJob expected = new NfvoJob().jobType("TYPE").jobAction(JobAction.CREATE).resourceId(RANDOM_ID) + .resourceName(DUMMY_NAME).startTime(CURRENT_DATE_TIME).status(JobStatusEnum.STARTED); + databaseServiceProvider.addJob(expected); + + final Optional<NfvoJob> actual = databaseServiceProvider.getJob(expected.getJobId()); + assertEquals(expected, actual.get()); + } + + @Test + public void testAddJobWithJobStatus_StoredInDatabase() { + final NfvoJob job = new NfvoJob().jobType("TYPE").jobAction(JobAction.CREATE).resourceId(RANDOM_ID) + .resourceName(DUMMY_NAME).startTime(CURRENT_DATE_TIME).status(JobStatusEnum.STARTED); + databaseServiceProvider.addJob(job); + + final NfvoJobStatus jobStatus = new NfvoJobStatus().status(JobStatusEnum.STARTED) + .description("Create NS workflow process started").updatedTime(CURRENT_DATE_TIME); + databaseServiceProvider.addJob(job.nfvoJobStatus(jobStatus)); + + final Optional<NfvoJob> actual = databaseServiceProvider.getJob(job.getJobId()); + final NfvoJob actualNfvoJob = actual.get(); + + assertEquals(job.getJobId(), actualNfvoJob.getJobId()); + assertFalse(actualNfvoJob.getNfvoJobStatuses().isEmpty()); + assertEquals(job.getJobId(), actualNfvoJob.getNfvoJobStatuses().get(0).getNfvoJob().getJobId()); + + } + + @Test + public void testAddNsInst_StoredInDatabase_ableTofindByQuery() { + + final NfvoNsInst nsInst = new NfvoNsInst().name(DUMMY_NAME).nsdId(RANDOM_ID).status(State.NOT_INSTANTIATED) + .nsdInvariantId(RANDOM_ID).statusUpdatedTime(CURRENT_DATE_TIME); + + databaseServiceProvider.saveNfvoNsInst(nsInst); + + Optional<NfvoNsInst> actual = databaseServiceProvider.getNfvoNsInst(nsInst.getNsInstId()); + NfvoNsInst actualNfvoNsInst = actual.get(); + assertEquals(nsInst.getNsInstId(), actualNfvoNsInst.getNsInstId()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdId()); + assertEquals(State.NOT_INSTANTIATED, actualNfvoNsInst.getStatus()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdInvariantId()); + assertEquals(CURRENT_DATE_TIME, actualNfvoNsInst.getStatusUpdatedTime()); + + actual = databaseServiceProvider.getNfvoNsInstByName(DUMMY_NAME); + actualNfvoNsInst = actual.get(); + + assertEquals(nsInst.getNsInstId(), actualNfvoNsInst.getNsInstId()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdId()); + assertEquals(State.NOT_INSTANTIATED, actualNfvoNsInst.getStatus()); + assertEquals(RANDOM_ID, actualNfvoNsInst.getNsdInvariantId()); + assertEquals(CURRENT_DATE_TIME, actualNfvoNsInst.getStatusUpdatedTime()); + + + assertTrue(databaseServiceProvider.isNsInstExists(DUMMY_NAME)); + } + + @Test + public void testAddNfInst_StoredInDatabase_ableTofindByQuery() { + + final NfvoNsInst nsInst = new NfvoNsInst().name(DUMMY_NAME).nsdId(RANDOM_ID).status(State.NOT_INSTANTIATED) + .nsdInvariantId(RANDOM_ID).statusUpdatedTime(CURRENT_DATE_TIME); + + databaseServiceProvider.saveNfvoNsInst(nsInst); + + final NfvoNfInst nfInst = new NfvoNfInst().nfvoNsInst(nsInst).name(DUMMY_NAME).vnfdId(RANDOM_ID) + .status(State.NOT_INSTANTIATED).createTime(CURRENT_DATE_TIME).lastUpdateTime(CURRENT_DATE_TIME); + databaseServiceProvider.saveNfvoNfInst(nfInst); + + final Optional<NfvoNfInst> actual = databaseServiceProvider.getNfvoNfInstByNfInstId(nfInst.getNfInstId()); + final NfvoNfInst actualNfvoNfInst = actual.get(); + assertEquals(nsInst.getNsInstId(), actualNfvoNfInst.getNsInst().getNsInstId()); + assertEquals(nfInst.getNfInstId(), actualNfvoNfInst.getNfInstId()); + assertEquals(nfInst.getName(), actualNfvoNfInst.getName()); + assertEquals(nfInst.getVnfdId(), actualNfvoNfInst.getVnfdId()); + assertEquals(nfInst.getStatus(), actualNfvoNfInst.getStatus()); + assertEquals(nfInst.getCreateTime(), actualNfvoNfInst.getCreateTime()); + assertEquals(nfInst.getLastUpdateTime(), actualNfvoNfInst.getLastUpdateTime()); + + + List<NfvoNfInst> nfvoNfInstList = databaseServiceProvider.getNfvoNfInstByNsInstId(nsInst.getNsInstId()); + assertFalse(nfvoNfInstList.isEmpty()); + assertEquals(nsInst.getNsInstId(), nfvoNfInstList.get(0).getNsInst().getNsInstId()); + + nfvoNfInstList = databaseServiceProvider.getNfvoNfInstByNsInstIdAndNfName(nsInst.getNsInstId(), DUMMY_NAME); + + assertFalse(nfvoNfInstList.isEmpty()); + assertEquals(nsInst.getNsInstId(), nfvoNfInstList.get(0).getNsInst().getNsInstId()); + assertEquals(DUMMY_NAME, nfvoNfInstList.get(0).getName()); + } + + @Test + public void testAddNsLcmOpOcc_StoredInDatabase_ableTofindByQuery() { + + final NfvoNsInst nsInst = new NfvoNsInst().name(DUMMY_NAME).nsdId(RANDOM_ID).status(State.NOT_INSTANTIATED) + .nsdInvariantId(RANDOM_ID).statusUpdatedTime(CURRENT_DATE_TIME); + + databaseServiceProvider.saveNfvoNsInst(nsInst); + + final NsLcmOpOcc nsLcmOpOcc = new NsLcmOpOcc().nfvoNsInst(nsInst).operationState(OperationStateEnum.PROCESSING) + .isCancelPending(false).isAutoInnovation(false).operation(NsLcmOpType.INSTANTIATE) + .startTime(CURRENT_DATE_TIME).stateEnteredTime(CURRENT_DATE_TIME).operationParams(""); + + + databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc); + + final Optional<NsLcmOpOcc> actual = databaseServiceProvider.getNsLcmOpOcc(nsLcmOpOcc.getId()); + final NsLcmOpOcc actualLcmOpOcc = actual.get(); + assertEquals(nsLcmOpOcc.getId(), actualLcmOpOcc.getId()); + + assertEquals(nsInst.getNsInstId(), actualLcmOpOcc.getNfvoNsInst().getNsInstId()); + + } +} 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/TestApplication.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/TestApplication.java new file mode 100644 index 0000000000..921cae2343 --- /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/TestApplication.java @@ -0,0 +1,45 @@ +/*- + * ============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 org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.FilterType; +import org.springframework.context.annotation.ComponentScan.Filter; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@SpringBootApplication(scanBasePackages = {"org.onap.so"}) +@EnableAutoConfiguration(exclude = {JacksonAutoConfiguration.class}) +@ComponentScan(basePackages = {"org.onap"}, + excludeFilters = {@Filter(type = FilterType.ANNOTATION, classes = SpringBootApplication.class)}) +public class TestApplication { + + public static void main(final String[] args) { + new SpringApplication(TestApplication.class).run(args); + } + +} 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/beans/utils/UtilsTest.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/beans/utils/UtilsTest.java new file mode 100644 index 0000000000..632bda937c --- /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/beans/utils/UtilsTest.java @@ -0,0 +1,65 @@ +/*- + * ============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.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import java.util.Arrays; +import java.util.Collections; +import org.junit.Test; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public class UtilsTest { + + @Test + public void testTwoEmptyLists_equal() { + assertTrue(Utils.isEquals(Collections.emptyList(), Collections.emptyList())); + } + + @Test + public void testEmptyListAndNonEmpty_notEqual() { + assertFalse(Utils.isEquals(Collections.emptyList(), Arrays.asList("A"))); + } + + @Test + public void testTwoNullLists_equal() { + assertTrue(Utils.isEquals(null, null)); + } + + @Test + public void testNullListAndEmptyList_notEqual() { + assertFalse(Utils.isEquals(null, Collections.emptyList())); + } + + @Test + public void testTwoNotEmptyListsContainSameObjects_equal() { + assertTrue(Utils.isEquals(Arrays.asList("A"), Arrays.asList("A"))); + } + + @Test + public void testTwoNotEmptyListsContainsDifferentObjects_equal() { + assertFalse(Utils.isEquals(Arrays.asList("A"), Arrays.asList(1))); + } + + +} diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/resources/application.yaml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/resources/application.yaml new file mode 100644 index 0000000000..adc36aca1d --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/resources/application.yaml @@ -0,0 +1,31 @@ +# Copyright © 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. +spring: + main: + web-application-type: none + datasource: + hikari: + nfvo: + jdbcUrl: jdbc:h2:mem:nfvo;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS nfvo; + driver-class-name: org.h2.Driver + pool-name: ns-lcm-bpmn-pool + registerMbeans: true + jpa: + generate-ddl: true + hibernate: + ddl-auto: create +hibernate: + dialect: org.hibernate.dialect.H2Dialect + hbm2ddl: + auto: create
\ No newline at end of file diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/pom.xml b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/pom.xml index 2c3c394d01..6605602f53 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/pom.xml +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/pom.xml @@ -16,6 +16,11 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>org.onap.so.etsi.nfvo</groupId> + <artifactId>so-etsi-nfvo-ns-lcm-bpmn-flows</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <exclusions> @@ -50,9 +55,24 @@ <version>${project.version}</version> </dependency> <dependency> + <groupId>org.onap.so.etsi.nfvo</groupId> + <artifactId>so-etsi-nfvo-ns-lcm-bpmn-flows</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <scope>test</scope> + </dependency> + <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + <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-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/Constants.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/Constants.java index 97ad1743bc..d330df3bae 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/Constants.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/Constants.java @@ -1,19 +1,19 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. + * 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========================================================= */ 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/EtsiSoNsLcmManagerUrlProvider.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/EtsiSoNsLcmManagerUrlProvider.java new file mode 100644 index 0000000000..da1649de57 --- /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/EtsiSoNsLcmManagerUrlProvider.java @@ -0,0 +1,53 @@ +/*- + * ============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; + +import java.net.URI; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +public class EtsiSoNsLcmManagerUrlProvider { + + private final String etsiNsLcmManagerEndpoint; + + @Autowired + public EtsiSoNsLcmManagerUrlProvider( + @Value("${so-etsi-nfvo-ns-lcm.endpoint:http://so-etsi-nfvo-ns-lcm.onap:9095}") final String etsiNsLcmManagerEndpoint) { + this.etsiNsLcmManagerEndpoint = etsiNsLcmManagerEndpoint; + } + + public URI getCreatedNsResourceUri(final String nsInstanceId) { + return URI.create(etsiNsLcmManagerEndpoint + Constants.NS_LIFE_CYCLE_MANAGEMENT_BASE_URL + "/ns_instances/" + + nsInstanceId); + } + + public URI getInstantiatedOccUri(final String nsLcmOpOccId) { + return URI.create(etsiNsLcmManagerEndpoint + Constants.NS_LIFE_CYCLE_MANAGEMENT_BASE_URL + "/ns_lcm_op_occs/" + + nsLcmOpOccId); + } + +} 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/GsonSerializerConfiguration.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/GsonSerializerConfiguration.java new file mode 100644 index 0000000000..2e11adae01 --- /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/GsonSerializerConfiguration.java @@ -0,0 +1,42 @@ +/*- + * ============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; + +import java.time.LocalDateTime; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.utils.LocalDateTimeTypeAdapter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import com.google.gson.GsonBuilder; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +public class GsonSerializerConfiguration { + + @Bean + public GsonBuilder gsonBuilder() { + return new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeTypeAdapter()); + } + +} + + 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 new file mode 100644 index 0000000000..792ffdd00a --- /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/NsLifeCycleManager.java @@ -0,0 +1,77 @@ +/*- + * ============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 java.net.URI; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.onap.so.etsi.nfvo.ns.lcm.EtsiSoNsLcmManagerUrlProvider; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService; +import org.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest; +import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Service +public class NsLifeCycleManager { + private static final Logger logger = getLogger(NsLifeCycleManager.class); + + private final JobExecutorService jobExecutorService; + + @Value("${etsi-so-ns-workflow-engine.requesttimeout.create.timeoutInSeconds:300}") + private int timeOutInSeconds; + + private final EtsiSoNsLcmManagerUrlProvider etsiSoNsLcmManagerUrlProvider; + + @Autowired + public NsLifeCycleManager(final JobExecutorService jobExecutorService, + final EtsiSoNsLcmManagerUrlProvider etsiSoNsLcmManagerUrlProvider) { + this.jobExecutorService = jobExecutorService; + this.etsiSoNsLcmManagerUrlProvider = etsiSoNsLcmManagerUrlProvider; + } + + public ImmutablePair<URI, NsInstancesNsInstance> createNs(final CreateNsRequest createNsRequest, + final String globalCustomerId, final String serviceType) { + logger.info("Will execute Create Ns for CreateNsRequest: {}, globalCustomerId: {} and serviceType: {}", + createNsRequest, globalCustomerId, serviceType); + final NsInstancesNsInstance nsInstanceResponse = + jobExecutorService.runCreateNsJob(createNsRequest, globalCustomerId, serviceType); + + return ImmutablePair.of(etsiSoNsLcmManagerUrlProvider.getCreatedNsResourceUri(nsInstanceResponse.getId()), + nsInstanceResponse); + } + + public URI instantiateNs(final String nsInstanceId, final InstantiateNsRequest instantiateNsRequest) { + logger.info("Will execute Instantiate Ns for InstantiateNsRequest: {} and nsInstanceId: {}", + instantiateNsRequest, nsInstanceId); + final String nsLcmOpOccId = jobExecutorService.runInstantiateNsJob(nsInstanceId, instantiateNsRequest); + + return etsiSoNsLcmManagerUrlProvider.getInstantiatedOccUri(nsLcmOpOccId); + + } + +} 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 aed4f4b9dd..ec79ce6329 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 @@ -1,19 +1,19 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. + * 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========================================================= */ 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 4dd12589a0..87ec8420c6 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 @@ -1,19 +1,19 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix. All rights reserved. + * 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========================================================= */ @@ -24,12 +24,17 @@ import static org.onap.so.etsi.nfvo.ns.lcm.Constants.HTTP_SERVICETYPE_HEADER_DEF import static org.onap.so.etsi.nfvo.ns.lcm.Constants.HTTP_SERVICETYPE_HEADER_PARM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.Constants.NS_LIFE_CYCLE_MANAGEMENT_BASE_URL; import static org.slf4j.LoggerFactory.getLogger; +import java.net.URI; import javax.ws.rs.core.MediaType; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.onap.so.etsi.nfvo.ns.lcm.lifecycle.NsLifeCycleManager; import org.onap.so.etsi.nfvo.ns.lcm.model.Body; import org.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest; import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest; +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; @@ -53,6 +58,12 @@ import org.springframework.web.bind.annotation.RequestMapping; public class NsLifecycleManagementController { private static final Logger logger = getLogger(NsLifecycleManagementController.class); + private final NsLifeCycleManager nsLifeCycleManager; + + @Autowired + public NsLifecycleManagementController(final NsLifeCycleManager nsLifeCycleManager) { + this.nsLifeCycleManager = nsLifeCycleManager; + } /** * The POST method creates new {@link Body new NS instance resource} request. See Section Number: 6.3.1 for more @@ -74,7 +85,17 @@ public class NsLifecycleManagementController { @RequestBody final CreateNsRequest createNsRequest) { logger.info("Received Create NS Request: {}\n with globalCustomerId: {}\n serviceType: {}\n", createNsRequest, globalCustomerId, serviceType); - return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet"); + + final ImmutablePair<URI, NsInstancesNsInstance> nsInstance = + nsLifeCycleManager.createNs(createNsRequest, globalCustomerId, serviceType); + + final URI resourceUri = nsInstance.getLeft(); + final NsInstancesNsInstance createdNsresponse = nsInstance.getRight(); + + logger.info("NS resource created successfully. Resource location: {}, response: {}", resourceUri, + createdNsresponse); + + return ResponseEntity.created(resourceUri).body(createdNsresponse); } /** @@ -104,7 +125,10 @@ public class NsLifecycleManagementController { public ResponseEntity<?> instantiateNs(@PathVariable("nsInstanceId") final String nsInstanceId, @RequestBody final InstantiateNsRequest instantiateNsRequest) { logger.debug("Received instantiate NS request: {}\n with nsInstanceId: {}", instantiateNsRequest, nsInstanceId); - return ResponseEntity.status(HttpStatus.NOT_IMPLEMENTED).body("Operation is not supported yet"); + final URI resourceUri = nsLifeCycleManager.instantiateNs(nsInstanceId, instantiateNsRequest); + logger.info("{} Ns Instantiation started successfully. Resource Operation Occurrence uri: {}", nsInstanceId, + resourceUri); + return ResponseEntity.accepted().location(resourceUri).build(); } /** 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/exceptions/NsLcmControllerExceptionHandler.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/exceptions/NsLcmControllerExceptionHandler.java new file mode 100644 index 0000000000..3db04fcfe8 --- /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/rest/exceptions/NsLcmControllerExceptionHandler.java @@ -0,0 +1,58 @@ +/*- + * ============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.rest.exceptions; + +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.exceptions.NsRequestProcessingException; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; +import org.onap.so.etsi.nfvo.ns.lcm.rest.NsLifecycleManagementController; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@ControllerAdvice(assignableTypes = NsLifecycleManagementController.class) +public class NsLcmControllerExceptionHandler { + + @ExceptionHandler(NsRequestProcessingException.class) + public ResponseEntity<InlineResponse400> handleNsRequestProcessingException( + final NsRequestProcessingException nsRequestProcessingException) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) + .body(getInlineResponse400(nsRequestProcessingException)); + } + + @ExceptionHandler(Exception.class) + public ResponseEntity<InlineResponse400> handleNsRequestProcessingException(final Exception exception) { + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(new InlineResponse400() + .status(HttpStatus.INTERNAL_SERVER_ERROR.value()).detail(exception.getMessage())); + } + + private InlineResponse400 getInlineResponse400(final NsRequestProcessingException nsRequestProcessingException) { + if (nsRequestProcessingException.getProblemDetails() != null) { + return nsRequestProcessingException.getProblemDetails(); + } + return new InlineResponse400().status(HttpStatus.INTERNAL_SERVER_ERROR.value()) + .detail(nsRequestProcessingException.getMessage()); + } + +} 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/TestApplication.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/TestApplication.java index 6e5f6c0467..d6f4a83811 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/TestApplication.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/TestApplication.java @@ -1,19 +1,19 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. + * 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========================================================= */ 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 ae491b6f1e..9eace927d6 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 @@ -1,19 +1,19 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. + * 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========================================================= */ 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 6f25092050..81c4e8fd68 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 @@ -1,19 +1,19 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Ericsson. All rights reserved. + * 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========================================================= */ @@ -24,18 +24,30 @@ 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 static org.mockito.ArgumentMatchers.eq; +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; 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.bpmn.flows.exceptions.NsRequestProcessingException; +import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.service.JobExecutorService; import org.onap.so.etsi.nfvo.ns.lcm.model.CreateNsRequest; +import org.onap.so.etsi.nfvo.ns.lcm.model.InlineResponse400; import org.onap.so.etsi.nfvo.ns.lcm.model.InstantiateNsRequest; +import org.onap.so.etsi.nfvo.ns.lcm.model.NsInstancesNsInstance; import org.onap.so.etsi.nfvo.ns.lcm.model.TerminateNsRequest; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.boot.web.server.LocalServerPort; @@ -57,27 +69,107 @@ import com.google.gson.Gson; @SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @ActiveProfiles("test") public class NsLifecycleManagementControllerTest { + private static final String EXPECTED_BASE_URL = + "http://so-etsi-nfvo-ns-lcm.onap:9095/so/so-etsi-nfvo-ns-lcm/v1/api/nslcm/v1"; + private static final String RANDOM_NS_LCM_OP_OCC_ID = UUID.randomUUID().toString(); + private static final String RANDOM_NS_INST_ID = UUID.randomUUID().toString(); + private static final String SERVICE_TYPE = "NetworkService"; + private static final String GLOBAL_CUSTOMER_ID = UUID.randomUUID().toString(); + private static final String EXPECTED_CREATE_REQ_LOCATION_URL = + EXPECTED_BASE_URL + "/ns_instances/" + RANDOM_NS_INST_ID; + private static final String EXPECTED_INSTANTIATE_REQ_LOCATION_URL = + EXPECTED_BASE_URL + "/ns_lcm_op_occs/" + RANDOM_NS_LCM_OP_OCC_ID; + @LocalServerPort private int port; private TestRestTemplate testRestTemplate; + @Autowired + private GsonProvider gsonProvider; + + @MockBean + private JobExecutorService mockedJobExecutorService; + @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 testCreateNs_ValidCreateNsRequest() { + public void testCreateNs_ValidCreateNsRequest() throws URISyntaxException { + + final CreateNsRequest createNsRequest = getCreateNsRequest(); + + when(mockedJobExecutorService.runCreateNsJob(eq(createNsRequest), eq(GLOBAL_CUSTOMER_ID), eq(SERVICE_TYPE))) + .thenReturn(new NsInstancesNsInstance().id(RANDOM_NS_INST_ID)); + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances"; final HttpHeaders headers = new HttpHeaders(); - headers.add(Constants.HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME, "GLOBAL_CUSTOMER_ID"); - final HttpEntity<?> request = new HttpEntity<>(getCreateNsRequest(), headers); - final ResponseEntity<Void> responseEntity = - testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, Void.class); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); + headers.add(Constants.HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME, GLOBAL_CUSTOMER_ID); + final HttpEntity<?> request = new HttpEntity<>(createNsRequest, headers); + final ResponseEntity<NsInstancesNsInstance> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, NsInstancesNsInstance.class); + assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); + + final HttpHeaders httpHeaders = responseEntity.getHeaders(); + assertTrue(httpHeaders.containsKey(HttpHeaders.LOCATION)); + final List<String> actual = httpHeaders.get(HttpHeaders.LOCATION); + assertEquals(1, actual.size()); + assertEquals(EXPECTED_CREATE_REQ_LOCATION_URL, actual.get(0)); + } + + @Test + public void testCreateNs_createNsRequest_nsRequestProcessingExceptionThrown_returnInlineResponse400() + throws URISyntaxException { + + final CreateNsRequest createNsRequest = getCreateNsRequest(); + + final String message = "Unable to process request"; + when(mockedJobExecutorService.runCreateNsJob(eq(createNsRequest), eq(GLOBAL_CUSTOMER_ID), eq(SERVICE_TYPE))) + .thenThrow(new NsRequestProcessingException(message, new InlineResponse400().detail(message))); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances"; + final HttpHeaders headers = new HttpHeaders(); + headers.add(Constants.HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME, GLOBAL_CUSTOMER_ID); + final HttpEntity<?> request = new HttpEntity<>(createNsRequest, headers); + final ResponseEntity<InlineResponse400> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, InlineResponse400.class); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); + + final InlineResponse400 body = responseEntity.getBody(); + assertEquals(message, body.getDetail()); + + } + + @Test + public void testCreateNs_createNsRequest_exceptionThrown_returnInlineResponse400() throws URISyntaxException { + + final CreateNsRequest createNsRequest = getCreateNsRequest(); + + final String message = "Unable to process request"; + when(mockedJobExecutorService.runCreateNsJob(eq(createNsRequest), eq(GLOBAL_CUSTOMER_ID), eq(SERVICE_TYPE))) + .thenThrow(new RuntimeException(message)); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances"; + final HttpHeaders headers = new HttpHeaders(); + headers.add(Constants.HTTP_GLOBAL_CUSTOMER_ID_HTTP_HEADER_PARM_NAME, GLOBAL_CUSTOMER_ID); + final HttpEntity<?> request = new HttpEntity<>(createNsRequest, headers); + final ResponseEntity<InlineResponse400> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, InlineResponse400.class); + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); + + final InlineResponse400 body = responseEntity.getBody(); + assertEquals(message, body.getDetail()); + } @Test @@ -90,11 +182,39 @@ public class NsLifecycleManagementControllerTest { @Test public void testInstantiateNs_ValidInstantiateNsRequest() { - final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + UUID.randomUUID().toString() + "/instantiate"; - final HttpEntity<?> request = new HttpEntity<>(getInstantiateNsRequest()); + + final InstantiateNsRequest instantiateNsRequest = getInstantiateNsRequest(); + when(mockedJobExecutorService.runInstantiateNsJob(eq(RANDOM_NS_INST_ID), eq(instantiateNsRequest))) + .thenReturn(RANDOM_NS_LCM_OP_OCC_ID); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + RANDOM_NS_INST_ID + "/instantiate"; + final HttpEntity<?> request = new HttpEntity<>(instantiateNsRequest); final ResponseEntity<Void> responseEntity = testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, Void.class); - assertEquals(HttpStatus.NOT_IMPLEMENTED, responseEntity.getStatusCode()); + assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode()); + + final HttpHeaders httpHeaders = responseEntity.getHeaders(); + assertTrue(httpHeaders.containsKey(HttpHeaders.LOCATION)); + final List<String> actual = httpHeaders.get(HttpHeaders.LOCATION); + assertEquals(1, actual.size()); + assertEquals(EXPECTED_INSTANTIATE_REQ_LOCATION_URL, actual.get(0)); + } + + @Test + public void testInstantiateNs_instantiateNsRequest_nsRequestProcessingExceptionThrown_returnInlineResponse400() { + final String message = "Unable to process request"; + final InstantiateNsRequest instantiateNsRequest = getInstantiateNsRequest(); + when(mockedJobExecutorService.runInstantiateNsJob(eq(RANDOM_NS_INST_ID), eq(instantiateNsRequest))) + .thenThrow(new NsRequestProcessingException(message, new InlineResponse400().detail(message))); + + final String baseUrl = getNsLcmBaseUrl() + "/ns_instances/" + RANDOM_NS_INST_ID + "/instantiate"; + final HttpEntity<?> request = new HttpEntity<>(instantiateNsRequest); + final ResponseEntity<InlineResponse400> responseEntity = + testRestTemplate.exchange(baseUrl, HttpMethod.POST, request, InlineResponse400.class); + + assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); + assertTrue(responseEntity.hasBody()); + assertNotNull(responseEntity.getBody()); } @Test @@ -116,7 +236,7 @@ public class NsLifecycleManagementControllerTest { } private CreateNsRequest getCreateNsRequest() { - return new CreateNsRequest().nsdId(UUID.randomUUID().toString()); + return new CreateNsRequest().nsdId(RANDOM_NS_INST_ID); } private String getNsLcmBaseUrl() { 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 new file mode 100644 index 0000000000..44acda20a4 --- /dev/null +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-service/src/test/resources/application.yaml @@ -0,0 +1,39 @@ +# Copyright © 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. +spring: + main: + allow-bean-definition-overriding: true + flyway: + baseline-on-migrate: false + datasource: + hikari: + camunda: + jdbcUrl: jdbc:h2:mem:example-simple;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE + driver-class-name: org.h2.Driver + pool-name: ns-lcm-bpmn-pool + registerMbeans: true + nfvo: + jdbcUrl: jdbc:h2:mem:NFVO;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS NFVO; + driver-class-name: org.h2.Driver + pool-name: ns-lcm-nfvo-pool + registerMbeans: true + jpa: + hibernate: + ddl-auto: none +logging: + level: + org.reflections.Reflections: ERROR +etsi-catalog-manager: + base: + endpoint: http://modeling-etsicatalog.onap:8806/api
\ No newline at end of file |