Skip to content

Commit

Permalink
Merge 43a5538 into a45258c
Browse files Browse the repository at this point in the history
  • Loading branch information
Dinos Kousidis committed Feb 11, 2019
2 parents a45258c + 43a5538 commit a0bd785
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 6 deletions.
125 changes: 125 additions & 0 deletions reana_commons/openapi_specifications/reana_server.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@
"name": "access_token",
"required": true,
"type": "string"
},
{
"description": "Optional flag to show more information.",
"in": "query",
"name": "verbose",
"required": false,
"type": "boolean"
}
],
"produces": [
Expand All @@ -227,27 +234,31 @@
"created": "2018-06-13T09:47:35.66097",
"id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
"name": "mytest.1",
"size": "10M",
"status": "running",
"user": "00000000-0000-0000-0000-000000000000"
},
{
"created": "2018-06-13T09:47:35.66097",
"id": "3c9b117c-d40a-49e3-a6de-5f89fcada5a3",
"name": "mytest.2",
"size": "12M",
"status": "finished",
"user": "00000000-0000-0000-0000-000000000000"
},
{
"created": "2018-06-13T09:47:35.66097",
"id": "72e3ee4f-9cd3-4dc7-906c-24511d9f5ee3",
"name": "mytest.3",
"size": "180K",
"status": "created",
"user": "00000000-0000-0000-0000-000000000000"
},
{
"created": "2018-06-13T09:47:35.66097",
"id": "c4c0a1a6-beef-46c7-be04-bf4b3beca5a1",
"name": "mytest.4",
"size": "1G",
"status": "created",
"user": "00000000-0000-0000-0000-000000000000"
}
Expand All @@ -265,6 +276,9 @@
"name": {
"type": "string"
},
"size": {
"type": "string"
},
"status": {
"type": "string"
},
Expand Down Expand Up @@ -504,6 +518,117 @@
"summary": "Get diff between two workflows."
}
},
"/api/workflows/{workflow_id_or_name}/disk_usage": {
"get": {
"description": "This resource reports the disk usage of a workflow. Resource is expecting a workflow UUID and some parameters .",
"operationId": "get_workflow_disk_usage",
"parameters": [
{
"description": "Required. API access_token of workflow owner.",
"in": "query",
"name": "access_token",
"required": true,
"type": "string"
},
{
"description": "Required. Analysis UUID or name.",
"in": "path",
"name": "workflow_id_or_name",
"required": true,
"type": "string"
},
{
"description": "Optional. Additional input parameters and operational options.",
"in": "body",
"name": "parameters",
"required": false,
"schema": {
"type": "object"
}
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "Request succeeded. Info about the disk usage is returned.",
"examples": {
"application/json": {
"disk_usage_info": [
{
"name": "file1.txt",
"size": "12KB"
},
{
"name": "plot.png",
"size": "100KB"
}
],
"workflow_id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
"workflow_name": "mytest.1"
}
},
"schema": {
"properties": {
"disk_usage_info": {
"items": {
"properties": {
"name": {
"type": "string"
},
"size": {
"type": "string"
}
},
"type": "object"
},
"type": "array"
},
"user": {
"type": "string"
},
"workflow_id": {
"type": "string"
},
"workflow_name": {
"type": "string"
}
},
"type": "object"
}
},
"400": {
"description": "Request failed. The incoming data specification seems malformed.",
"examples": {
"application/json": {
"message": "Malformed request."
}
}
},
"403": {
"description": "Request failed. User is not allowed to access workflow.",
"examples": {
"application/json": {
"message": "User 00000000-0000-0000-0000-000000000000 is not allowed to access workflow 256b25f4-4cfb-4684-b7a8-73872ef455a1"
}
}
},
"404": {
"description": "Request failed. User does not exist.",
"examples": {
"application/json": {
"message": "Workflow cdcf48b1-c2f3-4693-8230-b066e088c6ac does not exist"
}
}
},
"500": {
"description": "Request failed. Internal controller error."
}
},
"summary": "Get disk usage of a workflow."
}
},
"/api/workflows/{workflow_id_or_name}/logs": {
"get": {
"description": "This resource reports the status of a workflow. Resource is expecting a workflow UUID.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
"name": "user",
"required": true,
"type": "string"
},
{
"description": "Optional flag to show more information.",
"in": "query",
"name": "verbose",
"required": false,
"type": "boolean"
}
],
"produces": [
Expand All @@ -31,29 +38,33 @@
{
"created": "2018-06-13T09:47:35.66097",
"id": "256b25f4-4cfb-4684-b7a8-73872ef455a1",
"name": "mytest-1",
"name": "mytest.1",
"size": "10M",
"status": "running",
"user": "00000000-0000-0000-0000-000000000000"
},
{
"created": "2018-06-13T09:47:35.66097",
"id": "3c9b117c-d40a-49e3-a6de-5f89fcada5a3",
"name": "mytest-2",
"name": "mytest.2",
"size": "12M",
"status": "finished",
"user": "00000000-0000-0000-0000-000000000000"
},
{
"created": "2018-06-13T09:47:35.66097",
"id": "72e3ee4f-9cd3-4dc7-906c-24511d9f5ee3",
"name": "mytest-3",
"status": "waiting",
"name": "mytest.3",
"size": "180K",
"status": "created",
"user": "00000000-0000-0000-0000-000000000000"
},
{
"created": "2018-06-13T09:47:35.66097",
"id": "c4c0a1a6-beef-46c7-be04-bf4b3beca5a1",
"name": "mytest-4",
"status": "waiting",
"name": "mytest.4",
"size": "1G",
"status": "created",
"user": "00000000-0000-0000-0000-000000000000"
}
]
Expand All @@ -70,6 +81,9 @@
"name": {
"type": "string"
},
"size": {
"type": "string"
},
"status": {
"type": "string"
},
Expand Down
15 changes: 15 additions & 0 deletions reana_commons/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import json
import os
import shutil
import subprocess
from hashlib import md5

import click
Expand Down Expand Up @@ -172,3 +173,17 @@ def build_caching_info_message(job_spec,
"result_path": result_path
}
return caching_info_message


def get_workspace_disk_usage(workspace, summarize=False):
"""Retrieve disk usage information of a workspace."""
command = ['du', '-ha']
if summarize:
command.append('-s')
command.append(workspace)
disk_usage_info = subprocess.check_output(command).decode().split()
filesize_pairs = list(zip(disk_usage_info[::2], disk_usage_info[1::2]))
filesizes = []
for filesize_pair in filesize_pairs:
filesizes.append(dict((name, size) for size, name in filesize_pair))
return filesizes

0 comments on commit a0bd785

Please sign in to comment.