Search in sources :

Example 6 with AbstractToscaType

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

the class SearchTest method searchPostTest.

@Test
public void searchPostTest() {
    String query = "positive";
    RestResponse<FacetedSearchResult<? extends AbstractToscaType>> response;
    ComponentSearchRequest req;
    FacetedSearchResult data;
    String[] ids;
    // without filters
    req = new ComponentSearchRequest(QueryComponentType.NODE_TYPE, query, 0, NUMBER_ELEMENT, null);
    response = componentController.search(req);
    assertNotNull(response);
    assertNotNull(response.getData());
    assertNull(response.getError());
    data = response.getData();
    assertEquals(2, data.getTotalResults());
    assertEquals(2, data.getTypes().length);
    assertEquals(2, data.getData().length);
    ids = new String[] { indexedNodeTypeTest.getId(), indexedNodeTypeTest4.getId() };
    for (int i = 0; i < data.getData().length; i++) {
        NodeType idnt = (NodeType) data.getData()[i];
        assertElementIn(idnt.getId(), ids);
    }
    // filter based test
    Map<String, String[]> filters = new HashMap<String, String[]>();
    filters.put("capabilities.type", new String[] { "container", "banana" });
    req = new ComponentSearchRequest(QueryComponentType.NODE_TYPE, query, 0, NUMBER_ELEMENT, filters);
    response = componentController.search(req);
    assertNotNull(response);
    assertNotNull(response.getData());
    assertNull(response.getError());
    data = response.getData();
    assertEquals(1, data.getTotalResults());
    assertEquals(1, data.getTypes().length);
    assertEquals(1, data.getData().length);
    NodeType idnt = (NodeType) data.getData()[0];
    assertElementIn(idnt.getId(), new String[] { indexedNodeTypeTest.getId() });
    // test nothing found
    query = "pacpac";
    req = new ComponentSearchRequest(QueryComponentType.NODE_TYPE, query, 0, NUMBER_ELEMENT, null);
    response = componentController.search(req);
    assertNotNull(response);
    assertNotNull(response.getData());
    assertNull(response.getError());
    data = response.getData();
    assertNotNull(data.getTypes());
    assertEquals(0, data.getTotalResults());
    assertEquals(0, data.getData().length);
    assertEquals(0, data.getTypes().length);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) HashMap(java.util.HashMap) NodeType(org.alien4cloud.tosca.model.types.NodeType) FacetedSearchResult(alien4cloud.dao.model.FacetedSearchResult) Test(org.junit.Test)

Example 7 with AbstractToscaType

use of org.alien4cloud.tosca.model.types.AbstractToscaType 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 8 with AbstractToscaType

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

the class QuickSearchDefinitionsSteps method createAndIndexComponent.

private void createAndIndexComponent(int count, String type, 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;
    for (int i = 0; i < count; i++) {
        AbstractToscaType componentTemplate = (AbstractToscaType) clazz.newInstance();
        componentTemplate.setElementId(type + "_" + i);
        componentTemplate.setArchiveVersion(DEFAULT_ARCHIVE_VERSION);
        componentTemplate.setWorkspace(AlienConstants.GLOBAL_WORKSPACE_ID);
        if (property != null && remaining > 0) {
            if (type.equalsIgnoreCase("node types")) {
                switch(property) {
                    case "elementId":
                        ((NodeType) componentTemplate).setElementId(propertyValue + "_" + remaining);
                        break;
                    default:
                        break;
                }
            } else if (type.equalsIgnoreCase("relationship types")) {
                ((RelationshipType) componentTemplate).setValidSources(new String[] { propertyValue });
            }
            remaining -= 1;
        }
        String serializeDatum = jsonMapper.writeValueAsString(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));
        }
    }
    indexedTypes.put(type, typeName);
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 9 with AbstractToscaType

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

the class LocationResourceService method loadResourcesTypes.

private <T extends AbstractLocationResourceTemplate> void loadResourcesTypes(List<T> resources, Location location, ToscaTypeLoader toscaTypeLoader) {
    for (T resource : resources) {
        String type = resource.getTemplate().getType();
        AbstractToscaType toscaType = csarRepoSearchService.getRequiredElementInDependencies(AbstractToscaType.class, type, location.getDependencies());
        toscaTypeLoader.loadType(resource.getTemplate().getType(), csarDependencyLoader.buildDependencyBean(toscaType.getArchiveName(), toscaType.getArchiveVersion()));
    }
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType)

Example 10 with AbstractToscaType

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

the class TopologyTreeBuilderService method mergeInterfaces.

@SneakyThrows
private void mergeInterfaces(AbstractPaaSTemplate pasSTemplate, AbstractInstantiableTemplate abstractTemplate) {
    AbstractToscaType type = pasSTemplate.getIndexedToscaElement();
    Map<String, Interface> typeInterfaces = null;
    if (type instanceof AbstractInstantiableToscaType) {
        typeInterfaces = ((AbstractInstantiableToscaType) type).getInterfaces();
    }
    Map<String, Interface> templateInterfaces = abstractTemplate.getInterfaces();
    // Here merge interfaces: the interface defined in the template should override those from type.
    pasSTemplate.setInterfaces(IndexedModelUtils.mergeInterfaces(JsonUtil.toMap(JsonUtil.toString(typeInterfaces), String.class, Interface.class), templateInterfaces));
}
Also used : AbstractToscaType(org.alien4cloud.tosca.model.types.AbstractToscaType) AbstractInstantiableToscaType(org.alien4cloud.tosca.model.types.AbstractInstantiableToscaType) Interface(org.alien4cloud.tosca.model.definitions.Interface) SneakyThrows(lombok.SneakyThrows)

Aggregations

AbstractToscaType (org.alien4cloud.tosca.model.types.AbstractToscaType)15 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 ApiOperation (io.swagger.annotations.ApiOperation)3 NodeType (org.alien4cloud.tosca.model.types.NodeType)3 Tag (alien4cloud.model.common.Tag)2 Given (cucumber.api.java.en.Given)2 FacetedSearchResult (alien4cloud.dao.model.FacetedSearchResult)1 GetMultipleDataResult (alien4cloud.dao.model.GetMultipleDataResult)1 NotFoundException (alien4cloud.exception.NotFoundException)1 Application (alien4cloud.model.application.Application)1 And (cucumber.api.java.en.And)1 HashMap (java.util.HashMap)1 Set (java.util.Set)1 SneakyThrows (lombok.SneakyThrows)1 CatalogVersionResult (org.alien4cloud.tosca.catalog.CatalogVersionResult)1 CSARDependency (org.alien4cloud.tosca.model.CSARDependency)1 Csar (org.alien4cloud.tosca.model.Csar)1 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)1 Interface (org.alien4cloud.tosca.model.definitions.Interface)1