Search in sources :

Example 16 with DeploymentArtifact

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

the class InputArtifactService method onCopyConfiguration.

@EventListener
@Order(11)
public void onCopyConfiguration(OnDeploymentConfigCopyEvent onDeploymentConfigCopyEvent) {
    ApplicationEnvironment source = onDeploymentConfigCopyEvent.getSourceEnvironment();
    ApplicationEnvironment target = onDeploymentConfigCopyEvent.getTargetEnvironment();
    DeploymentInputs deploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(source.getTopologyVersion(), source.getId()));
    if (deploymentInputs == null || MapUtils.isEmpty(deploymentInputs.getInputArtifacts())) {
        // Nothing to copy
        return;
    }
    Topology topology = topologyServiceCore.getOrFail(Csar.createId(target.getApplicationId(), target.getTopologyVersion()));
    if (MapUtils.isNotEmpty(topology.getInputArtifacts())) {
        Map<String, DeploymentArtifact> inputsArtifactsDefinitions = topology.getInputArtifacts();
        // Copy only artifacts which exists in the new topology's definition
        Map<String, DeploymentArtifact> inputsArtifactsToCopy = deploymentInputs.getInputArtifacts().entrySet().stream().filter(inputEntry -> inputsArtifactsDefinitions.containsKey(inputEntry.getKey())).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (MapUtils.isNotEmpty(inputsArtifactsToCopy)) {
            // There's something to copy
            DeploymentInputs targetDeploymentInputs = deploymentConfigurationDao.findById(DeploymentInputs.class, AbstractDeploymentConfig.generateId(target.getTopologyVersion(), target.getId()));
            if (targetDeploymentInputs == null) {
                targetDeploymentInputs = new DeploymentInputs(target.getTopologyVersion(), target.getId());
            }
            targetDeploymentInputs.setInputArtifacts(inputsArtifactsToCopy);
            deploymentConfigurationDao.save(targetDeploymentInputs);
        }
    }
}
Also used : MapUtils(org.apache.commons.collections4.MapUtils) Order(org.springframework.core.annotation.Order) Csar(org.alien4cloud.tosca.model.Csar) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) TopologyServiceCore(alien4cloud.topology.TopologyServiceCore) Resource(javax.annotation.Resource) EventListener(org.springframework.context.event.EventListener) IOException(java.io.IOException) HashMap(java.util.HashMap) AbstractDeploymentConfig(org.alien4cloud.alm.deployment.configuration.model.AbstractDeploymentConfig) Collectors(java.util.stream.Collectors) NotFoundException(alien4cloud.exception.NotFoundException) Inject(javax.inject.Inject) IFileRepository(alien4cloud.component.repository.IFileRepository) Service(org.springframework.stereotype.Service) Map(java.util.Map) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) MultipartFile(org.springframework.web.multipart.MultipartFile) Topology(org.alien4cloud.tosca.model.templates.Topology) ArtifactRepositoryConstants(alien4cloud.component.repository.ArtifactRepositoryConstants) OnDeploymentConfigCopyEvent(org.alien4cloud.alm.deployment.configuration.events.OnDeploymentConfigCopyEvent) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) InputStream(java.io.InputStream) DeploymentInputs(org.alien4cloud.alm.deployment.configuration.model.DeploymentInputs) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationEnvironment(alien4cloud.model.application.ApplicationEnvironment) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) HashMap(java.util.HashMap) Map(java.util.Map) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 17 with DeploymentArtifact

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

the class SetNodeArtifactAsInputProcessor method processNodeOperation.

