use of org.onap.so.db.catalog.beans.InstanceGroup in project so by onap.
the class ServiceEBBLoaderTest method traverseCatalogDbServiceMultipleNetworkTest.
@Test
public void traverseCatalogDbServiceMultipleNetworkTest() throws IOException, VrfBondingServiceException {
execution.setVariable("testProcessKey", "testProcessKeyValue");
Service service = new Service();
List<NetworkResourceCustomization> networkCustomizations = new ArrayList<>();
NetworkResourceCustomization networkCust = new NetworkResourceCustomization();
networkCust.setModelCustomizationUUID("123");
networkCustomizations.add(networkCust);
service.setNetworkCustomizations(networkCustomizations);
NetworkCollectionResourceCustomization collectionResourceCustomization = new NetworkCollectionResourceCustomization();
collectionResourceCustomization.setModelCustomizationUUID("123");
CollectionResource collectionResource = new CollectionResource();
collectionResource.setToscaNodeType("NetworkCollection");
InstanceGroup instanceGroup = new InstanceGroup();
List<CollectionResourceInstanceGroupCustomization> collectionInstanceGroupCustomizations = new ArrayList<>();
CollectionResourceInstanceGroupCustomization collectionInstanceGroupCustomization = new CollectionResourceInstanceGroupCustomization();
collectionInstanceGroupCustomization.setSubInterfaceNetworkQuantity(3);
collectionInstanceGroupCustomizations.add(collectionInstanceGroupCustomization);
instanceGroup.setCollectionInstanceGroupCustomizations(collectionInstanceGroupCustomizations);
collectionResource.setInstanceGroup(instanceGroup);
collectionResourceCustomization.setCollectionResource(collectionResource);
;
service.setModelUUID("abc");
service.getCollectionResourceCustomizations().add(collectionResourceCustomization);
service.getCollectionResourceCustomizations().add(collectionResourceCustomization);
doReturn(service).when(mockCatalogDbClient).getServiceByID("3c40d244-808e-42ca-b09a-256d83d19d0a");
doReturn(collectionResourceCustomization).when(mockCatalogDbClient).getNetworkCollectionResourceCustomizationByID("123");
String bpmnRequest = readBpmnRequestFromFile(MACRO_ACTIVATE_DELETE_UNASSIGN_JSON);
ObjectMapper mapper = new ObjectMapper();
ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
List<Resource> resource = new ArrayList<>();
List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
serviceEBBLoader.traverseCatalogDbService(execution, sIRequest, resource, aaiResourceIds);
assertEquals(resource.size(), 2);
}
use of org.onap.so.db.catalog.beans.InstanceGroup 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.InstanceGroup in project so by onap.
the class BBInputSetupMapperLayerTest method testMapCatalogInstanceGroupToInstanceGroup.
@Test
public void testMapCatalogInstanceGroupToInstanceGroup() throws IOException {
ModelInfoInstanceGroup expected = mapper.readValue(new File(RESOURCE_PATH + "ModelInfoInstanceGroup.json"), ModelInfoInstanceGroup.class);
InstanceGroup instanceGroup = mapper.readValue(new File(RESOURCE_PATH + "InstanceGroup.json"), InstanceGroup.class);
instanceGroup.setCollectionInstanceGroupCustomizations(new ArrayList<>());
CollectionResourceInstanceGroupCustomization collectionInstanceGroupCust = new CollectionResourceInstanceGroupCustomization();
collectionInstanceGroupCust.setModelCustomizationUUID("modelCustomizationUUID");
collectionInstanceGroupCust.setFunction("function");
collectionInstanceGroupCust.setDescription("description");
instanceGroup.getCollectionInstanceGroupCustomizations().add(collectionInstanceGroupCust);
CollectionResourceCustomization collectionResourceCust = new CollectionResourceCustomization();
collectionResourceCust.setModelCustomizationUUID("modelCustomizationUUID");
ModelInfoInstanceGroup actual = bbInputSetupMapperLayer.mapCatalogInstanceGroupToInstanceGroup(collectionResourceCust, instanceGroup);
assertThat(actual, sameBeanAs(expected));
}
use of org.onap.so.db.catalog.beans.InstanceGroup in project so by onap.
the class ToscaResourceInstaller method createVNFCInstanceGroup.
protected VnfcInstanceGroupCustomization createVNFCInstanceGroup(IEntityDetails vfcInstanceEntity, IEntityDetails vfEntityDetails, VnfResourceCustomization vnfResourceCustomization, ToscaResourceStructure toscaResourceStructure, Set<VnfcCustomization> existingVnfcGroupSet) {
Metadata instanceMetadata = vfcInstanceEntity.getMetadata();
InstanceGroup existingInstanceGroup = instanceGroupRepo.findByModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
VFCInstanceGroup vfcInstanceGroup;
if (existingInstanceGroup == null) {
// Populate InstanceGroup
vfcInstanceGroup = new VFCInstanceGroup();
vfcInstanceGroup.setModelName(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
vfcInstanceGroup.setModelInvariantUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
vfcInstanceGroup.setModelUUID(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
vfcInstanceGroup.setModelVersion(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_VERSION));
vfcInstanceGroup.setToscaNodeType(vfcInstanceEntity.getToscaType());
// Set Role
vfcInstanceGroup.setRole("SUB-INTERFACE");
// Set type
vfcInstanceGroup.setType(InstanceGroupType.VNFC);
} else {
vfcInstanceGroup = (VFCInstanceGroup) existingInstanceGroup;
}
// Populate VNFCInstanceGroupCustomization
VnfcInstanceGroupCustomization vfcInstanceGroupCustom = new VnfcInstanceGroupCustomization();
vfcInstanceGroupCustom.setVnfResourceCust(vnfResourceCustomization);
vnfResourceCustomization.getVnfcInstanceGroupCustomizations().add(vfcInstanceGroupCustom);
vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
vfcInstanceGroup.getVnfcInstanceGroupCustomizations().add(vfcInstanceGroupCustom);
vfcInstanceGroupCustom.setDescription(instanceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
String getInputName = null;
Map<String, Property> groupProperties = vfcInstanceEntity.getProperties();
for (String key : groupProperties.keySet()) {
Property property = groupProperties.get(key);
String vfcName = property.getName();
if (vfcName != null) {
if (vfcName.equals("vfc_instance_group_function")) {
String vfcValue = property.getValue().toString();
int getInputIndex = vfcValue.indexOf("{get_input=");
if (getInputIndex > -1) {
getInputName = vfcValue.substring(getInputIndex + 11, vfcValue.length() - 1);
}
}
}
}
List<IEntityDetails> serviceEntityList = getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(SdcTypes.VF).customizationUUID(vnfResourceCustomization.getModelCustomizationUUID()), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
if (serviceEntityList != null && !serviceEntityList.isEmpty()) {
vfcInstanceGroupCustom.setFunction(getLeafPropertyValue(serviceEntityList.get(0), getInputName));
}
vfcInstanceGroupCustom.setInstanceGroup(vfcInstanceGroup);
List<Input> inputs = vfEntityDetails.getInputs();
createVFCInstanceGroupMembers(vfcInstanceGroupCustom, vfcInstanceEntity, inputs, existingVnfcGroupSet);
return vfcInstanceGroupCustom;
}
Aggregations