From d7ef9a5b2f6f1a7e807a100f7e69fc373dc5e71a Mon Sep 17 00:00:00 2001 From: JerzySzachniewicz Date: Fri, 31 Jul 2020 08:18:58 +0200 Subject: Ensure that model related parameters are set when re-using Inventoried PNF instance Issue-ID: SO-3110 Signed-off-by: JerzySzachniewicz Change-Id: I79834c0b3b756cc64d98fb10acab8e93a15c6f2b Signed-off-by: JerzySzachniewicz --- .../infrastructure/aai/tasks/AAICreateTasks.java | 2 +- .../so/client/orchestration/AAIPnfResources.java | 35 ++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) (limited to 'bpmn/so-bpmn-tasks/src/main/java/org') 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 e3181c3e91..55edf0bb6c 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,7 +260,7 @@ public class AAICreateTasks { public void createPnf(BuildingBlockExecution execution) { try { Pnf pnf = extractPojosForBB.extractByKey(execution, ResourceKey.PNF); - aaiPnfResources.checkIfPnfExistsInAaiAndCanBeUsed(pnf.getPnfName()); + aaiPnfResources.checkIfPnfExistsInAaiAndCanBeUsed(pnf); ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); aaiPnfResources.createPnfAndConnectServiceInstance(pnf, serviceInstance); 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 3b22cd9d81..3da17194ff 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 @@ -22,6 +22,7 @@ package org.onap.so.client.orchestration; import com.google.common.base.Strings; import java.util.Optional; +import org.apache.commons.lang3.StringUtils; import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; @@ -68,11 +69,39 @@ public class AAIPnfResources { 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)); + public void checkIfPnfExistsInAaiAndCanBeUsed(Pnf pnf) throws Exception { + Optional pnfFromAai = + injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.Pnf.class, + AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnf.getPnfName())); if (pnfFromAai.isPresent()) { checkIfPnfCanBeUsed(pnfFromAai.get()); + updatePnfInAAI(pnf, pnfFromAai.get()); + } + } + + private void updatePnfInAAI(Pnf pnf, org.onap.aai.domain.yang.Pnf pnfFromAai) { + updatePnfFields(pnf, pnfFromAai); + injectionHelper.getAaiClient().update(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnf.getPnfName()), + pnfFromAai); + logger.debug("updatePnfInAAI: {}", pnfFromAai); + } + + private void updatePnfFields(Pnf pnf, org.onap.aai.domain.yang.Pnf pnfFromAai) { + if (pnf.getModelInfoPnf() != null + && StringUtils.isNotBlank(pnf.getModelInfoPnf().getModelCustomizationUuid())) { + pnfFromAai.setModelCustomizationId(pnf.getModelInfoPnf().getModelCustomizationUuid()); + } + if (pnf.getModelInfoPnf() != null && StringUtils.isNotBlank(pnf.getModelInfoPnf().getModelInvariantUuid())) { + pnfFromAai.setModelInvariantId(pnf.getModelInfoPnf().getModelInvariantUuid()); + } + if (pnf.getModelInfoPnf() != null && StringUtils.isNotBlank(pnf.getModelInfoPnf().getModelUuid())) { + pnfFromAai.setModelVersionId(pnf.getModelInfoPnf().getModelUuid()); + } + if (pnf.getOrchestrationStatus() != null && StringUtils.isNotBlank(pnf.getOrchestrationStatus().toString())) { + pnfFromAai.setOrchestrationStatus(pnf.getOrchestrationStatus().toString()); + } + if (StringUtils.isNotBlank(pnf.getRole())) { + pnfFromAai.setNfRole(pnf.getRole()); } } -- cgit 1.2.3-korg