diff options
Diffstat (limited to 'adapters/mso-openstack-adapters')
4 files changed, 96 insertions, 23 deletions
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); } |