summaryrefslogtreecommitdiffstats
path: root/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main')
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiHelper.java11
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProvider.java2
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/aai/AaiServiceProviderImpl.java2
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHelper.java30
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java130
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/TenantNotFoundException.java35
6 files changed, 200 insertions, 10 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 ee04819ca4..b9ffd8bac5 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
@@ -31,13 +31,14 @@ 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.aai.domain.yang.Vserver;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.LcnVnfLcmOperationOccurrenceNotificationAffectedVnfcs;
+import org.onap.so.adapters.vnfmadapter.rest.exceptions.TenantNotFoundException;
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.onap.vnfmadapter.v1.model.Tenant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -124,8 +125,11 @@ public class AaiHelper {
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);
+ if (cloudOwner == null || cloudRegion == null || tenantId == null) {
+ throw new TenantNotFoundException("No matching Tenant found in AAI. VNFID: " + vnf.getVnfId());
+ } else {
+ return new Tenant().cloudOwner(cloudOwner).regionName(cloudRegion).tenantId(tenantId);
+ }
}
private Relationship getRelationship(final GenericVnf vnf, final String relationshipRelatedToValue) {
@@ -233,5 +237,4 @@ public class AaiHelper {
public OamIpAddressSource getOamIpAddressSource(final String vnfId) {
return mapOfVnfIdToOamIpAddressHolder.get(vnfId);
}
-
}
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 b3767a3b62..2708742e6a 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
@@ -25,8 +25,8 @@ 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.aai.domain.yang.Vserver;
+import org.onap.vnfmadapter.v1.model.Tenant;
/**
* Provides methods for invoking REST calls to AAI.
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 6c3d7c2ca6..55a2cc39ec 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
@@ -25,10 +25,10 @@ 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.aai.domain.yang.Vserver;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
+import org.onap.vnfmadapter.v1.model.Tenant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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
index c0d3cf8567..b370dc35c8 100644
--- 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
@@ -22,10 +22,6 @@ package org.onap.so.adapters.vnfmadapter.extclients.vnfm;
import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL;
import static org.onap.so.adapters.vnfmadapter.Constants.OPERATION_NOTIFICATION_ENDPOINT;
-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;
@@ -34,6 +30,7 @@ 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.grant.model.InlineResponse201VimConnections;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.InstantiateVnfRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthentication;
@@ -53,6 +50,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
+import com.google.common.reflect.TypeToken;
+import com.google.gson.Gson;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
/**
* Provides helper methods for interactions with VNFM.
@@ -199,4 +200,25 @@ public class VnfmHelper {
return authentication;
}
+ /**
+ * Get the VIM connections for a tenant
+ *
+ * @param tenant the tenant
+ * @return the VIM connections
+ */
+ public InlineResponse201VimConnections getVimConnections(final Tenant tenant) {
+ final EsrSystemInfo esrSystemInfo =
+ aaiServiceProvider.invokeGetCloudRegionEsrSystemInfoList(tenant.getCloudOwner(), tenant.getRegionName())
+ .getEsrSystemInfo().iterator().next();
+
+ final InlineResponse201VimConnections vimConnection = new InlineResponse201VimConnections();
+ vimConnection.setId(createVimId(tenant.getCloudOwner(), tenant.getRegionName()));
+ vimConnection.setVimId(vimConnection.getId());
+ vimConnection.setVimType(esrSystemInfo.getType());
+ vimConnection.setInterfaceInfo(getInterfaceInfo(esrSystemInfo.getServiceUrl()));
+ vimConnection.setAccessInfo(getAccessInfo(esrSystemInfo, tenant.getTenantId()));
+ return vimConnection;
+ }
+
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java
new file mode 100644
index 0000000000..82e72a7630
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003GrantController.java
@@ -0,0 +1,130 @@
+/*-
+ * ============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;
+
+import static org.onap.so.adapters.vnfmadapter.Constants.BASE_URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+import javax.ws.rs.core.MediaType;
+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.grant.model.GrantRequest;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.GrantsAddResources;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201AddResources;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.grant.model.InlineResponse201VimConnections;
+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.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+@Controller
+@RequestMapping(value = BASE_URL, produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
+public class Sol003GrantController {
+
+ private static final String SEPARATOR = "_";
+ private static final String VIM_TYPE = "OPENSTACK";
+ private static final String CLOUD_OWNER = "myTestCloudOwner";
+ private static final String REGION = "myTestRegion";
+ private static final String TENANT_ID = "myTestTenantId";
+ private static final Logger logger = LoggerFactory.getLogger(Sol003GrantController.class);
+ public final AaiServiceProvider aaiServiceProvider;
+ public final AaiHelper aaiHelper;
+ public final VnfmHelper vnfmHelper;
+
+ @Autowired
+ public Sol003GrantController(final AaiServiceProvider aaiServiceProvider, final AaiHelper aaiHelper,
+ final VnfmHelper vnfmHelper) {
+ this.aaiServiceProvider = aaiServiceProvider;
+ this.aaiHelper = aaiHelper;
+ this.vnfmHelper = vnfmHelper;
+ }
+
+ @GetMapping(value = "/grants/{grantId}")
+ public ResponseEntity<InlineResponse201> grantsGrantIdGet(@PathVariable("grantId") final String grantId) {
+ logger.info("Get grant received from VNFM, grant id: " + grantId);
+ return new ResponseEntity<InlineResponse201>(HttpStatus.NOT_IMPLEMENTED);
+ }
+
+ @PostMapping(value = "/grants")
+ public ResponseEntity<InlineResponse201> grantsPost(@RequestBody final GrantRequest grantRequest) {
+ logger.info("Grant request received from VNFM: " + grantRequest);
+
+ final InlineResponse201 grantResponse = createGrantResponse(grantRequest);
+ logger.info("Grant request returning to VNFM: " + grantResponse);
+ return new ResponseEntity<InlineResponse201>(grantResponse, HttpStatus.CREATED);
+ }
+
+ private InlineResponse201 createGrantResponse(final GrantRequest grantRequest) {
+ final InlineResponse201 grantResponse = new InlineResponse201();
+ grantResponse.setId(UUID.randomUUID().toString());
+ grantResponse.setVnfInstanceId(grantRequest.getVnfInstanceId());
+ grantResponse.setVnfLcmOpOccId(grantRequest.getVnfLcmOpOccId());
+ final Tenant tenant =
+ aaiHelper.getAssignedTenant(aaiServiceProvider.invokeGetGenericVnf((grantRequest.getVnfInstanceId())));
+
+ String vimConnectionId = "";
+ final InlineResponse201VimConnections vimConnection = vnfmHelper.getVimConnections(tenant);
+ grantResponse.addVimConnectionsItem(vimConnection);
+ vimConnectionId = vimConnection.getId();
+
+ if (grantRequest.getOperation().equals(GrantRequest.OperationEnum.INSTANTIATE)) {
+ grantResponse.addResources(getResources(grantRequest.getAddResources(), vimConnectionId));
+ } else if (grantRequest.getOperation().equals(GrantRequest.OperationEnum.TERMINATE)) {
+ grantResponse.addResources(getResources(grantRequest.getRemoveResources(), vimConnectionId));
+ }
+ return grantResponse;
+ }
+
+ private InlineResponse201VimConnections getVimConnectionsItem(final Tenant tenant) {
+ final InlineResponse201VimConnections vimConnection = new InlineResponse201VimConnections();
+ vimConnection.setId(createVimConnectionId(tenant.getCloudOwner(), tenant.getRegionName()));
+ vimConnection.setVimId(vimConnection.getId());
+ vimConnection.setVimType(VIM_TYPE);
+ return vimConnection;
+ }
+
+ private List<InlineResponse201AddResources> getResources(final List<GrantsAddResources> requestResources,
+ final String vimId) {
+ final List<InlineResponse201AddResources> resources = new ArrayList<>();
+ for (final GrantsAddResources requestResource : requestResources) {
+ final InlineResponse201AddResources responseResource = new InlineResponse201AddResources();
+ responseResource.setResourceDefinitionId(requestResource.getId());
+ responseResource.setVimConnectionId(vimId);
+ resources.add(responseResource);
+ }
+ return resources;
+ }
+
+ private String createVimConnectionId(String cloudOwner, String cloudRegionId) {
+ return cloudOwner + SEPARATOR + cloudRegionId;
+ }
+}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/TenantNotFoundException.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/TenantNotFoundException.java
new file mode 100644
index 0000000000..215e68adcf
--- /dev/null
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/exceptions/TenantNotFoundException.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 Tenant not found.
+ */
+
+public class TenantNotFoundException extends RuntimeException {
+
+ private static final long serialVersionUID = 6398018034431666933L;
+
+ public TenantNotFoundException(final String message) {
+ super(message);
+ }
+
+}