Search in sources :

Example 1 with AllottedResource

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

the class ToscaResourceInstaller method createAR.

protected AllottedResource createAR(IEntityDetails arEntity) {
    AllottedResource allottedResource = new AllottedResource();
    allottedResource.setModelUUID(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID)));
    allottedResource.setModelInvariantUUID(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID)));
    allottedResource.setModelName(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_NAME)));
    allottedResource.setModelVersion(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_VERSION)));
    allottedResource.setToscaNodeType(testNull(arEntity.getToscaType()));
    allottedResource.setSubcategory(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_SUBCATEGORY)));
    allottedResource.setDescription(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
    return allottedResource;
}
Also used : AllottedResource(org.onap.so.db.catalog.beans.AllottedResource)

Example 2 with AllottedResource

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

the class ASDCRestInterfaceTest method testAllottedResourceService.

@Test
@Transactional
public void testAllottedResourceService() 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())));
    ObjectMapper mapper = new ObjectMapper();
    NotificationDataImpl request = mapper.readValue(new File("src/test/resources/resource-examples/allottedresource/notif-portm.json"), NotificationDataImpl.class);
    headers.add("resource-location", "src/test/resources/resource-examples/allottedresource/");
    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());
    AllottedResource expectedService = new AllottedResource();
    expectedService.setDescription("rege1802pnf");
    expectedService.setModelInvariantUUID("b8f83c3f-077c-4e2c-b489-c66382060436");
    expectedService.setModelName("rege1802pnf");
    expectedService.setModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d");
    expectedService.setModelVersion("1.0");
    expectedService.setSubcategory("Contrail Route");
    expectedService.setToscaNodeType("org.openecomp.resource.pnf.Rege1802pnf");
    Set<AllottedResourceCustomization> arCustomizationSet = new HashSet<AllottedResourceCustomization>();
    AllottedResourceCustomization arCustomization = new AllottedResourceCustomization();
    arCustomization.setModelCustomizationUUID("f62bb612-c5d4-4406-865c-0abec30631ba");
    arCustomization.setModelInstanceName("rege1802pnf 0");
    arCustomizationSet.add(arCustomization);
    arCustomization.setAllottedResource(expectedService);
    expectedService.setAllotedResourceCustomization(arCustomizationSet);
    AllottedResource actualResponse = allottedRepo.findResourceByModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d");
    if (actualResponse == null)
        throw new Exception("No Allotted Resource Written to database");
    assertThat(actualResponse, sameBeanAs(expectedService).ignoring("0x1.created").ignoring("0x1.allotedResourceCustomization.created"));
}
Also used : NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) HttpEntity(org.springframework.http.HttpEntity) File(java.io.File) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization) HashSet(java.util.HashSet) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 3 with AllottedResource

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

the class CatalogDbAdapterRest method resourceRecipe.

/**
 * Get the resource recipe info from catalog <br>
 *
 * @param rmUuid resource model uuid
 * @return the recipe information of the resource.
 * @since ONAP Beijing Release
 */
