Search in sources :

Example 26 with Tuple

use of org.elasticsearch.common.collect.Tuple in project crate by crate.

the class FileReadingIterator method initCollectorState.

private void initCollectorState() {
    lineContext = new LineContext();
    for (LineCollectorExpression<?> collectorExpression : collectorExpressions) {
        collectorExpression.startCollect(lineContext);
    }
    List<Tuple<FileInput, UriWithGlob>> fileInputs = new ArrayList<>(urisWithGlob.size());
    for (UriWithGlob fileUri : urisWithGlob) {
        try {
            FileInput fileInput = getFileInput(fileUri.uri);
            fileInputs.add(new Tuple<>(fileInput, fileUri));
        } catch (IOException e) {
            rethrowUnchecked(e);
        }
    }
    fileInputsIterator = fileInputs.iterator();
}
Also used : LineContext(io.crate.operation.reference.file.LineContext) IOException(java.io.IOException) Tuple(org.elasticsearch.common.collect.Tuple)

Example 27 with Tuple

use of org.elasticsearch.common.collect.Tuple in project elasticsearch by elastic.

the class InstallPluginCommand method checkMisspelledPlugin.

/** Returns all the official plugin names that look similar to pluginId. **/
private List<String> checkMisspelledPlugin(String pluginId) {
    LevensteinDistance ld = new LevensteinDistance();
    List<Tuple<Float, String>> scoredKeys = new ArrayList<>();
    for (String officialPlugin : OFFICIAL_PLUGINS) {
        float distance = ld.getDistance(pluginId, officialPlugin);
        if (distance > 0.7f) {
            scoredKeys.add(new Tuple<>(distance, officialPlugin));
        }
    }
    CollectionUtil.timSort(scoredKeys, (a, b) -> b.v1().compareTo(a.v1()));
    return scoredKeys.stream().map((a) -> a.v2()).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) URLDecoder(java.net.URLDecoder) URL(java.net.URL) VERBOSE(org.elasticsearch.cli.Terminal.Verbosity.VERBOSE) Environment(org.elasticsearch.env.Environment) DirectoryStream(java.nio.file.DirectoryStream) Locale(java.util.Locale) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) OptionSet(joptsimple.OptionSet) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) OptionSpec(joptsimple.OptionSpec) PosixFileAttributes(java.nio.file.attribute.PosixFileAttributes) PosixFilePermission(java.nio.file.attribute.PosixFilePermission) Set(java.util.Set) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) Version(org.elasticsearch.Version) JarHell(org.elasticsearch.bootstrap.JarHell) ZipInputStream(java.util.zip.ZipInputStream) PosixFileAttributeView(java.nio.file.attribute.PosixFileAttributeView) TreeSet(java.util.TreeSet) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) PosixFilePermissions(java.nio.file.attribute.PosixFilePermissions) URLConnection(java.net.URLConnection) LevensteinDistance(org.apache.lucene.search.spell.LevensteinDistance) OutputStream(java.io.OutputStream) FileSystemUtils(org.elasticsearch.common.io.FileSystemUtils) Files(java.nio.file.Files) IOUtils(org.apache.lucene.util.IOUtils) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) InputStreamReader(java.io.InputStreamReader) MessageDigests(org.elasticsearch.common.hash.MessageDigests) CollectionUtil(org.apache.lucene.util.CollectionUtil) SuppressForbidden(org.elasticsearch.common.SuppressForbidden) ExitCodes(org.elasticsearch.cli.ExitCodes) EnvironmentAwareCommand(org.elasticsearch.cli.EnvironmentAwareCommand) BufferedReader(java.io.BufferedReader) Tuple(org.elasticsearch.common.collect.Tuple) Collections(java.util.Collections) Terminal(org.elasticsearch.cli.Terminal) UserException(org.elasticsearch.cli.UserException) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) LevensteinDistance(org.apache.lucene.search.spell.LevensteinDistance) Tuple(org.elasticsearch.common.collect.Tuple)

Example 28 with Tuple

use of org.elasticsearch.common.collect.Tuple in project elasticsearch by elastic.

the class TasksIT method testSearchTaskDescriptions.

