Skip to content

Commit

Permalink
Merge pull request #23 from orkes-io/metadata_tag
Browse files Browse the repository at this point in the history
Metadata tag
  • Loading branch information
v1r3n authored Sep 14, 2022
2 parents 720c56e + 8cbf25e commit c214730
Show file tree
Hide file tree
Showing 27 changed files with 813 additions and 749 deletions.
60 changes: 59 additions & 1 deletion docs/METADATA.md
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
# Metadata Management APIs
# Metadata Management APIs

### Create instance of MetadataClient
```
MetadataClient metadataClient = orkesClients.getMetadataClient();
```
### Create task definition
```
TaskDef taskDef = new TaskDef("testing", "sample task");
taskDef.setRetryCount(3); // Task will be executed 4 times assuming each attempt failed.
taskDef.setRetryLogic(TaskDef.RetryLogic.FIXED); // FIXED, EXPONENTIAL_BACKOFF, LINEAR_BACKOFF
taskDef.setRetryDelaySeconds(1); // Delay between each retry
taskDef.setTimeoutPolicy(TaskDef.TimeoutPolicy.TIME_OUT_WF); // RETRY, TIME_OUT_WF, ALERT_ONLY
taskDef.setTimeoutSeconds(10); // Task timeout
taskDef.setResponseTimeoutSeconds(5); // Response timeout for worker tasks.
taskDef.setOwnerEmail("[email protected]"); // Owner email
```
### Register task definition
```
metadataClient.registerTaskDefs(Arrays.asList(taskDef));
```

### Create workflow definition
```
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("example");
workflowDef.setVersion(1); // Workflow version
workflowDef.setOwnerEmail("[email protected]");
workflowDef.setFailureWorkflow("failure_workflow"); // Failure workflow to be executed on failure of current workflow.
workflowDef.setTimeoutSeconds(10); // Workflow timeout.
workflowDef.setVariables(Map.of("value", 2)); // Workflow variables
workflowDef.setInputParameters(List.of("input_value"));
```

### Create workflow task
```
WorkflowTask testing = new WorkflowTask();
testing.setTaskReferenceName("testing");
testing.setName("testing");
testing.setType("SIMPLE");
testing.setInputParameters(Map.of("value", "${workflow.variables.workflow_input_value}",
"order", "${workflow.input.order_id}"));
testing.setWorkflowTaskType(SIMPLE);
```

### Register workflow definition
```
workflowDef.setTasks(Arrays.asList(testing)); // Add task to workflow
metadataClient.registerWorkflowDef(workflowDef); // Register workflow definition
```

### Unregister task definition
```
metadataClient.unregisterTaskDef("SIMPLE");
```
### Unregister workflow definition
```
metadataClient.unregisterWorkflowDef("example", 1); // Unregister workflow example with version 1
```
44 changes: 0 additions & 44 deletions src/main/java/io/orkes/conductor/client/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -823,50 +823,6 @@ public <T> ApiResponse<T> execute(Call call, Type returnType) throws ApiExceptio
}
}

/**
* {@link #executeAsync(Call, Type, ApiCallback)}
*
* @param <T> Type
* @param call An instance of the Call object
* @param callback ApiCallback&lt;T&gt;
*/
public <T> void executeAsync(Call call, ApiCallback<T> callback) {
executeAsync(call, null, callback);
}

/**
* Execute HTTP call asynchronously.
*
* @see #execute(Call, Type)
* @param <T> Type
* @param call The callback to be executed when the API call finishes
* @param returnType Return type
* @param callback ApiCallback
*/
@SuppressWarnings("unchecked")
public <T> void executeAsync(Call call, final Type returnType, final ApiCallback<T> callback) {
call.enqueue(
new Callback() {
@Override
public void onFailure(Request request, IOException e) {
callback.onFailure(new ApiException(e), 0, null);
}

@Override
public void onResponse(Response response) throws IOException {
T result;
try {
result = (T) handleResponse(response, returnType);
} catch (ApiException e) {
callback.onFailure(e, response.code(), response.headers().toMultimap());
return;
}
callback.onSuccess(
result, response.code(), response.headers().toMultimap());
}
});
}

