From 7d36092d69706b3f94e4f5b53aa3554487099dd0 Mon Sep 17 00:00:00 2001 From: Lukasz Muszkieta Date: Thu, 14 May 2020 17:33:22 +0200 Subject: possibility to use inventoried PNF instance in new service instance Issue-ID: SO-2937 Signed-off-by: Lukasz Muszkieta Change-Id: I5b34234d453bbd5ff1fef3c41f5cd50b23f66db1 --- .../infrastructure/aai/tasks/AAICreateTasks.java | 3 +- .../so/client/orchestration/AAIPnfResources.java | 36 ++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'bpmn/so-bpmn-tasks/src/main/java') 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 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); + + } + } } -- cgit 1.2.3-korg