Search in sources :

Example 1 with ClusterAdminClient

use of org.elasticsearch.client.ClusterAdminClient in project elasticsearch by elastic.

the class AbstractS3SnapshotRestoreTest method testGetDeleteNonExistingSnapshot86.

/**
     * For issue #86: https://github.com/elastic/elasticsearch-cloud-aws/issues/86
     */
public void testGetDeleteNonExistingSnapshot86() {
    ClusterAdminClient client = client().admin().cluster();
    logger.info("-->  creating s3 repository without any path");
    PutRepositoryResponse putRepositoryResponse = client.preparePutRepository("test-repo").setType("s3").setSettings(Settings.builder().put(S3Repository.Repository.BASE_PATH_SETTING.getKey(), basePath)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    try {
        client.prepareGetSnapshots("test-repo").addSnapshots("no-existing-snapshot").get();
        fail("Shouldn't be here");
    } catch (SnapshotMissingException ex) {
    // Expected
    }
    try {
        client.prepareDeleteSnapshot("test-repo", "no-existing-snapshot").get();
        fail("Shouldn't be here");
    } catch (SnapshotMissingException ex) {
    // Expected
    }
}
Also used : ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)

Example 2 with ClusterAdminClient

use of org.elasticsearch.client.ClusterAdminClient in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method testListBlobs_26.

/**
     * 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));
}
Also used : CreateSnapshotResponse(org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)

Example 3 with ClusterAdminClient

use of org.elasticsearch.client.ClusterAdminClient in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method testGetDeleteNonExistingSnapshot_28.

/**
     * For issue #28: https://github.com/elastic/elasticsearch-cloud-azure/issues/28
     */
public void testGetDeleteNonExistingSnapshot_28() throws StorageException, URISyntaxException {
    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));
    try {
        client.prepareGetSnapshots("test-repo").addSnapshots("nonexistingsnapshotname").get();
        fail("Shouldn't be here");
    } catch (SnapshotMissingException ex) {
    // Expected
    }
    try {
        client.prepareDeleteSnapshot("test-repo", "nonexistingsnapshotname").get();
        fail("Shouldn't be here");
    } catch (SnapshotMissingException ex) {
    // Expected
    }
}
Also used : ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)

Example 4 with ClusterAdminClient

use of org.elasticsearch.client.ClusterAdminClient in project elasticsearch by elastic.

the class AzureSnapshotRestoreTests method testRemoveAndCreateContainer.

/**
     * When a user remove a container you can not immediately create it again.
     */
public void testRemoveAndCreateContainer() throws Exception {
    final String container = getContainerName().concat("-testremove");
    final AzureStorageService storageService = new AzureStorageServiceImpl(internalCluster().getDefaultSettings());
    // It could happen that we run this test really close to a previous one
    // so we might need some time to be able to create the container
    assertBusy(() -> {
        try {
            storageService.createContainer(null, LocationMode.PRIMARY_ONLY, container);
            logger.debug(" -> container created...");
        } catch (URISyntaxException e) {
            // Incorrect URL. This should never happen.
            fail();
        } catch (StorageException e) {
            // It could happen. Let's wait for a while.
            logger.debug(" -> container is being removed. Let's wait a bit...");
            fail();
        }
    }, 30, TimeUnit.SECONDS);
    storageService.removeContainer(null, LocationMode.PRIMARY_ONLY, container);
    ClusterAdminClient client = client().admin().cluster();
    logger.info("-->  creating azure repository while container is being removed");
    try {
        client.preparePutRepository("test-repo").setType("azure").setSettings(Settings.builder().put(Repository.CONTAINER_SETTING.getKey(), container)).get();
        fail("we should get a RepositoryVerificationException");
    } catch (RepositoryVerificationException e) {
    // Fine we expect that
    }
}
Also used : AzureStorageServiceImpl(org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) RepositoryVerificationException(org.elasticsearch.repositories.RepositoryVerificationException) URISyntaxException(java.net.URISyntaxException) AzureStorageService(org.elasticsearch.cloud.azure.storage.AzureStorageService) StorageException(com.microsoft.azure.storage.StorageException)

Example 5 with ClusterAdminClient

