Search in sources :

Example 6 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class ResetNodeDeploymentArtifactProcessor method process.

@Override
public void process(Csar csar, Topology topology, ResetNodeDeploymentArtifactOperation operation) {
    // Get the node template's artifacts to reset
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
    DeploymentArtifact currentArtifact = nodeTemplate.getArtifacts() == null ? null : nodeTemplate.getArtifacts().get(operation.getArtifactName());
    if (currentArtifact == null) {
        throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist in node template [" + nodeTemplate.getName() + "].");
    }
    // Get the node type's artifact
    Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, false, true);
    NodeType nodeType = nodeTypes.get(nodeTemplate.getType());
    DeploymentArtifact artifactFromNodeType = nodeType.getArtifacts() == null ? null : nodeType.getArtifacts().get(operation.getArtifactName());
    if (artifactFromNodeType == null) {
        throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist in node type [" + nodeType.getId() + "].");
    }
    currentArtifact.setArtifactRef(artifactFromNodeType.getArtifactRef());
    currentArtifact.setArtifactName(artifactFromNodeType.getArtifactName());
    currentArtifact.setArtifactType(artifactFromNodeType.getArtifactType());
    currentArtifact.setArtifactRepository(artifactFromNodeType.getArtifactRepository());
    currentArtifact.setRepositoryName(artifactFromNodeType.getRepositoryName());
    currentArtifact.setRepositoryURL(artifactFromNodeType.getRepositoryURL());
    currentArtifact.setRepositoryCredential(artifactFromNodeType.getRepositoryCredential());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 7 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class DeploymentTopologyStepDefinitions method iSelectTheFileFromTheCurrentTopologyArchiveForTheInputArtifact.

@When("^I select the file \"([^\"]*)\" from the current topology archive for the input artifact \"([^\"]*)\"$")
public void iSelectTheFileFromTheCurrentTopologyArchiveForTheInputArtifact(String fileRef, String inputArtifactName) throws Throwable {
    Application application = Context.getInstance().getApplication();
    String envId = Context.getInstance().getDefaultApplicationEnvironmentId(application.getName());
    String url = String.format("/rest/applications/%s/environments/%s/deployment-topology/inputArtifacts/%s/update", application.getId(), envId, inputArtifactName);
    DeploymentArtifact inputArtifact = new DeploymentArtifact();
    inputArtifact.setArchiveName(application.getId());
    inputArtifact.setArchiveVersion(TestUtils.getVersionFromId(Context.getInstance().getTopologyId()));
    inputArtifact.setArtifactRef(fileRef);
    inputArtifact.setArtifactRepository(ArtifactRepositoryConstants.ALIEN_TOPOLOGY_REPOSITORY);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(url, JsonUtil.toString(inputArtifact)));
}
Also used : Application(alien4cloud.model.application.Application) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) When(cucumber.api.java.en.When)

Example 8 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class InputArtifactsModifier method processInputArtifactForTemplate.

/**
 * Map the template's artifacts associated with an input to into the given artifactMap.
 *
 * @param artifactMap The map of inputArtifactId -> List of associated artifacts into which to map the given template's artifacts.
 * @param template The template for which to map artifact.
 */
private static void processInputArtifactForTemplate(Map<String, List<DeploymentArtifact>> artifactMap, AbstractInstantiableTemplate template) {
    for (DeploymentArtifact da : template.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);
        }
    }
}
Also used : DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 9 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class InputArtifactsModifier method process.

@Override
public void process(Topology topology, FlowExecutionContext context) {
    ApplicationEnvironment environment = context.getEnvironmentContext().orElseThrow(() -> new IllegalArgumentException("Input modifier requires an environment context.")).getEnvironment();
    DeploymentInputs deploymentInputs = context.getConfiguration(DeploymentInputs.class, InputsModifier.class.getSimpleName()).orElse(new DeploymentInputs(environment.getTopologyVersion(), environment.getId()));
    if (deploymentInputs.getInputArtifacts() == null) {
        deploymentInputs.setInputArtifacts(Maps.newHashMap());
    }
    boolean updated = false;
    // Cleanup inputs artifacts that does not exists anymore
    Iterator<Entry<String, DeploymentArtifact>> inputArtifactsIterator = safe(deploymentInputs.getInputArtifacts()).entrySet().iterator();
    while (inputArtifactsIterator.hasNext()) {
        Entry<String, DeploymentArtifact> inputArtifactEntry = inputArtifactsIterator.next();
        if (!topology.getInputArtifacts().containsKey(inputArtifactEntry.getKey())) {
            inputArtifactsIterator.remove();
            updated = true;
        }
    }
    processInputArtifacts(topology, deploymentInputs.getInputArtifacts());
    // should save if deploymentInput updated
    if (updated) {
        context.saveConfiguration(deploymentInputs);
    }
}
Also used : Entry(java.util.Map.Entry) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 10 with DeploymentArtifact

