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