if(response.isSourceEmpty()) { System.out.println(" FAIL: Configuration for '"+_id+"' failed because of empty source"); return false;
@Override public void onResponse(MultiGetResponse response) { MultiGetItemResponse[] responses = response.getResponses(); for (int i = 0; i < responses.length; i++) { MultiGetItemResponse singleResponse = responses[i]; if(singleResponse != null && !singleResponse.isFailed()) { GetResponse singleGetResponse = singleResponse.getResponse(); if(singleGetResponse.isExists() && !singleGetResponse.isSourceEmpty()) { //success final Tuple<Long, Settings> _settings = toSettings(singleGetResponse); if(_settings.v2() != null) { callback.success(singleGetResponse.getType(), _settings); } else { log.error("Cannot parse settings for "+singleGetResponse.getType()); } } else { //does not exist or empty source callback.noData(singleGetResponse.getType()); } } else { //failure callback.singleFailure(singleResponse==null?null:singleResponse.getFailure()); } } }
@Override public void onResponse(MultiGetResponse response) { MultiGetItemResponse[] responses = response.getResponses(); for (int i = 0; i < responses.length; i++) { MultiGetItemResponse singleResponse = responses[i]; if(singleResponse != null && !singleResponse.isFailed()) { GetResponse singleGetResponse = singleResponse.getResponse(); if(singleGetResponse.isExists() && !singleGetResponse.isSourceEmpty()) { //success final Tuple<Long, Settings> _settings = toSettings(singleGetResponse); if(_settings.v2() != null) { callback.success(singleGetResponse.getId(), _settings); } else { log.error("Cannot parse settings for "+singleGetResponse.getId()); } } else { //does not exist or empty source callback.noData(singleGetResponse.getId()); } } else { //failure callback.singleFailure(singleResponse==null?null:singleResponse.getFailure()); } } }
@Override public void onResponse(GetResponse getResponse) { List<Object> terms = new ArrayList<>(); if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap()); terms.addAll(extractedValues); } actionListener.onResponse(terms); }
gr = tc.prepareGet("searchguard", "sg", "config").setRealtime(Boolean.TRUE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close(); gr = tc.prepareGet("searchguard", "config", "0").setRealtime(Boolean.FALSE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close(); gr = tc.prepareGet("searchguard", "sg", "config").setRealtime(Boolean.TRUE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close(); gr = tc.prepareGet("searchguard", "sg", "config").setRealtime(Boolean.TRUE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close(); gr = tc.prepareGet("searchguard", "sg", "config").setRealtime(Boolean.FALSE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close();
gr = tc.prepareGet("searchguard", "sg", "config").setRealtime(Boolean.TRUE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close(); gr = tc.prepareGet("searchguard", "config", "0").setRealtime(Boolean.FALSE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close(); gr = tc.prepareGet("searchguard", "sg", "config").setRealtime(Boolean.TRUE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close(); gr = tc.prepareGet("searchguard", "sg", "config").setRealtime(Boolean.TRUE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close(); gr = tc.prepareGet("searchguard", "sg", "config").setRealtime(Boolean.FALSE).get(); Assert.assertFalse(gr.isExists()); Assert.assertTrue(gr.isSourceEmpty()); } finally { ctx.close();
/** * Checks if the requested document or source is missing. * * @param response a response * @throws ResourceNotFoundException if the document or source is missing */ private void checkResource(final GetResponse response) { final String index = response.getIndex(); final String type = response.getType(); final String id = response.getId(); if (response.isExists() == false) { throw new ResourceNotFoundException("Document not found [" + index + "]/[" + type + "]/[" + id + "]"); } else if (response.isSourceEmpty()) { throw new ResourceNotFoundException("Source not found [" + index + "]/[" + type + "]/[" + id + "]"); } } }
+ "] not found"); if (response.isSourceEmpty()) { throw new IllegalArgumentException("Shape with ID [" + getRequest.id() + "] in type [" + getRequest.type() + "] source disabled");
/** * Called with the {@linkplain GetResponse} from loading the task from the results index. Called on the node that once had the task if * that node is part of the cluster or on the coordinating node if the node wasn't part of the cluster. */ void onGetFinishedTaskFromIndex(GetResponse response, ActionListener<GetTaskResponse> listener) throws IOException { if (false == response.isExists()) { listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", response.getId())); return; } if (response.isSourceEmpty()) { listener.onFailure(new ElasticsearchException("Stored task status for [{}] didn't contain any source!", response.getId())); return; } try (XContentParser parser = XContentHelper .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, response.getSourceAsBytesRef())) { TaskResult result = TaskResult.PARSER.apply(parser, null); listener.onResponse(new GetTaskResponse(result)); } } }
@Override public void onResponse(GetResponse getResponse) { List<Object> terms = new ArrayList<>(); if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap()); terms.addAll(extractedValues); } actionListener.onResponse(terms); }
@Override public void onResponse(final GetResponse response) { if (response.isExists() && !response.isSourceEmpty()) { securityConfiguration = response.getSourceAsBytesRef(); latch.countDown(); logger.debug("Security configuration reloaded"); } }
private String getLastUpdate() { String res = ""; SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); //TODO: status update GetRequest getRequest = new GetRequest(this.statusIndex, "last_update", riverName ); //TODO: move to async ? try { GetResponse getResponse = client.get(getRequest); if(!getResponse.isSourceEmpty()){ Long updated = (Long) getResponse.getSource().get("updated_at"); res = sdf.format(updated); } } catch (IOException e) { logger.error("Could not get last_update, use Date(0)", e); res = sdf.format(new Date(0)); } return res; }
@Override public void onResponse(GetResponse getResponse) { List<Object> terms = new ArrayList<>(); if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap()); terms.addAll(extractedValues); } actionListener.onResponse(terms); }
@Override public void applyLazyFields(MultiGetItemResponse response) { GetResponse getResponse = response.getResponse(); if(getResponse.isSourceEmpty()) return; setFields(getResponse.getSource()); }
/** get the last tick from ES */ public Tick getLastTick() { LOG.debug("Fetching last tick"); GetResponse get = client // .prepareGet(index, type, id) // .get(); if (get.isSourceEmpty()) { return null; } byte[] bytes = get.getSourceAsBytes(); try { return MAPPER.readValue(bytes, Tick.class); } catch (IOException e) { return null; } } }
@Override public T selectByPrimaryKey(ID primaryKey) { try { // bulk delete GetResponse response = getElasticClient().prepareGet(getIndexName(), getIndexType(), "" + primaryKey).execute().get(); if(!response.isSourceEmpty()){ response.getSourceAsBytes(); } } catch (Exception e) { LOG.error(e.getLocalizedMessage(), e); } return null; }
private List<Object> fetch(TermsLookup termsLookup, Client client) { List<Object> terms = new ArrayList<>(); GetRequest getRequest = new GetRequest(termsLookup.index(), termsLookup.type(), termsLookup.id()) .preference("_local").routing(termsLookup.routing()); final GetResponse getResponse = client.get(getRequest).actionGet(); if (getResponse.isSourceEmpty() == false) { // extract terms only if the doc source exists List<Object> extractedValues = XContentMapValues.extractRawValues(termsLookup.path(), getResponse.getSourceAsMap()); terms.addAll(extractedValues); } return terms; }
@Override public synchronized State getRiverState(final Folder folder) throws MessagingException { try { waitForCluster(); if (client.admin().indices().prepareExists(index()).execute().actionGet().isExists()) { final GetResponse response = client .prepareGet(index(), RIVERSTATE_TYPE, FOLDERSTATE_ID + "_" + folder.getURLName().toString().hashCode()).execute() .get(); if (!response.isSourceEmpty()) { return mapper.readValue(response.getSourceAsString(), new TypeReference<State>() { }); } } } catch (final Exception ex) { throw new MessagingException("Unable to get river state", ex); } final State rs = new State(); rs.setFolderUrl(folder.getURLName().toString()); // rs.setLastUid(1L); rs.setExists(true); return rs; }
/** * Called with the {@linkplain GetResponse} from loading the task from the results index. Called on the node that once had the task if * that node is part of the cluster or on the coordinating node if the node wasn't part of the cluster. */ void onGetFinishedTaskFromIndex(GetResponse response, ActionListener<GetTaskResponse> listener) throws IOException { if (false == response.isExists()) { listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", response.getId())); return; } if (response.isSourceEmpty()) { listener.onFailure(new ElasticsearchException("Stored task status for [{}] didn't contain any source!", response.getId())); return; } try (XContentParser parser = XContentHelper.createParser(xContentRegistry, response.getSourceAsBytesRef())) { TaskResult result = TaskResult.PARSER.apply(parser, null); listener.onResponse(new GetTaskResponse(result)); } } }
/** * Called with the {@linkplain GetResponse} from loading the task from the results index. Called on the node that once had the task if * that node is part of the cluster or on the coordinating node if the node wasn't part of the cluster. */ void onGetFinishedTaskFromIndex(GetResponse response, ActionListener<GetTaskResponse> listener) throws IOException { if (false == response.isExists()) { listener.onFailure(new ResourceNotFoundException("task [{}] isn't running and hasn't stored its results", response.getId())); return; } if (response.isSourceEmpty()) { listener.onFailure(new ElasticsearchException("Stored task status for [{}] didn't contain any source!", response.getId())); return; } try (XContentParser parser = XContentHelper .createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, response.getSourceAsBytesRef())) { TaskResult result = TaskResult.PARSER.apply(parser, null); listener.onResponse(new GetTaskResponse(result)); } } }