aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2019-04-03 11:25:53 +0000
committerMichaelMorris <michael.morris@est.tech>2019-04-03 11:25:53 +0000
commit3312a682e0aabe2d81fcd4c5ea6090ec255f8ccf (patch)
treea880e68b0c8b2b1cc8171b36e5ba326821207cd0
parent0ea204d5d1db87a34be2581d8ea4790d0dfacb8b (diff)
Send instantiate VNF Request to VNFM
Issue-ID: SO-1624 Change-Id: Ida69ecaed5323e42ecebe189ef79c323133855f3 Signed-off-by: MichaelMorris <michael.morris@est.tech>
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java37
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java21
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java23
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/AccessInfo.java109
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/InterfaceInfo.java76
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/VimCredentials.java86
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java152
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProvider.java10
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmServiceProviderImpl.java20
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java6
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/lifecycle/LifecycleManager.java49
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmRequestFailureException.java35
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/VnfmAdapterControllerTest.java276
-rw-r--r--common/src/main/java/org/onap/so/client/aai/AAIObjectType.java1
14 files changed, 719 insertions, 182 deletions
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
index 043d2d309d..893df02019 100644
--- 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
@@ -29,6 +29,7 @@ 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.aai.domain.yang.Tenant;
import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmNotFoundException;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIVersion;
@@ -92,20 +93,42 @@ public class AaiHelper {
* @return the VNFM to use, or <code>null</code> if no VNFM has been assigned yet
*/
public EsrVnfm getAssignedVnfm(final GenericVnf vnf) {
+ final Relationship relationship = getRelationship(vnf, "esr-vnfm");
+ final String vnfmId = getRelationshipKey(relationship, "esr-vnfm.vnfm-id");
+ return vnfmId == null ? null : aaiServiceProvider.invokeGetVnfm(vnfmId);
+ }
+
+ /**
+ * Get the tenant assigned for use for the given generic VNF.
+ *
+ * @param vnf the generic VNF
+ * @return the tenant to use, or <code>null</code> if no tenant has been assigned yet
+ */
+ public Tenant getAssignedTenant(final GenericVnf vnf) {
+ final Relationship relationship = getRelationship(vnf, "tenant");
+ final String cloudOwner = getRelationshipKey(relationship, "cloud-region.cloud-owner");
+ final String cloudRegion = getRelationshipKey(relationship, "cloud-region.cloud-region-id");
+ final String tenantId = getRelationshipKey(relationship, "tenant.tenant-id");
+ return cloudOwner == null || cloudRegion == null || tenantId == null ? null
+ : aaiServiceProvider.invokeGetTenant(cloudOwner, cloudRegion, tenantId);
+ }
+
+ private Relationship getRelationship(final GenericVnf vnf, final String relationshipRelatedToValue) {
for (final Relationship relationship : vnf.getRelationshipList() == null ? Collections.<Relationship>emptyList()
: vnf.getRelationshipList().getRelationship()) {
- if ("esr-vnfm".equals(relationship.getRelatedTo())) {
- return getRelatedVnfmId(relationship);
+ if (relationship.getRelatedTo().equals(relationshipRelatedToValue)) {
+ return 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());
+ private String getRelationshipKey(final Relationship relationship, final String relationshipKey) {
+ if (relationship != null) {
+ for (final RelationshipData relationshipData : relationship.getRelationshipData()) {
+ if (relationshipData.getRelationshipKey().equals(relationshipKey)) {
+ return relationshipData.getRelationshipValue();
+ }
}
}
return null;
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
index b8f0706a8e..d11da0c91b 100644
--- 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
@@ -24,6 +24,7 @@ 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.Tenant;
/**
* Provides methods for invoking REST calls to AAI.
@@ -52,7 +53,6 @@ public interface AaiServiceProvider {
*/
EsrSystemInfoList invokeGetVnfmEsrSystemInfoList(final String vnfmId);
-
/**
* Invoke a GET request for the a VNFM.
*
@@ -69,4 +69,23 @@ public interface AaiServiceProvider {
*/
void invokePutGenericVnf(GenericVnf vnf);
+ /**
+ * Invoke a GET request for the a tenant.
+ *
+ * @param cloudOwner the cloud owner
+ * @param cloudRegion the cloud region
+ * @param tenantId the ID of the tenant
+ * @return the tenant
+ */
+ Tenant invokeGetTenant(final String cloudOwner, final String cloudRegion, final String tenantId);
+
+ /**
+ * Invoke a GET request for the esr system info list for a cloud region.
+ *
+ * @param cloudOwner the cloud owner
+ * @param cloudRegion the cloud region
+ * @return the esr system info list for the VNFM
+ */
+ EsrSystemInfoList invokeGetCloudRegionEsrSystemInfoList(final String cloudOwner, final String cloudRegion);
+
}
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
index 234748e5e1..fa0dcf07f1 100644
--- 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
@@ -24,6 +24,7 @@ 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.Tenant;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.slf4j.Logger;
@@ -87,4 +88,26 @@ public class AaiServiceProviderImpl implements AaiServiceProvider {
.update(AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnf.getVnfId()), vnf);
}
+ @Override
+ public Tenant invokeGetTenant(final String cloudOwner, final String cloudRegion, final String tenantId) {
+ return aaiClientProvider.getAaiClient()
+ .get(Tenant.class,
+ AAIUriFactory.createResourceUri(AAIObjectType.TENANT, cloudOwner, cloudRegion, tenantId))
+ .orElseGet(() -> {
+ logger.debug("Tenant not found in AAI");
+ return null;
+ });
+ }
+
+ @Override
+ public EsrSystemInfoList invokeGetCloudRegionEsrSystemInfoList(final String cloudOwner, final String cloudRegion) {
+ return aaiClientProvider
+ .getAaiClient().get(EsrSystemInfoList.class, AAIUriFactory
+ .createResourceUri(AAIObjectType.CLOUD_ESR_SYSTEM_INFO_LIST, cloudOwner, cloudRegion))
+ .orElseGet(() -> {
+ logger.debug("Cloud esr system info list not found in AAI");
+ return null;
+ });
+ }
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/AccessInfo.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/AccessInfo.java
new file mode 100644
index 0000000000..6f2827c7ff
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/AccessInfo.java
@@ -0,0 +1,109 @@
+/*-
+ * ============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.vim.model;
+
+import java.util.Objects;
+
+public class AccessInfo {
+
+ protected String projectId;
+ protected String projectName;
+ protected String domainName;
+ protected VimCredentials credentials;
+
+ public String getProjectId() {
+ return projectId;
+ }
+
+ public void setProjectId(final String value) {
+ projectId = value;
+ }
+
+ public String getProjectName() {
+ return projectName;
+ }
+
+ public void setProjectName(final String value) {
+ projectName = value;
+ }
+
+ public String getDomainName() {
+ return domainName;
+ }
+
+ public void setDomainName(final String value) {
+ domainName = value;
+ }
+
+ public VimCredentials getCredentials() {
+ return credentials;
+ }
+
+ public void setCredentials(final VimCredentials value) {
+ credentials = value;
+ }
+
+ @Override
+ public boolean equals(final java.lang.Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final AccessInfo accessInfo = (AccessInfo) o;
+ return Objects.equals(this.projectId, accessInfo.projectId)
+ && Objects.equals(this.projectName, accessInfo.projectName)
+ && Objects.equals(this.domainName, accessInfo.domainName)
+ && Objects.equals(this.credentials, accessInfo.credentials);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(projectId, projectName, domainName, credentials);
+ }
+
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("class AccessInfo {\n");
+
+ sb.append(" projectId: ").append(toIndentedString(projectId)).append("\n");
+ sb.append(" projectName: ").append(toIndentedString(projectName)).append("\n");
+ sb.append(" domainName: ").append(toIndentedString(domainName)).append("\n");
+ sb.append(" credentials: ").append(toIndentedString(credentials)).append("\n");
+ sb.append("}");
+ return sb.toString();
+ }
+
+ /**
+ * Convert the given object to string with each line indented by 4 spaces (except the first line).
+ */
+ private String toIndentedString(final java.lang.Object o) {
+ if (o == null) {
+ return "null";
+ }
+ return o.toString().replace("\n", "\n ");
+ }
+
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/InterfaceInfo.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/InterfaceInfo.java
new file mode 100644
index 0000000000..c974f2bbaa
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/InterfaceInfo.java
@@ -0,0 +1,76 @@
+/*-
+ * ============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.vim.model;
+
+import java.util.Objects;
+
+public class InterfaceInfo {
+
+ protected String identityEndPoint;
+
+ public String getIdentityEndPoint() {
+ return identityEndPoint;
+ }
+
+ public void setIdentityEndPoint(final String value) {
+ identityEndPoint = value;
+ }
+
+ @Override
+ public boolean equals(final java.lang.Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final InterfaceInfo interfaceInfo = (InterfaceInfo) o;
+ return Objects.equals(this.identityEndPoint, interfaceInfo.identityEndPoint);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(identityEndPoint);
+ }
+
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("class InterfaceInfo {\n");
+
+ sb.append(" identityEndPoint: ").append(toIndentedString(identityEndPoint)).append("\n");
+ sb.append("}");
+ return sb.toString();
+ }
+
+ /**
+ * Convert the given object to string with each line indented by 4 spaces (except the first line).
+ */
+ private String toIndentedString(final java.lang.Object o) {
+ if (o == null) {
+ return "null";
+ }
+ return o.toString().replace("\n", "\n ");
+ }
+
+
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/VimCredentials.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/VimCredentials.java
new file mode 100644
index 0000000000..35971bafe8
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vim/model/VimCredentials.java
@@ -0,0 +1,86 @@
+/*-
+ * ============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.vim.model;
+
+import java.util.Objects;
+
+public class VimCredentials {
+
+ protected String username;
+
+ protected String password;
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setUsername(final String value) {
+ username = value;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(final String password) {
+ this.password = password;
+ }
+
+ @Override
+ public boolean equals(final java.lang.Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final VimCredentials vimCredentials = (VimCredentials) o;
+ return Objects.equals(this.username, vimCredentials.username)
+ && Objects.equals(this.password, vimCredentials.password);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(username, password);
+ }
+
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder();
+ sb.append("class AccessInfo {\n");
+
+ sb.append(" username: ").append(toIndentedString(username)).append("\n");
+ sb.append(" password: ").append(toIndentedString(password)).append("\n");
+ sb.append("}");
+ return sb.toString();
+ }
+
+ /**
+ * Convert the given object to string with each line indented by 4 spaces (except the first line).
+ */
+ private String toIndentedString(final java.lang.Object o) {
+ if (o == null) {
+ return "null";
+ }
+ return o.toString().replace("\n", "\n ");
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java
new file mode 100644
index 0000000000..3b2b87f661
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.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.vnfm;
+
+import com.google.common.reflect.TypeToken;
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import org.onap.aai.domain.yang.EsrSystemInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.aai.AaiServiceProvider;
+import org.onap.so.adapters.vnfmadapter.extclients.vim.model.AccessInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vim.model.InterfaceInfo;
+import org.onap.so.adapters.vnfmadapter.extclients.vim.model.VimCredentials;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.VnfInstancesvnfInstanceIdinstantiateExtVirtualLinks;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.VnfInstancesvnfInstanceIdinstantiateVimConnectionInfo;
+import org.onap.vnfmadapter.v1.model.CreateVnfRequest;
+import org.onap.vnfmadapter.v1.model.ExternalVirtualLink;
+import org.onap.vnfmadapter.v1.model.Tenant;
+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 VNFM.
+ */
+@Service
+public class VnfmHelper {
+
+ private static final Logger logger = LoggerFactory.getLogger(VnfmHelper.class);
+ private static final String SEPARATOR = "_";
+ private final AaiServiceProvider aaiServiceProvider;
+
+ @Autowired
+ public VnfmHelper(final AaiServiceProvider aaiServiceProvider) {
+ this.aaiServiceProvider = aaiServiceProvider;
+ }
+
+ /**
+ * Create an {@link InstantiateVnfRequest} to send in an instantiation request to a VNFM.
+ *
+ * @param tenant the tenant the request is to be fulfilled on
+ * @param createVnfRequest the request received by the VNFM adapter
+ */
+ public InstantiateVnfRequest createInstantiateRequest(final Tenant tenant,
+ final CreateVnfRequest createVnfRequest) {
+ final InstantiateVnfRequest instantiateVnfRequest = new InstantiateVnfRequest();
+ instantiateVnfRequest.setFlavourId(getFlavourId());
+ instantiateVnfRequest.setVimConnectionInfo(getVimConnectionInfos(tenant));
+ instantiateVnfRequest
+ .setAdditionalParams(getAdditionalParametersAsJsonObject(createVnfRequest.getAdditionalParams()));
+ instantiateVnfRequest.setExtVirtualLinks(getExternalVirtualLinks(createVnfRequest.getExternalVirtualLinks()));
+ createVnfRequest.getExternalVirtualLinks();
+ return instantiateVnfRequest;
+ }
+
+ private String getFlavourId() {
+ // TODO read from csar
+ return "default";
+ }
+
+ private List<VnfInstancesvnfInstanceIdinstantiateVimConnectionInfo> getVimConnectionInfos(final Tenant tenant) {
+ final List<VnfInstancesvnfInstanceIdinstantiateVimConnectionInfo> connectionInfos = new ArrayList<>();
+ connectionInfos.add(getVimConnectionInfo(tenant));
+ return connectionInfos;
+ }
+
+ private VnfInstancesvnfInstanceIdinstantiateVimConnectionInfo getVimConnectionInfo(final Tenant tenant) {
+ final EsrSystemInfo esrSystemInfo =
+ aaiServiceProvider.invokeGetCloudRegionEsrSystemInfoList(tenant.getCloudOwner(), tenant.getRegionName())
+ .getEsrSystemInfo().iterator().next();
+
+ final VnfInstancesvnfInstanceIdinstantiateVimConnectionInfo vnfInstancesVimConnectionInfo =
+ new VnfInstancesvnfInstanceIdinstantiateVimConnectionInfo();
+ final String vimId = createVimId(tenant.getCloudOwner(), tenant.getRegionName());
+ vnfInstancesVimConnectionInfo.setId(vimId);
+ vnfInstancesVimConnectionInfo.setVimId(vimId);
+ vnfInstancesVimConnectionInfo.setVimType(esrSystemInfo.getType());
+ vnfInstancesVimConnectionInfo.setInterfaceInfo(getInterfaceInfo(esrSystemInfo.getServiceUrl()));
+ vnfInstancesVimConnectionInfo.setAccessInfo(getAccessInfo(esrSystemInfo, tenant.getTenantId()));
+ return vnfInstancesVimConnectionInfo;
+ }
+
+ private InterfaceInfo getInterfaceInfo(final String url) {
+ final InterfaceInfo interfaceInfo = new InterfaceInfo();
+ interfaceInfo.setIdentityEndPoint(url);
+ return interfaceInfo;
+ }
+
+ private AccessInfo getAccessInfo(final EsrSystemInfo esrSystemInfo, final String tenantId) {
+ final AccessInfo accessInfo = new AccessInfo();
+ accessInfo.setProjectId(tenantId);
+ accessInfo.setDomainName(esrSystemInfo.getCloudDomain());
+
+ final VimCredentials vimCredentials = new VimCredentials();
+ vimCredentials.setUsername(esrSystemInfo.getUserName());
+ vimCredentials.setPassword(esrSystemInfo.getPassword());
+ accessInfo.setCredentials(vimCredentials);
+ return accessInfo;
+ }
+
+ private String createVimId(final String cloudOwner, final String cloudRegion) {
+ return cloudOwner + SEPARATOR + cloudRegion;
+ }
+
+ private JsonObject getAdditionalParametersAsJsonObject(final Map<String, String> additionalParameters) {
+ final JsonObject additionalParametersJsonObject = new JsonObject();
+ if (additionalParameters != null) {
+ for (final Map.Entry<String, JsonElement> item : new Gson().toJsonTree(additionalParameters)
+ .getAsJsonObject().entrySet()) {
+ additionalParametersJsonObject.add(item.getKey(), item.getValue());
+ }
+ } else {
+ logger.warn("No additional parameters were specified for the operation");
+ }
+ return additionalParametersJsonObject;
+ }
+
+ private List<VnfInstancesvnfInstanceIdinstantiateExtVirtualLinks> getExternalVirtualLinks(
+ final List<ExternalVirtualLink> extVirtualLinks) {
+ if (extVirtualLinks != null) {
+ final String extVirtualLinksJsonObject =
+ new Gson().toJson(extVirtualLinks, new TypeToken<List<ExternalVirtualLink>>() {}.getType());
+ return new Gson().fromJson(extVirtualLinksJsonObject,
+ new TypeToken<List<VnfInstancesvnfInstanceIdinstantiateExtVirtualLinks>>() {}.getType());
+ }
+ return null;
+ }
+
+}
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
index f0646f3cf2..aaf7e460ed 100644
--- 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
@@ -23,6 +23,7 @@ package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
import com.google.common.base.Optional;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest;
/**
* Provides methods for invoking REST calls to a VNFM.
@@ -38,6 +39,15 @@ public interface VnfmServiceProvider {
Optional<InlineResponse201> getVnf(final String vnfSelfLink);
/**
+ * Invoke an instantiate request for a VNF.
+ *
+ * @param vnfSelfLink the link to he VNF on the VNFM
+ * @param instantiateVnfRequest the instantiate request
+ * @return the operation ID of the instantiation operation
+ */
+ String instantiateVnf(final String vnfSelfLink, final InstantiateVnfRequest instantiateVnfRequest);
+
+ /**
* Invoke a get request for a VNFM operation.
*
* @param vnfmId the id of the VNFM in AAI
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
index 43d4f1e0dd..4a2c7a9696 100644
--- 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
@@ -23,13 +23,20 @@ package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
import com.google.common.base.Optional;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfmRequestFailureException;
import org.onap.so.rest.service.HttpRestServiceProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
@Service
public class VnfmServiceProviderImpl implements VnfmServiceProvider {
+ private static final Logger logger = LoggerFactory.getLogger(VnfmServiceProviderImpl.class);
private final HttpRestServiceProvider httpServiceProvider;
private final VnfmUrlProvider urlProvider;
@@ -47,8 +54,21 @@ public class VnfmServiceProviderImpl implements VnfmServiceProvider {
}
@Override
+ public String instantiateVnf(final String vnfSelfLink, final InstantiateVnfRequest instantiateVnfRequest) {
+ logger.debug("Sending instantiate request " + instantiateVnfRequest + " to : " + vnfSelfLink);
+ final ResponseEntity<Void> response = httpServiceProvider.getHttpResponse(vnfSelfLink, Void.class);
+ if (response.getStatusCode() != HttpStatus.ACCEPTED) {
+ throw new VnfmRequestFailureException("Instantiate request to " + vnfSelfLink + " return status code: "
+ + response.getStatusCode() + ", request: " + instantiateVnfRequest);
+ }
+ final String locationHeader = response.getHeaders().get("Location").iterator().next();
+ return locationHeader.substring(locationHeader.lastIndexOf("/") + 1);
+ }
+
+ @Override
public Optional<InlineResponse200> getOperation(final String vnfmId, final String operationId) {
final String url = urlProvider.getOperationUrl(vnfmId, operationId);
return httpServiceProvider.get(url, InlineResponse200.class);
}
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java
index f5a99b1d95..f0280d6a71 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmUrlProvider.java
@@ -46,10 +46,10 @@ public class VnfmUrlProvider {
}
/**
- * Get the URL for a generic VNF in AAI.
+ * Get the URL for an operation on a VNFM.
*
- * @param vnfId The identifier of the VNF
- * @return the URL of the VNF
+ * @param vnfmId The ID of the VNFM
+ * @return the URL of the operation
*/
public String getOperationUrl(final String vnfmId, final String operationId) {
final String url = UriComponentsBuilder.fromUri(getBaseUri(vnfmId)).pathSegment("/vnf_lcm_op_occs/")
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
index 5c944ca38b..4bedb47e3d 100644
--- 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
@@ -24,14 +24,13 @@ 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.aai.AaiServiceProvider;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmHelper;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmServiceProvider;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest;
import org.onap.so.adapters.vnfmadapter.jobmanagement.JobManager;
-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.onap.vnfmadapter.v1.model.DeleteVnfResponse;
@@ -46,17 +45,19 @@ import org.springframework.stereotype.Component;
@Component
public class LifecycleManager {
private static final Logger logger = LoggerFactory.getLogger(LifecycleManager.class);
- private final AaiClientProvider aaiClientProvider;
+ private final AaiServiceProvider aaiServiceProvider;
private final VnfmServiceProvider vnfmServiceProvider;
private final AaiHelper aaiHelper;
+ private final VnfmHelper vnfmHelper;
private final JobManager jobManager;
@Autowired
- LifecycleManager(final AaiClientProvider aaiClientProvider, final AaiHelper aaiHelper,
- final VnfmServiceProvider vnfmServiceProvider, final JobManager jobManager) {
- this.aaiClientProvider = aaiClientProvider;
+ LifecycleManager(final AaiServiceProvider aaiServiceProvider, final AaiHelper aaiHelper,
+ final VnfmHelper vnfmHelper, final VnfmServiceProvider vnfmServiceProvider, final JobManager jobManager) {
+ this.aaiServiceProvider = aaiServiceProvider;
this.vnfmServiceProvider = vnfmServiceProvider;
this.aaiHelper = aaiHelper;
+ this.vnfmHelper = vnfmHelper;
this.jobManager = jobManager;
}
@@ -77,22 +78,17 @@ public class LifecycleManager {
aaiHelper.addRelationshipFromGenericVnfToVnfm(genericVnf, vnfm.getVnfmId());
}
- // operation ID set to random value for now, will be set correctly once we implement instantiate
- // call towards the VNFM
- final String jobId = jobManager.createJob(vnfm.getVnfmId(), UUID.randomUUID().toString(), false);
+ final String vnfIdInVnfm = sendCreateRequestToVnfm(genericVnf);
+ final String operationId = sendInstantiateRequestToVnfm(vnfm, genericVnf, request, vnfIdInAai, vnfIdInVnfm);
+
+ final String jobId = jobManager.createJob(vnfm.getVnfmId(), operationId, false);
final CreateVnfResponse response = new CreateVnfResponse();
response.setJobId(jobId);
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;
- });
+ final GenericVnf genericVnf = aaiServiceProvider.invokeGetGenericVnf(vnfIdInAai);
logger.debug("Retrieved generic VNF from AAI: " + genericVnf);
return genericVnf;
}
@@ -112,6 +108,23 @@ public class LifecycleManager {
}
}
+ private String sendCreateRequestToVnfm(final GenericVnf genericVnf) {
+ // TODO call create request
+ genericVnf.setSelflink("http://dummy.value/until/create/implememted/vnfId");
+ return "vnfId";
+ }
+
+ private String sendInstantiateRequestToVnfm(final EsrVnfm vnfm, final GenericVnf genericVnf,
+ final CreateVnfRequest createVnfRequest, final String vnfIdInAai, final String vnfIdInVnfm) {
+
+ final InstantiateVnfRequest instantiateVnfRequest =
+ vnfmHelper.createInstantiateRequest(createVnfRequest.getTenant(), createVnfRequest);
+ final String jobId = vnfmServiceProvider.instantiateVnf(genericVnf.getSelflink(), instantiateVnfRequest);
+
+ logger.info("Instantiate VNF request successfully sent to " + genericVnf.getSelflink());
+ return jobId;
+ }
+
/**
* Delete a VNF on a VNFM.
*
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmRequestFailureException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmRequestFailureException.java
new file mode 100644
index 0000000000..57a812da0a
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/VnfmRequestFailureException.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 indicating a request to a VNFM failed.
+ */
+public class VnfmRequestFailureException extends RuntimeException {
+
+ private static final long serialVersionUID = 6398018034431666933L;
+
+ public VnfmRequestFailureException(final String message) {
+ super(message);
+ }
+
+}
+
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 29bab9dc6a..ae2e280b47 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
@@ -27,6 +27,7 @@ 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.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
import com.google.gson.Gson;
import java.net.URI;
@@ -90,6 +91,9 @@ public class VnfmAdapterControllerTest {
OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 12, 0), ZoneOffset.UTC);
private static final OffsetDateTime JAN_1_2019_1_00 =
OffsetDateTime.of(LocalDateTime.of(2019, 1, 1, 1, 0), ZoneOffset.UTC);
+ private static final String CLOUD_OWNER = "myTestCloudOwner";
+ private static final String REGION = "myTestRegion";
+ private static final String TENANT_ID = "myTestTenantId";
@LocalServerPort
private int port;
@@ -112,65 +116,28 @@ public class VnfmAdapterControllerTest {
@Test
public void createVnf_ValidRequest_Returns202AndJobId() throws Exception {
- final Tenant tenant =
- new Tenant().cloudOwner("myTestCloudOwner").regionName("myTestRegion").tenantId("myTestTenantId");
+ final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
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);
+ setUpGenericVnfInMockAai("vnfmType2");
+ setUpVnfmsInMockAai();
+ setUpVimInMockAai();
- final EsrVnfm esrVnfm1 = new EsrVnfm();
- esrVnfm1.setVnfmId("vnfm1");
- esrVnfm1.setEsrSystemInfoList(esrSystemInfoList1);
- esrVnfm1.setResourceVersion("1234");
+ mockRestServer.expect(requestTo("http://dummy.value/until/create/implememted/vnfId"))
+ .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON)
+ .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/123456")));
- 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 InlineResponse200 firstOperationQueryResponse = createOperationQueryResponse(
org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.INSTANTIATE,
org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.PROCESSING);
- mockRestServer.expect(requestTo(new StringStartsWith("http://vnfm2:8080/vnf_lcm_op_occs")))
+ mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_lcm_op_occs/123456"))
.andRespond(withSuccess(gson.toJson(firstOperationQueryResponse), MediaType.APPLICATION_JSON));
final InlineResponse200 secondOperationQueryReponse = createOperationQueryResponse(
org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationEnum.INSTANTIATE,
org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InlineResponse200.OperationStateEnum.COMPLETED);
- mockRestServer.expect(requestTo(new StringStartsWith("http://vnfm2:8080/vnf_lcm_op_occs")))
+ mockRestServer.expect(requestTo("http://vnfm2:8080/vnf_lcm_op_occs/123456"))
.andRespond(withSuccess(gson.toJson(secondOperationQueryReponse), MediaType.APPLICATION_JSON));
// Invoke the create request
@@ -214,138 +181,47 @@ public class VnfmAdapterControllerTest {
@Test(expected = IllegalArgumentException.class)
public void createVnf_VnfAlreadyExistsOnVnfm_ThrowsIllegalArgumentException() throws Exception {
- final Tenant tenant =
- new Tenant().cloudOwner("myTestCloudOwner").regionName("myTestRegion").tenantId("myTestTenantId");
+ final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
final GenericVnf genericVnf = new GenericVnf();
genericVnf.setVnfId("myTestVnfId");
- genericVnf.setNfType("vnfmType");
+ genericVnf.setNfType("vnfmType1");
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);
+ doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId")));
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 Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
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")));
+ setUpGenericVnfInMockAai("anotherType");
+ setUpVnfmsInMockAai();
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 Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
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")));
+ setUpGenericVnfWithVnfmRelationshipInMockAai("vnfmType2", "vnfm1");
+ setUpVnfmsInMockAai();
+ setUpVimInMockAai();
- 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")));
+ mockRestServer.expect(requestTo("http://dummy.value/until/create/implememted/vnfId"))
+ .andRespond(withStatus(HttpStatus.ACCEPTED).contentType(MediaType.APPLICATION_JSON)
+ .location(new URI("http://vnfm2:8080/vnf_lcm_op_occs/123456")));
final ResponseEntity<CreateVnfResponse> response =
controller.vnfCreate("myTestVnfId", createVnfRequest, "asadas", "so", "1213");
@@ -356,8 +232,7 @@ public class VnfmAdapterControllerTest {
@Test
public void createVnf_UnauthorizedUser_Returns401() throws Exception {
final TestRestTemplate restTemplateWrongPassword = new TestRestTemplate("test", "wrongPassword");
- final Tenant tenant =
- new Tenant().cloudOwner("myTestCloudOwner").regionName("myTestRegion").tenantId("myTestTenantId");
+ final Tenant tenant = new Tenant().cloudOwner(CLOUD_OWNER).regionName(REGION).tenantId(TENANT_ID);
final CreateVnfRequest createVnfRequest = new CreateVnfRequest().name("myTestName").tenant(tenant);
final RequestEntity<CreateVnfRequest> request =
@@ -435,6 +310,101 @@ public class VnfmAdapterControllerTest {
return response;
}
+ private GenericVnf createGenericVnf(final String type) {
+ final GenericVnf genericVnf = new GenericVnf();
+ genericVnf.setVnfId("myTestVnfId");
+ genericVnf.setNfType(type);
+ return genericVnf;
+ }
+
+ private void setUpGenericVnfInMockAai(final String type) {
+ final GenericVnf genericVnf = createGenericVnf(type);
+
+ doReturn(Optional.of(genericVnf)).when(aaiResourcesClient).get(eq(GenericVnf.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher("/network/generic-vnfs/generic-vnf/myTestVnfId")));
+ }
+
+ private void setUpGenericVnfWithVnfmRelationshipInMockAai(final String type, final String vnfmId) {
+ final GenericVnf genericVnf = createGenericVnf(type);
+
+ final Relationship relationshipToVnfm = new Relationship();
+ relationshipToVnfm.setRelatedLink(
+ "/aai/v15/external-system/esr-vnfm-li// final InlineResponse201 vnfInstance = new InlineResponse201();\n"
+ + "// vnfInstance.setInstantiationState(InstantiationStateEnum.NOT_INSTANTIATED);\n"
+ + "// mockRestServer.expect(requestTo(\"http://dummy.value/until/create/implememted/vnfId\"))\n"
+ + "// .andRespond(withSuccess(gson.toJson(vnfInstance), MediaType.APPLICATION_JSON));st/esr-vnfm/"
+ + vnfmId);
+ relationshipToVnfm.setRelatedTo("esr-vnfm");
+ final RelationshipData relationshipData = new RelationshipData();
+ relationshipData.setRelationshipKey("esr-vnfm.vnfm-id");
+ relationshipData.setRelationshipValue(vnfmId);
+ 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")));
+ }
+
+ private void setUpVnfmsInMockAai() {
+ 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")));
+ }
+
+ private void setUpVimInMockAai() {
+ final EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
+ esrSystemInfo.setServiceUrl("http://myVim:8080");
+ esrSystemInfo.setType("openstack");
+ esrSystemInfo.setSystemType("VIM");
+ esrSystemInfo.setCloudDomain("myDomain");
+ esrSystemInfo.setUserName("myUser");
+ esrSystemInfo.setPassword("myPassword");
+
+ final EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
+ esrSystemInfoList.getEsrSystemInfo().add(esrSystemInfo);
+
+ doReturn(Optional.of(esrSystemInfoList)).when(aaiResourcesClient).get(eq(EsrSystemInfoList.class),
+ MockitoHamcrest.argThat(new AaiResourceUriMatcher("/cloud-infrastructure/cloud-regions/cloud-region/"
+ + CLOUD_OWNER + "/" + REGION + "/esr-system-info-list")));
+ }
+
private class AaiResourceUriMatcher extends BaseMatcher<AAIResourceUri> {
final String uriAsString;
diff --git a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
index f6aa2fdb19..44b00e4f6b 100644
--- a/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
+++ b/common/src/main/java/org/onap/so/client/aai/AAIObjectType.java
@@ -145,6 +145,7 @@ public class AAIObjectType implements GraphInventoryObjectType, Serializable {
public static final AAIObjectType VNFM = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM + "/esr-vnfm-list/esr-vnfm/{vnfm-id}", EsrVnfm.class);
public static final AAIObjectType VNFM_LIST = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM, "/esr-vnfm-list", "vnfm-list");
public static final AAIObjectType VNFM_ESR_SYSTEM_INFO_LIST = new AAIObjectType(AAINamespaceConstants.EXTERNAL_SYSTEM + "/esr-vnfm-list", "/esr-vnfm/{vnfm-id}/esr-system-info-list", "vnfm-esr-system-info-list");
+ public static final AAIObjectType CLOUD_ESR_SYSTEM_INFO_LIST = new AAIObjectType(AAIObjectType.CLOUD_REGION.uriTemplate(), "/esr-system-info-list", "cloud-esr-system-info-list");
private final String uriTemplate;