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);
}
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);
}
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);
}
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()));
}
}
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));
}
Aggregations