@GET
@Path("resourceRecipe")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response resourceRecipe(@QueryParam("resourceModelUuid") String rmUuid, @QueryParam("action") String action) {
    int respStatus = HttpStatus.SC_OK;
    String entity = "";
    try {
        if (rmUuid != null && !"".equals(rmUuid)) {
            logger.debug("Query recipe by resource model uuid: {}", rmUuid);
            // check vnf and network and ar, the resource could be any resource.
            Recipe recipe = null;
            VnfResource vnf = vnfResourceRepo.findResourceByModelUUID(rmUuid);
            if (vnf != null) {
                recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(vnf.getModelName(), action, vnf.getModelVersion());
                // for network service fetch the default recipe
                if (recipe == null && vnf.getSubCategory().equalsIgnoreCase(NETWORK_SERVICE)) {
                    recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndAction("NS_DEFAULT", action);
                }
            }
            if (null == recipe) {
                NetworkResource nResource = networkResourceRepo.findResourceByModelUUID(rmUuid);
                if (nResource != null) {
                    recipe = networkRecipeRepo.findFirstByModelNameAndActionAndVersionStr(nResource.getModelName(), action, nResource.getModelVersion());
                    // for network fetch the default recipe
                    if (recipe == null) {
                        recipe = networkRecipeRepo.findFirstByModelNameAndAction("SDNC_DEFAULT", action);
                    }
                }
            }
            if (null == recipe) {
                AllottedResource arResource = arResourceRepo.findResourceByModelUUID(rmUuid);
                if (arResource != null) {
                    recipe = arRecipeRepo.findByModelNameAndActionAndVersion(arResource.getModelName(), action, arResource.getModelVersion());
                }
            }
            if (null == recipe) {
                InstanceGroup grpResource = instanceGroupRepository.findByModelUUID(rmUuid);
                if (grpResource != null) {
                    recipe = vnfRecipeRepo.findFirstVnfRecipeByNfRoleAndActionAndVersionStr(grpResource.getModelName(), action, grpResource.getModelVersion());
                }
            }
            if (recipe != null) {
                QueryResourceRecipe resourceRecipe = new QueryResourceRecipe(recipe);
                entity = resourceRecipe.JSON2(false, false);
            } 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 recipe by resource 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 : NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) VnfResource(org.onap.so.db.catalog.beans.VnfResource) QueryResourceRecipe(org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe) VnfRecipe(org.onap.so.db.catalog.beans.VnfRecipe) Recipe(org.onap.so.db.catalog.beans.Recipe) QueryResourceRecipe(org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) CatalogQueryException(org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException) InstanceGroup(org.onap.so.db.catalog.beans.InstanceGroup) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 4 with AllottedResource

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

the class ToscaResourceInstaller method createAllottedResource.

protected AllottedResourceCustomization createAllottedResource(IEntityDetails arEntity, ToscaResourceStructure toscaResourceStructure, Service service) {
    AllottedResourceCustomization allottedResourceCustomization = allottedCustomizationRepo.findOneByModelCustomizationUUID(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID));
    if (allottedResourceCustomization == null) {
        AllottedResource allottedResource = findExistingAllottedResource(service, arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
        if (allottedResource == null)
            allottedResource = createAR(arEntity);
        toscaResourceStructure.setAllottedResource(allottedResource);
        allottedResourceCustomization = createAllottedResourceCustomization(arEntity, toscaResourceStructure);
        allottedResourceCustomization.setAllottedResource(allottedResource);
        allottedResource.getAllotedResourceCustomization().add(allottedResourceCustomization);
    }
    return allottedResourceCustomization;
}
Also used : AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization)

Example 5 with AllottedResource

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

the class ToscaResourceStructureTest method toscaResourceStructureBeanTest.

@Test
public void toscaResourceStructureBeanTest() {
    artifactInfo = mock(ArtifactInfoImpl.class);
    sdcCsarHelper = mock(SdcCsarHelperImpl.class);
    toscaResourceStructure = new ToscaResourceStructure();
    toscaResourceStructure.setHeatTemplateUUID("heatTemplateUUID");
    toscaResourceStructure.setAllottedList(new ArrayList<NodeTemplate>());
    toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
    toscaResourceStructure.setServiceMetadata(new Metadata(new HashMap<>()));
    toscaResourceStructure.setCatalogService(new Service());
    toscaResourceStructure.setNetworkTypes(new ArrayList<>());
    toscaResourceStructure.setVfTypes(new ArrayList<>());
    toscaResourceStructure.setCatalogResourceCustomization(new AllottedResourceCustomization());
    toscaResourceStructure.setCatalogNetworkResourceCustomization(new NetworkResourceCustomization());
    toscaResourceStructure.setCatalogNetworkResource(new NetworkResource());
    toscaResourceStructure.setCatalogVfModule(new VfModule());
    toscaResourceStructure.setVnfResourceCustomization(new VnfResourceCustomization());
    toscaResourceStructure.setVfModuleCustomization(new VfModuleCustomization());
    toscaResourceStructure.setAllottedResource(new AllottedResource());
    toscaResourceStructure.setAllottedResourceCustomization(new AllottedResourceCustomization());
    toscaResourceStructure.setCatalogTempNetworkHeatTemplateLookup(new TempNetworkHeatTemplateLookup());
    toscaResourceStructure.setHeatFilesUUID("heatFilesUUID");
    toscaResourceStructure.setToscaArtifact(artifactInfo);
    toscaResourceStructure.setToscaCsar(new ToscaCsar());
    toscaResourceStructure.setVolHeatTemplateUUID("volHeatTemplateUUID");
    toscaResourceStructure.setEnvHeatTemplateUUID("envHeatTemplateUUID");
    toscaResourceStructure.setServiceVersion("serviceVersion");
    toscaResourceStructure.setWorkloadPerformance("workloadPerformance");
    toscaResourceStructure.setVfModule(new VfModule());
    toscaResourceStructure.setTempNetworkHeatTemplateLookup(new TempNetworkHeatTemplateLookup());
    toscaResourceStructure.setSuccessfulDeployment();
    assertEquals("heatTemplateUUID", toscaResourceStructure.getHeatTemplateUUID());
    assertThat(toscaResourceStructure.getAllottedList(), sameBeanAs(new ArrayList<NodeTemplate>()));
    assertEquals(sdcCsarHelper, toscaResourceStructure.getSdcCsarHelper());
    assertThat(toscaResourceStructure.getServiceMetadata(), sameBeanAs(new Metadata(new HashMap<>())));
    assertThat(toscaResourceStructure.getCatalogService(), sameBeanAs(new Service()));
    assertThat(toscaResourceStructure.getNetworkTypes(), sameBeanAs(new ArrayList<>()));
    assertThat(toscaResourceStructure.getVfTypes(), sameBeanAs(new ArrayList<>()));
    assertThat(toscaResourceStructure.getCatalogResourceCustomization(), sameBeanAs(new AllottedResourceCustomization()));
    assertThat(toscaResourceStructure.getCatalogNetworkResourceCustomization(), sameBeanAs(new NetworkResourceCustomization()));
    assertThat(toscaResourceStructure.getCatalogNetworkResource(), sameBeanAs(new NetworkResource()));
    assertThat(toscaResourceStructure.getCatalogVfModule(), sameBeanAs(new VfModule()));
    assertThat(toscaResourceStructure.getVnfResourceCustomization(), sameBeanAs(new VnfResourceCustomization()));
    assertThat(toscaResourceStructure.getVfModuleCustomization(), sameBeanAs(new VfModuleCustomization()));
    assertThat(toscaResourceStructure.getAllottedResource(), sameBeanAs(new AllottedResource()));
    assertThat(toscaResourceStructure.getAllottedResourceCustomization(), sameBeanAs(new AllottedResourceCustomization()));
    assertThat(toscaResourceStructure.getCatalogTempNetworkHeatTemplateLookup(), sameBeanAs(new TempNetworkHeatTemplateLookup()));
    assertEquals("heatFilesUUID", toscaResourceStructure.getHeatFilesUUID());
    assertEquals(artifactInfo, toscaResourceStructure.getToscaArtifact());
    assertThat(toscaResourceStructure.getToscaCsar(), sameBeanAs(new ToscaCsar()));
    assertEquals("volHeatTemplateUUID", toscaResourceStructure.getVolHeatTemplateUUID());
    assertEquals("envHeatTemplateUUID", toscaResourceStructure.getEnvHeatTemplateUUID());
    assertEquals("serviceVersion", toscaResourceStructure.getServiceVersion());
    assertEquals("workloadPerformance", toscaResourceStructure.getWorkloadPerformance());
    assertThat(toscaResourceStructure.getVfModule(), sameBeanAs(new VfModule()));
    assertThat(toscaResourceStructure.getTempNetworkHeatTemplateLookup(), sameBeanAs(new TempNetworkHeatTemplateLookup()));
    assertEquals(true, toscaResourceStructure.isDeployedSuccessfully());
}
Also used : ArtifactInfoImpl(org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl) HashMap(java.util.HashMap) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) ArrayList(java.util.ArrayList) Service(org.onap.so.db.catalog.beans.Service) VfModule(org.onap.so.db.catalog.beans.VfModule) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) NodeTemplate(org.onap.sdc.toscaparser.api.NodeTemplate) TempNetworkHeatTemplateLookup(org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup) SdcCsarHelperImpl(org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) VfModuleCustomization(org.onap.so.db.catalog.beans.VfModuleCustomization) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) Test(org.junit.Test)

Aggregations

AllottedResource (org.onap.so.db.catalog.beans.AllottedResource)5 AllottedResourceCustomization (org.onap.so.db.catalog.beans.AllottedResourceCustomization)3 Test (org.junit.Test)2 NetworkResource (org.onap.so.db.catalog.beans.NetworkResource)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Transactional (javax.transaction.Transactional)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 SdcCsarHelperImpl (org.onap.sdc.tosca.parser.impl.SdcCsarHelperImpl)1 NodeTemplate (org.onap.sdc.toscaparser.api.NodeTemplate)1 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)1 CatalogQueryException (org.onap.so.adapters.catalogdb.catalogrest.CatalogQueryException)1 QueryResourceRecipe (org.onap.so.adapters.catalogdb.catalogrest.QueryResourceRecipe)1 BaseTest (org.onap.so.asdc.BaseTest)1 ArtifactInfoImpl (org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl)1