aboutsummaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
authorSmokowski, Steven <steve.smokowski@att.com>2020-03-19 17:57:25 -0400
committerBenjamin, Max (mb388a) <mb388a@att.com>2020-03-19 17:57:25 -0400
commit0c6057ea8f21c63af4791107c2440a6ed992f5f0 (patch)
tree7475d19646f176f30b4f80fcfacd6c68ab18b136 /adapters
parentc1fcea306877deed8ec05e3608b2a7534b345900 (diff)
mso to add support for creating the cloud region
mso to add support for creating the cloud region Updated tag name to msoRequest on deletes. Issue-ID: SO-2753 Signed-off-by: Benjamin, Max (mb388a) <mb388a@att.com> Change-Id: I80e318ce34f5938a42896398eb1a38b5c5f6e831
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java4
-rw-r--r--adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.5__AddCloudOwner.sql13
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRegionRestV1.java6
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRestImpl.java70
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java9
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java34
6 files changed, 110 insertions, 26 deletions
diff --git a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
index f5464645d6..97ba7828c0 100644
--- a/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
+++ b/adapters/mso-adapter-utils/src/main/java/org/onap/so/openstack/utils/MsoHeatUtils.java
@@ -33,6 +33,7 @@ import java.util.Map.Entry;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import org.onap.logging.filter.base.ErrorCode;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.adapters.vdu.CloudInfo;
import org.onap.so.adapters.vdu.PluginAction;
@@ -45,14 +46,11 @@ import org.onap.so.adapters.vdu.VduPlugin;
import org.onap.so.adapters.vdu.VduStateType;
import org.onap.so.adapters.vdu.VduStatus;
import org.onap.so.cloud.authentication.KeystoneAuthHolder;
-import org.onap.so.db.catalog.beans.CloudIdentity;
-import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.db.catalog.beans.HeatTemplate;
import org.onap.so.db.catalog.beans.HeatTemplateParam;
import org.onap.so.db.request.beans.CloudApiRequests;
import org.onap.so.db.request.beans.InfraActiveRequests;
import org.onap.so.db.request.client.RequestsDbClient;
-import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.logger.MessageEnum;
import org.onap.so.openstack.beans.CreateStackRequest;
import org.onap.so.openstack.beans.HeatStatus;
diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.5__AddCloudOwner.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.5__AddCloudOwner.sql
new file mode 100644
index 0000000000..92502e2696
--- /dev/null
+++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V8.5__AddCloudOwner.sql
@@ -0,0 +1,13 @@
+use catalogdb;
+
+
+ALTER TABLE cloud_sites
+ ADD COLUMN IF NOT EXISTS CLOUD_OWNER varchar(255);
+
+
+CREATE TABLE IF NOT EXISTS `network_technology_reference` (
+ `ID` INT(11) NOT NULL AUTO_INCREMENT,
+ `NETWORK_TECHNOLOGY` varchar(200) NOT NULL ,
+ `CLOUD_OWNER` varchar(200) NOT NULL,
+ PRIMARY KEY (`ID`)
+) ENGINE=InnoDB DEFAULT CHARSET=latin1; \ No newline at end of file
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRegionRestV1.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRegionRestV1.java
index 780480507b..6cf42e1433 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRegionRestV1.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRegionRestV1.java
@@ -56,7 +56,6 @@ public class CloudRegionRestV1 {
private CloudRestImpl cloudRestImpl;
@POST
- @Path("{cloud-region-id}/{cloud-owner}")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@ApiOperation(value = "CreateCloudRegion", response = Response.class,
@@ -65,9 +64,8 @@ public class CloudRegionRestV1 {
@ApiResponse(code = 500, message = "Create Cloud Region has failed")})
public Response createCloudRegion(
@ApiParam(value = "cloud-region-id", required = true) @PathParam("cloud-region-id") String cloudRegionId,
- @ApiParam(value = "cloud-owner", required = true) @PathParam("cloud-owner") String cloudOwner,
@ApiParam(value = "CloudSite", required = true) final CloudSite cloudSite) {
- cloudRestImpl.createCloudRegion(cloudSite, cloudOwner);
+ cloudRestImpl.createCloudRegion(cloudSite);
return Response.status(HttpStatus.SC_CREATED).build();
}
@@ -96,7 +94,7 @@ public class CloudRegionRestV1 {
@ApiParam(value = "cloud-region-id", required = true) @PathParam("cloud-region-id") String cloudRegionId,
@ApiParam(value = "cloud-owner", required = true) @PathParam("cloud-owner") String cloudOwner,
@ApiParam(value = "CloudSite", required = true) final CloudSite cloudSite) {
- cloudRestImpl.updateCloudRegion(cloudSite, cloudOwner);
+ cloudRestImpl.updateCloudRegion(cloudSite);
return Response.status(HttpStatus.SC_OK).build();
}
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRestImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRestImpl.java
index 4cde8655ae..380f42fa69 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRestImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRestImpl.java
@@ -1,13 +1,21 @@
package org.onap.so.adapters.cloudregion;
+import java.util.List;
import java.util.Optional;
import org.onap.aai.domain.yang.CloudRegion;
+import org.onap.aai.domain.yang.Complex;
+import org.onap.aai.domain.yang.NetworkTechnologies;
+import org.onap.so.client.aai.AAIObjectPlurals;
import org.onap.so.client.aai.AAIObjectType;
import org.onap.so.client.aai.AAIResourcesClient;
+import org.onap.so.client.aai.entities.uri.AAIPluralResourceUri;
import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.db.catalog.beans.CloudSite;
+import org.onap.so.db.catalog.beans.NetworkTechnologyReference;
import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.db.catalog.data.repository.NetworkTechnologyReferenceRepository;
+import org.onap.so.db.catalog.utils.MavenLikeVersioning;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,14 +29,17 @@ public class CloudRestImpl {
private AAIResourcesClient aaiClient;
@Autowired
+ private NetworkTechnologyReferenceRepository ctrRepo;
+
+ @Autowired
private CatalogDbClient catalogDBClient;
- public void createCloudRegion(CloudSite cloudSite, String cloudOwner) throws CloudException {
+ public void createCloudRegion(CloudSite cloudSite) throws CloudException {
createRegionInCatalogDb(cloudSite);
- createCloudRegionInAAI(cloudSite, cloudOwner);
+ createCloudRegionInAAI(cloudSite);
}
- public void updateCloudRegion(CloudSite cloudSite, String cloudOwner) throws CloudException {
+ public void updateCloudRegion(CloudSite cloudSite) throws CloudException {
updateRegionInCatalogDb(cloudSite);
}
@@ -50,18 +61,49 @@ public class CloudRestImpl {
}
}
- protected void createCloudRegionInAAI(CloudSite cloudSite, String cloudOwner) {
+ protected void createCloudRegionInAAI(CloudSite cloudSite) {
try {
- CloudRegion cloudRegion = mapCloudRegion(cloudSite, cloudOwner);
- AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION,
+ CloudRegion cloudRegion = mapCloudRegion(cloudSite);
+ Optional<Complex> complex = retrieveComplex(cloudSite);
+ if (complex.isPresent()) {
+ cloudRegion.setComplexName(complex.get().getComplexName());
+ }
+ AAIResourceUri cloudRegionURI = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION,
cloudRegion.getCloudOwner(), cloudRegion.getCloudRegionId());
- getAaiClient().createIfNotExists(uri, Optional.of(cloudRegion));
+ getAaiClient().createIfNotExists(cloudRegionURI, Optional.of(cloudRegion));
+ if (complex.isPresent()) {
+ AAIResourceUri complexURI = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, cloudSite.getClli());
+ getAaiClient().connect(cloudRegionURI, complexURI);
+ }
+ createCloudRegionNetworkTechnologyRelationship(cloudSite, cloudRegionURI);
} catch (Exception e) {
logger.error("Error creating cloud region in AAI", e);
throw new CloudException("Error creating cloud region in AAI: " + e.getMessage(), e);
}
}
+ protected void createCloudRegionNetworkTechnologyRelationship(CloudSite cloudSite, AAIResourceUri cloudRegionURI) {
+ List<NetworkTechnologyReference> listOfNetworkTech = ctrRepo.findAllByCloudOwner(cloudSite.getCloudOwner());
+ listOfNetworkTech.stream().forEach(tech -> linkCloudAndTechnology(tech.getNetworkTechnology(), cloudRegionURI));
+ }
+
+ protected Optional<Complex> retrieveComplex(CloudSite cloudSite) {
+ AAIResourceUri complexURI = AAIUriFactory.createResourceUri(AAIObjectType.COMPLEX, cloudSite.getClli());
+ return getAaiClient().get(Complex.class, complexURI);
+ }
+
+ protected void linkCloudAndTechnology(String networkTechnologyName, AAIResourceUri cloudRegionURI) {
+ AAIPluralResourceUri technologyPluralUri = AAIUriFactory.createResourceUri(AAIObjectPlurals.NETWORK_TECHNOLOGY)
+ .queryParam("network-technology-name", networkTechnologyName);
+ Optional<NetworkTechnologies> networkTechnology =
+ getAaiClient().get(NetworkTechnologies.class, technologyPluralUri);
+ if (networkTechnology.isPresent()) {
+ AAIResourceUri networkTechnologyURI = AAIUriFactory.createResourceUri(AAIObjectType.NETWORK_TECHNOLOGY,
+ networkTechnology.get().getNetworkTechnology().get(0).getNetworkTechnologyId());
+ getAaiClient().connect(cloudRegionURI, networkTechnologyURI);
+ }
+ }
+
protected void createRegionInCatalogDb(CloudSite cloudSite) throws CloudException {
try {
CloudSite existingCloudSite = catalogDBClient.getCloudSite(cloudSite.getRegionId());
@@ -74,16 +116,22 @@ public class CloudRestImpl {
}
}
- protected CloudRegion mapCloudRegion(CloudSite cloudSite, String cloudOwner) {
+ protected CloudRegion mapCloudRegion(CloudSite cloudSite) {
CloudRegion region = new CloudRegion();
- region.setCloudOwner(cloudOwner);
+ region.setCloudOwner(cloudSite.getCloudOwner());
region.setCloudRegionId(cloudSite.getRegionId());
region.setCloudRegionVersion(cloudSite.getCloudVersion());
region.setOwnerDefinedType("cLCP");
+ region.setCloudType("openstack");
+ MavenLikeVersioning cloudVersion = new MavenLikeVersioning();
+ cloudVersion.setVersion(cloudSite.getCloudVersion());
+ if (cloudVersion.isMoreRecentThan("3.0")) {
+ region.setCloudZone(cloudSite.getRegionId().substring(0, cloudSite.getRegionId().length() - 1));
+ } else {
+ region.setCloudZone(cloudSite.getRegionId());
+ }
region.setOrchestrationDisabled(false);
- region.setComplexName("NA");
region.setInMaint(false);
- region.setCloudType("openstack");
return region;
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java
index 32e88d8cad..60c5a0ca2a 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/vnf/MsoVnfAdapterImpl.java
@@ -33,6 +33,7 @@ import java.util.Optional;
import javax.jws.WebService;
import javax.xml.ws.Holder;
import org.apache.commons.collections.CollectionUtils;
+import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.adapters.vnf.exceptions.VnfException;
import org.onap.so.adapters.vnf.exceptions.VnfNotFound;
import org.onap.so.client.aai.AAIResourcesClient;
@@ -53,7 +54,6 @@ import org.onap.so.entity.MsoRequest;
import org.onap.so.heatbridge.HeatBridgeApi;
import org.onap.so.heatbridge.HeatBridgeException;
import org.onap.so.heatbridge.HeatBridgeImpl;
-import org.onap.logging.filter.base.ErrorCode;
import org.onap.so.logger.LoggingAnchor;
import org.onap.so.logger.MessageEnum;
import org.onap.so.openstack.beans.HeatStatus;
@@ -1052,9 +1052,10 @@ public class MsoVnfAdapterImpl implements MsoVnfAdapter {
heatStack = msoHeatUtils.createStack(cloudSiteId, cloudOwner, tenantId, vfModuleName, null,
template, goldenInputs, true, heatTemplate.getTimeoutMinutes(), newEnvironmentString,
nestedTemplatesChecked, heatFilesObjects, backout.booleanValue(), failIfExists);
-
- msoHeatUtils.updateResourceStatus(msoRequest.getRequestId(),
- heatStack.isOperationPerformed() ? VF_EXIST_STATUS_MESSAGE : VF_CREATED_STATUS_MESSAGE);
+ if (msoRequest.getRequestId() != null) {
+ msoHeatUtils.updateResourceStatus(msoRequest.getRequestId(),
+ heatStack.isOperationPerformed() ? VF_EXIST_STATUS_MESSAGE : VF_CREATED_STATUS_MESSAGE);
+ }
} else {
throw new MsoHeatNotFoundException();
}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java
index 9c62c286ac..2df56ede10 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java
@@ -23,6 +23,7 @@ import org.onap.so.client.aai.entities.uri.AAIResourceUri;
import org.onap.so.client.aai.entities.uri.AAIUriFactory;
import org.onap.so.db.catalog.beans.CloudSite;
import org.onap.so.db.catalog.client.CatalogDbClient;
+import org.onap.so.db.catalog.data.repository.NetworkTechnologyReferenceRepository;
@RunWith(MockitoJUnitRunner.class)
@@ -38,6 +39,9 @@ public class CloudRegionRestImplTest {
@Mock
private AAIResourcesClient aaiResClientMock;
+ @Mock
+ private NetworkTechnologyReferenceRepository ntRepoMock;
+
private CloudSite cloudSite = new CloudSite();
private CloudRegion testCloudRegion = new CloudRegion();
@@ -46,30 +50,52 @@ public class CloudRegionRestImplTest {
public void setup() {
cloudSite.setCloudVersion("1.0");
cloudSite.setRegionId("region1");
+ cloudSite.setCloudOwner("bob");
Mockito.doReturn(aaiResClientMock).when(cloudRestImpl).getAaiClient();
testCloudRegion.setCloudOwner("bob");
testCloudRegion.setCloudRegionId("region1");
testCloudRegion.setCloudRegionVersion("1.0");
testCloudRegion.setInMaint(false);
testCloudRegion.setOrchestrationDisabled(false);
- testCloudRegion.setComplexName("NA");
testCloudRegion.setCloudRegionVersion("1.0");
testCloudRegion.setOwnerDefinedType("cLCP");
testCloudRegion.setCloudType("openstack");
+ testCloudRegion.setCloudZone("region1");
}
@Test
public void mapCloudRegionTest() {
- CloudRegion mappedRegion = cloudRestImpl.mapCloudRegion(cloudSite, "bob");
+ CloudRegion mappedRegion = cloudRestImpl.mapCloudRegion(cloudSite);
assertThat(mappedRegion, sameBeanAs(testCloudRegion));
}
+
+ @Test
+ public void mapCloudRegionVersionGreaterThan3Test() {
+ CloudSite cloudSite2 = new CloudSite();
+ cloudSite2.setCloudVersion("3.0.1");
+ cloudSite2.setRegionId("region1");
+ cloudSite2.setCloudOwner("bob");
+
+ CloudRegion mappedRegion = cloudRestImpl.mapCloudRegion(cloudSite2);
+ CloudRegion testRegion2 = new CloudRegion();
+ testRegion2.setCloudOwner("bob");
+ testRegion2.setCloudRegionId("region1");
+ testRegion2.setCloudRegionVersion("3.0.1");
+ testRegion2.setInMaint(false);
+ testRegion2.setOrchestrationDisabled(false);
+ testRegion2.setOwnerDefinedType("cLCP");
+ testRegion2.setCloudType("openstack");
+ testRegion2.setCloudZone("region");
+ assertThat(mappedRegion, sameBeanAs(testRegion2));
+ }
+
@Test
public void createCloudRegionTest() {
when(catalogDbClientMock.getCloudSite("region1")).thenReturn(null);
when(catalogDbClientMock.postCloudSite(cloudSite)).thenReturn(cloudSite);
AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, "bob", "region1");
- cloudRestImpl.createCloudRegion(cloudSite, "bob");
+ cloudRestImpl.createCloudRegion(cloudSite);
ArgumentCaptor<AAIResourceUri> actualURI = ArgumentCaptor.forClass(AAIResourceUri.class);
ArgumentCaptor<Optional<Object>> actualCloudRegion = ArgumentCaptor.forClass(Optional.class);
verify(catalogDbClientMock, times(1)).getCloudSite("region1");
@@ -82,7 +108,7 @@ public class CloudRegionRestImplTest {
@Test
public void updateCloudRegionTest() {
when(catalogDbClientMock.updateCloudSite(cloudSite)).thenReturn(cloudSite);
- cloudRestImpl.updateCloudRegion(cloudSite, "bob");
+ cloudRestImpl.updateCloudRegion(cloudSite);
verify(catalogDbClientMock, times(1)).updateCloudSite(cloudSite);
}