Search in sources :

Example 1 with ToscaCsar

use of org.onap.so.db.catalog.beans.ToscaCsar in project so by onap.

the class ASDCRestInterfaceTest method test_Vcpe_Infra_Distribution.

@Test
public void test_Vcpe_Infra_Distribution() throws Exception {
    wireMockServer.stubFor(post(urlPathMatching("/aai/.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
    String resourceLocation = "src/test/resources/resource-examples/vcpe-infra/";
    ObjectMapper mapper = new ObjectMapper();
    NotificationDataImpl request = mapper.readValue(new File(resourceLocation + "demovcpeinfra-notification.json"), NotificationDataImpl.class);
    headers.add("resource-location", resourceLocation);
    HttpEntity<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
    ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), HttpMethod.POST, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    Optional<ToscaCsar> toscaCsar = toscaCsarRepo.findById("144606d8-a505-4ba0-90a9-6d1c6219fc6b");
    assertTrue(toscaCsar.isPresent());
    assertEquals("service-Demovcpeinfra-csar.csar", toscaCsar.get().getName());
    Optional<Service> service = serviceRepo.findById("8a77cbbb-9850-40bb-a42f-7aec8e3e6ab7");
    assertTrue(service.isPresent());
    assertEquals("demoVCPEInfra", service.get().getModelName());
    Optional<NetworkResource> networkResource = networkRepo.findById("89789b26-a46b-4cee-aed0-d46e21f93a5e");
    assertTrue(networkResource.isPresent());
    assertEquals("Generic NeutronNet", networkResource.get().getModelName());
    List<VnfResourceCustomization> vnfCustomizationResources = vnfCustRepo.findByModelCustomizationUUID("01564fe7-0541-4d92-badc-464cc35f83ba");
    for (VnfResourceCustomization vnfResourceCustomization : vnfCustomizationResources) {
        assertTrue(vnfResourceCustomization.getVfModuleCustomizations().stream().anyMatch(vfModuleCust -> "354b1e83-47db-4af1-8af4-9c14b03b482d".equals(vfModuleCust.getModelCustomizationUUID())));
    }
}
Also used : Matchers.sameBeanAs(com.shazam.shazamcrest.matcher.Matchers.sameBeanAs) ArgumentMatchers(org.mockito.ArgumentMatchers) Autowired(org.springframework.beans.factory.annotation.Autowired) DistributionClientEmulator(org.onap.so.asdc.client.test.emulators.DistributionClientEmulator) Service(org.onap.so.db.catalog.beans.Service) Spy(org.mockito.Spy) NetworkResourceRepository(org.onap.so.db.catalog.data.repository.NetworkResourceRepository) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) ConfigurationResourceCustomization(org.onap.so.db.catalog.beans.ConfigurationResourceCustomization) Transactional(javax.transaction.Transactional) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) HttpHeaders(org.springframework.http.HttpHeaders) Set(java.util.Set) List(java.util.List) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) HttpEntity(org.springframework.http.HttpEntity) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) VnfCustomizationRepository(org.onap.so.db.catalog.data.repository.VnfCustomizationRepository) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) HashSet(java.util.HashSet) AllottedResourceCustomizationRepository(org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository) WireMock.urlPathMatching(com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching) AllottedResourceRepository(org.onap.so.db.catalog.data.repository.AllottedResourceRepository) VnfResource(org.onap.so.db.catalog.beans.VnfResource) Before(org.junit.Before) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) WorkflowRepository(org.onap.so.db.catalog.data.repository.WorkflowRepository) Files(java.nio.file.Files) BaseTest(org.onap.so.asdc.BaseTest) Assert.assertNotNull(org.junit.Assert.assertNotNull) MatcherAssert.assertThat(com.shazam.shazamcrest.MatcherAssert.assertThat) VnfResourceRepository(org.onap.so.db.catalog.data.repository.VnfResourceRepository) HttpMethod(org.springframework.http.HttpMethod) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) File(java.io.File) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) Workflow(org.onap.so.db.catalog.beans.Workflow) LocalServerPort(org.springframework.boot.web.server.LocalServerPort) Mockito(org.mockito.Mockito) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) Paths(java.nio.file.Paths) ServiceRepository(org.onap.so.db.catalog.data.repository.ServiceRepository) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization) ResponseEntity(org.springframework.http.ResponseEntity) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) ToscaCsarRepository(org.onap.so.db.catalog.data.repository.ToscaCsarRepository) HttpEntity(org.springframework.http.HttpEntity) Service(org.onap.so.db.catalog.beans.Service) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) File(java.io.File) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 2 with ToscaCsar

