Search in sources :

Example 1 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class TopologySubstitutionService method updateSubstitutionType.

@ToscaContextual
public void updateSubstitutionType(final Topology topology, Csar csar) {
    if (topology.getSubstitutionMapping() == null || topology.getSubstitutionMapping().getSubstitutionType() == null) {
        return;
    }
    // first we update the csar and the dependencies
    NodeType nodeType = ToscaContext.getOrFail(NodeType.class, topology.getSubstitutionMapping().getSubstitutionType());
    if (csar.getDependencies() == null) {
        csar.setDependencies(Sets.newHashSet());
    }
    boolean updateCsar = false;
    if (csar.getDependencies().add(csarDependencyLoader.buildDependencyBean(nodeType.getArchiveName(), nodeType.getArchiveVersion()))) {
        updateCsar = true;
    }
    Path archiveGitPath = csarRepositry.getExpandedCSAR(csar.getName(), csar.getVersion());
    String hash = FileUtil.deepSHA1(archiveGitPath);
    if (!hash.equals(csar.getHash())) {
        csar.setHash(hash);
        updateCsar = true;
    }
    if (updateCsar) {
        csarService.save(csar);
    }
    // We create the nodeType that will serve as substitute
    NodeType substituteNodeType = buildSubstituteNodeType(topology, csar, nodeType);
    // inputs from topology become properties of type
    substituteNodeType.setProperties(topology.getInputs());
    // output attributes become attributes for the type
    fillSubstituteAttributesFromTypeAtttributes(topology, substituteNodeType);
    // output properties become attributes for the type
    fillSubstituteAttributesFromOutputProperties(topology, substituteNodeType);
    // output capabilities properties also become attributes for the type
    fillAttributesFromOutputCapabilitiesProperties(topology, substituteNodeType);
    // capabilities substitution
    fillCapabilities(topology, substituteNodeType);
    // requirement substitution
    fillRequirements(topology, substituteNodeType);
    // finally we index the created type
    indexerService.indexInheritableElement(csar.getName(), csar.getVersion(), substituteNodeType, csar.getDependencies());
    // Dispatch event
    publisher.publishEvent(new SubstitutionTypeChangedEvent(this, topology, substituteNodeType));
}
Also used : Path(java.nio.file.Path) SubstitutionTypeChangedEvent(org.alien4cloud.tosca.editor.events.SubstitutionTypeChangedEvent) NodeType(org.alien4cloud.tosca.model.types.NodeType) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 2 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method buildPaaSTopology.

/**
 * Build the topology for deployment on the PaaS.
 *
 * @param topology The topology.
 * @return The parsed topology for the PaaS with.
 */
@ToscaContextual
public PaaSTopology buildPaaSTopology(Topology topology) {
    PaaSTopology paaSTopology = buildPaaSTopology(buildPaaSNodeTemplates(topology));
    // Reuse this utility to query all types and inject them in the PaaSTopology
    TopologyDTO topologyDTO = topologyDTOBuilder.initTopologyDTO(topology, new TopologyDTO());
    paaSTopology.setDataTypes(topologyDTO.getDataTypes());
    paaSTopology.setCapabilityTypes(topologyDTO.getCapabilityTypes());
    paaSTopology.setRelationshipTypes(topologyDTO.getRelationshipTypes());
    paaSTopology.setNodeTypes(topologyDTO.getNodeTypes());
    return paaSTopology;
}
Also used : PaaSTopology(alien4cloud.paas.model.PaaSTopology) TopologyDTO(alien4cloud.topology.TopologyDTO) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 3 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class DeploymentTopologyDTOBuilder method prepareDeployment.

@Override
@ToscaContextual
public DeploymentTopologyDTO prepareDeployment(Topology topology, Application application, ApplicationEnvironment environment, ApplicationTopologyVersion topologyVersion, IDeploymentConfigAction deploymentConfigAction) {
    // Execute the update
    deploymentConfigAction.execute(application, environment, topologyVersion, topology);
    FlowExecutionContext executionContext = flowExecutor.executeDeploymentFlow(topology, application, environment);
    return build(executionContext);
}
Also used : FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 4 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class NodeInstanceService method checkRequired.

/**
 * Performs validation of the node instance. Note that based on the actual node state the validation is more or less strict.
 *
 * When the node state is initial the validation checks that all elements defined in the node template or node instance attributes matches the definition of
 * the node
 * type. It however does not check if the type has all required properties configured.
 *
 * When the node state is anything else the validation performs above validation and also checks that all required properties are defined.
 *
 * @param nodeType The node type against which to perform validation of the node instance.
 * @param nodeInstance The actual node instance to validate
 */
@ToscaContextual
public void checkRequired(NodeType nodeType, NodeInstance nodeInstance) {
    List<PropertiesTask> errors = Lists.newArrayList();
    topologyPropertiesValidationService.validateNodeTemplate(errors, nodeType, nodeInstance.getNodeTemplate(), "", false);
    if (!errors.isEmpty()) {
        Set<String> errorProperties = Sets.newHashSet();
        for (PropertiesTask task : errors) {
            for (List<String> properties : task.getProperties().values()) {
                errorProperties.addAll(properties);
            }
        }
        throw new InstanceRequiredPropertiesException("Some required properties are not defined.", errorProperties);
    }
}
Also used : InstanceRequiredPropertiesException(org.alien4cloud.alm.service.exceptions.InstanceRequiredPropertiesException) PropertiesTask(alien4cloud.topology.task.PropertiesTask) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 5 with ToscaContextual

use of alien4cloud.tosca.context.ToscaContextual in project alien4cloud by alien4cloud.

the class NodeInstanceService method create.

/**
 * Create a new instance of a given node type based on default generated template.
 *
 * @param nodeType The node type out of which to create the version.
 * @param typeVersion The node instance type's version.
 * @return An instance that matches the given type created from a default template (default values). Note that the node instance may be constructed from an
 *         invalid template (missing required properties) without errors. State of the node is set to initial.
 */
@ToscaContextual
public NodeInstance create(NodeType nodeType, String typeVersion) {
    NodeTemplate nodeTemplate = TemplateBuilder.buildNodeTemplate(nodeType, null);
    NodeInstance instance = new NodeInstance();
    instance.setAttribute(ToscaNodeLifecycleConstants.ATT_STATE, ToscaNodeLifecycleConstants.INITIAL);
    instance.setNodeTemplate(nodeTemplate);
    instance.setTypeVersion(typeVersion);
    return instance;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeInstance(org.alien4cloud.tosca.model.instances.NodeInstance) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Aggregations

ToscaContextual (alien4cloud.tosca.context.ToscaContextual)13 TopologyDTO (alien4cloud.topology.TopologyDTO)2 ParsingException (alien4cloud.tosca.parser.ParsingException)2 Path (java.nio.file.Path)2 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)2 CsarDependenciesBean (org.alien4cloud.tosca.model.CsarDependenciesBean)2 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)1 PaaSTopology (alien4cloud.paas.model.PaaSTopology)1 AbstractTopologyDTO (alien4cloud.topology.AbstractTopologyDTO)1 PropertiesTask (alien4cloud.topology.task.PropertiesTask)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 ToscaMeta (alien4cloud.tosca.model.ToscaMeta)1 ParsingContext (alien4cloud.tosca.parser.ParsingContext)1 ParsingResult (alien4cloud.tosca.parser.ParsingResult)1 IOException (java.io.IOException)1 FileSystem (java.nio.file.FileSystem)1 ProviderNotFoundException (java.nio.file.ProviderNotFoundException)1 HashMap (java.util.HashMap)1