Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feature/finish wfspec migration #897

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import io.littlehorse.common.model.getable.core.wfrun.haltreason.PendingFailureHandlerHaltReasonModel;
import io.littlehorse.common.model.getable.core.wfrun.haltreason.PendingInterruptHaltReasonModel;
import io.littlehorse.common.model.getable.global.taskdef.TaskDefModel;
import io.littlehorse.common.model.getable.global.wfspec.NodeMigrationModel;
import io.littlehorse.common.model.getable.global.wfspec.ThreadSpecMigrationModel;
import io.littlehorse.common.model.getable.global.wfspec.node.EdgeModel;
import io.littlehorse.common.model.getable.global.wfspec.node.FailureHandlerDefModel;
import io.littlehorse.common.model.getable.global.wfspec.node.NodeModel;
import io.littlehorse.common.model.getable.global.wfspec.node.subnode.TaskNodeModel;
Expand All @@ -44,6 +47,7 @@
import io.littlehorse.sdk.common.proto.ThreadRun;
import io.littlehorse.sdk.common.proto.ThreadType;
import io.littlehorse.sdk.common.proto.VariableType;
import io.littlehorse.server.streams.storeinternals.MetadataManager;
import io.littlehorse.sdk.common.proto.WfRunVariableAccessLevel;
import io.littlehorse.server.streams.topology.core.ExecutionContext;
import io.littlehorse.server.streams.topology.core.ProcessorExecutionContext;
Expand All @@ -53,6 +57,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.AccessLevel;
import java.util.Optional;
import lombok.Getter;
import lombok.Setter;
Expand Down Expand Up @@ -85,14 +91,15 @@ public class ThreadRunModel extends LHSerializable<ThreadRun> {

public ThreadType type;

private ExecutionContext executionContext;
private ExecutionContext ctx;
// Only contains value in Processor execution context.
private ProcessorExecutionContext processorContext;
private ThreadSpecMigrationModel migration;

public ThreadRunModel() {}

public ThreadRunModel(ProcessorExecutionContext processorContext) {
this.executionContext = processorContext;
this.ctx = processorContext;
this.processorContext = processorContext;
}

Expand All @@ -104,7 +111,7 @@ public void initFrom(Message p, ExecutionContext context) {
threadSpecName = proto.getThreadSpecName();
currentNodePosition = proto.getCurrentNodePosition();
startTime = LHUtil.fromProtoTs(proto.getStartTime());
wfSpecId = LHSerializable.fromProto(proto.getWfSpecId(), WfSpecIdModel.class, executionContext);
wfSpecId = LHSerializable.fromProto(proto.getWfSpecId(), WfSpecIdModel.class, ctx);
if (proto.hasEndTime()) {
endTime = LHUtil.fromProtoTs(proto.getEndTime());
}
Expand Down Expand Up @@ -134,7 +141,7 @@ public void initFrom(Message p, ExecutionContext context) {
for (int handledFailedChildId : proto.getHandledFailedChildrenList()) {
handledFailedChildren.add(handledFailedChildId);
}
executionContext = context;
ctx = context;
processorContext = context.castOnSupport(ProcessorExecutionContext.class);
type = proto.getType();
}
Expand Down Expand Up @@ -191,19 +198,19 @@ public Class<ThreadRun> getProtoBaseClass() {

public WfRunModel wfRun;

private ThreadSpecModel threadSpecModel;
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
private ThreadSpecModel threadSpecModelDoNotUseMe;

public ThreadSpecModel getThreadSpec() {
if (threadSpecModel == null) {
threadSpecModel = wfRun.getWfSpec().threadSpecs.get(threadSpecName);
if (threadSpecModelDoNotUseMe == null) {
threadSpecModelDoNotUseMe = ctx.metadataManager().get(wfSpecId).threadSpecs.get(threadSpecName);
}
return threadSpecModel;
return threadSpecModelDoNotUseMe;
}

public NodeModel getCurrentNode() {
NodeRunModel currRun = getCurrentNodeRun();

// TODO (#465): Determine which version of WfSpec we should get the ThreadSpec from.
ThreadSpecModel threadSpec = getThreadSpec();
if (currRun == null) {
return threadSpec.nodes.get(threadSpec.getEntrypointNodeName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.tuple.Pair;

Expand Down Expand Up @@ -652,4 +653,9 @@ public void handleThreadStatus(int threadRunNumber, Date time, LHStatus newStatu
// want to wake up. Ding Ding Ding! Get out of bed.
advance(time);
}

private void startMigration() {
// TODO: For each ThreadRun, we should add the ThreadMigrationModel if there is one.
throw new NotImplementedException();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package io.littlehorse.common.model.getable.global.wfspec;

import org.apache.commons.lang3.NotImplementedException;

import com.google.protobuf.Message;
import io.littlehorse.common.LHSerializable;
import io.littlehorse.common.model.getable.core.noderun.NodeRunModel;
import io.littlehorse.common.model.getable.core.wfrun.ThreadRunModel;
import io.littlehorse.sdk.common.proto.NodeMigration;
import io.littlehorse.server.streams.topology.core.ExecutionContext;
import lombok.Getter;
Expand Down Expand Up @@ -31,4 +35,10 @@ public void initFrom(Message proto, ExecutionContext executionContext) {
newNodeName = p.getNewNodeName();
this.context = executionContext;
}

public void execute(ThreadRunModel thread) {
NodeRunModel currentNode = thread.getCurrentNodeRun();

throw new NotImplementedException();
}
}
Loading