use of org.onap.so.db.catalog.beans.ToscaCsar in project so by onap.

the class ASDCControllerITTest method treatNotification_ValidPnfResource_ExpectedOutput.

/**
 * Test with service-pnfservice.csar.
 */
@Test
public void treatNotification_ValidPnfResource_ExpectedOutput() {
    /**
     * service UUID/invariantUUID from global metadata in service-PnfServiceTestCds-template.yml.
     */
    String serviceUuid = "77cf276e-905c-43f6-8d54-dda474be2f2e";
    String serviceInvariantUuid = "913e6776-4bc3-49b9-b399-b5bb4690f0c7";
    initMockAaiServer(serviceUuid, serviceInvariantUuid);
    NotificationDataImpl notificationData = new NotificationDataImpl();
    notificationData.setServiceUUID(serviceUuid);
    notificationData.setDistributionID(distributionId);
    notificationData.setServiceInvariantUUID(serviceInvariantUuid);
    notificationData.setServiceVersion("1.0");
    ResourceInfoImpl resourceInfo = constructPnfResourceInfo();
    List<ResourceInfoImpl> resourceInfoList = new ArrayList<>();
    resourceInfoList.add(resourceInfo);
    notificationData.setResources(resourceInfoList);
    ArtifactInfoImpl artifactInfo = constructPnfServiceArtifact();
    List<ArtifactInfoImpl> artifactInfoList = new ArrayList<>();
    artifactInfoList.add(artifactInfo);
    notificationData.setServiceArtifacts(artifactInfoList);
    try {
        asdcController.treatNotification(notificationData);
        logger.info("Checking the database for PNF ingestion");
        /**
         * Check the tosca csar entity, it should be the same as provided from NotficationData.
         */
        ToscaCsar toscaCsar = toscaCsarRepository.findById(artifactUuid).orElseThrow(() -> new EntityNotFoundException("Tosca csar: " + artifactUuid + " not found"));
        assertEquals("tosca csar UUID", artifactUuid, toscaCsar.getArtifactUUID());
        assertEquals("tosca csar name", "service-pnfservice.csar", toscaCsar.getName());
        assertEquals("tosca csar version", "1.0", toscaCsar.getVersion());
        assertNull("tosca csar descrption", toscaCsar.getDescription());
        assertEquals("tosca csar checksum", "MANUAL_RECORD", toscaCsar.getArtifactChecksum());
        assertEquals("toscar csar URL", "/download/service-pnfservice.csar", toscaCsar.getUrl());
        /**
         * Check the service entity, it should be the same as global metadata information in
         * service-Testservice140-template.yml inside csar.
         */
        Service service = serviceRepository.findById(serviceUuid).orElseThrow(() -> new EntityNotFoundException("Service: " + serviceUuid + " not found"));
        assertEquals("model UUID", serviceUuid, service.getModelUUID());
        assertEquals("model name", "PNF Service Test CDS", service.getModelName());
        assertEquals("model invariantUUID", serviceInvariantUuid, service.getModelInvariantUUID());
        assertEquals("model version", "1.0", service.getModelVersion());
        assertEquals("description", "123123", service.getDescription().trim());
        assertEquals("tosca csar artifact UUID", artifactUuid, service.getCsar().getArtifactUUID());
        assertEquals("service type", "", service.getServiceType());
        assertEquals("service role", "", service.getServiceRole());
        assertEquals("environment context", "General_Revenue-Bearing", service.getEnvironmentContext());
        assertEquals("service category", "Network L1-3", service.getCategory());
        assertNull("workload context", service.getWorkloadContext());
        assertEquals("resource order", "PNF CDS Test", service.getResourceOrder());
        assertEquals("CDS blueprint name", "Blueprint140", service.getBlueprintName());
        assertEquals("CDS blueprint version", "v1.4.0", service.getBlueprintVersion());
        assertEquals("controller actor", "SO-REF-DATA", service.getControllerActor());
        /**
         * Check PNF resource, it should be the same as metadata in the topology template in
         * service-PnfServiceTestCds-template.yml OR global metadata in the resource-PnfServiceTestCds-template.yml
         */
        String pnfResourceKey = "aa5d0562-80e7-43e9-af74-3085e57ab09f";
        PnfResource pnfResource = pnfResourceRepository.findById(pnfResourceKey).orElseThrow(() -> new EntityNotFoundException("PNF resource:" + pnfResourceKey + " not found"));
        assertNull("orchestration mode", pnfResource.getOrchestrationMode());
        assertEquals("Description", "123123", pnfResource.getDescription().trim());
        assertEquals("model UUID", pnfResourceKey, pnfResource.getModelUUID());
        assertEquals("model invariant UUID", "17d9d183-cee5-4a46-b5c4-6d5203f7d2e8", pnfResource.getModelInvariantUUID());
        assertEquals("model version", "1.0", pnfResource.getModelVersion());
        assertEquals("model name", "PNF CDS Test", pnfResource.getModelName());
        assertEquals("tosca node type", "org.openecomp.resource.pnf.PnfCdsTest", pnfResource.getToscaNodeType());
        assertEquals("resource category", "Application L4+", pnfResource.getCategory());
        assertEquals("resource sub category", "Firewall", pnfResource.getSubCategory());
        /**
         * Check PNF resource customization, it should be the same as metadata in the topology template in
         * service-PnfServiceTestCds-template.yml OR global metadata in the resource-PnfServiceTestCds-template.yml
         */
        String pnfCustomizationKey = "9f01263a-eaf7-4d98-a37b-3785f751903e";
        PnfResourceCustomization pnfCustomization = pnfCustomizationRepository.findById(pnfCustomizationKey).orElseThrow(() -> new EntityNotFoundException("PNF resource customization: " + pnfCustomizationKey + " not found"));
        assertEquals("model customizationUUID", pnfCustomizationKey, pnfCustomization.getModelCustomizationUUID());
        assertEquals("model instance name", "PNF CDS Test 0", pnfCustomization.getModelInstanceName());
        assertEquals("NF type", "", pnfCustomization.getNfType());
        assertEquals("NF Role", "nf", pnfCustomization.getNfRole());
        assertEquals("NF function", "nf", pnfCustomization.getNfFunction());
        assertEquals("NF naming code", "", pnfCustomization.getNfNamingCode());
        assertEquals("PNF resource model UUID", pnfResourceKey, pnfCustomization.getPnfResources().getModelUUID());
        assertEquals("Multi stage design", "", pnfCustomization.getMultiStageDesign());
        assertNull("resource input", pnfCustomization.getResourceInput());
        assertEquals("cds blueprint name(sdnc_model_name property)", "Blueprint140", pnfCustomization.getBlueprintName());
        assertEquals("cds blueprint version(sdnc_model_version property)", "v1.4.0", pnfCustomization.getBlueprintVersion());
        assertTrue("skip post instantiation configuration", pnfCustomization.getSkipPostInstConf());
        assertEquals("controller actor", "SO-REF-DATA", pnfCustomization.getControllerActor());
        /**
         * Check the pnf resource customization with service mapping
         */
        List<PnfResourceCustomization> pnfCustList = service.getPnfCustomizations();
        assertEquals("PNF resource customization entity", 1, pnfCustList.size());
        assertEquals(pnfCustomizationKey, pnfCustList.get(0).getModelCustomizationUUID());
        /**
         * Check the watchdog for component distribution status
         */
        List<WatchdogComponentDistributionStatus> distributionList = watchdogCDStatusRepository.findByDistributionId(this.distributionId);
        assertNotNull(distributionList);
        assertEquals(1, distributionList.size());
        WatchdogComponentDistributionStatus distributionStatus = distributionList.get(0);
        assertEquals("COMPONENT_DONE_OK", distributionStatus.getComponentDistributionStatus());
        assertEquals("SO", distributionStatus.getComponentName());
    } catch (Exception e) {
        logger.info(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : PnfResourceCustomization(org.onap.so.db.catalog.beans.PnfResourceCustomization) ArtifactInfoImpl(org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl) WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) ResourceInfoImpl(org.onap.so.asdc.client.test.emulators.ResourceInfoImpl) PnfResource(org.onap.so.db.catalog.beans.PnfResource) ArrayList(java.util.ArrayList) Service(org.onap.so.db.catalog.beans.Service) EntityNotFoundException(javax.persistence.EntityNotFoundException) EntityNotFoundException(javax.persistence.EntityNotFoundException) ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 3 with ToscaCsar

use of org.onap.so.db.catalog.beans.ToscaCsar in project so by onap.

the class ToscaResourceInstaller method isCsarAlreadyDeployed.

public boolean isCsarAlreadyDeployed(ToscaResourceStructure toscaResourceStructure) throws ArtifactInstallerException {
    boolean deployed = false;
    if (toscaResourceStructure == null) {
        return deployed;
    }
    IArtifactInfo inputToscaCsar = toscaResourceStructure.getToscaArtifact();
    String checkSum = inputToscaCsar.getArtifactChecksum();
    String artifactUuid = inputToscaCsar.getArtifactUUID();
    Optional<ToscaCsar> toscaCsarObj = toscaCsarRepo.findById(artifactUuid);
    if (toscaCsarObj.isPresent()) {
        ToscaCsar toscaCsar = toscaCsarObj.get();
        if (!toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
            String errorMessage = String.format("Csar with UUID: %s already exists.Their checksums don't match", artifactUuid);
            throw new ArtifactInstallerException(errorMessage);
        } else if (toscaCsar.getArtifactChecksum().equalsIgnoreCase(checkSum)) {
            deployed = true;
        }
    }
    return deployed;
}
Also used : IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar)

Example 4 with ToscaCsar

use of org.onap.so.db.catalog.beans.ToscaCsar in project so by onap.

the class CatalogDbAdapterRest method serviceToscaCsar.

/**
 * Get the tosca csar info from catalog <br>
 *
 * @param smUuid service model uuid
 * @return the tosca csar information of the serivce.
 * @since ONAP Beijing Release
 */
@GET
@Path("serviceToscaCsar")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response serviceToscaCsar(@QueryParam("serviceModelUuid") String smUuid) {
    int respStatus = HttpStatus.SC_OK;
    String entity = "";
    try {
        if (smUuid != null && !"".equals(smUuid)) {
            logger.debug("Query Csar by service model uuid: {}", smUuid);
            Service service = serviceRepo.findFirstOneByModelUUIDOrderByModelVersionDesc(smUuid);
            if (service != null) {
                ToscaCsar toscaCsar = service.getCsar();
                if (toscaCsar != null) {
                    QueryServiceCsar serviceCsar = new QueryServiceCsar(toscaCsar);
                    entity = serviceCsar.JSON2(false, false);
                } else {
                    respStatus = HttpStatus.SC_NOT_FOUND;
                }
            } else {
                respStatus = HttpStatus.SC_NOT_FOUND;
            }
        } else {
            throw (new Exception("Incoming parameter is null or blank"));
        }
        return Response.status(respStatus).entity(entity).header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).build();
    } catch (Exception e) {
        logger.error("Exception during query csar by service model uuid: ", e);
        CatalogQueryException excResp = new CatalogQueryException(e.getMessage(), CatalogQueryExceptionCategory.INTERNAL, Boolean.FALSE, null);
        return Response.status(HttpStatus.SC_INTERNAL_SERVER_ERROR).entity(new GenericEntity<CatalogQueryException>(excResp) {
        }).build();
    }
}
Also used : Service(org.onap.so.db.catalog.beans.Service) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) QueryServiceCsar(org.onap.so.adapters.catalogdb.catalogrest.QueryServiceCsar) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with ToscaCsar

