aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2019-04-02 13:46:47 +0000
committerMichaelMorris <michael.morris@est.tech>2019-04-02 13:46:47 +0000
commit44a205e0d5fd357bd24c4298a01c74197b79efe3 (patch)
treecbcbe32c4e6fac94e58da308ac29d20a9adb3aa0 /adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter
parent1f8531ddb54b133ed0b25628d43ec698caa9b087 (diff)
Check for existing VNF in VNFM
Issue-ID: SO-1622 Change-Id: I6aa6af3c6988032f436c5da79c0140370469439e Signed-off-by: MichaelMorris <michael.morris@est.tech>
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter')
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml26
-rwxr-xr-xadapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java5
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiClientProvider.java34
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java152
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiPropertiesImpl.java68
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java72
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java90
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java39
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java51
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java47
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java97
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java13
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmNotFoundException.java35
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties1
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml8
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java2
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java296
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application-test.yaml10
18 files changed, 1029 insertions, 17 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml
index 2e1fc97336..d932c4e768 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/pom.xml
@@ -81,5 +81,31 @@
<artifactId>mso-vnfm-adapter-api</artifactId>
<version>${project.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.onap.so.adapters</groupId>
+ <artifactId>mso-vnfm-adapter-ext-clients</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.core</groupId>
+ <artifactId>jersey-client</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.inject</groupId>
+ <artifactId>jersey-hk2</artifactId>
+ <version>2.26</version>
+ </dependency>
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ </dependency>
</dependencies>
</project>
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java
index 024e936cfb..d7021e7eb8 100755
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmAdapterApplication.java
@@ -29,8 +29,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* The spring boot application for the VNFM (Virtual Network Function Manager) Adapter.
* <p>
- * The VNFM Adapter receives requests through its REST API {@link VnfmAdapterController} which it adapts
- * into ETSI SOL003 compliant LCM (Life Cycle Management) calls towards an ETSI compliant VNFM.
+ * The VNFM Adapter receives requests through its REST API {@link VnfmAdapterController} which it
+ * adapts into ETSI SOL003 compliant LCM (Life Cycle Management) calls towards an ETSI compliant
+ * VNFM.
*
* @see <a href=
* "https://www.etsi.org/deliver/etsi_gs/NFV-SOL/001_099/003/02.05.01_60/gs_nfv-sol003v020501p.pdf">ETSI
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiClientProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiClientProvider.java
new file mode 100644
index 0000000000..674314d9da
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiClientProvider.java
@@ -0,0 +1,34 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.aai;
+
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class AaiClientProvider {
+
+ @Bean
+ public AAIResourcesClient getAaiClient() {
+ return new AAIResourcesClient();
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java
new file mode 100644
index 0000000000..043d2d309d
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java
@@ -0,0 +1,152 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.aai;
+
+import java.util.Collections;
+import org.onap.aai.domain.yang.EsrSystemInfo;
+import org.onap.aai.domain.yang.EsrSystemInfoList;
+import org.onap.aai.domain.yang.EsrVnfm;
+import org.onap.aai.domain.yang.EsrVnfmList;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipData;
+import org.onap.aai.domain.yang.RelationshipList;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.AAIVersion;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * Provides helper methods for interactions with AAI.
+ */
+@Service
+public class AaiHelper {
+
+ private static final Logger logger = LoggerFactory.getLogger(AaiHelper.class);
+ private final AaiServiceProvider aaiServiceProvider;
+
+ @Autowired
+ public AaiHelper(final AaiServiceProvider aaiServiceProvider) {
+ this.aaiServiceProvider = aaiServiceProvider;
+ }
+
+ /**
+ * Add a relationship to the given generic VNF to the given VNFM.
+ *
+ * @param vnf the generic VNF
+ * @param vnfmId the ID of the VNFM
+ */
+ public void addRelationshipFromGenericVnfToVnfm(final GenericVnf vnf, final String vnfmId) {
+ if (vnf.getRelationshipList() == null) {
+ vnf.setRelationshipList(new RelationshipList());
+ }
+ final RelationshipList vnfmRelationshiplist = vnf.getRelationshipList();
+ vnfmRelationshiplist.getRelationship().add(createRelationshipToVnfm(vnfmId));
+
+ aaiServiceProvider.invokePutGenericVnf(vnf);
+ }
+
+ private Relationship createRelationshipToVnfm(final String vnfmId) {
+ final Relationship relationship = new Relationship();
+ relationship.setRelatedTo("esr-vnfm");
+ relationship.setRelationshipLabel("tosca.relationships.DependsOn");
+ relationship.setRelatedLink("/aai/" + AAIVersion.LATEST
+ + AAIUriFactory.createResourceUri(AAIObjectType.VNFM, vnfmId).build().toString());
+ relationship.getRelationshipData().add(createRelationshipData("esr-vnfm.vnfm-id", vnfmId));
+ return relationship;
+ }
+
+ private RelationshipData createRelationshipData(final String key, final String value) {
+ final RelationshipData data = new RelationshipData();
+ data.setRelationshipKey(key);
+ data.setRelationshipValue(value);
+ return data;
+ }
+
+ /**
+ * Get the VNFM assigned for use for the given generic VNF.
+ *
+ * @param vnf the generic VNF
+ * @return the VNFM to use, or <code>null</code> if no VNFM has been assigned yet
+ */
+ public EsrVnfm getAssignedVnfm(final GenericVnf vnf) {
+ for (final Relationship relationship : vnf.getRelationshipList() == null ? Collections.<Relationship>emptyList()
+ : vnf.getRelationshipList().getRelationship()) {
+ if ("esr-vnfm".equals(relationship.getRelatedTo())) {
+ return getRelatedVnfmId(relationship);
+ }
+ }
+ return null;
+ }
+
+ private EsrVnfm getRelatedVnfmId(final Relationship relationship) {
+ for (final RelationshipData relationshipData : relationship.getRelationshipData()) {
+ if ("esr-vnfm.vnfm-id".equals(relationshipData.getRelationshipKey())) {
+ logger.debug("VNFM URL from GenericVnf relataionship: " + relationshipData.getRelationshipValue());
+ return aaiServiceProvider.invokeGetVnfm(relationshipData.getRelationshipValue());
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Select a VNFM to use for the given generic VNF. Should only be used when no VNFM has already been
+ * assigned to the VNF.
+ *
+ * @param vnf the generic VNF
+ * @return the VNFM to use
+ */
+ public EsrVnfm selectVnfm(final GenericVnf vnf) {
+ final EsrVnfmList vnfmsInEsr = aaiServiceProvider.invokeGetVnfms();
+
+ if (vnfmsInEsr == null) {
+ throw new VnfmNotFoundException("No VNFMs found in AAI ESR");
+ }
+ logger.debug("VNFMs in ESR: " + vnfmsInEsr);
+
+ for (final EsrVnfm vnfm : vnfmsInEsr.getEsrVnfm()) {
+ if (vnfmHasMatchingEsrSystemInfoType(vnfm, vnf.getNfType())) {
+ return vnfm;
+ }
+ }
+ throw new VnfmNotFoundException("No matching VNFM found in AAI ESR");
+ }
+
+ private boolean vnfmHasMatchingEsrSystemInfoType(final EsrVnfm vnfm, final String type) {
+ logger.debug("Checking VNFM ID: " + vnfm + ": " + vnfm.getVnfmId());
+
+ final EsrSystemInfoList systemInfolist = aaiServiceProvider.invokeGetVnfmEsrSystemInfoList(vnfm.getVnfmId());
+ if (systemInfolist != null) {
+ for (final EsrSystemInfo esrSystemInfo : systemInfolist.getEsrSystemInfo()) {
+ if (esrSystemInfo.getType().equals(type)) {
+ logger.debug("Matched VNFM ID: " + vnfm + ", based on type");
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiPropertiesImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiPropertiesImpl.java
new file mode 100644
index 0000000000..ea12c5a265
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiPropertiesImpl.java
@@ -0,0 +1,68 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.aai;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import org.onap.so.client.aai.AAIProperties;
+import org.onap.so.client.aai.AAIVersion;
+import org.onap.so.spring.SpringContextHelper;
+import org.springframework.context.ApplicationContext;
+
+public class AaiPropertiesImpl implements AAIProperties {
+
+ private final String endpoint;
+ private final String encryptedBasicAuth;
+ private final String encrytptionKey;
+
+ public AaiPropertiesImpl() {
+
+ final ApplicationContext context = SpringContextHelper.getAppContext();
+ this.endpoint = context.getEnvironment().getProperty("aai.endpoint");
+ this.encryptedBasicAuth = context.getEnvironment().getProperty("aai.auth");
+ this.encrytptionKey = context.getEnvironment().getProperty("mso.key");
+ }
+
+ @Override
+ public URL getEndpoint() throws MalformedURLException {
+ return new URL(endpoint);
+ }
+
+ @Override
+ public String getSystemName() {
+ return "MSO";
+ }
+
+ @Override
+ public AAIVersion getDefaultVersion() {
+ return AAIVersion.LATEST;
+ }
+
+ @Override
+ public String getAuth() {
+ return encryptedBasicAuth;
+ }
+
+ @Override
+ public String getKey() {
+ return encrytptionKey;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java
new file mode 100644
index 0000000000..b8f0706a8e
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.aai;
+
+import org.onap.aai.domain.yang.EsrSystemInfoList;
+import org.onap.aai.domain.yang.EsrVnfm;
+import org.onap.aai.domain.yang.EsrVnfmList;
+import org.onap.aai.domain.yang.GenericVnf;
+
+/**
+ * Provides methods for invoking REST calls to AAI.
+ */
+public interface AaiServiceProvider {
+
+ /**
+ * Invoke a get request for a generic VNF.
+ *
+ * @param vnfId the VNF id
+ * @return the generic VNF
+ */
+ GenericVnf invokeGetGenericVnf(final String vnfId);
+
+ /**
+ * Invoke a GET request for the VNFMs.
+ *
+ * @return the VNFMs
+ */
+ EsrVnfmList invokeGetVnfms();
+
+ /**
+ * Invoke a GET request for the esr system info list for a VNFM.
+ *
+ * @return the esr system info list for the VNFM
+ */
+ EsrSystemInfoList invokeGetVnfmEsrSystemInfoList(final String vnfmId);
+
+
+ /**
+ * Invoke a GET request for the a VNFM.
+ *
+ * @param vnfmId the ID of the VNFM
+ * @return the VNFM
+ */
+ EsrVnfm invokeGetVnfm(final String vnfmId);
+
+ /**
+ * Invoke a PUT request for a generic vnf.
+ *
+ * @param vnf the generic vnf
+ * @return
+ */
+ void invokePutGenericVnf(GenericVnf vnf);
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java
new file mode 100644
index 0000000000..234748e5e1
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java
@@ -0,0 +1,90 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.aai;
+
+import org.onap.aai.domain.yang.EsrSystemInfoList;
+import org.onap.aai.domain.yang.EsrVnfm;
+import org.onap.aai.domain.yang.EsrVnfmList;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class AaiServiceProviderImpl implements AaiServiceProvider {
+
+ private static final Logger logger = LoggerFactory.getLogger(AaiServiceProviderImpl.class);
+ private final AaiClientProvider aaiClientProvider;
+
+ @Autowired
+ public AaiServiceProviderImpl(final AaiClientProvider aaiClientProvider) {
+ this.aaiClientProvider = aaiClientProvider;
+ }
+
+ @Override
+ public GenericVnf invokeGetGenericVnf(final String vnfId) {
+ return aaiClientProvider.getAaiClient()
+ .get(GenericVnf.class, AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId))
+ .orElseGet(() -> {
+ logger.debug("No vnf found in AAI with ID: {}", vnfId);
+ return null;
+ });
+ }
+
+ @Override
+ public EsrVnfmList invokeGetVnfms() {
+ return aaiClientProvider.getAaiClient()
+ .get(EsrVnfmList.class, AAIUriFactory.createResourceUri(AAIObjectType.VNFM_LIST)).orElseGet(() -> {
+ logger.debug("No VNFMs in AAI");
+ return null;
+ });
+ }
+
+ @Override
+ public EsrVnfm invokeGetVnfm(final String vnfmId) {
+ return aaiClientProvider.getAaiClient()
+ .get(EsrVnfm.class, AAIUriFactory.createResourceUri(AAIObjectType.VNFM, vnfmId)).orElseGet(() -> {
+ logger.debug("VNFM not found in AAI");
+ return null;
+ });
+ }
+
+ @Override
+ public EsrSystemInfoList invokeGetVnfmEsrSystemInfoList(final String vnfmId) {
+ return aaiClientProvider.getAaiClient()
+ .get(EsrSystemInfoList.class,
+ AAIUriFactory.createResourceUri(AAIObjectType.VNFM_ESR_SYSTEM_INFO_LIST, vnfmId))
+ .orElseGet(() -> {
+ logger.debug("VNFM ESR system info list not found in AAI");
+ return null;
+ });
+ }
+
+ @Override
+ public void invokePutGenericVnf(final GenericVnf vnf) {
+ aaiClientProvider.getAaiClient()
+ .update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()), vnf);
+ }
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java
new file mode 100644
index 0000000000..0b5b65e7c3
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java
@@ -0,0 +1,39 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
+
+import com.google.common.base.Optional;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+
+/**
+ * Provides methods for invoking REST calls to a VNFM.
+ */
+public interface VnfmServiceProvider {
+
+ /**
+ * Invoke a get request for a VNF.
+ *
+ * @param vnfSelfLink the link to the VNF in the VNFM
+ * @return the VNF from the VNFM
+ */
+ Optional<InlineResponse201> getVnf(final String vnfSelfLink);
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java
new file mode 100644
index 0000000000..28b0b14e4c
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderConfiguration.java
@@ -0,0 +1,51 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
+
+import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
+import org.onap.so.configuration.rest.BasicHttpHeadersProvider;
+import org.onap.so.configuration.rest.HttpHeadersProvider;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.onap.so.rest.service.HttpRestServiceProviderImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
+
+/**
+ * Configures the HttpRestServiceProvider for REST call to a VNFM.
+ */
+@Configuration
+public class VnfmServiceProviderConfiguration {
+
+ @Bean(name = "vnfmServiceProvider")
+ public HttpRestServiceProvider httpRestServiceProvider(
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate) {
+ return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider());
+ }
+
+ private HttpRestServiceProvider getHttpRestServiceProvider(final RestTemplate restTemplate,
+ final HttpHeadersProvider httpHeadersProvider) {
+ return new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider);
+ }
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java
new file mode 100644
index 0000000000..4a141ede4c
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java
@@ -0,0 +1,47 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
+
+import com.google.common.base.Optional;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.stereotype.Service;
+
+@Service
+public class VnfmServiceProviderImpl implements VnfmServiceProvider {
+
+ private final HttpRestServiceProvider httpServiceProvider;
+
+ @Autowired
+ public VnfmServiceProviderImpl(
+ @Qualifier("vnfmServiceProvider") final HttpRestServiceProvider httpServiceProvider) {
+ this.httpServiceProvider = httpServiceProvider;
+ }
+
+ @Override
+ public Optional<InlineResponse201> getVnf(final String vnfSelfLink) {
+ return httpServiceProvider.get(vnfSelfLink, InlineResponse201.class);
+ }
+
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java
new file mode 100644
index 0000000000..4c54ded4ae
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.lifecycle;
+
+import com.google.common.base.Optional;
+import java.util.UUID;
+import org.onap.aai.domain.yang.EsrVnfm;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiClientProvider;
+import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiHelper;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmServiceProvider;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.client.aai.AAIObjectType;
+import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.so.client.graphinventory.entities.uri.Depth;
+import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
+import org.onap.vnfmadapter.v1.model.CreateVnfResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+@Component
+public class LifecycleManager {
+ private static final Logger logger = LoggerFactory.getLogger(LifecycleManager.class);
+ private final AaiClientProvider aaiClientProvider;
+ private final VnfmServiceProvider vnfmServiceProvider;
+ private final AaiHelper aaiHelper;
+
+ @Autowired
+ LifecycleManager(final AaiClientProvider aaiClientProvider, final AaiHelper aaiHelper,
+ final VnfmServiceProvider vnfmServiceProvider) {
+ this.aaiClientProvider = aaiClientProvider;
+ this.vnfmServiceProvider = vnfmServiceProvider;
+ this.aaiHelper = aaiHelper;
+ }
+
+ public CreateVnfResponse createVnf(final String vnfIdInAai, final CreateVnfRequest request) {
+ final GenericVnf genericVnf = getGenericVnfFromAai(vnfIdInAai);
+ checkIfVnfAlreadyExistsInVnfm(genericVnf);
+
+ EsrVnfm vnfm = aaiHelper.getAssignedVnfm(genericVnf);
+ if (vnfm == null) {
+ vnfm = aaiHelper.selectVnfm(genericVnf);
+ aaiHelper.addRelationshipFromGenericVnfToVnfm(genericVnf, vnfm.getVnfmId());
+ }
+
+ final CreateVnfResponse response = new CreateVnfResponse();
+ response.setJobId(UUID.randomUUID().toString());
+ return response;
+ }
+
+ private GenericVnf getGenericVnfFromAai(final String vnfIdInAai) {
+ final GenericVnf genericVnf = aaiClientProvider.getAaiClient()
+ .get(GenericVnf.class,
+ AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfIdInAai).depth(Depth.ONE))
+ .orElseGet(() -> {
+ logger.debug("No Generic Vnf matched by id");
+ return null;
+ });
+ logger.debug("Retrieved generic VNF from AAI: " + genericVnf);
+ return genericVnf;
+ }
+
+ private void checkIfVnfAlreadyExistsInVnfm(final GenericVnf genericVnf) {
+ if (genericVnf.getSelflink() != null && !genericVnf.getSelflink().isEmpty()) {
+ Optional<InlineResponse201> response = Optional.absent();
+ try {
+ response = vnfmServiceProvider.getVnf(genericVnf.getSelflink());
+ } catch (final Exception exception) {
+ logger.debug("Ignoring invalid self link in generic vnf", exception);
+ }
+ if (response.isPresent()) {
+ throw new IllegalArgumentException("VNF " + genericVnf.getVnfId()
+ + " is already defined on the VNFM, self link: " + genericVnf.getSelflink());
+ }
+ }
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java
index b14ead0c4f..65d5478a57 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterController.java
@@ -25,12 +25,14 @@ import java.util.UUID;
import javax.validation.Valid;
import javax.ws.rs.core.MediaType;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
+import org.onap.so.adapters.vnfmadapter.lifecycle.LifecycleManager;
import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
import org.onap.vnfmadapter.v1.model.CreateVnfResponse;
import org.onap.vnfmadapter.v1.model.DeleteVnfResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
@@ -51,6 +53,12 @@ import io.swagger.annotations.ApiParam;
public class VnfmAdapterController {
private static final Logger logger = LoggerFactory.getLogger(VnfmAdapterController.class);
+ private final LifecycleManager lifecycleManager;
+
+ @Autowired
+ VnfmAdapterController(final LifecycleManager lifecycleManager) {
+ this.lifecycleManager = lifecycleManager;
+ }
@PostMapping(value = "/vnfs/{vnfId}")
public ResponseEntity<CreateVnfResponse> vnfCreate(
@@ -75,10 +83,9 @@ public class VnfmAdapterController {
logger.info("REST request vnfCreate with body: {}", createVnfRequest);
- final CreateVnfResponse response = new CreateVnfResponse();
- response.setJobId(UUID.randomUUID().toString());
+ final CreateVnfResponse createVnfResponse = lifecycleManager.createVnf(vnfId, createVnfRequest);
clearLoggingMDCs();
- return new ResponseEntity<>(response, HttpStatus.ACCEPTED);
+ return new ResponseEntity<>(createVnfResponse, HttpStatus.ACCEPTED);
}
@DeleteMapping(value = "/vnfs/{vnfId}")
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmNotFoundException.java
new file mode 100644
index 0000000000..100aa17893
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmNotFoundException.java
@@ -0,0 +1,35 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2019 Nordix Foundation.
+ * ================================================================================
+ * 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.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.so.adapters.vnfmadapter.rest.exceptions;
+
+/**
+ * Exception for VNFM not found.
+ */
+public class VnfmNotFoundException extends RuntimeException {
+
+ private static final long serialVersionUID = 6398018034431666933L;
+
+ public VnfmNotFoundException(final String message) {
+ super(message);
+ }
+
+}
+
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties
new file mode 100644
index 0000000000..86cc3f0a0e
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/META-INF/services/org.onap.so.client.RestProperties
@@ -0,0 +1 @@
+org.onap.so.adapters.vnfmadapter.extclients.aai.AaiPropertiesImpl \ No newline at end of file
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml
index 7719c0c98c..bbe13152fc 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/resources/application.yaml
@@ -15,6 +15,14 @@ server:
port: 9092
tomcat:
max-threads: 50
+
+mso:
+ key: 07a7159d3bf51a0e53be7a8f89699be7
+
+aai:
+ auth: 2A11B07DB6214A839394AA1EC5844695F5114FC407FF5422625FB00175A3DCB8A1FF745F22867EFA72D5369D599BBD88DA8BED4233CF5586
+ version: v15
+ endpoint: https://aai.onap:8443
#Actuator
management:
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java
index ee22e03f87..c25d8257d8 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/HealthCheckTest.java
@@ -42,7 +42,7 @@ public class HealthCheckTest {
@LocalServerPort
private int port;
- private final TestRestTemplate restTemplate = new TestRestTemplate();
+ private final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
@Test
public void testHealthcheck() throws Exception {
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java
index 071a330e8b..e307a253f8 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java
@@ -22,50 +22,303 @@ package org.onap.so.adapters.vnfmadapter.rest;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.verify;
+import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE;
+import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
+import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
+import com.google.gson.Gson;
import java.net.URI;
+import java.util.Optional;
+import org.hamcrest.BaseMatcher;
+import org.hamcrest.Description;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.hamcrest.MockitoHamcrest;
+import org.onap.aai.domain.yang.EsrSystemInfo;
+import org.onap.aai.domain.yang.EsrSystemInfoList;
+import org.onap.aai.domain.yang.EsrVnfm;
+import org.onap.aai.domain.yang.EsrVnfmList;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.Relationship;
+import org.onap.aai.domain.yang.RelationshipData;
+import org.onap.aai.domain.yang.RelationshipList;
import org.onap.so.adapters.vnfmadapter.VnfmAdapterApplication;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException;
+import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
import org.onap.vnfmadapter.v1.model.CreateVnfResponse;
import org.onap.vnfmadapter.v1.model.DeleteVnfResponse;
+import org.onap.vnfmadapter.v1.model.Tenant;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.web.client.MockRestServiceServer;
+import org.springframework.web.client.RestTemplate;
+
@RunWith(SpringRunner.class)
@SpringBootTest(classes = VnfmAdapterApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT)
@ActiveProfiles("test")
+
public class VnfmAdapterControllerTest {
@LocalServerPort
private int port;
+ @Autowired
+ @Qualifier(CONFIGURABLE_REST_TEMPLATE)
+ private RestTemplate testRestTemplate;
+ private MockRestServiceServer mockRestServer;
+
+ @MockBean
+ AAIResourcesClient aaiResourcesClient;
- private final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
+ @Autowired
+ VnfmAdapterController controller;
+ Gson gson = new Gson();
+
+ @Before
+ public void setUp() throws Exception {
+ mockRestServer = MockRestServiceServer.bindTo(testRestTemplate).build();
+ }
@Test
public void createVnf_ValidRequest_Returns202AndJobId() throws Exception {
- final CreateVnfRequest createVnfRequest = new CreateVnfRequest();
- final RequestEntity<CreateVnfRequest> request =
- RequestEntity.post(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId"))
- .accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
- .header("X-ONAP-RequestId", "myRequestId").header("X-ONAP-InvocationID", "myInvocationId")
- .body(createVnfRequest);
- final ResponseEntity<CreateVnfResponse> response = restTemplate.exchange(request, CreateVnfResponse.class);
- assertEquals(202, response.getStatusCode().value());
+ final Tenant tenant =
+ new Tenant().cloudOwner("myTestCloudOwner").regionName("myTestRegion").tenantId("myTestTenantId");
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
+ final GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("myTestVnfId");
+ genericVnf.setNfType("vnfmType2");
+
+ doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class), MockitoHamcrest
+ .argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId?depth=1")));
+
+ final EsrSystemInfo esrSystemInfo1 = new EsrSystemInfo();
+ esrSystemInfo1.setServiceUrl("http://vnfm1:8080");
+ esrSystemInfo1.setType("vnfmType1");
+ esrSystemInfo1.setSystemType("VNFM");
+ final EsrSystemInfoList esrSystemInfoList1 = new EsrSystemInfoList();
+ esrSystemInfoList1.getEsrSystemInfo().add(esrSystemInfo1);
+
+ final EsrVnfm esrVnfm1 = new EsrVnfm();
+ esrVnfm1.setVnfmId("vnfm1");
+ esrVnfm1.setEsrSystemInfoList(esrSystemInfoList1);
+ esrVnfm1.setResourceVersion("1234");
+
+ final EsrSystemInfo esrSystemInfo2 = new EsrSystemInfo();
+ esrSystemInfo2.setServiceUrl("http://vnfm2:8080");
+ esrSystemInfo2.setType("vnfmType2");
+ esrSystemInfo2.setSystemType("VNFM");
+ final EsrSystemInfoList esrSystemInfoList2 = new EsrSystemInfoList();
+ esrSystemInfoList2.getEsrSystemInfo().add(esrSystemInfo2);
+
+ final EsrVnfm esrVnfm2 = new EsrVnfm();
+ esrVnfm2.setVnfmId("vnfm2");
+ esrVnfm2.setEsrSystemInfoList(esrSystemInfoList2);
+ esrVnfm2.setResourceVersion("1234");
+
+ final EsrVnfmList esrVnfmList = new EsrVnfmList();
+ esrVnfmList.getEsrVnfm().add(esrVnfm1);
+ esrVnfmList.getEsrVnfm().add(esrVnfm2);
+
+ doReturn(Optional.of(esrVnfmList)).when(aaiResourcesClient).get(eq(EsrVnfmList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list")));
+
+ doReturn(Optional.of(esrSystemInfoList1)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher(
+ "/external-system/esr-vnfm-list/esr-vnfm/vnfm1/esr-system-info-list")));
+
+ doReturn(Optional.of(esrSystemInfoList2)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher(
+ "/external-system/esr-vnfm-list/esr-vnfm/vnfm2/esr-system-info-list")));
+
+
+ final ResponseEntity<CreateVnfResponse> response =
+ controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
+ assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
+ assertNotNull(response.getBody().getJobId());
+
+ final ArgumentCaptor<GenericVnf> genericVnfArgument = ArgumentCaptor.forClass(GenericVnf.class);
+ final ArgumentCaptor<AAIResourceUri> uriArgument = ArgumentCaptor.forClass(AAIResourceUri.class);
+
+ verify(aaiResourcesClient).update(uriArgument.capture(), genericVnfArgument.capture());
+
+ assertEquals("/network/generic-vnfs/generic-vnf/myTestVnfId", uriArgument.getValue().build().toString());
+
+ assertEquals("myTestVnfId", genericVnfArgument.getValue().getVnfId());
+ assertEquals(1, genericVnfArgument.getValue().getRelationshipList().getRelationship().size());
+ final Relationship createdRelationship =
+ genericVnfArgument.getValue().getRelationshipList().getRelationship().get(0);
+ assertEquals("esr-vnfm", createdRelationship.getRelatedTo());
+ assertEquals("tosca.relationships.DependsOn", createdRelationship.getRelationshipLabel());
+ assertEquals("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/vnfm2", createdRelationship.getRelatedLink());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void createVnf_VnfAlreadyExistsOnVnfm_ThrowsIllegalArgumentException() throws Exception {
+ final Tenant tenant =
+ new Tenant().cloudOwner("myTestCloudOwner").regionName("myTestRegion").tenantId("myTestTenantId");
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
+ final GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("myTestVnfId");
+ genericVnf.setNfType("vnfmType");
+ genericVnf.setSelflink("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm");
+
+ doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class), MockitoHamcrest
+ .argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId?depth=1")));
+
+ final EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
+ esrSystemInfo.setServiceUrl("http://vnfm:8080");
+ esrSystemInfo.setType("vnfmType");
+ esrSystemInfo.setSystemType("VNFM");
+ final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
+ esrSystemInfoList.getEsrSystemInfo().add(esrSystemInfo);
+
+ final EsrVnfm esrVnfm = new EsrVnfm();
+ esrVnfm.setVnfmId("vnfm");
+ esrVnfm.setEsrSystemInfoList(esrSystemInfoList);
+ esrVnfm.setResourceVersion("1234");
+
+ final EsrVnfmList esrVnfmList = new EsrVnfmList();
+ esrVnfmList.getEsrVnfm().add(esrVnfm);
+
+ final InlineResponse201 reponse = new InlineResponse201();
+ mockRestServer.expect(requestTo(new URI("http://vnfm:8080/vnfs/myTestVnfIdOnVnfm")))
+ .andRespond(withSuccess(gson.toJson(reponse), MediaType.APPLICATION_JSON));
+
+ doReturn(Optional.of(esrVnfmList)).when(aaiResourcesClient).get(eq(EsrVnfmList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list")));
+
+ controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
+ }
+
+ @Test(expected = VnfmNotFoundException.class)
+ public void createVnf_NoMatchingVnfmFound_ThrowsException() throws Exception {
+ final Tenant tenant =
+ new Tenant().cloudOwner("myTestCloudOwner").regionName("myTestRegion").tenantId("myTestTenantId");
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
+ final GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("myTestVnfId");
+ genericVnf.setNfType("anotherType");
+
+ doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class), MockitoHamcrest
+ .argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId?depth=1")));
+
+ final EsrSystemInfo esrSystemInfo1 = new EsrSystemInfo();
+ esrSystemInfo1.setServiceUrl("http://vnfm1:8080");
+ esrSystemInfo1.setType("vnfmType1");
+ esrSystemInfo1.setSystemType("VNFM");
+ final EsrSystemInfoList esrSystemInfoList1 = new EsrSystemInfoList();
+ esrSystemInfoList1.getEsrSystemInfo().add(esrSystemInfo1);
+
+ final EsrVnfm esrVnfm1 = new EsrVnfm();
+ esrVnfm1.setVnfmId("vnfm1");
+ esrVnfm1.setEsrSystemInfoList(esrSystemInfoList1);
+ esrVnfm1.setResourceVersion("1234");
+
+ final EsrSystemInfo esrSystemInfo2 = new EsrSystemInfo();
+ esrSystemInfo2.setServiceUrl("http://vnfm2:8080");
+ esrSystemInfo2.setType("vnfmType2");
+ esrSystemInfo2.setSystemType("VNFM");
+ final EsrSystemInfoList esrSystemInfoList2 = new EsrSystemInfoList();
+ esrSystemInfoList2.getEsrSystemInfo().add(esrSystemInfo2);
+
+ final EsrVnfm esrVnfm2 = new EsrVnfm();
+ esrVnfm2.setVnfmId("vnfm2");
+ esrVnfm2.setEsrSystemInfoList(esrSystemInfoList2);
+ esrVnfm2.setResourceVersion("1234");
+
+ final EsrVnfmList esrVnfmList = new EsrVnfmList();
+ esrVnfmList.getEsrVnfm().add(esrVnfm1);
+ esrVnfmList.getEsrVnfm().add(esrVnfm2);
+
+ doReturn(Optional.of(esrVnfmList)).when(aaiResourcesClient).get(eq(EsrVnfmList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list")));
+
+
+ doReturn(Optional.of(esrSystemInfoList1)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher(
+ "/external-system/esr-vnfm-list/esr-vnfm/vnfm1/esr-system-info-list")));
+
+ doReturn(Optional.of(esrSystemInfoList2)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher(
+ "/external-system/esr-vnfm-list/esr-vnfm/vnfm2/esr-system-info-list")));
+
+ controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
+ }
+
+ @Test
+ public void createVnf_VnfmAlreadyAssociatedWithVnf_Returns202AndJobId() throws Exception {
+ final Tenant tenant =
+ new Tenant().cloudOwner("myTestCloudOwner").regionName("myTestRegion").tenantId("myTestTenantId");
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
+ final GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("myTestVnfId");
+ genericVnf.setNfType("vnfmType2");
+
+ final Relationship relationshipToVnfm = new Relationship();
+ relationshipToVnfm.setRelatedLink("/aai/v15/external-system/esr-vnfm-list/esr-vnfm/vnfm1");
+ relationshipToVnfm.setRelatedTo("esr-vnfm");
+ final RelationshipData relationshipData = new RelationshipData();
+ relationshipData.setRelationshipKey("esr-vnfm.vnfm-id");
+ relationshipData.setRelationshipValue("vnfm1");
+ relationshipToVnfm.getRelationshipData().add(relationshipData);
+
+ final RelationshipList relationshipList = new RelationshipList();
+ relationshipList.getRelationship().add(relationshipToVnfm);
+ genericVnf.setRelationshipList(relationshipList);
+
+ doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class), MockitoHamcrest
+ .argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId?depth=1")));
+
+ final EsrSystemInfo esrSystemInfo1 = new EsrSystemInfo();
+ esrSystemInfo1.setServiceUrl("http://vnfm1:8080");
+ esrSystemInfo1.setType("vnfmType1");
+ esrSystemInfo1.setSystemType("VNFM");
+ final EsrSystemInfoList esrSystemInfoList1 = new EsrSystemInfoList();
+ esrSystemInfoList1.getEsrSystemInfo().add(esrSystemInfo1);
+
+ final EsrVnfm esrVnfm1 = new EsrVnfm();
+ esrVnfm1.setVnfmId("vnfm1");
+ esrVnfm1.setEsrSystemInfoList(esrSystemInfoList1);
+ esrVnfm1.setResourceVersion("1234");
+
+ doReturn(Optional.of(esrVnfm1)).when(aaiResourcesClient).get(eq(EsrVnfm.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher("/external-system/esr-vnfm-list/esr-vnfm/vnfm1")));
+
+ final ResponseEntity<CreateVnfResponse> response =
+ controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
+ assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
assertNotNull(response.getBody().getJobId());
}
@Test
public void createVnf_UnauthorizedUser_Returns401() throws Exception {
final TestRestTemplate restTemplateWrongPassword = new TestRestTemplate("test", "wrongPassword");
- final CreateVnfRequest createVnfRequest = new CreateVnfRequest();
+ final Tenant tenant =
+ new Tenant().cloudOwner("myTestCloudOwner").regionName("myTestRegion").tenantId("myTestTenantId");
+ final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
+
final RequestEntity<CreateVnfRequest> request =
RequestEntity.post(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId"))
.accept(MediaType.APPLICATION_JSON).contentType(MediaType.APPLICATION_JSON)
@@ -78,6 +331,7 @@ public class VnfmAdapterControllerTest {
@Test
public void deleteVnf_ValidRequest_Returns202AndJobId() throws Exception {
+ final TestRestTemplate restTemplate = new TestRestTemplate("test", "test");
final RequestEntity<Void> request = RequestEntity
.delete(new URI("http://localhost:" + port + "/so/vnfm-adapter/v1/vnfs/myVnfId"))
.accept(MediaType.APPLICATION_JSON).header("X-ONAP-RequestId", "myRequestId")
@@ -87,4 +341,26 @@ public class VnfmAdapterControllerTest {
assertNotNull(response.getBody().getJobId());
}
+ private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> {
+
+ final String uriAsString;
+
+ public AaiResourceUriMatcher(final String uriAsString) {
+ this.uriAsString = uriAsString;
+ }
+
+ @Override
+ public boolean matches(final Object item) {
+ if (item instanceof AAIResourceUri) {
+ return ((AAIResourceUri) item).build().toString().equals(uriAsString);
+ }
+ return false;
+ }
+
+ @Override
+ public void describeTo(final Description description) {}
+
+ }
+
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application-test.yaml b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application-test.yaml
index cc5a068d69..2b51181f46 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application-test.yaml
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/resources/application-test.yaml
@@ -16,4 +16,12 @@ spring:
usercredentials:
- username: test
password: '$2a$12$Zi3AuYcZoZO/gBQyUtST2.F5N6HqcTtaNci2Et.ufsQhski56srIu'
- role: BPEL-Client \ No newline at end of file
+ role: BPEL-Client
+
+mso:
+ key: 07a7159d3bf51a0e53be7a8f89699be7
+
+aai:
+ auth: 2A11B07DB6214A839394AA1EC5844695F5114FC407FF5422625FB00175A3DCB8A1FF745F22867EFA72D5369D599BBD88DA8BED4233CF5586
+ endpoint: https://aai.onap:8443
+ version: v15 \ No newline at end of file