public void testSearchTaskDescriptions() {
    // main task
    registerTaskManageListeners(SearchAction.NAME);
    // shard task
    registerTaskManageListeners(SearchAction.NAME + "[*]");
    createIndex("test");
    // Make sure all shards are allocated to catch replication tasks
    ensureGreen("test");
    client().prepareIndex("test", "doc", "test_id").setSource("{\"foo\": \"bar\"}", XContentType.JSON).setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE).get();
    assertSearchResponse(client().prepareSearch("test").setTypes("doc").setQuery(QueryBuilders.matchAllQuery()).get());
    // the search operation should produce one main task
    List<TaskInfo> mainTask = findEvents(SearchAction.NAME, Tuple::v1);
    assertEquals(1, mainTask.size());
    assertThat(mainTask.get(0).getDescription(), startsWith("indices[test], types[doc], search_type["));
    assertThat(mainTask.get(0).getDescription(), containsString("\"query\":{\"match_all\""));
    // check that if we have any shard-level requests they all have non-zero length description
    List<TaskInfo> shardTasks = findEvents(SearchAction.NAME + "[*]", Tuple::v1);
    for (TaskInfo taskInfo : shardTasks) {
        assertThat(taskInfo.getParentTaskId(), notNullValue());
        assertEquals(mainTask.get(0).getTaskId(), taskInfo.getParentTaskId());
        switch(taskInfo.getAction()) {
            case SearchTransportService.QUERY_ACTION_NAME:
            case SearchTransportService.DFS_ACTION_NAME:
                assertTrue(taskInfo.getDescription(), Regex.simpleMatch("shardId[[test][*]]", taskInfo.getDescription()));
                break;
            case SearchTransportService.QUERY_ID_ACTION_NAME:
                assertTrue(taskInfo.getDescription(), Regex.simpleMatch("id[*], indices[test]", taskInfo.getDescription()));
                break;
            case SearchTransportService.FETCH_ID_ACTION_NAME:
                assertTrue(taskInfo.getDescription(), Regex.simpleMatch("id[*], size[1], lastEmittedDoc[null]", taskInfo.getDescription()));
                break;
            default:
                fail("Unexpected action [" + taskInfo.getAction() + "] with description [" + taskInfo.getDescription() + "]");
        }
        // assert that all task descriptions have non-zero length
        assertThat(taskInfo.getDescription().length(), greaterThan(0));
    }
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) Tuple(org.elasticsearch.common.collect.Tuple)

Example 29 with Tuple

use of org.elasticsearch.common.collect.Tuple in project elasticsearch by elastic.

the class TasksIT method testTaskStoringFailureResult.

public void testTaskStoringFailureResult() throws Exception {
    // we need this to get task id of the process
    registerTaskManageListeners(TestTaskPlugin.TestTaskAction.NAME);
    // Start non-blocking test task that should fail
    assertThrows(TestTaskPlugin.TestTaskAction.INSTANCE.newRequestBuilder(client()).setShouldFail(true).setShouldStoreResult(true).setShouldBlock(false), IllegalStateException.class);
    List<TaskInfo> events = findEvents(TestTaskPlugin.TestTaskAction.NAME, Tuple::v1);
    assertEquals(1, events.size());
    TaskInfo failedTaskInfo = events.get(0);
    TaskId failedTaskId = failedTaskInfo.getTaskId();
    GetResponse failedResultDoc = client().prepareGet(TaskResultsService.TASK_INDEX, TaskResultsService.TASK_TYPE, failedTaskId.toString()).get();
    assertTrue(failedResultDoc.isExists());
    Map<String, Object> source = failedResultDoc.getSource();
    @SuppressWarnings("unchecked") Map<String, Object> task = (Map<String, Object>) source.get("task");
    assertEquals(failedTaskInfo.getTaskId().getNodeId(), task.get("node"));
    assertEquals(failedTaskInfo.getAction(), task.get("action"));
    assertEquals(Long.toString(failedTaskInfo.getId()), task.get("id").toString());
    @SuppressWarnings("unchecked") Map<String, Object> error = (Map<String, Object>) source.get("error");
    assertEquals("Simulating operation failure", error.get("reason"));
    assertEquals("illegal_state_exception", error.get("type"));
    assertNull(source.get("result"));
    GetTaskResponse getResponse = expectFinishedTask(failedTaskId);
    assertNull(getResponse.getTask().getResponse());
    assertEquals(error, getResponse.getTask().getErrorAsMap());
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) TaskId(org.elasticsearch.tasks.TaskId) GetTaskResponse(org.elasticsearch.action.admin.cluster.node.tasks.get.GetTaskResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) GetResponse(org.elasticsearch.action.get.GetResponse) Map(java.util.Map) HashMap(java.util.HashMap) Tuple(org.elasticsearch.common.collect.Tuple)

