Пример #1
0
def family_limit():
    """ example """
    return (
        Family("limits").add(
            Limits({"total": 15,
                    "prio": 10,
                    "other": 20}),  # use dictionnary
            Defstatus("complete")),
        Limit("record", 50),  # record active/submit tasks
        Inlimit("record"),
        Limit("total", 2),  # limiter

        Family("limit").add(
            Defstatus("complete"),
            Family("prio").add(  # on top: submitted first
                Inlimit("../limits:prio"),

                [Family("%03d" % step).add(
                    Task("process"), Variables(STEP=step))
                 for step in range(0, 120 + 1, 3)]),

            Family("side").add(  # below: take remaining tokens
                Inlimit("../limits:other"),
                [Family("%03d" % step).add(
                    Task("process"), Variables(STEP=step))
                 for step in range(0, 120, 3)])))
Пример #2
0
def family_limiter():
    """ alternative example """
    return (
        Family("limiter").add(
            Limit("total", 10),
            Inlimit("total"),

            Task("alarm").add(
                Complete("limits eq complete"),
                Trigger("../limiter:total gt 8")),  # relative path

            Family("limits").add(
                Defstatus("complete"),

            Family("weaker").add(  # weaker is located above, not to be shadowed
                Trigger("../limiter:total le 10"),
                [Family("%03d" % step).add(
                    Task("process"), Variables(STEP=step))
                 for step in range(0, 120, 3)]),

            Family("prio").add(  # favourite shall not lead weaker to starve
                Trigger("../limiter:total le 15"),
                [Family("%03d" % step).add(
                    Task("process"), Variables(STEP=step))
                 for step in range(0, 120, 3)]))))
def create_families():
    """ provider """
    return (Family("f4").add(
        Variables(SLEEP=2),
        Repeat("NAME", ["a", "b", "c", "d", "e", "f"], kind="enumerated"),
        Task("t1")), Family("f5").add(
            Repeat("DATE", 20170101, 20200105, kind="date"),
            Task("t1").add(Repeat("PARAM", 1, 10, kind="integer"),
                           Label("info", ""))))
Пример #4
0
def family_for():
    """ for family """
    return (
        Family("for").add(
            process(),
            Repeat(kind="integer", name="STEP", start=1, end=240, step=3)),
        Family("loop").add(process(), Repeat("PARAM", PARAMS, kind="string")),
        Family("parallel").add(Limit("lim", 2), Inlimit("lim"), [
            Family(param).add(Variables(PARAM=param),
                              process().add(Label("info", param)))
            for param in PARAMS
        ]),
        Family("explode").add(
            Limit("lim", 2),
            Inlimit("lim"),
            # LIST COMPREHENSION:
            [Task("t%d" % num) for num in xrange(1, 5 + 1)]))
Пример #5
0
def model(fclen=240, name="model", dependencies="acquisition"):  # leaf task
    deploy("""# task wrapper, turned into a job by ecFlow
%manual
  useful information for Operators...
%end
%comment
# comment, ... ecflow_ui Edit
%end
%nopp
# no preprocessing here
%end
ID=%ID:-1%  # model id, default value -1, -1: HRES, 0: CF, N: PF
ecflow_client --event 1  # ecflow hook: send an event
for i in $(seq 0 %FCLENGTH:240%); do  # variable with default value
  sleep %SLEEP:0%; ecflow_client --meter step $i  # share progress with ecFlow
done
ecflow_client --label info "OK"  # report a label to ecFlow""", files + name + extn)
    return Task(name).add(  # HRES
        Trigger(dependencies + " eq complete"),
        Variables(FCLENGTH=fclen),  # python variable to suite variable
        Meter("step", -1, fclen),
        Label("info", ""))
Пример #6
0
#!/usr/bin/env python2.7
""" back archive example """
from __future__ import print_function
import os
import ecf as ecflow
from ecf import (Defs, Defstatus, Suite, Family, Task, Variables, Label,
                 Limit, Inlimit, Repeat, Trigger)
HOME = os.getenv("HOME") + "/ecflow_server"
NAME = "back_archiving"; FILES = HOME + "/back"; DEFS = Defs()
DEFS.add(Suite(NAME).add(
    Defstatus("suspended"),  # so that jobs do not start immediately
    Repeat(kind="day", step=1),
    Variables(ECF_HOME=HOME, ECF_INCLUDE=HOME, ECF_FILES=FILES, SLEEP=2),
    Limit("access", 2),
    [Family(kind).add(
        Repeat("DATE", 19900101, 19950712, kind="date"),
        Variables(KIND=kind),
        Task("get_old").add(Inlimit("access"), Label("info", "")),
        Task("convert").add(Trigger("get_old == complete")),
        Task("save_new").add(Trigger("convert eq complete"))
    ) for kind in ("analysis", "forecast", "climatology", "observations", "images")]))
