diff options
author | Steve Smokowski <ss835w@att.com> | 2019-04-01 13:24:50 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-04-01 13:24:50 +0000 |
commit | c9296dc7147f22ed636f928f6c38ad099e3ed398 (patch) | |
tree | 6e5c23f721ba5ad9f6704bd830965f1125368419 /bpmn/so-bpmn-tasks/src/main/java/org | |
parent | 24117e55159518d2e3599fd7cf6705d476cfda81 (diff) | |
parent | b098903d536b2e6b6b76a310035f9e0950817f50 (diff) |
Merge "Added ETSI Delete VNF BB"
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java/org')
5 files changed, 199 insertions, 69 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java index 667ac133af..0153b4b3f9 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/Constants.java @@ -25,21 +25,20 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; */ public class Constants { - public static final String CREATE_VNF_REQUEST_PARAM_NAME = "createVnfRequest"; - public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse"; - - public static final String INPUT_PARAMETER = "inputParameter"; + public static final String CREATE_VNF_REQUEST_PARAM_NAME = "createVnfRequest"; + public static final String CREATE_VNF_RESPONSE_PARAM_NAME = "createVnfResponse"; + public static final String INPUT_PARAMETER = "inputParameter"; + public static final String DELETE_VNF_RESPONSE_PARAM_NAME = "deleteVnfResponse"; - public static final String DOT = "."; - public static final String UNDERSCORE = "_"; - public static final String SPACE = "\\s+"; + public static final String DOT = "."; + public static final String UNDERSCORE = "_"; + public static final String SPACE = "\\s+"; - public static final String VNFM_ADAPTER_DEFAULT_URL = "http://so-vnfm-adapter.onap:9092/so/vnfm-adapter/v1/"; - public static final String VNFM_ADAPTER_DEFAULT_AUTH = "Basic dm5mbTpwYXNzd29yZDEk"; - - public static final String FORWARD_SLASH = "/"; - public static final String PRELOAD_VNFS_URL = "/restconf/config/VNF-API:preload-vnfs/vnf-preload-list/"; + public static final String VNFM_ADAPTER_DEFAULT_URL = "http://so-vnfm-adapter.onap:9092/so/vnfm-adapter/v1/"; + public static final String VNFM_ADAPTER_DEFAULT_AUTH = "Basic dm5mbTpwYXNzd29yZDEk"; + public static final String FORWARD_SLASH = "/"; + public static final String PRELOAD_VNFS_URL = "/restconf/config/VNF-API:preload-vnfs/vnf-preload-list/"; - private Constants() {} + private Constants() {} } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTask.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTask.java new file mode 100644 index 0000000000..857c5cb6fe --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/EtsiVnfDeleteTask.java @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; + +import static org.onap.so.bpmn.servicedecomposition.entities.ResourceKey.GENERIC_VNF_ID; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.ExceptionBuilder; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import com.google.common.base.Optional; + +/** + * + * @author Lathishbabu Ganesan (lathishbabu.ganesan@est.tech) + */ +@Component +public class EtsiVnfDeleteTask { + + private static final Logger LOGGER = LoggerFactory.getLogger(EtsiVnfDeleteTask.class); + private final ExtractPojosForBB extractPojosForBB; + private final ExceptionBuilder exceptionUtil; + private final VnfmAdapterServiceProvider vnfmAdapterServiceProvider; + + @Autowired + public EtsiVnfDeleteTask(final ExceptionBuilder exceptionUtil, final ExtractPojosForBB extractPojosForBB, + final VnfmAdapterServiceProvider vnfmAdapterServiceProvider) { + this.exceptionUtil = exceptionUtil; + this.extractPojosForBB = extractPojosForBB; + this.vnfmAdapterServiceProvider = vnfmAdapterServiceProvider; + } + + /** + * Invoke VNFM adapter to delete the VNF + * + * @param execution {@link org.onap.so.bpmn.common.DelegateExecutionImpl} + */ + public void invokeVnfmAdapter(final BuildingBlockExecution execution) { + try { + LOGGER.debug("Executing invokeVnfmAdapter ..."); + final GenericVnf vnf = extractPojosForBB.extractByKey(execution, GENERIC_VNF_ID); + + final Optional<DeleteVnfResponse> response = vnfmAdapterServiceProvider.invokeDeleteRequest(vnf.getVnfId()); + + if (!response.isPresent()) { + final String errorMessage = "Unexpected error while processing delete request"; + LOGGER.error(errorMessage); + exceptionUtil.buildAndThrowWorkflowException(execution, 1211, errorMessage); + } + + final DeleteVnfResponse vnfResponse = response.get(); + + LOGGER.debug("Vnf delete response: {}", vnfResponse); + execution.setVariable(Constants.DELETE_VNF_RESPONSE_PARAM_NAME, vnfResponse); + + LOGGER.debug("Finished executing invokeVnfmAdapter ..."); + } catch (final Exception exception) { + LOGGER.error("Unable to invoke delete request", exception); + exceptionUtil.buildAndThrowWorkflowException(execution, 1212, exception); + } + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProvider.java index 02303ef09d..a76a4bf3c1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProvider.java @@ -22,17 +22,19 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; - +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; import com.google.common.base.Optional; /** * Provide a service which interacts with VNFM adapter for instantiating, monitoring VNF - * + * * @author waqas.ikram@est.tech */ public interface VnfmAdapterServiceProvider { - Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, final CreateVnfRequest request); + Optional<CreateVnfResponse> invokeCreateInstantiationRequest(final String vnfId, final CreateVnfRequest request); + + Optional<DeleteVnfResponse> invokeDeleteRequest(final String vnfId); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java index afdcccfd36..f727423e85 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterServiceProviderImpl.java @@ -25,13 +25,13 @@ import org.onap.so.rest.exceptions.RestProcessingException; import org.onap.so.rest.service.HttpRestServiceProvider; import org.onap.vnfmadapter.v1.model.CreateVnfRequest; import org.onap.vnfmadapter.v1.model.CreateVnfResponse; +import org.onap.vnfmadapter.v1.model.DeleteVnfResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; - import com.google.common.base.Optional; /** @@ -40,50 +40,85 @@ import com.google.common.base.Optional; @Service public class VnfmAdapterServiceProviderImpl implements VnfmAdapterServiceProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(VnfmAdapterServiceProviderImpl.class); + private static final Logger LOGGER = LoggerFactory.getLogger(VnfmAdapterServiceProviderImpl.class); + + private final VnfmAdapterUrlProvider urlProvider; + private final HttpRestServiceProvider httpServiceProvider; + + @Autowired + public VnfmAdapterServiceProviderImpl(final VnfmAdapterUrlProvider urlProvider, + 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.absent(); + } + + if (!response.hasBody()) { + LOGGER.error("Received response without body: {}", response); + return Optional.absent(); + } + + final CreateVnfResponse createVnfResponse = response.getBody(); - private final VnfmAdapterUrlProvider urlProvider; - private final HttpRestServiceProvider httpServiceProvider; + if (createVnfResponse.getJobId() == null || createVnfResponse.getJobId().isEmpty()) { + LOGGER.error("Received invalid instantiation response: {}", response); + return Optional.absent(); + } - @Autowired - public VnfmAdapterServiceProviderImpl(final VnfmAdapterUrlProvider urlProvider, - final HttpRestServiceProvider httpServiceProvider) { - this.urlProvider = urlProvider; - this.httpServiceProvider = httpServiceProvider; + return Optional.of(createVnfResponse); + } catch (final RestProcessingException | InvalidRestRequestException httpInvocationException) { + LOGGER.error("Unexpected error while processing create and instantiation request", httpInvocationException); + return Optional.absent(); } - @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); + @Override + public Optional<DeleteVnfResponse> invokeDeleteRequest(final String vnfId) { + try { + final String url = urlProvider.getDeleteUrl(vnfId); + LOGGER.debug("Will send request to vnfm adapter using url: {}", url); - 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.absent(); - } + final ResponseEntity<DeleteVnfResponse> response = + httpServiceProvider.deleteHttpRequest(url, DeleteVnfResponse.class); - if (!response.hasBody()) { - LOGGER.error("Received response without body: {}", response); - return Optional.absent(); - } + LOGGER.debug("Response received: ", response); - final CreateVnfResponse createVnfResponse = response.getBody(); + final HttpStatus httpStatus = response.getStatusCode(); - if (createVnfResponse.getJobId() == null || createVnfResponse.getJobId().isEmpty()) { - LOGGER.error("Received invalid instantiation response: {}", response); - return Optional.absent(); - } + if (!(httpStatus.equals(HttpStatus.ACCEPTED)) && !(httpStatus.equals(HttpStatus.OK))) { + LOGGER.error("Unable to invoke HTTP DELETE using URL: {}, Response Code: {}", url, httpStatus.value()); + return Optional.absent(); + } - return Optional.of(createVnfResponse); - } catch (final RestProcessingException | InvalidRestRequestException httpInvocationException) { - LOGGER.error("Unexpected error while processing create and instantiation request", httpInvocationException); - return Optional.absent(); - } + if (!response.hasBody()) { + LOGGER.error("Received response without body: {}", response); + return Optional.absent(); + } + final DeleteVnfResponse deleteVnfResponse = response.getBody(); + if (deleteVnfResponse.getJobId() == null || deleteVnfResponse.getJobId().isEmpty()) { + LOGGER.error("Received invalid delete response: {}", response); + return Optional.absent(); + } + return Optional.of(deleteVnfResponse); + } catch (final RestProcessingException | InvalidRestRequestException httpInvocationException) { + LOGGER.error("Unexpected error while processing delete request", httpInvocationException); + return Optional.absent(); } + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProvider.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProvider.java index 03ee0712e7..61063fe90e 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProvider.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterUrlProvider.java @@ -21,7 +21,6 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; import java.net.URI; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.util.UriComponentsBuilder; @@ -36,23 +35,34 @@ import org.springframework.web.util.UriComponentsBuilder; @Service public class VnfmAdapterUrlProvider { - private final URI baseUri; - - @Autowired - public VnfmAdapterUrlProvider(final VnfmBasicHttpConfigProvider etsiVnfmAdapter) { - this.baseUri = UriComponentsBuilder.fromHttpUrl(etsiVnfmAdapter.getUrl()).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(); - } + private final URI baseUri; + + @Autowired + public VnfmAdapterUrlProvider(final VnfmBasicHttpConfigProvider etsiVnfmAdapter) { + this.baseUri = UriComponentsBuilder.fromHttpUrl(etsiVnfmAdapter.getUrl()).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 VNFM delete URL + * + * @param vnfId The identifier of the VNF. This must be the vnf-id of an existing generic-vnf in + * AAI. + * @return VNFM delete URL + */ + public String getDeleteUrl(final String vnfId) { + return UriComponentsBuilder.fromUri(baseUri).pathSegment("vnfs").pathSegment(vnfId).build().toString(); + } } |