Search in sources :

Example 1 with Property

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

the class ToscaResourceInstaller method getVnfcResourceInput.

public String getVnfcResourceInput(IEntityDetails vfcEntity, List<Input> inputList) {
    Map<String, String> resouceRequest = new HashMap<>();
    Map<String, Property> vfcTemplateProperties = vfcEntity.getProperties();
    for (String key : vfcTemplateProperties.keySet()) {
        Property property = vfcTemplateProperties.get(key);
        String resourceValue = getValue(property.getValue(), inputList);
        resouceRequest.put(key, resourceValue);
    }
    String resourceCustomizationUuid = vfcEntity.getMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
    String jsonStr = null;
    try {
        ObjectMapper objectMapper = new ObjectMapper();
        jsonStr = objectMapper.writeValueAsString(resouceRequest);
        jsonStr = jsonStr.replace("\"", "\\\"");
        logger.debug("vfcResource request for resource customization id {}: {}", resourceCustomizationUuid, jsonStr);
    } catch (JsonProcessingException e) {
        logger.debug("Json Exception: {}", e.getMessage());
        logger.error("Exception occurred", e);
    }
    return jsonStr;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) Property(org.onap.sdc.toscaparser.api.Property) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with Property

use of org.onap.sdc.toscaparser.api.Property 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 3 with Property

use of org.onap.sdc.toscaparser.api.Property 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)

Example 4 with Property

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

the class ToscaResourceInputTest method resouceInputTest.

@Test
public void resouceInputTest() throws ArtifactInstallerException {
    ToscaResourceInstaller toscaResourceInstaller = new ToscaResourceInstaller();
    ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure();
    toscaResourceStructure.setSdcCsarHelper(sdcCsarHelper);
    Map 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(entityDetails.getMetadata()).thenReturn(metadata);
    when(entityDetails.getProperties()).thenReturn(propertyMap);
    when(property.getValue()).thenReturn("value1");
    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)

Example 5 with Property

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

the class ToscaResourceInstaller method createPnfResourceCustomization.

/**
 * Construct the {@link PnfResourceCustomization} from {@link IEntityDetails} object.
 */
private PnfResourceCustomization createPnfResourceCustomization(IEntityDetails entityDetails, PnfResource pnfResource) {
    PnfResourceCustomization pnfResourceCustomization = new PnfResourceCustomization();
    Metadata metadata = entityDetails.getMetadata();
    Map<String, Property> properties = entityDetails.getProperties();
    pnfResourceCustomization.setModelCustomizationUUID(testNull(metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID)));
    pnfResourceCustomization.setModelInstanceName(entityDetails.getName());
    pnfResourceCustomization.setNfFunction(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFFUNCTION)));
    pnfResourceCustomization.setNfNamingCode(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFCODE)));
    pnfResourceCustomization.setNfRole(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFROLE)));
    pnfResourceCustomization.setNfType(getStringValue(properties.get(SdcPropertyNames.PROPERTY_NAME_NFTYPE)));
    pnfResourceCustomization.setMultiStageDesign(getStringValue(properties.get(MULTI_STAGE_DESIGN)));
    pnfResourceCustomization.setBlueprintName(getStringValue(properties.get(SDNC_MODEL_NAME)));
    pnfResourceCustomization.setBlueprintVersion(getStringValue(properties.get(SDNC_MODEL_VERSION)));
    pnfResourceCustomization.setSkipPostInstConf(getBooleanValue(properties.get(SKIP_POST_INST_CONF)));
    pnfResourceCustomization.setControllerActor(getStringValue(properties.get(CONTROLLER_ACTOR)));
    pnfResourceCustomization.setDefaultSoftwareVersion(extractDefaultSoftwareVersionFromSwVersions(properties));
    pnfResourceCustomization.setPnfResources(pnfResource);
    return pnfResourceCustomization;
}
Also used : PnfResourceCustomization(org.onap.so.db.catalog.beans.PnfResourceCustomization) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) Property(org.onap.sdc.toscaparser.api.Property)

Aggregations

Property (org.onap.sdc.toscaparser.api.Property)9 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)8 Test (org.junit.Test)4 ToscaResourceStructure (org.onap.so.asdc.installer.ToscaResourceStructure)4 IEntityDetails (org.onap.sdc.tosca.parser.api.IEntityDetails)3 GetInput (org.onap.sdc.toscaparser.api.functions.GetInput)3 Input (org.onap.sdc.toscaparser.api.parameters.Input)3 NetworkInstanceGroup (org.onap.so.db.catalog.beans.NetworkInstanceGroup)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 CollectionNetworkResourceCustomization (org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization)2 CollectionResource (org.onap.so.db.catalog.beans.CollectionResource)2 CollectionResourceInstanceGroupCustomization (org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization)2 HeatTemplate (org.onap.so.db.catalog.beans.HeatTemplate)2 InstanceGroup (org.onap.so.db.catalog.beans.InstanceGroup)2 NetworkCollectionResourceCustomization (org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization)2