Search in sources :

Example 1 with SnapshotMissingException

use of org.elasticsearch.snapshots.SnapshotMissingException in project elasticsearch by elastic.

the class AbstractS3SnapshotRestoreTest method testNonExistingRepo86.

/**
     * Test case for issue #86: https://github.com/elastic/elasticsearch-cloud-aws/issues/86
     */
public void testNonExistingRepo86() {
    Client client = client();
    logger.info("-->  creating s3 repository with bucket[{}] and path [{}]", internalCluster().getInstance(Settings.class).get("repositories.s3.bucket"), basePath);
    PutRepositoryResponse putRepositoryResponse = client.admin().cluster().preparePutRepository("test-repo").setType("s3").setSettings(Settings.builder().put(S3Repository.Repository.BASE_PATH_SETTING.getKey(), basePath)).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    logger.info("--> restore non existing snapshot");
    try {
        client.admin().cluster().prepareRestoreSnapshot("test-repo", "no-existing-snapshot").setWaitForCompletion(true).execute().actionGet();
        fail("Shouldn't be here");
    } catch (SnapshotMissingException ex) {
    // Expected
    }
}
Also used : SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) PutRepositoryResponse(org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse) Client(org.elasticsearch.client.Client) ClusterAdminClient(org.elasticsearch.client.ClusterAdminClient)

Example 2 with SnapshotMissingException

use of org.elasticsearch.snapshots.SnapshotMissingException 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 3 with SnapshotMissingException

use of org.elasticsearch.snapshots.SnapshotMissingException 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 SnapshotMissingException

use of org.elasticsearch.snapshots.SnapshotMissingException in project elasticsearch by elastic.

the class TransportSnapshotsStatusAction method buildResponse.

