Search in sources :

Example 81 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project scheduling by ow2-proactive.

the class RestSmartProxyTest method testInErrorEventsReception.

@Test(timeout = TEN_MINUTES)
public void testInErrorEventsReception() throws Exception {
    System.out.println("Begin testInErrorEventsReception ");
    TaskFlowJob job = createInErrorJob();
    final Semaphore semaphore = new Semaphore(0);
    printJobXmlRepresentation(job);
    final MutableBoolean taskHasBeenInError = new MutableBoolean(false);
    final MutableBoolean taskMarkedAsFinished = new MutableBoolean(false);
    SchedulerEventListenerExtended listener = new SchedulerEventListenerExtended() {

        @Override
        public void schedulerStateUpdatedEvent(SchedulerEvent eventType) {
            System.out.println("RestSmartProxyTest.schedulerStateUpdatedEvent " + eventType);
        }

        @Override
        public void jobSubmittedEvent(JobState job) {
            System.out.println("RestSmartProxyTest.jobSubmittedEvent");
        }

        @Override
        public void jobStateUpdatedEvent(NotificationData<JobInfo> notification) {
            JobStatus status = notification.getData().getStatus();
            System.out.println("RestSmartProxyTest.jobStateUpdatedEvent, eventType=" + notification.getEventType() + ", jobStatus=" + status);
            if (status == JobStatus.IN_ERROR) {
                semaphore.release();
            }
        }

        @Override
        public void taskStateUpdatedEvent(NotificationData<TaskInfo> notification) {
            TaskStatus status = notification.getData().getStatus();
            System.out.println("RestSmartProxyTest.taskStateUpdatedEvent, taskStatus=" + status);
            if (status == TaskStatus.WAITING_ON_ERROR || status == TaskStatus.IN_ERROR) {
                // IN_ERROR previously
                taskHasBeenInError.setTrue();
            }
            if (status == TaskStatus.FINISHED && taskHasBeenInError.isTrue()) {
                taskMarkedAsFinished.setTrue();
            }
        }

        @Override
        public void usersUpdatedEvent(NotificationData<UserIdentification> notification) {
            System.out.println("RestSmartProxyTest.usersUpdatedEvent " + notification.getData());
        }

        @Override
        public void pullDataFinished(String jobId, String taskName, String localFolderPath) {
            System.out.println("RestSmartProxyTest.pullDataFinished");
        }

        @Override
        public void pullDataFailed(String jobId, String taskName, String remoteFolder_URL, Throwable t) {
            System.out.println("RestSmartProxyTest.pullDataFailed");
        }

        @Override
        public void jobUpdatedFullDataEvent(JobState job) {
            System.out.println("RestSmartProxyTest.jobUpdatedFullDataEvent");
        }
    };
    restSmartProxy.addEventListener(listener);
    JobId jobId = restSmartProxy.submit(job, inputLocalFolder.getAbsolutePath(), outputLocalFolder.getAbsolutePath(), false, false);
    // the next line blocks until jobStateUpdatedEvent is called on the
    // listener
    // with job status set to IN_ERROR
    semaphore.acquire();
    String jobIdAsString = jobId.value();
    System.out.println("Finish in-error task");
    restSmartProxy.finishInErrorTask(jobIdAsString, inerrorTaskName);
    waitForJobFinishState(jobIdAsString);
    assertThat(taskHasBeenInError.booleanValue()).isTrue();
    assertThat(taskMarkedAsFinished.booleanValue()).isTrue();
    System.out.println("End testInErrorEventsReception");
}
Also used : JobStatus(org.ow2.proactive.scheduler.common.job.JobStatus) TaskFlowJob(org.ow2.proactive.scheduler.common.job.TaskFlowJob) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) JobState(org.ow2.proactive.scheduler.common.job.JobState) SchedulerEventListenerExtended(org.ow2.proactive.scheduler.smartproxy.common.SchedulerEventListenerExtended) Semaphore(java.util.concurrent.Semaphore) TaskStatus(org.ow2.proactive.scheduler.common.task.TaskStatus) JobId(org.ow2.proactive.scheduler.common.job.JobId) SchedulerEvent(org.ow2.proactive.scheduler.common.SchedulerEvent) NotificationData(org.ow2.proactive.scheduler.common.NotificationData) Test(org.junit.Test)