use of org.onap.so.db.catalog.beans.ToscaCsar in project so by onap.

the class QueryServiceCsarTest method createToscaCsar.

private ToscaCsar createToscaCsar() {
    ToscaCsar toscaCsar = new ToscaCsar();
    toscaCsar.setArtifactUUID(TOSCA_ARTIFACT_UUID);
    toscaCsar.setName(TOSCA_NAME);
    toscaCsar.setVersion(TOSCA_VERSION);
    toscaCsar.setArtifactChecksum(TOSCA_ARTIFACT_CHECKSUM);
    toscaCsar.setUrl(TOSCA_URL);
    toscaCsar.setDescription(TOSCA_DESCRIPTION);
    return toscaCsar;
}
Also used : ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar)

Aggregations

ToscaCsar (org.onap.so.db.catalog.beans.ToscaCsar)10 Service (org.onap.so.db.catalog.beans.Service)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 BaseTest (org.onap.so.asdc.BaseTest)5 NotificationDataImpl (org.onap.so.asdc.client.test.emulators.NotificationDataImpl)5 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 ASDCControllerException (org.onap.so.asdc.client.exceptions.ASDCControllerException)4 ArtifactInfoImpl (org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl)4 ResourceInfoImpl (org.onap.so.asdc.client.test.emulators.ResourceInfoImpl)3 WatchdogComponentDistributionStatus (org.onap.so.db.request.beans.WatchdogComponentDistributionStatus)3 PnfResourceCustomization (org.onap.so.db.catalog.beans.PnfResourceCustomization)2 VnfResourceCustomization (org.onap.so.db.catalog.beans.VnfResourceCustomization)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.post (com.github.tomakehurst.wiremock.client.WireMock.post)1 WireMock.urlPathEqualTo (com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo)1 WireMock.urlPathMatching (com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching)1 MatcherAssert.assertThat (com.shazam.shazamcrest.MatcherAssert.assertThat)1 Matchers.sameBeanAs (com.shazam.shazamcrest.matcher.Matchers.sameBeanAs)1