def main():
    print('Hello World')
    # Create a conductor worker client
    # Args: location of WF server, number of threads, and polling interval
    cc = ConductorWorker('http://localhost:8080/api', 1, 0.1)
    # Start polling for task
    cc.start('hello_task', execute, True)
Exemple #2
0
def test_conductor_worker():
    num_threads = 2
    worker = ConductorWorker('http://server_url', num_threads, 0.1, 'wid')
    num_tasks = num_threads * 3
    id_range = range(123, 123 + num_tasks)
    events = [threading.Event() for _ in id_range]
    return_val = {'status': '', 'output': 'out', 'logs': []}

    tasks = [{'taskId': str(n)} for n in id_range]

    # output is named outputData in the resulting task
    out_tasks = [{'status': '', 'outputData': 'out', 'logs': [], 'taskId': task['taskId']} for task in tasks]

    def exec_function(task):
        assert task in tasks
        tasks.remove(task)
        for ev in events:
            if not ev.is_set():
                ev.set()
                break
        return return_val

    # verify conductor worker call the appropriate method in TaskClient, acks the task, and updates the output
    poll = mock.Mock()
    ack = mock.Mock()
    update = mock.Mock()
    with mock.patch.multiple('conductor.conductor.TaskClient', pollForTask=poll, updateTask=update, ackTask=ack):
        poll.side_effect = tasks + [None] * num_threads
        worker.start('task_a', exec_function, False, 'my_domain')
        for ev in events:
            assert ev.wait(2) is True

        poll.assert_has_calls([mock.call('task_a', 'wid', 'my_domain')] * num_tasks)
        ack.assert_has_calls([mock.call(str(i), 'wid') for i in id_range])
        update.assert_has_calls([mock.call(t) for t in out_tasks])
def main():
    log.info('send_email worker connecting to conductor at {}'.format(conf.conductor))
    cc = ConductorWorker(conf.conductor + "/api", 1, 0.1)

    cc.start('send_email', send_email_task, True)

    return 1
Exemple #4
0
 def start_polling(self, num_threads=1, polling_interval=0.1, wait=False):
     """
     Hook handling function, which handles communicating with component services
     to the task and start polling.
     """
     cc = ConductorWorker(self.wf_server_addr, num_threads,
                          polling_interval)
     cc.start(self.task_name, self.task_service_func, wait)
def main():
    global template
    cd = os.path.dirname(os.path.realpath(sys.argv[0]))
    with open(os.path.join(cd, 'template')) as tfile:
        template = Template(tfile.read())

    log.info('connecting to conductor at %s', conf.conductor)
    cc = ConductorWorker(conf.conductor + '/api', 1, 0.1)

    cc.start('prepare_org_welcome_email', prepare_org_welcome_email, True)
Exemple #6
0
def main():
    print('Starting tinadi-demo workflows')
    cc = ConductorWorker('http://202.120.167.198:8080/api', 1, 2)
    cc.start('tiandi_health_check_task', execute_health_check, False)
    cc.start('tiandi_a', execute_a, False)
    cc.start('tiandi_b', execute_b, False)
    cc.start('tiandi_c', execute_c, True)
def main():
    task_def = define_task()
    with open('hover_power.json', 'w') as j:
        json.dump(task_def, j, indent=2)

    # Try to run function as a test
    hover_power({'inputData': task_def['inputTemplate']})

    # Register this task
    mc = MetadataClient('http://localhost:8080/api')
    # unregister_default_tasks(mc)
    mc.registerTaskDefs([task_def])

    # Start worker
    cw = ConductorWorker('http://localhost:8080/api', 1, 0.1)
    cw.start(taskType=task_def['name'],
             exec_function=hover_power,
             wait=False)

    # Create workflow
    wf_def = define_workflow()
    mc.updateWorkflowDefs([wf_def])

    # Start workflow
    wc = WorkflowClient('http://localhost:8080/api')
    wc.startWorkflow(wfName=wf_def['name'],
                     inputjson=task_def['inputTemplate'])
    # sleep(200)

    # Start worker
    cw = ConductorWorker('http://localhost:8080/api', 1, 0.1)
    cw.start(taskType=task_def['name'],
             exec_function=hover_power,
             wait=True)
