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