use of org.elasticsearch.client.ClusterAdminClient in project graylog2-server by Graylog2.

the class ElasticsearchProbe method elasticsearchStats.

public ElasticsearchStats elasticsearchStats() {
    final ClusterAdminClient adminClient = client.admin().cluster();
    final ClusterStatsResponse clusterStatsResponse = adminClient.clusterStats(new ClusterStatsRequest()).actionGet();
    final String clusterName = clusterStatsResponse.getClusterNameAsString();
    final ClusterStatsNodes clusterNodesStats = clusterStatsResponse.getNodesStats();
    final NodesStats nodesStats = NodesStats.create(clusterNodesStats.getCounts().getTotal(), clusterNodesStats.getCounts().getMasterOnly(), clusterNodesStats.getCounts().getDataOnly(), clusterNodesStats.getCounts().getMasterData(), clusterNodesStats.getCounts().getClient());
    final IndicesStats indicesStats = IndicesStats.create(clusterStatsResponse.getIndicesStats().getIndexCount(), clusterStatsResponse.getIndicesStats().getStore().sizeInBytes(), clusterStatsResponse.getIndicesStats().getFieldData().getMemorySizeInBytes());
    final PendingClusterTasksResponse pendingClusterTasksResponse = adminClient.pendingClusterTasks(new PendingClusterTasksRequest()).actionGet();
    final int pendingTasksSize = pendingClusterTasksResponse.pendingTasks().size();
    final List<Long> pendingTasksTimeInQueue = Lists.newArrayListWithCapacity(pendingTasksSize);
    for (PendingClusterTask pendingClusterTask : pendingClusterTasksResponse) {
        pendingTasksTimeInQueue.add(pendingClusterTask.getTimeInQueueInMillis());
    }
    final ClusterHealthResponse clusterHealthResponse = adminClient.health(new ClusterHealthRequest(indexSetRegistry.getIndexWildcards())).actionGet();
    final ClusterHealth clusterHealth = ClusterHealth.create(clusterHealthResponse.getNumberOfNodes(), clusterHealthResponse.getNumberOfDataNodes(), clusterHealthResponse.getActiveShards(), clusterHealthResponse.getRelocatingShards(), clusterHealthResponse.getActivePrimaryShards(), clusterHealthResponse.getInitializingShards(), clusterHealthResponse.getUnassignedShards(), clusterHealthResponse.isTimedOut(), pendingTasksSize, pendingTasksTimeInQueue);
    return ElasticsearchStats.create(clusterName, clusterHealthResponse.getStatus(), clusterHealth, nodesStats, indicesStats);
}
Also used : ClusterHealthResponse(org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient) ClusterHealthRequest(org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest) ClusterStatsNodes(org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodes) PendingClusterTask(org.elasticsearch.cluster.service.PendingClusterTask) PendingClusterTasksResponse(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse) ClusterStatsRequest(org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest) PendingClusterTasksRequest(org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest) ClusterStatsResponse(org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse)

Aggregations

ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)7 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 SnapshotMissingException (org.elasticsearch.snapshots.SnapshotMissingException)2 StorageException (com.microsoft.azure.storage.StorageException)1 URISyntaxException (java.net.URISyntaxException)1 ClusterHealthRequest (org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest)1 ClusterHealthResponse (org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse)1 NodeInfo (org.elasticsearch.action.admin.cluster.node.info.NodeInfo)1 NodesInfoRequest (org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)1 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)1 NodesStatsRequest (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest)1 CreateSnapshotResponse (org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse)1 ClusterStatsNodes (org.elasticsearch.action.admin.cluster.stats.ClusterStatsNodes)1 ClusterStatsRequest (org.elasticsearch.action.admin.cluster.stats.ClusterStatsRequest)1 ClusterStatsResponse (org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse)1 PendingClusterTasksRequest (org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksRequest)1 PendingClusterTasksResponse (org.elasticsearch.action.admin.cluster.tasks.PendingClusterTasksResponse)1 AzureStorageService (org.elasticsearch.cloud.azure.storage.AzureStorageService)1 AzureStorageServiceImpl (org.elasticsearch.cloud.azure.storage.AzureStorageServiceImpl)1