Exemple #8
0
def main():
    print('Starting tinadi-demo workflows')
    metadataClient = conductor.MetadataClient('http://202.120.167.198:8080/api')
    # metadataClient.unRegisterTaskDef('tiandi_c');
    cc = ConductorWorker('http://10.60.38.173:18080/api', 1, 2)
    cc.start('tiandi_health_check_task', execute_health_check, False)
    cc.start('tiandi_a', execute_a, False)
    cc.start('tiandi_b', execute_b, False)
    cc.start('tiandi_c', execute_c, True)
Exemple #9
0
def main():
    print('Starting Kitchensink workflows')
    cc = ConductorWorker('http://localhost:8080/api', 1, 0.1)
    for x in range(1, 30):
        if (x == 4):
            cc.start('task_{0}'.format(x), execute4, False)
        else:
            cc.start('task_{0}'.format(x), execute, False)
    cc.start('task_30', execute, True)
def main():
    print 'Hello World'
    cc = ConductorWorker('http://localhost:8080/api', 1, 0.1)
    for x in range(1, 30):
        if (x == 4):
            cc.start('task_{0}'.format(x), execute4, False)
        else:
            cc.start('task_{0}'.format(x), execute, False)
    cc.start('task_30', execute, True)
Exemple #11
0
def execute(task):
    return ConductorWorker.task_result(status=TaskStatus.COMPLETED,
                                       output={
                                           'mod': 5,
                                           'taskToExecute': 'task_1',
                                           'oddEven': 0
                                       },
                                       logs=['one', 'two'])
Exemple #12
0
def test_conductor_worker():
    num_threads = 2
    worker = ConductorWorker('http://server_url', num_threads, 0.1, 'wid')
    num_tasks = num_threads * 3
    id_range = range(123, 123 + num_tasks)
    events = [threading.Event() for _ in id_range]
    return_val = {'status': '', 'output': 'out', 'logs': []}

    tasks = [{'taskId': str(n)} for n in id_range]

    # output is named outputData in the resulting task
    out_tasks = [{
        'status': '',
        'outputData': 'out',
        'logs': [],
        'taskId': task['taskId']
    } for task in tasks]

    def exec_function(task):
        assert task in tasks
        tasks.remove(task)
        for ev in events:
            if not ev.is_set():
                ev.set()
                break
        return return_val

    # verify conductor worker call the appropriate method in TaskClient, acks the task, and updates the output
    poll = mock.Mock()
    ack = mock.Mock()
    update = mock.Mock()
    with mock.patch.multiple('conductor.conductor.TaskClient',
                             pollForTask=poll,
                             updateTask=update,
                             ackTask=ack):
        poll.side_effect = tasks + [None] * num_threads
        worker.start('task_a', exec_function, False, 'my_domain')
        for ev in events:
            assert ev.wait(2) is True

        poll.assert_has_calls([mock.call('task_a', 'wid', 'my_domain')] *
                              num_tasks)
        ack.assert_has_calls([mock.call(str(i), 'wid') for i in id_range])
        update.assert_has_calls([mock.call(t) for t in out_tasks])
def main():
    print('Starting Kitchensink workflows')
    cc = ConductorWorker('http://localhost:8080/api', 1, 0.1)
    for x in range(1, 30):
        if(x == 4):
            cc.start('task_{0}'.format(x), execute4, False)
        else:
            cc.start('task_{0}'.format(x), execute, False)
    cc.start('task_30', execute, True)
def main():
    print('Starting FRINX workers')
    cc = ConductorWorker(conductor_url_base, 1, 0.1)

    cli_worker.start(cc)
    platform_worker.start(cc)
    l3vpn_worker.start(cc)
    lldp_worker.start(cc)
    inventory_worker.start(cc)
    unified_worker.start(cc)
    uniconfig_worker.start(cc)
    terraform_worker.start(cc)

    # block
    while 1:
        time.sleep(1)