# print(DEFS); DEFS.generate_scripts(); 
RESULT = DEFS.simulate(); print(RESULT)
CLIENT = ecflow.Client(os.getenv("ECF_HOST", "localhost"),
                       os.getenv("ECF_PORT", 2500))
CLIENT.replace("/%s" % NAME, DEFS)
Пример #7
0
            Variables(SLEEP=2),
            Repeat("NAME", ["a", "b", "c", "d", "e", "f"], kind="enumerated"),
            Task("t1")),
        Family("f5").add(
            Repeat("DATE", 20170101, 20200105, kind="date"),
            Task("t1").add(
                Repeat("PARAM", 1, 10, kind="integer"),
                Label("info", ""))))


DEFS.add(  # suite definition
    Suite(NAME).add(
        Defstatus("suspended"),  # so that jobs do not start immediately
        Variables(  # we can add multiple variables at once
            ECF_HOME=ECF_HOME,  # where job files are created by ecflow
            ECF_FILES=ECF_HOME + "/files",  # where to find script templates
            ECF_INCLUDE=ECF_HOME + "/include",  # where to find head.h tail.h
            SLEEP=2),
        create_families()))

SCRIPT_TEMPLATE = """#!/bin/bash
%include <head.h>
STEP=0
while [[ $STEP -le 240 ]] ; do
  sleep %SLEEP:1%; ecflow_client --meter step $STEP  # share progress
  msg="The date is %DATE:$(date)%. PARAM is %PARAM:% NAME is %NAME:%"
  ecflow_client --label info "$msg"
  (( STEP = STEP + 1))
done
%include <tail.h>
"""
#!/usr/bin/env python
from __future__ import print_function
import os
import ecf as ecflow
from ecf import (Defstatus, Suite, Family, Task, Variables)
print("Creating suite definition")
ECF_HOME = os.path.join(os.getenv("HOME"), "ecflow_server")
NAME = os.getenv("SUITE", "elearning")
DEFS = ecflow.Defs()
DEFS.add(  # suite definition
    Suite(NAME).add(
        Defstatus("suspended"),  # so that jobs do not start immediately
        Variables(ECF_HOME=ECF_HOME,
                  ECF_FILES=ECF_HOME + "/files",
                  ECF_INCLUDE=ECF_HOME + "/include"),
        Family("f1").add(  # hosting family
            Task("t1"),  # a first task
            Task("t2"),  # a second task
        )))

if __name__ == '__main__':
    HOST = os.getenv("ECF_HOST", "localhost")
    PORT = int(os.getenv("ECF_PORT", "%d" % (1500 + os.getuid())))
    CLIENT = ecflow.Client(HOST, PORT)

    NODE = "/" + NAME  # replace suite node: add f1, delete t1 t2
    CLIENT.replace(NODE, DEFS)
    print("replaced node %s into" % NODE, HOST, PORT)
#!/usr/bin/env python
from __future__ import print_function
import os
import ecf as ecflow
from ecf import (Defstatus, Suite, Family, Task, Variables, Trigger)
TASK3 = Task("t3")  # a python object can be set, and added later to the suite
ECF_HOME = os.path.join(os.getenv("HOME"), "ecflow_server")
NAME = os.getenv("SUITE", "elearning")
DEFS = ecflow.Defs()
DEFS.add(  # suite definition
    Suite(NAME).add(
        Defstatus("suspended"),  # so that jobs do not start immediately
        Variables(
            ECF_HOME=ECF_HOME,  # where job files are created by ecflow
            ECF_FILES=ECF_HOME + "/files",      # where to find script template
            ECF_INCLUDE=ECF_HOME + "/include",  # where to find head.h tail.h
            SLEEP=1, ),
        Family("f1").add(
            Task("t1").add(Variables(SLEEP=5)),
            Task("t2").add(Variables(SLEEP=7),
                           Trigger("t1 eq complete")),
            TASK3,
            Task("t4").add(Trigger(["t1", "t2"])))))

SCRIPT_TEMPLATE = """#!/bin/bash
%include <head.h>
echo "I will now sleep for %SLEEP:1% seconds"; sleep %SLEEP:1%
%include <tail.h>
"""

if __name__ == '__main__':
Пример #10
0
        print(script, file=destination)
        print("#MSG: created", pathname)


#####################################################################
# suite definition
acq = "acquisition"
deploy("echo acq %TASK%", files + acq + extn)  # create wrapper
post = "postproc"
deploy("ecflow_client --label info %TASK%", files + post + extn)
suite = Suite("course").add(
    Defstatus("suspended"),
    Repeat("YMD", 20180101, 20321212, kind="date"),
    Variables(ECF_HOME=home,  # jobs files are created there by ecflow
              ECF_FILES=home + "/files",  # task-wrappers location
              ECF_INCLUDE=home + "/include",  # include files location
              # ECF_OUT=home,  # output files location on remote systems, 
                               # no directory created there by ecflow...
              ECF_EXTN=extn, ),  # task wrapper extension
    Task(acq).add(Event(1)),
    Family("ensemble").add(  # ENS
        Complete(acq + ":1"),
        [Family("%02d" % num).add(
            Variables(ID=num),
            model(360, dependencies="../../" + acq))  # relative path...
         for num in xrange(0, 10)]),
    model(240, dependencies=acq),  # HRES
    Task(post).add(
        Trigger("model eq complete"),
        Label("info", "")))

