protected Map<ShardInfo, NodeInfo> doGetWriteTargetPrimaryShards(boolean clientNodesOnly) { List<List<Map<String, Object>>> info = client.targetShards(resources.getResourceWrite().index(), SettingsUtils.getFixedRouting(settings)); Map<ShardInfo, NodeInfo> shards = new LinkedHashMap<ShardInfo, NodeInfo>(); List<NodeInfo> nodes = client.getHttpNodes(clientNodesOnly); Map<String, NodeInfo> nodeMap = new HashMap<String, NodeInfo>(nodes.size()); for (NodeInfo node : nodes) { nodeMap.put(node.getId(), node); } for (List<Map<String, Object>> shardGroup : info) { // consider only primary shards for (Map<String, Object> shardData : shardGroup) { ShardInfo shard = new ShardInfo(shardData); if (shard.isPrimary()) { NodeInfo node = nodeMap.get(shard.getNode()); if (node == null) { log.warn(String.format("Cannot find node with id [%s] (is HTTP enabled?) from shard [%s] in nodes [%s]; layout [%s]", shard.getNode(), shard, nodes, info)); return null; } shards.put(shard, node); break; } } } return shards; }
client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type()); if (resources.getResourceWrite().isTyped()) { client.delete(resources.getResourceWrite().index() + "/" + resources.getResourceWrite().type() + "/_query?q=*"); } else { client.delete(resources.getResourceWrite().index() + "/_query?q=*"); StringBuilder sb = new StringBuilder(resources.getResourceWrite().index()); if (resources.getResourceWrite().isTyped()) { sb.append('/').append(resources.getResourceWrite().type()); flush(); client.refresh(resources.getResourceWrite());
public boolean waitForYellow() { return client.waitForHealth(resources.getResourceWrite().index(), RestClient.Health.YELLOW, TimeValue.timeValueSeconds(10)); }
public void putMapping(BytesArray mapping) { client.putMapping(resources.getResourceWrite().index(), resources.getResourceWrite().mapping(), mapping.bytes()); }
/** postpone writing initialization since we can do only reading so there's no need to allocate buffers */ private void lazyInitWriting() { if (!writeInitialized) { this.writeInitialized = true; this.bulkProcessor = new BulkProcessor(client, resources.getResourceWrite(), settings); this.trivialBytesRef = new BytesRef(); this.bulkEntryWriter = new BulkEntryWriter(settings, BulkCommands.create(settings, metaExtractor, client.internalVersion)); } }
public RestRepository(Settings settings) { this.settings = settings; this.resources = new Resources(settings); // Check if we have a read resource first, and if not, THEN check the write resource // The write resource has more strict parsing rules, and if the process is only reading // with a resource that isn't good for writing, then eagerly parsing the resource as a // write resource can erroneously throw an error. Instead, we should just get the write // resource lazily as needed. Assert.isTrue(resources.getResourceRead() != null || resources.getResourceWrite() != null, "Invalid configuration - No read or write resource specified"); this.client = new RestClient(settings); }
public boolean isEmpty(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); boolean exists = client.indexExists(res.index()); return (exists ? count(read) <= 0 : true); }
public boolean isEmpty(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); boolean exists = client.indexExists(res.index()); return (exists ? count(read) <= 0 : true); }
public boolean isEmpty(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); boolean exists = client.indexExists(res.index()); return (exists ? count(read) <= 0 : true); }
public RestRepository(Settings settings) { this.settings = settings; this.resources = new Resources(settings); // Check if we have a read resource first, and if not, THEN check the write resource // The write resource has more strict parsing rules, and if the process is only reading // with a resource that isn't good for writing, then eagerly parsing the resource as a // write resource can erroneously throw an error. Instead, we should just get the write // resource lazily as needed. Assert.isTrue(resources.getResourceRead() != null || resources.getResourceWrite() != null, "Invalid configuration - No read or write resource specified"); this.client = new RestClient(settings); }
/** postpone writing initialization since we can do only reading so there's no need to allocate buffers */ private void lazyInitWriting() { if (!writeInitialized) { this.writeInitialized = true; this.bulkProcessor = new BulkProcessor(client, resources.getResourceWrite(), settings); this.trivialBytesRef = new BytesRef(); this.bulkEntryWriter = new BulkEntryWriter(settings, BulkCommands.create(settings, metaExtractor, client.internalVersion)); } }
/** postpone writing initialization since we can do only reading so there's no need to allocate buffers */ private void lazyInitWriting() { if (!writeInitialized) { this.writeInitialized = true; this.bulkProcessor = new BulkProcessor(client, resources.getResourceWrite(), settings); this.trivialBytesRef = new BytesRef(); this.bulkEntryWriter = new BulkEntryWriter(settings, BulkCommands.create(settings, metaExtractor, client.internalVersion)); } }
public RestRepository(Settings settings) { this.settings = settings; this.resources = new Resources(settings); // Check if we have a read resource first, and if not, THEN check the write resource // The write resource has more strict parsing rules, and if the process is only reading // with a resource that isn't good for writing, then eagerly parsing the resource as a // write resource can erroneously throw an error. Instead, we should just get the write // resource lazily as needed. Assert.isTrue(resources.getResourceRead() != null || resources.getResourceWrite() != null, "Invalid configuration - No read or write resource specified"); this.client = new RestClient(settings); }
public boolean resourceExists(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); // cheap hit - works for exact index names, index patterns, the `_all` resource, and alias names boolean exists = client.indexExists(res.index()); // Do we really care if it's typed? // Yes! If the index exists and a type is given, the type should exist on the index as well. if (exists && res.isTyped()) { exists = client.typeExists(res.index(), res.type()); } // could be a _all or a pattern which is valid for read // try again by asking the mapping - could be expensive if (!exists && read) { try { // make sure the mapping is null since the index might exist but the type might be missing MappingSet mappings = client.getMappings(res); exists = mappings != null && !mappings.isEmpty(); } catch (EsHadoopInvalidRequest ex) { exists = false; } } return exists; }
public boolean waitForYellow() { return client.waitForHealth(resources.getResourceWrite().index(), RestClient.Health.YELLOW, TimeValue.timeValueSeconds(10)); }
public boolean touch() { return client.touch(resources.getResourceWrite().index()); }
public boolean isEmpty(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); boolean exists = client.indexExists(res.index()); return (exists ? count(read) <= 0 : true); }
public long count(boolean read) { Resource res = (read ? resources.getResourceRead() : resources.getResourceWrite()); if (res.isTyped()) { return client.count(res.index(), res.type(), QueryUtils.parseQuery(settings)); } else { return client.count(res.index(), QueryUtils.parseQuery(settings)); } }
public RestRepository(Settings settings) { this.settings = settings; this.resources = new Resources(settings); // Check if we have a read resource first, and if not, THEN check the write resource // The write resource has more strict parsing rules, and if the process is only reading // with a resource that isn't good for writing, then eagerly parsing the resource as a // write resource can erroneously throw an error. Instead, we should just get the write // resource lazily as needed. Assert.isTrue(resources.getResourceRead() != null || resources.getResourceWrite() != null, "Invalid configuration - No read or write resource specified"); this.client = new RestClient(settings); }
/** postpone writing initialization since we can do only reading so there's no need to allocate buffers */ private void lazyInitWriting() { if (!writeInitialized) { this.writeInitialized = true; this.bulkProcessor = new BulkProcessor(client, resources.getResourceWrite(), settings); this.trivialBytesRef = new BytesRef(); this.bulkEntryWriter = new BulkEntryWriter(settings, BulkCommands.create(settings, metaExtractor, client.internalVersion)); } }