From 5ec955ce08cd3101eed327bbb6d1ceb3903f5bfc Mon Sep 17 00:00:00 2001 From: Remigiusz Janeczek Date: Thu, 9 Jan 2020 12:23:18 +0100 Subject: Align AssignPnfBB with Service Macro Create -move and align logic of BB delegates with tests -remove unnecessary classes -add tests cases for Pnfs in ExtractPojosForBBTests Issue-ID: SO-2568 Signed-off-by: Remigiusz Janeczek Change-Id: Ic48e2c1c6ab852c33837091da3e7916b71c26466 --- .../delegate/AssignPnfInputsCheckerDelegate.java | 40 ------------------- .../pnf/tasks/CheckAaiForPnfCorrelationId.java | 45 ++++++++++++++++++++++ .../pnf/tasks/CreatePnfEntryInAai.java | 34 ++++++++++++++++ .../infrastructure/pnf/tasks/PnfBaseTasks.java | 29 ++++++++++++++ 4 files changed, 108 insertions(+), 40 deletions(-) delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java (limited to 'bpmn/so-bpmn-infrastructure-common/src/main/java/org') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java deleted file mode 100644 index 9176948288..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.onap.so.bpmn.infrastructure.pnf.delegate; - -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID; -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID; -import com.google.common.base.Strings; -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.onap.so.bpmn.common.scripts.ExceptionUtil; -import org.springframework.stereotype.Component; - -@Component -public class AssignPnfInputsCheckerDelegate implements JavaDelegate { - - public static final String UUID_REGEX = - "(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[1-5]{1}[0-9a-f]{3}-[89ab]{1}[0-9a-f]{3}-[0-9a-f]{12}$"; - - @Override - public void execute(DelegateExecution execution) { - validatePnfCorrelationId(execution); - validatePnfUuid(execution); - } - - private void validatePnfCorrelationId(DelegateExecution execution) { - String pnfCorrelationId = (String) execution.getVariable(PNF_CORRELATION_ID); - if (Strings.isNullOrEmpty(pnfCorrelationId)) { - new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, - "pnfCorrelationId variable not defined"); - } - } - - private void validatePnfUuid(DelegateExecution execution) { - String pnfUuid = (String) execution.getVariable(PNF_UUID); - if (Strings.isNullOrEmpty(pnfUuid)) { - new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid variable not defined"); - } - if (!pnfUuid.matches(UUID_REGEX)) { - new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid is not a valid UUID"); - } - } -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java new file mode 100644 index 0000000000..29914252d8 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CheckAaiForPnfCorrelationId.java @@ -0,0 +1,45 @@ +package org.onap.so.bpmn.infrastructure.pnf.tasks; + +import joptsimple.internal.Strings; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import java.io.IOException; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID; + +@Component +public class CheckAaiForPnfCorrelationId extends PnfBaseTasks { + private static final Logger logger = LoggerFactory.getLogger(CheckAaiForPnfCorrelationId.class); + + @Override + public void execute(BuildingBlockExecution execution) { + try { + String pnfCorrelationId = extractPnf(execution).getPnfName(); + checkIfPnfCorrelationIdPresent(execution, pnfCorrelationId); + checkIfPnfExistsInAai(execution, pnfCorrelationId); + } catch (BBObjectNotFoundException e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); + } + + } + + private void checkIfPnfCorrelationIdPresent(BuildingBlockExecution execution, String pnfCorrelationId) { + if (Strings.isNullOrEmpty(pnfCorrelationId)) { + exceptionUtil.buildAndThrowWorkflowException(execution, 500, PNF_CORRELATION_ID + " is not set"); + } + } + + private void checkIfPnfExistsInAai(BuildingBlockExecution execution, String pnfCorrelationId) { + try { + boolean isEntry = pnfManagement.getEntryFor(pnfCorrelationId).isPresent(); + logger.debug("AAI entry is found for pnf correlation id {}: {}", PNF_CORRELATION_ID, isEntry); + execution.setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, isEntry); + } catch (IOException e) { + logger.error("Exception in check AAI for pnf_correlation_id execution", e); + exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e); + } + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java new file mode 100644 index 0000000000..6e86ad619e --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/CreatePnfEntryInAai.java @@ -0,0 +1,34 @@ +package org.onap.so.bpmn.infrastructure.pnf.tasks; + +import org.onap.aai.domain.yang.Pnf; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class CreatePnfEntryInAai extends PnfBaseTasks { + private static final Logger logger = LoggerFactory.getLogger(CreatePnfEntryInAai.class); + + @Override + public void execute(BuildingBlockExecution execution) throws Exception { + try { + org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf = extractPnf(execution); + String pnfCorrelationId = pnf.getPnfName(); + pnfManagement.createEntry(pnfCorrelationId, preparePnfForAai(pnf)); + logger.debug("AAI entry is created for pnf correlation id: {}, pnf uuid: {}", pnfCorrelationId, + pnf.getPnfId()); + } catch (BBObjectNotFoundException e) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e); + } + } + + private Pnf preparePnfForAai(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf pnf) { + Pnf pnfAai = new Pnf(); + pnfAai.setPnfId(pnf.getPnfId()); + pnfAai.setPnfName(pnf.getPnfName()); + return pnfAai; + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java new file mode 100644 index 0000000000..d8e3379afb --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/tasks/PnfBaseTasks.java @@ -0,0 +1,29 @@ +package org.onap.so.bpmn.infrastructure.pnf.tasks; + +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.infrastructure.pnf.management.PnfManagement; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; +import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.BBObjectNotFoundException; +import org.onap.so.client.exception.ExceptionBuilder; +import org.springframework.beans.factory.annotation.Autowired; + +public abstract class PnfBaseTasks { + protected PnfManagement pnfManagement; + @Autowired + protected ExceptionBuilder exceptionUtil; + @Autowired + protected ExtractPojosForBB extractPojosForBB; + + @Autowired + public void setPnfManagement(PnfManagement pnfManagement) { + this.pnfManagement = pnfManagement; + } + + public abstract void execute(BuildingBlockExecution execution) throws Exception; + + protected Pnf extractPnf(BuildingBlockExecution execution) throws BBObjectNotFoundException { + return extractPojosForBB.extractByKey(execution, ResourceKey.PNF); + } +} -- cgit 1.2.3-korg