Пример #11
0
def create_family_f5():
    return Family("f5").add(Limit(
        "l1", 2), Inlimit("l1"), Variables(SLEEP=2), [
            Task("t%d" % idn).add(Late("-s 00:03 -a 00:10"))
            for idn in xrange(1, 10)
        ])
Пример #12
0
#!/usr/bin/env python
from __future__ import print_function
import os
import ecf as ecflow
from ecf import (Defstatus, Suite, Task, Variables)
ECF_HOME = os.path.join(os.getenv("HOME"), "ecflow_server")
ECF_FILES = ECF_HOME + "/files"
NAME = os.getenv("SUITE", "elearning")
DEFS = ecflow.Defs()
DEFS.add(  # suite definition
    Suite(NAME).add(
        Defstatus("suspended"),  # so that jobs do not start immediately
        Variables(  # we can add multiple variables at once
            ECF_HOME=ECF_HOME,  # where job files are created by ecflow
            ECF_FILES=ECF_FILES,  # where to find script templates .ecf
            ECF_INCLUDE=ECF_HOME + "/include",  # where to find head.h tail.h
            SLEEP=1,  # user variable to be inherited by task/families below
        ),
        Task("t1").add(
            Variables(SLEEP=5),  # overwriting with value 5 for task t1
        ),
        Task("t2").add(
            Variables(SLEEP=7),  # overwriting with value 7 for task t2
        )))

SCRIPT_TEMPLATE = """#!/bin/bash
%include <head.h>
echo "I will now sleep for %SLEEP:1% seconds"
sleep %SLEEP:1%
%include <tail.h>
"""
Пример #13
0
NAME = "operational_suite"


def cycle_trigger(cyc):
    if cyc == "12":
        return Trigger("./00==complete")
    return None


DEFS = Defs()
DEFS.add(
    Suite(NAME).add(
        Defstatus("suspended"),  # so that jobs do not start immediately
        Repeat(kind="day", step=1),
        Variables(ECF_HOME=HOME,
                  ECF_INCLUDE=HOME + "/include",
                  ECF_FILES=HOME + "/files"),
        [
            Family(str(cycle)).add(
                Variables(CYCLE=cycle, LAST_STEP=LAST_STEP[cycle]),
                cycle_trigger(cycle),
                Family("analysis").add(
                    Task("get_observations"),
                    Task("run_analysis").add(Trigger([
                        "get_observations",
                    ])),
                    Task("post_processing").add(Trigger([
                        "run_analysis",
                    ]))),
                Family("forecast").add(
                    Trigger("analysis == complete"),
Пример #14
0
def create_family_f5():
    """ provider """
    return Family("f5").add(Limit("l1", 2), Inlimit("l1"), Variables(SLEEP=2),
                            [Task("t%d" % tid) for tid in range(1, 10)])
Пример #15
0
""" a first suite """
# from __future__ import print_function
import os, sys
if 0: # try:
    from ecf import (Defs, Suite, Defstatus, Variables, Task)
else: # except ImportError, err:
    INST = "/usr/local/apps/ecflow/lib/python2.7/site-packages/ecflow:"
    sys.path.append(INST)
    INST = "/usr/local/lib/python2.7/site-packages/ecflow"
    sys.path.append(INST)
    from ecf import (Defs, Suite, Defstatus, Variables, Task)
    if 0: raise Exception(#ERR: could not import ecf. Does the following line help?"+
        "\nexport PYTHONPATH=$PYTHONPATH:%s" % INST)

print("Creating suite definition")
ECF_HOME = os.path.join(os.getenv("HOME"), "ecflow_server")
NAME = os.getenv("SUITE", "elearning")
DEFS = Defs()
DEFS.add(
    Suite(NAME).add(  # simplest suite definition
        Defstatus("suspended"),  # so that jobs do not start immediately
        Variables(ECF_HOME=ECF_HOME,  # where to find jobs + output files
                  ECF_FILES=ECF_HOME + "/files",  # script template .ecf
                  ECF_INCLUDE=ECF_HOME + "/include"),  # include files .h
        Task("t1")))  # a first task

if __name__ == '__main__':
    print(DEFS)
    print("Saving definition to file '%s.def'" % NAME)
    DEFS.save_as_defs(ECF_HOME+"%s.def" % NAME)  # an external client can use it