Skip to content

Commit

Permalink
Merge pull request #16 from easymorph/development/5.0.0.0
Browse files Browse the repository at this point in the history
version/5.0.0.0
  • Loading branch information
strongtigerman authored Oct 27, 2021
2 parents 4ac0d11 + 44a6f88 commit eb87937
Show file tree
Hide file tree
Showing 42 changed files with 717 additions and 388 deletions.
51 changes: 10 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,7 @@ To get a list of tasks in Space, use ```GetTasksListAsync```.
var result = await client.GetTasksListAsync(apiSession, cancellationToken );
foreach(var task in result.Items){
// do somethig with task
if(task.TaskState == TaskState.Failed){
// task failed
}
}
```
If you want to get more details about a task (e.g. task parameters), use the `GetTaskAsync` method.
Expand All @@ -135,7 +133,7 @@ Use ```TaskChangeModeAsync```.
cancellationToken);
```

##### Starting the Task
##### Starting the Workflow

To run the task:

Expand All @@ -147,18 +145,17 @@ To run the task:
new TaskParameterBase{ Name ="String parameter", Value ="string parameter value" }
};
var result2 = await apiClient.StartTaskAsync(apiSession,
new StartTaskRequest { TaskId = taskId, TaskParameters = taskParameters }, cancellationToken);
new StartTaskRequest(taskId) { TaskParameters = taskParameters }, cancellationToken);
```
The caller gets control back immediately after the task is started. If you attempt to start a task that is already running, no exception is generated.


##### Stopping the Task
##### Stopping the Worflow

To stop the task, call ```StopTaskAsync```:
``` C#

var taskGuid = Guid.Parse("691ea42e-9e6b-438e-84d6-b743841c970e");
await client.StopTaskAsync(apiSession, taskGuid, cancellationToken );
To stop the workflow, call ```CancelComputationAsync``` with ```computationId``` obtained during the ```StartTaskAsync``` call :
``` C#

await client.StopTaskAsync(apiSession, computationId, cancellationToken );
```
The caller gets control back immediately after the task is instructed to stop.

Expand All @@ -171,13 +168,8 @@ Allows to get the task info (including the task parameters)