use of org.alien4cloud.tosca.model.definitions.DeploymentArtifact in project alien4cloud by alien4cloud.

the class InputArtifactsModifier method processInputArtifacts.

/**
 * Inject input artifacts in the corresponding nodes.
 *
 * @param topology The topology in which to inject input artifacts.
 * @param inputArtifacts The input artifacts to inject in the topology.
 */
private void processInputArtifacts(Topology topology, Map<String, DeploymentArtifact> inputArtifacts) {
    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 (MapUtils.isNotEmpty(nodeTemplate.getArtifacts())) {
                processInputArtifactForTemplate(artifactMap, nodeTemplate);
            }
            if (MapUtils.isNotEmpty(nodeTemplate.getRelationships())) {
                nodeTemplate.getRelationships().entrySet().stream().filter(relationshipTemplateEntry -> MapUtils.isNotEmpty(relationshipTemplateEntry.getValue().getArtifacts())).forEach(relationshipTemplateEntry -> processInputArtifactForTemplate(artifactMap, relationshipTemplateEntry.getValue()));
            }
        }
        // Override the artifacts definition in the topology with the input artifact data.
        Map<String, DeploymentArtifact> allInputArtifact = new HashMap<>();
        allInputArtifact.putAll(topology.getInputArtifacts());
        if (MapUtils.isNotEmpty(inputArtifacts)) {
            allInputArtifact.putAll(inputArtifacts);
        }
        for (Map.Entry<String, DeploymentArtifact> inputArtifact : allInputArtifact.entrySet()) {
            List<DeploymentArtifact> nodeArtifacts = artifactMap.get(inputArtifact.getKey());
            if (nodeArtifacts != null) {
                for (DeploymentArtifact nodeArtifact : nodeArtifacts) {
                    nodeArtifact.setArtifactRef(inputArtifact.getValue().getArtifactRef());
                    nodeArtifact.setArtifactName(inputArtifact.getValue().getArtifactName());
                    nodeArtifact.setArtifactRepository(inputArtifact.getValue().getArtifactRepository());
                    nodeArtifact.setRepositoryName(inputArtifact.getValue().getRepositoryName());
                    nodeArtifact.setRepositoryCredential(inputArtifact.getValue().getRepositoryCredential());
                    nodeArtifact.setRepositoryURL(inputArtifact.getValue().getRepositoryURL());
                    nodeArtifact.setArchiveName(inputArtifact.getValue().getArchiveName());
                    nodeArtifact.setArchiveVersion(inputArtifact.getValue().getArchiveVersion());
                }
            }
        }
    }
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) Lists(org.elasticsearch.common.collect.Lists) Iterator(java.util.Iterator) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) InputArtifactUtil(alien4cloud.utils.InputArtifactUtil) HashMap(java.util.HashMap) Maps(com.google.common.collect.Maps) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) AbstractInstantiableTemplate(org.alien4cloud.tosca.model.templates.AbstractInstantiableTemplate) List(java.util.List) Component(org.springframework.stereotype.Component) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Map(java.util.Map) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Entry(java.util.Map.Entry) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) Topology(org.alien4cloud.tosca.model.templates.Topology) ITopologyModifier(org.alien4cloud.alm.deployment.configuration.flow.ITopologyModifier) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) HashMap(java.util.HashMap) List(java.util.List) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)25 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)10 NotFoundException (alien4cloud.exception.NotFoundException)6 Map (java.util.Map)5 DeploymentInputs (org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 HashMap (java.util.HashMap)4 Test (org.junit.Test)4 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ArtifactRepositoryConstants (alien4cloud.component.repository.ArtifactRepositoryConstants)2 IFileRepository (alien4cloud.component.repository.IFileRepository)2 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)2 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)2 Path (java.nio.file.Path)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 Resource (javax.annotation.Resource)2 Interface (org.alien4cloud.tosca.model.definitions.Interface)2