from nepi.execution.attribute import Attribute, Flags, Types
from nepi.execution.trace import Trace, TraceAttr
from nepi.execution.resource import clsinit_copy, ResourceState, \
- ResourceAction
-from nepi.resources.linux.ccn.ccnapplication import LinuxCCNApplication
+ ResourceAction, reschedule_delay
+from nepi.resources.linux.application import LinuxApplication
from nepi.resources.linux.ccn.ccnd import LinuxCCND
from nepi.util.timefuncs import tnow
import os
@clsinit_copy
-class LinuxCCNR(LinuxCCNApplication):
+class LinuxCCNR(LinuxApplication):
_rtype = "LinuxCCNR"
@classmethod
"Sets the CCNS_SYNC_SCOPE environmental variable. ",
flags = Flags.ExecReadOnly)
+ repo_file = Attribute("repoFile1",
+ "The Repository uses $CCNR_DIRECTORY/repoFile1 for "
+ "persistent storage of CCN Content Objects",
+ flags = Flags.ExecReadOnly)
+
cls._register_attribute(max_fanout)
cls._register_attribute(max_leaf_entries)
cls._register_attribute(max_node_bytes)
cls._register_attribute(ccns_root_advise_lifetime)
cls._register_attribute(ccns_stable_enabled)
cls._register_attribute(ccns_sync_scope)
+ cls._register_attribute(repo_file)
@classmethod
def _register_traces(cls):
super(LinuxCCNR, self).__init__(ec, guid)
self._home = "ccnr-%s" % self.guid
- def deploy(self):
+ @property
+ def ccnd(self):
+ ccnd = self.get_connected(LinuxCCND.rtype())
+ if ccnd: return ccnd[0]
+ return None
+
+ @property
+ def node(self):
+ if self.ccnd: return self.ccnd.node
+ return None
+
+ def do_deploy(self):
if not self.ccnd or self.ccnd.state < ResourceState.READY:
self.debug("---- RESCHEDULING DEPLOY ---- CCND state %s " % self.ccnd.state )
- reschedule_delay = "0.5s"
# ccnr needs to wait until ccnd is deployed and running
self.ec.schedule(reschedule_delay, self.deploy)
else:
- command = self._start_command
- env = self._environment
+ if not self.get("command"):
+ self.set("command", self._start_command)
- self.set("command", command)
- self.set("env", env)
+ if not self.get("env"):
+ self.set("env", self._environment)
- self.info("Deploying command '%s' " % command)
-
- self.node.mkdir(self.app_home)
-
- # upload sources
- self.upload_sources()
+ command = self.get("command")
- # We want to make sure the repository is running
- # before the experiment starts.
- # Run the command as a bash script in background,
- # in the host ( but wait until the command has
- # finished to continue )
- env = self.replace_paths(env)
- command = self.replace_paths(command)
+ self.info("Deploying command '%s' " % command)
- self.node.run_and_wait(command, self.app_home,
- env = env,
- shfile = "app.sh",
- raise_on_error = True)
+ self.do_discover()
+ self.do_provision()
self.debug("----- READY ---- ")
- self._ready_time = tnow()
- self._state = ResourceState.READY
-
- def start(self):
- if self._state == ResourceState.READY:
+ self.set_ready()
+
+ def upload_start_command(self):
+ command = self.get("command")
+ env = self.get("env")
+
+ if self.get("repoFile1"):
+ # upload repoFile1
+ local_file = self.get("repoFile1")
+ remote_file = "${RUN_HOME}/repoFile1"
+ remote_file = self.replace_paths(remote_file)
+ self.node.upload(local_file,
+ remote_file,
+ overwrite = False)
+
+ # We want to make sure the repository is running
+ # before the experiment starts.
+ # Run the command as a bash script in background,
+ # in the host ( but wait until the command has
+ # finished to continue )
+ env = self.replace_paths(env)
+ command = self.replace_paths(command)
+
+ shfile = os.path.join(self.app_home, "start.sh")
+ self.node.run_and_wait(command, self.run_home,
+ shfile = shfile,
+ overwrite = False,
+ env = env,
+ raise_on_error = True)
+
+ def do_start(self):
+ if self.state == ResourceState.READY:
command = self.get("command")
self.info("Starting command '%s'" % command)
- self._start_time = tnow()
- self._state = ResourceState.STARTED
+ self.set_started()
else:
msg = " Failed to execute command '%s'" % command
self.error(msg, out, err)
- self._state = ResourceState.FAILED
raise RuntimeError, msg
@property
"ccnsSyncScope": "CCNS_SYNC_SCOPE",
})
- env = "PATH=$PATH:${EXP_HOME}/ccnx/bin "
+ env = self.ccnd.path
env += " ".join(map(lambda k: "%s=%s" % (envs.get(k), self.get(k)) \
if self.get(k) else "", envs.keys()))