Search in sources :

Example 6 with Metadata

use of org.onap.sdc.toscaparser.api.elements.Metadata in project so by onap.

the class ToscaResourceInstaller method processPnfResources.

/**
 * This is used to process the PNF specific resource, including resource and resource_customization.
 * {@link IEntityDetails} based API is used to retrieve information. Please check {@link ISdcCsarHelper} for
 * details.
 */
protected void processPnfResources(ToscaResourceStructure toscaResourceStruct, Service service, PnfResourceStructure resourceStructure) throws Exception {
    logger.info("Processing PNF resource: {}", resourceStructure.getResourceInstance().getResourceUUID());
    ISdcCsarHelper sdcCsarHelper = toscaResourceStruct.getSdcCsarHelper();
    EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.PNF).build();
    TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build();
    List<IEntityDetails> entityDetailsList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
    for (IEntityDetails entityDetails : entityDetailsList) {
        Metadata metadata = entityDetails.getMetadata();
        String customizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
        String modelUuid = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
        String notifCustomizationUUID = resourceStructure.getResourceInstance().getResourceCustomizationUUID();
        if (customizationUUID != null && customizationUUID.equals(notifCustomizationUUID)) {
            logger.info("Resource customization UUID: {} is the same as notified resource customizationUUID: {}", customizationUUID, notifCustomizationUUID);
            if (checkExistingPnfResourceCutomization(customizationUUID)) {
                logger.info("Resource customization UUID: {} already deployed", customizationUUID);
            } else {
                PnfResource pnfResource = findExistingPnfResource(service, modelUuid);
                if (pnfResource == null) {
                    pnfResource = createPnfResource(entityDetails);
                }
                PnfResourceCustomization pnfResourceCustomization = createPnfResourceCustomization(entityDetails, pnfResource);
                pnfResource.getPnfResourceCustomizations().add(pnfResourceCustomization);
                toscaResourceStruct.setPnfResourceCustomization(pnfResourceCustomization);
                service.getPnfCustomizations().add(pnfResourceCustomization);
            }
        } else {
            logger.warn("Resource customization UUID: {} is NOT the same as notified resource customizationUUID: {}", customizationUUID, notifCustomizationUUID);
        }
    }
}
Also used : IEntityDetails(org.onap.sdc.tosca.parser.api.IEntityDetails) PnfResourceCustomization(org.onap.so.db.catalog.beans.PnfResourceCustomization) TopologyTemplateQuery(org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery) ISdcCsarHelper(org.onap.sdc.tosca.parser.api.ISdcCsarHelper) PnfResource(org.onap.so.db.catalog.beans.PnfResource) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) EntityQuery(org.onap.sdc.tosca.parser.elements.queries.EntityQuery)

Example 7 with Metadata

use of org.onap.sdc.toscaparser.api.elements.Metadata 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);
            }
        }
    }
}
Also used : IEntityDetails(org.onap.sdc.tosca.parser.api.IEntityDetails) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization)

Example 8 with Metadata

use of org.onap.sdc.toscaparser.api.elements.Metadata in project so by onap.

the class ToscaResourceInputTest method getListResourceInput.

@Test
public void getListResourceInput() {
    ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
    LinkedHashMap<String, Property> hashMap = new LinkedHashMap<>();
    hashMap.put("key1", property);
    Map<String, Object> map = new HashMap<>();
    map.put("customizationUUID", "69df3303-d2b3-47a1-9d04-41604d3a95fd");
    Metadata metadata = new Metadata(map);
    when(entityDetails.getProperties()).thenReturn(hashMap);
    when(property.getValue()).thenReturn(getInput);
    when(getInput.getInputName()).thenReturn("nameKey");
    when(input.getName()).thenReturn("nameKey");
    when(input.getDefault()).thenReturn("defaultValue");
    when(getInput.toString()).thenReturn("getinput:[sites,INDEX,role]");
    when(entityDetails.getMetadata()).thenReturn(metadata);
    List<Input> inputs = new ArrayList<>();
    inputs.add(input);
    String resourceInput = toscaResourceInstaller.getVnfcResourceInput(entityDetails, inputs);
    assertEquals("{\\\"key1\\\":\\\"[sites,INDEX,role]|defaultValue\\\"}", resourceInput);
}
Also used : Input(org.onap.sdc.toscaparser.api.parameters.Input) GetInput(org.onap.sdc.toscaparser.api.functions.GetInput) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) Property(org.onap.sdc.toscaparser.api.Property) Test(org.junit.Test)

