Search in sources :

Example 16 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class PolicyTemplatePostProcessor method process.

@Override
public void process(final PolicyTemplate instance) {
    // ensure type exists
    referencePostProcessor.process(new ReferencePostProcessor.TypeReference(instance, instance.getType(), PolicyType.class));
    final PolicyType policyType = ToscaContext.get(PolicyType.class, instance.getType());
    if (policyType == null) {
        // error managed by the reference post processor.
        return;
    }
    final Topology topology = ((ArchiveRoot) ParsingContextExecution.getRoot().getWrappedInstance()).getTopology();
    // check that the targets are exiting node templates
    // TODO should we also check the type of the target, see if it matches with one provided in PolicyType.getTargets() ?
    safe(instance.getTargets()).forEach(target -> {
        if (!safe((topology.getNodeTemplates())).containsKey(target)) {
            // Dispatch an error.
            Node node = ParsingContextExecution.getObjectToNodeMap().get(instance.getTargets());
            ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.POLICY_TARGET_NOT_FOUND, instance.getName(), node.getStartMark(), null, node.getEndMark(), target));
        }
    });
    // Merge the policy template with data coming from the type (default values etc.).
    PolicyTemplate tempObject = TemplateBuilder.buildPolicyTemplate(policyType, instance, false);
    instance.setProperties(tempObject.getProperties());
    propertyValueChecker.checkProperties(policyType, instance.getProperties(), instance.getName());
}
Also used : PolicyType(org.alien4cloud.tosca.model.types.PolicyType) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) Node(org.yaml.snakeyaml.nodes.Node) Topology(org.alien4cloud.tosca.model.templates.Topology) PolicyTemplate(org.alien4cloud.tosca.model.templates.PolicyTemplate)

Example 17 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class EditionContextManager method setup.

@PostConstruct
public void setup() {
    // initialize the cache
    contextCache = CacheBuilder.newBuilder().expireAfterAccess(30, TimeUnit.MINUTES).removalListener(new RemovalListener<String, EditionContext>() {

        @Override
        public void onRemoval(RemovalNotification<String, EditionContext> removalNotification) {
            log.debug("Topology edition context with id {} has been evicted. {} pending operations are lost.", removalNotification.getKey(), removalNotification.getValue().getOperations().size());
            for (AbstractEditorOperation operation : removalNotification.getValue().getOperations()) {
                if (operation instanceof UpdateFileOperation) {
                    String fileId = ((UpdateFileOperation) operation).getTempFileId();
                    if (artifactRepository.isFileExist(fileId)) {
                        artifactRepository.deleteFile(fileId);
                    }
                }
            }
        }
    }).build(new CacheLoader<String, EditionContext>() {

        @Override
        public EditionContext load(String csarId) throws Exception {
            log.debug("Loading edition context for archive {}", csarId);
            Csar csar = csarService.getOrFail(csarId);
            Topology topology = topologyServiceCore.getOrFail(csarId);
            // check if the topology git repository has been created already
            Path topologyGitPath = repositoryService.createGitDirectory(csar);
            log.debug("Edition context for archive {} loaded", csar);
            return new EditionContext(csar, topology, topologyGitPath);
        }
    });
}
Also used : Path(java.nio.file.Path) Csar(org.alien4cloud.tosca.model.Csar) UpdateFileOperation(org.alien4cloud.tosca.editor.operations.UpdateFileOperation) AbstractEditorOperation(org.alien4cloud.tosca.editor.operations.AbstractEditorOperation) Topology(org.alien4cloud.tosca.model.templates.Topology) PostConstruct(javax.annotation.PostConstruct)

Example 18 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class EditionContextManager method reset.

/**
 * Reset the state of the topology context to it's initial state.
 *
 * @throws IOException In case the parsing of the directory content fails.
 */
public void reset() throws IOException {
    Topology topology = topologyServiceCore.getOrFail(getTopology().getId());
    contextThreadLocal.get().reset(topology);
    ToscaContext.set(contextThreadLocal.get().getToscaContext());
}
Also used : Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 19 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class TopologyCatalogService method createTopologyAsTemplate.

@Override
public Topology createTopologyAsTemplate(String name, String description, String version, String workspace, String fromTopologyId) {
    NameValidationUtils.validate("topologyTemplateName", name);
    // Every version of a topology template has a Cloud Service Archive
    Csar csar = new Csar(name, StringUtils.isNotBlank(version) ? version : VersionUtil.DEFAULT_VERSION_NAME);
    csar.setWorkspace(workspace);
    csar.setDelegateType(ArchiveDelegateType.CATALOG.toString());
    csar.setToscaDefinitionsVersion(ToscaParser.LATEST_DSL);
    if (description == null) {
        csar.setDescription("This archive has been created with alien4cloud.");
    } else {
        csar.setDescription("Enclosing archive for topology " + description);
    }
    Topology topology;
    if (fromTopologyId != null) {
        // "cloning" the topology
        topology = alienDAO.findById(Topology.class, fromTopologyId);
    } else {
        topology = new Topology();
    }
    topology.setDescription(description);
    topology.setArchiveName(csar.getName());
    topology.setArchiveVersion(csar.getVersion());
    topology.setWorkspace(csar.getWorkspace());
    archiveIndexer.importNewArchive(csar, topology, null);
    return topology;
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 20 with Topology

use of org.alien4cloud.tosca.model.templates.Topology in project alien4cloud by alien4cloud.

the class EditorService method checkTopologyRecovery.

/**
 * Checks if the topology needs to be recovered and eventually throws an error.
 * The {@link RecoverTopologyOperation} is cache for later use in recovering process
 */
public void checkTopologyRecovery() {
    Topology topology = EditionContextManager.getTopology();
    EditionContext context = EditionContextManager.get();
    context.setRecoveryOperation(recoveryHelperService.buildRecoveryOperation(topology));
    if (context.getRecoveryOperation() != null) {
        throw new RecoverTopologyException("The topology needs to be recovered.", context.getRecoveryOperation());
    }
}
Also used : Topology(org.alien4cloud.tosca.model.templates.Topology) RecoverTopologyException(org.alien4cloud.tosca.editor.exception.RecoverTopologyException)

Aggregations

Topology (org.alien4cloud.tosca.model.templates.Topology)80 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)23 Map (java.util.Map)21 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)17 Csar (org.alien4cloud.tosca.model.Csar)17 Application (alien4cloud.model.application.Application)15 NotFoundException (alien4cloud.exception.NotFoundException)14 ApiOperation (io.swagger.annotations.ApiOperation)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ApplicationTopologyVersion (alien4cloud.model.application.ApplicationTopologyVersion)12 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)12 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)12 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)10 FlowExecutionContext (org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext)10 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 Component (org.springframework.stereotype.Component)9 IOException (java.io.IOException)8 List (java.util.List)8 Set (java.util.Set)8 DeploymentMatchingConfiguration (org.alien4cloud.alm.deployment.configuration.model.DeploymentMatchingConfiguration)8