def main():
    print('Starting Task Get Date Worker')
    conductor_host = os.getenv("CONDUCTOR_HOST", "http://localhost:8080")
    cc = ConductorWorker(conductor_host + '/api', 1, 5)

    cc.start('task_get_date', execute, True)
Exemple #16
0
    # Add(TestThing(), 'one')
    mc = MetadataClient('http://localhost:8080/api')

    unregister_default_tasks(mc)

    # Let's do this one.
    hp_task_def = define_as_task(HoverPower())
    mc.registerTaskDefs([hp_task_def])

    cp_task_def = define_as_task(CruisePower())
    mc.registerTaskDefs([cp_task_def])

    # Create workflow
    wf_def = define_workflow()
    mc.updateWorkflowDefs([wf_def])

    # Start workflow
    wc = WorkflowClient('http://localhost:8080/api')
    defaults = hp_task_def['inputTemplate']
    defaults.update(cp_task_def['inputTemplate'])
    wc.startWorkflow(wfName=wf_def['name'], inputjson=defaults)

    # Start workers
    cw = ConductorWorker('http://localhost:8080/api', 1, 0.1)
    cw.start(taskType=hp_task_def['name'],
             exec_function=run_hoverpower_component,
             wait=False)
    cw.start(taskType=cp_task_def['name'],
             exec_function=run_cruisepower_component,
             wait=True)
def main():
    log.info('connecting to conductor at {}'.format(conf.conductor))
    cc = ConductorWorker('http://mender-conductor:8080/api', 1, 0.1)

    cc.start('dummy', dummy, True)
Exemple #18
0
def main():
    print('Starting Task Collate Output Worker')
    conductor_host = os.getenv("CONDUCTOR_HOST", "http://localhost:8080")
    cc = ConductorWorker(conductor_host + '/api', 1, 5)

    cc.start('task_collate_output', execute, True)
Exemple #19
0
 def start(self, endpoint='http://localhost:8080/api', wait=False):
     cw = ConductorWorker(endpoint, 1, 0.1)
     cw.start(taskType=self.name, exec_function=self._run_task, wait=wait)
Exemple #20
0
def execute_b(task):
    print('exec b function')
    url = 'http://10.60.38.176:8080/b'
    res = requests.get(url)
    return {'status': 'COMPLETED', 'output': {'result': res.text}, 'logs': ['one', 'two']}


def execute_c(task):
    print('exec c function')
    url = 'http://10.60.38.176:8080/c'
    res = requests.get(url)
    return {'status': 'COMPLETED', 'output': {'result': res.text}, 'logs': ['one', 'two']}


def main():
    print('Starting tinadi-demo workflows')
    cc = ConductorWorker('http://202.120.167.198:8080/api', 1, 2)
    cc.start('tiandi_health_check_task', execute_health_check, False)
    cc.start('tiandi_a', execute_a, False)
    cc.start('tiandi_b', execute_b, False)
    cc.start('tiandi_c', execute_c, True)
cc = ConductorWorker('http://202.120.167.198:8080/api', 1, 2)

def task_handler(task,url, ):
    print('exec c function')
    res = requests.get(url)
    return {'status': 'COMPLETED', 'output': {'result': res.text}, 'logs': ['one', 'two']}
@http('/task/reg','POST')
def task_reg(name,parms):
    cc.start(NAME, task_handler,parms, False)
 def start(self, taskType, exec_function, wait, domain=None):
     # Random small sleep in order to NOT start all the workers at the same time
     time.sleep(randint(25, 100) * 0.001)
     ConductorWorker.start(self, taskType, exec_function, wait, domain)
Exemple #22
0
def main():
    print('Starting tinadi-demo workflows')
    cc = ConductorWorker('http://10.60.38.173:18080/api', 1, 2)
    cc.start('tiandi_code_task', execute_code, False)
    cc.start('tiandi_register_task', execute_register, False)
    cc.start('tiandi_deregister_task', execute_deregister, True)