Console.WriteLine("Info about task:");
Console.WriteLine(string.Format("Id:'{0}'", task.Id));
Console.WriteLine(string.Format("Name:'{0}'", task.TaskName));
Console.WriteLine(string.Format("IsRunning:'{0}'", task.IsRunning));
Console.WriteLine(string.Format("Enabled:'{0}'", task.Enabled));
Console.WriteLine(string.Format("Note:'{0}'", task.Note));
Console.WriteLine(string.Format("ProjectPath:'{0}'", task.ProjectPath));
Console.WriteLine(string.Format("StatusText:'{0}'", task.StatusText));
Console.WriteLine(string.Format("TaskState:'{0}'", task.TaskState));
Console.WriteLine(string.Format("Name:'{0}'", task.TaskName));
Console.WriteLine(string.Format("Note:'{0}'", task.Note));
Console.WriteLine("Task Parameters:");
foreach (var parameter in task.TaskParameters)
{
Expand All @@ -192,29 +184,6 @@ Allows to get the task info (including the task parameters)

```


#### Retrieving task status

To check the task state (running/ not running / failed) and to retrieve task errors, call `GetTaskStatusAsync`:

``` C#
try
{
var taskGuid = Guid.Parse("691ea42e-9e6b-438e-84d6-b743841c970e");
var status = await client.GetTaskStatusAsync(apiSession, taskGuid, cancellationToken );
if(status.IsRunning){
Console.WriteLine(string.Format("Task {0} is running", status.TaskName));
}
}
catch(MorphApiNotFoundException notFound){
Console.WriteLine("Task not found");
}

```


####

### Files API

The EasyMorph Server API allows accessing files of a Server space remotely.
Expand Down
26 changes: 17 additions & 9 deletions src/Client/ILowLevelApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,23 @@ internal interface ILowLevelApiClient: IDisposable
IRestClient RestClient { get; }

// TASKS
Task<ApiResult<TaskStatusDto>> GetTaskStatusAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken);
Task<ApiResult<SpaceTasksListDto>> GetTasksListAsync(ApiSession apiSession, CancellationToken cancellationToken);
Task<ApiResult<SpaceTaskDto>> GetTaskAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken);
Task<ApiResult<SpaceTaskDto>> TaskChangeModeAsync(ApiSession apiSession, Guid taskId, SpaceTaskChangeModeRequestDto requestDto, CancellationToken cancellationToken);

// RUN-STOP Task
Task<ApiResult<RunningTaskStatusDto>> GetRunningTaskStatusAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken);
Task<ApiResult<RunningTaskStatusDto>> StartTaskAsync(ApiSession apiSession, Guid taskId, TaskStartRequestDto taskStartRequestDto, CancellationToken cancellationToken);
Task<ApiResult<NoContentResult>> StopTaskAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken);

Task<ApiResult<TasksListDto>> GetTasksListAsync(ApiSession apiSession, CancellationToken cancellationToken);
Task<ApiResult<TaskFullDto>> GetTaskAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken);
Task<ApiResult<TaskFullDto>> TaskChangeModeAsync(ApiSession apiSession, Guid taskId, SpaceTaskChangeModeRequestDto requestDto, CancellationToken cancellationToken);

// start/cancel/info running workflow

Task<ApiResult<ComputationDetailedItemDto>> StartTaskAsync(ApiSession apiSession, TaskStartRequestDto taskStartRequestDto, CancellationToken cancellationToken);

Task<ApiResult<ComputationDetailedItemDto>> GetComputationDetailsAsync(ApiSession apiSession, string computationId , CancellationToken cancellationToken);
Task CancelComputationAsync(ApiSession apiSession, string computationId , CancellationToken cancellationToken);

Task<ApiResult<WorkflowResultDetailsDto>> GetWorkflowResultDetailsAsync(ApiSession apiSession, string resultToken,
CancellationToken cancellationToken);

Task AcknowledgeWorkflowResultAsync(ApiSession apiSession, string resultToken, CancellationToken cancellationToken);


// Tasks validation
Task<ApiResult<ValidateTasksResponseDto>> ValidateTasksAsync(ApiSession apiSession, ValidateTasksRequestDto validateTasksRequestDto, CancellationToken cancellationToken);
Expand Down
16 changes: 13 additions & 3 deletions src/Client/IMorphServerApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,21 @@ public interface IMorphServerApiClient: IHasConfig, IDisposable


Task<ServerStatus> GetServerStatusAsync(CancellationToken cancellationToken);
Task<Model.TaskStatus> GetTaskStatusAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken);

Task<ApiSession> OpenSessionAsync(OpenSessionRequest openSessionRequest, CancellationToken cancellationToken);

Task<RunningTaskStatus> StartTaskAsync(ApiSession apiSession, StartTaskRequest startTaskRequest, CancellationToken cancellationToken);
Task StopTaskAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken);
/*COMPUTATIONS*/
Task<ComputationDetailedItem> StartTaskAsync(ApiSession apiSession, StartTaskRequest startTaskRequest, CancellationToken cancellationToken);
Task<ComputationDetailedItem> GetComputationDetailsAsync(ApiSession apiSession, string computationId , CancellationToken cancellationToken);
Task CancelComputationAsync(ApiSession apiSession, string computationId , CancellationToken cancellationToken);

Task<WorkflowResultDetails> GetWorkflowResultDetailsAsync(ApiSession apiSession, string resultToken,
CancellationToken cancellationToken);

Task AcknowledgeWorkflowResultAsync(ApiSession apiSession, string resultToken, CancellationToken cancellationToken);





Task<SpaceTask> TaskChangeModeAsync(ApiSession apiSession, Guid taskId, TaskChangeModeRequest taskChangeModeRequest, CancellationToken cancellationToken);
Expand Down
85 changes: 47 additions & 38 deletions src/Client/LowLevelApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,7 @@ public Task<ApiResult<NoContentResult>> AuthLogoutAsync(ApiSession apiSession, C
return apiClient.PostAsync<NoContentRequest, NoContentResult>(url, null, null, apiSession.ToHeadersCollection(), cancellationToken);
}

public Task<ApiResult<RunningTaskStatusDto>> GetRunningTaskStatusAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken)
{
if (apiSession == null)
{
throw new ArgumentNullException(nameof(apiSession));
}

var spaceName = apiSession.SpaceName;
var url = UrlHelper.JoinUrl("space", spaceName, "runningtasks", taskId.ToString("D"));
return apiClient.GetAsync<RunningTaskStatusDto>(url, null, apiSession.ToHeadersCollection(), cancellationToken);
}


public Task<ApiResult<SpacesEnumerationDto>> SpacesGetListAsync(CancellationToken cancellationToken)
{
Expand All @@ -63,42 +53,32 @@ public Task<ApiResult<SpacesLookupResponseDto>> SpacesLookupAsync(SpacesLookupRe
return apiClient.PostAsync<SpacesLookupRequestDto,SpacesLookupResponseDto>(url, requestDto,null, new HeadersCollection(), cancellationToken);
}

public Task<ApiResult<SpaceTaskDto>> GetTaskAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken)
public Task<ApiResult<TaskFullDto>> GetTaskAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken)
{
if (apiSession == null)
{
throw new ArgumentNullException(nameof(apiSession));
}

var url = UrlHelper.JoinUrl("space", apiSession.SpaceName, "tasks", taskId.ToString("D"));
return apiClient.GetAsync<SpaceTaskDto>(url, null, apiSession.ToHeadersCollection(), cancellationToken);
return apiClient.GetAsync<TaskFullDto>(url, null, apiSession.ToHeadersCollection(), cancellationToken);
}

public Task<ApiResult<SpaceTasksListDto>> GetTasksListAsync(ApiSession apiSession, CancellationToken cancellationToken)
public Task<ApiResult<TasksListDto>> GetTasksListAsync(ApiSession apiSession, CancellationToken cancellationToken)
{
if (apiSession == null)
{
throw new ArgumentNullException(nameof(apiSession));
}

var url = UrlHelper.JoinUrl("space", apiSession.SpaceName, "tasks");
return apiClient.GetAsync<SpaceTasksListDto>(url, null, apiSession.ToHeadersCollection(), cancellationToken);
return apiClient.GetAsync<TasksListDto>(url, null, apiSession.ToHeadersCollection(), cancellationToken);
}


public Task<ApiResult<TaskStatusDto>> GetTaskStatusAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken)
{
if (apiSession == null)
{
throw new ArgumentNullException(nameof(apiSession));
}
var spaceName = apiSession.SpaceName;
var url = UrlHelper.JoinUrl("space", spaceName, "tasks", taskId.ToString("D"));
return apiClient.GetAsync<TaskStatusDto>(url, null, apiSession.ToHeadersCollection(), cancellationToken);


}

public Task<ApiResult<SpaceTaskDto>> TaskChangeModeAsync(ApiSession apiSession, Guid taskId, SpaceTaskChangeModeRequestDto requestDto, CancellationToken cancellationToken)
public Task<ApiResult<TaskFullDto>> TaskChangeModeAsync(ApiSession apiSession, Guid taskId, SpaceTaskChangeModeRequestDto requestDto, CancellationToken cancellationToken)
{
if (apiSession == null)
{
Expand All @@ -108,7 +88,7 @@ public Task<ApiResult<SpaceTaskDto>> TaskChangeModeAsync(ApiSession apiSession,
var spaceName = apiSession.SpaceName;
var url = UrlHelper.JoinUrl("space", spaceName, "tasks", taskId.ToString("D"), "changeMode");

return apiClient.PostAsync<SpaceTaskChangeModeRequestDto, SpaceTaskDto>(url, requestDto, null, apiSession.ToHeadersCollection(), cancellationToken);
return apiClient.PostAsync<SpaceTaskChangeModeRequestDto, TaskFullDto>(url, requestDto, null, apiSession.ToHeadersCollection(), cancellationToken);
}

public Task<ApiResult<ServerStatusDto>> ServerGetStatusAsync(CancellationToken cancellationToken)
Expand All @@ -117,31 +97,60 @@ public Task<ApiResult<ServerStatusDto>> ServerGetStatusAsync(CancellationToken c
return apiClient.GetAsync<ServerStatusDto>(url, null, new HeadersCollection(), cancellationToken);
}

public Task<ApiResult<RunningTaskStatusDto>> StartTaskAsync(ApiSession apiSession, Guid taskId, TaskStartRequestDto taskStartRequestDto, CancellationToken cancellationToken)
public Task<ApiResult<ComputationDetailedItemDto>> StartTaskAsync(ApiSession apiSession, TaskStartRequestDto taskStartRequestDto, CancellationToken cancellationToken)
{
if (apiSession == null)
{
throw new ArgumentNullException(nameof(apiSession));
}

var spaceName = apiSession.SpaceName;
var url = UrlHelper.JoinUrl("space", spaceName, "runningtasks", taskId.ToString("D"), "payload");
var url = UrlHelper.JoinUrl("space", spaceName, "computations", "start", "task");

return apiClient.PostAsync<TaskStartRequestDto, RunningTaskStatusDto>(url, taskStartRequestDto, null, apiSession.ToHeadersCollection(), cancellationToken);
return apiClient.PostAsync<TaskStartRequestDto, ComputationDetailedItemDto>(url, taskStartRequestDto, null, apiSession.ToHeadersCollection(), cancellationToken);
}

public Task<ApiResult<NoContentResult>> StopTaskAsync(ApiSession apiSession, Guid taskId, CancellationToken cancellationToken)
public Task<ApiResult<ComputationDetailedItemDto>> GetComputationDetailsAsync(ApiSession apiSession, string computationId, CancellationToken cancellationToken)
{
if (apiSession == null)
{
throw new ArgumentNullException(nameof(apiSession));
}
if (apiSession == null) throw new ArgumentNullException(nameof(apiSession));
if (computationId == null) throw new ArgumentNullException(nameof(computationId));

var spaceName = apiSession.SpaceName;
var url = UrlHelper.JoinUrl("space", spaceName, "runningtasks", taskId.ToString("D"));
return apiClient.DeleteAsync<NoContentResult>(url, null, apiSession.ToHeadersCollection(), cancellationToken);
var url = UrlHelper.JoinUrl("space", spaceName, "computations", computationId);
return apiClient.GetAsync<ComputationDetailedItemDto>(url, null, apiSession.ToHeadersCollection(), cancellationToken);
}

public Task CancelComputationAsync(ApiSession apiSession, string computationId, CancellationToken cancellationToken)
{
if (apiSession == null) throw new ArgumentNullException(nameof(apiSession));
if (computationId == null) throw new ArgumentNullException(nameof(computationId));

var spaceName = apiSession.SpaceName;
var url = UrlHelper.JoinUrl("space", spaceName, "computations", computationId);
return apiClient.DeleteAsync<NoContentRequest>(url, null, apiSession.ToHeadersCollection(), cancellationToken);
}

public Task<ApiResult<WorkflowResultDetailsDto>> GetWorkflowResultDetailsAsync(ApiSession apiSession, string resultToken, CancellationToken cancellationToken)
{
if (apiSession == null) throw new ArgumentNullException(nameof(apiSession));
if (resultToken == null) throw new ArgumentNullException(nameof(resultToken));

var spaceName = apiSession.SpaceName;
var url = UrlHelper.JoinUrl("space", spaceName, "workflows-result", resultToken, "details");
return apiClient.GetAsync<WorkflowResultDetailsDto>(url, null, apiSession.ToHeadersCollection(), cancellationToken);
}

public Task AcknowledgeWorkflowResultAsync(ApiSession apiSession, string resultToken, CancellationToken cancellationToken)
{
if (apiSession == null) throw new ArgumentNullException(nameof(apiSession));
if (resultToken == null) throw new ArgumentNullException(nameof(resultToken));

var spaceName = apiSession.SpaceName;
var url = UrlHelper.JoinUrl("space", spaceName, "workflows-result", resultToken, "ack");
return apiClient.PostAsync<NoContentRequest, NoContentResult>(url, null, null, apiSession.ToHeadersCollection(), cancellationToken);
}


public Task<ApiResult<ValidateTasksResponseDto>> ValidateTasksAsync(ApiSession apiSession, ValidateTasksRequestDto validateTasksRequestDto, CancellationToken cancellationToken)
{
if (apiSession == null)
Expand Down
Loading

0 comments on commit eb87937

Please sign in to comment.