Search in sources :

Example 6 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive in project alien4cloud by alien4cloud.

the class PluginArchiveIndexer method getArchivesToIndex.

/**
 * From all exposed plugin archives of the location, get the one that are not yet indexed
 *
 * @param orchestrator
 * @param location
 * @return an object of type {@link ArchiveToIndex} with the indexable archives and the full list of dependencies
 */
private ArchiveToIndex getArchivesToIndex(Orchestrator orchestrator, Location location) {
    Set<CSARDependency> dependencies = Sets.newHashSet();
    IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.getOrFail(orchestrator.getId());
    ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
    List<PluginArchive> allPluginArchives = configuratorPlugin.pluginArchives();
    Set<PluginArchive> archivesToIndex = Sets.newHashSet();
    for (PluginArchive pluginArchive : safe(allPluginArchives)) {
        ArchiveRoot archive = pluginArchive.getArchive();
        Csar csar = csarService.get(archive.getArchive().getName(), archive.getArchive().getVersion());
        String lastParsedHash = null;
        if (csar == null) {
            // the archive does not exist into the repository: should be indexed
            lastParsedHash = archive.getArchive().getHash();
            archivesToIndex.add(pluginArchive);
        } else {
            // Else, just take the hash
            lastParsedHash = csar.getHash();
        }
        if (archive.getArchive().getDependencies() != null) {
            dependencies.addAll(archive.getArchive().getDependencies());
        }
        dependencies.add(new CSARDependency(archive.getArchive().getName(), archive.getArchive().getVersion(), lastParsedHash));
    }
    return new ArchiveToIndex(dependencies, archivesToIndex);
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Example 7 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive in project alien4cloud by alien4cloud.

the class PluginArchiveIndexer method indexOrchestratorArchives.

/**
 * Index archives defined at the orchestrator level by a plugin.
 *
 * @param orchestratorFactory The orchestrator factory.
 * @param orchestratorInstance The instance of the orchestrator (created by the factory).
 */
public void indexOrchestratorArchives(IOrchestratorPluginFactory<IOrchestratorPlugin<?>, ?> orchestratorFactory, IOrchestratorPlugin<Object> orchestratorInstance) {
    for (PluginArchive pluginArchive : orchestratorInstance.pluginArchives()) {
        try {
            archiveIndexer.importArchive(pluginArchive.getArchive(), CSARSource.ORCHESTRATOR, pluginArchive.getArchiveFilePath(), Lists.<ParsingError>newArrayList());
            publishLocationTypeIndexedEvent(pluginArchive.getArchive().getNodeTypes().values(), orchestratorFactory, null);
        } catch (AlreadyExistException e) {
            log.debug("Skipping orchestrator archive import as the released version already exists in the repository. " + e.getMessage());
        } catch (CSARUsedInActiveDeployment e) {
            log.debug("Skipping orchestrator archive import as it is used in an active deployment. " + e.getMessage());
        } catch (ToscaTypeAlreadyDefinedInOtherCSAR e) {
            log.debug("Skipping orchestrator archive import, it's archive contain's a tosca type already defined in an other archive." + e.getMessage());
        }
    }
}
Also used : PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) CSARUsedInActiveDeployment(alien4cloud.component.repository.exception.CSARUsedInActiveDeployment) ToscaTypeAlreadyDefinedInOtherCSAR(alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 8 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive in project alien4cloud by alien4cloud.

the class AbstractPluginArchiveService method parse.

/**
 * Parse an archive given a path relative to the plugin
 *
 * @param archiveRelativePath Relative path where the archive is in the plugin
 * @return The parsed archive as a @{@link PluginArchive}
 * @throws PluginArchiveException
 */
public PluginArchive parse(String archiveRelativePath) throws PluginArchiveException {
    String archiveErrorMsge = "Archive in path: [ " + archiveRelativePath + " ]";
    // Parse the archives
    ParsingResult<ArchiveRoot> result;
    Path archivePath = selfContext.getPluginPath().resolve(archiveRelativePath);
    try {
        result = this.archiveParser.parseDir(archivePath, AlienConstants.GLOBAL_WORKSPACE_ID);
    } catch (ParsingException e) {
        throw new PluginArchiveException("Failed to parse " + archiveErrorMsge, e);
    }
    if (result.getContext().getParsingErrors() != null && !result.getContext().getParsingErrors().isEmpty()) {
        log.error("Parsing errors for" + archiveErrorMsge);
        for (ParsingError parsingError : result.getContext().getParsingErrors()) {
            log.error(parsingError.toString());
        }
        throw new PluginArchiveException(archiveErrorMsge + " is invalid");
    }
    return new PluginArchive(result.getResult(), archivePath);
}
Also used : Path(java.nio.file.Path) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) ParsingException(alien4cloud.tosca.parser.ParsingException) PluginArchiveException(alien4cloud.plugin.exception.PluginArchiveException)

