From: Bonkur, Venkat (vb8416) Date: Fri, 15 Mar 2019 20:16:21 +0000 (-0400) Subject: Add VnfInPlaceSoftwareUpdate for WFD X-Git-Tag: 1.4.1~165 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=853440d183783ebfe65f45b49ad8874d9c87ef8d;p=so.git Add VnfInPlaceSoftwareUpdate for WFD Added CheckPserversLocked,SetClosedLoopDisabled,UnsetClosedLoopDisabled, CheckClosedLoopDisabled, CheckInMain Change-Id: I6405b2c88d2109d952d452648bef2f99be6993df Issue-ID: SO-1518 Signed-off-by: Bonkur, Venkat (vb8416) --- diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFCheckClosedLoopDisabledFlagActivity.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFCheckClosedLoopDisabledFlagActivity.bpmn new file mode 100644 index 0000000000..9ac0f38835 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFCheckClosedLoopDisabledFlagActivity.bpmn @@ -0,0 +1,50 @@ + + + + + SequenceFlow_01c8z5u + + + SequenceFlow_12mzh2v + + + SequenceFlow_01c8z5u + SequenceFlow_12mzh2v + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFCheckInMaintFlagActivity.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFCheckInMaintFlagActivity.bpmn new file mode 100644 index 0000000000..8709f399a5 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFCheckInMaintFlagActivity.bpmn @@ -0,0 +1,50 @@ + + + + + SequenceFlow_0h1gkvd + + + SequenceFlow_0xu6esl + + + SequenceFlow_0h1gkvd + SequenceFlow_0xu6esl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFCheckPserversLockedFlagActivity.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFCheckPserversLockedFlagActivity.bpmn new file mode 100644 index 0000000000..9c327a4da9 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFCheckPserversLockedFlagActivity.bpmn @@ -0,0 +1,50 @@ + + + + + SequenceFlow_0a56huh + + + SequenceFlow_1f2j7tx + + + SequenceFlow_0a56huh + SequenceFlow_1f2j7tx + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFSetClosedLoopDisabledFlagActivity.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFSetClosedLoopDisabledFlagActivity.bpmn new file mode 100644 index 0000000000..f356634106 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFSetClosedLoopDisabledFlagActivity.bpmn @@ -0,0 +1,50 @@ + + + + + SequenceFlow_0pp6ze7 + + + SequenceFlow_0g0xfi3 + + + SequenceFlow_0pp6ze7 + SequenceFlow_0g0xfi3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFUnsetClosedLoopDisabledFlagActivity.bpmn b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFUnsetClosedLoopDisabledFlagActivity.bpmn new file mode 100644 index 0000000000..0dbe989cb2 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/main/resources/subprocess/Activity/VNFUnsetClosedLoopDisabledFlagActivity.bpmn @@ -0,0 +1,47 @@ + + + + + SequenceFlow_19it9ao + + + SequenceFlow_1en9xbh + + + SequenceFlow_19it9ao + SequenceFlow_1en9xbh + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFCheckClosedLoopDisabledFlagActivityTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFCheckClosedLoopDisabledFlagActivityTest.java new file mode 100644 index 0000000000..ac4499bf89 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFCheckClosedLoopDisabledFlagActivityTest.java @@ -0,0 +1,55 @@ +/*- + * ============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.bpmn.subprocess; +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Test; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.BaseBPMNTest; + +public class VNFCheckClosedLoopDisabledFlagActivityTest extends BaseBPMNTest{ + @Test + public void sunnyDayVNFCheckClosedLoopDisabledFlagActivity_Test() throws InterruptedException { + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFCheckClosedLoopDisabledFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFCheckClosedLoopDisabledFlagActivity_Start", + "TaskCheckClosedLoopDisabledFlagActivity", + "VNFCheckClosedLoopDisabledFlagActivity_End"); + assertThat(pi).isEnded(); + } + + @Test + public void rainyDayVNFCheckClosedLoopDisabledFlagActivity_Test() throws Exception { + doThrow(new BpmnError("7000", "TESTING ERRORS")).when(aaiFlagTasks) + .checkVnfClosedLoopDisabledFlag(any(BuildingBlockExecution.class)); + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFCheckClosedLoopDisabledFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFCheckClosedLoopDisabledFlagActivity_Start", + "TaskCheckClosedLoopDisabledFlagActivity").hasNotPassed( + "VNFCheckClosedLoopDisabledFlagActivity_End"); + assertThat(pi).isEnded(); + } + +} diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFCheckInMaintFlagActivityTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFCheckInMaintFlagActivityTest.java new file mode 100644 index 0000000000..050d3124f6 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFCheckInMaintFlagActivityTest.java @@ -0,0 +1,56 @@ +/*- + * ============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.bpmn.subprocess; +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Test; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.BaseBPMNTest; + + +public class VNFCheckInMaintFlagActivityTest extends BaseBPMNTest{ + @Test + public void sunnyDayVNFCheckInMaintFlagActivity_Test() throws InterruptedException { + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFCheckInMaintFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFCheckInMaintFlagActivity_Start", + "TaskCheckInMaintFlag", + "VNFCheckInMaintFlagActivity_End"); + assertThat(pi).isEnded(); + } + + @Test + public void rainyDayVNFCheckInMaintFlagActivity_Test() throws Exception { + doThrow(new BpmnError("7000", "TESTING ERRORS")).when(aaiFlagTasks) + .checkVnfInMaintFlag(any(BuildingBlockExecution.class)); + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFCheckInMaintFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFCheckInMaintFlagActivity_Start", + "TaskCheckInMaintFlag").hasNotPassed( + "VNFCheckInMaintFlagActivity_End"); + assertThat(pi).isEnded(); + } + +} diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFCheckPserversLockedFlagActivity.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFCheckPserversLockedFlagActivity.java new file mode 100644 index 0000000000..e43f47fa6a --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFCheckPserversLockedFlagActivity.java @@ -0,0 +1,55 @@ +/*- + * ============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.bpmn.subprocess; +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Test; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.BaseBPMNTest; + +public class VNFCheckPserversLockedFlagActivity extends BaseBPMNTest{ + @Test + public void sunnyDayVNFCheckInMaintFlagActivity_Test() throws InterruptedException { + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFCheckPserversLockedFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFCheckPserversLockedFlagActivity_Start", + "TaskCheckPserversLockedFlagActivity", + "VNFCheckPserversLockedFlagActivity_End"); + assertThat(pi).isEnded(); + } + + @Test + public void rainyDayVNFCheckPserversLockedFlagActivity_Test() throws Exception { + doThrow(new BpmnError("7000", "TESTING ERRORS")).when(aaiFlagTasks) + .checkVnfPserversLockedFlag(any(BuildingBlockExecution.class)); + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFCheckPserversLockedFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFCheckPserversLockedFlagActivity_Start", + "TaskCheckPserversLockedFlagActivity").hasNotPassed( + "VNFCheckPserversLockedFlagActivity_End"); + assertThat(pi).isEnded(); + } + +} diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFSetClosedLoopDisabledFlagActivityTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFSetClosedLoopDisabledFlagActivityTest.java new file mode 100644 index 0000000000..8e56051f47 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFSetClosedLoopDisabledFlagActivityTest.java @@ -0,0 +1,55 @@ +/*- + * ============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.bpmn.subprocess; +import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat; +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Test; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.BaseBPMNTest; + +public class VNFSetClosedLoopDisabledFlagActivityTest extends BaseBPMNTest{ + @Test + public void sunnyDayVNFSetClosedLoopDisabledFlagActivity_Test() throws InterruptedException { + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFSetClosedLoopDisabledFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFSetClosedLoopDisabledFlagActivity_Start", + "TaskSetClosedLoopDisabledFlagActivity", + "VNFSetClosedLoopDisabledFlagActivity_End"); + assertThat(pi).isEnded(); + } + + @Test + public void rainyDayVNFSetClosedLoopDisabledFlagActivity_Test() throws Exception { + doThrow(new BpmnError("7000", "TESTING ERRORS")).when(aaiFlagTasks) + .modifyVnfClosedLoopDisabledFlag(any(BuildingBlockExecution.class), any(boolean.class)); + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFSetClosedLoopDisabledFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFSetClosedLoopDisabledFlagActivity_Start", + "TaskSetClosedLoopDisabledFlagActivity").hasNotPassed( + "VNFSetInMaintFlagActivity_End"); + assertThat(pi).isEnded(); + } +} diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFUnsetClosedLoopDisabledFlagActivityTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFUnsetClosedLoopDisabledFlagActivityTest.java new file mode 100644 index 0000000000..4c9b33c2c7 --- /dev/null +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/VNFUnsetClosedLoopDisabledFlagActivityTest.java @@ -0,0 +1,54 @@ +/*- + * ============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.bpmn.subprocess; +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doThrow; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.junit.Test; +import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.onap.so.bpmn.BaseBPMNTest; + +public class VNFUnsetClosedLoopDisabledFlagActivityTest extends BaseBPMNTest{ + @Test + public void sunnyDayVNFUnsetClosedLoopDisabledFlagActivity_Test() throws InterruptedException { + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFUnsetInClosedLoopDisabledFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFUnsetClosedLoopDisabledFlagActivity_Start", + "TaskVNFUnsetClosedLoopDisabledFlagActivity", + "VNFUnsetClosedLoopDisabledFlagActivity_End"); + assertThat(pi).isEnded(); + } + + @Test + public void rainyDayVNFUnsetClosedLoopFlag_Test() throws Exception { + doThrow(new BpmnError("7000", "TESTING ERRORS")).when(aaiFlagTasks) + .modifyVnfClosedLoopDisabledFlag(any(BuildingBlockExecution.class), any(boolean.class)); + ProcessInstance pi = runtimeService.startProcessInstanceByKey("VNFUnsetInClosedLoopDisabledFlagActivity", variables); + assertThat(pi).isNotNull(); + assertThat(pi).isStarted().hasPassedInOrder("VNFUnsetClosedLoopDisabledFlagActivity_Start", + "TaskVNFUnsetClosedLoopDisabledFlagActivity").hasNotPassed( + "VNFUnsetClosedLoopDisabledFlagActivity_End"); + assertThat(pi).isEnded(); + } +} diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIFlagTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIFlagTasks.java index 94529f915b..ccc9fb0e43 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIFlagTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIFlagTasks.java @@ -73,4 +73,45 @@ public class AAIFlagTasks { } } + public void checkVnfClosedLoopDisabledFlag(BuildingBlockExecution execution) { + boolean isClosedLoopDisabled = false; + try { + GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + String vnfId = vnf.getVnfId(); + isClosedLoopDisabled = aaiVnfResources.checkVnfClosedLoopDisabledFlag(vnfId); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + if (isClosedLoopDisabled) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF Close Loop Disabled in A&AI"); + } + } + + public void modifyVnfClosedLoopDisabledFlag(BuildingBlockExecution execution, boolean closedLoopDisabled) { + try { + GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + + GenericVnf copiedGenericVnf = genericVnf.shallowCopyId(); + copiedGenericVnf.setClosedLoopDisabled(closedLoopDisabled); + genericVnf.setClosedLoopDisabled(closedLoopDisabled); + + aaiVnfResources.updateObjectVnf(copiedGenericVnf); + } catch(Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + } + + public void checkVnfPserversLockedFlag(BuildingBlockExecution execution) { + boolean inPserversLocked = false; + try { + GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID, execution.getLookupMap().get(ResourceKey.GENERIC_VNF_ID)); + String vnfId = vnf.getVnfId(); + inPserversLocked = aaiVnfResources.checkVnfPserversLockedFlag(vnfId); + } catch (Exception ex) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); + } + if (inPserversLocked) { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "VNF PServers in Locked in A&AI"); + } + } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java index 0c65abfe0c..48a1c1e558 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/AAIVnfResources.java @@ -22,6 +22,7 @@ package org.onap.so.client.orchestration; +import java.io.IOException; import java.util.Optional; import org.onap.so.bpmn.common.InjectionHelper; @@ -31,6 +32,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness; import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIValidatorImpl; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; @@ -50,6 +52,8 @@ public class AAIVnfResources { @Autowired private AAIObjectMapper aaiObjectMapper; + private AAIValidatorImpl aaiValidatorImpl= new AAIValidatorImpl(); + public void createVnfandConnectServiceInstance(GenericVnf vnf, ServiceInstance serviceInstance) { AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()); vnf.setOrchestrationStatus(OrchestrationStatus.INVENTORIED); @@ -125,4 +129,19 @@ public class AAIVnfResources { AAIResourceUri vnfURI = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()); injectionHelper.getAaiClient().connect(tenantURI, vnfURI); } + + public boolean checkVnfClosedLoopDisabledFlag(String vnfId) { + org.onap.aai.domain.yang.GenericVnf vnf = injectionHelper.getAaiClient() + .get(org.onap.aai.domain.yang.GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)) + .orElse(new org.onap.aai.domain.yang.GenericVnf()); + return vnf.isIsClosedLoopDisabled(); + } + + public boolean checkVnfPserversLockedFlag (String vnfId) throws IOException { + org.onap.aai.domain.yang.GenericVnf vnf = injectionHelper.getAaiClient() + .get(org.onap.aai.domain.yang.GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)) + .orElse(new org.onap.aai.domain.yang.GenericVnf()); + return aaiValidatorImpl.isPhysicalServerLocked(vnf.getVnfId()); + + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java index cf28c114e8..cad97cad6e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/bpmn/common/aai/tasks/AAIFlagTasksTest.java @@ -29,6 +29,8 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import java.io.IOException; + import org.camunda.bpm.engine.delegate.BpmnError; import org.junit.Before; import org.junit.Test; @@ -119,4 +121,89 @@ public class AAIFlagTasksTest extends BaseTaskTest { verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); } } + + @Test + public void checkVnfClosedLoopDisabledTestTrue() throws Exception { + doThrow(new BpmnError("VNF Closed Loop Disabled in A&AI")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + doReturn(false).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class)); + try { + aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution); + } catch (Exception e) { + verify(aaiVnfResources, times(1)).checkVnfClosedLoopDisabledFlag(any(String.class)); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), eq("VNF Closed Loop Disabled in A&AI")); + } + } + + @Test + public void checkVnfClosedLoopDisabledTestFalse() throws Exception { + doReturn(false).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class)); + aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution); + verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), any(int.class), any(String.class)); + } + + @Test + public void checkVnfClosedLoopDisabledFlagExceptionTest() { + + doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + doThrow(RuntimeException.class).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class)); + try { + aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution); + } catch (Exception e) { + verify(aaiVnfResources, times(1)).checkVnfClosedLoopDisabledFlag(any(String.class)); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + } + } + + @Test + public void modifyVnfClosedLoopDisabledFlagTest() throws Exception { + doNothing().when(aaiVnfResources).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class)); + aaiFlagTasks.modifyVnfClosedLoopDisabledFlag(execution, true); + verify(aaiVnfResources, times(1)).updateObjectVnf(ArgumentMatchers.any(GenericVnf.class)); + } + + @Test + public void modifyVnfClosedLoopDisabledFlagExceptionTest() { + + doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + doThrow(RuntimeException.class).when(aaiVnfResources).updateObjectVnf(isA(GenericVnf.class)); + try { + aaiFlagTasks.modifyVnfClosedLoopDisabledFlag(execution, true); + } catch (Exception e) { + verify(aaiVnfResources, times(1)).checkVnfClosedLoopDisabledFlag(any(String.class)); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + } + } + + + @Test + public void checkVnfPserversLockedFlagTestTrue() throws Exception { + doThrow(new BpmnError("VNF PServers in Locked in A&AI")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + doReturn(true).when(aaiVnfResources).checkVnfPserversLockedFlag(isA(String.class)); + try { + aaiFlagTasks.checkVnfClosedLoopDisabledFlag(execution); + } catch (Exception e) { + verify(aaiVnfResources, times(1)).checkVnfPserversLockedFlag(any(String.class)); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), eq("VNF PServers in Locked in A&AI")); + } + } + + @Test + public void checkVnfPserversLockedFlagTestFalse() throws Exception { + doReturn(false).when(aaiVnfResources).checkVnfPserversLockedFlag(isA(String.class)); + aaiFlagTasks.checkVnfPserversLockedFlag(execution); + verify(exceptionUtil, times(0)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), any(int.class), any(String.class)); + } + + @Test + public void checkVnfPserversLockedFlagExceptionTest() throws IOException { + + doThrow(new BpmnError("Unknown Error")).when(exceptionUtil).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + doThrow(RuntimeException.class).when(aaiVnfResources).checkVnfClosedLoopDisabledFlag(isA(String.class)); + try { + aaiFlagTasks.checkVnfPserversLockedFlag(execution); + } catch (Exception e) { + verify(aaiVnfResources, times(1)).checkVnfPserversLockedFlag(any(String.class)); + verify(exceptionUtil, times(1)).buildAndThrowWorkflowException(any(BuildingBlockExecution.class), eq(7000), any(String.class)); + } + } } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java index b87b5e4166..d499bcd36e 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/orchestration/AAIVnfResourcesTest.java @@ -21,6 +21,7 @@ package org.onap.so.client.orchestration; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isA; @@ -29,6 +30,7 @@ import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import java.io.IOException; import java.util.Optional; import org.junit.Before; @@ -47,6 +49,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.client.aai.AAIObjectType; import org.onap.so.client.aai.AAIResourcesClient; +import org.onap.so.client.aai.AAIValidatorImpl; import org.onap.so.client.aai.entities.uri.AAIResourceUri; import org.onap.so.client.aai.entities.uri.AAIUriFactory; import org.onap.so.client.aai.mapper.AAIObjectMapper; @@ -70,6 +73,9 @@ public class AAIVnfResourcesTest extends TestDataSetup { @Mock protected InjectionHelper MOCK_injectionHelper; + @Mock + protected AAIValidatorImpl MOCK_aaiValidatorImpl; + @InjectMocks AAIVnfResources aaiVnfResources = new AAIVnfResources(); @@ -182,4 +188,29 @@ public class AAIVnfResourcesTest extends TestDataSetup { eq(AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, cloudRegion.getCloudOwner(), cloudRegion.getLcpCloudRegionId()))); } + + + @Test + public void checkVnfClosedLoopDisabledFlagTest () { + Optional vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf()); + vnf.get().setVnfId("vnfId"); + vnf.get().setIsClosedLoopDisabled(true); + doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class)); + boolean isCheckVnfClosedLoopDisabledFlag = aaiVnfResources.checkVnfClosedLoopDisabledFlag("vnfId"); + verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class)); + assertEquals(isCheckVnfClosedLoopDisabledFlag, true); + } + + @Test + public void checkVnfPserversLockedFlagTest () throws IOException { + + Optional vnf = Optional.of(new org.onap.aai.domain.yang.GenericVnf()); + vnf.get().setVnfId("vnfId"); + doReturn(vnf).when(MOCK_aaiResourcesClient).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class)); + doReturn(true).when(MOCK_aaiValidatorImpl).isPhysicalServerLocked("vnfId"); + boolean isVnfPserversLockedFlag = aaiVnfResources.checkVnfPserversLockedFlag("vnfId"); + verify(MOCK_aaiResourcesClient, times(1)).get(eq(org.onap.aai.domain.yang.GenericVnf.class),isA(AAIResourceUri.class)); + verify(MOCK_aaiValidatorImpl, times(1)).isPhysicalServerLocked(isA(String.class)); + assertTrue(isVnfPserversLockedFlag); + } } diff --git a/common/src/main/java/org/onap/so/client/aai/AAIValidatorImpl.java b/common/src/main/java/org/onap/so/client/aai/AAIValidatorImpl.java index 6ece8a2620..1bd7720e55 100644 --- a/common/src/main/java/org/onap/so/client/aai/AAIValidatorImpl.java +++ b/common/src/main/java/org/onap/so/client/aai/AAIValidatorImpl.java @@ -26,8 +26,7 @@ import java.util.List; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.Pserver; import org.springframework.beans.factory.annotation.Autowired; - - +import org.springframework.stereotype.Component; public class AAIValidatorImpl implements AAIValidator { @@ -50,10 +49,12 @@ public class AAIValidatorImpl implements AAIValidator { List pservers; boolean isLocked = false; pservers = client.getPhysicalServerByVnfId(vnfId); - for (Pserver pserver : pservers) - if (pserver.isInMaint()) + for (Pserver pserver : pservers) { + if (pserver.isInMaint()) { isLocked = true; - + return isLocked; + } + } return isLocked; } diff --git a/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java b/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java index f32633122d..85d690feaf 100644 --- a/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java +++ b/common/src/test/java/org/onap/so/client/aai/AAIValidatorTest.java @@ -49,11 +49,25 @@ public class AAIValidatorTest { validator.setClient(client); } - public List getPservers(boolean locked){ - Pserver pserver = new Pserver(); - pserver.setInMaint(locked); + public List getPserversLocked(){ + Pserver pserver1 = new Pserver(); + pserver1.setInMaint(true); + Pserver pserver2 = new Pserver(); + pserver2.setInMaint(false); List pservers = new ArrayList(); - pservers.add(pserver); + pservers.add(pserver1); + pservers.add(pserver2); + return pservers; + } + + public List getPserversNotLocked(){ + Pserver pserver1 = new Pserver(); + pserver1.setInMaint(false); + Pserver pserver2 = new Pserver(); + pserver2.setInMaint(false); + List pservers = new ArrayList(); + pservers.add(pserver1); + pservers.add(pserver2); return pservers; } @@ -64,15 +78,15 @@ public class AAIValidatorTest { } @Test - public void test_IsPhysicalServerLocked_True() throws IOException{ - when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPservers(true)); + public void test_IsPhysicalServerLocked_True() throws IOException{ + when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversLocked()); boolean locked = validator.isPhysicalServerLocked(vnfName); assertEquals(true, locked); } @Test public void test_IsPhysicalServerLocked_False() throws IOException { - when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPservers(false)); + when(client.getPhysicalServerByVnfId(vnfName)).thenReturn(getPserversNotLocked()); boolean locked = validator.isPhysicalServerLocked(vnfName); assertEquals(false, locked); }