use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class NodeTemplateUtilsTest method getMissingCapabilityByTypeTest.
@Test
public void getMissingCapabilityByTypeTest() {
NodeTemplate nodeTemplate = new NodeTemplate();
Capability nodeCapability = new Capability("org.alien4cloud.capabilities.SampleCapability", null);
nodeTemplate.setCapabilities(Maps.newHashMap("test", nodeCapability));
// if the capability derives from parent type then a TOSCA context and query is required to fetch the type.
CapabilityType capabilityType = new CapabilityType();
capabilityType.setElementId("org.alien4cloud.capabilities.SampleCapability");
capabilityType.setDerivedFrom(Lists.newArrayList("org.alien4cloud.capabilities.TestCapability"));
Mockito.reset(csarRepositorySearchService);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("org.alien4cloud.capabilities.SampleCapability"), Mockito.any(Set.class))).thenReturn(capabilityType);
Capability capability = toscaContextualAspect.execInToscaContext(() -> getCapabilityByType(nodeTemplate, "org.alien4cloud.capabilities.Unknown"), false, Sets.newHashSet(new CSARDependency("org.alien4cloud.testArchive", "1.0.0-SNAPSHOT")));
assertNull(capability);
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method doScale.
private void doScale(final String nodeTemplateId, final int instances, final IPaaSCallback<Object> callback, final Deployment deployment, final DeploymentTopology topology, SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
NodeTemplate nodeTemplate = TopologyUtils.getNodeTemplate(topology, nodeTemplateId);
// get the secret provider configuration from the location
Map<String, String> locationIds = TopologyLocationUtils.getLocationIds(topology);
Map<String, Location> locations = deploymentTopologyService.getLocations(locationIds);
SecretProviderConfigurationAndCredentials authResponse = null;
if (secretProviderService.isSecretProvided(secretProviderConfigurationAndCredentials)) {
authResponse = secretProviderService.generateToken(locations, secretProviderConfigurationAndCredentials.getSecretProviderConfiguration().getPluginName(), secretProviderConfigurationAndCredentials.getCredentials());
}
// Get alien4cloud specific interface to support cluster controller nodes.
Capability clusterControllerCapability = NodeTemplateUtils.getCapabilityByType(nodeTemplate, AlienCapabilityTypes.CLUSTER_CONTROLLER);
if (clusterControllerCapability == null) {
doScaleNode(nodeTemplateId, instances, callback, deployment, topology, nodeTemplate, authResponse);
} else {
triggerClusterManagerScaleOperation(nodeTemplateId, instances, callback, deployment, topology, clusterControllerCapability, secretProviderConfigurationAndCredentials);
}
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class DeploymentRuntimeService method doScaleNode.
private void doScaleNode(final String nodeTemplateId, final int instances, final IPaaSCallback<Object> callback, final Deployment deployment, final DeploymentTopology topology, NodeTemplate nodeTemplate, SecretProviderConfigurationAndCredentials secretProviderConfigurationAndCredentials) {
final Capability capability = NodeTemplateUtils.getCapabilityByTypeOrFail(nodeTemplate, NormativeCapabilityTypes.SCALABLE);
final int previousInitialInstances = TopologyUtils.getScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, capability);
final int newInitialInstances = previousInitialInstances + instances;
log.info("Scaling [ {} ] node from [ {} ] to [ {} ]. Updating runtime topology...", nodeTemplateId, previousInitialInstances, newInitialInstances);
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, newInitialInstances, capability);
alienMonitorDao.save(topology);
IOrchestratorPlugin orchestratorPlugin = orchestratorPluginService.getOrFail(deployment.getOrchestratorId());
PaaSDeploymentContext deploymentContext = new PaaSDeploymentContext(deployment, topology, secretProviderConfigurationAndCredentials);
orchestratorPlugin.scale(deploymentContext, nodeTemplateId, instances, new IPaaSCallback() {
@Override
public void onFailure(Throwable throwable) {
log.info("Failed to scale [ {} ] node from [ {} ] to [ {} ]. rolling back to {}...", nodeTemplateId, previousInitialInstances, newInitialInstances, previousInitialInstances);
TopologyUtils.setScalingProperty(NormativeComputeConstants.SCALABLE_DEFAULT_INSTANCES, previousInitialInstances, capability);
alienMonitorDao.save(topology);
callback.onFailure(throwable);
}
@Override
public void onSuccess(Object data) {
callback.onSuccess(data);
}
});
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class DefaultNodeMatcher method typeSpecificMatching.
@Override
protected boolean typeSpecificMatching(NodeTemplate abstractTemplate, LocationResourceTemplate candidate, NodeType candidateType, LocationResources locationResources, MatchingConfiguration matchingConfiguration) {
for (Entry<String, Capability> candidateCapability : safe(candidate.getTemplate().getCapabilities()).entrySet()) {
MatchingFilterDefinition configuredFilterDefinition = matchingConfiguration == null ? null : safe(matchingConfiguration.getCapabilities()).get(candidateCapability.getKey());
Map<String, List<IMatchPropertyConstraint>> configuredFilters = configuredFilterDefinition == null ? null : configuredFilterDefinition.getProperties();
CapabilityType capabilityType = locationResources.getCapabilityTypes().get(candidateCapability.getValue().getType());
// Ignore scalable capabiltiy for matching.
if (!ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) {
Capability templateCapability = safe(abstractTemplate.getCapabilities()).get(candidateCapability.getKey());
if (templateCapability != null && !isValidTemplatePropertiesMatch(templateCapability.getProperties(), candidateCapability.getValue().getProperties(), capabilityType.getProperties(), configuredFilters)) {
return false;
}
}
}
return true;
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class TopologyServiceCore method getIndexedCapabilityTypesFromTopology.
/**
* Get all capability types used in a topology
*
* @param topology the topology to find all relationship types
* @return The map that contains the capability types.
*/
public Map<String, CapabilityType> getIndexedCapabilityTypesFromTopology(Topology topology) {
Map<String, CapabilityType> capabilityTypes = Maps.newHashMap();
if (topology.getNodeTemplates() == null) {
return capabilityTypes;
}
for (Map.Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
NodeTemplate template = templateEntry.getValue();
if (template.getCapabilities() != null) {
for (Map.Entry<String, Capability> capabilityEntry : template.getCapabilities().entrySet()) {
Capability capability = capabilityEntry.getValue();
if (!capabilityTypes.containsKey(capability.getType())) {
CapabilityType capabilityType = getFromContextIfDefined(CapabilityType.class, capability.getType(), topology.getDependencies(), true);
capabilityTypes.put(capability.getType(), capabilityType);
}
}
}
}
return capabilityTypes;
}
Aggregations