Search in sources :

Example 76 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class InputPropertiesStepDefinitions method I_define_the_property_of_the_node_as_of_typeId_as_input_property.

@When("^I define the property \"([^\"]*)\" of the node \"([^\"]*)\" of typeId \"([^\"]*)\" as input property$")
public void I_define_the_property_of_the_node_as_of_typeId_as_input_property(String inputId, String nodeName, String typeId) throws Throwable {
    // get the component to use the right property definition
    String componentResponse = Context.getRestClientInstance().get("/rest/v1/components/" + typeId);
    RestResponse<NodeType> componentResult = JsonUtil.read(componentResponse, NodeType.class, Context.getJsonMapper());
    PropertyDefinition propertyDefinition = componentResult.getData().getProperties().get(inputId);
    String fullUrl = String.format("/rest/v1/topologies/%s/inputs/%s", Context.getInstance().getTopologyId(), inputId);
    String json = JsonUtil.toString(propertyDefinition);
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().postJSon(fullUrl, json));
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) PropertyDefinition(org.alien4cloud.tosca.model.definitions.PropertyDefinition) When(cucumber.api.java.en.When)

Example 77 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class GetComponentDefinitionsSteps method I_should_retrieve_a_component_detail_with_list_of_it_s_properties_and_interfaces.

@Then("^I should retrieve a component detail with list of it's properties and interfaces.$")
public void I_should_retrieve_a_component_detail_with_list_of_it_s_properties_and_interfaces() throws Throwable {
    NodeType idnt = JsonUtil.read(Context.getInstance().takeRestResponse(), NodeType.class).getData();
    assertNotNull(idnt);
    assertNotNull(idnt.getProperties());
    assertTrue(!idnt.getProperties().isEmpty());
    assertTrue(!idnt.getProperties().values().isEmpty());
    assertNotNull(idnt.getInterfaces());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Then(cucumber.api.java.en.Then)

Example 78 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class SearchDefinitionSteps method createAndIndexComponent.

private void createAndIndexComponent(int count, String type, String baseName, int countHavingProperty, String property, String propertyValue) throws Exception {
    testDataList.clear();
    Class<?> clazz = QUERY_TYPES.get(type).getIndexedToscaElementClass();
    String typeName = MappingBuilder.indexTypeFromClass(clazz);
    int remaining = countHavingProperty;
    baseName = baseName == null || baseName.isEmpty() ? typeName : baseName;
    for (int i = 0; i < count; i++) {
        AbstractToscaType componentTemplate = (AbstractToscaType) clazz.newInstance();
        String elementId = baseName + "_" + i;
        componentTemplate.setElementId(elementId);
        componentTemplate.setArchiveVersion(DEFAULT_ARCHIVE_VERSION);
        componentTemplate.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
        if (property != null && remaining > 0) {
            if (type.equalsIgnoreCase("node types")) {
                switch(property) {
                    case "capability":
                        ((NodeType) componentTemplate).setCapabilities(Lists.newArrayList(new CapabilityDefinition(propertyValue, propertyValue, 1)));
                        break;
                    case "requirement":
                        ((NodeType) componentTemplate).setRequirements((Lists.newArrayList(new RequirementDefinition(propertyValue, propertyValue))));
                        break;
                    case "default capability":
                        ((NodeType) componentTemplate).setDefaultCapabilities((Lists.newArrayList(propertyValue)));
                        break;
                    case "elementId":
                        ((NodeType) componentTemplate).setElementId(propertyValue);
                        break;
                    default:
                        break;
                }
            } else if (type.equalsIgnoreCase("relationship types")) {
                ((RelationshipType) componentTemplate).setValidSources(new String[] { propertyValue });
            }
            remaining -= 1;
        }
        String serializeDatum = JsonUtil.toString(componentTemplate);
        log.debug("Saving in ES: " + serializeDatum);
        esClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName).setSource(serializeDatum).setRefresh(true).execute().actionGet();
        if (componentTemplate instanceof NodeType) {
            testDataList.add((NodeType) (componentTemplate));
        }
    }
    indexedComponentTypes.put(type, typeName);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition)

Example 79 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class UpdateDeleteTagDefinitionsSteps method I_should_have_tag_with_value.

@Then("^I should have tag \"([^\"]*)\" with value \"([^\"]*)\"$")
public void I_should_have_tag_with_value(String tagKey, String tagValue) throws Throwable {
    Context.getInstance().registerRestResponse(Context.getRestClientInstance().get("/rest/v1/components/" + Context.getInstance().getComponentId(0)));
    NodeType idnt = JsonUtil.read(Context.getInstance().takeRestResponse(), NodeType.class).getData();
    assertNotNull(idnt);
    int index = idnt.getTags().indexOf(new Tag(tagKey, null));
    assertEquals(idnt.getTags().get(index).getValue(), tagValue);
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Tag(alien4cloud.model.common.Tag) Then(cucumber.api.java.en.Then)

Example 80 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class UpdateDeleteTagDefinitionsSteps method createOneIndexNodeType.

/**
 * Load components IndexedNodeType from a file to use it in tests
 *
 * @param componentId
 * @param refresh
 * @throws IOException
 * @throws IndexingServiceException
 */
@SuppressWarnings("unchecked")
private void createOneIndexNodeType(String componentId, String archiveVersion, List<Tag> tags, boolean refresh) throws IOException, IndexingServiceException {
    String samplePathString = "src/test/resources/data/components/indexed_nodetypes.json";
    Path path = Paths.get(samplePathString);
    List<Object> tempList = jsonMapper.readValue(path.toFile(), ArrayList.class);
    List<NodeType> idntList = new ArrayList<>();
    for (Object ob : tempList) {
        idntList.add(jsonMapper.readValue(jsonMapper.writeValueAsString(ob), NodeType.class));
    }
    String typeName = MappingBuilder.indexTypeFromClass(NodeType.class);
    NodeType indexedNodeType = null;
    // Save on nodeType with
    if (componentId != null && archiveVersion != null && !componentId.trim().isEmpty()) {
        // Get the first nodetype to update its id and insert it
        indexedNodeType = idntList.get(0);
        indexedNodeType.setElementId(componentId);
        indexedNodeType.setArchiveVersion(archiveVersion);
        indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
        if (tags != null) {
            indexedNodeType.setTags(tags);
        }
        String serializeDatum = jsonMapper.writeValueAsString(indexedNodeType);
        esClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName).setSource(serializeDatum).setRefresh(refresh).execute().actionGet();
    }
}
Also used : Path(java.nio.file.Path) NodeType(org.alien4cloud.tosca.model.types.NodeType) ArrayList(java.util.ArrayList)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7