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