diff options
46 files changed, 1208 insertions, 86 deletions
diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000000..3797dc8bb9 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,20 @@ +--- +# .readthedocs.yml +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details +# Required +version: 2 + +formats: + - htmlzip + +build: + image: latest + +python: + version: 3.7 + install: + - requirements: docs/requirements-docs.txt + +sphinx: + configuration: docs/conf.py diff --git a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java index 707a2a45af..739b4b62de 100644 --- a/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java +++ b/adapters/mso-catalog-db-adapter/src/test/java/org/onap/so/db/catalog/client/CatalogDbClientTest.java @@ -22,8 +22,8 @@ package org.onap.so.db.catalog.client; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -428,7 +428,7 @@ public class CatalogDbClientTest extends CatalogDbAdapterBaseTest { } @Test - public void testPostCloudSite() { + public void testCloudSiteClient() { CatalogDbClientPortChanger localClient = new CatalogDbClientPortChanger( "http://localhost:" + client.wiremockPort, msoAdaptersAuth, client.wiremockPort); CloudSite cloudSite = new CloudSite(); @@ -455,6 +455,19 @@ public class CatalogDbClientTest extends CatalogDbAdapterBaseTest { assertEquals("TESTCLLI", getCloudSite.getClli()); assertEquals("regionId", getCloudSite.getRegionId()); assertEquals("RANDOMID", getCloudSite.getIdentityServiceId()); + + getCloudSite.setClli("clli2"); + getCloudSite.setRegionId("region2"); + + CloudSite updatedCloudSite = this.client.updateCloudSite(getCloudSite); + assertNotNull(updatedCloudSite); + assertNotNull(updatedCloudSite.getIdentityService()); + assertEquals("clli2", updatedCloudSite.getClli()); + assertEquals("region2", updatedCloudSite.getRegionId()); + + this.client.deleteCloudSite(getCloudSite.getId()); + getCloudSite = this.client.getCloudSite("MTN6"); + assertNull(getCloudSite); } @Test diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudException.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudException.java new file mode 100644 index 0000000000..9cdf7e3b2a --- /dev/null +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudException.java @@ -0,0 +1,14 @@ +package org.onap.so.adapters.cloudregion; + +public class CloudException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = -2631715095942372451L; + + public CloudException(String error, Exception e) { + super(error, e); + } + +} 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 new file mode 100644 index 0000000000..780480507b --- /dev/null +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRegionRestV1.java @@ -0,0 +1,102 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright (C) 2018 IBM. + * Modifications Copyright (c) 2019 Samsung + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.cloudregion; + + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import org.apache.http.HttpStatus; +import org.onap.so.db.catalog.beans.CloudSite; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; + + +@Path("/v1/cloud-region") +@Api(value = "/v1/cloud-region", description = "root of cloud region adapter") +@Component +public class CloudRegionRestV1 { + private static Logger logger = LoggerFactory.getLogger(CloudRegionRestV1.class); + + @Autowired + private CloudRestImpl cloudRestImpl; + + @POST + @Path("{cloud-region-id}/{cloud-owner}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "CreateCloudRegion", response = Response.class, + notes = "Create a cloud site in MSO and Region In AAI") + @ApiResponses({@ApiResponse(code = 201, message = "Cloud Region has been created"), + @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); + return Response.status(HttpStatus.SC_CREATED).build(); + } + + @DELETE + @Path("{cloud-region-id}/{cloud-owner}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "CreateCloudRegion", response = Response.class, notes = "Delete an cloud Region in SO") + @ApiResponses({@ApiResponse(code = 204, message = "cloud Region has been deleted"), + @ApiResponse(code = 500, message = "Cloud Region delete has failed")}) + public Response deleteCloudRegion( + @ApiParam(value = "cloud-region-id", required = true) @PathParam("cloud-region-id") String cloudRegionId, + @ApiParam(value = "cloud-owner", required = true) @PathParam("cloud-owner") String cloudOwner) { + cloudRestImpl.deleteCloudRegion(cloudRegionId); + return Response.status(HttpStatus.SC_NO_CONTENT).build(); + } + + @PUT + @Path("{cloud-region-id}/{cloud-owner}") + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + @ApiOperation(value = "CreateCloudRegion", response = Response.class, notes = "Update an existing Cloud Region") + @ApiResponses({@ApiResponse(code = 200, message = "Cloud Region has been updated"), + @ApiResponse(code = 500, message = "Update Cloud Region has failed examine entity object for details")}) + public Response updateCloudRegion( + @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); + 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 new file mode 100644 index 0000000000..4cde8655ae --- /dev/null +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/cloudregion/CloudRestImpl.java @@ -0,0 +1,97 @@ +package org.onap.so.adapters.cloudregion; + +import java.util.Optional; +import org.onap.aai.domain.yang.CloudRegion; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + + +@Component +public class CloudRestImpl { + private static final Logger logger = LoggerFactory.getLogger(CloudRestImpl.class); + + private AAIResourcesClient aaiClient; + + @Autowired + private CatalogDbClient catalogDBClient; + + public void createCloudRegion(CloudSite cloudSite, String cloudOwner) throws CloudException { + createRegionInCatalogDb(cloudSite); + createCloudRegionInAAI(cloudSite, cloudOwner); + } + + public void updateCloudRegion(CloudSite cloudSite, String cloudOwner) throws CloudException { + updateRegionInCatalogDb(cloudSite); + } + + protected void updateRegionInCatalogDb(CloudSite cloudSite) { + try { + catalogDBClient.updateCloudSite(cloudSite); + } catch (Exception e) { + logger.error("Error updating cloud region in catalogdb", e); + throw new CloudException("Error updating cloud region in Catalog: " + e.getMessage(), e); + } + } + + public void deleteCloudRegion(String cloudRegionId) throws CloudException { + try { + catalogDBClient.deleteCloudSite(cloudRegionId); + } catch (Exception e) { + logger.error("Error deleting cloud region in catalogdb", e); + throw new CloudException("Error deleting cloud region in Catalog: " + e.getMessage(), e); + } + } + + protected void createCloudRegionInAAI(CloudSite cloudSite, String cloudOwner) { + try { + CloudRegion cloudRegion = mapCloudRegion(cloudSite, cloudOwner); + AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.CLOUD_REGION, + cloudRegion.getCloudOwner(), cloudRegion.getCloudRegionId()); + getAaiClient().createIfNotExists(uri, Optional.of(cloudRegion)); + } 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 createRegionInCatalogDb(CloudSite cloudSite) throws CloudException { + try { + CloudSite existingCloudSite = catalogDBClient.getCloudSite(cloudSite.getRegionId()); + if (existingCloudSite == null) { + catalogDBClient.postCloudSite(cloudSite); + } + } catch (Exception e) { + logger.error("Error creating cloud site in Catalog Adapter: " + e.getMessage(), e); + throw new CloudException("Error creating cloud site in Catalog Adapter", e); + } + } + + protected CloudRegion mapCloudRegion(CloudSite cloudSite, String cloudOwner) { + CloudRegion region = new CloudRegion(); + region.setCloudOwner(cloudOwner); + region.setCloudRegionId(cloudSite.getRegionId()); + region.setCloudRegionVersion(cloudSite.getCloudVersion()); + region.setOwnerDefinedType("cLCP"); + region.setOrchestrationDisabled(false); + region.setComplexName("NA"); + region.setInMaint(false); + region.setCloudType("openstack"); + return region; + } + + protected AAIResourcesClient getAaiClient() { + if (aaiClient == null) + return new AAIResourcesClient(); + else + return aaiClient; + } + +} diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/CXFConfiguration.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/CXFConfiguration.java index 9fc5c979d8..9badd795eb 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/CXFConfiguration.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/openstack/CXFConfiguration.java @@ -32,6 +32,7 @@ import org.apache.cxf.jaxrs.JAXRSServerFactoryBean; import org.apache.cxf.jaxrs.swagger.Swagger2Feature; import org.apache.cxf.jaxws.EndpointImpl; import org.apache.cxf.transport.servlet.CXFServlet; +import org.onap.so.adapters.cloudregion.CloudRegionRestV1; import org.onap.so.adapters.network.MsoNetworkAdapterAsyncImpl; import org.onap.so.adapters.network.MsoNetworkAdapterImpl; import org.onap.so.adapters.network.NetworkAdapterRest; @@ -47,10 +48,12 @@ import org.onap.so.adapters.vnf.VolumeAdapterRestV2; import org.onap.so.client.policy.JettisonStyleMapperProvider; import org.onap.so.logging.cxf.interceptor.SOAPLoggingInInterceptor; import org.onap.so.logging.cxf.interceptor.SOAPLoggingOutInterceptor; +import org.onap.so.logging.jaxrs.filter.SOAuditLogContainerFilter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; @@ -81,7 +84,14 @@ public class CXFConfiguration { @Autowired private MsoVnfCloudifyAdapterImpl vnfCloudifyAdapterImpl; @Autowired + private CloudRegionRestV1 cloudRegionRestV1; + @Autowired private JettisonStyleMapperProvider jettisonStyleObjectMapper; + @Autowired + private ObjectMapper mapper; + @Autowired + private SOAuditLogContainerFilter soAuditLogContainerFilter; + @Bean(name = Bus.DEFAULT_BUS_ID) public SpringBus springBus() { @@ -170,6 +180,7 @@ public class CXFConfiguration { return endpoint; } + // Uses Jettson Style marshalling semantics @Bean public Server rsServer() { JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); @@ -178,7 +189,20 @@ public class CXFConfiguration { vnfAdapterRestV2, volumeAdapterRest, volumeAdapterRestV2)); endpoint.setAddress("/rest"); endpoint.setFeatures(Arrays.asList(createSwaggerFeature(), new LoggingFeature())); - endpoint.setProvider(new JacksonJsonProvider(jettisonStyleObjectMapper.getMapper())); + endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(jettisonStyleObjectMapper.getMapper()), + soAuditLogContainerFilter)); + return endpoint.create(); + } + + // Uses normal Jackson marshalling semantics + @Bean + public Server rsServerApi() { + JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean(); + endpoint.setBus(springBus()); + endpoint.setServiceBeans(Arrays.<Object>asList(cloudRegionRestV1)); + endpoint.setAddress("/api"); + endpoint.setFeatures(Arrays.asList(new LoggingFeature())); + endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(mapper), soAuditLogContainerFilter)); return endpoint.create(); } 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 new file mode 100644 index 0000000000..9c62c286ac --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/cloudregion/CloudRegionRestImplTest.java @@ -0,0 +1,96 @@ +package org.onap.so.adapters.cloudregion; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; +import java.util.Optional; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.aai.domain.yang.CloudRegion; +import org.onap.so.client.aai.AAIObjectType; +import org.onap.so.client.aai.AAIResourcesClient; +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; + + +@RunWith(MockitoJUnitRunner.class) +public class CloudRegionRestImplTest { + + @Spy + @InjectMocks + private CloudRestImpl cloudRestImpl; + + @Mock + private CatalogDbClient catalogDbClientMock; + + @Mock + private AAIResourcesClient aaiResClientMock; + + private CloudSite cloudSite = new CloudSite(); + + private CloudRegion testCloudRegion = new CloudRegion(); + + @Before + public void setup() { + cloudSite.setCloudVersion("1.0"); + cloudSite.setRegionId("region1"); + 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"); + } + + @Test + public void mapCloudRegionTest() { + CloudRegion mappedRegion = cloudRestImpl.mapCloudRegion(cloudSite, "bob"); + assertThat(mappedRegion, sameBeanAs(testCloudRegion)); + } + + @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"); + ArgumentCaptor<AAIResourceUri> actualURI = ArgumentCaptor.forClass(AAIResourceUri.class); + ArgumentCaptor<Optional<Object>> actualCloudRegion = ArgumentCaptor.forClass(Optional.class); + verify(catalogDbClientMock, times(1)).getCloudSite("region1"); + verify(catalogDbClientMock, times(1)).postCloudSite(cloudSite); + verify(aaiResClientMock, times(1)).createIfNotExists(Mockito.eq(uri), Mockito.any()); + verify(aaiResClientMock, times(1)).createIfNotExists(actualURI.capture(), actualCloudRegion.capture()); + assertThat((CloudRegion) actualCloudRegion.getValue().get(), sameBeanAs(testCloudRegion)); + } + + @Test + public void updateCloudRegionTest() { + when(catalogDbClientMock.updateCloudSite(cloudSite)).thenReturn(cloudSite); + cloudRestImpl.updateCloudRegion(cloudSite, "bob"); + verify(catalogDbClientMock, times(1)).updateCloudSite(cloudSite); + } + + @Test + public void deleteCloudRegionTest() { + doNothing().when(catalogDbClientMock).deleteCloudSite("region1"); + cloudRestImpl.deleteCloudRegion(cloudSite.getRegionId()); + verify(catalogDbClientMock, times(1)).deleteCloudSite("region1"); + } + +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java index 2e5a00ad02..1882b4e183 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/controller/NotificationController.java @@ -20,9 +20,11 @@ package org.onap.so.adapters.vevnfm.controller; +import org.onap.so.adapters.vevnfm.service.DmaapService; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -33,9 +35,13 @@ public class NotificationController { private static final Logger logger = LoggerFactory.getLogger(NotificationController.class); + @Autowired + private DmaapService dmaapService; + @PostMapping("${notification.url}") public ResponseEntity receiveNotification(@RequestBody final VnfLcmOperationOccurrenceNotification notification) { logger.info("Notification received {}", notification); + dmaapService.send(notification); return ResponseEntity.ok().build(); } } diff --git a/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java new file mode 100644 index 0000000000..59397cead3 --- /dev/null +++ b/adapters/mso-ve-vnfm-adapter/src/main/java/org/onap/so/adapters/vevnfm/service/DmaapService.java @@ -0,0 +1,39 @@ +package org.onap.so.adapters.vevnfm.service; + +import org.onap.so.adapters.vnfmadapter.extclients.vnfm.lcn.model.VnfLcmOperationOccurrenceNotification; +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.Value; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; + +@Service +public class DmaapService { + + private static final Logger logger = LoggerFactory.getLogger(DmaapService.class); + + @Value("${dmaap.endpoint}") + private String endpoint; + + @Value("${dmaap.topic}") + private String topic; + + @Autowired + private HttpRestServiceProvider restProvider; + + public void send(final VnfLcmOperationOccurrenceNotification notification) { + final ResponseEntity<String> response = restProvider.postHttpRequest(notification, getUrl(), String.class); + + final HttpStatus statusCode = response.getStatusCode(); + final String body = response.getBody(); + + logger.info("The DMaaP replied with the code {} and the body {}", statusCode, body); + } + + private String getUrl() { + return endpoint + topic; + } +} diff --git a/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml b/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml index f3ad9615ec..35871c51ac 100644 --- a/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml +++ b/adapters/mso-ve-vnfm-adapter/src/main/resources/application.yaml @@ -33,6 +33,10 @@ aai: vnfm: subscription: /vnflcm/v1/subscriptions +dmaap: + endpoint: http://message-router:30227 + topic: /events/unauthenticated.DCAE_CL_OUTPUT + spring: security: usercredentials: diff --git a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java index 418c2e2201..57638a165a 100644 --- a/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java +++ b/adapters/mso-ve-vnfm-adapter/src/test/java/org/onap/so/adapters/vevnfm/controller/NotificationControllerTest.java @@ -21,6 +21,9 @@ package org.onap.so.adapters.vevnfm.controller; import static org.junit.Assert.assertEquals; +import static org.springframework.test.web.client.ExpectedCount.once; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.anything; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -33,11 +36,13 @@ import org.springframework.http.MediaType; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.client.RestTemplate; import org.springframework.web.context.WebApplicationContext; @SpringBootTest @@ -54,11 +59,16 @@ public class NotificationControllerTest { @Autowired private WebApplicationContext webApplicationContext; + @Autowired + private RestTemplate restTemplate; + private MockMvc mvc; + private MockRestServiceServer mockRestServer; @Before public void init() { mvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build(); + mockRestServer = MockRestServiceServer.bindTo(restTemplate).build(); } @Test @@ -67,6 +77,8 @@ public class NotificationControllerTest { final MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(notificationUrl) .contentType(MediaType.APPLICATION_JSON).content(MINIMAL_JSON_CONTENT); + mockRestServer.expect(once(), anything()).andRespond(withSuccess()); + // when final MvcResult mvcResult = mvc.perform(request).andReturn(); @@ -74,5 +86,6 @@ public class NotificationControllerTest { final MockHttpServletResponse response = mvcResult.getResponse(); assertEquals(HttpStatus.OK.value(), response.getStatus()); assertEquals(ZERO, response.getContentLength()); + mockRestServer.verify(); } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicWebSecurityConfigurerAdapter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicHttpSecurityConfigurer.java index a5404607b4..1e0a18a339 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicWebSecurityConfigurerAdapter.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/VnfmBasicHttpSecurityConfigurer.java @@ -22,34 +22,41 @@ package org.onap.so.adapters.vnfmadapter; -import org.onap.so.security.SoBasicWebSecurityConfigurerAdapter; +import org.onap.so.security.HttpSecurityConfigurer; import org.onap.so.security.SoUserCredentialConfiguration; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; import org.springframework.http.HttpMethod; import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; /** * @author Waqas Ikram (waqas.ikram@est.tech) * @author Gareth Roper (gareth.roper@est.tech) * */ -@EnableWebSecurity -@Configuration -public class VnfmBasicWebSecurityConfigurerAdapter extends SoBasicWebSecurityConfigurerAdapter { +@Primary +@Component +public class VnfmBasicHttpSecurityConfigurer implements HttpSecurityConfigurer { + + @Autowired + private SoUserCredentialConfiguration soUserCredentialConfiguration; @Value("${server.ssl.client-auth:none}") private String clientAuth; - SoUserCredentialConfiguration soUserCredentialConfiguration; @Override - protected void configure(final HttpSecurity http) throws Exception { + public void configure(final HttpSecurity http) throws Exception { if (("need").equalsIgnoreCase(clientAuth)) { http.csrf().disable().authorizeRequests().anyRequest().permitAll(); } else { - super.configure(http); - http.authorizeRequests().antMatchers(HttpMethod.GET, "/etsi/subscription/notification").permitAll(); + http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() + .antMatchers(HttpMethod.GET, "/etsi/subscription/notification").permitAll().antMatchers("/**") + .hasAnyRole(StringUtils.collectionToDelimitedString(soUserCredentialConfiguration.getRoles(), ",")) + .and().httpBasic(); + } } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java index 62b365745c..e0eed159c2 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProvider.java @@ -23,7 +23,6 @@ package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog; import java.util.Optional; import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscription; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001; -import org.springframework.http.ResponseEntity; /** * Provides methods for invoking REST calls to the ETSI Catalog Manager. @@ -74,11 +73,18 @@ public interface EtsiCatalogServiceProvider { Optional<byte[]> getVnfPackageArtifact(final String vnfPkgId, final String artifactPath); /** - * Post the SubscriptionRequest Object. + * POST the SubscriptionRequest Object. * - * @return The ResponseEntity containing the ETSI Catalog Manager's PkgmSubscription object. + * @return The ETSI Catalog Manager's PkgmSubscription object. */ Optional<PkgmSubscription> postSubscription( final org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscriptionRequest etsiCatalogManagerSubscriptionRequest); + /** + * DELETE the SubscriptionRequest Object. + * + * @return A Boolean representing if the delete was successful or not. + */ + Boolean deleteSubscription(final String subscriptionId); + } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java index 1a48494e1a..573a798410 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java @@ -21,11 +21,14 @@ package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog; import java.util.Optional; -import javax.swing.text.html.Option; import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscription; import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.VnfPkgInfo; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2001; -import org.onap.so.adapters.vnfmadapter.rest.exceptions.*; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerBadRequestException; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.EtsiCatalogManagerRequestFailureException; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgBadRequestException; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgConflictException; +import org.onap.so.adapters.vnfmadapter.rest.exceptions.VnfPkgNotFoundException; import org.onap.so.rest.exceptions.HttpResouceNotFoundException; import org.onap.so.rest.exceptions.InvalidRestRequestException; import org.onap.so.rest.exceptions.RestProcessingException; @@ -190,7 +193,8 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide return Optional.empty(); } catch (final InvalidRestRequestException invalidRestRequestException) { logger.error("Caught InvalidRestRequestException", invalidRestRequestException); - throw new EtsiCatalogManagerBadRequestException("Bad Request Received on postSubscription call."); + throw new EtsiCatalogManagerBadRequestException( + "Bad Request Received on postSubscription call to ETSI Catalog Manager."); } catch (final RestProcessingException restProcessingException) { logger.error("Caught RestProcessingException with Status Code: {}", restProcessingException.getStatusCode(), restProcessingException); @@ -200,6 +204,28 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide } } + public Boolean deleteSubscription(final String subscriptionId) { + try { + final ResponseEntity<Void> responseEntity = httpServiceProvider + .deleteHttpRequest(etsiCatalogUrlProvider.getSubscriptionUrl() + "/" + subscriptionId, Void.class); + + if (responseEntity.getStatusCode() == HttpStatus.NO_CONTENT) { + logger.info("Subscription with ID: {} has been successfully deleted from the ETSI Catalog Manager", + subscriptionId); + return true; + } + logger.error("Unexpected Status Code Received on deleteSubscription: {}", responseEntity.getStatusCode()); + return false; + } catch (final InvalidRestRequestException invalidRestRequestException) { + logger.error("Caught InvalidRestRequestException on deleteSubscription call to ETSI Catalog Manager.", + invalidRestRequestException); + throw new EtsiCatalogManagerBadRequestException( + "Bad Request Received on deleteSubscription call to ETSI Catalog Manager."); + } + } + + + private Optional<byte[]> requestVnfElement(final String vnfPkgId, final String vnfRequestUrl, final String vnfRequestName) { try { diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java index 30a16f70a8..bbf8b74952 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/SubscriptionManager.java @@ -143,6 +143,15 @@ public class SubscriptionManager { return response; } + public boolean deleteSubscription(final String subscriptionId) { + if (getSubscription(subscriptionId).isPresent()) { + if (etsiCatalogServiceProvider.deleteSubscription(subscriptionId)) { + return packageManagementCacheServiceProvider.deleteSubscription(subscriptionId); + } + } + return false; + } + public URI getSubscriptionUri(final String subscriptionId) { return URI.create( vnfmAdapterEndpoint + Constants.PACKAGE_MANAGEMENT_BASE_URL + "/subscriptions/" + subscriptionId); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java index 6042513a50..437d20e593 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/cache/PackageManagementCacheServiceProvider.java @@ -60,7 +60,7 @@ public interface PackageManagementCacheServiceProvider { * Delete subscription from cache * * @param subscriptionId - * @return true if subscription exists and able to be removed, otherwise returns false + * @return Boolean */ boolean deleteSubscription(final String subscriptionId); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java index cbad564210..4be0838c08 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionController.java @@ -23,14 +23,13 @@ package org.onap.so.adapters.vnfmadapter.rest; import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL; import static org.slf4j.LoggerFactory.getLogger; import java.net.URI; -import java.net.URISyntaxException; import java.security.GeneralSecurityException; import java.util.List; import java.util.Optional; import javax.ws.rs.core.MediaType; +import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse2002; import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest; -import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.ProblemDetails; import org.onap.so.adapters.vnfmadapter.packagemanagement.subscriptionmanagement.SubscriptionManager; import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; @@ -38,6 +37,7 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -140,6 +140,24 @@ public class Sol003PackageManagementSubscriptionController { } /** + * DELETE a specific subscription, by subscriptionId. Section Number: 10.4.8.3.5 + * + * @param subscriptionId The ID of the subscription that you wish to delete. + * @return Empty response if successful. Object: Void Response Code: 204 No Content + */ + @DeleteMapping(value = "/subscriptions/{subscriptionId}") + public ResponseEntity<?> deleteSubscription(@PathVariable("subscriptionId") final String subscriptionId) { + if (subscriptionManager.deleteSubscription(subscriptionId)) { + logger.debug("Successfully deleted subscription with id {}", subscriptionId); + return ResponseEntity.noContent().build(); + } + final String errorMessage = + "The requested subscription: " + subscriptionId + " was not found on call deleteSubscription"; + logger.error(errorMessage); + return ResponseEntity.status(HttpStatus.NOT_FOUND).body(new ProblemDetails().detail(errorMessage)); + } + + /** * Method to set the Location in the header with the URI parameter * * @param subscriptionUri diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java index f90978e0d5..3d26c33679 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java @@ -68,6 +68,7 @@ import org.springframework.web.client.RestTemplate; import org.springframework.http.HttpMethod; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.hamcrest.Matchers.is; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; /** @@ -199,6 +200,41 @@ public class Sol003PackageManagementSubscriptionControllerTest { assertEquals(HttpStatus.OK, response.getStatusCode()); } + @Test + public void testSuccessDeleteSubscriptionWithSubscriptionId() throws GeneralSecurityException { + final PkgmSubscriptionRequest pkgmSubscriptionRequest = buildPkgmSubscriptionRequest(); + final PkgmSubscription pkgmSubscription = buildPkgmSubscription(); + final String subscriptionId = pkgmSubscription.getId(); + + mockRestServer.expect(requestTo(msbEndpoint)).andExpect(method(HttpMethod.POST)) + .andRespond(withSuccess(gson.toJson(pkgmSubscription), MediaType.APPLICATION_JSON)); + mockRestServer.expect(requestTo(msbEndpoint + "/" + subscriptionId)).andExpect(method(HttpMethod.DELETE)) + .andRespond(withStatus(HttpStatus.NO_CONTENT)); + + final ResponseEntity<InlineResponse2002> responsePost = + (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController + .postSubscriptionRequest(pkgmSubscriptionRequest); + + + final ResponseEntity responseDelete = + sol003PackageManagementSubscriptionController.deleteSubscription(subscriptionId); + + // Attempt to retrieve the subscription after delete + final ResponseEntity<InlineResponse2002> responseGetSubscription = + (ResponseEntity<InlineResponse2002>) sol003PackageManagementSubscriptionController + .getSubscription(subscriptionId); + + assertEquals(HttpStatus.NOT_FOUND, responseGetSubscription.getStatusCode()); + assertEquals(HttpStatus.NO_CONTENT, responseDelete.getStatusCode()); + } + + @Test + public void testFailDeleteSubscriptionWithInvalidSubscriptionId() throws URISyntaxException, InterruptedException { + final ResponseEntity<Void> responseDelete = (ResponseEntity<Void>) sol003PackageManagementSubscriptionController + .deleteSubscription("invalidSubscriptionId"); + assertEquals(HttpStatus.NOT_FOUND, responseDelete.getStatusCode()); + } + private PkgmSubscriptionRequest buildPkgmSubscriptionRequest() { final PkgmSubscriptionRequest pkgmSubscriptionRequest = new PkgmSubscriptionRequest(); final SubscriptionsFilter sub = buildSubscriptionsFilter(); diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/Pnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/Pnf.java index 772c61e48b..1953ba410b 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/Pnf.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/bbobjects/Pnf.java @@ -24,6 +24,7 @@ import java.io.Serializable; import javax.persistence.Id; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoPnf; import org.onap.so.db.catalog.beans.OrchestrationStatus; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; @@ -41,7 +42,7 @@ public class Pnf implements Serializable, ShallowCopy<Pnf> { @JsonProperty("pnf-name") private String pnfName; - @JsonProperty("role") + @JsonProperty("nf-role") private String role; @JsonProperty("orchestration-status") @@ -50,6 +51,8 @@ public class Pnf implements Serializable, ShallowCopy<Pnf> { @JsonProperty("cloud-region") private CloudRegion cloudRegion; + @JsonProperty("model-info-pnf") + private ModelInfoPnf modelInfoPnf; public String getPnfId() { return pnfId; @@ -97,6 +100,14 @@ public class Pnf implements Serializable, ShallowCopy<Pnf> { this.cloudRegion = cloudRegion; } + public ModelInfoPnf getModelInfoPnf() { + return modelInfoPnf; + } + + public void setModelInfoPnf(ModelInfoPnf modelInfoPnf) { + this.modelInfoPnf = modelInfoPnf; + } + @Override public boolean equals(final Object other) { if (!(other instanceof Pnf)) { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/modelinfo/ModelInfoPnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/modelinfo/ModelInfoPnf.java new file mode 100644 index 0000000000..a01fa9698b --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/modelinfo/ModelInfoPnf.java @@ -0,0 +1,27 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.bpmn.servicedecomposition.modelinfo; + +import java.io.Serializable; + +public class ModelInfoPnf extends ModelInfoMetadata implements Serializable { + private static final long serialVersionUID = 50687109134317615L; +} diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java index 145d4c83a7..e7e51bba77 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetup.java @@ -6,7 +6,7 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ - * Modifications Copyright (c) 2019 Nokia + * Modifications Copyright (c) 2020 Nokia * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -815,13 +815,6 @@ public class BBInputSetup implements JavaDelegate { } } - private void populatePnf(Pnfs pnf, String pnfId, ServiceInstance serviceInstance) { - Pnf genericPnf = new Pnf(); - genericPnf.setPnfId(pnfId); - genericPnf.setPnfName(pnf.getInstanceName()); - serviceInstance.getPnfs().add(genericPnf); - } - protected boolean instanceGroupInList(GenericVnf vnf, String instanceGroupId) { for (InstanceGroup instanceGroup : vnf.getInstanceGroups()) { if (instanceGroup.getId() != null && instanceGroup.getId().equalsIgnoreCase(instanceGroupId)) { @@ -1503,8 +1496,8 @@ public class BBInputSetup implements JavaDelegate { } else if (bbName.contains(PNF)) { String pnfId = lookupKeyMap.get(ResourceKey.PNF); resources.getPnfs().stream() - .filter(pnf -> Objects.equals(key, pnf.getModelInfo().getModelCustomizationId())).findFirst() - .ifPresent(pnf -> this.populatePnf(pnf, pnfId, serviceInstance)); + .filter(pnfs -> Objects.equals(key, pnfs.getModelInfo().getModelCustomizationId())).findFirst() + .ifPresent(pnfs -> BBInputSetupPnf.populatePnfToServiceInstance(pnfs, pnfId, serviceInstance)); } else if (bbName.contains(VF_MODULE) || bbName.contains(VOLUME_GROUP)) { Pair<Vnfs, VfModules> vnfsAndVfModules = getVfModulesAndItsVnfsByKey(key, resources); if (vnfsAndVfModules != null) { diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupPnf.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupPnf.java new file mode 100644 index 0000000000..68161a8dd5 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupPnf.java @@ -0,0 +1,48 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + + +package org.onap.so.bpmn.servicedecomposition.tasks; + +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoPnf; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.serviceinstancebeans.Pnfs; + +final class BBInputSetupPnf { + + private BBInputSetupPnf() { + throw new IllegalStateException("Utility class"); + } + + static void populatePnfToServiceInstance(Pnfs pnfs, String pnfId, ServiceInstance serviceInstance) { + Pnf pnf = new Pnf(); + pnf.setPnfId(pnfId); + pnf.setPnfName(pnfs.getInstanceName()); + pnf.setModelInfoPnf(new ModelInfoPnf()); + pnf.getModelInfoPnf().setModelCustomizationUuid(pnfs.getModelInfo().getModelCustomizationId()); + pnf.getModelInfoPnf().setModelInvariantUuid(pnfs.getModelInfo().getModelInvariantId()); + pnf.getModelInfoPnf().setModelUuid(pnfs.getModelInfo().getModelVersionId()); + pnf.setOrchestrationStatus(OrchestrationStatus.PRECREATED); + + serviceInstance.getPnfs().add(pnf); + } +} diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupPnfTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupPnfTest.java new file mode 100644 index 0000000000..aa9943b9b1 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/bpmn/servicedecomposition/tasks/BBInputSetupPnfTest.java @@ -0,0 +1,73 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Nokia Intellectual Property. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + + +package org.onap.so.bpmn.servicedecomposition.tasks; + +import static org.junit.Assert.*; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; +import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; +import org.onap.so.db.catalog.beans.OrchestrationStatus; +import org.onap.so.serviceinstancebeans.ModelInfo; +import org.onap.so.serviceinstancebeans.Pnfs; +import static org.mockito.Mockito.doReturn; + +@RunWith(MockitoJUnitRunner.class) +public class BBInputSetupPnfTest { + + @Mock + private Pnfs pnfs; + + @Mock + private ModelInfo modelInfo; + + @Test + public void populatePnfShouldSetRequiredFields() { + final String pnfId = "PNF_id1"; + final String pnfName = "PNF_name1"; + final String modelCustomizationId = "8421fe03-fd1b-4bf7-845a-c3fe91edb031"; + final String modelInvariantId = "3360a2a5-22ff-44c7-8935-08c8e5ecbd06"; + final String modelVersionId = "b80c3a52-abd4-436c-a22e-9c5da768781a"; + + doReturn(modelCustomizationId).when(modelInfo).getModelCustomizationId(); + doReturn(modelInvariantId).when(modelInfo).getModelInvariantId(); + doReturn(modelVersionId).when(modelInfo).getModelVersionId(); + doReturn(pnfName).when(pnfs).getInstanceName(); + doReturn(modelInfo).when(pnfs).getModelInfo(); + + ServiceInstance serviceInstance = new ServiceInstance(); + BBInputSetupPnf.populatePnfToServiceInstance(pnfs, pnfId, serviceInstance); + + assertEquals(1, serviceInstance.getPnfs().size()); + + Pnf pnf = serviceInstance.getPnfs().get(0); + + assertEquals(pnfId, pnf.getPnfId()); + assertEquals(pnfName, pnf.getPnfName()); + assertEquals(modelCustomizationId, pnf.getModelInfoPnf().getModelCustomizationUuid()); + assertEquals(modelInvariantId, pnf.getModelInfoPnf().getModelInvariantUuid()); + assertEquals(modelVersionId, pnf.getModelInfoPnf().getModelUuid()); + assertEquals(OrchestrationStatus.PRECREATED, pnf.getOrchestrationStatus()); + } +} diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/PauseForManualTaskRainyDayTest.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/PauseForManualTaskRainyDayTest.java index 576f9c4f01..29d7a80f63 100644 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/PauseForManualTaskRainyDayTest.java +++ b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/bpmn/infrastructure/bpmn/subprocess/PauseForManualTaskRainyDayTest.java @@ -20,24 +20,24 @@ package org.onap.so.bpmn.infrastructure.bpmn.subprocess; -import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.assertThat; +import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions.assertThat; import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import org.camunda.bpm.engine.ManagementService; import org.camunda.bpm.engine.TaskService; import org.camunda.bpm.engine.delegate.BpmnError; import org.camunda.bpm.engine.runtime.Job; import org.camunda.bpm.engine.runtime.ProcessInstance; -import org.camunda.bpm.engine.delegate.DelegateExecution; import org.camunda.bpm.engine.task.Task; import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareAssertions; +import org.junit.Ignore; import org.junit.Test; -import org.springframework.beans.factory.annotation.Autowired; import org.onap.so.bpmn.BaseBPMNTest; import org.onap.so.bpmn.common.BuildingBlockExecution; +import org.springframework.beans.factory.annotation.Autowired; - +@Ignore public class PauseForManualTaskRainyDayTest extends BaseBPMNTest { private static final String TIMEOUT_10_S = "PT10S"; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java index 533dd89276..4522f7f2e7 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java @@ -24,6 +24,7 @@ package org.onap.so.bpmn.infrastructure.activity; +import java.io.IOException; import java.io.Serializable; import java.util.HashMap; import java.util.Map; @@ -89,8 +90,8 @@ public class ExecuteActivity implements JavaDelegate { @Override public void execute(DelegateExecution execution) throws Exception { final String requestId = (String) execution.getVariable(G_REQUEST_ID); - WorkflowException workflowException = null; - String handlingCode = null; + WorkflowException workflowException; + String handlingCode; try { Boolean workflowSyncAckSent = (Boolean) execution.getVariable(WORKFLOW_SYNC_ACK_SENT); if (workflowSyncAckSent == null || workflowSyncAckSent == false) { @@ -114,7 +115,7 @@ public class ExecuteActivity implements JavaDelegate { if (execution.getVariables() != null) { execution.getVariables().forEach((key, value) -> { if (value instanceof Serializable) { - variables.put(key, (Serializable) value); + variables.put(key, value); } }); } @@ -153,25 +154,22 @@ public class ExecuteActivity implements JavaDelegate { } protected BuildingBlock buildBuildingBlock(String activityName) { - BuildingBlock buildingBlock = new BuildingBlock().setBpmnFlowName(activityName) - .setMsoId(UUID.randomUUID().toString()).setKey("").setIsVirtualLink(false).setVirtualLinkKey(""); - return buildingBlock; + return new BuildingBlock().setBpmnFlowName(activityName).setMsoId(UUID.randomUUID().toString()).setKey("") + .setIsVirtualLink(false).setVirtualLinkKey(""); } protected ExecuteBuildingBlock buildExecuteBuildingBlock(DelegateExecution execution, String requestId, - BuildingBlock buildingBlock) throws Exception { + BuildingBlock buildingBlock) throws IOException { WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds(); workflowResourceIds.setServiceInstanceId((String) execution.getVariable(SERVICE_INSTANCE_ID)); workflowResourceIds.setVnfId((String) execution.getVariable(VNF_ID)); String bpmnRequest = (String) execution.getVariable(G_BPMN_REQUEST); ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); RequestDetails requestDetails = sIRequest.getRequestDetails(); - ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock().setaLaCarte(true) - .setRequestAction((String) execution.getVariable(G_ACTION)) + return new ExecuteBuildingBlock().setaLaCarte(true).setRequestAction((String) execution.getVariable(G_ACTION)) .setResourceId((String) execution.getVariable(VNF_ID)) .setVnfType((String) execution.getVariable(VNF_TYPE)).setWorkflowResourceIds(workflowResourceIds) .setRequestId(requestId).setBuildingBlock(buildingBlock).setRequestDetails(requestDetails); - return executeBuildingBlock; } protected void buildAndThrowException(DelegateExecution execution, String msg, Exception ex) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetwork.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetwork.java index 164480d7c7..ff0f9e76a3 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetwork.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/AssignNetwork.java @@ -6,6 +6,8 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -46,17 +48,16 @@ public class AssignNetwork { * @return */ public boolean networkFoundByName(BuildingBlockExecution execution) { - boolean networkFound = false; try { L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID); if (!OrchestrationStatus.PRECREATED.equals(l3network.getOrchestrationStatus())) { - networkFound = true; logger.debug("network found in NOT PRECREATED status"); + return true; } } catch (Exception ex) { - // return false if no network present + return false; } - return networkFound; + return false; } } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollection.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollection.java index 36eab8f981..5e925bf9c6 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollection.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/flowspecific/tasks/CreateNetworkCollection.java @@ -6,6 +6,8 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -29,8 +31,6 @@ import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.orchestration.AAINetworkResources; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java index ea0b408e41..ccbce2de6a 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceCreateTasks.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -20,25 +22,16 @@ package org.onap.so.bpmn.infrastructure.namingservice.tasks; -import java.util.List; -import java.util.Optional; -import org.onap.aai.domain.yang.Zone; import org.onap.so.bpmn.common.BuildingBlockExecution; import org.onap.so.bpmn.common.InjectionHelper; -import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration; import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding; -import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; -import org.onap.so.client.aai.AAIObjectType; -import org.onap.so.client.aai.entities.AAIResultWrapper; -import org.onap.so.client.aai.entities.Relationships; -import org.onap.so.client.aai.entities.uri.AAIResourceUri; -import org.onap.so.client.aai.entities.uri.AAIUriFactory; +import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.namingservice.NamingRequestObject; import org.onap.so.client.namingservice.NamingServiceConstants; @@ -65,7 +58,7 @@ public class NamingServiceCreateTasks { this.bbInputSetupUtils = bbInputSetupUtils; } - public void createInstanceGroupName(BuildingBlockExecution execution) throws Exception { + public void createInstanceGroupName(BuildingBlockExecution execution) throws BBObjectNotFoundException { InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID); String policyInstanceName = execution.getVariable("policyInstanceName"); String nfNamingCode = execution.getVariable("nfNamingCode"); @@ -79,7 +72,7 @@ public class NamingServiceCreateTasks { instanceGroup.setInstanceGroupName(generatedInstanceGroupName); } - public void createWanTransportServiceName(BuildingBlockExecution execution) throws Exception { + public void createWanTransportServiceName(BuildingBlockExecution execution) throws BBObjectNotFoundException { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); NamingRequestObject namingRequestObject = new NamingRequestObject(); namingRequestObject.setExternalKeyValue(serviceInstance.getServiceInstanceId()); @@ -98,7 +91,7 @@ public class NamingServiceCreateTasks { serviceInstance.setServiceInstanceName(generatedWanTransportServiceName); } - public void createVpnBondingServiceName(BuildingBlockExecution execution) throws Exception { + public void createVpnBondingServiceName(BuildingBlockExecution execution) throws BBObjectNotFoundException { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); L3Network network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID); VpnBinding vpnBinding = extractPojosForBB.extractByKey(execution, ResourceKey.VPN_ID); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java index 507e14e42a..8d14bd3e89 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/namingservice/tasks/NamingServiceDeleteTasks.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -26,6 +28,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance; import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey; import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB; +import org.onap.so.client.exception.BBObjectNotFoundException; import org.onap.so.client.exception.ExceptionBuilder; import org.onap.so.client.namingservice.NamingRequestObject; import org.onap.so.client.orchestration.NamingServiceResources; @@ -43,7 +46,7 @@ public class NamingServiceDeleteTasks { @Autowired private NamingServiceResources namingServiceResources; - public void deleteInstanceGroupName(BuildingBlockExecution execution) throws Exception { + public void deleteInstanceGroupName(BuildingBlockExecution execution) throws BBObjectNotFoundException { InstanceGroup instanceGroup = extractPojosForBB.extractByKey(execution, ResourceKey.INSTANCE_GROUP_ID); try { @@ -53,7 +56,7 @@ public class NamingServiceDeleteTasks { } } - public void deleteServiceInstanceName(BuildingBlockExecution execution) throws Exception { + public void deleteServiceInstanceName(BuildingBlockExecution execution) throws BBObjectNotFoundException { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); NamingRequestObject namingRequestObject = new NamingRequestObject(); namingRequestObject.setExternalKeyValue(serviceInstance.getServiceInstanceId()); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java index 192cb3fc90..89d62e0752 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/sdnc/tasks/SDNCQueryTasks.java @@ -6,6 +6,8 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -64,7 +66,7 @@ public class SDNCQueryTasks { * @param execution * @throws Exception */ - public void queryVnf(BuildingBlockExecution execution) throws Exception { + public void queryVnf(BuildingBlockExecution execution) throws BBObjectNotFoundException { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); @@ -99,7 +101,7 @@ public class SDNCQueryTasks { * @param execution * @throws Exception */ - public void queryVfModule(BuildingBlockExecution execution) throws Exception { + public void queryVfModule(BuildingBlockExecution execution) throws BBObjectNotFoundException { ServiceInstance serviceInstance = extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID); GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java index 11a7b83259..cf56964af3 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/aai/mapper/AAIObjectMapper.java @@ -90,6 +90,17 @@ public class AAIObjectMapper { } public org.onap.aai.domain.yang.Pnf mapPnf(Pnf pnf) { + if (modelMapper.getTypeMap(Pnf.class, org.onap.aai.domain.yang.Pnf.class) == null) { + modelMapper.addMappings(new PropertyMap<Pnf, org.onap.aai.domain.yang.Pnf>() { + @Override + protected void configure() { + map().setModelCustomizationId(source.getModelInfoPnf().getModelCustomizationUuid()); + map().setModelInvariantId(source.getModelInfoPnf().getModelInvariantUuid()); + map().setModelVersionId(source.getModelInfoPnf().getModelUuid()); + } + }); + } + return modelMapper.map(pnf, org.onap.aai.domain.yang.Pnf.class); } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/VnfAdapterVolumeGroupResources.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/VnfAdapterVolumeGroupResources.java index 2ec63182a0..35e08563d1 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/VnfAdapterVolumeGroupResources.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/client/orchestration/VnfAdapterVolumeGroupResources.java @@ -6,6 +6,8 @@ * ================================================================================ * Modifications Copyright (c) 2019 Samsung * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -32,10 +34,9 @@ import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext; import org.onap.so.client.adapter.vnf.VnfVolumeAdapterClientImpl; import org.onap.so.client.adapter.vnf.mapper.VnfAdapterObjectMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.io.IOException; @Component public class VnfAdapterVolumeGroupResources { @@ -48,13 +49,13 @@ public class VnfAdapterVolumeGroupResources { public CreateVolumeGroupRequest createVolumeGroupRequest(RequestContext requestContext, CloudRegion cloudRegion, OrchestrationContext orchestrationContext, ServiceInstance serviceInstance, GenericVnf genericVnf, - VolumeGroup volumeGroup, String sdncVfModuleQueryResponse) throws Exception { + VolumeGroup volumeGroup, String sdncVfModuleQueryResponse) throws IOException { return vnfAdapterObjectMapper.createVolumeGroupRequestMapper(requestContext, cloudRegion, orchestrationContext, serviceInstance, genericVnf, volumeGroup, sdncVfModuleQueryResponse); } public DeleteVolumeGroupRequest deleteVolumeGroupRequest(RequestContext requestContext, CloudRegion cloudRegion, - ServiceInstance serviceInstance, VolumeGroup volumeGroup) throws Exception { + ServiceInstance serviceInstance, VolumeGroup volumeGroup) throws IOException { return vnfAdapterObjectMapper.deleteVolumeGroupRequestMapper(requestContext, cloudRegion, serviceInstance, volumeGroup); } diff --git a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java index 821e70a8c8..dc64e4ee48 100644 --- a/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java +++ b/bpmn/so-bpmn-tasks/src/test/java/org/onap/so/client/aai/mapper/AAIObjectMapperTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (c) 2020 Nokia + * ================================================================================ * 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 @@ -41,6 +43,7 @@ import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup; import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network; import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy; import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity; +import org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf; import org.onap.so.bpmn.servicedecomposition.bbobjects.Project; import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTarget; import org.onap.so.bpmn.servicedecomposition.bbobjects.SegmentationAssignment; @@ -55,6 +58,7 @@ import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork; +import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoPnf; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance; import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule; import org.onap.so.db.catalog.beans.OrchestrationStatus; @@ -233,6 +237,34 @@ public class AAIObjectMapperTest { } @Test + public void pnfMap() { + final String pnfId = "PNF_id1"; + final String pnfName = "PNF_name1"; + final String modelCustomizationId = "8421fe03-fd1b-4bf7-845a-c3fe91edb03e"; + final String modelInvariantId = "341a6f84-2cf9-4942-8f9e-2472ffe4e1d8"; + final String modelVersionId = "b13a0706-46b9-4a98-a9f9-5b28431235e7"; + final OrchestrationStatus orchestrationStatus = OrchestrationStatus.PRECREATED; + + Pnf pnf = new Pnf(); + pnf.setPnfId(pnfId); + pnf.setPnfName(pnfName); + pnf.setModelInfoPnf(new ModelInfoPnf()); + pnf.getModelInfoPnf().setModelCustomizationUuid(modelCustomizationId); + pnf.getModelInfoPnf().setModelInvariantUuid(modelInvariantId); + pnf.getModelInfoPnf().setModelUuid(modelVersionId); + pnf.setOrchestrationStatus(orchestrationStatus); + + org.onap.aai.domain.yang.Pnf aaiPnf = aaiObjectMapper.mapPnf(pnf); + + assertEquals(aaiPnf.getPnfId(), pnfId); + assertEquals(aaiPnf.getPnfName(), pnfName); + assertEquals(aaiPnf.getModelCustomizationId(), modelCustomizationId); + assertEquals(aaiPnf.getModelInvariantId(), modelInvariantId); + assertEquals(aaiPnf.getModelVersionId(), modelVersionId); + assertEquals(aaiPnf.getOrchestrationStatus(), orchestrationStatus.toString()); + } + + @Test public void vfModuleMap() throws Exception { VfModule vfModule = new VfModule(); vfModule.setVfModuleId("a"); diff --git a/common/src/main/java/org/onap/so/security/HttpSecurityConfigurer.java b/common/src/main/java/org/onap/so/security/HttpSecurityConfigurer.java new file mode 100644 index 0000000000..ffd5931c92 --- /dev/null +++ b/common/src/main/java/org/onap/so/security/HttpSecurityConfigurer.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Ericsson. All rights reserved. + * ================================================================================ + * 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.security; + +import org.springframework.security.config.annotation.web.builders.HttpSecurity; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +public interface HttpSecurityConfigurer { + + void configure(final HttpSecurity http) throws Exception; + +} diff --git a/common/src/main/java/org/onap/so/security/SoBasicHttpSecurityConfigurer.java b/common/src/main/java/org/onap/so/security/SoBasicHttpSecurityConfigurer.java new file mode 100644 index 0000000000..9aceb03519 --- /dev/null +++ b/common/src/main/java/org/onap/so/security/SoBasicHttpSecurityConfigurer.java @@ -0,0 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 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.security; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.stereotype.Component; +import org.springframework.util.StringUtils; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Component +public class SoBasicHttpSecurityConfigurer implements HttpSecurityConfigurer { + + @Autowired + private SoUserCredentialConfiguration soUserCredentialConfiguration; + + @Override + public void configure(final HttpSecurity http) throws Exception { + http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() + .antMatchers("/**") + .hasAnyRole(StringUtils.collectionToDelimitedString(soUserCredentialConfiguration.getRoles(), ",")) + .and().httpBasic(); + } + +} diff --git a/common/src/main/java/org/onap/so/security/SoBasicWebSecurityConfigurerAdapter.java b/common/src/main/java/org/onap/so/security/SoWebSecurityConfigurerAdapter.java index 21176e0d5d..903d586ab1 100644 --- a/common/src/main/java/org/onap/so/security/SoBasicWebSecurityConfigurerAdapter.java +++ b/common/src/main/java/org/onap/so/security/SoWebSecurityConfigurerAdapter.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2020 Nordix Foundation. + * Copyright (C) 2020 Ericsson. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ */ package org.onap.so.security; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @@ -31,7 +33,6 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.web.firewall.StrictHttpFirewall; -import org.springframework.util.StringUtils; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -40,11 +41,12 @@ import org.springframework.util.StringUtils; @EnableWebSecurity @Configuration @Order(1) -@Profile({"basic"}) -public class SoBasicWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { +@Profile({"basic", "test"}) +public class SoWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter { + private static final Logger LOGGER = LoggerFactory.getLogger(SoWebSecurityConfigurerAdapter.class); @Autowired - private SoUserCredentialConfiguration soUserCredentialConfiguration; + private HttpSecurityConfigurer httpSecurityConfigurer; @Autowired private UserDetailsService userDetailsService; @@ -54,10 +56,9 @@ public class SoBasicWebSecurityConfigurerAdapter extends WebSecurityConfigurerAd @Override protected void configure(final HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers("/manage/health", "/manage/info").permitAll() - .antMatchers("/**") - .hasAnyRole(StringUtils.collectionToDelimitedString(soUserCredentialConfiguration.getRoles(), ",")) - .and().httpBasic(); + LOGGER.debug("Injecting {} configuration ...", httpSecurityConfigurer.getClass()); + + httpSecurityConfigurer.configure(http); } @Override diff --git a/docs/.gitignore b/docs/.gitignore new file mode 100644 index 0000000000..43ca5b671f --- /dev/null +++ b/docs/.gitignore @@ -0,0 +1,3 @@ +/.tox +/_build/* +/__pycache__/* diff --git a/docs/_static/css/ribbon.css b/docs/_static/css/ribbon.css new file mode 100644 index 0000000000..6008cb1a08 --- /dev/null +++ b/docs/_static/css/ribbon.css @@ -0,0 +1,63 @@ +.ribbon { + z-index: 1000; + background-color: #a00; + overflow: hidden; + white-space: nowrap; + position: fixed; + top: 25px; + right: -50px; + -webkit-transform: rotate(45deg); + -moz-transform: rotate(45deg); + -ms-transform: rotate(45deg); + -o-transform: rotate(45deg); + transform: rotate(45deg); + -webkit-box-shadow: 0 0 10px #888; + -moz-box-shadow: 0 0 10px #888; + box-shadow: 0 0 10px #888; + +} + +.ribbon a { + border: 1px solid #faa; + color: #fff; + display: block; + font: bold 81.25% 'Helvetica Neue', Helvetica, Arial, sans-serif; + margin: 1px 0; + padding: 10px 50px; + text-align: center; + text-decoration: none; + text-shadow: 0 0 5px #444; + transition: 0.5s; +} + +.ribbon a:hover { + background: #c11; + color: #fff; +} + + +/* override table width restrictions */ +@media screen and (min-width: 767px) { + + .wy-table-responsive table td, .wy-table-responsive table th { + /* !important prevents the common CSS stylesheets from overriding + this as on RTD they are loaded after this stylesheet */ + white-space: normal !important; + } + + .wy-table-responsive { + overflow: visible !important; + } +} + +@media screen and (max-width: 767px) { + .wy-table-responsive table td { + white-space: nowrap; + } +} + +/* fix width of the screen */ + +.wy-nav-content { + max-width: none; +} diff --git a/docs/_static/favicon.ico b/docs/_static/favicon.ico Binary files differnew file mode 100755 index 0000000000..cb712ebd20 --- /dev/null +++ b/docs/_static/favicon.ico diff --git a/docs/_static/logo_onap_2017.png b/docs/_static/logo_onap_2017.png Binary files differnew file mode 100644 index 0000000000..5d064f431c --- /dev/null +++ b/docs/_static/logo_onap_2017.png diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000000..8f40e8b817 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,15 @@ +from docs_conf.conf import * + +branch = 'latest' +master_doc = 'index' + +linkcheck_ignore = [ + 'http://localhost', +] + +intersphinx_mapping = {} + +html_last_updated_fmt = '%d-%b-%y %H:%M' + +def setup(app): + app.add_stylesheet("css/ribbon_onap.css") diff --git a/docs/conf.yaml b/docs/conf.yaml new file mode 100644 index 0000000000..ab5928131c --- /dev/null +++ b/docs/conf.yaml @@ -0,0 +1,7 @@ +--- +project_cfg: onap +project: onap + +# Change this to ReleaseBranchName to modify the header +default-version: latest +# diff --git a/docs/requirements-docs.txt b/docs/requirements-docs.txt new file mode 100644 index 0000000000..b3188ddd38 --- /dev/null +++ b/docs/requirements-docs.txt @@ -0,0 +1,15 @@ +tox +Sphinx +doc8 +docutils +setuptools +six +sphinx_rtd_theme>=0.4.3 +sphinxcontrib-blockdiag +sphinxcontrib-needs>=0.2.3 +sphinxcontrib-nwdiag +sphinxcontrib-seqdiag +sphinxcontrib-swaggerdoc +sphinxcontrib-plantuml +sphinx_bootstrap_theme +lfdocs-conf diff --git a/docs/tox.ini b/docs/tox.ini new file mode 100644 index 0000000000..edac8c35fc --- /dev/null +++ b/docs/tox.ini @@ -0,0 +1,22 @@ +[tox] +minversion = 1.6 +envlist = docs, +skipsdist = true + +[testenv:docs] +basepython = python3 +deps = -r{toxinidir}/requirements-docs.txt +commands = + sphinx-build -b html -n -d {envtmpdir}/doctrees ./ {toxinidir}/_build/html + echo "Generated docs available in {toxinidir}/_build/html" +whitelist_externals = + echo + git + sh + +[testenv:docs-linkcheck] +basepython = python3 +#deps = -r{toxinidir}/requirements-docs.txt +commands = echo "Link Checking not enforced" +#commands = sphinx-build -b linkcheck -d {envtmpdir}/doctrees ./ {toxinidir}/_build/linkcheck +whitelist_externals = echo diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/OrchestrationTask.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/OrchestrationTask.java new file mode 100644 index 0000000000..53760f1b00 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/OrchestrationTask.java @@ -0,0 +1,143 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * 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. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.db.request.beans; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.hibernate.annotations.DynamicUpdate; +import javax.persistence.*; +import java.io.Serializable; +import java.util.Date; +import java.util.Objects; + +@Entity +@DynamicUpdate +@Table(name = "orchestration_task") +public class OrchestrationTask implements Serializable { + + private static final long serialVersionUID = -9158494554305291596L; + + @Id + @Column(name = "TASK_ID", nullable = false, updatable = false) + private String taskId; + + @Column(name = "REQUEST_ID", nullable = false, updatable = false) + private String requestId; + + @Column(name = "NAME") + private String name; + + @Column(name = "CREATED_TIME") + private Date createdTime; + + @Column(name = "STATUS") + private String status; + + @Column(name = "IS_MANUAL") + private String isManual; + + @Column(name = "PARAMS") + private String params; + + public String getTaskId() { + return taskId; + } + + public void setTaskId(String taskId) { + this.taskId = taskId; + } + + public String getRequestId() { + return requestId; + } + + public void setRequestId(String requestId) { + this.requestId = requestId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Date getCreatedTime() { + return createdTime; + } + + public void setCreatedTime(Date createdTime) { + this.createdTime = createdTime; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getIsManual() { + return isManual; + } + + public void setIsManual(String isManual) { + this.isManual = isManual; + } + + public String getParams() { + return params; + } + + public void setParams(String parameters) { + this.params = parameters; + } + + @Override + public boolean equals(final Object other) { + if (this == other) { + return true; + } + if (!(other instanceof OrchestrationTask)) { + return false; + } + OrchestrationTask castOther = (OrchestrationTask) other; + return Objects.equals(getTaskId(), castOther.getTaskId()); + } + + @Override + public int hashCode() { + return Objects.hash(this.getTaskId()); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("taskId", getTaskId()).toString(); + } + + @PrePersist + protected void onCreate() { + this.createdTime = new Date(); + } + +} + diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java index 7f5907e9bf..161ca2a2fb 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/client/CatalogDbClient.java @@ -764,8 +764,61 @@ public class CatalogDbClient { return this.getSingleResource(cloudSiteClient, getUri(uri + id)); } - public void postCloudSite(CloudSite cloudSite) { - this.postSingleResource(cloudSiteClient, cloudSite); + public CloudSite postCloudSite(CloudSite cloudSite) { + if (cloudSite == null) { + throw new EntityNotFoundException("CloudSite passed as null"); + } + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity<CloudSite> entity = new HttpEntity<>(cloudSite, headers); + CloudSite updatedCloudSite = restTemplate + .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite").build().encode().toString(), + HttpMethod.POST, entity, CloudSite.class) + .getBody(); + return updatedCloudSite; + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId()); + } + throw e; + } + } + + public CloudSite updateCloudSite(CloudSite cloudSite) { + if (cloudSite == null) { + throw new EntityNotFoundException("CloudSite passed as null"); + } + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity<CloudSite> entity = new HttpEntity<>(cloudSite, headers); + CloudSite updatedCloudSite = restTemplate + .exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSite.getId()).build() + .encode().toString(), HttpMethod.PUT, entity, CloudSite.class) + .getBody(); + return updatedCloudSite; + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSite.getId()); + } + throw e; + } + } + + public void deleteCloudSite(String cloudSiteId) { + if (cloudSiteId == null) { + throw new EntityNotFoundException("CloudSiteId passed as null"); + } + try { + HttpHeaders headers = getHttpHeaders(); + HttpEntity<String> entity = new HttpEntity<>(null, headers); + restTemplate.exchange(UriComponentsBuilder.fromUriString(endpoint + "/cloudSite/" + cloudSiteId).build() + .encode().toString(), HttpMethod.DELETE, entity, CloudSite.class).getBody(); + } catch (HttpClientErrorException e) { + if (HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()) { + throw new EntityNotFoundException("Unable to find CloudSite with Cloud Site Id: " + cloudSiteId); + } + throw e; + } } public List<CloudSite> getCloudSites() { |