Search in sources :

Example 91 with NodeTemplate

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;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 92 with NodeTemplate

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);
                    }
                }
            }
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Topology(org.alien4cloud.tosca.model.templates.Topology)

Example 93 with NodeTemplate

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);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 94 with NodeTemplate

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);
}
Also used : CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Set(java.util.Set) Capability(org.alien4cloud.tosca.model.templates.Capability) CSARDependency(org.alien4cloud.tosca.model.CSARDependency) Test(org.junit.Test)

Example 95 with NodeTemplate

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);
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Capability(org.alien4cloud.tosca.model.templates.Capability) SecretProviderConfigurationAndCredentials(alien4cloud.deployment.model.SecretProviderConfigurationAndCredentials) Location(alien4cloud.model.orchestrators.locations.Location)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10