Skip to content

Commit

Permalink
Fix client api namings (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng committed Dec 11, 2022
1 parent e7b4e70 commit 5dafc83
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 62 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ signing {
}

group = "io.github.cadence-oss"
version = "1.0.0-rc5"
version = "1.0.0-rc6"

nexusPublishing {
repositories {
Expand Down
66 changes: 34 additions & 32 deletions src/main/java/io/github/cadenceoss/iwf/core/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public UntypedClient getUntypedClient() {
return untypedClient;
}

public String StartWorkflow(
public String startWorkflow(
final Class<? extends Workflow> workflowClass,
final String startStateId,
final String workflowId,
final WorkflowStartOptions options) {
return StartWorkflow(workflowClass, startStateId, null, workflowId, options);
return startWorkflow(workflowClass, startStateId, null, workflowId, options);
}

public String StartWorkflow(
public String startWorkflow(
final Class<? extends Workflow> workflowClass,
final String startStateId,
final Object input,
Expand All @@ -52,7 +52,7 @@ public String StartWorkflow(
throw new IllegalArgumentException("invalid start stateId " + startStateId);
}

return untypedClient.StartWorkflow(wfType, startStateId, input, workflowId, options);
return untypedClient.startWorkflow(wfType, startStateId, input, workflowId, options);
}

/**
Expand All @@ -65,34 +65,36 @@ public String StartWorkflow(
* @param <T> type of the output
* @return
*/
public <T> T GetSimpleWorkflowResultWithWait(
public <T> T getSimpleWorkflowResultWithWait(
Class<T> valueClass,
final String workflowId,
final String workflowRunId) {
return untypedClient.GetSimpleWorkflowResultWithWait(valueClass, workflowId, workflowRunId);
return untypedClient.getSimpleWorkflowResultWithWait(valueClass, workflowId, workflowRunId);
}

public <T> T GetSimpleWorkflowResultWithWait(
public <T> T getSimpleWorkflowResultWithWait(
Class<T> valueClass,
final String workflowId) {
return GetSimpleWorkflowResultWithWait(valueClass, workflowId, "");
return getSimpleWorkflowResultWithWait(valueClass, workflowId, "");
}

/**
* In some cases, a workflow may have more than one completion states
*
* @param workflowId
* @param workflowRunId
* @return a list of the state output for completion states. User code will figure how to use ObjectEncoder to decode the output
*/
public List<StateCompletionOutput> GetComplexWorkflowResultWithWait(
public List<StateCompletionOutput> getComplexWorkflowResultWithWait(
final String workflowId, final String workflowRunId) {
return untypedClient.GetComplexWorkflowResultWithWait(workflowId, workflowRunId);
return untypedClient.getComplexWorkflowResultWithWait(workflowId, workflowRunId);
}

public List<StateCompletionOutput> GetComplexWorkflowResultWithWait(final String workflowId) {
return GetComplexWorkflowResultWithWait(workflowId, "");
public List<StateCompletionOutput> getComplexWorkflowResultWithWait(final String workflowId) {
return getComplexWorkflowResultWithWait(workflowId, "");
}
public void SignalWorkflow(

public void signalWorkflow(
final Class<? extends Workflow> workflowClass,
final String workflowId,
final String workflowRunId,
Expand All @@ -115,7 +117,7 @@ public void SignalWorkflow(
throw new IllegalArgumentException(String.format("Signal value is not of type %s", signalType.getName()));
}

untypedClient.SignalWorkflow(workflowId, workflowRunId, signalChannelName, signalValue);
untypedClient.signalWorkflow(workflowId, workflowRunId, signalChannelName, signalValue);
}

/**
Expand All @@ -124,46 +126,46 @@ public void SignalWorkflow(
* @param resetWorkflowTypeAndOptions
* @return
*/
public String ResetWorkflow(
public String resetWorkflow(
final String workflowId,
final String workflowRunId,
final ResetWorkflowTypeAndOptions resetWorkflowTypeAndOptions
){
) {

return untypedClient.ResetWorkflow(workflowId, workflowRunId, resetWorkflowTypeAndOptions);
return untypedClient.resetWorkflow(workflowId, workflowRunId, resetWorkflowTypeAndOptions);
}

/**
* Cancel a workflow, this is essentially terminate the workflow gracefully
* Stop a workflow, this is essentially terminate the workflow gracefully
*
* @param workflowId required
* @param workflowRunId optional, can be empty
*/
public void CancelWorkflow(
public void stopWorkflow(
final String workflowId,
final String workflowRunId) {
untypedClient.CancelWorkflow(workflowId, workflowRunId);
untypedClient.StopWorkflow(workflowId, workflowRunId);
}

public Map<String, Object> GetWorkflowQueryAttributes(
public Map<String, Object> getWorkflowDataObjects(
final Class<? extends Workflow> workflowClass,
final String workflowId,
final String workflowRunId,
List<String> attributeKeys) {
if (attributeKeys == null || attributeKeys.isEmpty()) {
throw new IllegalArgumentException("attributeKeys must contain at least one entry, or use getAllQueryAttributes API to get all");
throw new IllegalArgumentException("attributeKeys must contain at least one entry, or use getAllDataObjects API to get all");
}
return doGetWorkflowQueryAttributes(workflowClass, workflowId, workflowRunId, attributeKeys);
return doGetWorkflowDataObjects(workflowClass, workflowId, workflowRunId, attributeKeys);
}

public Map<String, Object> GetAllQueryAttributes(
public Map<String, Object> getAllDataObjects(
final Class<? extends Workflow> workflowClass,
final String workflowId,
final String workflowRunId) {
return doGetWorkflowQueryAttributes(workflowClass, workflowId, workflowRunId, null);
return doGetWorkflowDataObjects(workflowClass, workflowId, workflowRunId, null);
}

private Map<String, Object> doGetWorkflowQueryAttributes(
private Map<String, Object> doGetWorkflowDataObjects(
final Class<? extends Workflow> workflowClass,
final String workflowId,
final String workflowRunId,
Expand Down Expand Up @@ -192,7 +194,7 @@ private Map<String, Object> doGetWorkflowQueryAttributes(
}
}

final WorkflowGetDataObjectsResponse response = untypedClient.GetAnyWorkflowDataObjects(workflowId, workflowRunId, attributeKeys);
final WorkflowGetDataObjectsResponse response = untypedClient.getAnyWorkflowDataObjects(workflowId, workflowRunId, attributeKeys);

if (response.getObjects() == null) {
throw new InternalServiceException("query attributes not returned");
Expand All @@ -209,11 +211,11 @@ private Map<String, Object> doGetWorkflowQueryAttributes(
return result;
}

public WorkflowSearchResponse SearchWorkflow(final String query, final int pageSize) {
return untypedClient.SearchWorkflow(query, pageSize);
public WorkflowSearchResponse searchWorkflow(final String query, final int pageSize) {
return untypedClient.searchWorkflow(query, pageSize);
}

public Map<String, Object> GetWorkflowSearchAttributes(
public Map<String, Object> getWorkflowSearchAttributes(
final Class<? extends Workflow> workflowClass,
final String workflowId,
final String workflowRunId,
Expand All @@ -224,7 +226,7 @@ public Map<String, Object> GetWorkflowSearchAttributes(
return doGetWorkflowSearchAttributes(workflowClass, workflowId, workflowRunId, attributeKeys);
}

public Map<String, Object> GetAllSearchAttributes(
public Map<String, Object> getAllSearchAttributes(
final Class<? extends Workflow> workflowClass,
final String workflowId,
final String workflowRunId) {
Expand Down Expand Up @@ -279,7 +281,7 @@ private Map<String, Object> doGetWorkflowSearchAttributes(
});
}

WorkflowGetSearchAttributesResponse response = untypedClient.GetAnyWorkflowSearchAttributes(workflowId, workflowRunId, keyAndTypes);
WorkflowGetSearchAttributesResponse response = untypedClient.getAnyWorkflowSearchAttributes(workflowId, workflowRunId, keyAndTypes);

if (response.getSearchAttributes() == null) {
throw new InternalServiceException("query attributes not returned");
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/io/github/cadenceoss/iwf/core/UntypedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public UntypedClient(final ClientOptions clientOptions) {
.buildClient(DefaultApi.class);
}

public String StartWorkflow(
public String startWorkflow(
final String workflowType,
final String startStateId,
final Object input,
Expand Down Expand Up @@ -73,7 +73,7 @@ public String StartWorkflow(
* @param <T> type of the output
* @return
*/
public <T> T GetSimpleWorkflowResultWithWait(
public <T> T getSimpleWorkflowResultWithWait(
Class<T> valueClass,
final String workflowId,
final String workflowRunId) {
Expand All @@ -97,10 +97,10 @@ public <T> T GetSimpleWorkflowResultWithWait(
return clientOptions.getObjectEncoder().decode(output.getCompletedStateOutput(), valueClass);
}

public <T> T GetSimpleWorkflowResultWithWait(
public <T> T getSimpleWorkflowResultWithWait(
Class<T> valueClass,
final String workflowId) {
return GetSimpleWorkflowResultWithWait(valueClass, workflowId, "");
return getSimpleWorkflowResultWithWait(valueClass, workflowId, "");
}

/**
Expand All @@ -110,7 +110,7 @@ public <T> T GetSimpleWorkflowResultWithWait(
* @param workflowRunId optional runId, can be empty string
* @return a list of the state output for completion states. User code will figure how to use ObjectEncoder to decode the output
*/
public List<StateCompletionOutput> GetComplexWorkflowResultWithWait(
public List<StateCompletionOutput> getComplexWorkflowResultWithWait(
final String workflowId, final String workflowRunId) {
WorkflowGetResponse workflowGetResponse = defaultApi.apiV1WorkflowGetWithWaitPost(
new WorkflowGetRequest()
Expand All @@ -122,7 +122,7 @@ public List<StateCompletionOutput> GetComplexWorkflowResultWithWait(
return workflowGetResponse.getResults();
}

public void SignalWorkflow(
public void signalWorkflow(
final String workflowId,
final String workflowRunId,
final String signalChannelName,
Expand All @@ -140,7 +140,7 @@ public void SignalWorkflow(
* @param resetWorkflowTypeAndOptions
* @return
*/
public String ResetWorkflow(
public String resetWorkflow(
final String workflowId,
final String workflowRunId,
final ResetWorkflowTypeAndOptions resetWorkflowTypeAndOptions
Expand All @@ -166,12 +166,12 @@ public String ResetWorkflow(
}

/**
* Cancel a workflow, this is essentially terminate the workflow gracefully
* Stop a workflow, this is essentially terminate the workflow gracefully
*
* @param workflowId required
* @param workflowRunId optional
*/
public void CancelWorkflow(
public void StopWorkflow(
final String workflowId,
final String workflowRunId) {
defaultApi.apiV1WorkflowStopPost(new WorkflowStopRequest()
Expand All @@ -185,7 +185,7 @@ public void CancelWorkflow(
* @param attributeKeys, return all attributes if this is empty or null
* @return
*/
public WorkflowGetDataObjectsResponse GetAnyWorkflowDataObjects(
public WorkflowGetDataObjectsResponse getAnyWorkflowDataObjects(
final String workflowId,
final String workflowRunId,
List<String> attributeKeys) {
Expand All @@ -198,15 +198,15 @@ public WorkflowGetDataObjectsResponse GetAnyWorkflowDataObjects(
);
}

public WorkflowSearchResponse SearchWorkflow(final String query, final int pageSize) {
public WorkflowSearchResponse searchWorkflow(final String query, final int pageSize) {
return defaultApi.apiV1WorkflowSearchPost(
new WorkflowSearchRequest()
.query(query)
.pageSize(pageSize)
);
}

public WorkflowGetSearchAttributesResponse GetAnyWorkflowSearchAttributes(
public WorkflowGetSearchAttributesResponse getAnyWorkflowSearchAttributes(
final String workflowId,
final String workflowRunId,
List<SearchAttributeKeyAndType> attributeKeys) {
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/github/cadenceoss/iwf/integ/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public void testBasicWorkflow() throws InterruptedException {
.workflowIdReusePolicy(Optional.of(WorkflowIdReusePolicy.ALLOW_DUPLICATE))
.build();
final Integer input = 0;
client.StartWorkflow(BasicWorkflow.class, BasicWorkflowState1.StateId, input, wfId, startOptions);
client.startWorkflow(BasicWorkflow.class, BasicWorkflowState1.StateId, input, wfId, startOptions);
// wait for workflow to finish
final Integer output = client.GetSimpleWorkflowResultWithWait(Integer.class, wfId);
final Integer output = client.getSimpleWorkflowResultWithWait(Integer.class, wfId);
Assertions.assertEquals(input + 2, output);
}

Expand All @@ -50,8 +50,8 @@ public void testEmptyInputWorkflow() throws InterruptedException {
.build();

//client.StartWorkflow(EmptyInputWorkflow.class, EmptyInputWorkflowState1.StateId, null, wfId, startOptions);
client.getUntypedClient().StartWorkflow(EmptyInputWorkflow.CUSTOM_WF_TYPE, EmptyInputWorkflowState1.StateId, null, wfId, startOptions);
client.getUntypedClient().startWorkflow(EmptyInputWorkflow.CUSTOM_WF_TYPE, EmptyInputWorkflowState1.StateId, null, wfId, startOptions);
// wait for workflow to finish
client.GetSimpleWorkflowResultWithWait(Integer.class, wfId);
client.getSimpleWorkflowResultWithWait(Integer.class, wfId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public void testBasicInterStateWorkflow() throws InterruptedException {
final String wfId = "basic-inter-state-test-id" + System.currentTimeMillis() / 1000;
final WorkflowStartOptions startOptions = WorkflowStartOptions.minimum(10);
final Integer input = 1;
final String runId = client.StartWorkflow(
final String runId = client.startWorkflow(
BasicInterStateChannelWorkflow.class, BasicInterStateChannelWorkflowState0.STATE_ID, input, wfId, startOptions);
final Integer output = client.GetSimpleWorkflowResultWithWait(Integer.class, wfId);
final Integer output = client.getSimpleWorkflowResultWithWait(Integer.class, wfId);
Assertions.assertEquals(3, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,25 @@ public void testPersistenceWorkflow() throws InterruptedException {
final Client client = new Client(WorkflowRegistry.registry, ClientOptions.localDefault);
final String wfId = "basic-query-test-id" + System.currentTimeMillis() / 1000;
final WorkflowStartOptions startOptions = WorkflowStartOptions.minimum(10);
final String runId = client.StartWorkflow(
final String runId = client.startWorkflow(
BasicAttributeWorkflow.class, BasicAttributeWorkflowState1.STATE_ID, "start", wfId, startOptions);
final String output = client.GetSimpleWorkflowResultWithWait(String.class, wfId);
final String output = client.getSimpleWorkflowResultWithWait(String.class, wfId);
Map<String, Object> map =
client.GetWorkflowQueryAttributes(BasicAttributeWorkflow.class, wfId, runId, Arrays.asList(BasicAttributeWorkflow.TEST_DATA_OBJECT_KEY));
client.getWorkflowDataObjects(BasicAttributeWorkflow.class, wfId, runId, Arrays.asList(BasicAttributeWorkflow.TEST_DATA_OBJECT_KEY));
Assertions.assertEquals(
"query-start-query-decide", map.get(BasicAttributeWorkflow.TEST_DATA_OBJECT_KEY));
Map<String, Object> allQueryAttributes =
client.GetAllQueryAttributes(BasicAttributeWorkflow.class, wfId, runId);
client.getAllDataObjects(BasicAttributeWorkflow.class, wfId, runId);
Assertions.assertEquals(
"query-start-query-decide", allQueryAttributes.get(BasicAttributeWorkflow.TEST_DATA_OBJECT_KEY));
Assertions.assertEquals(
1, allQueryAttributes.size());
Assertions.assertEquals("test-value-2", output);

final Map<String, Object> searchAttributes1 = client.GetWorkflowSearchAttributes(BasicAttributeWorkflow.class,
final Map<String, Object> searchAttributes1 = client.getWorkflowSearchAttributes(BasicAttributeWorkflow.class,
wfId, "", Arrays.asList(TEST_SEARCH_ATTRIBUTE_KEYWORD, TEST_SEARCH_ATTRIBUTE_INT));

final Map<String, Object> searchAttributes2 = client.GetAllSearchAttributes(BasicAttributeWorkflow.class,
final Map<String, Object> searchAttributes2 = client.getAllSearchAttributes(BasicAttributeWorkflow.class,
wfId, "");

Assertions.assertEquals(searchAttributes1, searchAttributes2);
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/io/github/cadenceoss/iwf/integ/SignalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public void testBasicSignalWorkflow() throws InterruptedException {
final String wfId = "basic-signal-test-id" + System.currentTimeMillis() / 1000;
final WorkflowStartOptions startOptions = WorkflowStartOptions.minimum(10);
final Integer input = 1;
final String runId = client.StartWorkflow(
final String runId = client.startWorkflow(
BasicSignalWorkflow.class, BasicSignalWorkflowState1.STATE_ID, input, wfId, startOptions);
client.SignalWorkflow(
client.signalWorkflow(
BasicSignalWorkflow.class, wfId, runId, BasicSignalWorkflowState1.SIGNAL_CHANNEL_NAME_1, Integer.valueOf(2));
final Integer output = client.GetSimpleWorkflowResultWithWait(Integer.class, wfId);
final Integer output = client.getSimpleWorkflowResultWithWait(Integer.class, wfId);
Assertions.assertEquals(3, output);
}
}
4 changes: 2 additions & 2 deletions src/test/java/io/github/cadenceoss/iwf/integ/TimerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ public void testBasicTimerWorkflow() throws InterruptedException {
final WorkflowStartOptions startOptions = WorkflowStartOptions.minimum(10);
final Integer input = 5;

client.StartWorkflow(
client.startWorkflow(
BasicTimerWorkflow.class, BasicTimerWorkflowState1.STATE_ID, input, wfId, startOptions);

client.GetSimpleWorkflowResultWithWait(Integer.class, wfId);
client.getSimpleWorkflowResultWithWait(Integer.class, wfId);
final long elapsed = System.currentTimeMillis() - startTs;
Assertions.assertTrue(elapsed >= 4000 && elapsed <= 7000, String.format("actual duration: %d", elapsed));
}
Expand Down

0 comments on commit 5dafc83

Please sign in to comment.