Horizontal Navigation Bar |
---|
Button Group |
---|
Button Hyperlink |
---|
title | Previous |
---|
type | standard |
---|
url | https://confluence.ecmwf.int/display/ECFLOW/Going+Further |
---|
|
Button Hyperlink |
---|
title | Up |
---|
type | standard |
---|
url | https://confluence.ecmwf.int/display/ECFLOW/Going+Further |
---|
|
Button Hyperlink |
---|
title | Next |
---|
type | standard |
---|
url | https://confluence.ecmwf.int/display/ECFLOW/Families |
---|
|
|
|
Let’s add another task named t2.You must also create a file t2.ecf in $HOME/course/test
. Simply copy t1.ecf
.
First, modify the suite definition
Text
It is good practice to suspend your suite before you reload any part of it.
In ecflow_ui right click on the suite and select “Suspend”. Once you made your change(specified below) you can right-click on the suite and “Resume” it.
...
Definition of the suite test
suite test
edit ECF_HOME "$HOME/course" |
...
...
# replace '$HOME' with the |
...
path to your home directory |
...
...
...
...
...
...
...
...
...
Note |
---|
As before replace $HOME with the real path to your home directory. |
Then you must load the file again:
Code Block |
---|
|
ecflow_client --load |
...
...
Warning |
---|
This will fail because the suite is already loaded |
Because the suite is already defined, you need to delete and reload it first:
Code Block |
---|
|
ecflow_client --delete=_all_
|
...
ecflow_client --load=test. |
...
Then restart the suite:
Code Block |
---|
|
ecflow_client --begin= |
...
Rather than deleting, loading and beginning the suite every time you can replace
all or part of the suite for example to replace whole suite.
Code Block |
---|
|
ecflow_client --replace=/test test.def |
or to replace part of the suite:
Code Block |
---|
|
ecflow_client --replace=/test/t2 test.def |
Python
To delete the suite definition, reload and begin using the Client Server API: First update test.py to add task t2
Code Block |
---|
language | py |
---|
title | $HOME/course/test.py |
---|
|
import os
from ecflow import Defs,Suite,Task,Edit
print("Creating suite definition")
home = os.path.join(os.getenv("HOME"), "course")
defs = Defs(
Suite('test',
Edit(ECF_HOME=home),
Task('t1'),
Task('t2')))
print(defs)
print("Checking job creation: .ecf -> .job0")
print(defs.check_job_creation())
print("Saving definition to file 'test.def'")
defs.save_as_defs("test.def") |
To delete all suites in the server and reload the modified test.def, we could update client.py
Code Block |
---|
language | py |
---|
title | $HOME/course/client.py |
---|
|
import ecflow
print("Client -> Server: delete, then load a new definition")
try:
ci = ecflow.Client()
ci.delete_all() |
...
...
...
...
# load the definition into the |
...
...
...
start the suite
except RuntimeError as e:
print("Failed:", e)
|
Rather than deleting, loading, and beginning the suite every time you can replace
all or part of the suite. (i.e. to replace the whole suite see below)
Additionally, we do not want the suite to start straight away. This can be done
by suspending the suite in ecflow_ui before reloading. However, we will need to remember to do this, each time. To get around this we will
Code Block |
---|
language | py |
---|
title | $HOME/course/client.py |
---|
|
import ecflow
print("Client -> Server: replacing suite '/test' in the server, with a new definition")
try:
ci = ecflow.Client()
ci.suspend("/test") # so that we can resume manually in ecflow_ui
ci.replace("/test", "test.def") # replace suite /test with suite of same name in test.def
except RuntimeError as e:
print("Failed:", e) |
Note |
---|
For brevity the examples that follow, will not show the loading of the suite. |
What to do
- Suspend the suite using ecflow_ui or via python by modifying your client.py to add ecflow.Client.suspend
- Create a new task
- Create t2.ecf by copying from t1.ecf
- Update python scripts test.py and client.py or test.def
- Replace the suite
python: python3 test.py | ./test.py
python3 client.py | ./client.py
text: ecflow_client --replace=/test test.def - Resume the suite using ecflow_ui
- In ecflow_ui watch the two tasks running. They should run at the same time
Horizontal Navigation Bar |
---|
Button Group |
---|
Button Hyperlink |
---|
title | Previous |
---|
type | standard |
---|
url | https://confluence.ecmwf.int/display/ECFLOW/Going+Further |
---|
|
Button Hyperlink |
---|
title | Up |
---|
type | standard |
---|
url | https://confluence.ecmwf.int/display/ECFLOW/Going+Further |
---|
|
Button Hyperlink |
---|
title | Next |
---|
type | standard |
---|
url | https://confluence.ecmwf.int/display/ECFLOW/Families |
---|
|
| <span class="k">print</span> <span class="s">"failed: "</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
</pre></div>
</div>
<div class="line-block">
<div class="line">Rather than deleting, loading and beginning the suite every time you can replace</div>
<div class="line">all or part of the suite for example to replace whole suite.</div>
</div>
<div class="highlight-python"><pre>> ecf_client --replace /test test.def</pre>
</div>
<p>or to replace part of the suite:</p>
<div class="highlight-python"><pre>> ecf_client --replace /test/t2 test.def</pre>
</div>
<p>In python this would be:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="c">#!/usr/bin/env python2.5</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">ecflow</span>
<span class="n">defs</span> <span class="o">=</span> <span class="n">ecflow</span><span class="o">.</span><span class="n">Defs</span><span class="p">(</span><span class="s">"test.def"</span><span class="p">)</span>
<span class="n">suite</span> <span class="o">=</span> <span class="n">defs</span><span class="o">.</span><span class="n">add_suite</span><span class="p">(</span><span class="s">"test"</span><span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_variable</span><span class="p">(</span><span class="s">"ECF_HOME"</span><span class="p">,</span><span class="n">os</span><span class="o">.</span><span class="n">getenv</span><span class="p">(</span><span class="s">"HOME"</span><span class="p">)</span> <span class="o">+</span> <span class="s">"/course"</span><span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t1"</span><span class="p">)</span>
<span class="n">suite</span><span class="o">.</span><span class="n">add_task</span><span class="p">(</span><span class="s">"t2"</span><span class="p">)</span>
<span class="c"># replace suite /test in the server, with the definition provided in defs</span>
<span class="n">ci</span> <span class="o">=</span> <span class="n">ecflow</span><span class="o">.</span><span class="n">Client</span><span class="p">();</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">ci</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="s">"/test"</span><span class="p">,</span><span class="n">defs</span><span class="p">)</span>
<span class="k">except</span> <span class="ne">RuntimeError</span><span class="p">,</span> <span class="n">e</span><span class="p">:</span>
<span class="k">print</span> <span class="s">"failed: "</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
</pre></div>
</div>
<div class="line-block">
<div class="line">It is good practice to suspend your suite before you reload any part of it.</div>
<div class="line">In <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflowview"><em class="xref std std-term">ecFlowview</em></a> right click on the suite and select “Suspend”.</div>
<div class="line">Once you made your change you can right click on the suite and “Resume” it.</div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">For <strong>brevity</strong> the following examples, will not show the loading of the suite.</p>
</div>
<p>What to do:</p>
<ol class="arabic simple">
<li>Create the new task</li>
<li>Create <tt class="file docutils literal"><span class="pre">t2.ecf</span></tt> by copying from <tt class="file docutils literal"><span class="pre">t1.ecf</span></tt></li>
<li>Begin the suite</li>
<li>In <a class="reference internal" href="/wiki/display/ECFLOW/Glossary#term-ecflowview"><em class="xref std std-term">ecFlowview</em></a>, watch the two task running. They should run at the same time</li>
</ol>
</div>
|