Example 9 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive in project alien4cloud by alien4cloud.

the class MockOpenStackLocationConfigurer method addToAchive.

private void addToAchive(List<PluginArchive> archives, String path) throws ParsingException {
    Path archivePath = selfContext.getPluginPath().resolve(path);
    // Parse the archives
    ParsingResult<ArchiveRoot> result = archiveParser.parseDir(archivePath, AlienConstants.GLOBAL_WORKSPACE_ID);
    PluginArchive pluginArchive = new PluginArchive(result.getResult(), archivePath);
    archives.add(pluginArchive);
}
Also used : Path(java.nio.file.Path) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive)

Example 10 with PluginArchive

use of alien4cloud.orchestrators.plugin.model.PluginArchive in project yorc-a4c-plugin by ystia.

the class PluginArchiveService method parsePluginArchives.

public PluginArchive parsePluginArchives(String archiveRelativePath) {
    // Parse the archives
    ParsingResult<ArchiveRoot> result;
    Path archivePath = selfContext.getPluginPath().resolve(archiveRelativePath);
    try {
        result = this.archiveParser.parseDir(archivePath, AlienConstants.GLOBAL_WORKSPACE_ID);
    } catch (ParsingException e) {
        log.error("Failed to parse archive, plugin won't work", e);
        throw new RuntimeException("Failed to parse archive, plugin won't work", e);
    }
    if (result.getContext().getParsingErrors() != null && !result.getContext().getParsingErrors().isEmpty()) {
        log.error("Parsing errors for " + archiveRelativePath);
        for (ParsingError parsingError : result.getContext().getParsingErrors()) {
            log.error(parsingError.toString());
        }
        throw new RuntimeException("Plugin archive is invalid, plugin won't work");
    }
    return new PluginArchive(result.getResult(), archivePath);
}
Also used : Path(java.nio.file.Path) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) PluginArchive(alien4cloud.orchestrators.plugin.model.PluginArchive) ParsingException(alien4cloud.tosca.parser.ParsingException)

Aggregations

PluginArchive (alien4cloud.orchestrators.plugin.model.PluginArchive)10 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)6 Path (java.nio.file.Path)5 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)3 List (java.util.List)3 Csar (org.alien4cloud.tosca.model.Csar)3 Usage (alien4cloud.model.common.Usage)2 Location (alien4cloud.model.orchestrators.locations.Location)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 ParsingException (alien4cloud.tosca.parser.ParsingException)2 ArrayList (java.util.ArrayList)2 CSARUsedInActiveDeployment (alien4cloud.component.repository.exception.CSARUsedInActiveDeployment)1 ToscaTypeAlreadyDefinedInOtherCSAR (alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR)1 LocationArchiveDeleteRequested (alien4cloud.events.LocationArchiveDeleteRequested)1 AlreadyExistException (alien4cloud.exception.AlreadyExistException)1 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)1 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)1 PluginArchiveException (alien4cloud.plugin.exception.PluginArchiveException)1 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1