Search in sources :

Example 6 with InstanceGroup

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);
}
Also used : CollectionResource(org.onap.so.db.catalog.beans.CollectionResource) CollectionResourceInstanceGroupCustomization(org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization) ArrayList(java.util.ArrayList) Resource(org.onap.so.bpmn.infrastructure.workflow.tasks.Resource) CollectionResource(org.onap.so.db.catalog.beans.CollectionResource) Service(org.onap.so.db.catalog.beans.Service) Mockito.anyString(org.mockito.Mockito.anyString) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) InstanceGroup(org.onap.so.db.catalog.beans.InstanceGroup) NetworkCollectionResourceCustomization(org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Pair(org.javatuples.Pair) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 7 with InstanceGroup

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();
    }
}
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 8 with InstanceGroup

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));
}
Also used : ModelInfoInstanceGroup(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup) CollectionResourceInstanceGroupCustomization(org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization) CollectionResourceCustomization(org.onap.so.db.catalog.beans.CollectionResourceCustomization) File(java.io.File) InstanceGroup(org.onap.so.db.catalog.beans.InstanceGroup) ModelInfoInstanceGroup(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup) Test(org.junit.Test)

Example 9 with InstanceGroup

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;
}
Also used : IEntityDetails(org.onap.sdc.tosca.parser.api.IEntityDetails) Input(org.onap.sdc.toscaparser.api.parameters.Input) GetInput(org.onap.sdc.toscaparser.api.functions.GetInput) VFCInstanceGroup(org.onap.so.db.catalog.beans.VFCInstanceGroup) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) Property(org.onap.sdc.toscaparser.api.Property) NetworkInstanceGroup(org.onap.so.db.catalog.beans.NetworkInstanceGroup) VFCInstanceGroup(org.onap.so.db.catalog.beans.VFCInstanceGroup) InstanceGroup(org.onap.so.db.catalog.beans.InstanceGroup) VnfcInstanceGroupCustomization(org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization)

Aggregations

InstanceGroup (org.onap.so.db.catalog.beans.InstanceGroup)9 Test (org.junit.Test)5 CollectionResourceInstanceGroupCustomization (org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization)5 CollectionNetworkResourceCustomization (org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization)3 NetworkCollectionResourceCustomization (org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization)3 ArrayList (java.util.ArrayList)2 CatalogDbAdapterBaseTest (org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest)2 BaseTaskTest (org.onap.so.bpmn.BaseTaskTest)2 Resource (org.onap.so.bpmn.infrastructure.workflow.tasks.Resource)2 CollectionResource (org.onap.so.db.catalog.beans.CollectionResource)2 CollectionResourceCustomization (org.onap.so.db.catalog.beans.CollectionResourceCustomization)2 NetworkResourceCustomization (org.onap.so.db.catalog.beans.NetworkResourceCustomization)2 Service (org.onap.so.db.catalog.beans.Service)2 VnfcInstanceGroupCustomization (org.onap.so.db.catalog.beans.VnfcInstanceGroupCustomization)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 File (java.io.File)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Transactional (javax.transaction.Transactional)1 GET (javax.ws.rs.GET)1