@Override public void setup() throws Exception { elasticSearchClient.admin() .cluster() .prepareHealth() .setWaitForGreenStatus() .execute() .get(); try { initIndex(); updateLogIndexName(); Executors.newScheduledThreadPool(1) .scheduleAtFixedRate(() -> updateLogIndexName(), 0, 1, TimeUnit.HOURS); } catch (Exception e) { logger.error(e.getMessage(), e); } //1. Create the required index addIndex(indexName); //2. Add Mappings for the workflow document type addMappingToIndex(indexName, WORKFLOW_DOC_TYPE, "/mappings_docType_workflow.json"); //3. Add Mappings for task document type addMappingToIndex(indexName, TASK_DOC_TYPE, "/mappings_docType_task.json"); }
private static void startElasticsearch() throws Exception { try { FileUtils.deleteDirectory(new File("build/elasticsearch")); } catch (IOException e) { // ignore } final Settings settings = Settings.builder() .put("path.home", "build/elasticsearch") .put("node.name", "junit-es-node") .put("path.logs", "build/elasticsearch/logs") .put("path.data", "build/elasticsearch/data") .put("transport.type", "local") .put("http.type", "netty4") .build(); node = new TestNode(settings, Collections.singletonList(Netty4Plugin.class)); node.start(); node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get(); }
node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().get();
@BeforeClass public static void startServer() throws Exception { System.setProperty(ElasticSearchConfiguration.EMBEDDED_PORT_PROPERTY_NAME, "9203"); System.setProperty(ElasticSearchConfiguration.ELASTIC_SEARCH_URL_PROPERTY_NAME, "localhost:9303"); configuration = new SystemPropertiesElasticSearchConfiguration(); String host = configuration.getEmbeddedHost(); int port = configuration.getEmbeddedPort(); String clusterName = configuration.getEmbeddedClusterName(); embeddedElasticSearch = new EmbeddedElasticSearchV5(clusterName, host, port); embeddedElasticSearch.start(); ElasticSearchTransportClientProvider transportClientProvider = new ElasticSearchTransportClientProvider(configuration); elasticSearchClient = transportClientProvider.get(); elasticSearchClient.admin() .cluster() .prepareHealth() .setWaitForGreenStatus() .execute() .get(); ObjectMapper objectMapper = new ObjectMapper(); indexDAO = new ElasticSearchDAOV5(elasticSearchClient, configuration, objectMapper); }
@SuppressWarnings("unused") protected void createIndex(String indexName, boolean storeSourceData) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).execute().actionGet(); LOGGER.debug(createResponse.toString()); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: " + health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for green index status, for index: " + indexName); } }
@SuppressWarnings("unused") protected void createIndex(String indexName, boolean storeSourceData) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).execute().actionGet(); LOGGER.debug(createResponse.toString()); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: " + health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for green index status, for index: " + indexName); } }
@SuppressWarnings("unused") protected void createIndex(String indexName, boolean storeSourceData) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName).execute().actionGet(); LOGGER.debug(createResponse.toString()); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: " + health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for green index status, for index: " + indexName); } }
protected Node doCreateInternal(Dictionary properties) { ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder(); builder.put(settings); builder.classLoader(NodeFactory.class.getClassLoader()); if (properties != null) { for (Enumeration e = properties.keys(); e.hasMoreElements();) { String key = e.nextElement().toString(); Object oval = properties.get(key); String val = oval != null ? oval.toString() : null; builder.put(key, val); } } Node node = new InternalNode(builder.build(), false); try { node.start(); node.client().admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet(); } catch (RuntimeException t) { doDestroy(node); throw t; } return node; }
@SuppressWarnings("unused") protected void createIndex(String indexName) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName) .setSettings(Settings.settingsBuilder() .put("number_of_shards", getConfig().getNumberOfShards()) .put("number_of_replicas", getConfig().getNumberOfReplicas()) ) .execute().actionGet(); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: %s", health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName); } }
protected void startNode(long seed) throws Exception { ElassandraDaemon.instance.node(RandomizedContext.current().runWithPrivateRandomness(seed, this::newNode)); // we must wait for the node to actually be up and running. otherwise the node might have started, // elected itself master but might not yet have removed the // SERVICE_UNAVAILABLE/1/state not recovered / initialized block ClusterAdminClient clusterAdminClient = client().admin().cluster(); ClusterHealthRequestBuilder builder = clusterAdminClient.prepareHealth(); ClusterHealthResponse clusterHealthResponse = builder.setWaitForGreenStatus().get(); assertFalse(clusterHealthResponse.isTimedOut()); }
String waitForStatus = parameters.getProperty(WAIT_FOR_STATUS_KEY); if ("green".equals(waitForStatus)) { healthReqBuilder.setWaitForGreenStatus();
@SuppressWarnings("unused") protected void createIndex(String indexName) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName) .setSettings(XContentFactory.jsonBuilder() .startObject() .startObject("analysis") .startObject("normalizer") .startObject(LOWERCASER_NORMALIZER_NAME) .field("type", "custom") .array("filter", "lowercase") .endObject() .endObject() .endObject() .field("number_of_shards", getConfig().getNumberOfShards()) .field("number_of_replicas", getConfig().getNumberOfReplicas()) .field("index.mapping.total_fields.limit", getConfig().getIndexMappingTotalFieldsLimit()) .field("refresh_interval", getConfig().getIndexRefreshInterval()) .endObject() ) .execute().actionGet(); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: %s", health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName); } }
public void waitForGreen() { client.admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); }
@SuppressWarnings("unused") protected void createIndex(String indexName) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName) .setSettings(XContentFactory.jsonBuilder() .startObject() .startObject("analysis") .startObject("normalizer") .startObject(LOWERCASER_NORMALIZER_NAME) .field("type", "custom") .array("filter", "lowercase") .endObject() .endObject() .endObject() .field("number_of_shards", getConfig().getNumberOfShards()) .field("number_of_replicas", getConfig().getNumberOfReplicas()) .field("index.mapping.total_fields.limit", getConfig().getIndexMappingTotalFieldsLimit()) .field("refresh_interval", getConfig().getIndexRefreshInterval()) .endObject() ) .execute().actionGet(); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: %s", health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for yellow/green index status, for index: %s", indexName); } }
@SuppressWarnings("unused") protected void createIndex(String indexName) throws IOException { CreateIndexResponse createResponse = client.admin().indices().prepareCreate(indexName) .setSettings(ImmutableSettings.settingsBuilder() .put("number_of_shards", getConfig().getNumberOfShards()) .put("number_of_replicas", getConfig().getNumberOfReplicas()) ) .execute().actionGet(); ClusterHealthResponse health = client.admin().cluster().prepareHealth(indexName) .setWaitForGreenStatus() .execute().actionGet(); LOGGER.debug("Index status: %s", health.toString()); if (health.isTimedOut()) { LOGGER.warn("timed out waiting for green index status, for index: %s", indexName); } }
public void waitForGreen() { client.admin().cluster().prepareHealth().setWaitForGreenStatus().setTimeout("10s").execute().actionGet(); }
/** * Ensures the cluster has a green state via the cluster health API. This method will also wait for relocations. * It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating * are now allocated and started. * * @param timeout time out value to set on {@link org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest} */ public ClusterHealthStatus ensureGreen(TimeValue timeout, String... indices) { ClusterHealthRequestBuilder builder = client().admin().cluster().prepareHealth(indices); builder.setTimeout(timeout) .setWaitForGreenStatus() .setWaitForEvents(Priority.LANGUID) .setWaitForNoRelocatingShards(true); ClusterHealthResponse actionGet = builder.get(); if (actionGet.isTimedOut()) { logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState(), client().admin().cluster().preparePendingClusterTasks().get()); assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false)); } assertThat(actionGet.getStatus(), equalTo(ClusterHealthStatus.GREEN)); logger.debug("indices {} are green", indices.length == 0 ? "[_all]" : indices); return actionGet.getStatus(); }
@BeforeClass public void createNodes() throws Exception { ImmutableSettings.Builder settingsBuilder = settingsBuilder(); configureNodeSettings(settingsBuilder); Settings settings = settingsBuilder.build(); for (int i = 0; i < numberOfNodes(); i++) { startNode("node" + i, settings); } client = getClient(); try { client.admin().indices().prepareDelete("test").execute() .actionGet(); } catch (Exception e) { // ignore } client.admin().indices().prepareCreate("test").execute().actionGet(); client.admin().cluster().prepareHealth().setWaitForGreenStatus() .execute().actionGet(); loadData(); client.admin().indices().prepareRefresh().execute().actionGet(); }
searchClient.admin().cluster().prepareHealth(Config.APP_NAME_NS).setWaitForGreenStatus().execute().actionGet();