@Override protected void doExecute( final KnapsackPullRequest request, ActionListener<KnapsackPullResponse> listener) { final KnapsackState state = new KnapsackState().setMode("pull").setNodeName(nodeService.nodeName()); final KnapsackPullResponse response = new KnapsackPullResponse().setState(state); try { final BulkTransportClient transportClient = ClientBuilder.builder() .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, request.getMaxActionsPerBulkRequest()) .put(ClientBuilder.MAX_CONCURRENT_REQUESTS, request.getMaxBulkConcurrency()) .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(5)) .put(clientSettings(client, request)) .toBulkTransportClient(); final BulkNodeClient nodeClient = ClientBuilder.builder() .put(ClientBuilder.MAX_ACTIONS_PER_REQUEST, request.getMaxActionsPerBulkRequest()) .put(ClientBuilder.MAX_CONCURRENT_REQUESTS, request.getMaxBulkConcurrency()) .put(ClientBuilder.FLUSH_INTERVAL, TimeValue.timeValueSeconds(5)) .toBulkNodeClient(client); state.setTimestamp(new DateTime()); response.setRunning(true); knapsack.submit( new Thread() { public void run() { performPull(request, state, transportClient, nodeClient); } }); listener.onResponse(response); } catch (Throwable e) { logger.error(e.getMessage(), e); listener.onFailure(e); } }
@Override public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { builder.field("count", states.size()).startArray("states"); for (KnapsackState ks : states) { ks.toXContent(builder, params); } builder.endArray(); return builder; }
public boolean isPullActive() { if (states != null) { for (KnapsackState ks : states) { if (ks != null && "pull".equals(ks.getMode())) { return true; } } } return false; }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); if (states != null) { out.writeInt(states.size()); for (KnapsackState state : states) { state.writeTo(out); } } }
@Override public void readFrom(StreamInput in) throws IOException { super.readFrom(in); states = new LinkedList<>(); int size = in.readInt(); for (int i = 0; i < size; i++) { KnapsackState ks = new KnapsackState(); ks.readFrom(in); states.add(ks); } }
public boolean isImportActive(Path path) { if (states != null && path != null) { for (KnapsackState ks : states) { if (ks != null && "import".equals(ks.getMode()) && ks.getPath() != null && path.toString().equals(ks.getPath().toString())) { return true; } } } return false; }