Search in sources :

Example 16 with AlreadyExistException

use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.

the class PluginArchiveIndexer method indexArchive.

private void indexArchive(PluginArchive pluginArchive, Orchestrator orchestrator, Location location) {
    ArchiveRoot archive = pluginArchive.getArchive();
    // inject a specific tag to allow components catalog filtering search
    injectWorkSpace(archive.getNodeTypes().values(), orchestrator, location);
    injectWorkSpace(archive.getArtifactTypes().values(), orchestrator, location);
    injectWorkSpace(archive.getCapabilityTypes().values(), orchestrator, location);
    injectWorkSpace(archive.getRelationshipTypes().values(), orchestrator, location);
    List<ParsingError> parsingErrors = Lists.newArrayList();
    // index the archive in alien catalog
    try {
        archiveIndexer.importArchive(archive, CSARSource.ORCHESTRATOR, pluginArchive.getArchiveFilePath(), parsingErrors);
    } catch (AlreadyExistException e) {
        log.debug("Skipping location archive import as the released version already exists in the repository.");
    } 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());
    }
    // Publish event to allow plugins to post-process elements (portability plugin for example).
    publishLocationTypeIndexedEvent(archive.getNodeTypes().values(), orchestrator, location);
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) ParsingError(alien4cloud.tosca.parser.ParsingError) CSARUsedInActiveDeployment(alien4cloud.component.repository.exception.CSARUsedInActiveDeployment) ToscaTypeAlreadyDefinedInOtherCSAR(alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 17 with AlreadyExistException

use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.

the class OrchestratorStateService method load.

/**
 * Load and connect the given orchestrator.
 *
 * @param orchestrator the orchestrator to load and connect.
 */
private void load(Orchestrator orchestrator) throws PluginConfigurationException {
    log.info("Loading and connecting orchestrator {} (id: {})", orchestrator.getName(), orchestrator.getId());
    // check that the orchestrator is not already loaded.
    if (orchestratorPluginService.get(orchestrator.getId()) != null) {
        throw new AlreadyExistException("Plugin is already loaded.");
    }
    // switch the state to connecting
    orchestrator.setState(OrchestratorState.CONNECTING);
    alienDAO.save(orchestrator);
    // TODO move below in a thread to perform plugin loading and connection asynchronously
    IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
    IOrchestratorPlugin<Object> orchestratorInstance = orchestratorFactory.newInstance();
    // Set the configuration for the provider
    OrchestratorConfiguration orchestratorConfiguration = orchestratorConfigurationService.getConfigurationOrFail(orchestrator.getId());
    try {
        Object configuration = orchestratorConfigurationService.configurationAsValidObject(orchestrator.getId(), orchestratorConfiguration.getConfiguration());
        orchestratorInstance.setConfiguration(orchestrator.getId(), configuration);
    } catch (IOException e) {
        throw new PluginConfigurationException("Failed convert configuration json in object.", e);
    }
    // index the archive in alien catalog
    archiveIndexer.indexOrchestratorArchives(orchestratorFactory, orchestratorInstance);
    // connect the orchestrator
    orchestratorInstance.init(deploymentService.getCloudActiveDeploymentContexts(orchestrator.getId()));
    // register the orchestrator instance to be polled for updates
    orchestratorPluginService.register(orchestrator.getId(), orchestratorInstance);
    orchestrator.setState(OrchestratorState.CONNECTED);
    alienDAO.save(orchestrator);
    if (orchestratorInstance instanceof ILocationAutoConfigurer) {
        // trigger locations auto-configurations
        locationService.autoConfigure(orchestrator, (ILocationAutoConfigurer) orchestratorInstance);
    }
    indexLocationsArchives(orchestrator);
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ILocationAutoConfigurer(alien4cloud.orchestrators.plugin.ILocationAutoConfigurer) IOException(java.io.IOException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) OrchestratorConfiguration(alien4cloud.model.orchestrators.OrchestratorConfiguration)

Example 18 with AlreadyExistException

use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.

the class OrchestratorStateService method initialize.

/**
 * Initialize all orchestrator that have a non-disabled state.
 * Note: Each orchestrator initialization is down in it's own thread so it doesn't impact application startup or other orchestrator connection.
 *
 * @param callback the callback to be executed when initialize finish
 */
public ListenableFuture<?> initialize(FutureCallback callback) {
    ListeningExecutorService executorService = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool());
    try {
        List<ListenableFuture<?>> futures = new ArrayList<>();
        // get all the orchestrator that are not disabled
        final List<Orchestrator> enabledOrchestratorList = orchestratorService.getAllEnabledOrchestrators();
        if (enabledOrchestratorList == null || enabledOrchestratorList.isEmpty()) {
            return Futures.immediateFuture(null);
        }
        log.info("Initializing orchestrators");
        for (final Orchestrator orchestrator : enabledOrchestratorList) {
            // error in initialization and timeouts should not impact startup time of Alien 4 cloud and other PaaS Providers.
            ListenableFuture<?> future = executorService.submit(new Runnable() {

                @Override
                public void run() {
                    try {
                        load(orchestrator);
                    } catch (AlreadyExistException e) {
                        log.info("Orchestrator was already loaded at initialization for {}.", orchestrator.getId());
                    } catch (Exception e) {
                        // we have to catch everything as we don't know what a plugin can do here and cannot interrupt startup.
                        // Any orchestrator that failed to load will be considered as DISABLED as the registration didn't occurred
                        log.error("Unexpected error in plugin", e);
                        orchestrator.setState(OrchestratorState.DISABLED);
                        alienDAO.save(orchestrator);
                    }
                }
            });
            futures.add(future);
        }
        ListenableFuture<?> combinedFuture = Futures.allAsList(futures);
        if (callback != null) {
            Futures.addCallback(combinedFuture, callback);
        }
        Futures.addCallback(combinedFuture, new FutureCallback<Object>() {

            @Override
            public void onSuccess(Object result) {
                log.info("{} Orchestrators loaded", enabledOrchestratorList.size());
            }

            @Override
            public void onFailure(Throwable t) {
                log.error("Unable to load orchestrators", t);
            }
        });
        return combinedFuture;
    } finally {
        executorService.shutdown();
    }
}
Also used : ArrayList(java.util.ArrayList) Orchestrator(alien4cloud.model.orchestrators.Orchestrator) AlreadyExistException(alien4cloud.exception.AlreadyExistException) IOException(java.io.IOException) PluginConfigurationException(alien4cloud.paas.exception.PluginConfigurationException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 19 with AlreadyExistException

use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.

the class TopologyTreeBuilderService method fillType.

@SuppressWarnings("unchecked")
private <V extends AbstractInheritableToscaType> void fillType(Topology topology, AbstractInstantiableTemplate template, IPaaSTemplate<V> paaSTemplate, Class<V> clazz) {
    V indexedToscaElement = ToscaContext.getOrFail(clazz, template.getType());
    paaSTemplate.setIndexedToscaElement(indexedToscaElement);
    List<String> derivedFroms = indexedToscaElement.getDerivedFrom();
    List<V> derivedFromTypes = Lists.newArrayList();
    if (derivedFroms != null) {
        for (String derivedFrom : derivedFroms) {
            derivedFromTypes.add(ToscaContext.get(clazz, derivedFrom));
        }
    }
    paaSTemplate.setDerivedFroms(derivedFromTypes);
    try {
        Path csarPath = repository.getCSAR(indexedToscaElement.getArchiveName(), indexedToscaElement.getArchiveVersion());
        paaSTemplate.setCsarPath(csarPath);
    } catch (AlreadyExistException e) {
        log.debug("No csarPath for " + indexedToscaElement + "; not setting in " + paaSTemplate);
    }
}
Also used : Path(java.nio.file.Path) AlreadyExistException(alien4cloud.exception.AlreadyExistException)

Example 20 with AlreadyExistException

use of alien4cloud.exception.AlreadyExistException in project alien4cloud by alien4cloud.

the class RenameGroupProcessor method process.

@Override
public void process(Csar csar, Topology topology, RenameGroupOperation operation) {
    if (operation.getNewGroupName() == null || !operation.getNewGroupName().matches("\\w+")) {
        throw new InvalidNameException("groupName", operation.getGroupName(), "\\w+");
    }
    if (topology.getGroups() == null) {
        throw new NotFoundException("Group with name [" + operation.getGroupName() + "] does not exists and cannot be renamed.");
    }
    if (topology.getGroups().containsKey(operation.getNewGroupName())) {
        throw new AlreadyExistException("Group with name [" + operation.getNewGroupName() + "] already exists, please choose another name");
    }
    NodeGroup nodeGroup = topology.getGroups().remove(operation.getGroupName());
    if (nodeGroup == null) {
        throw new NotFoundException("Group with name [" + operation.getGroupName() + "] does not exists and cannot be renamed.");
    }
    nodeGroup.setName(operation.getNewGroupName());
    Map<String, NodeTemplate> nodeTemplates = TopologyUtils.getNodeTemplates(topology);
    for (NodeTemplate nodeTemplate : nodeTemplates.values()) {
        if (nodeTemplate.getGroups() != null) {
            if (nodeTemplate.getGroups().remove(operation.getGroupName())) {
                nodeTemplate.getGroups().add(operation.getNewGroupName());
            }
        }
    }
    topology.getGroups().put(operation.getNewGroupName(), nodeGroup);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) InvalidNameException(alien4cloud.exception.InvalidNameException) NotFoundException(alien4cloud.exception.NotFoundException) AlreadyExistException(alien4cloud.exception.AlreadyExistException) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Aggregations

AlreadyExistException (alien4cloud.exception.AlreadyExistException)26 NotFoundException (alien4cloud.exception.NotFoundException)9 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)7 CSARUsedInActiveDeployment (alien4cloud.component.repository.exception.CSARUsedInActiveDeployment)6 ToscaTypeAlreadyDefinedInOtherCSAR (alien4cloud.component.repository.exception.ToscaTypeAlreadyDefinedInOtherCSAR)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)5 InvalidNameException (alien4cloud.exception.InvalidNameException)4 SubstitutionTarget (org.alien4cloud.tosca.model.templates.SubstitutionTarget)4 Audit (alien4cloud.audit.annotation.Audit)3 ParsingException (alien4cloud.tosca.parser.ParsingException)3 ApiOperation (io.swagger.annotations.ApiOperation)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)2 DeploymentTopology (alien4cloud.model.deployment.DeploymentTopology)2 PluginConfigurationException (alien4cloud.paas.exception.PluginConfigurationException)2 ParsingError (alien4cloud.tosca.parser.ParsingError)2 Csar (org.alien4cloud.tosca.model.Csar)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 Application (alien4cloud.model.application.Application)1