use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class NodeMatchingCandidateModifier method getNodeTypes.
private Map<String, NodeType> getNodeTypes(Topology topology) {
Map<String, NodeType> nodeTypes = Maps.newHashMap();
for (NodeTemplate template : safe(topology.getNodeTemplates()).values()) {
if (!nodeTypes.containsKey(template.getType())) {
NodeType nodeType = ToscaContext.getOrFail(NodeType.class, template.getType());
nodeTypes.put(nodeType.getElementId(), nodeType);
}
}
return nodeTypes;
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class AbstractArchivePostProcessor method processArtifacts.
private void processArtifacts(final Path archive, ParsingResult<ArchiveRoot> parsedArchive) {
try (ArchivePathChecker archivePathResolver = createPathChecker(archive)) {
// Check if input artifacts are correctly set
processInputArtifact(archivePathResolver, parsedArchive);
// Process deployment artifact / implementation artifact for types
processTypes(archivePathResolver, parsedArchive.getResult().getNodeTypes(), parsedArchive);
processTypes(archivePathResolver, parsedArchive.getResult().getRelationshipTypes(), parsedArchive);
// Process topology
Topology topology = parsedArchive.getResult().getTopology();
if (topology != null && topology.getNodeTemplates() != null) {
for (NodeTemplate nodeTemplate : topology.getNodeTemplates().values()) {
processTemplate(archivePathResolver, nodeTemplate, parsedArchive);
if (nodeTemplate.getRelationships() != null) {
for (RelationshipTemplate relationshipTemplate : nodeTemplate.getRelationships().values()) {
processTemplate(archivePathResolver, relationshipTemplate, parsedArchive);
}
}
}
}
}
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.
the class NodeTemplateUtilsTest method getCapabilityByTypeTest.
@Test
public void getCapabilityByTypeTest() {
NodeTemplate nodeTemplate = new NodeTemplate();
Capability nodeCapability = new Capability("org.alien4cloud.capabilities.SampleCapability", null);
nodeTemplate.setCapabilities(Maps.newHashMap("test", nodeCapability));
// if the capability type exactly equals then no tosca context and request is required
Capability capability = getCapabilityByType(nodeTemplate, "org.alien4cloud.capabilities.SampleCapability");
assertSame(nodeCapability, capability);
// 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 = toscaContextualAspect.execInToscaContext(() -> getCapabilityByType(nodeTemplate, "org.alien4cloud.capabilities.TestCapability"), false, Sets.newHashSet(new CSARDependency("org.alien4cloud.testArchive", "1.0.0-SNAPSHOT")));
assertSame(nodeCapability, capability);
}
use of org.alien4cloud.tosca.model.templates.NodeTemplate 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.NodeTemplate 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);
}
}
Aggregations