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;
}
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"));
}
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();
}
}
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;
}
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());
}
Aggregations