From 5c788af30b182a75979ea30c76eb83511f5c944d Mon Sep 17 00:00:00 2001 From: biniek Date: Tue, 20 Mar 2018 16:41:13 +0100 Subject: Added subworkflow for Pnf pnp Change-Id: Ifeba2e74a03ce8c5a13b80f673809c3ef60bfe3f Issue-ID: SO-506 Signed-off-by: biniek --- .../policy/CommonObjectMapperProviderTest.java | 44 ++++ bpmn/MSOInfrastructureBPMN/pom.xml | 14 +- .../infrastructure/pnf/aai/AaiConnectionImpl.java | 45 ++++ .../delegate/CheckAaiForCorrelationIdDelegate.java | 78 ++++++ .../delegate/CreateAaiEntryWithPnfIdDelegate.java | 54 ++++ .../pnf/delegate/ExecutionVariableNames.java | 30 +++ .../pnf/implementation/AaiConnection.java | 32 +++ .../pnf/implementation/AaiResponse.java | 51 ++++ .../CheckAaiForCorrelationIdImplementation.java | 51 ++++ .../process/CreateAndActivatePnfResource.bpmn | 264 ++++++++++++++++++++ .../src/main/webapp/WEB-INF/applicationContext.xml | 9 + .../pnf/delegate/AaiConnectionTestImpl.java | 71 ++++++ .../delegate/AaiConnectionThrowingException.java | 39 +++ .../CheckAaiForCorrelationIdDelegateTest.java | 129 ++++++++++ .../bpmn/CreateAndActivatePnfResourceTest.java | 141 +++++++++++ .../resources/applicationContext_forPnfTesting.xml | 59 +++++ .../src/test/resources/log4j.properties | 8 + .../mso/client/aai/AAIResourcesClient.java | 12 +- .../openecomp/mso/client/aai/AAIRestClientI.java | 8 +- .../mso/client/aai/AAIRestClientImpl.java | 276 ++++++++++++--------- 20 files changed, 1289 insertions(+), 126 deletions(-) create mode 100644 bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/policy/CommonObjectMapperProviderTest.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/aai/AaiConnectionImpl.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiConnection.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml create mode 100644 bpmn/MSOInfrastructureBPMN/src/test/resources/log4j.properties diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/policy/CommonObjectMapperProviderTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/policy/CommonObjectMapperProviderTest.java new file mode 100644 index 0000000000..e1b1770180 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/openecomp/mso/client/policy/CommonObjectMapperProviderTest.java @@ -0,0 +1,44 @@ +/*- + * ============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.openecomp.mso.client.policy; + +import static org.assertj.core.api.Assertions.assertThat; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.junit.Test; + +public class CommonObjectMapperProviderTest { + + @Test + public void shouldSetCorrectMapperProperties() throws Exception { + // given + CommonObjectMapperProvider provider = new CommonObjectMapperProvider(); + // when + ObjectMapper context = provider.getContext(Object.class); + // then + assertThat(context.isEnabled(MapperFeature.USE_ANNOTATIONS)).isTrue(); + assertThat(context.isEnabled(SerializationFeature.WRAP_ROOT_VALUE)).isFalse(); + assertThat(context.isEnabled(DeserializationFeature.UNWRAP_ROOT_VALUE)).isFalse(); + } +} \ No newline at end of file diff --git a/bpmn/MSOInfrastructureBPMN/pom.xml b/bpmn/MSOInfrastructureBPMN/pom.xml index e6434092e1..be2a1dacbe 100644 --- a/bpmn/MSOInfrastructureBPMN/pom.xml +++ b/bpmn/MSOInfrastructureBPMN/pom.xml @@ -209,7 +209,7 @@ org.camunda.bpm.extension camunda-bpm-assert - 1.2 + 2.0-alpha2 test @@ -366,6 +366,18 @@ libphonenumber 8.9.1 + + org.assertj + assertj-core + 2.4.0 + test + + + org.springframework.boot + spring-boot-test + 1.4.2.RELEASE + test + ch.qos.logback logback-classic diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/aai/AaiConnectionImpl.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/aai/AaiConnectionImpl.java new file mode 100644 index 0000000000..2be5ebdc5d --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/aai/AaiConnectionImpl.java @@ -0,0 +1,45 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.aai; + +import java.io.IOException; +import java.util.Optional; +import java.util.UUID; +import org.apache.commons.lang.NotImplementedException; +import org.onap.aai.domain.yang.Pnf; +import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiConnection; +import org.openecomp.mso.client.aai.AAIRestClientImpl; +import org.springframework.stereotype.Component; + +public class AaiConnectionImpl implements AaiConnection { + + @Override + public Optional getEntryFor(String correlationId) throws IOException { + AAIRestClientImpl restClient = new AAIRestClientImpl(); + return restClient.getPnfByName(correlationId, UUID.randomUUID().toString()); + } + + @Override + public void createEntry(String correlationId, Pnf entry) throws IOException { + AAIRestClientImpl restClient = new AAIRestClientImpl(); + restClient.createPnf(correlationId, UUID.randomUUID().toString(), entry); + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java new file mode 100644 index 0000000000..f4483f5923 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegate.java @@ -0,0 +1,78 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; + +import java.io.IOException; +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiConnection; +import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiResponse; +import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.CheckAaiForCorrelationIdImplementation; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Implementation of "Check AAI for correlation_id" task in CreateAndActivatePnfResource.bpmn + * + * Inputs: + * - correlationId - String + * + * Outputs: + * - AAI_CONTAINS_INFO_ABOUT_PNF - local Boolean + * - aaiContainsInfoAboutIp - local Boolean (only present if AAI_CONTAINS_INFO_ABOUT_PNF is true) + */ + +public class CheckAaiForCorrelationIdDelegate implements JavaDelegate { + + private CheckAaiForCorrelationIdImplementation implementation = new CheckAaiForCorrelationIdImplementation(); + 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); + if (correlationId == null) { + //todo: fix Execution -> DelegateExecution in ALL groovy scripts +// new ExceptionUtil().buildAndThrowWorkflowException(execution, 500, CORRELATION_ID + " is not set"); + throw new BpmnError("MSOWorkflowException"); + } + + try { + AaiResponse aaiResponse = implementation.check(correlationId, aaiConnection); + + execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, aaiResponse.getContainsInfoAboutPnf()); + aaiResponse.getContainsInfoAboutIp().ifPresent( + isIp -> execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, isIp) + ); + } catch (IOException e) { + //todo: log this + throw new BpmnError("MSOWorkflowException"); + } + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.java new file mode 100644 index 0000000000..bc424fd347 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CreateAaiEntryWithPnfIdDelegate.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.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import static org.openecomp.mso.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.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiConnection; +import org.springframework.beans.factory.annotation.Autowired; + +/** + * Implementation of "Create AAI entry with pnf-id = correlation_id" task in CreateAndActivatePnfResource.bpmn + * + * Inputs: + * - correlationId - String + */ +public class CreateAaiEntryWithPnfIdDelegate implements JavaDelegate { + + 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.setInMaint(true); + pnf.setPnfId(correlationId); + aaiConnection.createEntry(correlationId, pnf); + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java new file mode 100644 index 0000000000..6b49908a0f --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/ExecutionVariableNames.java @@ -0,0 +1,30 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +@SuppressWarnings("ALL") +public class ExecutionVariableNames { + + public final static String CORRELATION_ID = "correlationId"; + public final static String AAI_CONTAINS_INFO_ABOUT_PNF = "aaiContainsInfoAboutPnf"; + public final static String AAI_CONTAINS_INFO_ABOUT_IP = "aaiContainsInfoAboutIp"; + public final static String DMAAP_MESSAGE = "dmaapMessage"; +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiConnection.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiConnection.java new file mode 100644 index 0000000000..0bb63d5e68 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiConnection.java @@ -0,0 +1,32 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.implementation; + +import java.io.IOException; +import java.util.Optional; +import org.onap.aai.domain.yang.Pnf; + +public interface AaiConnection { + + Optional getEntryFor(String correlationId) throws IOException; + + void createEntry(String correlationId, Pnf entry) throws IOException; +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java new file mode 100644 index 0000000000..bbb7adc143 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/AaiResponse.java @@ -0,0 +1,51 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.implementation; + +import java.util.Optional; +import javax.annotation.Nullable; +import javax.validation.constraints.NotNull; + +public class AaiResponse { + + private Boolean containsInfoAboutPnf; + private Boolean containsInfoAboutIp; + private String ipAddress; + + public AaiResponse(@NotNull Boolean containsInfoAboutPnf, @Nullable Boolean containsInfoAboutIp, + @Nullable String ipAddress) { + this.containsInfoAboutPnf = containsInfoAboutPnf; + this.containsInfoAboutIp = containsInfoAboutIp; + this.ipAddress = ipAddress; + } + + public Boolean getContainsInfoAboutPnf() { + return containsInfoAboutPnf; + } + + public Optional getContainsInfoAboutIp() { + return Optional.ofNullable(containsInfoAboutIp); + } + + public Optional getIpAddress() { + return Optional.ofNullable(ipAddress); + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java new file mode 100644 index 0000000000..353a3bd5d3 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/java/org/openecomp/mso/bpmn/infrastructure/pnf/implementation/CheckAaiForCorrelationIdImplementation.java @@ -0,0 +1,51 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.implementation; + +import java.io.IOException; +import java.util.Optional; +import org.onap.aai.domain.yang.Pnf; + +public class CheckAaiForCorrelationIdImplementation { + + public AaiResponse check(String correlationId, AaiConnection aaiConnection) throws IOException { + Optional pnf = aaiConnection.getEntryFor(correlationId); + if (!pnf.isPresent()) { + return new AaiResponse(false, null, null); + } + + Optional ip = extractIp(pnf.get()); + return ip.map( + s -> new AaiResponse(true, true, s) + ).orElseGet( + () -> new AaiResponse(true, false, null) + ); + } + + private Optional extractIp(Pnf pnf) { + if (pnf.getIpaddressV4Oam() != null) { + return Optional.of(pnf.getIpaddressV4Oam()); + } else { + return Optional.ofNullable(pnf.getIpaddressV6Oam()); + } + } + +} diff --git a/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn b/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn new file mode 100644 index 0000000000..262e08689d --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/main/resources/process/CreateAndActivatePnfResource.bpmn @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + #{!aaiContainsInfoAboutIp} + + + + #{aaiContainsInfoAboutPnf} + + + #{!aaiContainsInfoAboutPnf} + + + + #{aaiContainsInfoAboutIp} + + + + SequenceFlow_1h6yz62 + + + SequenceFlow_0p09qgm + + + SequenceFlow_0j5ksz1 + + + + + + SequenceFlow_0j5ksz1 + SequenceFlow_1j4r3zt + + + SequenceFlow_1j4r3zt + SequenceFlow_1l1t6ak + SequenceFlow_0v5ffpe + + + SequenceFlow_0v5ffpe + SequenceFlow_1qr6cmf + + + SequenceFlow_1l1t6ak + SequenceFlow_1h6yz62 + SequenceFlow_1ls8pua + + + SequenceFlow_1qr6cmf + SequenceFlow_1ls8pua + SequenceFlow_17s9025 + + + SequenceFlow_17s9025 + SequenceFlow_0p09qgm + + + SequenceFlow_1kc34bc + + #{timeoutForPnfEntryNotification} + + + + SequenceFlow_1kc34bc + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml index 6f61c8fbf4..46cea5da63 100644 --- a/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml +++ b/bpmn/MSOInfrastructureBPMN/src/main/webapp/WEB-INF/applicationContext.xml @@ -4,5 +4,14 @@ http://www.springframework.org/schema/beans/spring-beans.xsd"> + + + + + + + + + diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java new file mode 100644 index 0000000000..1ad1f9e5a4 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionTestImpl.java @@ -0,0 +1,71 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import java.io.IOException; +import java.util.LinkedList; +import java.util.List; +import java.util.Objects; +import java.util.Optional; +import org.onap.aai.domain.yang.Pnf; +import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiConnection; + +public class AaiConnectionTestImpl implements AaiConnection { + + public static final String ID_WITH_ENTRY_AND_IP = "idWithEntryAndIp"; + public static final String ID_WITH_IP_V6 = "idWithIpV6"; + public static final String ID_WITHOUT_ENTRY = "IdWithoutEntry"; + public static final String ID_WITH_ENTRY_NO_IP = "idWithEntryNoIp"; + public static final String DEFAULT_IP = "1.2.3.4"; + public static final String DEFAULT_IP_V6 = "2001:db8::ff00:42:8329"; + + private List created = new LinkedList<>(); + + @Override + public Optional getEntryFor(String correlationId) throws IOException { + if (Objects.equals(correlationId, ID_WITH_ENTRY_AND_IP)) { + Pnf pnf = new Pnf(); + pnf.setIpaddressV4Oam(DEFAULT_IP); + return Optional.of(pnf); + } else if (Objects.equals(correlationId, ID_WITH_IP_V6)) { + Pnf pnf = new Pnf(); + pnf.setIpaddressV6Oam(DEFAULT_IP_V6); + return Optional.of(pnf); + } else if (Objects.equals(correlationId, ID_WITH_ENTRY_NO_IP)) { + return Optional.of(new Pnf()); + } else { + return Optional.empty(); + } + } + + @Override + public void createEntry(String correlationId, Pnf entry) throws IOException { + created.add(correlationId); + } + + public List getCreated() { + return created; + } + + public void reset() { + created.clear(); + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java new file mode 100644 index 0000000000..9a8dd5df24 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/AaiConnectionThrowingException.java @@ -0,0 +1,39 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import java.io.IOException; +import java.util.Optional; +import org.onap.aai.domain.yang.Pnf; +import org.openecomp.mso.bpmn.infrastructure.pnf.implementation.AaiConnection; + +public class AaiConnectionThrowingException implements AaiConnection { + + @Override + public Optional getEntryFor(String correlationId) throws IOException { + throw new IOException(); + } + + @Override + public void createEntry(String correlationId, Pnf entry) throws IOException { + throw new IOException(); + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java new file mode 100644 index 0000000000..d98a395838 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/CheckAaiForCorrelationIdDelegateTest.java @@ -0,0 +1,129 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.delegate; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.DEFAULT_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_IP_V6; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; + +import org.camunda.bpm.engine.delegate.BpmnError; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.junit.Test; +import org.junit.experimental.runners.Enclosed; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(Enclosed.class) +public class CheckAaiForCorrelationIdDelegateTest { + + @RunWith(SpringRunner.class) + @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionTestImpl.class}) + public static class ConnectionOkTests { + + @Autowired + private CheckAaiForCorrelationIdDelegate delegate; + + @Test + public void shouldThrowExceptionWhenCorrelationIdIsNotSet() throws Exception { + // given + DelegateExecution execution = mock(DelegateExecution.class); + when(execution.getVariable(CORRELATION_ID)).thenReturn(null); + when(execution.getVariable("testProcessKey")).thenReturn("testProcessKeyValue"); + // when, then + assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class); + // todo: uncomment line below after fixing Execution -> DelecateExecution in groovy scripts +// verify(execution).setVariable(eq("WorkflowException"), any(WorkflowException.class)); + } + + @Test + public void shouldSetCorrectVariablesWhenAaiDoesNotContainInfoAboutPnf() throws Exception { + // given + DelegateExecution execution = mock(DelegateExecution.class); + when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITHOUT_ENTRY); + // when + delegate.execute(execution); + // then + verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, false); + } + + @Test + public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf() throws Exception { + shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_ENTRY_AND_IP); + } + + @Test + public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithIpV6() throws Exception { + shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(ID_WITH_IP_V6); + } + + private void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnf(String id) throws Exception { + // given + DelegateExecution execution = mock(DelegateExecution.class); + when(execution.getVariable(CORRELATION_ID)).thenReturn(id); + // when + delegate.execute(execution); + // then + verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true); + verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, true); + } + + @Test + public void shouldSetCorrectVariablesWhenAaiContainsInfoAboutPnfWithoutIp() throws Exception { + // given + DelegateExecution execution = mock(DelegateExecution.class); + when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP); + // when + delegate.execute(execution); + // then + verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, true); + verify(execution).setVariableLocal(AAI_CONTAINS_INFO_ABOUT_IP, false); + } + } + + + @RunWith(SpringRunner.class) + @SpringBootTest(classes = {CheckAaiForCorrelationIdDelegate.class, AaiConnectionThrowingException.class}) + public static class NoConnectionTests { + + @Autowired + private CheckAaiForCorrelationIdDelegate delegate; + + @Test + public void shouldThrowExceptionWhenSSADFDSADSFDS() throws Exception { + // given + DelegateExecution execution = mock(DelegateExecution.class); + when(execution.getVariable(CORRELATION_ID)).thenReturn(ID_WITH_ENTRY_NO_IP); + // when, then + assertThatThrownBy(() -> delegate.execute(execution)).isInstanceOf(BpmnError.class); + } + } +} \ No newline at end of file diff --git a/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java new file mode 100644 index 0000000000..88e7d2f4b3 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/java/org/openecomp/mso/bpmn/infrastructure/pnf/delegate/bpmn/CreateAndActivatePnfResourceTest.java @@ -0,0 +1,141 @@ +/*- + * ============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.openecomp.mso.bpmn.infrastructure.pnf.delegate.bpmn; + +import static org.camunda.bpm.engine.test.assertions.ProcessEngineAssertions.assertThat; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITHOUT_ENTRY; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_AND_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl.ID_WITH_ENTRY_NO_IP; +import static org.openecomp.mso.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.history.HistoricVariableInstance; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.camunda.bpm.engine.test.Deployment; +import org.camunda.bpm.engine.test.ProcessEngineRule; +import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openecomp.mso.bpmn.infrastructure.pnf.delegate.AaiConnectionTestImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ContextConfiguration(locations = "/applicationContext_forPnfTesting.xml") +public class CreateAndActivatePnfResourceTest { + + private static final String TIMEOUT_10_S = "PT10S"; + @Autowired + private RuntimeService runtimeService; + + @Autowired + @Rule + public ProcessEngineRule processEngineRule; + + @Autowired + private AaiConnectionTestImpl aaiConnection; + + @Test + @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"}) + public void shouldSaveCurrentIpToVariableIfItAlreadyExistsInAai() throws Exception { + // given + aaiConnection.reset(); + BpmnAwareTests.init(processEngineRule.getProcessEngine()); + Map variables = new HashMap<>(); + variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S); + variables.put(CORRELATION_ID, ID_WITH_ENTRY_AND_IP); + // when + ProcessInstance instance = runtimeService + .startProcessInstanceByKey("CreateAndActivatePnfResource", variables); + // then + assertThat(instance).isEnded().hasPassedInOrder( + "CreateAndActivatePnf_StartEvent", + "CheckAiiForCorrelationId", + "DoesAaiContainInfoAboutPnf", + "DoesAaiContainInfoAboutIp" + ); + } + + @Test + @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"}) + public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenIpIsMissingInAaiEntry() throws Exception { + // given + aaiConnection.reset(); + BpmnAwareTests.init(processEngineRule.getProcessEngine()); + Map variables = new HashMap<>(); + variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S); + variables.put(CORRELATION_ID, ID_WITH_ENTRY_NO_IP); + // when + ProcessInstance instance = runtimeService + .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables); + assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage"); + runtimeService.createMessageCorrelation("WorkflowMessage") + .processInstanceBusinessKey("businessKey") + .correlateWithResult(); + // then + assertThat(instance).isEnded().hasPassedInOrder( + "CreateAndActivatePnf_StartEvent", + "CheckAiiForCorrelationId", + "DoesAaiContainInfoAboutPnf", + "DoesAaiContainInfoAboutIp", + "AaiEntryExists", + "WaitForDmaapPnfReadyNotification" + ); + } + + @Test + @Deployment(resources = {"process/CreateAndActivatePnfResource.bpmn"}) + public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntry() throws Exception { + // given + aaiConnection.reset(); + BpmnAwareTests.init(processEngineRule.getProcessEngine()); + Map variables = new HashMap<>(); + variables.put("timeoutForPnfEntryNotification", TIMEOUT_10_S); + variables.put(CORRELATION_ID, ID_WITHOUT_ENTRY); + // when + ProcessInstance instance = runtimeService + .startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables); + assertThat(instance).isWaitingAt("WaitForDmaapPnfReadyNotification").isWaitingFor("WorkflowMessage"); + runtimeService.createMessageCorrelation("WorkflowMessage") + .processInstanceBusinessKey("businessKey") + .correlateWithResult(); + // then + assertThat(instance).isEnded().hasPassedInOrder( + "CreateAndActivatePnf_StartEvent", + "CheckAiiForCorrelationId", + "DoesAaiContainInfoAboutPnf", + "CreateAndActivatePnf_CreateAaiEntry", + "AaiEntryExists", + "WaitForDmaapPnfReadyNotification" + ); + assertThat(aaiConnection.getCreated()).containsExactly(ID_WITHOUT_ENTRY); + } + + private List getVariables(ProcessInstance instance) { + return processEngineRule.getHistoryService().createHistoricVariableInstanceQuery() + .processInstanceId(instance.getProcessInstanceId()).taskIdIn().list(); + } +} diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml b/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml new file mode 100644 index 0000000000..b222383c82 --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/applicationContext_forPnfTesting.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bpmn/MSOInfrastructureBPMN/src/test/resources/log4j.properties b/bpmn/MSOInfrastructureBPMN/src/test/resources/log4j.properties new file mode 100644 index 0000000000..393e0877ec --- /dev/null +++ b/bpmn/MSOInfrastructureBPMN/src/test/resources/log4j.properties @@ -0,0 +1,8 @@ +# Root logger option +log4j.rootLogger=INFO, stdout + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java index 32c61f7fd7..c55e5e9eee 100644 --- a/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java +++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIResourcesClient.java @@ -28,6 +28,7 @@ import javax.ws.rs.NotFoundException; import javax.ws.rs.client.ResponseProcessingException; import javax.ws.rs.core.GenericType; +import javax.ws.rs.core.Response; import org.onap.aai.domain.yang.Relationship; import org.openecomp.mso.client.aai.entities.AAIResultWrapper; import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; @@ -153,7 +154,7 @@ public class AAIResourcesClient extends AAIClient { aaiRC.patch(obj); return; } - + /** * Retrieves an object from A&AI and unmarshalls it into the Class specified * @param clazz @@ -163,6 +164,15 @@ public class AAIResourcesClient extends AAIClient { public T get(Class clazz, AAIResourceUri uri) { return this.createClient(uri).get(clazz); } + + /** + * Retrieves an object from A&AI and returns complete response + * @param uri + * @return + */ + public Response getFullResponse(AAIResourceUri uri) { + return this.createClient(uri).get(); + } /** * Retrieves an object from A&AI and automatically unmarshalls it into a Map or List diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientI.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientI.java index 801c0f91d4..6819ba1edf 100644 --- a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientI.java +++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientI.java @@ -23,7 +23,9 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.List; +import java.util.Optional; import org.onap.aai.domain.yang.GenericVnf; +import org.onap.aai.domain.yang.Pnf; import org.onap.aai.domain.yang.Pserver; import org.onap.aai.domain.yang.Pservers; @@ -39,6 +41,10 @@ public interface AAIRestClientI { void updateMaintenceFlag(String vnfId,boolean inMaint, String transactionLoggingUuid) throws Exception; void updateMaintenceFlagVnfId(String vnfId, boolean inMaint, String transactionLoggingUuid) throws Exception; - + GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws Exception; + + Optional getPnfByName(String pnfId, String transactionLoggingUuid) throws Exception; + + void createPnf(String pnfId, String transactionLoggingUuid, Pnf pnf) throws IOException; } diff --git a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java index e27075d9dd..54aab5c296 100644 --- a/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java +++ b/common/src/main/java/org/openecomp/mso/client/aai/AAIRestClientImpl.java @@ -20,14 +20,20 @@ package org.openecomp.mso.client.aai; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.UUID; - +import javax.ws.rs.core.Response; import org.onap.aai.domain.yang.GenericVnf; import org.onap.aai.domain.yang.GenericVnfs; +import org.onap.aai.domain.yang.Pnf; import org.onap.aai.domain.yang.Pserver; import org.onap.aai.domain.yang.Pservers; import org.openecomp.mso.client.aai.entities.CustomQuery; @@ -36,130 +42,154 @@ import org.openecomp.mso.client.aai.entities.uri.AAIResourceUri; import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory; import org.springframework.stereotype.Service; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - @Service public class AAIRestClientImpl implements AAIRestClientI { - - private static final EELFLogger logger = EELFManager.getInstance().getMetricsLogger(); - private static final AAIVersion ENDPOINT_VERSION = AAIVersion.V10; - private static final String ENDPOINT_GET_ALL = ENDPOINT_VERSION + "/cloud-infrastructure/pservers"; - private static final String ENDPOINT_GET_ALL_VNFS = ENDPOINT_VERSION + "/network/generic-vnfs"; - private static final String ENDPOINT_CUSTOM_QUERY = ENDPOINT_VERSION + "/query"; - private static final String PSERVER_VNF_QUERY = "pservers-fromVnf"; - private static final String GENERIC_VNF_PATH = ENDPOINT_VERSION + "/network/generic-vnfs/generic-vnf"; - private static final String SERVICE_TOPOLOGY_BY_SERVICE_INSTANCE_ID = "store(‘x’).union(__.in(‘subscribesTo’).has(‘aai-node-type’,’customer’).store(‘x’),__.out(‘uses’).has(‘aai-node-type’,’allotted-resource’).store(‘x’),__.in(‘hasInstance’).has(‘aai-node-type’,’generic-vnf’).store(‘x’).union(" - + ".out(‘has’).has(‘aai-node-type’,’vf-module’).store(‘x’),out(‘uses’).has(‘aai-node-type’,’volume-group’).store(‘x’)," - + ".out(‘hasLInterface’).has(‘aai-node-type’,’l-interface’).union(" - + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv4-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)," - + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv6-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)" - + ")," + ".out(‘runsOnVserver’).has(‘aai-node-type’,’vserver’).store(‘x’).union(" - + ".in(‘owns’).has(‘aai-node-type’,’tenant’).store(‘x’).in(‘has’).has(‘aai-node-type’,’cloud-region’).store(‘x’)," - + ".out(‘runsOnPserver’).has(‘aai-node-type’,’pserver’).store(‘x’)," - + ".out(‘hasLInterface’).has(‘aai-node-type’,’l-interface’).union(" - + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv4-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)," - + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv6-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)" - + ")" + ")" + ")" + ").cap(‘x’).unfold().dedup()"; - - public AAIRestClientImpl() { - - - } - - public AAIRestClientImpl(final String host) { - - - } - - @Override - public Pservers getPhysicalServers(String hostName, String uuid) { - UUID requestId; - try { - requestId = UUID.fromString(uuid); - } catch (IllegalArgumentException e) { - logger.warn("could not parse uuid: " + uuid + " creating valid uuid automatically"); - requestId = UUID.randomUUID(); - } - return new AAIResourcesClient(ENDPOINT_VERSION, requestId).get(Pservers.class, AAIUriFactory.createResourceUri(AAIObjectPlurals.PSERVER)); - } - - @Override - public List getPhysicalServerByVnfId(String vnfId, String transactionLoggingUuid) - throws JsonParseException, JsonMappingException, IOException { - UUID requestId; - try { - requestId = UUID.fromString(transactionLoggingUuid); - } catch (IllegalArgumentException e) { - logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); - requestId = UUID.randomUUID(); - } - List startNodes = new ArrayList<>(); - startNodes.add(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)); - String jsonInput = new AAIQueryClient(ENDPOINT_VERSION, requestId).query(Format.RESOURCE, new CustomQuery(startNodes,PSERVER_VNF_QUERY)); - - return this.getListOfPservers(jsonInput); - - } - - protected List getListOfPservers(String jsonInput) throws JsonParseException, JsonMappingException, IOException { - ObjectMapper mapper = new AAICommonObjectMapperProvider().getContext(Object.class); - Results> resultsFromJson = mapper.readValue(jsonInput, - new TypeReference>>() { - }); - List results = new ArrayList<>(); - for (Map m : resultsFromJson.getResult()) { - results.add(m.get("pserver")); - } - return results; - } - @Override - public void updateMaintenceFlag(String vnfName, boolean inMaint, String transactionLoggingUuid) throws JsonParseException, JsonMappingException, IOException { - UUID requestId; - try { - requestId = UUID.fromString(transactionLoggingUuid); - } catch (IllegalArgumentException e) { - logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); - requestId = UUID.randomUUID(); - } - GenericVnfs genericVnfs = new AAIResourcesClient(ENDPOINT_VERSION, requestId).get(GenericVnfs.class, AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName)); - if(genericVnfs.getGenericVnf().size() > 1) - throw new IndexOutOfBoundsException("Multiple Generic Vnfs Returned"); - - GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0); - updateMaintenceFlagVnfId(genericVnf.getVnfId(), inMaint, transactionLoggingUuid); - } - - @Override - public void updateMaintenceFlagVnfId(String vnfId, boolean inMaint, String transactionLoggingUuid) throws JsonParseException, JsonMappingException, IOException { - UUID requestId; - try { - requestId = UUID.fromString(transactionLoggingUuid); - } catch (IllegalArgumentException e) { - logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); - requestId = UUID.randomUUID(); - } - GenericVnf genericVnf = new GenericVnf(); - genericVnf.setInMaint(inMaint); - new AAIResourcesClient(ENDPOINT_VERSION, requestId).update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId), genericVnf); - - } - - @Override - public GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws JsonParseException, JsonMappingException, IOException { - UUID requestId; - try { - requestId = UUID.fromString(transactionLoggingUuid); - } catch (IllegalArgumentException e) { - logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); - requestId = UUID.randomUUID(); - } - return new AAIResourcesClient(ENDPOINT_VERSION, requestId).get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)); - } + private static final EELFLogger logger = EELFManager.getInstance().getMetricsLogger(); + private static final AAIVersion ENDPOINT_VERSION = AAIVersion.V10; + private static final String ENDPOINT_GET_ALL = ENDPOINT_VERSION + "/cloud-infrastructure/pservers"; + private static final String ENDPOINT_GET_ALL_VNFS = ENDPOINT_VERSION + "/network/generic-vnfs"; + private static final String ENDPOINT_CUSTOM_QUERY = ENDPOINT_VERSION + "/query"; + private static final String PSERVER_VNF_QUERY = "pservers-fromVnf"; + private static final String GENERIC_VNF_PATH = ENDPOINT_VERSION + "/network/generic-vnfs/generic-vnf"; + private static final String SERVICE_TOPOLOGY_BY_SERVICE_INSTANCE_ID = + "store(‘x’).union(__.in(‘subscribesTo’).has(‘aai-node-type’,’customer’).store(‘x’),__.out(‘uses’).has(‘aai-node-type’,’allotted-resource’).store(‘x’),__.in(‘hasInstance’).has(‘aai-node-type’,’generic-vnf’).store(‘x’).union(" + + ".out(‘has’).has(‘aai-node-type’,’vf-module’).store(‘x’),out(‘uses’).has(‘aai-node-type’,’volume-group’).store(‘x’)," + + ".out(‘hasLInterface’).has(‘aai-node-type’,’l-interface’).union(" + + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv4-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)," + + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv6-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)" + + ")," + ".out(‘runsOnVserver’).has(‘aai-node-type’,’vserver’).store(‘x’).union(" + + ".in(‘owns’).has(‘aai-node-type’,’tenant’).store(‘x’).in(‘has’).has(‘aai-node-type’,’cloud-region’).store(‘x’)," + + ".out(‘runsOnPserver’).has(‘aai-node-type’,’pserver’).store(‘x’)," + + ".out(‘hasLInterface’).has(‘aai-node-type’,’l-interface’).union(" + + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv4-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)," + + ".out(‘hasIpAddress’).has(‘aai-node-type’,’l3-interface-ipv6-address’).store(‘x’).out(‘isMemberOf’).has(‘aai-node-type’,’l3-network’).store(‘x’)" + + ")" + ")" + ")" + ").cap(‘x’).unfold().dedup()"; + + public AAIRestClientImpl() { + } + + @Override + public Pservers getPhysicalServers(String hostName, String uuid) { + UUID requestId; + try { + requestId = UUID.fromString(uuid); + } catch (IllegalArgumentException e) { + logger.warn("could not parse uuid: " + uuid + " creating valid uuid automatically"); + requestId = UUID.randomUUID(); + } + return new AAIResourcesClient(ENDPOINT_VERSION, requestId) + .get(Pservers.class, AAIUriFactory.createResourceUri(AAIObjectPlurals.PSERVER)); + } + + @Override + public List getPhysicalServerByVnfId(String vnfId, String transactionLoggingUuid) throws IOException { + UUID requestId; + try { + requestId = UUID.fromString(transactionLoggingUuid); + } catch (IllegalArgumentException e) { + logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); + requestId = UUID.randomUUID(); + } + List startNodes = new ArrayList<>(); + startNodes.add(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)); + String jsonInput = new AAIQueryClient(ENDPOINT_VERSION, requestId) + .query(Format.RESOURCE, new CustomQuery(startNodes, PSERVER_VNF_QUERY)); + + return this.getListOfPservers(jsonInput); + + } + + protected List getListOfPservers(String jsonInput) throws IOException { + ObjectMapper mapper = new AAICommonObjectMapperProvider().getContext(Object.class); + Results> resultsFromJson = mapper.readValue(jsonInput, + new TypeReference>>() { + }); + List results = new ArrayList<>(); + for (Map m : resultsFromJson.getResult()) { + results.add(m.get("pserver")); + } + return results; + } + + @Override + public void updateMaintenceFlag(String vnfName, boolean inMaint, String transactionLoggingUuid) throws IOException { + UUID requestId; + try { + requestId = UUID.fromString(transactionLoggingUuid); + } catch (IllegalArgumentException e) { + logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); + requestId = UUID.randomUUID(); + } + GenericVnfs genericVnfs = new AAIResourcesClient(ENDPOINT_VERSION, requestId).get(GenericVnfs.class, + AAIUriFactory.createResourceUri(AAIObjectPlurals.GENERIC_VNF).queryParam("vnf-name", vnfName)); + if (genericVnfs.getGenericVnf().size() > 1) { + throw new IndexOutOfBoundsException("Multiple Generic Vnfs Returned"); + } + + GenericVnf genericVnf = genericVnfs.getGenericVnf().get(0); + updateMaintenceFlagVnfId(genericVnf.getVnfId(), inMaint, transactionLoggingUuid); + } + + @Override + public void updateMaintenceFlagVnfId(String vnfId, boolean inMaint, String transactionLoggingUuid) + throws IOException { + UUID requestId; + try { + requestId = UUID.fromString(transactionLoggingUuid); + } catch (IllegalArgumentException e) { + logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); + requestId = UUID.randomUUID(); + } + GenericVnf genericVnf = new GenericVnf(); + genericVnf.setInMaint(inMaint); + new AAIResourcesClient(ENDPOINT_VERSION, requestId) + .update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId), genericVnf); + + } + + @Override + public GenericVnf getVnfByName(String vnfId, String transactionLoggingUuid) throws IOException { + UUID requestId; + try { + requestId = UUID.fromString(transactionLoggingUuid); + } catch (IllegalArgumentException e) { + logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); + requestId = UUID.randomUUID(); + } + return new AAIResourcesClient(ENDPOINT_VERSION, requestId) + .get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId)); + } + + @Override + public Optional getPnfByName(String pnfId, String transactionLoggingUuid) throws IOException { + UUID requestId; + try { + requestId = UUID.fromString(transactionLoggingUuid); + } catch (IllegalArgumentException e) { + logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); + requestId = UUID.randomUUID(); + } + Response response = new AAIResourcesClient(ENDPOINT_VERSION, requestId) + .getFullResponse(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId)); + if (response.getStatus() != 200) { + return Optional.empty(); + } else { + return Optional.of(response.readEntity(Pnf.class)); + } + } + + @Override + public void createPnf(String pnfId, String transactionLoggingUuid, Pnf pnf) throws IOException { + UUID requestId; + try { + requestId = UUID.fromString(transactionLoggingUuid); + } catch (IllegalArgumentException e) { + logger.warn("could not parse uuid: " + transactionLoggingUuid + " creating valid uuid automatically"); + requestId = UUID.randomUUID(); + } + new AAIResourcesClient(ENDPOINT_VERSION, requestId) + .createIfNotExists(AAIUriFactory.createResourceUri(AAIObjectType.PNF, pnfId), Optional.of(pnf)); + } } -- cgit 1.2.3-korg