Search in sources :

Example 21 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class CrudCSARSStepDefinition method I_have_the_CSAR_version_to_contain_a_dependency_to_version.

@Then("^I have the CSAR \"([^\"]*)\" version \"([^\"]*)\" to contain a dependency to \"([^\"]*)\" version \"([^\"]*)\"$")
public void I_have_the_CSAR_version_to_contain_a_dependency_to_version(String csarName, String csarVersion, String dependencyName, String dependencyVersion) throws Throwable {
    String response = Context.getRestClientInstance().get("/rest/v1/csars/" + csarName + ":" + csarVersion + "-SNAPSHOT");
    CsarInfoDTO csar = JsonUtil.read(response, CsarInfoDTO.class).getData();
    Assert.assertTrue(csar.getCsar().getDependencies().contains(new CSARDependency(dependencyName, dependencyVersion)));
}
Also used : CsarInfoDTO(alien4cloud.rest.csar.CsarInfoDTO) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Then(cucumber.api.java.en.Then)

Example 22 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class ServiceResourceService method create.

/**
 * Create a service.
 *
 * @param serviceName The unique name that defines the service from user point of view.
 * @param serviceVersion The id of the plugin used to communicate with the orchestrator.
 * @param serviceNodeType The type of the node type used to create the service.
 * @param serviceNodeVersion The version of the node type used to create the service.
 * @param environmentId In case the service is created out of an alien environment the id of the environment, null if not.
 * @return The generated identifier for the service.
 */
public String create(String serviceName, String serviceVersion, String serviceNodeType, String serviceNodeVersion, String environmentId) {
    ServiceResource serviceResource = new ServiceResource();
    // generate an unique id
    serviceResource.setId(UUID.randomUUID().toString());
    serviceResource.setName(serviceName);
    serviceResource.setVersion(serviceVersion);
    serviceResource.setEnvironmentId(environmentId);
    // build a node instance from the given type
    NodeType nodeType = toscaTypeSearchService.findOrFail(NodeType.class, serviceNodeType, serviceNodeVersion);
    serviceResource.setNodeInstance(nodeInstanceService.create(nodeType, serviceNodeVersion));
    serviceResource.setDependency(new CSARDependency(nodeType.getArchiveName(), nodeType.getArchiveVersion()));
    // ensure uniqueness and save
    save(serviceResource, true);
    // TODO: send an event: a service has been created
    return serviceResource.getId();
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) ServiceResource(alien4cloud.model.service.ServiceResource) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Example 23 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class ArchiveUploadService method preParsing.

@ToscaContextual
public Map<CSARDependency, CsarDependenciesBean> preParsing(Set<Path> paths, List<ParsingResult<Csar>> parsingResults) {
    Map<CSARDependency, CsarDependenciesBean> csarDependenciesBeans = Maps.newHashMap();
    for (Path path : paths) {
        try {
            // FIXME cleanup git import archives
            ParsingResult<CsarDependenciesBean> parsingResult = parser.parseImports(path);
            parsingResult.getResult().setPath(path);
            csarDependenciesBeans.put(parsingResult.getResult().getSelf(), parsingResult.getResult());
        } catch (ParsingException e) {
            ParsingResult<Csar> failedResult = new ParsingResult<>();
            failedResult.setContext(new ParsingContext(path.getFileName().toString()));
            failedResult.getContext().setParsingErrors(e.getParsingErrors());
            parsingResults.add(failedResult);
            log.debug("Not able to parse archive, ignoring it", e);
        }
    }
    return csarDependenciesBeans;
}
Also used : Path(java.nio.file.Path) ParsingResult(alien4cloud.tosca.parser.ParsingResult) ParsingContext(alien4cloud.tosca.parser.ParsingContext) ParsingException(alien4cloud.tosca.parser.ParsingException) CsarDependenciesBean(org.alien4cloud.tosca.model.CsarDependenciesBean) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Example 24 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class ArchiveRootPostProcessor method processImports.

/**
 * Process imports within the archive and compute its complete dependency set.
 * Resolve all dependency version conflicts using the following rules:
 * <ul>
 * <li>If two direct dependencies conflict with each other, use the latest version</li>
 * <li>If a transitive dependency conflicts with a direct dependency, use the direct dependency version</li>
 * <li>If two transitive dependency conflict with each other, use the latest version.</li>
 * </ul>
 *
 * @param archiveRoot The archive to process.
 */
