use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class EditorService method undoRedo.
/**
* Undo or redo operations until the given index (including)
*
* @param topologyId The id of the topology for which to undo or redo operations.
* @param at The index on which to place the undo/redo cursor (-1 means no operations, then 0 is first operation etc.)
* @param lastOperationId The last known operation id for client optimistic locking.
* @return The topology DTO.
*/
public TopologyDTO undoRedo(String topologyId, int at, String lastOperationId) {
try {
initContext(topologyId, lastOperationId);
if (-1 > at || at > EditionContextManager.get().getOperations().size()) {
throw new NotFoundException("Unable to find the requested index for undo/redo");
}
checkTopologyRecovery();
if (at == EditionContextManager.get().getLastOperationIndex()) {
// nothing to change.
return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
}
// TODO Improve this by avoiding dao query for (deep) cloning topology and keeping cache for TOSCA types that are required.
editionContextManager.reset();
Topology topology = EditionContextManager.getTopology();
Csar csar = EditionContextManager.getCsar();
for (int i = 0; i < at + 1; i++) {
AbstractEditorOperation operation = EditionContextManager.get().getOperations().get(i);
IEditorOperationProcessor processor = processorMap.get(operation.getClass());
processor.process(csar, topology, operation);
}
EditionContextManager.get().setLastOperationIndex(at);
return dtoBuilder.buildTopologyDTO(EditionContextManager.get());
} catch (IOException e) {
// FIXME undo should be fail-safe...
return null;
} finally {
EditionContextManager.get().setCurrentOperation(null);
editionContextManager.destroy();
}
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class ResetTopologyProcessor method process.
@Override
public void process(Csar csar, Topology topology, ResetTopologyOperation operation) {
Topology newTopology = new Topology();
newTopology.setArchiveName(topology.getArchiveName());
newTopology.setArchiveVersion(topology.getArchiveVersion());
newTopology.setWorkspace(topology.getWorkspace());
workflowBuilderService.initWorkflows(workflowBuilderService.buildTopologyContext(newTopology, csar));
try {
EditionContextManager.get().reset(newTopology);
} catch (IOException e) {
// FIXME what to do here????
log.error("Error occurs when trying to reset the topology <" + topology.getId() + ">", e);
}
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class ApplicationStepDefinitions method The_created_application_topology_is_the_same_as_the_one_in_the_base_topology_template.
@Then("^The created application topology is the same as the one in the base topology template$")
public void The_created_application_topology_is_the_same_as_the_one_in_the_base_topology_template() throws Throwable {
// created topology
String topologyId = Csar.createId(CURRENT_APPLICATION.getId(), VersionUtil.DEFAULT_VERSION_NAME);
Context.getInstance().registerRestResponse(getRestClientInstance().get("/rest/v1/topologies/" + topologyId));
TopologyDTO createdTopology = JsonUtil.read(Context.getInstance().getRestResponse(), TopologyDTO.class, Context.getJsonMapper()).getData();
// base topology template
// quick win solution
authSteps.I_am_authenticated_with_role("ARCHITECT");
String topoResponse = Context.getRestClientInstance().get("/rest/v1/catalog/topologies/" + TopologyTemplateStepDefinitions.CURRENT_TOPOLOGY_TEMP_ID);
Topology topologyTemplateBase = JsonUtil.read(topoResponse, Topology.class, Context.getJsonMapper()).getData();
Map<String, NodeTemplate> nodeTemplates = topologyTemplateBase.getNodeTemplates();
// node templates count test
assertEquals(createdTopology.getTopology().getNodeTemplates().size(), nodeTemplates.size());
// node templates name / type test
for (Map.Entry<String, NodeTemplate> entry : createdTopology.getTopology().getNodeTemplates().entrySet()) {
assertTrue(nodeTemplates.containsKey(entry.getKey()));
assertTrue(nodeTemplates.get(entry.getKey()).getType().equals(entry.getValue().getType()));
}
}
use of org.alien4cloud.tosca.model.templates.Topology 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());
}
}
}
}
}
use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.
the class SuggestionService method postProcessSuggestionFromArchive.
public void postProcessSuggestionFromArchive(ParsingResult<ArchiveRoot> parsingResult) {
ArchiveRoot archiveRoot = parsingResult.getResult();
ParsingContext context = parsingResult.getContext();
if (archiveRoot.hasToscaTopologyTemplate()) {
Topology topology = archiveRoot.getTopology();
Map<String, NodeTemplate> nodeTemplateMap = topology.getNodeTemplates();
if (MapUtils.isEmpty(nodeTemplateMap)) {
return;
}
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplateMap.entrySet()) {
NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
String nodeName = nodeTemplateEntry.getKey();
if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
checkProperties(nodeName, nodeTemplate.getProperties(), NodeType.class, nodeTemplate.getType(), context);
}
Map<String, Capability> capabilityMap = nodeTemplate.getCapabilities();
if (MapUtils.isNotEmpty(capabilityMap)) {
for (Map.Entry<String, Capability> capabilityEntry : capabilityMap.entrySet()) {
String capabilityName = capabilityEntry.getKey();
Capability capability = capabilityEntry.getValue();
if (MapUtils.isNotEmpty(capability.getProperties())) {
checkProperties(nodeName + ".capabilities." + capabilityName, capability.getProperties(), CapabilityType.class, capability.getType(), context);
}
}
}
Map<String, RelationshipTemplate> relationshipTemplateMap = nodeTemplate.getRelationships();
if (MapUtils.isNotEmpty(relationshipTemplateMap)) {
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : relationshipTemplateMap.entrySet()) {
String relationshipName = relationshipEntry.getKey();
RelationshipTemplate relationship = relationshipEntry.getValue();
if (MapUtils.isNotEmpty(relationship.getProperties())) {
checkProperties(nodeName + ".relationships." + relationshipName, relationship.getProperties(), RelationshipType.class, relationship.getType(), context);
}
}
}
}
}
if (archiveRoot.hasToscaTypes()) {
Map<String, NodeType> allNodeTypes = archiveRoot.getNodeTypes();
if (MapUtils.isNotEmpty(allNodeTypes)) {
for (Map.Entry<String, NodeType> nodeTypeEntry : allNodeTypes.entrySet()) {
NodeType nodeType = nodeTypeEntry.getValue();
if (nodeType.getRequirements() != null && !nodeType.getRequirements().isEmpty()) {
for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) {
NodeFilter nodeFilter = requirementDefinition.getNodeFilter();
if (nodeFilter != null) {
Map<String, FilterDefinition> capabilitiesFilters = nodeFilter.getCapabilities();
if (MapUtils.isNotEmpty(capabilitiesFilters)) {
for (Map.Entry<String, FilterDefinition> capabilityFilterEntry : capabilitiesFilters.entrySet()) {
FilterDefinition filterDefinition = capabilityFilterEntry.getValue();
for (Map.Entry<String, List<PropertyConstraint>> constraintEntry : filterDefinition.getProperties().entrySet()) {
List<PropertyConstraint> constraints = constraintEntry.getValue();
checkPropertyConstraints("node_filter.capabilities", CapabilityType.class, capabilityFilterEntry.getKey(), constraintEntry.getKey(), constraints, context);
}
}
}
// FIXME check also the value properties filter of a node filter
}
}
}
}
}
}
}
Aggregations