Search in sources :

Example 1 with NodeInstance

use of org.alien4cloud.tosca.model.instances.NodeInstance in project alien4cloud by alien4cloud.

the class ServiceResourceServiceTest method testGetByNodeTypes.

@Test
public void testGetByNodeTypes() {
    ServiceResource serviceResource = new ServiceResource();
    serviceResource.setId("service1");
    serviceResource.setNodeInstance(new NodeInstance());
    serviceResource.getNodeInstance().setTypeVersion("1.0.0-SNAPSHOT");
    serviceResource.getNodeInstance().setNodeTemplate(new NodeTemplate());
    serviceResource.getNodeInstance().getNodeTemplate().setType("org.alien4cloud.nodes.MyType");
    alienDao.save(serviceResource);
    ServiceResource[] services = serviceResourceService.getByNodeTypes("org.alien4cloud.nodes.MyType", "1.0.0-SNAPSHOT");
    Assert.assertNotNull(services);
    Assert.assertEquals(1, services.length);
    services = serviceResourceService.getByNodeTypes("org.alien4cloud.nodes.UnusedType", "1.0.0-SNAPSHOT");
    Assert.assertNotNull(services);
    Assert.assertEquals(0, services.length);
    services = serviceResourceService.getByNodeTypes("org.alien4cloud.nodes.MyType", "1.0.0");
    Assert.assertNotNull(services);
    Assert.assertEquals(0, services.length);
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) ServiceResource(alien4cloud.model.service.ServiceResource) NodeInstance(org.alien4cloud.tosca.model.instances.NodeInstance) Test(org.junit.Test)

Example 2 with NodeInstance

use of org.alien4cloud.tosca.model.instances.NodeInstance in project alien4cloud by alien4cloud.

the class NodeInstanceService method create.

/**
 * Create a new instance of a given node type based on default generated template.
 *
 * @param nodeType The node type out of which to create the version.
 * @param typeVersion The node instance type's version.
 * @return An instance that matches the given type created from a default template (default values). Note that the node instance may be constructed from an
 *         invalid template (missing required properties) without errors. State of the node is set to initial.
 */
@ToscaContextual
public NodeInstance create(NodeType nodeType, String typeVersion) {
    NodeTemplate nodeTemplate = TemplateBuilder.buildNodeTemplate(nodeType, null);
    NodeInstance instance = new NodeInstance();
    instance.setAttribute(ToscaNodeLifecycleConstants.ATT_STATE, ToscaNodeLifecycleConstants.INITIAL);
    instance.setNodeTemplate(nodeTemplate);
    instance.setTypeVersion(typeVersion);
    return instance;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeInstance(org.alien4cloud.tosca.model.instances.NodeInstance) ToscaContextual(alien4cloud.tosca.context.ToscaContextual)

Aggregations

NodeInstance (org.alien4cloud.tosca.model.instances.NodeInstance)2 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)2 ServiceResource (alien4cloud.model.service.ServiceResource)1 ToscaContextual (alien4cloud.tosca.context.ToscaContextual)1 Test (org.junit.Test)1