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));
}
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;
}
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);
}
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);
}
}
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;
}
Aggregations