Search in sources :

Example 1 with ILocationResourceAccessor

use of alien4cloud.orchestrators.plugin.ILocationResourceAccessor in project alien4cloud by alien4cloud.

the class LocationResourceServiceTest method getResources.

@Test
public void getResources() {
    ILocationResourceAccessor accessor = locationResourceService.accessor(LOCATION_ID);
    List<LocationResourceTemplate> resources = accessor.getResources();
    Assert.assertEquals(LOCATION_CONFIGURED_ELEMENTS, resources.size());
}
Also used : LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) ILocationResourceAccessor(alien4cloud.orchestrators.plugin.ILocationResourceAccessor) Test(org.junit.Test)

Example 2 with ILocationResourceAccessor

use of alien4cloud.orchestrators.plugin.ILocationResourceAccessor in project alien4cloud by alien4cloud.

the class LocationResourceServiceTest method getResourcesOfTypeForUnconfiguredLocationShouldReturnEmptyList.

@Test
public void getResourcesOfTypeForUnconfiguredLocationShouldReturnEmptyList() {
    ILocationResourceAccessor accessor = locationResourceService.accessor(UNCONFIGURED_LOCATION_ID);
    List<LocationResourceTemplate> resources = accessor.getResources(CONFIGURED_TYPE);
    Assert.assertEquals(0, resources.size());
}
Also used : LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) ILocationResourceAccessor(alien4cloud.orchestrators.plugin.ILocationResourceAccessor) Test(org.junit.Test)

Example 3 with ILocationResourceAccessor

use of alien4cloud.orchestrators.plugin.ILocationResourceAccessor in project alien4cloud by alien4cloud.

the class LocationResourceServiceTest method getResourcesForUnconfiguredLocationShouldReturnEmptyList.

@Test
public void getResourcesForUnconfiguredLocationShouldReturnEmptyList() {
    ILocationResourceAccessor accessor = locationResourceService.accessor(UNCONFIGURED_LOCATION_ID);
    List<LocationResourceTemplate> resources = accessor.getResources();
    Assert.assertEquals(0, resources.size());
}
Also used : LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) ILocationResourceAccessor(alien4cloud.orchestrators.plugin.ILocationResourceAccessor) Test(org.junit.Test)

Example 4 with ILocationResourceAccessor

use of alien4cloud.orchestrators.plugin.ILocationResourceAccessor in project alien4cloud by alien4cloud.

the class LocationResourceServiceTest method getResourcesOfType.

@Test
public void getResourcesOfType() {
    ILocationResourceAccessor accessor = locationResourceService.accessor(LOCATION_ID);
    List<LocationResourceTemplate> resources = accessor.getResources(CONFIGURED_TYPE);
    Assert.assertEquals(TYPE_CONFIGURED_ELEMENTS, resources.size());
}
Also used : LocationResourceTemplate(alien4cloud.model.orchestrators.locations.LocationResourceTemplate) ILocationResourceAccessor(alien4cloud.orchestrators.plugin.ILocationResourceAccessor) Test(org.junit.Test)

Example 5 with ILocationResourceAccessor

use of alien4cloud.orchestrators.plugin.ILocationResourceAccessor 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

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