private SnapshotsStatusResponse buildResponse(SnapshotsStatusRequest request, List<SnapshotsInProgress.Entry> currentSnapshotEntries, TransportNodesSnapshotsStatus.NodesSnapshotStatus nodeSnapshotStatuses) throws IOException {
    // First process snapshot that are currently processed
    List<SnapshotStatus> builder = new ArrayList<>();
    Set<String> currentSnapshotNames = new HashSet<>();
    if (!currentSnapshotEntries.isEmpty()) {
        Map<String, TransportNodesSnapshotsStatus.NodeSnapshotStatus> nodeSnapshotStatusMap;
        if (nodeSnapshotStatuses != null) {
            nodeSnapshotStatusMap = nodeSnapshotStatuses.getNodesMap();
        } else {
            nodeSnapshotStatusMap = new HashMap<>();
        }
        for (SnapshotsInProgress.Entry entry : currentSnapshotEntries) {
            currentSnapshotNames.add(entry.snapshot().getSnapshotId().getName());
            List<SnapshotIndexShardStatus> shardStatusBuilder = new ArrayList<>();
            for (ObjectObjectCursor<ShardId, SnapshotsInProgress.ShardSnapshotStatus> shardEntry : entry.shards()) {
                SnapshotsInProgress.ShardSnapshotStatus status = shardEntry.value;
                if (status.nodeId() != null) {
                    // We should have information about this shard from the shard:
                    TransportNodesSnapshotsStatus.NodeSnapshotStatus nodeStatus = nodeSnapshotStatusMap.get(status.nodeId());
                    if (nodeStatus != null) {
                        Map<ShardId, SnapshotIndexShardStatus> shardStatues = nodeStatus.status().get(entry.snapshot());
                        if (shardStatues != null) {
                            SnapshotIndexShardStatus shardStatus = shardStatues.get(shardEntry.key);
                            if (shardStatus != null) {
                                // We have full information about this shard
                                shardStatusBuilder.add(shardStatus);
                                continue;
                            }
                        }
                    }
                }
                final SnapshotIndexShardStage stage;
                switch(shardEntry.value.state()) {
                    case FAILED:
                    case ABORTED:
                    case MISSING:
                        stage = SnapshotIndexShardStage.FAILURE;
                        break;
                    case INIT:
                    case WAITING:
                    case STARTED:
                        stage = SnapshotIndexShardStage.STARTED;
                        break;
                    case SUCCESS:
                        stage = SnapshotIndexShardStage.DONE;
                        break;
                    default:
                        throw new IllegalArgumentException("Unknown snapshot state " + shardEntry.value.state());
                }
                SnapshotIndexShardStatus shardStatus = new SnapshotIndexShardStatus(shardEntry.key, stage);
                shardStatusBuilder.add(shardStatus);
            }
            builder.add(new SnapshotStatus(entry.snapshot(), entry.state(), Collections.unmodifiableList(shardStatusBuilder)));
        }
    }
    // Now add snapshots on disk that are not currently running
    final String repositoryName = request.repository();
    if (Strings.hasText(repositoryName) && request.snapshots() != null && request.snapshots().length > 0) {
        final Set<String> requestedSnapshotNames = Sets.newHashSet(request.snapshots());
        final RepositoryData repositoryData = snapshotsService.getRepositoryData(repositoryName);
        final Map<String, SnapshotId> matchedSnapshotIds = repositoryData.getAllSnapshotIds().stream().filter(s -> requestedSnapshotNames.contains(s.getName())).collect(Collectors.toMap(SnapshotId::getName, Function.identity()));
        for (final String snapshotName : request.snapshots()) {
            if (currentSnapshotNames.contains(snapshotName)) {
                // we've already found this snapshot in the current snapshot entries, so skip over
                continue;
            }
            SnapshotId snapshotId = matchedSnapshotIds.get(snapshotName);
            if (snapshotId == null) {
                // neither in the current snapshot entries nor found in the repository
                if (request.ignoreUnavailable()) {
                    // ignoring unavailable snapshots, so skip over
                    logger.debug("snapshot status request ignoring snapshot [{}], not found in repository [{}]", snapshotName, repositoryName);
                    continue;
                } else {
                    throw new SnapshotMissingException(repositoryName, snapshotName);
                }
            } else if (repositoryData.getIncompatibleSnapshotIds().contains(snapshotId)) {
                throw new SnapshotException(repositoryName, snapshotName, "cannot get the status for an incompatible snapshot");
            }
            SnapshotInfo snapshotInfo = snapshotsService.snapshot(repositoryName, snapshotId);
            List<SnapshotIndexShardStatus> shardStatusBuilder = new ArrayList<>();
            if (snapshotInfo.state().completed()) {
                Map<ShardId, IndexShardSnapshotStatus> shardStatues = snapshotsService.snapshotShards(request.repository(), snapshotInfo);
                for (Map.Entry<ShardId, IndexShardSnapshotStatus> shardStatus : shardStatues.entrySet()) {
                    shardStatusBuilder.add(new SnapshotIndexShardStatus(shardStatus.getKey(), shardStatus.getValue()));
                }
                final SnapshotsInProgress.State state;
                switch(snapshotInfo.state()) {
                    case FAILED:
                        state = SnapshotsInProgress.State.FAILED;
                        break;
                    case SUCCESS:
                    case PARTIAL:
                        // Translating both PARTIAL and SUCCESS to SUCCESS for now
                        // TODO: add the differentiation on the metadata level in the next major release
                        state = SnapshotsInProgress.State.SUCCESS;
                        break;
                    default:
                        throw new IllegalArgumentException("Unknown snapshot state " + snapshotInfo.state());
                }
                builder.add(new SnapshotStatus(new Snapshot(repositoryName, snapshotId), state, Collections.unmodifiableList(shardStatusBuilder)));
            }
        }
    }
    return new SnapshotsStatusResponse(Collections.unmodifiableList(builder));
}
Also used : ShardId(org.elasticsearch.index.shard.ShardId) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) SnapshotId(org.elasticsearch.snapshots.SnapshotId) Arrays(java.util.Arrays) ClusterService(org.elasticsearch.cluster.service.ClusterService) IndexShardSnapshotStatus(org.elasticsearch.index.snapshots.IndexShardSnapshotStatus) HashMap(java.util.HashMap) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) Function(java.util.function.Function) Strings(org.elasticsearch.common.Strings) Inject(org.elasticsearch.common.inject.Inject) ArrayList(java.util.ArrayList) TransportMasterNodeAction(org.elasticsearch.action.support.master.TransportMasterNodeAction) HashSet(java.util.HashSet) ObjectObjectCursor(com.carrotsearch.hppc.cursors.ObjectObjectCursor) ClusterState(org.elasticsearch.cluster.ClusterState) Settings(org.elasticsearch.common.settings.Settings) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) Map(java.util.Map) ThreadPool(org.elasticsearch.threadpool.ThreadPool) TransportService(org.elasticsearch.transport.TransportService) ClusterBlockLevel(org.elasticsearch.cluster.block.ClusterBlockLevel) ActionFilters(org.elasticsearch.action.support.ActionFilters) SnapshotsService(org.elasticsearch.snapshots.SnapshotsService) Set(java.util.Set) IOException(java.io.IOException) ObjectCursor(com.carrotsearch.hppc.cursors.ObjectCursor) Collectors(java.util.stream.Collectors) Sets(org.elasticsearch.common.util.set.Sets) List(java.util.List) SnapshotException(org.elasticsearch.snapshots.SnapshotException) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver) Snapshot(org.elasticsearch.snapshots.Snapshot) Collections(java.util.Collections) ActionListener(org.elasticsearch.action.ActionListener) RepositoryData(org.elasticsearch.repositories.RepositoryData) IndexShardSnapshotStatus(org.elasticsearch.index.snapshots.IndexShardSnapshotStatus) ArrayList(java.util.ArrayList) ShardId(org.elasticsearch.index.shard.ShardId) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) HashSet(java.util.HashSet) SnapshotException(org.elasticsearch.snapshots.SnapshotException) RepositoryData(org.elasticsearch.repositories.RepositoryData) SnapshotId(org.elasticsearch.snapshots.SnapshotId) Snapshot(org.elasticsearch.snapshots.Snapshot) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) IndexShardSnapshotStatus(org.elasticsearch.index.snapshots.IndexShardSnapshotStatus) SnapshotsInProgress(org.elasticsearch.cluster.SnapshotsInProgress) IndexShardSnapshotStatus(org.elasticsearch.index.snapshots.IndexShardSnapshotStatus) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with SnapshotMissingException

