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 destroy(self, destroy_pb, *args):
     log.info(" ".join(args))
     container_id = destroy_pb.container_id.value
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     state.await_launch()
     lk_d = state.lock("destroy", LOCK_EX)
     if state.exit() is None:
         Run()(deimos.docker.stop(state.cid()))
     else:
         log.info("Container is stopped")
     return 0
Example #4
0
 def destroy(self, destroy_pb, *args):
     log.info(" ".join(args))
     container_id = destroy_pb.container_id.value
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     state.await_launch()
     lk_d = state.lock("destroy", LOCK_EX)
     if state.exit() is None:
         Run()(deimos.docker.stop(state.cid()))
     else:
         log.info("Container is stopped")
     return 0
Example #5
0
 def observe(self, *args):
     log.info(" ".join(args))
     state = deimos.state.State(self.state_root, mesos_id=args[0])
     self.state = state
     deimos.sig.install(self.stop_docker_and_resume)
     state.await_launch()
     try:  # Take the wait lock to block calls to wait()
         state.lock("wait", LOCK_SH, seconds=None)
     except IOError as e:                       # Allows for signal recovery
         if e.errno != errno.EINTR:
             raise e
         state.lock("wait", LOCK_SH, seconds=1)
     if state.exit() is not None:
         return state.exit()
     raise Err("Wait lock is not held nor is exit file present")
Example #6
0
 def destroy(self, container_id, *args):
     log.info(" ".join([container_id] + list(args)))
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     state.await_launch()
     lk_d = state.lock("destroy", LOCK_EX)
     if state.exit() is not None:
         Run()(deimos.docker.stop(state.cid()))
     else:
         log.info("Container is stopped")
     if not sys.stdout.closed:
         # If we're called as part of the signal handler set up by launch,
         # STDOUT is probably closed already. Writing the Protobuf would
         # only result in a bevy of error messages.
         proto_out(protos.ExternalStatus, message="destroy: ok")
     return 0
Example #7
0
 def observe(self, *args):
     log.info(" ".join(args))
     state = deimos.state.State(self.state_root, mesos_id=args[0])
     self.state = state
     deimos.sig.install(self.stop_docker_and_resume)
     state.await_launch()
     try:  # Take the wait lock to block calls to wait()
         state.lock("wait", LOCK_SH, seconds=None)
     except IOError as e:  # Allows for signal recovery
         if e.errno != errno.EINTR:
             raise e
         state.lock("wait", LOCK_SH, seconds=1)
     if state.exit() is not None:
         return state.exit()
     raise Err("Wait lock is not held nor is exit file present")
Example #8
0
 def destroy(self, container_id, *args):
     log.info(" ".join([container_id] + list(args)))
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     state.await_launch()
     lk_d = state.lock("destroy", LOCK_EX)
     if state.exit() is not None:
         Run()(deimos.docker.stop(state.cid()))
     else:
         log.info("Container is stopped")
     if not sys.stdout.closed:
         # If we're called as part of the signal handler set up by launch,
         # STDOUT is probably closed already. Writing the Protobuf would
         # only result in a bevy of error messages.
         proto_out(protos.ExternalStatus, message="destroy: ok")
     return 0
Example #9
0
 def wait(self, *args):
     log.info(" ".join(list(args)))
     if list(args[0:1]) != ["--docker"]:
         return      # We rely on the Mesos default wait strategy in general
     # In Docker mode, we use Docker wait to wait for the container and
     # then exit with the returned exit code. The passed in ID should be a
     # Docker CID, not a Mesos container ID.
     state = deimos.state.State(self.state_root, docker_id=args[1])
     self.state = state
     deimos.sig.install(self.signal_docker_and_resume)
     state.await_launch()
     try:
         state.lock("wait", LOCK_SH, seconds=None)
     except IOError as e:                       # Allows for signal recovery
         if e.errno != errno.EINTR:
             raise e
         state.lock("wait", LOCK_SH, 1)
     if state.exit() is not None:
         return state.exit()
     raise Err("Wait lock is not held nor is exit file present")
Example #10
0
 def destroy(self, destroy_pb, *args):
     log.info(" ".join(args))
     container_id = destroy_pb.container_id.value
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     state.await_launch()
     lk_d = state.lock("destroy", LOCK_EX)
     if state.exit() is None:
         container_id = state.docker_id
         log.debug("Unwiring the container %s from MidoNet", container_id)
         try:
             log.info("state_root = %s", dir(state))
             midonet.unwire_container_from_midonet(container_id)
             log.debug("Successfully unwired the container %s from MidoNet " \
                       "bridge", container_id)
         except Exception as ex:
             log.error(traceback.format_exc())
         Run()(deimos.docker.stop(state.cid()))
     else:
         log.info("Container is stopped")
     return 0
Example #11
0
 def destroy(self, destroy_pb, *args):
     log.info(" ".join(args))
     container_id = destroy_pb.container_id.value
     state = deimos.state.State(self.state_root, mesos_id=container_id)
     state.await_launch()
     lk_d = state.lock("destroy", LOCK_EX)
     if state.exit() is None:
         container_id = state.docker_id
         log.debug("Unwiring the container %s from MidoNet", container_id)
         try:
             log.info("state_root = %s", dir(state))
             midonet.unwire_container_from_midonet(container_id)
             log.debug("Successfully unwired the container %s from MidoNet " \
                       "bridge", container_id)
         except Exception as ex:
             log.error(traceback.format_exc())
         Run()(deimos.docker.stop(state.cid()))
     else:
         log.info("Container is stopped")
     return 0
Example #12
0
 def wait(self, *args):
     log.info(" ".join(list(args)))
     if list(args[0:1]) != ["--docker"]:
         return  # We rely on the Mesos default wait strategy in general
     # In Docker mode, we use Docker wait to wait for the container and
     # then exit with the returned exit code. The passed in ID should be a
     # Docker CID, not a Mesos container ID.
     state = deimos.state.State(self.state_root, docker_id=args[1])
     self.state = state
     deimos.sig.install(self.stop_docker_and_resume)
     state.await_launch()
     try:
         state.lock("wait", LOCK_SH, seconds=None)
     except IOError as e:  # Allows for signal recovery
         if e.errno != errno.EINTR:
             raise e
         state.lock("wait", LOCK_SH, 1)
     if state.exit() is not None:
         return state.exit()
     raise Err("Wait lock is not held nor is exit file present")
Example #13
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 #14
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 #15
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")