use of org.onap.sdc.toscaparser.api.parameters.Input in project so by onap.
the class ToscaResourceInstaller method getResourceInput.
String getResourceInput(ToscaResourceStructure toscaResourceStructure, String resourceCustomizationUuid) throws ArtifactInstallerException {
Map<String, String> resouceRequest = new HashMap<>();
ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
List<IEntityDetails> nodeTemplateEntityList = getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(EntityTemplateType.NODE_TEMPLATE), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
List<Input> serInput = iSdcCsarHelper.getServiceInputs();
Optional<IEntityDetails> nodeTemplateOpt = nodeTemplateEntityList.stream().filter(e -> e.getMetadata().getValue(CUSTOMIZATION_UUID).equals(resourceCustomizationUuid)).findFirst();
if (nodeTemplateOpt.isPresent()) {
IEntityDetails entityDetails = nodeTemplateOpt.get();
Map<String, Property> resourceProperties = entityDetails.getProperties();
for (String key : resourceProperties.keySet()) {
Property property = resourceProperties.get(key);
String value = getValue(property.getValue(), serInput);
resouceRequest.put(key, value);
}
}
try {
ObjectMapper objectMapper = new ObjectMapper();
String jsonStr = objectMapper.writeValueAsString(resouceRequest);
jsonStr = jsonStr.replace("\"", "\\\"");
logger.debug("resource request for resource customization id {}: {}", resourceCustomizationUuid, jsonStr);
return jsonStr;
} catch (JsonProcessingException e) {
logger.error("resource input could not be deserialized for resource customization id (" + resourceCustomizationUuid + ")");
throw new ArtifactInstallerException("resource input could not be parsed", e);
}
}
use of org.onap.sdc.toscaparser.api.parameters.Input 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;
}
use of org.onap.sdc.toscaparser.api.parameters.Input in project so by onap.
the class ToscaResourceInstaller method createService.
protected Service createService(ToscaResourceStructure toscaResourceStructure, ResourceStructure resourceStructure) {
Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
List<Service> services = serviceRepo.findByModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
Service service;
if (!services.isEmpty() && services.size() > 0) {
service = services.get(0);
} else {
service = new Service();
}
if (serviceMetadata != null) {
if (toscaResourceStructure.getServiceVersion() != null) {
service.setModelVersion(toscaResourceStructure.getServiceVersion());
}
service.setServiceType(serviceMetadata.getValue("serviceType"));
service.setServiceRole(serviceMetadata.getValue("serviceRole"));
service.setServiceFunction(serviceMetadata.getValue("serviceFunction"));
service.setCategory(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
service.setDescription(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION));
service.setModelName(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_NAME));
service.setModelUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
service.setEnvironmentContext(serviceMetadata.getValue("environmentContext"));
if (resourceStructure != null)
service.setWorkloadContext(resourceStructure.getNotification().getWorkloadContext());
service.setModelInvariantUUID(serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID));
service.setCsar(toscaResourceStructure.getCatalogToscaCsar());
service.setNamingPolicy(serviceMetadata.getValue("namingPolicy"));
String generateNaming = serviceMetadata.getValue("ecompGeneratedNaming");
Boolean generateNamingValue = null;
if (generateNaming != null) {
generateNamingValue = "true".equalsIgnoreCase(generateNaming);
}
service.setOnapGeneratedNaming(generateNamingValue);
List<Input> serviceInputs = toscaResourceStructure.getSdcCsarHelper().getServiceInputs();
logger.debug("serviceInputs: {} " + serviceInputs);
if (!serviceInputs.isEmpty()) {
serviceInputs.forEach(input -> {
if (CDS_MODEL_NAME.equalsIgnoreCase(input.getName())) {
String value = input.getDefault() != null ? input.getDefault().toString() : null;
service.setBlueprintName(value);
}
if (CDS_MODEL_VERSION.equalsIgnoreCase(input.getName())) {
String value = input.getDefault() != null ? input.getDefault().toString() : null;
service.setBlueprintVersion(value);
}
if (CONTROLLER_ACTOR.equalsIgnoreCase(input.getName())) {
String value = input.getDefault() != null ? input.getDefault().toString() : null;
service.setControllerActor(value);
}
if (SKIP_POST_INST_CONF.equalsIgnoreCase(input.getName())) {
String value = input.getDefault() != null ? input.getDefault().toString() : "false";
service.setSkipPostInstConf(Boolean.valueOf(value));
}
});
}
}
toscaResourceStructure.setCatalogService(service);
return service;
}
use of org.onap.sdc.toscaparser.api.parameters.Input in project so by onap.
the class ToscaResourceInstaller method getValue.
// this of temporary solution
private static String getValue(Object value, List<Input> inputs) {
String outInput;
String defaultValue = null;
if (value instanceof Map) {
Collection values = ((LinkedHashMap) value).values();
outInput = (values.size() > 0) ? values.toArray()[0].toString() : "";
} else if (value instanceof GetInput) {
String inputName = ((GetInput) value).getInputName();
Optional<Input> inputOptional = inputs.stream().filter(input -> input.getName().equals(inputName)).findFirst();
if (inputOptional.isPresent()) {
Input input = inputOptional.get();
defaultValue = input.getDefault() != null ? input.getDefault().toString() : "";
}
// Gets a value between [ and ]
String regex = "\\[.*?\\]";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(value.toString());
String valueStr = matcher.find() ? matcher.group() : inputName;
outInput = valueStr + "|" + defaultValue;
} else {
outInput = value != null ? value.toString() : "";
}
return outInput;
}
Aggregations