private void processImports(ArchiveRoot archiveRoot) {
    if (archiveRoot.getArchive().getDependencies() == null || archiveRoot.getArchive().getDependencies().isEmpty()) {
        return;
    }
    // Dependencies defined in the import section only
    // These should override transitive deps regardless of type of conflict ?
    Set<CSARDependency> dependencies = archiveRoot.getArchive().getDependencies();
    // Ensure the archive does not import itself
    Csar archive = archiveRoot.getArchive();
    if (dependencies.contains(new CSARDependency(archive.getName(), archive.getVersion(), archive.getHash()))) {
        ParsingContextExecution.getParsingErrors().add(new ParsingError(ParsingErrorLevel.ERROR, ErrorCode.CSAR_IMPORT_ITSELF, AlienUtils.prefixWith(":", archive.getVersion(), archive.getName()), null, "Import itself", null, null));
    }
    /*
         * Three types of conflicts :
         * - A transitive dep has a different version than a direct dependency => Force transitive to direct version
         * - Transitive dependencies with the same name and different version are used => Use latest
         * - Direct dependencies with the same name and different version are used => Error or use latest ?
         */
    // 1. Resolve all direct dependencies using latest version
    dependencies.removeIf(dependency -> dependencyConflictsWithLatest(dependency, dependencies));
    // Compute all distinct transitives dependencies
    final Set<CSARDependency> transitiveDependencies = new HashSet<>(dependencies.stream().map(csarDependency -> ToscaContext.get().getArchive(csarDependency.getName(), csarDependency.getVersion())).map(Csar::getDependencies).filter(c -> c != null).reduce(Sets::union).orElse(Collections.emptySet()));
    // 2. Resolve all transitive vs. direct dependencies conflicts using the direct dependency's version
    transitiveDependencies.removeIf(transitiveDependency -> dependencyConflictsWithDirect(transitiveDependency, dependencies));
    // 3. Resolve all transitive dependencies conflicts using latest version
    transitiveDependencies.removeIf(transitiveDependency -> dependencyConflictsWithLatest(transitiveDependency, transitiveDependencies));
    // Merge all dependencies (direct + transitives)
    final Set<CSARDependency> mergedDependencies = new HashSet<>(Sets.union(dependencies, transitiveDependencies));
    archiveRoot.getArchive().setDependencies(mergedDependencies);
    // Update Tosca context with the complete dependency set
    ToscaContext.get().resetDependencies(mergedDependencies);
}
Also used : DataType(org.alien4cloud.tosca.model.types.DataType) VersionUtil(alien4cloud.utils.VersionUtil) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) HashSet(java.util.HashSet) Node(org.yaml.snakeyaml.nodes.Node) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) PropertyValue(org.alien4cloud.tosca.model.definitions.PropertyValue) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) Map(java.util.Map) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) RepositoryDefinition(org.alien4cloud.tosca.model.definitions.RepositoryDefinition) ToscaContext(alien4cloud.tosca.context.ToscaContext) PropertyUtil(alien4cloud.utils.PropertyUtil) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) Csar(org.alien4cloud.tosca.model.Csar) MapUtils(org.apache.commons.collections.MapUtils) AlienUtils(alien4cloud.utils.AlienUtils) ParsingErrorLevel(alien4cloud.tosca.parser.ParsingErrorLevel) Resource(javax.annotation.Resource) Set(java.util.Set) ErrorCode(alien4cloud.tosca.parser.impl.ErrorCode) Sets(com.google.common.collect.Sets) Objects(java.util.Objects) Component(org.springframework.stereotype.Component) ParsingContextExecution(alien4cloud.tosca.parser.ParsingContextExecution) NormativeCredentialConstant(org.alien4cloud.tosca.normative.constants.NormativeCredentialConstant) Collections(java.util.Collections) ParsingError(alien4cloud.tosca.parser.ParsingError) Csar(org.alien4cloud.tosca.model.Csar) ParsingError(alien4cloud.tosca.parser.ParsingError) Sets(com.google.common.collect.Sets) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) HashSet(java.util.HashSet)

Example 25 with CSARDependency

use of org.alien4cloud.tosca.model.CSARDependency in project alien4cloud by alien4cloud.

the class LaxImportParser method parse.

@Override
public CSARDependency parse(Node node, ParsingContextExecution context) {
    String valueAsString = scalarParser.parse(node, context);
    if (StringUtils.isNotBlank(valueAsString)) {
        if (valueAsString.contains(":")) {
            String[] dependencyStrs = valueAsString.split(":");
            if (dependencyStrs.length == 2) {
                String dependencyName = dependencyStrs[0];
                String dependencyVersion = dependencyStrs[1];
                // check that version has the righ format
                try {
                    VersionUtil.parseVersion(dependencyVersion);
                } catch (InvalidVersionException e) {
                    context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Version specified in the dependency is not a valid version.", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
                    return null;
                }
                return new CSARDependency(dependencyName, dependencyVersion);
            }
            context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Import definition is not valid", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
        } else {
            context.getParsingErrors().add(new ParsingError(ParsingErrorLevel.WARNING, ErrorCode.SYNTAX_ERROR, "Relative import is currently not supported in Alien 4 Cloud", node.getStartMark(), "Dependency should be specified as name:version", node.getEndMark(), "Import"));
        }
    }
    return null;
}
Also used : ParsingError(alien4cloud.tosca.parser.ParsingError) InvalidVersionException(alien4cloud.utils.version.InvalidVersionException) CSARDependency(org.alien4cloud.tosca.model.CSARDependency)

Aggregations

CSARDependency (org.alien4cloud.tosca.model.CSARDependency)50 Csar (org.alien4cloud.tosca.model.Csar)16 Test (org.junit.Test)11 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)8 Set (java.util.Set)7 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)6 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)6 ServiceResource (alien4cloud.model.service.ServiceResource)5 Capability (org.alien4cloud.tosca.model.templates.Capability)5 Topology (org.alien4cloud.tosca.model.templates.Topology)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)5 NotFoundException (alien4cloud.exception.NotFoundException)4 ParsingError (alien4cloud.tosca.parser.ParsingError)4 HashSet (java.util.HashSet)4 CsarDependenciesBean (org.alien4cloud.tosca.model.CsarDependenciesBean)4 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)3 ParsingException (alien4cloud.tosca.parser.ParsingException)3 VersionConflictException (alien4cloud.exception.VersionConflictException)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 Location (alien4cloud.model.orchestrators.locations.Location)2