Example 30 with Tuple

use of org.elasticsearch.common.collect.Tuple in project elasticsearch by elastic.

the class TasksIT method testTransportBulkTasks.

public void testTransportBulkTasks() {
    // main task
    registerTaskManageListeners(BulkAction.NAME);
    // shard task
    registerTaskManageListeners(BulkAction.NAME + "[s]");
    // shard task on primary
    registerTaskManageListeners(BulkAction.NAME + "[s][p]");
    // shard task on replica
    registerTaskManageListeners(BulkAction.NAME + "[s][r]");
    createIndex("test");
    // Make sure all shards are allocated to catch replication tasks
    ensureGreen("test");
    client().prepareBulk().add(client().prepareIndex("test", "doc", "test_id").setSource("{\"foo\": \"bar\"}", XContentType.JSON)).get();
    // the bulk operation should produce one main task
    List<TaskInfo> topTask = findEvents(BulkAction.NAME, Tuple::v1);
    assertEquals(1, topTask.size());
    assertEquals("requests[1], indices[test]", topTask.get(0).getDescription());
    // we should also get 1 or 2 [s] operation with main operation as a parent
    // in case the primary is located on the coordinating node we will have 1 operation, otherwise - 2
    List<TaskInfo> shardTasks = findEvents(BulkAction.NAME + "[s]", Tuple::v1);
    assertThat(shardTasks.size(), allOf(lessThanOrEqualTo(2), greaterThanOrEqualTo(1)));
    // Select the effective shard task
    TaskInfo shardTask;
    if (shardTasks.size() == 1) {
        // we have only one task - it's going to be the parent task for all [s][p] and [s][r] tasks
        shardTask = shardTasks.get(0);
        // and it should have the main task as a parent
        assertParentTask(shardTask, findEvents(BulkAction.NAME, Tuple::v1).get(0));
        assertEquals("requests[1], index[test]", shardTask.getDescription());
    } else {
        if (shardTasks.get(0).getParentTaskId().equals(shardTasks.get(1).getTaskId())) {
            // task 1 is the parent of task 0, that means that task 0 will control [s][p] and [s][r] tasks
            shardTask = shardTasks.get(0);
            // in turn the parent of the task 1 should be the main task
            assertParentTask(shardTasks.get(1), findEvents(BulkAction.NAME, Tuple::v1).get(0));
            assertEquals("requests[1], index[test]", shardTask.getDescription());
        } else {
            // otherwise task 1 will control [s][p] and [s][r] tasks
            shardTask = shardTasks.get(1);
            // in turn the parent of the task 0 should be the main task
            assertParentTask(shardTasks.get(0), findEvents(BulkAction.NAME, Tuple::v1).get(0));
            assertEquals("requests[1], index[test]", shardTask.getDescription());
        }
    }
    // we should also get one [s][p] operation with shard operation as a parent
    assertEquals(1, numberOfEvents(BulkAction.NAME + "[s][p]", Tuple::v1));
    assertParentTask(findEvents(BulkAction.NAME + "[s][p]", Tuple::v1), shardTask);
    // we should get as many [s][r] operations as we have replica shards
    // they all should have the same shard task as a parent
    assertEquals(getNumShards("test").numReplicas, numberOfEvents(BulkAction.NAME + "[s][r]", Tuple::v1));
    assertParentTask(findEvents(BulkAction.NAME + "[s][r]", Tuple::v1), shardTask);
}
Also used : TaskInfo(org.elasticsearch.tasks.TaskInfo) Tuple(org.elasticsearch.common.collect.Tuple)

Aggregations

Tuple (org.elasticsearch.common.collect.Tuple)50 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)17 HashMap (java.util.HashMap)12 List (java.util.List)12 Map (java.util.Map)12 Settings (org.elasticsearch.common.settings.Settings)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 HashSet (java.util.HashSet)6 ParameterizedMessage (org.apache.logging.log4j.message.ParameterizedMessage)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 Supplier (org.apache.logging.log4j.util.Supplier)5 TaskInfo (org.elasticsearch.tasks.TaskInfo)5 Set (java.util.Set)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Consumer (java.util.function.Consumer)4 ElasticsearchException (org.elasticsearch.ElasticsearchException)4 Version (org.elasticsearch.Version)4 DiscoveryNode (org.elasticsearch.cluster.node.DiscoveryNode)4