@Override
protected void processNodeOperation(Csar csar, Topology topology, SetNodeArtifactAsInputOperation operation, NodeTemplate nodeTemplate) {
    if (safe(nodeTemplate.getArtifacts()).get(operation.getArtifactName()) == null) {
        throw new NotFoundException("The artifact <" + operation.getArtifactName() + "> cannot be found on node <" + operation.getNodeName() + ">");
    }
    DeploymentArtifact artifact = nodeTemplate.getArtifacts().get(operation.getArtifactName());
    if (!safe(topology.getInputArtifacts()).containsKey(operation.getInputName())) {
        // we have to create the artifact
        operation.setNewArtifact(true);
        DeploymentArtifact inputArtifact = new DeploymentArtifact();
        inputArtifact.setArchiveName(artifact.getArchiveName());
        inputArtifact.setArchiveVersion(artifact.getArchiveVersion());
        inputArtifact.setArtifactType(artifact.getArtifactType());
        Map<String, DeploymentArtifact> inputArtifacts = topology.getInputArtifacts();
        if (inputArtifacts == null) {
            inputArtifacts = Maps.newHashMap();
            topology.setInputArtifacts(inputArtifacts);
        }
        inputArtifacts.put(operation.getInputName(), inputArtifact);
    }
    InputArtifactUtil.setInputArtifact(artifact, operation.getInputName());
}
Also used : NotFoundException(alien4cloud.exception.NotFoundException) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 18 with DeploymentArtifact

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

the class DeleteFileProcessor method process.

@Override
public void process(Csar csar, Topology topology, DeleteFileOperation operation) {
    if (csar.getYamlFilePath().equals(operation.getPath())) {
        throw new InvalidPathException("Topology yaml file cannot be removed.");
    }
    TreeNode target = FileProcessorHelper.getFileTreeNode(operation.getPath());
    target.getParent().getChildren().remove(target);
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        for (DeploymentArtifact artifact : safe(nodeTemplate.getArtifacts()).values()) {
            resetRemovedArtifact(artifact, operation.getPath());
        }
        cleanupInterfaces(nodeTemplate.getInterfaces(), operation.getPath());
        for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
            cleanupInterfaces(relationshipTemplate.getInterfaces(), operation.getPath());
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) TreeNode(alien4cloud.utils.TreeNode) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact) InvalidPathException(org.alien4cloud.tosca.editor.exception.InvalidPathException)

Example 19 with DeploymentArtifact

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

the class UpdateNodeDeploymentArtifactProcessor method process.

@Override
public void process(Csar csar, Topology topology, UpdateNodeDeploymentArtifactOperation operation) {
    // Get the node template's artifacts to update
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology.getId(), operation.getNodeName(), nodeTemplates);
    DeploymentArtifact artifact = nodeTemplate.getArtifacts() == null ? null : nodeTemplate.getArtifacts().get(operation.getArtifactName());
    if (artifact == null) {
        throw new NotFoundException("Artifact with key [" + operation.getArtifactName() + "] do not exist");
    }
    if (operation.getArtifactRepository() == null) {
        // this is an archive file, ensure that the file exists within the archive
        FileProcessorHelper.getFileTreeNode(operation.getArtifactReference());
        artifact.setArtifactRepository(ArtifactRepositoryConstants.ALIEN_TOPOLOGY_REPOSITORY);
        artifact.setRepositoryName(null);
        artifact.setRepositoryURL(null);
    } else {
        artifact.setArtifactRepository(operation.getArtifactRepository());
        artifact.setRepositoryName(operation.getRepositoryName());
        artifact.setRepositoryURL(operation.getRepositoryUrl());
    }
    artifact.setArtifactRef(operation.getArtifactReference());
    artifact.setArchiveName(operation.getArchiveName());
    artifact.setArchiveVersion(operation.getArchiveVersion());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NotFoundException(alien4cloud.exception.NotFoundException) DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

Example 20 with DeploymentArtifact

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

the class ToscaSerializerUtilsTest method createArtifact.

private DeploymentArtifact createArtifact() {
    DeploymentArtifact deploymentArtifact = new DeploymentArtifact();
    deploymentArtifact.setArchiveName("test");
    deploymentArtifact.setArchiveVersion("1.0");
    return deploymentArtifact;
}
Also used : DeploymentArtifact(org.alien4cloud.tosca.model.definitions.DeploymentArtifact)

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