use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project arctic-sea by 52North.
the class ElasticsearchAdminHandler method addUuidToMetadataIfNeeded.
@SuppressWarnings("unchecked")
private void addUuidToMetadataIfNeeded(String uuid) throws ElasticsearchException {
GetResponse resp = client.prepareGet(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setOperationThreaded(false).get();
Object retValues = resp.getSourceAsMap().get(MetadataDataMapping.METADATA_UUIDS_FIELD.getName());
List<String> values;
if (retValues instanceof String) {
values = new LinkedList<>();
values.add((String) retValues);
} else if (retValues instanceof List<?>) {
values = (List<String>) retValues;
} else {
throw new ConfigurationError("Invalid %s field type %s should have String or java.util.Collection<String>", MetadataDataMapping.METADATA_UUIDS_FIELD, retValues.getClass());
}
// add new uuid if needed
if (!values.stream().anyMatch(m -> m.equals(uuid))) {
Map<String, Object> uuids = new HashMap<>();
values.add(uuid);
uuids.put(MetadataDataMapping.METADATA_UUIDS_FIELD.getName(), values);
uuids.put(MetadataDataMapping.METADATA_UPDATE_TIME_FIELD.getName(), Calendar.getInstance(DateTimeZone.UTC.toTimeZone()));
client.prepareUpdate(settings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, "1").setDoc(uuids).get();
logger.info("UUID {} is added to the {} type", uuid, MetadataDataMapping.METADATA_TYPE_NAME);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project arctic-sea by 52North.
the class ElasticsearchAdminHandlerIT method createNewDatabase.
@Test
public void createNewDatabase() throws InterruptedException {
adminHandler.createSchema();
IndicesAdminClient indices = getEmbeddedClient().admin().indices();
IndicesExistsResponse index = indices.prepareExists(clientSettings.getIndexId()).get();
Assert.assertTrue(index.isExists());
GetResponse resp = getEmbeddedClient().prepareGet(clientSettings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setOperationThreaded(false).get();
Assert.assertEquals(1, resp.getSourceAsMap().get(MetadataDataMapping.METADATA_VERSION_FIELD.getName()));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project arctic-sea by 52North.
the class ElasticsearchAdminHandlerIT method addnewUuidOnConnect.
@SuppressWarnings("unchecked")
@Test
public void addnewUuidOnConnect() {
adminHandler.createSchema();
clientSettings.setUuid("lofasz janos");
adminHandler.createSchema();
GetResponse resp = getEmbeddedClient().prepareGet(clientSettings.getIndexId(), MetadataDataMapping.METADATA_TYPE_NAME, MetadataDataMapping.METADATA_ROW_ID).setOperationThreaded(false).get();
Map<String, Object> map = resp.getSourceAsMap();
Assert.assertNotNull(map.get(MetadataDataMapping.METADATA_CREATION_TIME_FIELD.getName()));
Assert.assertNotNull(map.get(MetadataDataMapping.METADATA_UUIDS_FIELD.getName()));
Assert.assertNotNull(map.get(MetadataDataMapping.METADATA_UPDATE_TIME_FIELD.getName()));
List<String> object = (List<String>) map.get(MetadataDataMapping.METADATA_UUIDS_FIELD.getName());
Assert.assertEquals(2, object.size());
Assert.assertThat(object, CoreMatchers.hasItem("lofasz janos"));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project alien4cloud by alien4cloud.
the class EsDaoCrudTest method assertDocumentExisit.
private void assertDocumentExisit(String indexName, String typeName, String id, boolean expected) {
GetResponse response = getDocument(indexName, typeName, id);
assertEquals(expected, response.isExists());
assertEquals(expected, !response.isSourceEmpty());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.get.GetResponse in project alien4cloud by alien4cloud.
the class EsDaoCrudTest method saveToscaComponentTest.
@Test
public void saveToscaComponentTest() throws IndexingServiceException, IOException {
dao.save(indexedNodeTypeTest);
String typeName1 = indexedNodeTypeTest.getClass().getSimpleName().toLowerCase();
assertDocumentExisit(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName1, indexedNodeTypeTest.getId(), true);
GetResponse resp = getDocument(ElasticSearchDAO.TOSCA_ELEMENT_INDEX, typeName1, indexedNodeTypeTest.getId());
log.info(resp.getSourceAsString());
NodeType nt = jsonMapper.readValue(resp.getSourceAsString(), NodeType.class);
assertBeanEqualsToOriginal(nt);
refresh();
}
Aggregations