Search in sources :

Example 11 with RepositoryException

use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.

the class OpenSearchExceptionTests method testFailureToAndFromXContentWithDetails.

public void testFailureToAndFromXContentWithDetails() throws IOException {
    final XContent xContent = randomFrom(XContentType.values()).xContent();
    Exception failure;
    Throwable failureCause;
    OpenSearchException expected;
    OpenSearchException expectedCause;
    OpenSearchException suppressed;
    switch(randomIntBetween(0, 6)) {
        case // Simple opensearch exception without cause
        0:
            failure = new NoNodeAvailableException("A");
            expected = new OpenSearchException("OpenSearch exception [type=no_node_available_exception, reason=A]");
            expected.addSuppressed(new OpenSearchException("OpenSearch exception [type=no_node_available_exception, reason=A]"));
            break;
        case // Simple opensearch exception with headers (other metadata of type number are not parsed)
        1:
            failure = new ParsingException(3, 2, "B", null);
            ((OpenSearchException) failure).addHeader("header_name", "0", "1");
            expected = new OpenSearchException("OpenSearch exception [type=parsing_exception, reason=B]");
            expected.addHeader("header_name", "0", "1");
            suppressed = new OpenSearchException("OpenSearch exception [type=parsing_exception, reason=B]");
            suppressed.addHeader("header_name", "0", "1");
            expected.addSuppressed(suppressed);
            break;
        case // OpenSearch exception with a cause, headers and parsable metadata
        2:
            failureCause = new NullPointerException("var is null");
            failure = new ScriptException("C", failureCause, singletonList("stack"), "test", "painless");
            ((OpenSearchException) failure).addHeader("script_name", "my_script");
            expectedCause = new OpenSearchException("OpenSearch exception [type=null_pointer_exception, reason=var is null]");
            expected = new OpenSearchException("OpenSearch exception [type=script_exception, reason=C]", expectedCause);
            expected.addHeader("script_name", "my_script");
            expected.addMetadata("opensearch.lang", "painless");
            expected.addMetadata("opensearch.script", "test");
            expected.addMetadata("opensearch.script_stack", "stack");
            suppressed = new OpenSearchException("OpenSearch exception [type=script_exception, reason=C]");
            suppressed.addHeader("script_name", "my_script");
            suppressed.addMetadata("opensearch.lang", "painless");
            suppressed.addMetadata("opensearch.script", "test");
            suppressed.addMetadata("opensearch.script_stack", "stack");
            expected.addSuppressed(suppressed);
            break;
        case // JDK exception without cause
        3:
            failure = new IllegalStateException("D");
            expected = new OpenSearchException("OpenSearch exception [type=illegal_state_exception, reason=D]");
            suppressed = new OpenSearchException("OpenSearch exception [type=illegal_state_exception, reason=D]");
            expected.addSuppressed(suppressed);
            break;
        case // JDK exception with cause
        4:
            failureCause = new RoutingMissingException("idx", "id");
            failure = new RuntimeException("E", failureCause);
            expectedCause = new OpenSearchException("OpenSearch exception [type=routing_missing_exception, " + "reason=routing is required for [idx]/[id]]");
            expectedCause.addMetadata("opensearch.index", "idx");
            expectedCause.addMetadata("opensearch.index_uuid", "_na_");
            expected = new OpenSearchException("OpenSearch exception [type=runtime_exception, reason=E]", expectedCause);
            suppressed = new OpenSearchException("OpenSearch exception [type=runtime_exception, reason=E]");
            expected.addSuppressed(suppressed);
            break;
        case // Wrapped exception with cause
        5:
            failureCause = new FileAlreadyExistsException("File exists");
            failure = new BroadcastShardOperationFailedException(new ShardId("_index", "_uuid", 5), "F", failureCause);
            expected = new OpenSearchException("OpenSearch exception [type=file_already_exists_exception, reason=File exists]");
            suppressed = new OpenSearchException("OpenSearch exception [type=file_already_exists_exception, reason=File exists]");
            expected.addSuppressed(suppressed);
            break;
        case // SearchPhaseExecutionException with cause and multiple failures
        6:
            DiscoveryNode node = new DiscoveryNode("node_g", buildNewFakeTransportAddress(), Version.CURRENT);
            failureCause = new NodeClosedException(node);
            failureCause = new NoShardAvailableActionException(new ShardId("_index_g", "_uuid_g", 6), "node_g", failureCause);
            ShardSearchFailure[] shardFailures = new ShardSearchFailure[] { new ShardSearchFailure(new ParsingException(0, 0, "Parsing g", null), new SearchShardTarget("node_g", new ShardId(new Index("_index_g", "_uuid_g"), 61), null, OriginalIndices.NONE)), new ShardSearchFailure(new RepositoryException("repository_g", "Repo"), new SearchShardTarget("node_g", new ShardId(new Index("_index_g", "_uuid_g"), 62), null, OriginalIndices.NONE)), new ShardSearchFailure(new SearchContextMissingException(new ShardSearchContextId(UUIDs.randomBase64UUID(), 0L)), null) };
            failure = new SearchPhaseExecutionException("phase_g", "G", failureCause, shardFailures);
            expectedCause = new OpenSearchException("OpenSearch exception [type=node_closed_exception, " + "reason=node closed " + node + "]");
            expectedCause = new OpenSearchException("OpenSearch exception [type=no_shard_available_action_exception, " + "reason=node_g]", expectedCause);
            expectedCause.addMetadata("opensearch.index", "_index_g");
            expectedCause.addMetadata("opensearch.index_uuid", "_uuid_g");
            expectedCause.addMetadata("opensearch.shard", "6");
            expected = new OpenSearchException("OpenSearch exception [type=search_phase_execution_exception, " + "reason=G]", expectedCause);
            expected.addMetadata("opensearch.phase", "phase_g");
            expected.addSuppressed(new OpenSearchException("OpenSearch exception [type=parsing_exception, reason=Parsing g]"));
            expected.addSuppressed(new OpenSearchException("OpenSearch exception [type=repository_exception, " + "reason=[repository_g] Repo]"));
            expected.addSuppressed(new OpenSearchException("OpenSearch exception [type=search_context_missing_exception, " + "reason=No search context found for id [0]]"));
            break;
        default:
            throw new UnsupportedOperationException("Failed to generate randomized failure");
    }
    Exception finalFailure = failure;
    BytesReference failureBytes = toShuffledXContent((builder, params) -> {
        OpenSearchException.generateFailureXContent(builder, params, finalFailure, true);
        return builder;
    }, xContent.type(), ToXContent.EMPTY_PARAMS, randomBoolean());
    try (XContentParser parser = createParser(xContent, failureBytes)) {
        failureBytes = BytesReference.bytes(shuffleXContent(parser, randomBoolean()));
    }
    OpenSearchException parsedFailure;
    try (XContentParser parser = createParser(xContent, failureBytes)) {
        assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
        assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
        parsedFailure = OpenSearchException.failureFromXContent(parser);
        assertEquals(XContentParser.Token.END_OBJECT, parser.nextToken());
        assertNull(parser.nextToken());
    }
    assertDeepEquals(expected, parsedFailure);
}
Also used : FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) Index(org.opensearch.index.Index) ShardId(org.opensearch.index.shard.ShardId) ScriptException(org.opensearch.script.ScriptException) ToXContent(org.opensearch.common.xcontent.ToXContent) XContent(org.opensearch.common.xcontent.XContent) ParsingException(org.opensearch.common.ParsingException) NodeClosedException(org.opensearch.node.NodeClosedException) BroadcastShardOperationFailedException(org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException) ShardSearchFailure(org.opensearch.action.search.ShardSearchFailure) RoutingMissingException(org.opensearch.action.RoutingMissingException) BytesReference(org.opensearch.common.bytes.BytesReference) SearchContextMissingException(org.opensearch.search.SearchContextMissingException) RepositoryException(org.opensearch.repositories.RepositoryException) NoNodeAvailableException(org.opensearch.client.transport.NoNodeAvailableException) IndexShardRecoveringException(org.opensearch.index.shard.IndexShardRecoveringException) NoNodeAvailableException(org.opensearch.client.transport.NoNodeAvailableException) ScriptException(org.opensearch.script.ScriptException) NodeClosedException(org.opensearch.node.NodeClosedException) BroadcastShardOperationFailedException(org.opensearch.action.support.broadcast.BroadcastShardOperationFailedException) ParsingException(org.opensearch.common.ParsingException) RepositoryException(org.opensearch.repositories.RepositoryException) RemoteTransportException(org.opensearch.transport.RemoteTransportException) ClusterBlockException(org.opensearch.cluster.block.ClusterBlockException) QueryShardException(org.opensearch.index.query.QueryShardException) SearchParseException(org.opensearch.search.SearchParseException) SearchContextMissingException(org.opensearch.search.SearchContextMissingException) EOFException(java.io.EOFException) FileNotFoundException(java.io.FileNotFoundException) RoutingMissingException(org.opensearch.action.RoutingMissingException) IndexNotFoundException(org.opensearch.index.IndexNotFoundException) IOException(java.io.IOException) FileAlreadyExistsException(java.nio.file.FileAlreadyExistsException) SearchPhaseExecutionException(org.opensearch.action.search.SearchPhaseExecutionException) XContentParseException(org.opensearch.common.xcontent.XContentParseException) NoShardAvailableActionException(org.opensearch.action.NoShardAvailableActionException) ShardSearchContextId(org.opensearch.search.internal.ShardSearchContextId) NoShardAvailableActionException(org.opensearch.action.NoShardAvailableActionException) SearchShardTarget(org.opensearch.search.SearchShardTarget) XContentParser(org.opensearch.common.xcontent.XContentParser)

