diff options
author | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2020-05-14 17:33:22 +0200 |
---|---|---|
committer | Lukasz Muszkieta <lukasz.muszkieta@nokia.com> | 2020-05-19 12:59:46 +0200 |
commit | 7d36092d69706b3f94e4f5b53aa3554487099dd0 (patch) | |
tree | 184daf66b1c948b20bd116059c2af4f573604828 /bpmn/so-bpmn-tasks/src/main/java/org | |
parent | 959d27a96f24cf74dfa3764df64b65a1ba9b9cbb (diff) |
possibility to use inventoried PNF instance in new service instance
Issue-ID: SO-2937
Signed-off-by: Lukasz Muszkieta <lukasz.muszkieta@nokia.com>
Change-Id: I5b34234d453bbd5ff1fef3c41f5cd50b23f66db1
Diffstat (limited to 'bpmn/so-bpmn-tasks/src/main/java/org')
2 files changed, 38 insertions, 1 deletions
diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java index 385b96c0f8..e3181c3e91 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAICreateTasks.java @@ -260,10 +260,11 @@ public class AAICreateTasks { public void createPnf(BuildingBlockExecution execution) { try { Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF); + aaiPnfResources.checkIfPnfExistsInAaiAndCanBeUsed(pnf.getPnfName()); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance); - } catch (BBObjectNotFoundException e) { + } catch (Exception e) { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java index a3df22a840..b8562ba6b5 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIPnfResources.java @@ -20,6 +20,7 @@ package org.onap.so.client.orchestration; +import com.google.common.base.Strings; import java.util.Optional; import org.onap.so.bpmn.common.InjectionHelper; import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; @@ -29,12 +30,16 @@ import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri; import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @Component public class AAIPnfResources { + private static final Logger logger = LoggerFactory.getLogger(AAIPnfResources.class); + @Autowired private InjectionHelper injectionHelper; @@ -59,4 +64,35 @@ public class AAIPnfResources { pnfCopy.setOrchestrationStatus(orchestrationStatus); injectionHelper.getAaiClient().update(pnfURI, aaiObjectMapper.mapPnf(pnfCopy)); } + + public void checkIfPnfExistsInAaiAndCanBeUsed(String pnfName) throws Exception { + Optional<org.onap.aai.domain.yang.Pnf> pnfFromAai = injectionHelper.getAaiClient() + .get(org.onap.aai.domain.yang.Pnf.class, AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfName)); + if (pnfFromAai.isPresent() && isOrchestrationStatusSet(pnfFromAai.get())) { + checkOrchestrationStatusOfExistingPnf(pnfFromAai.get()); + } + } + + private boolean isOrchestrationStatusSet(org.onap.aai.domain.yang.Pnf pnfFromAai) { + if (Strings.isNullOrEmpty(pnfFromAai.getOrchestrationStatus())) { + logger.debug("pnf with name {} already exists with not set orchestration status and can be used", + pnfFromAai.getPnfName()); + return false; + } + return true; + } + + private void checkOrchestrationStatusOfExistingPnf(org.onap.aai.domain.yang.Pnf pnfFromAai) throws Exception { + if (OrchestrationStatus.INVENTORIED.toString().equals(pnfFromAai.getOrchestrationStatus())) { + logger.debug("pnf with name {} already exists with orchestration status Inventoried and can be used", + pnfFromAai.getPnfName()); + } else { + String errorMessage = String.format( + "pnf with name %s already exists with orchestration status %s, only status Inventoried allows to use existing pnf", + pnfFromAai.getPnfName(), pnfFromAai.getOrchestrationStatus()); + logger.error(errorMessage); + throw new Exception(errorMessage); + + } + } } |