Skip to content

Commit

Permalink
Remove unused code from cadence.internal package
Browse files Browse the repository at this point in the history
  • Loading branch information
natemort committed Oct 17, 2024
1 parent c6891e2 commit 13d4daf
Show file tree
Hide file tree
Showing 10 changed files with 0 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -389,42 +389,6 @@ public static boolean isWorkflowExecutionCompleteDecision(Decision decision) {
|| decision.getDecisionType() == DecisionType.ContinueAsNewWorkflowExecution));
}

public static boolean isActivityTaskClosedEvent(HistoryEvent event) {
return ((event != null)
&& (event.getEventType() == EventType.ActivityTaskCompleted
|| event.getEventType() == EventType.ActivityTaskCanceled
|| event.getEventType() == EventType.ActivityTaskFailed
|| event.getEventType() == EventType.ActivityTaskTimedOut));
}

public static boolean isExternalWorkflowClosedEvent(HistoryEvent event) {
return ((event != null)
&& (event.getEventType() == EventType.ChildWorkflowExecutionCompleted
|| event.getEventType() == EventType.ChildWorkflowExecutionCanceled
|| event.getEventType() == EventType.ChildWorkflowExecutionFailed
|| event.getEventType() == EventType.ChildWorkflowExecutionTerminated
|| event.getEventType() == EventType.ChildWorkflowExecutionTimedOut));
}

public static WorkflowExecution getWorkflowIdFromExternalWorkflowCompletedEvent(
HistoryEvent event) {
if (event != null) {
if (event.getEventType() == EventType.ChildWorkflowExecutionCompleted) {
return event.getChildWorkflowExecutionCompletedEventAttributes().getWorkflowExecution();
} else if (event.getEventType() == EventType.ChildWorkflowExecutionCanceled) {
return event.getChildWorkflowExecutionCanceledEventAttributes().getWorkflowExecution();
} else if (event.getEventType() == EventType.ChildWorkflowExecutionFailed) {
return event.getChildWorkflowExecutionFailedEventAttributes().getWorkflowExecution();
} else if (event.getEventType() == EventType.ChildWorkflowExecutionTerminated) {
return event.getChildWorkflowExecutionTerminatedEventAttributes().getWorkflowExecution();
} else if (event.getEventType() == EventType.ChildWorkflowExecutionTimedOut) {
return event.getChildWorkflowExecutionTimedOutEventAttributes().getWorkflowExecution();
}
}

return null;
}