Example 12 with RepositoryException

use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.

the class MultiClusterRepoAccessIT method testConcurrentDeleteFromOtherCluster.

public void testConcurrentDeleteFromOtherCluster() throws InterruptedException {
    internalCluster().startMasterOnlyNode();
    internalCluster().startDataOnlyNode();
    final String repoNameOnFirstCluster = "test-repo";
    final String repoNameOnSecondCluster = randomBoolean() ? "test-repo" : "other-repo";
    createRepository(repoNameOnFirstCluster, "fs", repoPath);
    secondCluster.startMasterOnlyNode();
    secondCluster.startDataOnlyNode();
    secondCluster.client().admin().cluster().preparePutRepository(repoNameOnSecondCluster).setType("fs").setSettings(Settings.builder().put("location", repoPath)).get();
    createIndexWithRandomDocs("test-idx-1", randomIntBetween(1, 100));
    createFullSnapshot(repoNameOnFirstCluster, "snap-1");
    createIndexWithRandomDocs("test-idx-2", randomIntBetween(1, 100));
    createFullSnapshot(repoNameOnFirstCluster, "snap-2");
    createIndexWithRandomDocs("test-idx-3", randomIntBetween(1, 100));
    createFullSnapshot(repoNameOnFirstCluster, "snap-3");
    secondCluster.client().admin().cluster().prepareDeleteSnapshot(repoNameOnSecondCluster, "snap-1").get();
    secondCluster.client().admin().cluster().prepareDeleteSnapshot(repoNameOnSecondCluster, "snap-2").get();
    final SnapshotException sne = expectThrows(SnapshotException.class, () -> client().admin().cluster().prepareCreateSnapshot(repoNameOnFirstCluster, "snap-4").setWaitForCompletion(true).execute().actionGet());
    assertThat(sne.getMessage(), containsString("failed to update snapshot in repository"));
    final RepositoryException cause = (RepositoryException) sne.getCause();
    assertThat(cause.getMessage(), containsString("[" + repoNameOnFirstCluster + "] concurrent modification of the index-N file, expected current generation [2] but it was not found in the repository"));
    assertAcked(client().admin().cluster().prepareDeleteRepository(repoNameOnFirstCluster).get());
    createRepository(repoNameOnFirstCluster, "fs", repoPath);
    createFullSnapshot(repoNameOnFirstCluster, "snap-5");
}
Also used : RepositoryException(org.opensearch.repositories.RepositoryException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 13 with RepositoryException

use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.

the class ConcurrentSnapshotsIT method testMasterFailoverOnFinalizationLoop.

public void testMasterFailoverOnFinalizationLoop() throws Exception {
    internalCluster().startMasterOnlyNodes(3);
    final String dataNode = internalCluster().startDataOnlyNode();
    final String repoName = "test-repo";
    createRepository(repoName, "mock");
    createIndexWithContent("index-test");
    final NetworkDisruption networkDisruption = isolateMasterDisruption(NetworkDisruption.DISCONNECT);
    internalCluster().setDisruptionScheme(networkDisruption);
    final List<String> snapshotNames = createNSnapshots(repoName, randomIntBetween(2, 5));
    final String masterName = internalCluster().getMasterName();
    blockMasterFromDeletingIndexNFile(repoName);
    final ActionFuture<CreateSnapshotResponse> snapshotThree = startFullSnapshotFromMasterClient(repoName, "snap-other");
    waitForBlock(masterName, repoName, TimeValue.timeValueSeconds(30L));
    final String snapshotOne = snapshotNames.get(0);
    final ActionFuture<AcknowledgedResponse> deleteSnapshotOne = startDeleteSnapshot(repoName, snapshotOne);
    awaitNDeletionsInProgress(1);
    networkDisruption.startDisrupting();
    ensureStableCluster(3, dataNode);
    unblockNode(repoName, masterName);
    networkDisruption.stopDisrupting();
    ensureStableCluster(4);
    assertSuccessful(snapshotThree);
    try {
        deleteSnapshotOne.actionGet();
    } catch (RepositoryException re) {
    // ignored
    }
    awaitNoMoreRunningOperations();
}
Also used : CreateSnapshotResponse(org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse) AcknowledgedResponse(org.opensearch.action.support.master.AcknowledgedResponse) RepositoryException(org.opensearch.repositories.RepositoryException) Matchers.containsString(org.hamcrest.Matchers.containsString) NetworkDisruption(org.opensearch.test.disruption.NetworkDisruption)

Example 14 with RepositoryException

use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.

the class URLRepositoryTests method testIfNotWhiteListedMustSetRepoURL.

public void testIfNotWhiteListedMustSetRepoURL() throws IOException {
    String repoPath = createTempDir().resolve("repository").toUri().toURL().toString();
    Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(URLRepository.REPOSITORIES_URL_SETTING.getKey(), repoPath).build();
    RepositoryMetadata repositoryMetadata = new RepositoryMetadata("url", URLRepository.TYPE, baseSettings);
    final URLRepository repository = createRepository(baseSettings, repositoryMetadata);
    repository.start();
    try {
        repository.blobContainer();
        fail("RepositoryException should have been thrown.");
    } catch (RepositoryException e) {
        String msg = "[url] file url [" + repoPath + "] doesn't match any of the locations specified by path.repo or repositories.url.allowed_urls";
        assertEquals(msg, e.getMessage());
    }
}
Also used : RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) RepositoryException(org.opensearch.repositories.RepositoryException) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings)

