Skip to content

Commit

Permalink
Color tasks by Unified status
Browse files Browse the repository at this point in the history
  • Loading branch information
vined committed Oct 22, 2018
1 parent 657cdfb commit c9ba164
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 95 deletions.
26 changes: 21 additions & 5 deletions src/static/components/PrepWorkflowsTreeTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import CheckboxField from './fields/CheckboxField';
import {getReadableTimestamp} from '../utils/dates';

const WORKFLOW_CELL_WIDTH = 320;
const GREEN = '#c5e0c5';
const RED = '#ffbfbf';
const YELLOW = '#ffffad';

const Wrapper = styled.div`
width: 100%;
Expand Down Expand Up @@ -45,7 +48,7 @@ const Row = styled.div`
flex-direction: row;
width: 100%;
height: ${props => props.fill ? '100%' : 'auto'};
background: #efefef;
background: ${props => props.color || '#efefef'};
`;

const Col = styled.div`
Expand Down Expand Up @@ -176,16 +179,29 @@ export default class PrepWorkflowsTreeTable extends React.Component {
}, this.afterSelectionUpdate);
};

renderTask = (task, fill) => {
getTaskBgColor = (task) => {
if (task.failures_count) {
return task.task_action
? task.task_action.acted
? GREEN
: YELLOW
: RED
}
return null;
};

renderTask = (task, idx, fill) => {
const color = this.getTaskBgColor(task);

return (
<Row fill={fill} key={task.name}>
<Row fill={fill} color={color} key={`${idx}_${task.name}`}>
<Cell flex={1}>
<Value>
<Checkbox
checked={this.isTaskSelected(task.name)}
handleChange={checked => this.toggleTasksSelection([task], checked)}
/>
{task.name}
{task.short_name}
</Value>
</Cell>
<Cell width={200}><Value>{task.failures_count}</Value></Cell>
Expand All @@ -211,7 +227,7 @@ export default class PrepWorkflowsTreeTable extends React.Component {
{workflow.name}
</Value>
</Cell>
<Cell flex={1}>{workflow.tasks.map(task => this.renderTask(task, fillTask))}</Cell>
<Cell flex={1}>{workflow.tasks.map((task, idx) => this.renderTask(task, idx, fillTask))}</Cell>
</Row>

{!!workflow.children && workflow.children.map(child => this.renderWorkflow(child, level + 1))}
Expand Down
82 changes: 42 additions & 40 deletions src/workflows/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,46 @@ class Site(Document):
name = fields.StringField(max_length=400, primary_key=True)


# Actions

class Action(Document):
action = fields.StringField()
xrootd = fields.StringField()
cores = fields.StringField()
memory = fields.StringField()
secondary = fields.StringField()
splitting = fields.StringField()
group = fields.StringField()

sites = fields.ListField(fields.StringField())
reasons = fields.ListField(fields.StringField())


class Reason(Document):
text = fields.StringField()


class TaskActionParameters(EmbeddedDocument):
action = fields.StringField()
xrootd = fields.StringField()
cores = fields.StringField()
memory = fields.StringField()
secondary = fields.StringField()
splitting = fields.StringField()
group = fields.StringField()

sites = fields.ListField(fields.StringField())
reasons = fields.ListField(fields.StringField())


class TaskAction(Document):
name = fields.StringField()
workflow = fields.StringField()
acted = fields.IntField()
timestamp = fields.LongField()
parameters = fields.EmbeddedDocumentField(TaskActionParameters)


# Tasks

class TaskSiteStatus(EmbeddedDocument):
Expand All @@ -31,13 +71,15 @@ class TaskPrep(EmbeddedDocument):

class Task(EmbeddedDocument):
name = fields.StringField(primary_key=True)
short_name = fields.StringField()
workflow = fields.StringField()
parent_workflow = fields.StringField()
job_type = fields.StringField()
failures_count = fields.LongField()

prep = fields.EmbeddedDocumentField(TaskPrep)
statuses = fields.EmbeddedDocumentListField(TaskSiteStatus)
task_action = fields.ReferenceField(TaskAction)


class Workflow(EmbeddedDocument):
Expand All @@ -54,43 +96,3 @@ class Prep(Document):
updated = fields.DateTimeField()

workflows=fields.EmbeddedDocumentListField(Workflow)


# Actions

class Action(Document):
action = fields.StringField()
xrootd = fields.StringField()
cores = fields.StringField()
memory = fields.StringField()
secondary = fields.StringField()
splitting = fields.StringField()
group = fields.StringField()

sites = fields.ListField(fields.StringField())
reasons = fields.ListField(fields.StringField())


class Reason(Document):
text = fields.StringField()


class TaskActionParameters(EmbeddedDocument):
action = fields.StringField()
xrootd = fields.StringField()
cores = fields.StringField()
memory = fields.StringField()
secondary = fields.StringField()
splitting = fields.StringField()
group = fields.StringField()

sites = fields.ListField(fields.StringField())
reasons = fields.ListField(fields.StringField())


class TaskAction(Document):
name = fields.StringField()
workflow = fields.StringField()
acted = fields.IntField()
timestamp = fields.LongField()
parameters = fields.EmbeddedDocumentField(TaskActionParameters)
112 changes: 65 additions & 47 deletions src/workflows/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,6 @@
logger = logging.getLogger(__name__)


# Tasks

class TaskSiteStatusSerializer(EmbeddedDocumentSerializer):
class Meta:
model = TaskSiteStatus
fields = '__all__'


class TaskPrepSerializer(EmbeddedDocumentSerializer):
class Meta:
model = TaskPrep
fields = '__all__'


class TaskSerializer(EmbeddedDocumentSerializer):
prep = TaskPrepSerializer()
statuses = TaskSiteStatusSerializer(many=True)

class Meta:
model = Task
fields = '__all__'


class WorkflowSerializer(EmbeddedDocumentSerializer):
tasks = TaskSerializer(many=True)

class Meta:
model = Workflow
fields = '__all__'


class PrepSerializer(EmbeddedDocumentSerializer):
workflows = WorkflowSerializer(many=True)

class Meta:
model = Prep
fields = '__all__'


# Sites

class SiteSerializer(DocumentSerializer):
class Meta:
model = Site
fields = '__all__'


# Actions

def get_list_values(key, data):
Expand Down Expand Up @@ -112,6 +65,16 @@ class Meta:
fields = '__all__'


def set_action_to_task(filter_task_name, task, task_action):
if (task.name == filter_task_name):
task.task_action = task_action
return task

def set_action_to_tasks(filter_task_name, workflow, task_action):
workflow.tasks = list(map(lambda task: set_action_to_task(filter_task_name, task, task_action), workflow.tasks))
return workflow


class TaskActionSerializer(BulkSerializerMixin, DocumentSerializer):
parameters = TaskActionParametersSerializer()

Expand All @@ -134,4 +97,59 @@ def create(self, validated_data):
task_action.save()
save_new_reasons(action.reasons)

# Ugly task action reference insert as mongo does not support multiple positional args ($)
preps = Prep.objects(workflows__tasks__name=task_action.name)
for prep in preps:
prep.workflows = list(map(lambda wf: set_action_to_tasks(task_action.name, wf, task_action), prep.workflows))
prep.save()

return task_action


# Tasks

class TaskSiteStatusSerializer(EmbeddedDocumentSerializer):
class Meta:
model = TaskSiteStatus
fields = '__all__'


class TaskPrepSerializer(EmbeddedDocumentSerializer):
class Meta:
model = TaskPrep
fields = '__all__'


class TaskSerializer(EmbeddedDocumentSerializer):
prep = TaskPrepSerializer()
statuses = TaskSiteStatusSerializer(many=True)
task_action = TaskActionSerializer()

class Meta:
model = Task
fields = '__all__'
depth = 1


class WorkflowSerializer(EmbeddedDocumentSerializer):
tasks = TaskSerializer(many=True)

class Meta:
model = Workflow
fields = '__all__'


class PrepSerializer(EmbeddedDocumentSerializer):
workflows = WorkflowSerializer(many=True)

class Meta:
model = Prep
fields = '__all__'


# Sites

class SiteSerializer(DocumentSerializer):
class Meta:
model = Site
fields = '__all__'
7 changes: 4 additions & 3 deletions src/workflows/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_task_name(long_task_name):

def update_workflow_tasks(prep, workflow, parent_workflow, tasks_data):
tasks = []
for long_task_name, task_data in tasks_data:
for name, task_data in tasks_data:
if 'sites' not in task_data:
continue

Expand All @@ -101,13 +101,14 @@ def update_workflow_tasks(prep, workflow, parent_workflow, tasks_data):
if not job_type or job_type in settings.SKIP_JOB_TYPES:
continue

task_name = get_task_name(long_task_name)
short_name = get_task_name(name)
statuses = parse_task_statuses(task_data)
failures_count = get_failures_count(statuses)

try:
task = Task(
name=task_name,
name=name,
short_name=short_name,
workflow=workflow,
parent_workflow=parent_workflow,
job_type=job_type,
Expand Down

0 comments on commit c9ba164

Please sign in to comment.