Search in sources :

Example 36 with Topology

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

the class ApplicationVersionService method createApplicationVersion.

/**
 * Create a new version for an application. The new application version can be created from an exiting application version of not.
 * When created from an existing application version all topology versions from the original version will be created in the new application version.
 *
 * @param applicationId The id of the application for which to create the version.
 * @param version The new version.
 * @param description The description.
 * @param originalId The version (application version or topology) from witch to create the new application version.
 * @param originalIsAppVersion True if the originalId is the id of an application version id, false if it is the id of a topology id.
 */
public ApplicationVersion createApplicationVersion(String applicationId, String version, String description, String originalId, boolean originalIsAppVersion) {
    if (isVersionNameExist(applicationId, version)) {
        throw new AlreadyExistException("A version " + version + " already exists for application " + applicationId + ".");
    }
    ApplicationVersion appVersion = new ApplicationVersion();
    appVersion.setDelegateId(applicationId);
    appVersion.setVersion(version);
    appVersion.setNestedVersion(VersionUtil.parseVersion(version));
    appVersion.setReleased(!VersionUtil.isSnapshot(version));
    appVersion.setDescription(description);
    appVersion.setTopologyVersions(Maps.newHashMap());
    // Create all topology versions based on the previous version configuration
    if (originalIsAppVersion && originalId != null) {
        ApplicationVersion originalAppVersion = getOrFail(originalId);
        // Ensure that the id of the original application version is indeed the same as the one of the application
        if (!applicationId.equals(originalAppVersion.getApplicationId())) {
            throw new AuthorizationServiceException("Creating a new version of an application from the version of another application is not authorized.");
        }
        // if the version is a release version we have to ensure that every sub-topology can be released
        importTopologiesFromPreviousVersion(appVersion, originalAppVersion);
    } else {
        // Don't create the application version from an existing version but from either a topology template or start a blank topology
        Topology topology;
        if (originalId == null) {
            topology = new Topology();
        } else {
            topology = getTemplateTopology(originalId);
        }
        // Create a default topology version for this application version.
        ApplicationTopologyVersion applicationTopologyVersion = createTopologyVersion(applicationId, version, null, "default topology", topology);
        appVersion.getTopologyVersions().put(version, applicationTopologyVersion);
    }
    // Save the version object
    alienDAO.save(appVersion);
    return appVersion;
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) AuthorizationServiceException(org.springframework.security.access.AuthorizationServiceException) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 37 with Topology

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

the class ApplicationVersionService method createTopologyVersion.

/**
 * Create a new application topology version. If originalId is not null the topology will be created:
 * - From a topology template if originalIsVersion is false
 * - From a version of the application if
 *
 * @param applicationId The id of the application for which to create the new application topology version.
 * @param versionId The id of the version for which to create a new topology version.
 * @param qualifier The qualifier for this specific topology version.
 * @param description The description of the topology version.
 * @param originalId The id that points to a topology used to initialize the new application topology version.
 * @param originalIsVersion True if the originalId is the id of an application topology version, false if this is the id of a topology template.
 */
public void createTopologyVersion(String applicationId, String versionId, String qualifier, String description, String originalId, boolean originalIsVersion) {
    // validate the qualifier first if not null
    if (qualifier != null) {
        VersionUtil.isQualifierValidOrFail(qualifier);
    }
    // Get the version from elastic-search
    ApplicationVersion applicationVersion = getOrFail(versionId);
    Topology topology;
    if (originalId == null) {
        topology = new Topology();
    } else {
        if (originalIsVersion) {
            // we need to check that the version is indeed a previous version of this application
            ApplicationVersion originalVersion = getOrFailByArchiveId(originalId);
            if (!applicationId.equals(originalVersion.getApplicationId())) {
                throw new AuthorizationServiceException("Creating a new version of an application from the version of another application is not authorized.");
            }
            topology = topologyServiceCore.getOrFail(originalId);
        } else {
            topology = getTemplateTopology(originalId);
        }
    }
    String version = getTopologyVersion(applicationVersion.getVersion(), qualifier);
    if (applicationVersion.getTopologyVersions().get(version) != null) {
        throw new AlreadyExistException("The topology version [" + versionId + "] already exists for application [" + applicationId + "]");
    }
    // Create a new application version based on an existing topology.
    ApplicationTopologyVersion applicationTopologyVersion = createTopologyVersion(applicationId, version, qualifier, description, topology);
    applicationVersion.getTopologyVersions().put(version, applicationTopologyVersion);
    alienDAO.save(applicationVersion);
}
Also used : ApplicationVersion(alien4cloud.model.application.ApplicationVersion) AuthorizationServiceException(org.springframework.security.access.AuthorizationServiceException) Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 38 with Topology

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

