private static void update() { try { IndicesAdminClient indicesAdminClient = client.admin().indices(); if (indicesAdminClient.prepareExists(INDEX_NAME_v2).execute().actionGet().isExists()) { indicesAdminClient.delete(new DeleteIndexRequest(INDEX_NAME_v2)).actionGet(); } indicesAdminClient.prepareCreate(INDEX_NAME_v2).addMapping(INDEX_TYPE,getItemInfoMapping()).execute().actionGet(); //等待集群shard,防止No shard available for 异常 ClusterAdminClient clusterAdminClient = client.admin().cluster(); clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000); //0、更新mapping updateMapping(); //1、更新数据 reindexData(indicesAdminClient); //2、realias 重新建立连接 indicesAdminClient.prepareAliases().removeAlias(INDEX_NAME_v1, ALIX_NAME).addAlias(INDEX_NAME_v2, ALIX_NAME).execute().actionGet(); }catch (Exception e){ log.error("beforeUpdate error:{}"+e.getLocalizedMessage()); } }
private static void beforeUpdate() { try { IndicesAdminClient indicesAdminClient = client.admin().indices(); indicesAdminClient.delete(new DeleteIndexRequest(INDEX_NAME_v1)).actionGet(); if (!indicesAdminClient.prepareExists(INDEX_NAME_v1).execute().actionGet().isExists()) { indicesAdminClient.prepareCreate(INDEX_NAME_v1).addMapping(INDEX_TYPE,getItemInfoMapping()).execute().actionGet(); } //等待集群shard,防止No shard available for 异常 ClusterAdminClient clusterAdminClient = client.admin().cluster(); clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000); //创建别名alias indicesAdminClient.prepareAliases().addAlias(INDEX_NAME_v1, ALIX_NAME).execute().actionGet(); prepareData(indicesAdminClient); }catch (Exception e){ log.error("beforeUpdate error:{}"+e.getLocalizedMessage()); } }
public Client getClient() { Client client = node.client(); ExecutorService executor = Executors.newSingleThreadExecutor(); Future<Void> future = executor.submit(new Callable<Void>() { @Override public Void call() { ClusterAdminClient clusterAdmin = client.admin().cluster(); ClusterHealthResponse res = clusterAdmin.health(new ClusterHealthRequest()).actionGet(1000); while (res.getStatus().equals(ClusterHealthStatus.RED)) { res = clusterAdmin.health(new ClusterHealthRequest()).actionGet(1000); } return null; } }); try { future.get(3, TimeUnit.SECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { log.error("Failed to wait for cluster to startup synchronously. Unit tests may fail", e); } return client; }
public static void waitForActiveRiver(ClusterAdminClient client, String riverName, String riverType, int seconds) throws InterruptedException, IOException { GetRiverStateRequest riverStateRequest = new GetRiverStateRequest() .setRiverName(riverName) .setRiverType(riverType); GetRiverStateResponse riverStateResponse = client .execute(GetRiverStateAction.INSTANCE, riverStateRequest).actionGet(); while (seconds-- > 0 && !isActive(riverName, riverStateResponse)) { Thread.sleep(1000L); try { riverStateResponse = client.execute(GetRiverStateAction.INSTANCE, riverStateRequest).actionGet(); } catch (IndexMissingException e) { // } } if (seconds < 0) { throw new IOException("timeout waiting for active river"); } }
public static void waitForInactiveRiver(ClusterAdminClient client, String riverName, String riverType, int seconds) throws InterruptedException, IOException { GetRiverStateRequest riverStateRequest = new GetRiverStateRequest() .setRiverName(riverName) .setRiverType(riverType); GetRiverStateResponse riverStateResponse = client .execute(GetRiverStateAction.INSTANCE, riverStateRequest).actionGet(); while (seconds-- > 0 && isActive(riverName, riverStateResponse)) { Thread.sleep(1000L); try { riverStateResponse = client.execute(GetRiverStateAction.INSTANCE, riverStateRequest).actionGet(); } catch (IndexMissingException e) { // } } if (seconds < 0) { throw new IOException("timeout waiting for inactive river"); } }
private void SetupMocks(Client client, IndicesAdminClient indicesAdminClient, ImmutableOpenMap<String, IndexMetaData> indicesMap) { AdminClient adminClient = mock(AdminClient.class); ClusterAdminClient clusterAdminClient = mock(ClusterAdminClient.class); @SuppressWarnings("unchecked") ActionFuture<ClusterStateResponse> actionFuture = ((ActionFuture<ClusterStateResponse>) mock(ActionFuture.class)); ClusterStateResponse response = mock(ClusterStateResponse.class); ClusterState state = mock(ClusterState.class); MetaData metaData = mock(MetaData.class); when(client.admin()).thenReturn(adminClient); when(adminClient.indices()).thenReturn(indicesAdminClient); when(adminClient.cluster()).thenReturn(clusterAdminClient); when(clusterAdminClient.state(Mockito.any(ClusterStateRequest.class))).thenReturn(actionFuture); when(actionFuture.actionGet()).thenReturn(response); when(response.getState()).thenReturn(state); when(state.getMetaData()).thenReturn(metaData); when(metaData.getIndices()).thenReturn(indicesMap); }
public void refreshStatus() { TransportClient client = Elasticsearch.getClient(); ArrayList<TransportAddress> current_connected_nodes = convertList(client.connectedNodes()); if (current_connected_nodes.isEmpty()) { return; } ClusterAdminClient cluster_admin_client = client.admin().cluster(); ClusterStatsRequestBuilder cluster_stats_request = cluster_admin_client.prepareClusterStats(); ClusterStatsResponse cluster_stats_response = cluster_stats_request.execute().actionGet(); last_status_reports = new LinkedHashMap<String, StatusReport>(); last_status_reports.put("clusterhealthstatus", new StatusReport("Cluster health status").addCell("Color", "Cluster", cluster_stats_response.getStatus().name())); processHostsNodesLists(client.connectedNodes(), client.listedNodes(), client.filteredNodes()); processStats(cluster_stats_response.getIndicesStats()); processStats(cluster_stats_response.getNodesStats()); }
private void resolveAddresses() { ClusterAdminClient cluster = client.admin().cluster(); cluster.prepareHealth().setWaitForYellowStatus().get(); NodesInfoResponse nodeInfos = cluster.prepareNodesInfo(NODE_NAME) .setHttp(true).setTransport(true).get(); NodeInfo nodeInfo = nodeInfos.getAt(0); httpAddress = addressToString(nodeInfo.getHttp().getAddress()); transportAddress = addressToString(nodeInfo.getTransport().getAddress()); }
public static void main(String[] args) { try { index(); //等待集群shard,防止No shard available for 异常 ClusterAdminClient clusterAdminClient = client.admin().cluster(); clusterAdminClient.prepareHealth().setWaitForYellowStatus().execute().actionGet(5000); // analyze(); } catch (Exception e) { log.error("main error:{}", e.getMessage()); }finally { client.close(); } }
private NodeInfo getCurrentNode() { ClusterAdminClient cluster = client().admin().cluster(); return cluster .prepareNodesInfo(cluster.prepareState().get().getState() .getNodes().getLocalNodeId()) .get().getNodes().iterator().next(); }
public static void waitForRiverEnabled(ClusterAdminClient client, String riverName, String riverType, int seconds) throws InterruptedException, IOException { GetRiverStateRequest riverStateRequest = new GetRiverStateRequest() .setRiverName(riverName) .setRiverType(riverType); GetRiverStateResponse riverStateResponse = client .execute(GetRiverStateAction.INSTANCE, riverStateRequest).actionGet(); while (seconds-- > 0 && !isEnabled(riverName, riverStateResponse)) { Thread.sleep(1000L); try { riverStateResponse = client.execute(GetRiverStateAction.INSTANCE, riverStateRequest).actionGet(); } catch (IndexMissingException e) { // ignore } } }
@Before public void checkElasticSearchHealth() throws Throwable { AdminClient admin = client.admin(); ClusterAdminClient cluster = admin.cluster(); ClusterHealthRequest request = new ClusterHealthRequest().waitForGreenStatus(); ActionFuture<ClusterHealthResponse> health = cluster.health(request); ClusterHealthResponse healthResponse = health.get(); assertEquals(ClusterHealthStatus.GREEN, healthResponse.getStatus()); Operation operation = sequenceOf(StaticDataOperations.ALL_STATIC_DATA_ROWS, ArtistU2Operations.RELEASE_GROUP_U2_ROWS); DbSetup dbSetup = new DbSetup(new DataSourceDestination(dataSource), operation); dbSetup.launch(); }
@Test public void newRequestBuilder() { ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class); JRLifecycleRequestBuilder rb = JRLifecycleAction.INSTANCE.newRequestBuilder(client); Assert.assertNotNull(rb); }
@Test public void newRequestBuilder() { ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class); JRStateRequestBuilder rb = JRStateAction.INSTANCE.newRequestBuilder(client); Assert.assertNotNull(rb); }
@Test public void newRequestBuilder() { ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class); IncrementalUpdateRequestBuilder rb = IncrementalUpdateAction.INSTANCE.newRequestBuilder(client); Assert.assertNotNull(rb); }
@Test public void newRequestBuilder() { ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class); ListRiversRequestBuilder rb = ListRiversAction.INSTANCE.newRequestBuilder(client); Assert.assertNotNull(rb); }
@Test public void newRequestBuilder() { ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class); FullUpdateRequestBuilder rb = FullUpdateAction.INSTANCE.newRequestBuilder(client); Assert.assertNotNull(rb); }
@Override public ClusterAdminClient cluster() { return clusterAdmin; }
/** * For issue #26: https://github.com/elastic/elasticsearch-cloud-azure/issues/26 */ public void testListBlobs_26() throws StorageException, URISyntaxException { createIndex("test-idx-1", "test-idx-2", "test-idx-3"); ensureGreen(); logger.info("--> indexing some data"); for (int i = 0; i < 100; i++) { index("test-idx-1", "doc", Integer.toString(i), "foo", "bar" + i); index("test-idx-2", "doc", Integer.toString(i), "foo", "baz" + i); index("test-idx-3", "doc", Integer.toString(i), "foo", "baz" + i); } refresh(); ClusterAdminClient client = client().admin().cluster(); logger.info("--> creating azure repository without any path"); PutRepositoryResponse putRepositoryResponse = client.preparePutRepository("test-repo").setType("azure") .setSettings(Settings.builder() .put(Repository.CONTAINER_SETTING.getKey(), getContainerName()) ).get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); // Get all snapshots - should be empty assertThat(client.prepareGetSnapshots("test-repo").get().getSnapshots().size(), equalTo(0)); logger.info("--> snapshot"); CreateSnapshotResponse createSnapshotResponse = client.prepareCreateSnapshot("test-repo", "test-snap-26") .setWaitForCompletion(true).setIndices("test-idx-*").get(); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); // Get all snapshots - should have one assertThat(client.prepareGetSnapshots("test-repo").get().getSnapshots().size(), equalTo(1)); // Clean the snapshot client.prepareDeleteSnapshot("test-repo", "test-snap-26").get(); client.prepareDeleteRepository("test-repo").get(); logger.info("--> creating azure repository path [{}]", getRepositoryPath()); putRepositoryResponse = client.preparePutRepository("test-repo").setType("azure") .setSettings(Settings.builder() .put(Repository.CONTAINER_SETTING.getKey(), getContainerName()) .put(Repository.BASE_PATH_SETTING.getKey(), getRepositoryPath()) ).get(); assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true)); // Get all snapshots - should be empty assertThat(client.prepareGetSnapshots("test-repo").get().getSnapshots().size(), equalTo(0)); logger.info("--> snapshot"); createSnapshotResponse = client.prepareCreateSnapshot("test-repo", "test-snap-26").setWaitForCompletion(true) .setIndices("test-idx-*").get(); assertThat(createSnapshotResponse.getSnapshotInfo().successfulShards(), greaterThan(0)); // Get all snapshots - should have one assertThat(client.prepareGetSnapshots("test-repo").get().getSnapshots().size(), equalTo(1)); }
protected ClusterAdminClient clusterAdminClient() { Client client = ElasticSearch.CLIENT.get(); return client.admin().cluster(); }
@Override public FlushRequestBuilder newRequestBuilder(final ClusterAdminClient client) { return new FlushRequestBuilder(client); }
public FlushRequestBuilder(final ClusterAdminClient client) { super(client, new FlushRequest()); }
public ConfigUpdateRequestBuilder(final ClusterAdminClient client) { this(client, ConfigUpdateAction.INSTANCE); }
public LicenseInfoRequestBuilder(final ClusterAdminClient client) { this(client, LicenseInfoAction.INSTANCE); }
public WhoAmIRequestBuilder(final ClusterAdminClient client) { this(client, WhoAmIAction.INSTANCE); }
private ClusterHealthResponse waitForGreenClusterState(String index) { ClusterAdminClient clusterAdminClient = node.client().admin().cluster(); ClusterHealthRequest request = (new ClusterHealthRequestBuilder(clusterAdminClient, ClusterHealthAction.INSTANCE)) .setIndices(index).setWaitForGreenStatus().request(); return clusterAdminClient.health(request).actionGet(); }
public ClusterAdminClient cluster() { return internalClient.admin().cluster(); }
public GathererRequestBuilder(ClusterAdminClient clusterClient) { super((InternalClusterAdminClient) clusterClient, new GathererRequest()); }
@Override protected void doExecute(ActionListener<GathererResponse> listener) { ((ClusterAdminClient) client).execute(GathererAction.INSTANCE, request, listener); }
@Override public GathererRequestBuilder newRequestBuilder(ClusterAdminClient client) { return new GathererRequestBuilder(client); }
@Override public DeployRequestBuilder newRequestBuilder(ClusterAdminClient client) { return new DeployRequestBuilder(client); }
public DeployRequestBuilder(ClusterAdminClient clusterClient) { super((InternalClusterAdminClient) clusterClient, new DeployRequest()); }
@Override protected void doExecute(ActionListener<DeployResponse> listener) { ((ClusterAdminClient) client).execute(DeployAction.INSTANCE, request, listener); }
@Override public GetRiverStateRequestBuilder newRequestBuilder(ClusterAdminClient client) { return new GetRiverStateRequestBuilder(client); }
public GetRiverStateRequestBuilder(ClusterAdminClient client) { super(client, new GetRiverStateRequest()); }
public DeleteRiverStateRequestBuilder(ClusterAdminClient client) { super(client, new DeleteRiverStateRequest()); }
@Override public DeleteRiverStateRequestBuilder newRequestBuilder(ClusterAdminClient client) { return new DeleteRiverStateRequestBuilder(client); }
public PutRiverStateRequestBuilder(ClusterAdminClient client) { super(client, new PutRiverStateRequest()); }
@Override public PutRiverStateRequestBuilder newRequestBuilder(ClusterAdminClient client) { return new PutRiverStateRequestBuilder(client); }
public RiverExecuteRequestBuilder(ClusterAdminClient client) { super(client, new RiverExecuteRequest()); }