Example 82 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project janusgraph by JanusGraph.

the class IndexSelectionUtil method existsMatchingIndex.

public static boolean existsMatchingIndex(MultiCondition<JanusGraphElement> conditions, Predicate<IndexType> filter) {
    if (conditions == null || filter == null) {
        return false;
    }
    MutableBoolean exists = new MutableBoolean();
    ConditionUtil.traversal(conditions, condition -> {
        if (exists.isFalse()) {
            for (IndexType indexCandidate : getKeyIndexesForCondition(condition)) {
                if (filter.test(indexCandidate)) {
                    exists.setTrue();
                    return true;
                }
            }
        }
        return true;
    });
    return exists.booleanValue();
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) MixedIndexType(org.janusgraph.graphdb.types.MixedIndexType) IndexType(org.janusgraph.graphdb.types.IndexType)

Example 83 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project sqlg by pietermartin.

the class SchemaTableTree method constructOuterOrderByClause.

private static String constructOuterOrderByClause(SqlgGraph sqlgGraph, List<LinkedList<SchemaTableTree>> subQueryLinkedLists) {
    String result = "";
    int countOuter = 1;
    // last table list with order as last step wins
    int winningOrder = 0;
    for (LinkedList<SchemaTableTree> subQueryLinkedList : subQueryLinkedLists) {
        if (!subQueryLinkedList.isEmpty()) {
            SchemaTableTree schemaTableTree = subQueryLinkedList.peekLast();
            if (!schemaTableTree.getDbComparators().isEmpty()) {
                winningOrder = countOuter;
            }
        }
        countOuter++;
    }
    countOuter = 1;
    // construct the order by clause for the comparators
    MutableBoolean mutableOrderBy = new MutableBoolean(false);
    for (LinkedList<SchemaTableTree> subQueryLinkedList : subQueryLinkedLists) {
        if (!subQueryLinkedList.isEmpty()) {
            SchemaTableTree schemaTableTree = subQueryLinkedList.peekLast();
            if (countOuter == winningOrder) {
                result += schemaTableTree.toOrderByClause(sqlgGraph, mutableOrderBy, countOuter);
            }
            // support range without order
            result += schemaTableTree.toRangeClause(sqlgGraph, mutableOrderBy);
        }
        countOuter++;
    }
    return result;
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean)

Example 84 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project sqlg by pietermartin.

the class SchemaTableTree method constructSelectSinglePathSql.

