Search in sources :

Example 1 with LocationTemplateCreated

use of alien4cloud.events.LocationTemplateCreated in project alien4cloud by alien4cloud.

the class LocationResourceService method publishCreatedEventAndSaveResource.

private <T extends AbstractTemplate> void publishCreatedEventAndSaveResource(Location location, AbstractLocationResourceTemplate<T> locationResourceTemplate, AbstractInheritableToscaType resourceType) {
    LocationTemplateCreated event = new LocationTemplateCreated(this);
    event.setTemplate(locationResourceTemplate);
    event.setLocation(location);
    event.setToscaType(resourceType);
    applicationContext.publishEvent(event);
    saveResource(location, locationResourceTemplate);
}
Also used : LocationTemplateCreated(alien4cloud.events.LocationTemplateCreated)

Example 2 with LocationTemplateCreated

use of alien4cloud.events.LocationTemplateCreated 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;
}
Also used : IOrchestratorPluginFactory(alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory) ILocationConfiguratorPlugin(alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin) LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) ILocationResourceAccessor(alien4cloud.orchestrators.plugin.ILocationResourceAccessor) NodeType(org.alien4cloud.tosca.model.types.NodeType) LocationTemplateCreated(alien4cloud.events.LocationTemplateCreated) IOrchestratorPlugin(alien4cloud.orchestrators.plugin.IOrchestratorPlugin)

Aggregations

LocationTemplateCreated (alien4cloud.events.LocationTemplateCreated)2 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)1 ILocationConfiguratorPlugin (alien4cloud.orchestrators.plugin.ILocationConfiguratorPlugin)1 ILocationResourceAccessor (alien4cloud.orchestrators.plugin.ILocationResourceAccessor)1 IOrchestratorPlugin (alien4cloud.orchestrators.plugin.IOrchestratorPlugin)1 IOrchestratorPluginFactory (alien4cloud.orchestrators.plugin.IOrchestratorPluginFactory)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1