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