private String constructSelectSinglePathSql(SqlgGraph sqlgGraph, boolean partOfDuplicateQuery, LinkedList<SchemaTableTree> distinctQueryStack, SchemaTableTree lastOfPrevious, SchemaTableTree firstOfNextStack, Set<SchemaTableTree> leftJoinOn, boolean dropStep) {
    StringBuilder singlePathSql = new StringBuilder("\nSELECT\n\t");
    SchemaTableTree firstSchemaTableTree = distinctQueryStack.getFirst();
    SchemaTable firstSchemaTable = firstSchemaTableTree.getSchemaTable();
    // As its a DELETE there is no need for the 'index' to order on.
    if (!dropStep && lastOfPrevious == null && distinctQueryStack.getFirst().stepType != STEP_TYPE.GRAPH_STEP) {
        // if there is only 1 incoming start/traverser we use a where clause as its faster.
        if (this.parentIdsAndIndexes.size() == 1) {
            singlePathSql.append(this.parentIdsAndIndexes.get(0).getRight());
            singlePathSql.append(" as ");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("index"));
        } else if (sqlgGraph.getSqlDialect().supportsValuesExpression()) {
            // Hardcoding here for H2
            if (sqlgGraph.getSqlDialect().supportsFullValueExpression()) {
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("index"));
            } else {
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("C2"));
            }
            singlePathSql.append(" as ");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("index"));
        } else {
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("index"));
            singlePathSql.append(" as ");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("index"));
        }
        singlePathSql.append(",\n\t");
    }
    singlePathSql.append(constructFromClause(sqlgGraph, distinctQueryStack, lastOfPrevious, firstOfNextStack, dropStep));
    singlePathSql.append("\nFROM\n\t");
    singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTableTree.getSchemaTable().getSchema()));
    singlePathSql.append(".");
    singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTableTree.getSchemaTable().getTable()));
    SchemaTableTree previous = firstSchemaTableTree;
    boolean skipFirst = true;
    for (SchemaTableTree schemaTableTree : distinctQueryStack) {
        if (skipFirst) {
            skipFirst = false;
            continue;
        }
        singlePathSql.append(constructJoinBetweenSchemaTables(sqlgGraph, previous, schemaTableTree));
        previous = schemaTableTree;
    }
    SchemaTableTree previousLeftJoinSchemaTableTree = null;
    for (SchemaTableTree schemaTableTree : leftJoinOn) {
        if (previousLeftJoinSchemaTableTree == null || !previousLeftJoinSchemaTableTree.getSchemaTable().equals(schemaTableTree.getSchemaTable())) {
            singlePathSql.append(constructJoinBetweenSchemaTables(sqlgGraph, previous, schemaTableTree, true));
        } else {
            singlePathSql.append(appendToJoinBetweenSchemaTables(sqlgGraph, previous, schemaTableTree, true));
        }
        previousLeftJoinSchemaTableTree = schemaTableTree;
    }
    // These values are inserted/copy command into a temporary table before joining.
    for (SchemaTableTree schemaTableTree : distinctQueryStack) {
        if (sqlgGraph.getSqlDialect().supportsBulkWithinOut() && schemaTableTree.hasBulkWithinOrOut(sqlgGraph)) {
            singlePathSql.append(schemaTableTree.bulkWithJoin(sqlgGraph));
        }
    }
    MutableBoolean mutableWhere = new MutableBoolean(false);
    MutableBoolean mutableOrderBy = new MutableBoolean(false);
    // lastOfPrevious is null for the first call in the call stack it needs the id parameter in the where clause.
    if (lastOfPrevious == null && distinctQueryStack.getFirst().stepType != STEP_TYPE.GRAPH_STEP) {
        if (this.parentIdsAndIndexes.size() != 1 && sqlgGraph.getSqlDialect().supportsValuesExpression()) {
            singlePathSql.append(" INNER JOIN\n\t(VALUES");
            int count = 1;
            for (Pair<Long, Long> parentIdAndIndex : this.parentIdsAndIndexes) {
                singlePathSql.append("(");
                singlePathSql.append(parentIdAndIndex.getLeft());
                singlePathSql.append(", ");
                singlePathSql.append(parentIdAndIndex.getRight());
                singlePathSql.append(")");
                if (count++ < this.parentIdsAndIndexes.size()) {
                    singlePathSql.append(",");
                }
            }
            if (sqlgGraph.getSqlDialect().supportsFullValueExpression()) {
                singlePathSql.append(") AS tmp (");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("tmpId"));
                singlePathSql.append(", ");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("index"));
                singlePathSql.append(") ON ");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getSchema()));
                singlePathSql.append(".");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getTable()));
                singlePathSql.append(".");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(Topology.ID));
                singlePathSql.append(" = tmp.");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("tmpId"));
            } else {
                // This really is only for H2
                singlePathSql.append(") ON ");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getSchema()));
                singlePathSql.append(".");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getTable()));
                singlePathSql.append(".");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(Topology.ID));
                singlePathSql.append(" = ");
                singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("C1"));
            }
        } else if (this.parentIdsAndIndexes.size() != 1 && !sqlgGraph.getSqlDialect().supportsValuesExpression()) {
            // Mariadb lo and behold does not support VALUES
            // Need to use a randomized name here else the temp table gets reused within the same transaction.
            SecureRandom random = new SecureRandom();
            byte[] bytes = new byte[6];
            random.nextBytes(bytes);
            String tmpTableIdentified = Base64.getEncoder().encodeToString(bytes);
            sqlgGraph.tx().normalBatchModeOn();
            for (Pair<Long, Long> parentIdsAndIndex : this.parentIdsAndIndexes) {
                sqlgGraph.addTemporaryVertex(T.label, tmpTableIdentified, "tmpId", parentIdsAndIndex.getLeft(), "index", parentIdsAndIndex.getRight());
            }
            sqlgGraph.tx().flush();
            singlePathSql.append(" INNER JOIN\n\t");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(sqlgGraph.getSqlDialect().getPublicSchema()));
            singlePathSql.append(".");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(VERTEX_PREFIX + tmpTableIdentified));
            singlePathSql.append(" as tmp");
            singlePathSql.append(" ON ");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getSchema()));
            singlePathSql.append(".");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getTable()));
            singlePathSql.append(".");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(Topology.ID));
            singlePathSql.append(" = tmp.");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("tmpId"));
        } else {
            singlePathSql.append("\nWHERE\n\t");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getSchema()));
            singlePathSql.append(".");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(firstSchemaTable.getTable()));
            singlePathSql.append(".");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes(Topology.ID));
            singlePathSql.append(" = ");
            singlePathSql.append(this.parentIdsAndIndexes.get(0).getLeft());
            mutableWhere.setTrue();
        }
    }
    // construct the where clause for the hasContainers
    for (SchemaTableTree schemaTableTree : distinctQueryStack) {
        singlePathSql.append(schemaTableTree.toWhereClause(sqlgGraph, mutableWhere));
    }
    // add in the is null where clause for the optional left joins
    for (SchemaTableTree schemaTableTree : leftJoinOn) {
        singlePathSql.append(schemaTableTree.toOptionalLeftJoinWhereClause(sqlgGraph, mutableWhere));
    }
    // if partOfDuplicateQuery then the order by clause is on the outer select
    if (!partOfDuplicateQuery) {
        if (!dropStep && lastOfPrevious == null && distinctQueryStack.getFirst().stepType != STEP_TYPE.GRAPH_STEP) {
            singlePathSql.append("\nORDER BY\n\t");
            singlePathSql.append(sqlgGraph.getSqlDialect().maybeWrapInQoutes("index"));
            mutableOrderBy.setTrue();
        }
        // construct the order by clause for the comparators
        for (SchemaTableTree schemaTableTree : distinctQueryStack) {
            singlePathSql.append(schemaTableTree.toOrderByClause(sqlgGraph, mutableOrderBy, -1));
            singlePathSql.append(schemaTableTree.toRangeClause(sqlgGraph, mutableOrderBy));
        }
    }
    return singlePathSql.toString();
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) SecureRandom(java.security.SecureRandom) Pair(org.apache.commons.lang3.tuple.Pair)

