Example #1
0
 def usage(self, usage_pb, *args):
     log.info(" ".join(args))
     container_id = usage_pb.container_id.value
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     state.await_launch()
     state.ids()
     if state.cid() is None:
         log.info("Container not started?")
         return 0
     if state.exit() is not None:
         log.info("Container is stopped")
         return 0
     cg = deimos.cgroups.CGroups(**deimos.docker.cgroups(state.cid()))
     if len(cg.keys()) == 0:
         log.info("Container has no CGroups...already stopped?")
         return 0
     try:
         recordio.write(ResourceStatistics,
                        timestamp=time.time(),
                        mem_limit_bytes=cg.memory.limit(),
                        cpus_limit=cg.cpu.limit(),
                        # cpus_user_time_secs   = cg.cpuacct.user_time(),
                        # cpus_system_time_secs = cg.cpuacct.system_time(),
                        mem_rss_bytes=cg.memory.rss())
     except AttributeError as e:
         log.error("Missing CGroup!")
         raise e
     return 0
Example #2
0
 def usage(self, usage_pb, *args):
     log.info(" ".join(args))
     container_id = usage_pb.container_id.value
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     state.await_launch()
     state.ids()
     if state.cid() is None:
         log.info("Container not started?")
         return 0
     if state.exit() is not None:
         log.info("Container is stopped")
         return 0
     cg = deimos.cgroups.CGroups(**deimos.docker.cgroups(state.cid()))
     if len(cg.keys()) == 0:
         log.info("Container has no CGroups...already stopped?")
         return 0
     try:
         recordio.write(
             ResourceStatistics,
             timestamp=time.time(),
             mem_limit_bytes=cg.memory.limit(),
             cpus_limit=cg.cpu.limit(),
             # cpus_user_time_secs   = cg.cpuacct.user_time(),
             # cpus_system_time_secs = cg.cpuacct.system_time(),
             mem_rss_bytes=cg.memory.rss())
     except AttributeError as e:
         log.error("Missing CGroup!")
         raise e
     return 0
Example #3
0
 def wait(self, wait_pb, *args):
     log.info(" ".join(args))
     container_id = wait_pb.container_id.value
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     self.state = state
     deimos.sig.install(self.stop_docker_and_resume)
     state.await_launch()
     try:  # Wait for the observe lock so observe completes first
         state.lock("observe", LOCK_SH, seconds=None)
         state.lock("wait", LOCK_SH, seconds=None)
     except IOError as e:                       # Allows for signal recovery
         if e.errno != errno.EINTR:
             raise e
         state.lock("observe", LOCK_SH, seconds=1)
         state.lock("wait", LOCK_SH, seconds=1)
     termination = (state.exit() if state.exit() is not None else 64) << 8
     recordio.write(Termination,
                    killed=False,
                    message="",
                    status=termination)
     if state.exit() is not None:
         return state.exit()
     raise Err("Wait lock is not held nor is exit file present")
Example #4
0
 def wait(self, wait_pb, *args):
     log.info(" ".join(args))
     container_id = wait_pb.container_id.value
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     self.state = state
     deimos.sig.install(self.stop_docker_and_resume)
     state.await_launch()
     try:  # Wait for the observe lock so observe completes first
         state.lock("observe", LOCK_SH, seconds=None)
         state.lock("wait", LOCK_SH, seconds=None)
     except IOError as e:  # Allows for signal recovery
         if e.errno != errno.EINTR:
             raise e
         state.lock("observe", LOCK_SH, seconds=1)
         state.lock("wait", LOCK_SH, seconds=1)
     termination = (state.exit() if state.exit() is not None else 64) << 8
     recordio.write(Termination,
                    killed=False,
                    message="",
                    status=termination)
     if state.exit() is not None:
         return state.exit()
     raise Err("Wait lock is not held nor is exit file present")
Example #5
0
 def wait(self, *args):
     log.info(" ".join(args))
     observe = False
     # NB: The "@@observe-docker@@" variant is a work around for Mesos's
     #     option parser. There is a fix in the pipeline.
     if list(args[0:1]) in [ ["--observe-docker"], ["@@observe-docker@@"] ]:
         # In Docker mode, we use Docker wait to wait for the container
         # and then exit with the returned exit code. The Docker CID is
         # passed on the command line.
         state = deimos.state.State(self.state_root, docker_id=args[1])
         observe = True
     else:
         message = recordio.read(Wait)
         container_id = message.container_id.value
         state = deimos.state.State(self.state_root, mesos_id=container_id)
     self.state = state
     deimos.sig.install(self.stop_docker_and_resume)
     state.await_launch()
     try:
         if not observe:
             state.lock("observe", LOCK_SH, seconds=None)
         state.lock("wait", LOCK_SH, seconds=None)
     except IOError as e:                       # Allows for signal recovery
         if e.errno != errno.EINTR:
             raise e
         if not observe:
             state.lock("observe", LOCK_SH, seconds=1)
         state.lock("wait", LOCK_SH, seconds=1)
     termination = (state.exit() if state.exit() is not None else 64) << 8
     recordio.write(Termination,
                    killed  = False,
                    message = "",
                    status  = termination)
     if state.exit() is not None:
         return state.exit()
     raise Err("Wait lock is not held nor is exit file present")