Skip to content

Commit

Permalink
Merge pull request #5 from pavansharma36/dev
Browse files Browse the repository at this point in the history
fixed checkstyle
  • Loading branch information
pavansharma36 authored Dec 7, 2023
2 parents d769076 + dc6aee5 commit 55d7d4c
Show file tree
Hide file tree
Showing 24 changed files with 311 additions and 119 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@
import io.github.pavansharma36.workflow.api.adapter.PersistenceAdapter;
import io.github.pavansharma36.workflow.api.util.PollDelayGenerator;

/**
* persistent adapter builder.
*
* @param <T> - same class.
*/
public abstract class BasePersistenceAdapterBuilder<T extends BasePersistenceAdapterBuilder<T>>
extends BaseAdapterBuilder<T, PersistenceAdapter> {

/**
* heartbeat delay generator to use.
*
* @param heartbeatDelayGenerator - generator
* @return - this
*/
public T withHeartbeatDelayGenerator(PollDelayGenerator heartbeatDelayGenerator) {
this.pollDelayGenerator = heartbeatDelayGenerator;
return (T) this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,86 @@ public WorkflowAdapterBuilder withQueuePollDelayGenerator(
return this;
}

/**
* schedule poll delay generator to use.
*
* @param pollDelayGenerator - generator
* @return - this
*/
public WorkflowAdapterBuilder withSchedulePollDelayGenerator(
final PollDelayGenerator pollDelayGenerator) {
this.scheduleAdapterBuilder.withPollDelayGenerator(pollDelayGenerator);
return this;
}

public WorkflowAdapterBuilder withHeartbeatDelayGenerator(PollDelayGenerator heartbeatDelayGenerator) {
/**
* heartbeat generator to use.
*
* @param heartbeatDelayGenerator - generator
* @return - this
*/
public WorkflowAdapterBuilder withHeartbeatDelayGenerator(PollDelayGenerator
heartbeatDelayGenerator) {
this.persistenceAdapterBuilder.withHeartbeatDelayGenerator(heartbeatDelayGenerator);
return this;
}

/**
* poll delay generator to use.
*
* @param pollDelayGenerator - generator
* @return - this
*/
public WorkflowAdapterBuilder withMaintenancePollDelayGenerator(
final PollDelayGenerator pollDelayGenerator
) {
this.scheduleAdapterBuilder.withMaintenanceDelayGenerator(pollDelayGenerator);
return this;
}

/**
* max run duration to use.
*
* @param duration - duration
* @return - this
*/
public WorkflowAdapterBuilder withMaxRunDuration(Duration duration) {
this.scheduleAdapterBuilder.maxRunDuration(duration);
return this;
}

public WorkflowAdapterBuilder withScheduleAdapterBuilder(BaseScheduleAdapterBuilder<?> scheduleAdapterBuilder) {
/**
* scheduler adapter to use.
*
* @param scheduleAdapterBuilder - adapter
* @return - this
*/
public WorkflowAdapterBuilder withScheduleAdapterBuilder(BaseScheduleAdapterBuilder<?>
scheduleAdapterBuilder) {
this.scheduleAdapterBuilder = scheduleAdapterBuilder;
return this;
}

public WorkflowAdapterBuilder withPersistenceAdapterBuilder(BasePersistenceAdapterBuilder<?> persistenceAdapterBuilder) {
/**
* persistent adapter to use.
*
* @param persistenceAdapterBuilder - adaper
* @return - this
*/
public WorkflowAdapterBuilder withPersistenceAdapterBuilder(BasePersistenceAdapterBuilder<?>
persistenceAdapterBuilder) {
this.persistenceAdapterBuilder = persistenceAdapterBuilder;
return this;
}

public WorkflowAdapterBuilder withQueueAdapterBuilder(BaseAdapterBuilder<?, ? extends QueueAdapter> queueAdapterBuilder) {
/**
* queue adapter to use.
*
* @param queueAdapterBuilder - queue adaper
* @return - this
*/
public WorkflowAdapterBuilder withQueueAdapterBuilder(
BaseAdapterBuilder<?, ? extends QueueAdapter> queueAdapterBuilder) {
this.queueAdapterBuilder = queueAdapterBuilder;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ public class ExecutionResult {
private Map<String, Object> resultMeta;
private TaskId decision;

/**
* for serializer.
*/
public ExecutionResult() {

}

/**
* all args constructor.
*
* @param status - status
* @param message - message
* @param resultMeta - result
* @param decision - decision
*/
public ExecutionResult(TaskExecutionStatus status, String message, Map<String, Object> resultMeta,
TaskId decision) {
this.status = status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ private void run(final WorkflowManager workflowManager) {
break;
} catch (final Throwable e) {
log.error("Unhandled error in task execution {}", e.getMessage(), e);
executionResult = new ExecutionResult(TaskExecutionStatus.FAILED_STOP, e.getMessage(), null, null);
executionResult = new ExecutionResult(TaskExecutionStatus.FAILED_STOP,
e.getMessage(), null, null);
force = true;
}
} while (retry++ < taskInfo.getRetryCount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,22 @@
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import io.github.pavansharma36.workflow.api.bean.id.Id;
import java.io.IOException;

/**
* jackson serializer for Id.
*/
public class IdSerializer extends JsonSerializer<Id> {

/**
* serialize id as string.
*
* @param id - id to serialize
* @param jsonGenerator - json
* @param serializerProvider - serializer
* @throws IOException - invalid
*/
@Override
public void serialize(Id id, JsonGenerator jsonGenerator, SerializerProvider serializerProvider)
throws IOException {
Expand Down
2 changes: 1 addition & 1 deletion workflow-api/src/test/resources/simplelogger.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
org.slf4j.simpleLogger.defaultLogLevel=warn
org.slf4j.simpleLogger.defaultLogLevel=info
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public static void main(final String[] args) throws InterruptedException, IOExce
final WorkflowManager workflowManager = WorkflowManagerBuilder.builder().withAdapter(adapter)
.addingTaskExecutor(taskTypeA, 2, te).addingTaskExecutor(taskTypeB, 2, te)
.addingTaskExecutor(taskTypeC, 2, te).addingTaskExecutor(decisionType, 1,
(manager, task) -> new ExecutionResult(TaskExecutionStatus.SUCCESS, null, null, new TaskId("taske"))).build();
(manager, task) -> new ExecutionResult(TaskExecutionStatus.SUCCESS, null,
null, new TaskId("taske"))).build();

CountDownLatch countDownLatch = new CountDownLatch(SUBMIT_COUNT);
workflowManager.workflowManagerListener().addListener(new WorkflowListener() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,21 @@
import java.util.Optional;
import java.util.stream.Collectors;

/**
* inmemory persistence adapter.
*/
public class InmemoryPersistenceAdapter extends BasePersistenceAdapter {

private Map<ManagerId, ManagerInfo> managerInfos = new HashMap<>();
private Map<RunId, RunInfo> runInfos = new HashMap<>();
private Map<RunId, Map<TaskId, TaskInfo>> taskInfos = new HashMap<>();

/**
* required constructor.
*
* @param namespace - NA
* @param heartbeatDelayGenerator - poll delay generator.
*/
public InmemoryPersistenceAdapter(String namespace, PollDelayGenerator heartbeatDelayGenerator) {
super(namespace, heartbeatDelayGenerator);
}
Expand Down Expand Up @@ -130,7 +139,8 @@ public boolean updateRunInfoEpoch(RunId runId) {

@Override
public void createTaskInfos(RunId runId, List<TaskInfo> taskInfos) {
this.taskInfos.put(runId, taskInfos.stream().collect(Collectors.toMap(TaskInfo::getTaskId, t -> t)));
this.taskInfos.put(runId, taskInfos.stream().collect(
Collectors.toMap(TaskInfo::getTaskId, t -> t)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import java.util.Optional;
import lombok.RequiredArgsConstructor;

/**
* queue adapter for inmemory workflow.
*/
@RequiredArgsConstructor
public class InmemoryQueueAdapter implements QueueAdapter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import java.time.Duration;
import lombok.RequiredArgsConstructor;

/**
* schedule adapter for inmemory workflow.
*/
@RequiredArgsConstructor
public class InmemorySchedulerAdapter implements ScheduleAdapter {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
import io.github.pavansharma36.workflow.api.util.WorkflowException;
import io.github.pavansharma36.workflow.inmemory.adapter.InmemoryPersistenceAdapter;

/**
* persistent adapter builder for inmemory workflow.
*/
public class InmemoryPersistenceAdapterBuilder
extends BasePersistenceAdapterBuilder<InmemoryPersistenceAdapterBuilder> {

/**
* default constructor.
*/
public InmemoryPersistenceAdapterBuilder() {
namespace = "NA";
}

@Override
public PersistenceAdapter build() {
return new InmemoryPersistenceAdapter(namespace, pollDelayGenerator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@
import io.github.pavansharma36.workflow.api.util.WorkflowException;
import io.github.pavansharma36.workflow.inmemory.adapter.InmemoryQueueAdapter;

/**
* queue adapter builder for inmemory workflow.
*/
public class InmemoryQueueAdapterBuilder
extends BaseAdapterBuilder<InmemoryQueueAdapterBuilder, QueueAdapter> {

/**
* default constructor.
*/
public InmemoryQueueAdapterBuilder() {
namespace = "NA";
}

@Override
public QueueAdapter build() {
return new InmemoryQueueAdapter(pollDelayGenerator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
import io.github.pavansharma36.workflow.api.util.WorkflowException;
import io.github.pavansharma36.workflow.inmemory.adapter.InmemorySchedulerAdapter;

public class InmemoryScheduleAdapterBuilder extends BaseScheduleAdapterBuilder<InmemoryScheduleAdapterBuilder> {
/**
* schedule adapter builder for inmemory workflow.
*/
public class InmemoryScheduleAdapterBuilder
extends BaseScheduleAdapterBuilder<InmemoryScheduleAdapterBuilder> {

/**
* default constructor.
*/
public InmemoryScheduleAdapterBuilder() {
namespace = "NA";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@

import io.github.pavansharma36.workflow.api.adapter.builder.WorkflowAdapterBuilder;

/**
* workflow adapter builder for inmemory workflow.
*/
public class InmemoryWorkflowAdapterBuilder
extends WorkflowAdapterBuilder {


/**
* main builder.
*
* @return - this
*/
public static InmemoryWorkflowAdapterBuilder builder() {
InmemoryWorkflowAdapterBuilder builder = new InmemoryWorkflowAdapterBuilder();
builder.scheduleAdapterBuilder = new InmemoryScheduleAdapterBuilder();
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions workflow-mongodb/src/main/java/io/github/pavansharma36/App.java

This file was deleted.

Loading

0 comments on commit 55d7d4c

Please sign in to comment.