Example 15 with RepositoryException

use of org.opensearch.repositories.RepositoryException in project OpenSearch by opensearch-project.

the class URLRepositoryTests method testMustBeSupportedProtocol.

public void testMustBeSupportedProtocol() throws IOException {
    Path directory = createTempDir();
    String repoPath = directory.resolve("repository").toUri().toURL().toString();
    Settings baseSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString()).put(Environment.PATH_REPO_SETTING.getKey(), directory.toString()).put(URLRepository.REPOSITORIES_URL_SETTING.getKey(), repoPath).put(URLRepository.SUPPORTED_PROTOCOLS_SETTING.getKey(), "http,https").build();
    RepositoryMetadata repositoryMetadata = new RepositoryMetadata("url", URLRepository.TYPE, baseSettings);
    final URLRepository repository = createRepository(baseSettings, repositoryMetadata);
    repository.start();
    try {
        repository.blobContainer();
        fail("RepositoryException should have been thrown.");
    } catch (RepositoryException e) {
        assertEquals("[url] unsupported url protocol [file] from URL [" + repoPath + "]", e.getMessage());
    }
}
Also used : Path(java.nio.file.Path) RepositoryMetadata(org.opensearch.cluster.metadata.RepositoryMetadata) RepositoryException(org.opensearch.repositories.RepositoryException) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings) RecoverySettings(org.opensearch.indices.recovery.RecoverySettings)

Aggregations

RepositoryException (org.opensearch.repositories.RepositoryException)24 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)9 Settings (org.opensearch.common.settings.Settings)9 List (java.util.List)8 Set (java.util.Set)7 Executor (java.util.concurrent.Executor)7 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)7 Collection (java.util.Collection)6 Collections (java.util.Collections)6 Map (java.util.Map)6 Optional (java.util.Optional)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 Consumer (java.util.function.Consumer)6 Function (java.util.function.Function)6 Collectors (java.util.stream.Collectors)6 Stream (java.util.stream.Stream)6 LogManager (org.apache.logging.log4j.LogManager)6 Logger (org.apache.logging.log4j.Logger)6 NoSuchFileException (java.nio.file.NoSuchFileException)5