From 0ac8defd70bcc6e8aeef190390e8880174bc4168 Mon Sep 17 00:00:00 2001 From: Joanna Jeremicz Date: Wed, 5 Dec 2018 10:38:39 +0100 Subject: Use UUID to fill pnf-id in PNF PnP Issue-ID: SO-1272 Change-Id: If516b7ec38dad3fbc7409aff42275a98ef2af76a Signed-off-by: Joanna Jeremicz --- .../delegate/CreateAaiEntryWithPnfIdDelegate.java | 60 -------------------- .../pnf/delegate/CreatePnfEntryInAaiDelegate.java | 65 ++++++++++++++++++++++ .../pnf/delegate/ExecutionVariableNames.java | 3 + .../pnf/delegate/GeneratePnfUuidDelegate.java | 43 ++++++++++++++ .../pnf/delegate/PnfCheckInputs.java | 28 +++++++++- 5 files changed, 137 insertions(+), 62 deletions(-) delete mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegate.java create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegate.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/CreateAaiEntryWithPnfIdDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java deleted file mode 100644 index 849308e0ee..0000000000 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java +++ /dev/null @@ -1,60 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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.pnf.delegate; - -import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; - -import org.camunda.bpm.engine.delegate.DelegateExecution; -import org.camunda.bpm.engine.delegate.JavaDelegate; -import org.onap.aai.domain.yang.Pnf; -import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * Implementation of "Create AAI entry with pnf-id = correlation_id" task in CreateAndActivatePnfResource.bpmn - * - * Inputs: - * - correlationId - String - */ -@Component -public class CreateAaiEntryWithPnfIdDelegate implements JavaDelegate { - - private static final Logger logger = LoggerFactory.getLogger(CreateAaiEntryWithPnfIdDelegate.class); - private AaiConnection aaiConnection; - - @Autowired - public void setAaiConnection(AaiConnection aaiConnection) { - this.aaiConnection = aaiConnection; - } - - @Override - public void execute(DelegateExecution execution) throws Exception { - String correlationId = (String) execution.getVariable(CORRELATION_ID); - Pnf pnf = new Pnf(); - pnf.setPnfId(correlationId); - pnf.setPnfName(correlationId); - aaiConnection.createEntry(correlationId, pnf); - logger.debug("AAI entry is created for pnf correlation id: {}", correlationId); - } -} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegate.java new file mode 100644 index 0000000000..2268d22bd2 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreatePnfEntryInAaiDelegate.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ + * 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.pnf.delegate; + +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID; + +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.onap.aai.domain.yang.Pnf; +import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * Implementation of "Create Pnf entry in AAI" task in CreateAndActivatePnfResource.bpmn + * + * Inputs: + * - correlationId - String + * - pnfUuid - String + */ +@Component +public class CreatePnfEntryInAaiDelegate implements JavaDelegate { + + private static final Logger logger = LoggerFactory.getLogger(CreatePnfEntryInAaiDelegate.class); + private AaiConnection aaiConnection; + + @Autowired + public void setAaiConnection(AaiConnection aaiConnection) { + this.aaiConnection = aaiConnection; + } + + @Override + public void execute(DelegateExecution execution) throws Exception { + String correlationId = (String) execution.getVariable(CORRELATION_ID); + String pnfUuid = (String) execution.getVariable(PNF_UUID); + Pnf pnf = new Pnf(); + pnf.setPnfId(pnfUuid); + pnf.setPnfName(correlationId); + aaiConnection.createEntry(correlationId, pnf); + logger.debug("AAI entry is created for pnf correlation id: {}, pnf uuid: {}", correlationId, pnfUuid); + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java index b3f2f726a0..1407cb9211 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ * 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 @@ -30,4 +32,5 @@ public class ExecutionVariableNames { public final static String AAI_CONTAINS_INFO_ABOUT_IP = "aaiContainsInfoAboutIp"; public final static String DMAAP_MESSAGE = "dmaapMessage"; public final static String TIMEOUT_FOR_NOTIFICATION = "timeoutForPnfEntryNotification"; + public final static String PNF_UUID = "pnfUuid"; } diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegate.java new file mode 100644 index 0000000000..f5483e489e --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/GeneratePnfUuidDelegate.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Nokia. + * ================================================================================ + * 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.pnf.delegate; + +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID; + +import java.util.UUID; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; + +@Component +public class GeneratePnfUuidDelegate implements JavaDelegate { + + private static final Logger logger = LoggerFactory.getLogger(GeneratePnfUuidDelegate.class); + + @Override + public void execute(DelegateExecution delegateExecution){ + UUID uuid = UUID.randomUUID(); + logger.debug("Generated UUID for pnf: {}, version: {}, variant: {}", uuid, uuid.version(), uuid.variant()); + delegateExecution.setVariable(PNF_UUID, uuid.toString()); + } +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java index 94fb6a8674..e9b0bc77b2 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/PnfCheckInputs.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright 2018 Nokia + * ================================================================================ * 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 @@ -21,9 +23,11 @@ package org.onap.so.bpmn.infrastructure.pnf.delegate; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; +import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID; import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION; import com.google.common.base.Strings; +import java.util.regex.Pattern; import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.delegate.JavaDelegate; import org.onap.so.bpmn.common.scripts.ExceptionUtil; @@ -35,6 +39,8 @@ import org.springframework.stereotype.Component; @Component public class PnfCheckInputs implements JavaDelegate { + private static final Pattern UUID_PATTERN = Pattern + .compile("(?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}$"); private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, PnfCheckInputs.class); private String defaultTimeout; @@ -46,19 +52,37 @@ public class PnfCheckInputs implements JavaDelegate { @Override public void execute(DelegateExecution execution) { + validateCorrelationId(execution); + validatePnfUuid(execution); + validateTimeout(execution); + } + + private void validateCorrelationId(DelegateExecution execution) { String correlationId = (String) execution.getVariable(CORRELATION_ID); if (Strings.isNullOrEmpty(correlationId)) { new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "correlationId 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 (!UUID_PATTERN.matcher(pnfUuid).matches()) { + new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid is not a valid UUID"); + } + } + + private void validateTimeout(DelegateExecution execution) { String timeout = (String) execution.getVariable(TIMEOUT_FOR_NOTIFICATION); if (Strings.isNullOrEmpty(timeout)) { LOGGER.debug("timeoutForPnfEntryNotification variable not found, setting default"); if (defaultTimeout == null) { new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, - "default timeoutForPnfEntryNotification value not defined"); + "default timeoutForPnfEntryNotification value not defined"); } execution.setVariable(TIMEOUT_FOR_NOTIFICATION, defaultTimeout); } } - } -- cgit 1.2.3-korg