Various small fixes to Linux CCN RMs
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 23 Jul 2013 23:36:39 +0000 (16:36 -0700)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 23 Jul 2013 23:36:39 +0000 (16:36 -0700)
src/nepi/resources/all/collector.py
src/nepi/resources/linux/application.py
src/nepi/resources/linux/ccn/ccncontent.py
src/nepi/resources/linux/ccn/ccnr.py
src/nepi/resources/linux/ccn/fibentry.py
src/nepi/resources/linux/traceroute.py

index 61efa22..6101cdd 100644 (file)
@@ -118,9 +118,15 @@ class Collector(ResourceManager):
             result = self.ec.trace(rm.guid, trace_name)
             fpath = os.path.join(self.store_path, "%d.%s" % (rm.guid, 
                 rename))
-            f = open(fpath, "w")
-            f.write(result)
-            f.close()
+            try:
+                f = open(fpath, "w")
+                f.write(result)
+                f.close()
+            except:
+                msg = "Couldn't retrieve trace %s for %d at %s " % (trace_name, 
+                        rm.guid, fpath)
+                self.error(msg)
+                continue
 
         super(Collector, self).release()
 
index e874bcf..380470c 100644 (file)
@@ -585,14 +585,13 @@ class LinuxApplication(ResourceManager):
 
         if self.state == ResourceState.STARTED:
         
-            stopped = True
-
             self.info("Stopping command '%s'" % command)
         
             # If the command is running in foreground (it was launched using
             # the node 'execute' method), then we use the handler to the Popen
             # process to kill it. Else we send a kill signal using the pid and ppid
             # retrieved after running the command with the node 'run' method
+            stopped = True
 
             if self._proc:
                 self._proc.kill()
@@ -608,10 +607,9 @@ class LinuxApplication(ResourceManager):
                         msg = " Failed to STOP command '%s' " % self.get("command")
                         self.error(msg, out, err)
                         self.fail()
-                        stopped = False
 
-            if stopped:
-                super(LinuxApplication, self).stop()
+        if self.state == ResourceState.STARTED:
+            super(LinuxApplication, self).stop()
 
     def release(self):
         self.info("Releasing resource")
@@ -623,6 +621,8 @@ class LinuxApplication(ResourceManager):
         self.stop()
 
         if self.state == ResourceState.STOPPED:
+            self.info("Resource released")
+
             super(LinuxApplication, self).release()
     
     @property
index 35d1563..9d531de 100644 (file)
@@ -108,25 +108,24 @@ class LinuxCCNContent(LinuxApplication):
         command = self.get("command")
         env = self.get("env")
 
-        if command:
-            self.info("Uploading command '%s'" % command)
-
-            # We want to make sure the content is published
-            # before the experiment starts.
-            # Run the command as a bash script in the background, 
-            # in the host ( but wait until the command has
-            # finished to continue )
-            env = self.replace_paths(env)
-            command = self.replace_paths(command)
-
-            (out, err), proc = self.execute_command(command, env, 
-                    blocking = True)
-
-            if proc.poll():
-                self.fail()
-                msg = "Failed to execute command"
-                self.error(msg, out, err)
-                raise RuntimeError, msg
+        self.info("Uploading command '%s'" % command)
+
+        # We want to make sure the content is published
+        # before the experiment starts.
+        # Run the command as a bash script in the background, 
+        # in the host ( but wait until the command has
+        # finished to continue )
+        env = self.replace_paths(env)
+        command = self.replace_paths(command)
+
+        (out, err), proc = self.execute_command(command, env, 
+                blocking = True)
+
+        if proc.poll():
+            self.fail()
+            msg = "Failed to execute command"
+            self.error(msg, out, err)
+            raise RuntimeError, msg
 
     def start(self):
         if self._state == ResourceState.READY:
index 7ed260c..ac10840 100644 (file)
@@ -146,6 +146,11 @@ class LinuxCCNR(LinuxApplication):
             "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)
@@ -172,6 +177,7 @@ class LinuxCCNR(LinuxApplication):
         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):
@@ -226,22 +232,30 @@ class LinuxCCNR(LinuxApplication):
         command = self.get("command")
         env = self.get("env")
 
-        if 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)
-
-            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)
+        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 start(self):
         if self._state == ResourceState.READY:
             command = self.get("command")
index 0e4a687..fe0330e 100644 (file)
@@ -134,22 +134,21 @@ class LinuxFIBEntry(LinuxApplication):
         command = self.get("command")
         env = self.get("env")
 
-        if command:
-            # We want to make sure the FIB entries are created
-            # before the experiment starts.
-            # Run the command as a bash script in the background, 
-            # in the host ( but wait until the command has
-            # finished to continue )
-            env = env and self.replace_paths(env)
-            command = self.replace_paths(command)
+        # We want to make sure the FIB entries are created
+        # before the experiment starts.
+        # Run the command as a bash script in the background, 
+        # in the host ( but wait until the command has
+        # finished to continue )
+        env = env and self.replace_paths(env)
+        command = self.replace_paths(command)
 
-            (out, err), proc = self.execute_command(command, env)
+        (out, err), proc = self.execute_command(command, env)
 
-            if proc.poll():
-                self._state = ResourceState.FAILED
-                msg = "Failed to execute command"
-                self.error(msg, out, err)
-                raise RuntimeError, msg
+        if proc.poll():
+            self._state = ResourceState.FAILED
+            msg = "Failed to execute command"
+            self.error(msg, out, err)
+            raise RuntimeError, msg
 
     def configure(self):
         if self.trace_enabled("ping"):
@@ -158,9 +157,6 @@ class LinuxFIBEntry(LinuxApplication):
             self.ec.set(self._ping, "printTimestamp", True)
             self.ec.set(self._ping, "target", self.get("host"))
             self.ec.register_connection(self._ping, self.node.guid)
-            # force waiting until ping is READY before we starting the FIB
-            self.ec.register_condition(self.guid, ResourceAction.START, 
-                    self._ping, ResourceState.READY)
             # schedule ping deploy
             self.ec.deploy(group=[self._ping])
 
@@ -172,9 +168,6 @@ class LinuxFIBEntry(LinuxApplication):
             self.ec.set(self._mtr, "continuous", True)
             self.ec.set(self._mtr, "target", self.get("host"))
             self.ec.register_connection(self._mtr, self.node.guid)
-            # force waiting until mtr is READY before we starting the FIB
-            self.ec.register_condition(self.guid, ResourceAction.START, 
-                    self._mtr, ResourceState.READY)
             # schedule mtr deploy
             self.ec.deploy(group=[self._mtr])
 
@@ -185,9 +178,6 @@ class LinuxFIBEntry(LinuxApplication):
             self.ec.set(self._traceroute, "continuous", True)
             self.ec.set(self._traceroute, "target", self.get("host"))
             self.ec.register_connection(self._traceroute, self.node.guid)
-            # force waiting until mtr is READY before we starting the FIB
-            self.ec.register_condition(self.guid, ResourceAction.START, 
-                    self._traceroute, ResourceState.READY)
             # schedule mtr deploy
             self.ec.deploy(group=[self._traceroute])
 
index ea42514..4d55eb1 100644 (file)
@@ -73,7 +73,7 @@ class LinuxTraceroute(LinuxApplication):
         args.append("traceroute")
         args.append(self.get("target"))
         if self.get("continuous") == True:
-            args.append("; sleep 5 ; done ")
+            args.append("; sleep 2 ; done ")
 
         command = " ".join(args)