Search in sources :

Example 6 with State

use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.

the class VMUtils method getCombinedLocals.

/**
 * @see #getCombinedLocals(State, ThreadId)
 */
public static Map<String, Object> getCombinedLocals(Context ctx) {
    ThreadId threadId = ctx.execution().currentThreadId();
    State state = ctx.execution().state();
    return getCombinedLocals(state, threadId);
}
Also used : ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State)

Example 7 with State

use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.

the class VMUtilsTest method testLocals.

@Test
public void testLocals() {
    Frame rootFrame = Frame.builder().root().locals(Collections.singletonMap("x", 123)).build();
    State state = new InMemoryState(rootFrame);
    ThreadId threadId = state.getRootThreadId();
    Frame levelOneFrame = Frame.builder().nonRoot().locals(Collections.singletonMap("y", 234)).build();
    state.pushFrame(threadId, levelOneFrame);
    Frame levelTwoFrame = Frame.builder().nonRoot().locals(Collections.singletonMap("x", 345)).build();
    state.pushFrame(threadId, levelTwoFrame);
    Map<String, Object> locals = VMUtils.getCombinedLocals(state, threadId);
    assertEquals(2, locals.size());
    assertEquals(345, locals.get("x"));
    assertEquals(234, locals.get("y"));
}
Also used : Frame(com.walmartlabs.concord.svm.Frame) ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State) InMemoryState(com.walmartlabs.concord.svm.InMemoryState) InMemoryState(com.walmartlabs.concord.svm.InMemoryState) Test(org.junit.jupiter.api.Test)

Example 8 with State

use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.

the class ContextUtils method getCurrentRetryAttemptNumber.

/**
 * Returns the current "retry" attempt number (if applicable).
 *
 * @param ctx current {@link Context}
 * @return the current attemp number of {@code null} if the current call is a retry.
 * @see Constants.Runtime#RETRY_ATTEMPT_NUMBER
 */
public static Integer getCurrentRetryAttemptNumber(Context ctx) {
    Execution execution = ctx.execution();
    State state = execution.state();
    ThreadId threadId = execution.currentThreadId();
    Frame frame = state.peekFrame(threadId);
    Serializable value = frame.getLocal(Constants.Runtime.RETRY_ATTEMPT_NUMBER);
    if (value == null) {
        return null;
    }
    if (!(value instanceof Integer)) {
        throw new IllegalStateException(String.format("%s is expected to be a number, got: %s. This is most likely a bug", Constants.Runtime.RETRY_ATTEMPT_NUMBER, value.getClass()));
    }
    return (Integer) value;
}
Also used : Frame(com.walmartlabs.concord.svm.Frame) Serializable(java.io.Serializable) ThreadId(com.walmartlabs.concord.svm.ThreadId) State(com.walmartlabs.concord.svm.State)

Example 9 with State

use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.

the class ContextVariables method set.

@Override
public void set(String key, Object value) {
    TaskProviders providers = ctx.execution().runtime().getService(TaskProviders.class);
    if (providers.hasTask(key)) {
        log.warn("Local variable '{}' shadows a task. This may cause issues calling '{}' task in expressions. " + "Avoid using same names for tasks and variables.", key, key);
    }
    ThreadId threadId = ctx.execution().currentThreadId();
    State state = ctx.execution().state();
    VMUtils.putLocal(state, threadId, key, value);
}
Also used : ThreadId(com.walmartlabs.concord.svm.ThreadId) TaskProviders(com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders) State(com.walmartlabs.concord.svm.State)

Example 10 with State

use of com.walmartlabs.concord.svm.State in project concord by walmartlabs.

the class DefaultCheckpointService method create.

@Override
public void create(ThreadId threadId, String name, Runtime runtime, ProcessSnapshot snapshot) {
    validate(threadId, snapshot);
    UUID checkpointId = UUID.randomUUID();
    try (StateArchive archive = new StateArchive()) {
        // the goal here is to create a process state snapshot with
        // a "synthetic" event that can be used to continue the process
        // after the checkpoint step
        String resumeEventRef = checkpointId.toString();
        State state = clone(snapshot.vmState(), classLoader);
        state.setEventRef(threadId, resumeEventRef);
        state.setStatus(threadId, ThreadStatus.SUSPENDED);
        archive.withResumeEvent(resumeEventRef).withProcessState(ProcessSnapshot.builder().from(snapshot).vmState(state).build()).withSystemDirectory(workingDirectory.getValue());
        try (TemporaryPath zip = archive.zip()) {
            checkpointUploader.upload(checkpointId, name, zip.path());
        }
    } catch (Exception e) {
        throw new RuntimeException("Checkpoint upload error", e);
    }
    log.info("Checkpoint '{}' created", name);
}
Also used : State(com.walmartlabs.concord.svm.State) UUID(java.util.UUID) TemporaryPath(com.walmartlabs.concord.common.TemporaryPath)

Aggregations

State (com.walmartlabs.concord.svm.State)10 ThreadId (com.walmartlabs.concord.svm.ThreadId)6 Frame (com.walmartlabs.concord.svm.Frame)3 TemporaryPath (com.walmartlabs.concord.common.TemporaryPath)2 UUID (java.util.UUID)2 TaskProviders (com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders)1 InMemoryState (com.walmartlabs.concord.svm.InMemoryState)1 Serializable (java.io.Serializable)1 Test (org.junit.jupiter.api.Test)1