List of usage examples for org.apache.commons.collections4 MapUtils isEmpty
public static boolean isEmpty(final Map<?, ?> map)
From source file:org.openecomp.sdc.translator.services.heattotosca.impl.BaseResourceConnection.java
private List<String> addRequirementAndGetConnectorParamsFromResourceProperties( HeatOrchestrationTemplate nestedHeatOrchestrationTemplate, Map.Entry<String, T> entry, List<String> params, List<Map.Entry<String, Resource>> heatResources) { Resource heatResource;/* ww w . j av a2s. c o m*/ for (Map.Entry<String, Resource> resourceEntry : heatResources) { heatResource = resourceEntry.getValue(); if (!MapUtils.isEmpty(heatResource.getProperties())) { Optional<List<String>> connectorParamName = getConnectorParamName(resourceEntry.getKey(), heatResource, nestedHeatOrchestrationTemplate); if (!connectorParamName.isPresent()) { break; } else { params = connectorParamName.get(); } } Objects.requireNonNull(params); addRequirementToConnectResources(entry, params); } return params; }
From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNestedImpl.java
private void addSubstitutionNodeTypeCapabilities(NodeType substitutionNodeType, Map<String, CapabilityDefinition> capabilities) { if (capabilities == null || capabilities.entrySet().size() == 0) { return;//from w ww . j a v a2 s.c o m } if (MapUtils.isEmpty(substitutionNodeType.getCapabilities())) { substitutionNodeType.setCapabilities(new HashMap<>()); } if (capabilities.size() > 0) { substitutionNodeType.setCapabilities(new HashMap<>()); } for (Map.Entry<String, CapabilityDefinition> entry : capabilities.entrySet()) { substitutionNodeType.getCapabilities().put(entry.getKey(), entry.getValue()); } }
From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerImpl.java
private boolean isSchedulerHintsPropExist(Map<String, Object> properties) { return !MapUtils.isEmpty(properties) && Objects.nonNull(properties.get("scheduler_hints")); }
From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerImpl.java
private void getOrTranslatePortTemplate(String heatFileName, HeatOrchestrationTemplate heatOrchestrationTemplate, Object port, ServiceTemplate serviceTemplate, String novaServerResourceId, TranslationContext context, NodeTemplate novaNodeTemplate) { Optional<AttachedResourceId> attachedPortId = HeatToToscaUtil.extractAttachedResourceId(heatFileName, heatOrchestrationTemplate, context, port); if (!attachedPortId.isPresent()) { return;/*ww w . j av a 2s . co m*/ } if (attachedPortId.get().isGetResource()) { String resourceId = (String) attachedPortId.get().getEntityId(); Resource portResource = HeatToToscaUtil.getResource(heatOrchestrationTemplate, resourceId, heatFileName); if (!Arrays.asList(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource(), HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource()) .contains(portResource.getType())) { logger.warn("NovaServer connect to port resource with id : " + resourceId + " and type : " + portResource.getType() + ". This resource type is not supported, therefore the connection to the port is " + "ignored. " + "Supported types are: " + HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource() + ", " + HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource()); return; } else if (HeatResourcesTypes.CONTRAIL_V2_VIRTUAL_MACHINE_INTERFACE_RESOURCE_TYPE.getHeatResource() .equals(portResource.getType())) { Map<String, Object> properties = portResource.getProperties(); if (!MapUtils.isEmpty(properties) && Objects.nonNull(properties.get("port_tuple_refs"))) { novaNodeTemplate.getProperties().put("contrail_service_instance_ind", true); } } Optional<String> translatedPortId = ResourceTranslationFactory.getInstance(portResource) .translateResource(heatFileName, serviceTemplate, heatOrchestrationTemplate, portResource, resourceId, context); if (translatedPortId.isPresent()) { NodeTemplate portNodeTemplate = DataModelUtil.getNodeTemplate(serviceTemplate, translatedPortId.get()); addBindingReqFromPortToCompute(novaServerResourceId, portNodeTemplate); } else { logger.warn("NovaServer connect to port resource with id : " + resourceId + " and type : " + portResource.getType() + ". This resource type is not supported, therefore the connection to the port is " + "ignored."); } } }
From source file:org.openecomp.sdc.translator.services.heattotosca.impl.ResourceTranslationNovaServerImpl.java
private boolean isNodeTypeCreated(ServiceTemplate serviceTemplate, String nodeTypeName) { return !MapUtils.isEmpty(serviceTemplate.getNode_types()) && Objects.nonNull(serviceTemplate.getNode_types().get(nodeTypeName)); }
From source file:org.openecomp.sdc.validation.impl.util.HeatValidationService.java
/** * Loop over output map and validate get attr from nested. * * @param fileName the file name * @param outputMap the output map * @param heatOrchestrationTemplate the heat orchestration template * @param globalContext the global context *//*from ww w . j a va 2s. co m*/ @SuppressWarnings("unchecked") public static void loopOverOutputMapAndValidateGetAttrFromNested(String fileName, Map<String, Output> outputMap, HeatOrchestrationTemplate heatOrchestrationTemplate, GlobalValidationContext globalContext) { for (Output output : outputMap.values()) { Object outputValue = output.getValue(); if (outputValue != null && outputValue instanceof Map) { Map<String, Object> outputValueMap = (Map<String, Object>) outputValue; List<String> getAttrValue = (List<String>) outputValueMap .get(ResourceReferenceFunctions.GET_ATTR.getFunction()); if (!CollectionUtils.isEmpty(getAttrValue)) { String resourceName = getAttrValue.get(0); String propertyName = getAttrValue.get(1); String resourceType = getResourceTypeFromResourcesMap(resourceName, heatOrchestrationTemplate); if (Objects.nonNull(resourceType) && HeatValidationService.isNestedResource(resourceType)) { Map<String, Output> nestedOutputMap; HeatOrchestrationTemplate nestedHeatOrchestrationTemplate; try { nestedHeatOrchestrationTemplate = new YamlUtil().yamlToObject( globalContext.getFileContent(resourceType), HeatOrchestrationTemplate.class); } catch (Exception e0) { return; } nestedOutputMap = nestedHeatOrchestrationTemplate.getOutputs(); if (MapUtils.isEmpty(nestedOutputMap) || !nestedOutputMap.containsKey(propertyName)) { globalContext.addMessage(fileName, ErrorLevel.ERROR, ErrorMessagesFormatBuilder.getErrorWithParameters( Messages.GET_ATTR_NOT_FOUND.getErrorMessage(), propertyName, resourceName)); } } } } } }
From source file:org.openecomp.sdc.validation.impl.util.ResourceValidationHeatValidator.java
@SuppressWarnings("unchecked") private static void validateAllSecurityGroupsAreUsed(String filename, Map.Entry<String, Resource> resourceEntry, List<String> securityGroupResourceNameList, GlobalValidationContext globalContext) { Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties(); if (MapUtils.isEmpty(propertiesMap)) { return;//from w ww . j av a2 s. c o m } Object securityGroupsValue = propertiesMap.get("security_groups"); if (Objects.isNull(securityGroupsValue)) { return; } if (securityGroupsValue instanceof List) { List<Object> securityGroupsListFromCurrResource = (List<Object>) propertiesMap.get("security_groups"); for (Object securityGroup : securityGroupsListFromCurrResource) { removeSecurityGroupNamesFromListByGivenFunction(filename, ResourceReferenceFunctions.GET_RESOURCE.getFunction(), securityGroup, securityGroupResourceNameList, globalContext); } } }
From source file:org.openecomp.sdc.validation.impl.util.ResourceValidationHeatValidator.java
private static void validateSecurityGroupsFromBaseOutput(String filename, Map.Entry<String, Resource> resourceEntry, boolean isBaseFile, Set<String> securityGroupNamesFromBaseOutput, GlobalValidationContext globalContext) { if (!isBaseFile && CollectionUtils.isNotEmpty(securityGroupNamesFromBaseOutput)) { Map<String, Object> propertiesMap = resourceEntry.getValue().getProperties(); if (MapUtils.isEmpty(propertiesMap)) { return; }//from w ww. ja va2s. c om for (Map.Entry<String, Object> propertyEntry : propertiesMap.entrySet()) { removeSecurityGroupNamesFromListByGivenFunction(filename, ResourceReferenceFunctions.GET_PARAM.getFunction(), propertyEntry.getValue(), securityGroupNamesFromBaseOutput, globalContext); } } }
From source file:org.openecomp.sdc.validation.impl.util.ResourceValidationHeatValidator.java
private static Set<String> getSharedResourcesNamesFromOutputs(String filename, Map<String, Output> outputsMap, GlobalValidationContext globalContext) { Set<String> sharedResources = new HashSet<>(); if (MapUtils.isEmpty(outputsMap)) { return null; }/*from w ww . j a v a 2 s .c o m*/ for (Map.Entry<String, Output> outputEntry : outputsMap.entrySet()) { Output output = outputEntry.getValue(); Object valueObject = output.getValue(); if (valueObject instanceof Map) { Map<String, Object> outputValueMap = (Map<String, Object>) valueObject; Object getResourceValue = outputValueMap.get(ResourceReferenceFunctions.GET_RESOURCE.getFunction()); if (Objects.nonNull(getResourceValue)) { if (getResourceValue instanceof String) { String resourceName = (String) outputValueMap .get(ResourceReferenceFunctions.GET_RESOURCE.getFunction()); sharedResources.add(resourceName); } else { globalContext.addMessage(filename, ErrorLevel.ERROR, ErrorMessagesFormatBuilder.getErrorWithParameters( Messages.INVALID_GET_RESOURCE_SYNTAX.getErrorMessage(), getResourceValue.toString())); } } } } return sharedResources; }
From source file:org.openecomp.sdc.validation.impl.validators.EcompGuideLineValidator.java
private void validatePortNetworkNamingConvention(String fileName, HeatOrchestrationTemplate heatOrchestrationTemplate, GlobalValidationContext globalContext) { if (MapUtils.isEmpty(heatOrchestrationTemplate.getResources())) { return;/* ww w . j av a 2 s. co m*/ } String[] regexList = new String[] { ".*_net_id", ".*_net_name", ".*_net_fqdn" }; heatOrchestrationTemplate.getResources().entrySet().stream() .filter(entry -> entry.getValue().getType() != null && entry.getValue().getType() .equals(HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource())) .forEach(entry -> entry.getValue().getProperties().entrySet().stream() .filter(propertyEntry -> propertyEntry != null && (propertyEntry.getKey().toLowerCase().equals("network".toLowerCase()) || propertyEntry.getKey().equals("network_id"))) .forEach(propertyEntry -> validateParamNamingConvention(fileName, entry.getKey(), propertyEntry.getValue(), regexList, Messages.NETWORK_PARAM_NOT_ALIGNED_WITH_GUIDE_LINE, globalContext))); }