Example 9 with Metadata

use of org.onap.sdc.toscaparser.api.elements.Metadata in project so by onap.

the class ToscaResourceInputTest method processResourceSequenceTest.

@Test
public void processResourceSequenceTest() {
    ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
    ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
    toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
    ArrayList<Input> inputs = new ArrayList<>();
    Service service = new Service();
    HashMap<String, Object> hashMap = new HashMap();
    hashMap.put("name", "node1");
    Metadata metadata = new Metadata(hashMap);
    when(entityDetails.getMetadata()).thenReturn(metadata);
    when(sdcCsarHelper.getServiceInputs()).thenReturn(inputs);
    when(toscaResourceInstaller.getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(EntityTemplateType.NODE_TEMPLATE), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false)).thenReturn(Arrays.asList(entityDetails));
    when(entityDetails.getRequirements()).thenReturn(null);
    toscaResourceInstaller.processResourceSequence(toscaResourceStructure, service);
    assertEquals(service.getResourceOrder(), "");
}
Also used : Input(org.onap.sdc.toscaparser.api.parameters.Input) GetInput(org.onap.sdc.toscaparser.api.functions.GetInput) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) Service(org.onap.so.db.catalog.beans.Service) Test(org.junit.Test)

Example 10 with Metadata

use of org.onap.sdc.toscaparser.api.elements.Metadata in project so by onap.

the class ToscaResourceInputTest method resouceInputGetInputTest.

@Test
public void resouceInputGetInputTest() throws ArtifactInstallerException {
    ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
    ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
    toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
    HashMap hashMap = new HashMap();
    hashMap.put("customizationUUID", "id1");
    Metadata metadata = new Metadata(hashMap);
    Map<String, Property> propertyMap = new HashMap<String, Property>();
    propertyMap.put("prop1", property);
    when(toscaResourceInstaller.getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(EntityTemplateType.NODE_TEMPLATE), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false)).thenReturn(Arrays.asList(entityDetails));
    when(sdcCsarHelper.getServiceInputs()).thenReturn(Arrays.asList(input));
    when(entityDetails.getMetadata()).thenReturn(metadata);
    when(entityDetails.getProperties()).thenReturn(propertyMap);
    when(property.getValue()).thenReturn(getInput);
    when(getInput.getInputName()).thenReturn("res_key");
    when(input.getName()).thenReturn("res_key");
    when(input.getDefault()).thenReturn("default_value");
    String resourceInput = toscaResourceInstaller.getResourceInput(toscaResourceStructure, "id1");
    assertEquals("{}", resourceInput);
}
Also used : ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) Property(org.onap.sdc.toscaparser.api.Property) Test(org.junit.Test)

Aggregations

Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)31 IEntityDetails (org.onap.sdc.tosca.parser.api.IEntityDetails)10 ToscaResourceStructure (org.onap.so.asdc.installer.ToscaResourceStructure)10 Property (org.onap.sdc.toscaparser.api.Property)9 Input (org.onap.sdc.toscaparser.api.parameters.Input)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 Service (org.onap.so.db.catalog.beans.Service)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 ISdcCsarHelper (org.onap.sdc.tosca.parser.api.ISdcCsarHelper)6 NodeTemplate (org.onap.sdc.toscaparser.api.NodeTemplate)6 GetInput (org.onap.sdc.toscaparser.api.functions.GetInput)6 ConfigurationResource (org.onap.so.db.catalog.beans.ConfigurationResource)6 Map (java.util.Map)5 VfResourceStructure (org.onap.so.asdc.installer.VfResourceStructure)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 NetworkInstanceGroup (org.onap.so.db.catalog.beans.NetworkInstanceGroup)4 NetworkResource (org.onap.so.db.catalog.beans.NetworkResource)4 TempNetworkHeatTemplateLookup (org.onap.so.db.catalog.beans.TempNetworkHeatTemplateLookup)4