diff options
author | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2020-12-10 07:51:40 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-12-10 07:51:40 +0000 |
commit | a0e765a046b0ca7f55845df1c110eef6d6621cf7 (patch) | |
tree | 4cd634fec7dc8c0dc0677b29303f18e221d5c9f0 /bpmn/so-bpmn-tasks | |
parent | d750219ea2d0cf7360607f3cb8406205807bd28e (diff) | |
parent | 1bad00ddeecd2d6e53ae967fd9faad64cacdafc4 (diff) |
Merge "added in support for delete instance cnf"
Diffstat (limited to 'bpmn/so-bpmn-tasks')
2 files changed, 85 insertions, 0 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterDeleteTasks.java new file mode 100644 index 0000000000..87466bbbd4 --- /dev/null +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/cnf/tasks/CnfAdapterDeleteTasks.java @@ -0,0 +1,66 @@ +/*- + * ============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.bpmn.infrastructure.adapter.cnf.tasks; + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.adapter.cnf.CnfAdapterClient; +import org.onap.so.client.exception.ExceptionBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CnfAdapterDeleteTasks { + private static final Logger logger = LoggerFactory.getLogger(CnfAdapterDeleteTasks.class); + + @Autowired + private ExtractPojosForBB extractPojosForBB; + @Autowired + private ExceptionBuilder exceptionUtil; + @Autowired + private CnfAdapterClient cnfAdapterClient; + + /** + * This method is used for deleting the instance with Multicloud K8s Plugin. + * + * @param execution + * @return + */ + public void deleteInstance(BuildingBlockExecution execution) { + try { + logger.debug("Running delete instance - Helm"); + VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); + String heatStackId = vfModule.getHeatStackId(); + execution.setVariable("heatStackId", heatStackId); + cnfAdapterClient.deleteVfModule(heatStackId); + } catch (Exception ex) { + logger.error("Exception occurred", ex); + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java index 65f8a084eb..da36a6f040 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/adapter/cnf/CnfAdapterClient.java @@ -76,6 +76,25 @@ public class CnfAdapterClient { } } + + @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000)) + public void deleteVfModule(String heatStackId) throws CnfAdapterClientException { + try { + // String uri = env.getRequiredProperty("mso.cnf.adapter.endpoint"); //TODO: This needs to be added as well + // for configuration + String uri = "http://so-cnf-adapter:8090"; + String endpoint = UriBuilder.fromUri(uri).path(INSTANCE_CREATE_PATH + "/" + heatStackId).build().toString(); + HttpEntity<?> entity = new HttpEntity<>(getHttpHeaders()); + restTemplate.exchange(endpoint, HttpMethod.DELETE, entity, String.class); + } catch (HttpClientErrorException e) { + logger.error("Error Calling CNF Adapter, e"); + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException(e.getResponseBodyAsString()); + } + throw e; + } + } + @Retryable(value = {HttpServerErrorException.class}, maxAttempts = 3, backoff = @Backoff(delay = 3000)) public InstanceResponse healthcheck() throws CnfAdapterClientException { try { |