Search in sources :

Example 6 with NodeType

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

the class EsDaoPaginatedSearchTest method saveDataToES.

private void saveDataToES() throws IOException, IndexingServiceException {
    testDataList.clear();
    Path path = Paths.get("src/test/resources/nodetypes-faceted-search-result.json");
    FacetedSearchResult res = jsonMapper.readValue(path.toFile(), FacetedSearchResult.class);
    Object[] data = res.getData();
    for (Object element : data) {
        String serializeDatum = jsonMapper.writeValueAsString(element);
        NodeType indexedNodeType = jsonMapper.readValue(serializeDatum, NodeType.class);
        indexedNodeType.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
        String typeName = MappingBuilder.indexTypeFromClass(NodeType.class);
        dao.save(indexedNodeType);
        assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName, indexedNodeType.getId(), true);
        testDataList.add(indexedNodeType);
        for (CapabilityDefinition capaDef : indexedNodeType.getCapabilities()) {
            if (capaDef.getType().equals("jndi")) {
                jndiTestDataList.add(indexedNodeType);
            }
        }
    }
    refresh();
}
Also used : Path(java.nio.file.Path) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult)

Example 7 with NodeType

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

the class EsDaoPaginatedSearchTest method facetedSearchPaginatedTest.

// @Ignore
@Test
public void facetedSearchPaginatedTest() throws IndexingServiceException, IOException, InterruptedException {
    String searchText = "jndi";
    int maxElement = getCount(QueryBuilders.matchPhrasePrefixQuery("_all", searchText).maxExpansions(10));
    int size = 7;
    // simple faceted pagination
    assertTrue(maxElement > 0);
    testFacetedSearchWellPaginated(maxElement, size, searchText, null, null);
    // faceted search with filters
    FilterBuilder filter = FilterBuilders.termFilter("capabilities.type", "jndi");
    QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
    queryBuilder = QueryBuilders.filteredQuery(queryBuilder, filter);
    maxElement = getCount(queryBuilder);
    Map<String, String[]> filters = new HashMap<String, String[]>();
    filters.put("capabilities.type", new String[] { "jndi" });
    assertTrue(maxElement > 0);
    testFacetedSearchWellPaginated(maxElement, size, searchText, filters, FetchContext.SUMMARY);
    // test nothing found
    // test when nothing found
    searchText = "pacpac";
    maxElement = getCount(QueryBuilders.matchPhrasePrefixQuery("_all", searchText).maxExpansions(10));
    assertEquals(0, maxElement);
    GetMultipleDataResult<NodeType> searchResp = dao.facetedSearch(NodeType.class, searchText, null, null, 0, size);
    assertNotNull(searchResp);
    assertNotNull(searchResp.getData());
    assertNotNull(searchResp.getTypes());
    assertEquals(0, searchResp.getData().length);
    assertEquals(0, searchResp.getTypes().length);
}
Also used : HashMap(java.util.HashMap) FilterBuilder(org.elasticsearch.index.query.FilterBuilder) NodeType(org.alien4cloud.tosca.model.types.NodeType) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) Test(org.junit.Test)

Example 8 with NodeType

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

the class EsDaoPaginatedSearchTest method testTextBasedSearchWellPaginated.

private void testTextBasedSearchWellPaginated(int maxElement, int size, String searchText, Map<String, String[]> filters) throws IOException {
    List<NodeType> expectedDataList = new ArrayList<>(jndiTestDataList);
    GetMultipleDataResult searchResp;
    int expectedSize;
    for (int from = 0; from < maxElement; from += size) {
        expectedSize = (maxElement - from) > size ? size : maxElement - from;
        searchResp = dao.search(NodeType.class, searchText, filters, from, size);
        assertNotNull(searchResp);
        assertNotNull(searchResp.getTypes());
        assertNotNull(searchResp.getData());
        assertEquals(expectedSize, searchResp.getTypes().length);
        assertEquals(expectedSize, searchResp.getData().length);
        // testing the pertinence of returned data
        Object[] data = searchResp.getData();
        for (Object element : data) {
            NodeType nt = jsonMapper.readValue(jsonMapper.writeValueAsString(element), NodeType.class);
            assertTrue(expectedDataList.contains(nt));
            expectedDataList.remove(nt);
        }
    }
    // assert the list is empty at the end.
    assertTrue(expectedDataList.isEmpty());
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) ArrayList(java.util.ArrayList) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult)

Example 9 with NodeType

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

the class EsDaoSearchTest method textBasedSearch.

@Test
public void textBasedSearch() throws IndexingServiceException, JsonParseException, JsonMappingException, IOException, InterruptedException {
    // text search based
    String searchText = "positive";
    GetMultipleDataResult searchResp = dao.search(NodeType.class, searchText, null, 10);
    assertNotNull(searchResp);
    assertEquals(2, searchResp.getTypes().length);
    assertEquals(2, searchResp.getData().length);
    String[] ids = new String[] { indexedNodeTypeTest.getId(), indexedNodeTypeTest4.getId() };
    for (int i = 0; i < searchResp.getData().length; i++) {
        NodeType idnt = (NodeType) searchResp.getData()[i];
        assertElementIn(idnt.getId(), ids);
    }
    // text search based with filters
    Map<String, String[]> filters = new HashMap<String, String[]>();
    filters.put("capabilities.type", new String[] { "container" });
    searchResp = dao.search(NodeType.class, searchText, filters, 10);
    assertNotNull(searchResp);
    assertNotNull(searchResp.getTypes());
    assertNotNull(searchResp.getData());
    assertEquals(1, searchResp.getTypes().length);
    assertEquals(1, searchResp.getData().length);
    NodeType idnt = (NodeType) searchResp.getData()[0];
    assertElementIn(idnt.getElementId(), new String[] { "1" });
    // test nothing found
    searchText = "pacpac";
    searchResp = dao.search(NodeType.class, searchText, null, 10);
    assertNotNull(searchResp);
    assertNotNull(searchResp.getData());
    assertNotNull(searchResp.getTypes());
    assertEquals(0, searchResp.getData().length);
    assertEquals(0, searchResp.getTypes().length);
}
Also used : HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) GetMultipleDataResult(alien4cloud.dao.model.GetMultipleDataResult) Test(org.junit.Test)

Example 10 with NodeType

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

the class EsDaoSuggestionTest method saveDataToES.

private void saveDataToES(boolean refresh) throws JsonProcessingException {
    for (NodeType datum : dataTest) {
        String json = jsonMapper.writeValueAsString(datum);
        String typeName = MappingBuilder.indexTypeFromClass(datum.getClass());
        nodeClient.prepareIndex(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName).setSource(json).setRefresh(refresh).execute().actionGet();
        assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName, datum.getId(), true);
    }
    refresh();
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType)

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