use of alien4cloud.model.orchestrators.locations.LocationResources 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.model.orchestrators.locations.LocationResources in project alien4cloud by alien4cloud.
the class LocationResourceService method getLocationResources.
/*
* (non-Javadoc)
*
* @see alien4cloud.orchestrators.locations.services.ILocationResourceService#getLocationResources(alien4cloud.model.orchestrators.locations.Location)
*/
@Override
public LocationResources getLocationResources(Location location) {
Orchestrator orchestrator = orchestratorService.get(location.getOrchestratorId());
Optional<LocationResources> locationResourcesFromOrchestrator = Optional.empty();
if (orchestrator != null && orchestratorPluginService.get(orchestrator.getId()) != null) {
locationResourcesFromOrchestrator = Optional.ofNullable(getLocationResourcesFromOrchestrator(location));
}
// Also get resource templates from outside of the orchestrator definition - eg custom resources
List<LocationResourceTemplate> locationResourceTemplates = getResourcesTemplates(location.getId());
LocationResources locationResources = new LocationResources(getLocationResourceTypes(locationResourceTemplates));
// process policies types also
List<PolicyLocationResourceTemplate> policyLocationResourceTemplates = getPoliciesResourcesTemplates(location.getId());
locationResources.addFrom(getPoliciesLocationResourceTypes(policyLocationResourceTemplates));
/*
* If the orchestrator is present, take node types computed from the resources template
* as "Custom resources types". If not, consider this is an orchestrator-free location.
*/
locationResourcesFromOrchestrator.ifPresent(orchestratorResources -> {
locationResources.getCapabilityTypes().putAll(orchestratorResources.getCapabilityTypes());
locationResources.getConfigurationTypes().putAll(orchestratorResources.getConfigurationTypes());
locationResources.getNodeTypes().putAll(orchestratorResources.getNodeTypes());
locationResources.getProvidedTypes().addAll(orchestratorResources.getNodeTypes().keySet());
locationResources.getAllNodeTypes().putAll(orchestratorResources.getAllNodeTypes());
locationResources.getOnDemandTypes().putAll(orchestratorResources.getOnDemandTypes());
locationResources.getPolicyTypes().putAll(orchestratorResources.getPolicyTypes());
});
setLocationRessource(locationResourceTemplates, locationResources);
locationResources.getPolicyTemplates().addAll(policyLocationResourceTemplates);
return locationResources;
}
use of alien4cloud.model.orchestrators.locations.LocationResources in project alien4cloud by alien4cloud.
the class NodeMatcherService method match.
public Map<String, List<LocationResourceTemplate>> match(Map<String, NodeType> nodesTypes, Map<String, NodeTemplate> nodesToMatch, Location location, String environmentId) {
Map<String, List<LocationResourceTemplate>> matchingResult = Maps.newHashMap();
// fetch location resources
LocationResources locationResources = locationResourceService.getLocationResources(location);
// Authorization filtering of location resources
filterOnAuthorization(locationResources.getNodeTemplates(), environmentId);
// fetch service resources
List<ServiceResource> services = serviceResourceService.searchByLocation(location.getId());
// self filtering: remove managed service linked to this location
filterSelfManagedService(services, environmentId);
// Authorization filtering of location resources
filterOnAuthorization(services, environmentId);
// from serviceResource to locationResource
populateLocationResourcesWithServiceResource(locationResources, services, location.getId());
Map<String, MatchingConfiguration> matchingConfigurations = locationMatchingConfigurationService.getMatchingConfiguration(location);
Set<String> typesManagedByLocation = Sets.newHashSet();
for (NodeType nodeType : locationResources.getNodeTypes().values()) {
typesManagedByLocation.add(nodeType.getElementId());
typesManagedByLocation.addAll(nodeType.getDerivedFrom());
}
INodeMatcherPlugin nodeMatcherPlugin = getNodeMatcherPlugin();
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodesToMatch.entrySet()) {
String nodeTemplateId = nodeTemplateEntry.getKey();
NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
if (typesManagedByLocation.contains(nodeTemplate.getType())) {
NodeType nodeTemplateType = nodesTypes.get(nodeTemplate.getType());
if (nodeTemplateType == null) {
throw new InvalidArgumentException("The given node types map must contain the type of the node template");
}
matchingResult.put(nodeTemplateId, nodeMatcherPlugin.matchNode(nodeTemplate, nodeTemplateType, locationResources, matchingConfigurations));
}
}
return matchingResult;
}
use of alien4cloud.model.orchestrators.locations.LocationResources in project alien4cloud by alien4cloud.
the class PolicyMatcherService method match.
/**
* Perform matching of policies from a topology.
*
* @param policyTemplates The policy templates to match.
* @param location The location against which to match policies.
* @return A Map of available matches for every policy template.
*/
public Map<String, List<PolicyLocationResourceTemplate>> match(Map<String, PolicyTemplate> policyTemplates, Map<String, PolicyType> policyTypes, Location location, String environmentId) {
if (MapUtils.isEmpty(policyTemplates)) {
return Maps.newHashMap();
}
Map<String, List<PolicyLocationResourceTemplate>> matches = Maps.newHashMap();
// fetch location resources
LocationResources locationResources = locationResourceService.getLocationResources(location);
// Authorization filtering of location resources
locationResources.getPolicyTemplates().removeIf(securedResource -> !locationSecurityService.isAuthorised(securedResource, environmentId));
for (Entry<String, PolicyTemplate> policyTemplateEntry : policyTemplates.entrySet()) {
PolicyType policyType = policyTypes.get(policyTemplateEntry.getValue().getType());
matches.put(policyTemplateEntry.getKey(), policyMatcher.match(policyTemplateEntry.getValue(), policyType, locationResources.getPolicyTemplates(), locationResources.getPolicyTypes(), locationResources, null));
}
return matches;
}
use of alien4cloud.model.orchestrators.locations.LocationResources in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method setUp.
@Before
public void setUp() throws Exception {
this.nodeMatcher = new DefaultNodeMatcher();
this.computeNodeType = nodeType("org.alien4cloud.nodes.mock.aws.Compute", "tosca.nodes.Compute");
this.computeNodeTemplate = nodeTemplate("org.alien4cloud.nodes.mock.aws.Compute");
NodeType mongoDbNodeType = nodeType("alien.service.MongoDB", "", "tosca.service.ServiceType", "test.nodes.DB");
NodeTemplate mongoDbNodeTemplate = nodeTemplate("alien.service.MongoDB");
LocationResourceTemplate mongoDbLocationTemplate = locationResourceTemplate(mongoDbNodeTemplate);
mongoDbLocationTemplate.setService(true);
locationResources = new LocationResources();
//
locationResources.setNodeTemplates(//
Arrays.asList(//
locationResourceTemplate(computeNodeTemplate), //
mongoDbLocationTemplate));
//
locationResources.setNodeTypes(//
ImmutableMap.of(//
computeNodeType.getElementId(), //
computeNodeType, //
mongoDbNodeType.getElementId(), //
mongoDbNodeType));
}
Aggregations