Java 类org.elasticsearch.client.ClusterAdminClient 实例源码

项目:javabase    文件:UpdateMappingFieldDemo.java   
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());
    }

}
项目:javabase    文件:UpdateMappingFieldDemo.java   
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());
    }
}
项目:Rapture    文件:EmbeddedServer.java   
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;
}
项目:elasticsearch-sentiment    文件:RiverHelper.java   
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");
    }
}
项目:elasticsearch-sentiment    文件:RiverHelper.java   
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");
    }
}
项目:alfa    文件:LogCleanerTest.java   
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);
}
项目:MyDMAM    文件:ElasticsearchStatus.java   
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());
}
项目:beepbeep    文件:EmbeddedElasticsearch.java   
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());
}
项目:javabase    文件:CrudDemo.java   
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();
    }
}
项目:utils-elasticsearch    文件:JMEmbededElastricsearch.java   
private NodeInfo getCurrentNode() {
    ClusterAdminClient cluster = client().admin().cluster();
    return cluster
            .prepareNodesInfo(cluster.prepareState().get().getState()
                    .getNodes().getLocalNodeId())
            .get().getNodes().iterator().next();
}
项目:elasticsearch-sentiment    文件:RiverHelper.java   
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
        }
    }
}
项目:musicbrainz-elasticsearch    文件:TestMusicAlbumJob.java   
@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();
}
项目:elasticsearch-river-remote    文件:JRLifecycleActionTest.java   
@Test
public void newRequestBuilder() {
    ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class);

    JRLifecycleRequestBuilder rb = JRLifecycleAction.INSTANCE.newRequestBuilder(client);
    Assert.assertNotNull(rb);
}
项目:elasticsearch-river-remote    文件:JRStateActionTest.java   
@Test
public void newRequestBuilder() {
    ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class);

    JRStateRequestBuilder rb = JRStateAction.INSTANCE.newRequestBuilder(client);
    Assert.assertNotNull(rb);
}
项目:elasticsearch-river-remote    文件:IncrementalUpdateActionTest.java   
@Test
public void newRequestBuilder() {
    ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class);

    IncrementalUpdateRequestBuilder rb = IncrementalUpdateAction.INSTANCE.newRequestBuilder(client);
    Assert.assertNotNull(rb);
}
项目:elasticsearch-river-remote    文件:ListRiversActionTest.java   
@Test
public void newRequestBuilder() {
    ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class);

    ListRiversRequestBuilder rb = ListRiversAction.INSTANCE.newRequestBuilder(client);
    Assert.assertNotNull(rb);
}
项目:elasticsearch-river-remote    文件:FullUpdateActionTest.java   
@Test
public void newRequestBuilder() {
    ClusterAdminClient client = Mockito.mock(ClusterAdminClient.class);

    FullUpdateRequestBuilder rb = FullUpdateAction.INSTANCE.newRequestBuilder(client);
    Assert.assertNotNull(rb);
}
项目:elasticsearch_my    文件:AbstractClient.java   
@Override
public ClusterAdminClient cluster() {
    return clusterAdmin;
}
项目:elasticsearch_my    文件:AzureSnapshotRestoreTests.java   
/**
 * 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));


}
项目:geeCommerce-Java-Shop-Software-and-PIM    文件:DefaultElasticsearchIndexHelper.java   
protected ClusterAdminClient clusterAdminClient() {
    Client client = ElasticSearch.CLIENT.get();
    return client.admin().cluster();
}
项目:elasticsearch-sample-plugin-audit    文件:FlushAction.java   
@Override
public FlushRequestBuilder newRequestBuilder(final ClusterAdminClient client) {
    return new FlushRequestBuilder(client);
}
项目:elasticsearch-sample-plugin-audit    文件:FlushRequestBuilder.java   
public FlushRequestBuilder(final ClusterAdminClient client) {
    super(client, new FlushRequest());
}
项目:search-guard    文件:ConfigUpdateRequestBuilder.java   
public ConfigUpdateRequestBuilder(final ClusterAdminClient client) {
    this(client, ConfigUpdateAction.INSTANCE);
}
项目:search-guard    文件:LicenseInfoRequestBuilder.java   
public LicenseInfoRequestBuilder(final ClusterAdminClient client) {
    this(client, LicenseInfoAction.INSTANCE);
}
项目:search-guard    文件:WhoAmIRequestBuilder.java   
public WhoAmIRequestBuilder(final ClusterAdminClient client) {
    this(client, WhoAmIAction.INSTANCE);
}
项目:egov-search    文件:AbstractNodeIntegrationTest.java   
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();
}
项目:spacedog-server    文件:ElasticClient.java   
public ClusterAdminClient cluster() {
    return internalClient.admin().cluster();
}
项目:elasticsearch-gatherer    文件:GathererRequestBuilder.java   
public GathererRequestBuilder(ClusterAdminClient clusterClient) {
    super((InternalClusterAdminClient) clusterClient, new GathererRequest());
}
项目:elasticsearch-gatherer    文件:GathererRequestBuilder.java   
@Override
protected void doExecute(ActionListener<GathererResponse> listener) {
    ((ClusterAdminClient) client).execute(GathererAction.INSTANCE, request, listener);
}
项目:elasticsearch-gatherer    文件:GathererAction.java   
@Override
public GathererRequestBuilder newRequestBuilder(ClusterAdminClient client) {
    return new GathererRequestBuilder(client);
}
项目:elasticsearch-gatherer    文件:DeployAction.java   
@Override
public DeployRequestBuilder newRequestBuilder(ClusterAdminClient client) {
    return new DeployRequestBuilder(client);
}
项目:elasticsearch-gatherer    文件:DeployRequestBuilder.java   
public DeployRequestBuilder(ClusterAdminClient clusterClient) {
    super((InternalClusterAdminClient) clusterClient, new DeployRequest());
}
项目:elasticsearch-gatherer    文件:DeployRequestBuilder.java   
@Override
protected void doExecute(ActionListener<DeployResponse> listener) {
    ((ClusterAdminClient) client).execute(DeployAction.INSTANCE, request, listener);
}
项目:elasticsearch-sentiment    文件:GetRiverStateAction.java   
@Override
public GetRiverStateRequestBuilder newRequestBuilder(ClusterAdminClient client) {
    return new GetRiverStateRequestBuilder(client);
}
项目:elasticsearch-sentiment    文件:GetRiverStateRequestBuilder.java   
public GetRiverStateRequestBuilder(ClusterAdminClient client) {
    super(client, new GetRiverStateRequest());
}
项目:elasticsearch-sentiment    文件:DeleteRiverStateRequestBuilder.java   
public DeleteRiverStateRequestBuilder(ClusterAdminClient client) {
    super(client, new DeleteRiverStateRequest());
}
项目:elasticsearch-sentiment    文件:DeleteRiverStateAction.java   
@Override
public DeleteRiverStateRequestBuilder newRequestBuilder(ClusterAdminClient client) {
    return new DeleteRiverStateRequestBuilder(client);
}
项目:elasticsearch-sentiment    文件:PutRiverStateRequestBuilder.java   
public PutRiverStateRequestBuilder(ClusterAdminClient client) {
    super(client, new PutRiverStateRequest());
}
项目:elasticsearch-sentiment    文件:PutRiverStateAction.java   
@Override
public PutRiverStateRequestBuilder newRequestBuilder(ClusterAdminClient client) {
    return new PutRiverStateRequestBuilder(client);
}
项目:elasticsearch-sentiment    文件:RiverExecuteRequestBuilder.java   
public RiverExecuteRequestBuilder(ClusterAdminClient client) {
    super(client, new RiverExecuteRequest());
}