use of org.onap.so.db.catalog.beans.AllottedResourceCustomization in project so by onap.
the class ToscaResourceInstaller method processAllottedResources.
protected void processAllottedResources(List<IEntityDetails> arEntityDetails, ToscaResourceStructure toscaResourceStruct, Service service) throws ArtifactInstallerException {
List<IEntityDetails> pnfAREntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder(SdcTypes.PNF), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
for (IEntityDetails pnfEntity : pnfAREntityList) {
Metadata metadata = pnfEntity.getMetadata();
String category = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
if (ALLOTTED_RESOURCE.equalsIgnoreCase(category)) {
arEntityDetails.add(pnfEntity);
}
}
if (arEntityDetails != null) {
for (IEntityDetails arEntity : arEntityDetails) {
AllottedResourceCustomization allottedResource = createAllottedResource(arEntity, toscaResourceStruct, service);
String resourceInput = getResourceInput(toscaResourceStruct, allottedResource.getModelCustomizationUUID());
if (!"{}".equals(resourceInput)) {
allottedResource.setResourceInput(resourceInput);
}
if (!service.getAllottedCustomizations().contains(allottedResource)) {
service.getAllottedCustomizations().add(allottedResource);
}
}
}
}
use of org.onap.so.db.catalog.beans.AllottedResourceCustomization in project so by onap.
the class ToscaResourceInstaller method createAllottedResourceCustomization.
protected AllottedResourceCustomization createAllottedResourceCustomization(IEntityDetails arEntity, ToscaResourceStructure toscaResourceStructure) {
AllottedResourceCustomization allottedResourceCustomization = new AllottedResourceCustomization();
allottedResourceCustomization.setModelCustomizationUUID(testNull(arEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
allottedResourceCustomization.setModelInstanceName(arEntity.getName());
allottedResourceCustomization.setNfFunction(getLeafPropertyValue(arEntity, SdcPropertyNames.PROPERTY_NAME_NFFUNCTION));
allottedResourceCustomization.setNfNamingCode(getLeafPropertyValue(arEntity, "nf_naming_code"));
allottedResourceCustomization.setNfRole(getLeafPropertyValue(arEntity, SdcPropertyNames.PROPERTY_NAME_NFROLE));
allottedResourceCustomization.setNfType(getLeafPropertyValue(arEntity, SdcPropertyNames.PROPERTY_NAME_NFTYPE));
EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.VFC).build();
TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.VF).customizationUUID(allottedResourceCustomization.getModelCustomizationUUID()).build();
List<IEntityDetails> vfcEntities = toscaResourceStructure.getSdcCsarHelper().getEntity(entityQuery, topologyTemplateQuery, false);
if (vfcEntities != null) {
for (IEntityDetails vfcEntity : vfcEntities) {
allottedResourceCustomization.setProvidingServiceModelUUID(getLeafPropertyValue(vfcEntity, "providing_service_uuid"));
allottedResourceCustomization.setProvidingServiceModelInvariantUUID(getLeafPropertyValue(vfcEntity, "providing_service_invariant_uuid"));
allottedResourceCustomization.setProvidingServiceModelName(getLeafPropertyValue(vfcEntity, "providing_service_name"));
}
}
List<CapabilityAssignment> capAssignmentList = arEntity.getCapabilities();
if (capAssignmentList != null) {
for (CapabilityAssignment arCapability : capAssignmentList) {
if (arCapability != null) {
String capabilityName = arCapability.getName();
if (capabilityName.equals(SCALABLE)) {
allottedResourceCustomization.setMinInstances(Integer.getInteger(getCapabilityLeafPropertyValue(arCapability, SdcPropertyNames.PROPERTY_NAME_MININSTANCES)));
allottedResourceCustomization.setMinInstances(Integer.getInteger(getCapabilityLeafPropertyValue(arCapability, SdcPropertyNames.PROPERTY_NAME_MAXINSTANCES)));
}
}
}
}
return allottedResourceCustomization;
}
use of org.onap.so.db.catalog.beans.AllottedResourceCustomization 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.AllottedResourceCustomization in project so by onap.
the class QueryAllottedResourceCustomization method JSON2.
@Override
public String JSON2(boolean isArray, boolean isEmbed) {
StringBuilder sb = new StringBuilder();
if (!isEmbed && isArray)
sb.append("{ ");
if (isArray)
sb.append("\"serviceAllottedResources\": [");
Map<String, String> valueMap = new HashMap<>();
String sep = "";
boolean first = true;
if (this.allottedResourceCustomization != null) {
for (AllottedResourceCustomization o : allottedResourceCustomization) {
if (first)
sb.append("\n");
first = false;
boolean arNull = o.getAllottedResource() == null;
put(valueMap, "MODEL_NAME", arNull ? null : o.getAllottedResource().getModelName());
put(valueMap, "MODEL_UUID", arNull ? null : o.getAllottedResource().getModelUUID());
put(valueMap, "MODEL_INVARIANT_ID", arNull ? null : o.getAllottedResource().getModelInvariantUUID());
put(valueMap, "MODEL_VERSION", arNull ? null : o.getAllottedResource().getModelVersion());
put(valueMap, "MODEL_CUSTOMIZATION_UUID", o.getModelCustomizationUUID());
put(valueMap, "MODEL_INSTANCE_NAME", o.getModelInstanceName());
put(valueMap, "TOSCA_NODE_TYPE", arNull ? null : o.getAllottedResource().getToscaNodeType());
put(valueMap, "ALLOTTED_RESOURCE_TYPE", arNull ? null : o.getAllottedResource().getSubcategory());
put(valueMap, "ALLOTTED_RESOURCE_ROLE", o.getTargetNetworkRole() != null ? o.getTargetNetworkRole() : o.getNfRole());
put(valueMap, "NF_TYPE", o.getNfType());
put(valueMap, "NF_ROLE", o.getNfRole());
put(valueMap, "NF_FUNCTION", o.getNfFunction());
put(valueMap, "NF_NAMING_CODE", o.getNfNamingCode());
put(valueMap, "PROVIDING_SERVICE_MODEL_INVARIANT_UUID", o.getProvidingServiceModelInvariantUUID());
put(valueMap, "PROVIDING_SERVICE_MODEL_UUID", o.getProvidingServiceModelUUID());
put(valueMap, "PROVIDING_SERVICE_MODEL_NAME", o.getProvidingServiceModelName());
if (isJSONValid(o.getResourceInput())) {
put(valueMap, "RESOURCE_INPUT", o.getResourceInput());
}
sb.append(sep).append(this.setTemplate(TEMPLATE, valueMap));
sep = ",\n";
}
}
if (!first)
sb.append("\n");
if (isArray)
sb.append("]");
if (!isEmbed && isArray)
sb.append("}");
return sb.toString();
}
use of org.onap.so.db.catalog.beans.AllottedResourceCustomization in project so by onap.
the class QueryAllottedResourceCustomization method toString.
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
boolean first = true;
int i = 1;
for (AllottedResourceCustomization o : allottedResourceCustomization) {
sb.append(i).append("\t");
if (!first)
sb.append("\n");
first = false;
sb.append(o);
}
return sb.toString();
}
Aggregations