/** Inject input artifacts in the corresponding nodes. */
  public void processInputArtifacts(DeploymentTopology topology) {
    if (topology.getInputArtifacts() != null && !topology.getInputArtifacts().isEmpty()) {
      // we'll build a map inputArtifactId -> List<DeploymentArtifact>
      Map<String, List<DeploymentArtifact>> artifactMap = Maps.newHashMap();
      // iterate over nodes in order to remember all nodes referencing an input artifact
      for (NodeTemplate nodeTemplate : topology.getNodeTemplates().values()) {
        if (nodeTemplate.getArtifacts() != null && !nodeTemplate.getArtifacts().isEmpty()) {
          for (DeploymentArtifact da : nodeTemplate.getArtifacts().values()) {
            String inputArtifactId = InputArtifactUtil.getInputArtifactId(da);
            if (inputArtifactId != null) {
              List<DeploymentArtifact> das = artifactMap.get(inputArtifactId);
              if (das == null) {
                das = Lists.newArrayList();
                artifactMap.put(inputArtifactId, das);
              }
              das.add(da);
            }
          }
        }
      }

      for (Map.Entry<String, DeploymentArtifact> e : topology.getInputArtifacts().entrySet()) {
        List<DeploymentArtifact> nodeArtifacts = artifactMap.get(e.getKey());
        if (nodeArtifacts != null) {
          for (DeploymentArtifact nodeArtifact : nodeArtifacts) {
            nodeArtifact.setArtifactRef(e.getValue().getArtifactRef());
            nodeArtifact.setArtifactName(e.getValue().getArtifactName());
          }
        }
      }
    }
  }
 /**
  * Process default deployment properties
  *
  * @param deploymentTopology the deployment setup to generate configuration for
  */
 public void processProviderDeploymentProperties(DeploymentTopology deploymentTopology) {
   if (deploymentTopology.getOrchestratorId() == null) {
     // No orchestrator assigned for the topology do nothing
     return;
   }
   Map<String, PropertyDefinition> propertyDefinitionMap =
       orchestratorDeploymentService.getDeploymentPropertyDefinitions(
           deploymentTopology.getOrchestratorId());
   if (propertyDefinitionMap != null) {
     // Reset deployment properties as it might have changed between cloud
     Map<String, String> propertyValueMap = deploymentTopology.getProviderDeploymentProperties();
     if (propertyValueMap == null) {
       propertyValueMap = Maps.newHashMap();
     } else {
       Iterator<Map.Entry<String, String>> propertyValueMapIterator =
           propertyValueMap.entrySet().iterator();
       while (propertyValueMapIterator.hasNext()) {
         Map.Entry<String, String> entry = propertyValueMapIterator.next();
         if (!propertyDefinitionMap.containsKey(entry.getKey())) {
           // Remove the mapping if topology do not contain the node with that name and of type
           // compute
           // Or the mapping do not exist anymore in the match result
           propertyValueMapIterator.remove();
         }
       }
     }
     for (Map.Entry<String, PropertyDefinition> propertyDefinitionEntry :
         propertyDefinitionMap.entrySet()) {
       String existingValue = propertyValueMap.get(propertyDefinitionEntry.getKey());
       if (existingValue != null) {
         try {
           constraintPropertyService.checkSimplePropertyConstraint(
               propertyDefinitionEntry.getKey(),
               existingValue,
               propertyDefinitionEntry.getValue());
         } catch (ConstraintViolationException
             | ConstraintValueDoNotMatchPropertyTypeException e) {
           propertyValueMap.put(
               propertyDefinitionEntry.getKey(), propertyDefinitionEntry.getValue().getDefault());
         }
       } else if (propertyDefinitionEntry.getValue().getDefault() != null) {
         propertyValueMap.put(
             propertyDefinitionEntry.getKey(), propertyDefinitionEntry.getValue().getDefault());
       }
     }
     deploymentTopology.setProviderDeploymentProperties(propertyValueMap);
   }
 }
 /**
  * Fill-in the inputs properties definitions (and default values) based on the properties
  * definitions from the topology.
  *
  * @param topology The deployment topology to impact.
  */
 public void processInputProperties(DeploymentTopology topology) {
   Map<String, String> inputProperties = topology.getInputProperties();
   Map<String, PropertyDefinition> inputDefinitions = topology.getInputs();
   if (inputDefinitions == null || inputDefinitions.isEmpty()) {
     topology.setInputProperties(null);
   } else {
     if (inputProperties == null) {
       inputProperties = Maps.newHashMap();
       topology.setInputProperties(inputProperties);
     } else {
       Iterator<Map.Entry<String, String>> inputPropertyEntryIterator =
           inputProperties.entrySet().iterator();
       while (inputPropertyEntryIterator.hasNext()) {
         Map.Entry<String, String> inputPropertyEntry = inputPropertyEntryIterator.next();
         if (!inputDefinitions.containsKey(inputPropertyEntry.getKey())) {
           inputPropertyEntryIterator.remove();
         } else {
           try {
             constraintPropertyService.checkSimplePropertyConstraint(
                 inputPropertyEntry.getKey(),
                 inputPropertyEntry.getValue(),
                 inputDefinitions.get(inputPropertyEntry.getKey()));
           } catch (ConstraintViolationException
               | ConstraintValueDoNotMatchPropertyTypeException e) {
             // Property is not valid anymore for the input, remove the old value
             inputPropertyEntryIterator.remove();
           }
         }
       }
     }
     for (Map.Entry<String, PropertyDefinition> inputDefinitionEntry :
         inputDefinitions.entrySet()) {
       String existingValue = inputProperties.get(inputDefinitionEntry.getKey());
       if (existingValue == null) {
         String defaultValue = inputDefinitionEntry.getValue().getDefault();
         if (defaultValue != null) {
           inputProperties.put(inputDefinitionEntry.getKey(), defaultValue);
         }
       }
     }
   }
 }