public static String getId(HistoryEvent historyEvent) {
String id = null;
if (historyEvent != null) {
Expand All @@ -436,67 +400,6 @@ public static String getId(HistoryEvent historyEvent) {
return id;
}

public static String getFailureCause(HistoryEvent historyEvent) {
String failureCause = null;
if (historyEvent != null) {
if (historyEvent.getEventType() == EventType.StartChildWorkflowExecutionFailed) {
failureCause =
historyEvent
.getStartChildWorkflowExecutionFailedEventAttributes()
.getCause()
.toString();
// } else if (historyEvent.getEventType() ==
// EventType.SignalExternalWorkflowExecutionFailed) {
// failureCause =
// historyEvent.getSignalExternalWorkflowExecutionFailedEventAttributes().getCause();
} else {
failureCause = "Cannot extract failure cause from " + historyEvent.getEventType();
}
}

return failureCause;
}

/**
* Blocks until workflow instance completes. <strong>Never</strong> use in production setting as
* polling for worklow instance status is an expensive operation.
*
* @param workflowExecution result of {@link
* IWorkflowService#StartWorkflowExecution(StartWorkflowExecutionRequest)}
* @return instance close status
*/
public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletion(
IWorkflowService service, String domain, WorkflowExecution workflowExecution)
throws EntityNotExistsError {
try {
return waitForWorkflowInstanceCompletion(
service, domain, workflowExecution, 0, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
throw new Error("should never happen", e);
}
}

/**
* Waits up to specified timeout for workflow instance completion. <strong>Never</strong> use in
* production setting as polling for worklow instance status is an expensive operation.
*
* @param workflowExecution result of {@link
* IWorkflowService#StartWorkflowExecution(StartWorkflowExecutionRequest)}
* @param timeout maximum time to wait for completion. 0 means wait forever.
* @return instance close status
*/
public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletion(
IWorkflowService service,
String domain,
WorkflowExecution workflowExecution,
long timeout,
TimeUnit unit)
throws TimeoutException, EntityNotExistsError {
HistoryEvent closeEvent =
getInstanceCloseEvent(service, domain, workflowExecution, timeout, unit);
return getCloseStatus(closeEvent);
}

public static WorkflowExecutionCloseStatus getCloseStatus(HistoryEvent event) {
switch (event.getEventType()) {
case WorkflowExecutionCanceled:
Expand All @@ -516,88 +419,6 @@ public static WorkflowExecutionCloseStatus getCloseStatus(HistoryEvent event) {
}
}

/**
* Like {@link #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution,
* long, TimeUnit)} , except will wait for continued generations of the original workflow
* execution too.
*
* @see #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution, long,
* TimeUnit)
*/
public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletionAcrossGenerations(
IWorkflowService service,
String domain,
WorkflowExecution workflowExecution,
long timeout,
TimeUnit unit)
throws TimeoutException, EntityNotExistsError {

WorkflowExecution lastExecutionToRun = workflowExecution;
long millisecondsAtFirstWait = System.currentTimeMillis();
WorkflowExecutionCloseStatus lastExecutionToRunCloseStatus =
waitForWorkflowInstanceCompletion(service, domain, lastExecutionToRun, timeout, unit);

// keep waiting if the instance continued as new
while (lastExecutionToRunCloseStatus == WorkflowExecutionCloseStatus.CONTINUED_AS_NEW) {
// get the new execution's information
HistoryEvent closeEvent =
getInstanceCloseEvent(service, domain, lastExecutionToRun, timeout, unit);
WorkflowExecutionContinuedAsNewEventAttributes continuedAsNewAttributes =
closeEvent.getWorkflowExecutionContinuedAsNewEventAttributes();

WorkflowExecution newGenerationExecution = new WorkflowExecution();
newGenerationExecution.setRunId(continuedAsNewAttributes.getNewExecutionRunId());
newGenerationExecution.setWorkflowId(lastExecutionToRun.getWorkflowId());

// and wait for it
long currentTime = System.currentTimeMillis();
long millisecondsSinceFirstWait = currentTime - millisecondsAtFirstWait;
long timeoutInSecondsForNextWait =
unit.toMillis(timeout) - (millisecondsSinceFirstWait / 1000L);

lastExecutionToRunCloseStatus =
waitForWorkflowInstanceCompletion(
service,
domain,
newGenerationExecution,
timeoutInSecondsForNextWait,
TimeUnit.MILLISECONDS);
lastExecutionToRun = newGenerationExecution;
}

return lastExecutionToRunCloseStatus;
}

/**
* Like {@link #waitForWorkflowInstanceCompletion(IWorkflowService, String, WorkflowExecution,
* long, TimeUnit)} , but with no timeout.*
*/
public static WorkflowExecutionCloseStatus waitForWorkflowInstanceCompletionAcrossGenerations(
IWorkflowService service, String domain, WorkflowExecution workflowExecution)
throws InterruptedException, EntityNotExistsError {
try {
return waitForWorkflowInstanceCompletionAcrossGenerations(
service, domain, workflowExecution, 0L, TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
throw new Error("should never happen", e);
}
}

public static WorkflowExecutionInfo describeWorkflowInstance(
IWorkflowService service, String domain, WorkflowExecution workflowExecution) {
DescribeWorkflowExecutionRequest describeRequest = new DescribeWorkflowExecutionRequest();
describeRequest.setDomain(domain);
describeRequest.setExecution(workflowExecution);
DescribeWorkflowExecutionResponse executionDetail = null;
try {
executionDetail = service.DescribeWorkflowExecution(describeRequest);
} catch (TException e) {
throw new RuntimeException(e);
}
WorkflowExecutionInfo instanceMetadata = executionDetail.getWorkflowExecutionInfo();
return instanceMetadata;
}

public static GetWorkflowExecutionHistoryResponse getHistoryPage(
byte[] nextPageToken,
IWorkflowService service,
Expand All @@ -621,26 +442,6 @@ public static GetWorkflowExecutionHistoryResponse getHistoryPage(
return history;
}

/** Returns workflow instance history in a human readable format. */
public static String prettyPrintHistory(
IWorkflowService service, String domain, WorkflowExecution workflowExecution) {
return prettyPrintHistory(service, domain, workflowExecution, true);
}
/**
* Returns workflow instance history in a human readable format.
*
* @param showWorkflowTasks when set to false workflow task events (decider events) are not
* included
*/
public static String prettyPrintHistory(
IWorkflowService service,
String domain,
WorkflowExecution workflowExecution,
boolean showWorkflowTasks) {
Iterator<HistoryEvent> events = getHistory(service, domain, workflowExecution);
return prettyPrintHistory(events, showWorkflowTasks);
}

public static Iterator<HistoryEvent> getHistory(
IWorkflowService service, String domain, WorkflowExecution workflowExecution) {
return new Iterator<HistoryEvent>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ public ActivityDecisionStateMachine(
this.scheduleAttributes = scheduleAttributes;
}

/** Used for unit testing */
ActivityDecisionStateMachine(
DecisionId id,
ScheduleActivityTaskDecisionAttributes scheduleAttributes,
DecisionState state) {
super(id, state);
this.scheduleAttributes = scheduleAttributes;
}

@Override
public Decision getDecision() {
switch (state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ public ChildWorkflowDecisionStateMachine(
this.startAttributes = startAttributes;
}

/** Used for unit testing */
ChildWorkflowDecisionStateMachine(
DecisionId id,
StartChildWorkflowExecutionDecisionAttributes startAttributes,
DecisionState state) {
super(id, state);
this.startAttributes = startAttributes;
}

@Override
public Decision getDecision() {
switch (state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,6 @@ public SignalDecisionStateMachine(
this.attributes = attributes;
}

/** Used for unit testing */
SignalDecisionStateMachine(
DecisionId id,
SignalExternalWorkflowExecutionDecisionAttributes attributes,
DecisionState state) {
super(id, state);
this.attributes = attributes;
}

@Override
public Decision getDecision() {
switch (state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ public TimerDecisionStateMachine(DecisionId id, StartTimerDecisionAttributes att
this.attributes = attributes;
}

/** Used for unit testing */
TimerDecisionStateMachine(
DecisionId id, StartTimerDecisionAttributes attributes, DecisionState state) {
super(id, state);
this.attributes = attributes;
}

@Override
public Decision getDecision() {
switch (state) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@ final class SimulatedTimeoutExceptionInternal extends RuntimeException {
this.details = details;
}

SimulatedTimeoutExceptionInternal(TimeoutType timeoutType) {
this.timeoutType = timeoutType;
this.details = null;
}

TimeoutType getTimeoutType() {
return timeoutType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,18 +224,6 @@ public boolean isSuspended() {
return workflowWorker.isSuspended() && laWorker.isSuspended() && ldaWorker.isSuspended();
}

public <R> R queryWorkflowExecution(
WorkflowExecution execution,
String queryType,
Class<R> resultClass,
Type resultType,
Object[] args)
throws Exception {
byte[] serializedArgs = dataConverter.toData(args);
byte[] result = workflowWorker.queryWorkflowExecution(execution, queryType, serializedArgs);
return dataConverter.fromData(result, resultClass, resultType);
}

public <R> R queryWorkflowExecution(
WorkflowExecutionHistory history,
String queryType,
Expand Down
32 changes: 0 additions & 32 deletions src/main/java/com/uber/cadence/internal/sync/WorkflowInternal.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,6 @@ public static WorkflowThread newThread(boolean ignoreParentCancellation, Runnabl
return WorkflowThread.newThread(runnable, ignoreParentCancellation);
}

public static WorkflowThread newThread(
boolean ignoreParentCancellation, String name, Runnable runnable) {
if (name == null) {
throw new NullPointerException("name cannot be null");
}
return WorkflowThread.newThread(runnable, ignoreParentCancellation, name);
}

public static Promise<Void> newTimer(Duration duration) {
return getWorkflowInterceptor().newTimer(duration);
}
Expand Down Expand Up @@ -228,26 +220,6 @@ public static <T> T newContinueAsNewStub(
new ContinueAsNewWorkflowInvocationHandler(options, getWorkflowInterceptor()));
}

/**
* Execute activity by name.
*
* @param name name of the activity
* @param resultClass activity return type
* @param args list of activity arguments
* @param <R> activity return type
* @return activity result
*/
public static <R> R executeActivity(
String name, ActivityOptions options, Class<R> resultClass, Type resultType, Object... args) {
Promise<R> result =
getWorkflowInterceptor().executeActivity(name, resultClass, resultType, args, options);
if (AsyncInternal.isAsync()) {
AsyncInternal.setAsyncResult(result);
return null; // ignored
}
return result.get();
}

private static WorkflowInterceptor getWorkflowInterceptor() {
return DeterministicRunnerImpl.currentThreadInternal()
.getDecisionContext()
Expand Down Expand Up @@ -347,10 +319,6 @@ public static void continueAsNew(
decisionContext.continueAsNew(workflowType, options, args);
}

public static Promise<Void> cancelWorkflow(WorkflowExecution execution) {
return getWorkflowInterceptor().cancelWorkflow(execution);
}

public static void sleep(Duration duration) {
getWorkflowInterceptor().sleep(duration);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@
*/
final class WorkflowRetryerInternal {

/**
* Retry procedure synchronously.
*
* @param options retry options.
* @param proc procedure to retry.
*/
public static void retry(RetryOptions options, Functions.Proc proc) {
retry(
options,
() -> {
proc.apply();
return null;
});
}

public static <R> R validateOptionsAndRetry(RetryOptions options, Functions.Func<R> func) {
return retry(RetryOptions.merge(null, options), func);
}
Expand Down
Loading

0 comments on commit 13d4daf

Please sign in to comment.