Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions data/views/workflows.2.0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
<% if (hasOwnProperty("node")) { %>
"node": "<%=node%>",
<% }%>
<% if (hasOwnProperty("_status")) { %>
"status": "<%=_status%>",
<% }%>
<% if (hasOwnProperty("context")) { %>
"context": <%- JSON.stringify(context) %>,
<% }%>
<% if (hasOwnProperty("definition")) { %>
"definition": "<%=basepath%>/workflows/graphs/<%=definition.injectableName%>",
<% } %>

<% if (hasOwnProperty("domain")) { %>
"domain": "<%=domain%>",
<% } %>
<% if (hasOwnProperty("id")) { %>
"id": "<%=id%>",
<% } %>
"injectableName": "<%=injectableName%>",
<% if (hasOwnProperty("instanceId")) { %>
"instanceId": "<%=instanceId%>",
<% } %>
<% if (hasOwnProperty("logContext")) { %>
"logContext": <%- JSON.stringify(logContext) %>,
<% }%>
<% if (hasOwnProperty("name")) { %>
"name": "<%=name%>",
<% }%>
<% if (hasOwnProperty("serviceGraph")) { %>
"serviceGraph": "<%=serviceGraph%>",
<% }%>
"tasks": [
<% if (hasOwnProperty("tasks")) { %>
<%
var taskCount = Object.keys(tasks).length;
var count = 0;
%>
<% _.forEach(tasks, function(value, i, arr) { %>
{
<% count += 1; %>
<% if (value.label) { %>
"label": "<%= value.label%>",
<% }%>
<% if (value.instanceId) { %>
"instanceId": "<%=value.instanceId%>",
<% }%>
<% if (value.error) { %>
"error": <%- JSON.stringify(value.error) %>,
<% } %>
<% if (value.options) { %>
"options": <%- JSON.stringify(value.options)%>,
<% } %>
<% if (value.runJob) { %>
"runJob": "<%=value.runJob%>",
<% } %>
<% if (value.state) { %>
"state": "<%=value.state%>",
<% } %>
<% if (value.taskStartTime) { %>
"taskStartTime": "<%=value.taskStartTime%>",
<% } %>
<% if (value.terminalOnStates) { %>
"terminalOnStates": <%- JSON.stringify(value.terminalOnStates)%>,
<% } %>
<% if (value.waitingOn) { %>
"waitingOn": <%- JSON.stringify(value.waitingOn)%>
<% } %>
}
<%= ( count > 0 && count < taskCount ) ? ',': '' %>
<% }); %>
<% } %>
]
}
122 changes: 107 additions & 15 deletions spec/lib/api/2.0/workflows-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ describe('Http.Api.Workflows.2.0', function () {
var arpCache = {
getCurrent: sinon.stub().resolves([])
};
var views;

before('start HTTP server', function () {
var self = this;
Expand All @@ -26,8 +25,6 @@ describe('Http.Api.Workflows.2.0', function () {
this.sandbox = sinon.sandbox.create();

return helper.startServer([
dihelper.simpleWrapper(waterline, 'Services.Waterline'),
dihelper.simpleWrapper(arpCache, 'ARPCache')
])
.then(function() {
Errors = helper.injector.get('Errors');
Expand All @@ -39,8 +36,6 @@ describe('Http.Api.Workflows.2.0', function () {
self.sandbox.stub(workflowApiService, 'cancelTaskGraph').resolves();
self.sandbox.stub(workflowApiService, 'deleteTaskGraph').resolves();

views = helper.injector.get('Views');
self.sandbox.stub(views, 'render').resolves();
});
});

Expand All @@ -62,6 +57,8 @@ describe('Http.Api.Workflows.2.0', function () {
// to logging.
findOneByTerm: sinon.stub().rejects()
};
return helper.injector.get('Views').load();

});

afterEach('clean up mocks', function () {
Expand All @@ -75,23 +72,70 @@ describe('Http.Api.Workflows.2.0', function () {

describe('workflowsGet', function () {
it('should return a list of persisted graph objects', function () {
var graph = { name: 'foobar' };
var graph =
{
"id": "foobar",
"injectableName": "foobar",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still there are a lot indent errors.
@srinia6 : There is some tool can beautify the code automatically, this will save you time to check every line, such as http://jsbeautifier.org/.

"_status": "running",
"tasks": {
"77444ae5-3232-47b9-b5e6-693ef3dfd11e": {
"friendlyName": "Redfish requester",
"ignoreFailure": false,
"implementsTask": "Task.Base.Redfish",
"injectableName": "Task.Inline.Redfish",
"instanceId": "77444ae5-3232-47b9-b5e6-693ef3dfd11e",
"label": "redfish",
"name": "Task.Inline.Redfish",
"properties": {},
"runJob": "Job.Redfish",
"state": "pending",
"taskStartTime": "2016-08-25T08:22:45.943Z",
"terminalOnStates": [
"succeeded",
"timeout",
"cancelled",
"failed"
],
"waitingOn": {}
}
}
};
var outputWorkflow =
{
"status": 'running',
"injectableName": "foobar",
"id": 'foobar',
"tasks":[{
"label": 'redfish',
"instanceId": '77444ae5-3232-47b9-b5e6-693ef3dfd11e',
"runJob": 'Job.Redfish',
"state": 'pending',
"taskStartTime": '2016-08-25T08:22:45.943Z',
"terminalOnStates":[
"succeeded",
"timeout",
"cancelled",
"failed"
] ,
"waitingOn": {}
}]
};

workflowApiService.getAllWorkflows.resolves([graph]);

return helper.request().get('/api/2.0/workflows')
.expect('Content-Type', /^application\/json/)
.expect(200, [graph])
.expect(function () {
.expect(200)
.expect(function (res) {
expect(workflowApiService.getAllWorkflows).to.have.been.calledOnce;
expect(res.body).to.deep.equal([outputWorkflow]);
});
});

it('should return 404 if not found ', function () {
workflowApiService.getAllWorkflows.rejects(new Errors.NotFoundError('test'));
views.render.resolves('{"message": "error"}');

return helper.request().get('/api/2.0/workflows')
.expect('Content-Type', /^application\/json/)
.expect(404);
});
});
Expand Down Expand Up @@ -119,25 +163,73 @@ describe('Http.Api.Workflows.2.0', function () {

describe('workflowsGetById', function () {
it('should return a single persisted graph', function () {
var graph = { id: 'foobar' };
var graph =
{
"id": "foobar",
"injectableName": "foobar",
"_status": "running",
"tasks": {
"77444ae5-3232-47b9-b5e6-693ef3dfd11e": {
"friendlyName": "Redfish requester",
"ignoreFailure": false,
"implementsTask": "Task.Base.Redfish",
"injectableName": "Task.Inline.Redfish",
"instanceId": "77444ae5-3232-47b9-b5e6-693ef3dfd11e",
"label": "redfish",
"name": "Task.Inline.Redfish",
"properties": {},
"runJob": "Job.Redfish",
"state": "pending",
"taskStartTime": "2016-08-25T08:22:45.943Z",
"terminalOnStates": [
"succeeded",
"timeout",
"cancelled",
"failed"
],
"waitingOn": {}
}
}
};
var outputWorkflow =
{
"status": 'running',
"injectableName": "foobar",
"id": 'foobar',
"tasks":[{
"label": 'redfish',
"instanceId": '77444ae5-3232-47b9-b5e6-693ef3dfd11e',
"runJob": 'Job.Redfish',
"state": 'pending',
"taskStartTime": '2016-08-25T08:22:45.943Z',
"terminalOnStates":[
"succeeded",
"timeout",
"cancelled",
"failed"
] ,
"waitingOn": {}
}]
};

workflowApiService.getWorkflowByInstanceId.resolves(graph);

return helper.request().get('/api/2.0/workflows/foobar')
.expect('Content-Type', /^application\/json/)
.expect(200, graph)
.expect(function () {
.expect(200)
.expect(function (res) {
expect(workflowApiService.getWorkflowByInstanceId).to.have.been.calledOnce;
expect(workflowApiService.getWorkflowByInstanceId)
.to.have.been.calledWith('foobar');
expect(res.body).to.deep.equal(outputWorkflow);

});
});

it('should return a 404 if not found', function () {
workflowApiService.getWorkflowByInstanceId.rejects(new Errors.NotFoundError('test'));
views.render.resolves('{"message": "error"}');

return helper.request().get('/api/2.0/workflows/12345')
.expect('Content-Type', /^application\/json/)
.expect(404);
});
});
Expand Down
2 changes: 2 additions & 0 deletions static/monorail-2.0.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1764,6 +1764,7 @@ paths:
operationId: workflowsGet
x-privileges: [ 'Read' ]
x-authentication-type: [ 'jwt' ]
x-view: workflows.2.0.json
summary: |
Get a list of workflow instances
description: |
Expand Down Expand Up @@ -1844,6 +1845,7 @@ paths:
operationId: workflowsGetByInstanceId
x-privileges: [ 'Read' ]
x-authentication-type: [ 'jwt' ]
x-view: workflows.2.0.json
summary: |
Get a workflow
description: |
Expand Down