<commit_before>#!/usr/bin/python
#    Copyright 2015 Mirantis, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import click

from solar.orchestration import graph
from solar.orchestration import tasks
from solar.orchestration import filters
from solar.orchestration import utils
from solar.cli.uids_history import SOLARUID, remember_uid


@click.group(name='orch')
def orchestration():
    """
    \b
    create solar/orchestration/examples/multi.yaml
    <id>
    run-once <id>
    report <id>
    <task> -> <status>
    restart <id> --reset
    """


@orchestration.command()
@click.argument('plan')
def create(plan):
    uid = graph.create_plan(plan).graph['uid']
    remember_uid(uid)
    click.echo(uid)


@orchestration.command()
@click.argument('uid', type=SOLARUID)
@click.argument('plan')
def update(uid, plan):
    graph.update_plan(uid, plan)


@orchestration.command()
@click.argument('uid', type=SOLARUID)
def report(uid):
    colors = {
        'PENDING': 'cyan',
        'ERROR': 'red',
        'SUCCESS': 'green',
        'INPROGRESS': 'yellow',
        'SKIPPED': 'blue'}

    total = 0.0
    report = graph.report_topo(uid)
    for item in report:
        msg = '{} -> {}'.format(item[0], item[1])
        if item[2]:
            msg += ' :: {}'.format(item[2])
        if item[4] and item[3]:
            delta = float(item[4])-float(item[3])
            total += delta
            msg += ' D: {}'.format(delta)
        click.echo(click.style(msg, fg=colors[item[1]]))
    click.echo('Delta SUM: {}'.format(total))


@orchestration.command()
@click.argument('uid', type=SOLARUID)
@click.option('--start', '-s', multiple=True)
@click.option('--end', '-e', multiple=True)
def filter(uid, start, end):
    graph.reset_filtered(uid)
    plan = graph.get_graph(uid)
    errors = filters.filter(plan, start=start, end=end)
    if errors:
        raise click.ClickException('\n'.join(errors))
    graph.save_graph(uid, plan)
    utils.write_graph(plan)
    click.echo('Created {name}.png'.format(name=plan.graph['name']))


@orchestration.command(name='run-once')
@click.argument('uid', type=SOLARUID)
def run_once(uid):
    tasks.schedule_start.apply_async(
        args=[uid],
        queue='scheduler')


@orchestration.command()
@click.argument('uid', type=SOLARUID)
def restart(uid):
    graph.reset_by_uid(uid)
    tasks.schedule_start.apply_async(args=[uid], queue='scheduler')<commit_msg>CLI: make 'last' the default for orch run-once and report<commit_after>#!/usr/bin/python
#    Copyright 2015 Mirantis, Inc.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.

import click

from solar.orchestration import graph
from solar.orchestration import tasks
from solar.orchestration import filters
from solar.orchestration import utils
from solar.cli.uids_history import SOLARUID, remember_uid


@click.group(name='orch')
def orchestration():
    """
    \b
    create solar/orchestration/examples/multi.yaml
    <id>
    run-once <id>
    report <id>
    <task> -> <status>
    restart <id> --reset
    """


@orchestration.command()
@click.argument('plan')
def create(plan):
    uid = graph.create_plan(plan).graph['uid']
    remember_uid(uid)
    click.echo(uid)


@orchestration.command()
@click.argument('uid', type=SOLARUID)
@click.argument('plan')
def update(uid, plan):
    graph.update_plan(uid, plan)


@orchestration.command()
@click.argument('uid', type=SOLARUID, default='last')
def report(uid):
    colors = {
        'PENDING': 'cyan',
        'ERROR': 'red',
        'SUCCESS': 'green',
        'INPROGRESS': 'yellow',
        'SKIPPED': 'blue'}

    total = 0.0
    report = graph.report_topo(uid)
    for item in report:
        msg = '{} -> {}'.format(item[0], item[1])
        if item[2]:
            msg += ' :: {}'.format(item[2])
        if item[4] and item[3]:
            delta = float(item[4])-float(item[3])
            total += delta
            msg += ' D: {}'.format(delta)
        click.echo(click.style(msg, fg=colors[item[1]]))
    click.echo('Delta SUM: {}'.format(total))


@orchestration.command()
@click.argument('uid', type=SOLARUID)
@click.option('--start', '-s', multiple=True)
@click.option('--end', '-e', multiple=True)
def filter(uid, start, end):
    graph.reset_filtered(uid)
    plan = graph.get_graph(uid)
    errors = filters.filter(plan, start=start, end=end)
    if errors:
        raise click.ClickException('\n'.join(errors))
    graph.save_graph(uid, plan)
    utils.write_graph(plan)
    click.echo('Created {name}.png'.format(name=plan.graph['name']))


@orchestration.command(name='run-once')
@click.argument('uid', type=SOLARUID, default='last')
def run_once(uid):
    tasks.schedule_start.apply_async(
        args=[uid],
        queue='scheduler')


@orchestration.command()
@click.argument('uid', type=SOLARUID)
def restart(uid):
    graph.reset_by_uid(uid)
    tasks.schedule_start.apply_async(args=[uid], queue='scheduler')
{'fraction_non_alphanumeric': 0.1480859637340497, 'fraction_numerical': 0.0063801208865010076, 'mean_word_length': 3.489073097211756, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7624278', 'n_tokens_mistral': 1941, 'n_tokens_neox': 1920, 'n_words': 472}