use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin in project alien4cloud by alien4cloud.
the class LocationResourceService method getLocationResourcesFromOrchestrator.
/*
* (non-Javadoc)
*
* @see
* alien4cloud.orchestrators.locations.services.ILocationResourceService#getLocationResourcesFromOrchestrator(alien4cloud.model.orchestrators.locations.
* Location)
*/
@Override
public LocationResources getLocationResourcesFromOrchestrator(Location location) {
LocationResources locationResources = new LocationResources();
Orchestrator orchestrator = orchestratorService.getOrFail(location.getOrchestratorId());
IOrchestratorPlugin orchestratorInstance = orchestratorPluginService.getOrFail(orchestrator.getId());
ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
fillLocationResourceTypes(configuratorPlugin.getResourcesTypes(), locationResources, location.getDependencies());
fillPoliciesLocationResourceTypes(configuratorPlugin.getPoliciesTypes(), locationResources, location.getDependencies());
// add LocationResourceTemplate
List<LocationResourceTemplate> locationResourceTemplates = getResourcesTemplates(location.getId());
setLocationRessource(locationResourceTemplates, locationResources);
// add PolicyLocationResourceTemplate
locationResources.getPolicyTemplates().addAll(getPoliciesResourcesTemplates(location.getId()));
return locationResources;
}
use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin in project alien4cloud by alien4cloud.
the class PluginArchiveIndexer method getConfiguratorPlugin.
private ILocationConfiguratorPlugin getConfiguratorPlugin(Location location) {
ILocationConfiguratorPlugin configuratorPlugin;
try {
IOrchestratorPlugin<Object> orchestratorInstance = orchestratorPluginService.getOrFail(location.getOrchestratorId());
configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
} catch (OrchestratorDisabledException e) {
IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestratorService.getOrFail(location.getOrchestratorId()));
IOrchestratorPlugin<Object> orchestratorInstance = orchestratorFactory.newInstance();
configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
orchestratorFactory.destroy(orchestratorInstance);
}
return configuratorPlugin;
}
use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin in project alien4cloud by alien4cloud.
the class LocationMatchingConfigurationService method getMatchingConfiguration.
/**
* Get the matching configuration for a given location.
*
* @param location The location for which to get the configuration.
* @return A map nodetype, matching configuration to be used for matching.
*/
public Map<String, MatchingConfiguration> getMatchingConfiguration(Location location) {
Orchestrator orchestrator = orchestratorService.getOrFail(location.getOrchestratorId());
IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.get(orchestrator.getId());
if (orchestratorInstance == null) {
return null;
}
ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
return configuratorPlugin.getMatchingConfigurations();
}
use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin in project alien4cloud by alien4cloud.
the class LocationService method autoConfigure.
/**
* This method calls the orchestrator plugin to try to auto-configure the
*
* @param orchestrator The orchestrator for which to auto-configure a location.
* @param location The location to auto-configure
* @return the List of {@link LocationResourceTemplate} generated from the location auto-configuration call, null is a valid answer.
*/
private List<LocationResourceTemplate> autoConfigure(Orchestrator orchestrator, Location location) throws UnsupportedOperationException {
// get the orchestrator plugin instance
IOrchestratorPlugin orchestratorInstance = (IOrchestratorPlugin) orchestratorPluginService.getOrFail(orchestrator.getId());
ILocationConfiguratorPlugin configuratorPlugin = orchestratorInstance.getConfigurator(location.getInfrastructureType());
IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
ILocationResourceAccessor accessor = locationResourceService.accessor(location.getId());
// let's try to auto-configure the location
List<LocationResourceTemplate> templates = configuratorPlugin.instances(accessor);
if (templates != null) {
// save the instances
for (LocationResourceTemplate template : templates) {
// initialize the instances from data.
template.setId(UUID.randomUUID().toString());
template.setLocationId(location.getId());
template.setGenerated(true);
template.setEnabled(true);
NodeType nodeType = csarRepoSearchService.getRequiredElementInDependencies(NodeType.class, template.getTemplate().getType(), location.getDependencies());
nodeType.getDerivedFrom().add(0, template.getTemplate().getType());
template.setTypes(nodeType.getDerivedFrom());
LocationTemplateCreated event = new LocationTemplateCreated(this);
event.setTemplate(template);
event.setLocation(location);
event.setToscaType(nodeType);
applicationContext.publishEvent(event);
}
alienDAO.save(templates.toArray(new LocationResourceTemplate[templates.size()]));
alienDAO.save(location);
}
return templates;
}
use of alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin in project alien4cloud by alien4cloud.
the class PluginArchiveIndexer method deleteArchives.
/**
* Delete all archives related to a location, if not exposed or used by another location
*
* @param location
* @return Map of usages per archives if found (that means the deletion wasn't performed successfully), null if everything went well.
*/
public Map<Csar, List<Usage>> deleteArchives(Orchestrator orchestrator, Location location) {
ILocationConfiguratorPlugin configuratorPlugin = getConfiguratorPlugin(location);
IOrchestratorPluginFactory orchestratorFactory = orchestratorService.getPluginFactory(orchestrator);
List<PluginArchive> pluginArchives = configuratorPlugin.pluginArchives();
// abort if no archive is exposed by this location
if (CollectionUtils.isEmpty(pluginArchives)) {
return null;
}
Map<String, List<Location>> allExposedArchivesIds = getAllExposedArchivesIdsExluding(location);
Map<Csar, List<Usage>> usages = Maps.newHashMap();
for (PluginArchive pluginArchive : pluginArchives) {
Csar csar = pluginArchive.getArchive().getArchive();
List<Location> locationsExposingArchive = allExposedArchivesIds.get(csar.getId());
LocationArchiveDeleteRequested e = new LocationArchiveDeleteRequested(this);
e.setCsar(csar);
e.setLocation(location);
e.setOrchestratorFactory(orchestratorFactory);
e.setLocationsExposingArchive(locationsExposingArchive);
// only delete if no other location exposed this archive
if (locationsExposingArchive == null) {
List<Usage> csarUsage = csarService.deleteCsarWithElements(csar);
if (CollectionUtils.isNotEmpty(csarUsage)) {
usages.put(csar, csarUsage);
}
e.setDeleted(true);
} else {
e.setDeleted(false);
}
applicationContext.publishEvent(e);
}
return usages.isEmpty() ? null : usages;
}
Aggregations