the class ApplicationVersionService method importTopologiesFromPreviousVersion.

private void importTopologiesFromPreviousVersion(ApplicationVersion newVersion, ApplicationVersion originalAppVersion) {
    // if the version is a release version we have to ensure that every sub-topology can be released
    Map<String, Topology> previousTopologies = Maps.newHashMap();
    // If the previous version was not a release and we want to create a release version then we have to check that all topologies can indeed be released.
    boolean mustCheckReleasable = newVersion.isReleased() && !originalAppVersion.isReleased();
    for (ApplicationTopologyVersion originalAppTopoVersion : originalAppVersion.getTopologyVersions().values()) {
        // Ensure that all versions can be created and does not exists already.
        csarService.ensureUniqueness(newVersion.getApplicationId(), newVersion.getVersion() + "-" + originalAppTopoVersion.getQualifier());
        // Cache the previous topology for duplication when creating the new version.
        Topology topology = alienDAO.findById(Topology.class, originalAppTopoVersion.getArchiveId());
        if (mustCheckReleasable) {
            // If the new version is a release, we have to ensure that all dependencies are released
            checkTopologyReleasable(topology);
        }
        previousTopologies.put(originalAppTopoVersion.getArchiveId(), topology);
    }
    for (ApplicationTopologyVersion originalAppTopoVersion : originalAppVersion.getTopologyVersions().values()) {
        String newTopologyVersion = getTopologyVersion(newVersion.getVersion(), originalAppTopoVersion.getQualifier());
        ApplicationTopologyVersion applicationTopologyVersion = createTopologyVersion(newVersion.getApplicationId(), newTopologyVersion, originalAppTopoVersion.getQualifier(), originalAppTopoVersion.getDescription(), previousTopologies.get(originalAppTopoVersion.getArchiveId()));
        // Add the newly created application version to the list.
        newVersion.getTopologyVersions().put(newTopologyVersion, applicationTopologyVersion);
    }
}
Also used : Topology(org.alien4cloud.tosca.model.templates.Topology) ApplicationTopologyVersion(alien4cloud.model.application.ApplicationTopologyVersion)

Example 39 with Topology

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

the class TopologyCompositionService method renameNodes.

private void renameNodes(CompositionCouple compositionCouple) {
    Topology topology = compositionCouple.child;
    String[] nodeNames = new String[topology.getNodeTemplates().size()];
    nodeNames = topology.getNodeTemplates().keySet().toArray(nodeNames);
    for (String nodeName : nodeNames) {
        String newName = ensureNodeNameIsUnique(topology.getNodeTemplates().keySet(), compositionCouple.nodeNamePrefix + nodeName, 0);
        renameNodeTemplate(topology, nodeName, newName);
    }
}
Also used : Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 40 with Topology

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

the class TopologyCompositionService method recursivelyDetectTopologyCompositionCyclicReference.

/**
 * Deeply explore composition in order to detect cyclic reference: if a descendant references the mainTopologyId.
 */
public void recursivelyDetectTopologyCompositionCyclicReference(String mainTopologyId, String substitutionTopologyId) {
    Topology child = topologyServiceCore.getOrFail(substitutionTopologyId);
    if (child == null || child.getNodeTemplates() == null || child.getNodeTemplates().isEmpty()) {
        return;
    }
    for (Entry<String, NodeTemplate> nodeEntry : child.getNodeTemplates().entrySet()) {
        String type = nodeEntry.getValue().getType();
        NodeType nodeType = csarRepoSearchService.getElementInDependencies(NodeType.class, type, child.getDependencies());
        if (nodeType.getSubstitutionTopologyId() != null) {
            if (nodeType.getSubstitutionTopologyId().equals(mainTopologyId)) {
                throw new CyclicReferenceException("Cyclic reference : a topology template can not reference itself (even indirectly)");
            }
            recursivelyDetectTopologyCompositionCyclicReference(mainTopologyId, nodeType.getSubstitutionTopologyId());
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Topology(org.alien4cloud.tosca.model.templates.Topology) CyclicReferenceException(alien4cloud.exception.CyclicReferenceException)

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