use of org.elasticsearch.snapshots.SnapshotMissingException in project elasticsearch by elastic.

the class TransportGetSnapshotsAction method masterOperation.

@Override
protected void masterOperation(final GetSnapshotsRequest request, ClusterState state, final ActionListener<GetSnapshotsResponse> listener) {
    try {
        final String repository = request.repository();
        List<SnapshotInfo> snapshotInfoBuilder = new ArrayList<>();
        final Map<String, SnapshotId> allSnapshotIds = new HashMap<>();
        final List<SnapshotId> currentSnapshotIds = new ArrayList<>();
        for (SnapshotInfo snapshotInfo : snapshotsService.currentSnapshots(repository)) {
            SnapshotId snapshotId = snapshotInfo.snapshotId();
            allSnapshotIds.put(snapshotId.getName(), snapshotId);
            currentSnapshotIds.add(snapshotId);
        }
        if (isCurrentSnapshotsOnly(request.snapshots()) == false) {
            for (SnapshotId snapshotId : snapshotsService.getRepositoryData(repository).getAllSnapshotIds()) {
                allSnapshotIds.put(snapshotId.getName(), snapshotId);
            }
        }
        final Set<SnapshotId> toResolve = new HashSet<>();
        if (isAllSnapshots(request.snapshots())) {
            toResolve.addAll(allSnapshotIds.values());
        } else {
            for (String snapshotOrPattern : request.snapshots()) {
                if (GetSnapshotsRequest.CURRENT_SNAPSHOT.equalsIgnoreCase(snapshotOrPattern)) {
                    toResolve.addAll(currentSnapshotIds);
                } else if (Regex.isSimpleMatchPattern(snapshotOrPattern) == false) {
                    if (allSnapshotIds.containsKey(snapshotOrPattern)) {
                        toResolve.add(allSnapshotIds.get(snapshotOrPattern));
                    } else if (request.ignoreUnavailable() == false) {
                        throw new SnapshotMissingException(repository, snapshotOrPattern);
                    }
                } else {
                    for (Map.Entry<String, SnapshotId> entry : allSnapshotIds.entrySet()) {
                        if (Regex.simpleMatch(snapshotOrPattern, entry.getKey())) {
                            toResolve.add(entry.getValue());
                        }
                    }
                }
            }
            if (toResolve.isEmpty() && request.ignoreUnavailable() == false && isCurrentSnapshotsOnly(request.snapshots()) == false) {
                throw new SnapshotMissingException(repository, request.snapshots()[0]);
            }
        }
        snapshotInfoBuilder.addAll(snapshotsService.snapshots(repository, new ArrayList<>(toResolve), request.ignoreUnavailable()));
        listener.onResponse(new GetSnapshotsResponse(snapshotInfoBuilder));
    } catch (Exception e) {
        listener.onFailure(e);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) ClusterBlockException(org.elasticsearch.cluster.block.ClusterBlockException) SnapshotId(org.elasticsearch.snapshots.SnapshotId) SnapshotInfo(org.elasticsearch.snapshots.SnapshotInfo) SnapshotMissingException(org.elasticsearch.snapshots.SnapshotMissingException) HashSet(java.util.HashSet)

Aggregations

SnapshotMissingException (org.elasticsearch.snapshots.SnapshotMissingException)8 PutRepositoryResponse (org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryResponse)4 ClusterAdminClient (org.elasticsearch.client.ClusterAdminClient)4 IOException (java.io.IOException)3 SnapshotException (org.elasticsearch.snapshots.SnapshotException)3 SnapshotInfo (org.elasticsearch.snapshots.SnapshotInfo)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)2 Supplier (org.apache.logging.log4j.util.Supplier)2 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)2 Client (org.elasticsearch.client.Client)2 ClusterBlockException (org.elasticsearch.cluster.block.ClusterBlockException)2 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)2 MetaData (org.elasticsearch.cluster.metadata.MetaData)2 RepositoryMetaData (org.elasticsearch.cluster.metadata.RepositoryMetaData)2 BlobContainer (org.elasticsearch.common.blobstore.BlobContainer)2 BlobMetaData (org.elasticsearch.common.blobstore.BlobMetaData)2 BlobPath (org.elasticsearch.common.blobstore.BlobPath)2