/**
* Handle the given response, return the deserialized object when the response is successful.
*
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/io/orkes/conductor/client/AuthorizationClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public interface AuthorizationClient {

Map<String, List<Subject>> getPermissions(String type, String id);

void grantPermissions(AuthorizationRequest body);
void grantPermissions(AuthorizationRequest authorizationRequest);

void removePermissions(AuthorizationRequest body);
void removePermissions(AuthorizationRequest authorizationRequest);

// Users
void deleteUser(String id);
Expand All @@ -36,9 +36,9 @@ public interface AuthorizationClient {

List<ConductorUser> listUsers(Boolean apps);

void sendInviteEmail(String id, ConductorUser body);
void sendInviteEmail(String id, ConductorUser conductorUser);

ConductorUser upsertUser(UpsertUserRequest body, String id);
ConductorUser upsertUser(UpsertUserRequest upsertUserRequest, String id);

// Groups
void addUserToGroup(String groupId, String userId);
Expand All @@ -55,14 +55,14 @@ public interface AuthorizationClient {

void removeUserFromGroup(String groupId, String userId);

Group upsertGroup(UpsertGroupRequest body, String id);
Group upsertGroup(UpsertGroupRequest upsertGroupRequest, String id);

// Applications
void addRoleToApplicationUser(String applicationId, String role);

CreateAccessKeyResponse createAccessKey(String id);

ConductorApplication createApplication(CreateOrUpdateApplicationRequest body);
ConductorApplication createApplication(CreateOrUpdateApplicationRequest createOrUpdateApplicationRequest);

void deleteAccessKey(String applicationId, String keyId);

Expand All @@ -78,5 +78,6 @@ public interface AuthorizationClient {

AccessKeyResponse toggleAccessKeyStatus(String applicationId, String keyId);

ConductorApplication updateApplication(CreateOrUpdateApplicationRequest body, String id);
ConductorApplication updateApplication(
CreateOrUpdateApplicationRequest createOrUpdateApplicationRequest, String id);
}
22 changes: 22 additions & 0 deletions src/main/java/io/orkes/conductor/client/MetadataClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import com.netflix.conductor.common.metadata.tasks.TaskDef;
import com.netflix.conductor.common.metadata.workflow.WorkflowDef;

import io.orkes.conductor.client.http.ApiException;
import io.orkes.conductor.client.model.TagObject;
import io.orkes.conductor.client.model.TagString;

public interface MetadataClient {
void registerWorkflowDef(WorkflowDef workflowDef);

Expand All @@ -33,4 +37,22 @@ public interface MetadataClient {
TaskDef getTaskDef(String taskType);

void unregisterTaskDef(String taskType);

void addTaskTag(TagObject tagObject, String taskName) throws ApiException;

void addWorkflowTag(TagObject tagObject, String name) throws ApiException;

void deleteTaskTag(TagString tagString, String taskName) throws ApiException;

void deleteWorkflowTag(TagObject tagObject, String name) throws ApiException;

List<TagObject> getTags() throws ApiException;

List<TagObject> getTaskTags(String taskName) throws ApiException;

List<TagObject> getWorkflowTags(String name) throws ApiException;

void setTaskTags(List<TagObject> tagObjects, String taskName) throws ApiException;

void setWorkflowTags(List<TagObject> tagObjects, String name) throws ApiException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ List<Long> getNextFewSchedules(

void resumeSchedule(String name);

void saveSchedule(SaveScheduleRequest body);
void saveSchedule(SaveScheduleRequest saveScheduleRequest);

SearchResultWorkflowScheduleExecutionModel searchV22(
Integer start, Integer size, String sort, String freeText, String query);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/orkes/conductor/client/SecretClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public interface SecretClient {

List<String> listSecretsThatUserCanGrantAccessTo();

void putSecret(String body, String key);
void putSecret(String name, String key);

boolean secretExists(String key);
}
25 changes: 5 additions & 20 deletions src/main/java/io/orkes/conductor/client/WorkflowClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@
import com.netflix.conductor.common.run.Workflow;
import com.netflix.conductor.common.run.WorkflowSummary;

import io.orkes.conductor.client.http.ApiCallback;
import io.orkes.conductor.client.model.WorkflowStatus;

import com.squareup.okhttp.Call;

public interface WorkflowClient {
String startWorkflow(StartWorkflowRequest startWorkflowRequest);

Expand Down Expand Up @@ -74,27 +71,15 @@ SearchResult<Workflow> searchV2(
Integer start, Integer size, String sort, String freeText, String query);

// Bulk operations
BulkResponse pauseWorkflow(List<String> body);

Call pauseWorkflowAsync(List<String> body, ApiCallback<BulkResponse> callback);

BulkResponse restartWorkflow(List<String> body, Boolean useLatestDefinitions);

Call restartWorkflowAsync(
List<String> body, Boolean useLatestDefinitions, ApiCallback<BulkResponse> callback);

BulkResponse resumeWorkflow(List<String> body);

Call resumeWorkflowAsync(List<String> body, ApiCallback<BulkResponse> callback);
BulkResponse pauseWorkflow(List<String> workflowIds);

BulkResponse retryWorkflow(List<String> body);
BulkResponse restartWorkflow(List<String> workflowIds, Boolean useLatestDefinitions);

Call retryWorkflowAsync(List<String> body, ApiCallback<BulkResponse> callback);
BulkResponse resumeWorkflow(List<String> workflowIds);

BulkResponse terminateWorkflow(List<String> body, String reason);
BulkResponse retryWorkflow(List<String> workflowIds);

Call terminateWorkflowAsync(
List<String> body, String reason, ApiCallback<BulkResponse> callback);
BulkResponse terminateWorkflow(List<String> workflowIds, String reason);

WorkflowStatus getWorkflowStatusSummary(
String workflowId, Boolean includeOutput, Boolean includeVariables);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ public Map<String, List<Subject>> getPermissions(String type, String id) throws
}

@Override
public void grantPermissions(AuthorizationRequest body) throws ApiException {
authorizationResourceApi.grantPermissions(body);
public void grantPermissions(AuthorizationRequest authorizationRequest) throws ApiException {
authorizationResourceApi.grantPermissions(authorizationRequest);
}

@Override
public void removePermissions(AuthorizationRequest body) throws ApiException {
authorizationResourceApi.removePermissions(body);
public void removePermissions(AuthorizationRequest authorizationRequest) throws ApiException {
authorizationResourceApi.removePermissions(authorizationRequest);
}

@Override
Expand Down Expand Up @@ -89,8 +89,8 @@ public void removeUserFromGroup(String groupId, String userId) throws ApiExcepti
}

@Override
public Group upsertGroup(UpsertGroupRequest body, String id) throws ApiException {
return groupResourceApi.upsertGroup(body, id);
public Group upsertGroup(UpsertGroupRequest upsertGroupRequest, String id) throws ApiException {
return groupResourceApi.upsertGroup(upsertGroupRequest, id);
}

@Override
Expand All @@ -114,13 +114,14 @@ public List<ConductorUser> listUsers(Boolean apps) throws ApiException {
}

@Override
public void sendInviteEmail(String id, ConductorUser body) throws ApiException {
userResourceApi.sendInviteEmail(id, body);
public void sendInviteEmail(String id, ConductorUser conductorUser) throws ApiException {
userResourceApi.sendInviteEmail(id, conductorUser);
}

@Override
public ConductorUser upsertUser(UpsertUserRequest body, String id) throws ApiException {
return userResourceApi.upsertUser(body, id);
public ConductorUser upsertUser(UpsertUserRequest upsertUserRequest, String id)
throws ApiException {
return userResourceApi.upsertUser(upsertUserRequest, id);
}

@Override
Expand All @@ -134,9 +135,9 @@ public CreateAccessKeyResponse createAccessKey(String id) throws ApiException {
}

@Override
public ConductorApplication createApplication(CreateOrUpdateApplicationRequest body)
public ConductorApplication createApplication(CreateOrUpdateApplicationRequest createOrUpdateApplicationRequest)
throws ApiException {
return applicationResourceApi.createApplication(body);
return applicationResourceApi.createApplication(createOrUpdateApplicationRequest);
}

@Override
Expand Down Expand Up @@ -177,8 +178,9 @@ public AccessKeyResponse toggleAccessKeyStatus(String applicationId, String keyI
}

@Override
public ConductorApplication updateApplication(CreateOrUpdateApplicationRequest body, String id)
public ConductorApplication updateApplication(
CreateOrUpdateApplicationRequest createOrUpdateApplicationRequest, String id)
throws ApiException {
return applicationResourceApi.updateApplication(body, id);
return applicationResourceApi.updateApplication(createOrUpdateApplicationRequest, id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,40 +87,48 @@ public void unregisterTaskDef(String taskType) {
metadataResourceApi.unregisterTaskDef(taskType);
}

// Tags APIs
public void addTaskTag(TagObject body, String taskName) {
tagsApi.addTaskTag(body, taskName);
@Override
public void addTaskTag(TagObject tagObject, String taskName) {
tagsApi.addTaskTag(tagObject, taskName);
}

public void addWorkflowTag(TagObject body, String name) {
tagsApi.addWorkflowTag(body, name);
@Override
public void addWorkflowTag(TagObject tagObject, String name) {
tagsApi.addWorkflowTag(tagObject, name);
}

public void deleteTaskTag(TagString body, String taskName) {
tagsApi.deleteTaskTag(body, taskName);
@Override
public void deleteTaskTag(TagString tagString, String taskName) {
tagsApi.deleteTaskTag(tagString, taskName);
}

public void deleteWorkflowTag(TagObject body, String name) {
tagsApi.deleteWorkflowTag(body, name);
@Override
public void deleteWorkflowTag(TagObject tagObject, String name) {
tagsApi.deleteWorkflowTag(tagObject, name);
}

@Override
public List<TagObject> getTags() {
return tagsApi.getTags();
}

@Override
public List<TagObject> getTaskTags(String taskName) {
return tagsApi.getTaskTags(taskName);
}

@Override
public List<TagObject> getWorkflowTags(String name) {
return tagsApi.getWorkflowTags(name);
}

public void setTaskTags(List<TagObject> body, String taskName) {
tagsApi.setTaskTags(body, taskName);
@Override
public void setTaskTags(List<TagObject> tagObjects, String taskName) {
tagsApi.setTaskTags(tagObjects, taskName);
}

public void setWorkflowTags(List<TagObject> body, String name) {
tagsApi.setWorkflowTags(body, name);
@Override
public void setWorkflowTags(List<TagObject> tagObjects, String name) {
tagsApi.setWorkflowTags(tagObjects, name);
}
}
Loading

0 comments on commit c214730

Please sign in to comment.