Example 85 with MutableBoolean

use of org.apache.commons.lang3.mutable.MutableBoolean in project codeforces-commons by Codeforces.

the class StringUtil method fieldToString.

@Nullable
private static String fieldToString(@Nonnull Object value, @Nonnull String fieldName, ToStringOptions options) {
    if (value.getClass() == Boolean.class || value.getClass() == boolean.class) {
        return (boolean) value ? fieldName : '!' + fieldName;
    }
    MutableBoolean quoted = new MutableBoolean();
    String stringValue = valueToString(value, quoted);
    if (shouldSkipField(stringValue, options, quoted)) {
        return null;
    }
    return fieldName + '=' + stringValue;
}
Also used : MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) MutableBoolean(org.apache.commons.lang3.mutable.MutableBoolean) Nullable(javax.annotation.Nullable)

Aggregations

MutableBoolean (org.apache.commons.lang3.mutable.MutableBoolean)107 Test (org.junit.Test)28 Path (java.nio.file.Path)26 Test (org.junit.jupiter.api.Test)17 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)12 Query (org.apache.apex.malhar.lib.appdata.schemas.Query)11 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)11 List (java.util.List)9 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)8 MutableInt (org.apache.commons.lang3.mutable.MutableInt)7 MutableLong (org.apache.commons.lang3.mutable.MutableLong)7 Collections (java.util.Collections)6 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)6 Set (java.util.Set)5 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 PageCache (org.neo4j.io.pagecache.PageCache)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ClassAd (org.apache.asterix.external.classad.ClassAd)4