Пример #1
0
    def start_framework(master_uri, exe_path, n_workers, uow_name, prefix,
                        cpu_alloc, mem_alloc):
        # initialize an executor
        executor = mesos_pb2.ExecutorInfo()
        executor.executor_id.value = uuid1().hex
        executor.command.value = exe_path
        executor.name = "Exelixi Executor"
        executor.source = "per-job build"

        ## NB: TODO download tarball/container from HDFS
        #uri = executor.command.uris.add()
        #uri.executable = false
        #uri.value = "hdfs://namenode/exelixi/exelixi.tgz"

        # initialize the framework
        framework = mesos_pb2.FrameworkInfo()
        framework.user = ""  # have Mesos fill in the current user
        framework.name = "Exelixi Framework"

        if os.getenv("MESOS_CHECKPOINT"):
            logging.debug(
                "Mesos Scheduler: enabling checkpoint for the framework")
            framework.checkpoint = True

        # create a scheduler and capture the command line options
        sched = MesosScheduler(executor, exe_path, n_workers, uow_name, prefix,
                               cpu_alloc, mem_alloc)

        # initialize a driver
        if os.getenv("MESOS_AUTHENTICATE"):
            logging.debug(
                "Mesos Scheduler: enabling authentication for the framework")

            if not os.getenv("DEFAULT_PRINCIPAL"):
                logging.critical(
                    "Mesos Scheduler: expecting authentication principal in the environment"
                )
                sys.exit(1)

            if not os.getenv("DEFAULT_SECRET"):
                logging.critical(
                    "Mesos Scheduler: expecting authentication secret in the environment"
                )
                sys.exit(1)

            credential = mesos_pb2.Credential()
            credential.principal = os.getenv("DEFAULT_PRINCIPAL")
            credential.secret = os.getenv("DEFAULT_SECRET")

            driver = mesos.MesosSchedulerDriver(sched, framework, master_uri,
                                                credential)
        else:
            driver = mesos.MesosSchedulerDriver(sched, framework, master_uri)

        return driver
Пример #2
0
    def __init__(self, scheduler, workrepo, config):
        super(MesosDRMS, self).__init__(scheduler, workrepo, config)

        if self.config.mesos is None:
            logging.error("Mesos not configured")
            return
        self.sched = NebularMesos(scheduler, workrepo, config)
        self.framework = mesos_pb2.FrameworkInfo()
        self.framework.user = ""  # Have Mesos fill in the current user.
        self.framework.name = "Nebula"
        ## additional authentication stuff would go here
        self.driver = mesos.MesosSchedulerDriver(self.sched, self.framework,
                                                 self.config.mesos)
Пример #3
0
    def run(self):
        self.queue.branchUpdate("/")
        executor = mesos_pb2.ExecutorInfo()
        executor.executor_id.value = "default"
        executor.command.value = "PYTHONPATH=%s %s " % (
            os.environ['PYTHONPATH'], sys.executable) + os.path.abspath(
                os.path.join(os.path.dirname(__file__), "./jobTreeExec.py %s" %
                             (self.common_dir)))
        executor.name = "JobTreeExec"
        executor.source = "JobTree"

        framework = mesos_pb2.FrameworkInfo()
        framework.user = ""  # Have Mesos fill in the current user.
        framework.name = "JobTree"

        # TODO(vinod): Make checkpointing the default when it is default
        # on the slave.
        if os.getenv("MESOS_CHECKPOINT"):
            logging.info("Enabling checkpoint for the framework")
            framework.checkpoint = True

        if os.getenv("MESOS_AUTHENTICATE"):
            logging.info("Enabling authentication for the framework")

            if not os.getenv("DEFAULT_PRINCIPAL"):
                logging.error(
                    "Expecting authentication principal in the environment")
                return

            if not os.getenv("DEFAULT_SECRET"):
                logging.error(
                    "Expecting authentication secret in the environment")
                return

            credential = mesos_pb2.Credential()
            credential.principal = os.getenv("DEFAULT_PRINCIPAL")
            credential.secret = os.getenv("DEFAULT_SECRET")

            driver = mesos.MesosSchedulerDriver(
                JobTreeScheduler(executor, self.queue), framework,
                self.mesos_url, credential)
        else:
            logging.info("Contacting Mesos: %s" % self.mesos_url)
            driver = mesos.MesosSchedulerDriver(
                JobTreeScheduler(executor, self.queue), framework,
                self.mesos_url)

        status = 0 if driver.run() == mesos_pb2.DRIVER_STOPPED else 1
        logging.info("Status: %s" % status)
        # Ensure that the driver process terminates.
        driver.stop()
Пример #4
0
    def start(self):
        self.out_logger = self.start_logger(sys.stdout)
        self.err_logger = self.start_logger(sys.stderr)

        name = '[dpark@%s] ' % socket.gethostname()
        name += os.path.abspath(sys.argv[0]) + ' ' + ' '.join(sys.argv[1:])
        framework = mesos_pb2.FrameworkInfo()
        framework.user = getpass.getuser()
        framework.name = name

        # ignore INFO and DEBUG log
        os.environ['GLOG_logtostderr'] = '1'
        os.environ['GLOG_minloglevel'] = '1'
        import mesos
        self.driver = mesos.MesosSchedulerDriver(self, framework, self.master)
        self.driver.start()
        logger.debug("Mesos Scheudler driver started")
Пример #5
0
 def __init__(self, options, command):
     self.framework = mesos_pb2.FrameworkInfo()
     self.framework.user = getpass.getuser()
     self.framework.name = '[drun@%s] ' % socket.gethostname() + ' '.join(
         sys.argv[1:])
     self.executor = self.getExecutorInfo()
     self.cpus = options.cpus
     self.mem = parse_mem(options.mem)
     self.options = options
     self.command = command
     self.total_tasks = list(
         reversed([Task(i) for i in range(options.start, options.tasks)]))
     self.task_launched = {}
     self.slaveTasks = {}
     self.refused = set()
     self.started = False
     self.stopped = False
     self.status = 0
     self.next_try = 0
     self.lock = RLock()
Пример #6
0
        print "Received message:", repr(str(message))

        if self.messagesReceived == TOTAL_TASKS:
            if self.messagesReceived != self.messagesSent:
                print "Sent", self.messagesSent,
                print "but received", self.messagesReceived
                sys.exit(1)
            print "All tasks done, and all messages received, exiting"
            driver.stop()


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print "Usage: %s master" % sys.argv[0]
        sys.exit(1)

    executor = mesos_pb2.ExecutorInfo()
    executor.executor_id.value = "default"
    executor.command.value = os.path.abspath("./test-executor")
    executor.name = "Test Executor (Python)"
    executor.source = "python_test"

    framework = mesos_pb2.FrameworkInfo()
    framework.user = ""  # Have Mesos fill in the current user.
    framework.name = "Test Framework (Python)"

    driver = mesos.MesosSchedulerDriver(TestScheduler(executor), framework,
                                        sys.argv[1])

    sys.exit(0 if driver.run() == mesos_pb2.DRIVER_STOPPED else 1)
Пример #7
0
def cli():
    schedulers = {
        "sleep": SleepScheduler,
        "pg": PGScheduler,
        "executor": ExecutorScheduler
    }
    p = argparse.ArgumentParser(prog="deimos-test.py")
    p.add_argument("--master",
                   default="localhost:5050",
                   help="Mesos master URL")
    p.add_argument("--test",
                   choices=schedulers.keys(),
                   default="sleep",
                   help="Test scheduler to use")
    p.add_argument("--executor",
                   action="store_true",
                   default=False,
                   help="Runs the executor instead of a test scheduler")
    p.add_argument("--test.container", help="Image URL to use (for any test)")
    p.add_argument("--test.uris",
                   action="append",
                   help="Pass any number of times to add URIs (for any test)")
    p.add_argument("--test.trials",
                   type=int,
                   help="Number of tasks to run (for any test)")
    p.add_argument("--test.sleep",
                   type=int,
                   help="Seconds to sleep (for sleep test)")
    p.add_argument("--test.command", help="Command to use (for executor test)")
    parsed = p.parse_args()

    if parsed.executor:
        log.info("Mesos executor mode was chosen")
        driver = mesos.MesosExecutorDriver(ExecutorSchedulerExecutor())
        code = driver.run()
        log.info(mesos_pb2.Status.Name(code))
        driver.stop()
        if code != mesos_pb2.DRIVER_STOPPED:
            log.error("Driver died in an anomalous state")
            os._exit(2)
        os._exit(0)

    pairs = [(k.split("test.")[1:], v) for k, v in vars(parsed).items()]
    constructor_args = dict((k[0], v) for k, v in pairs if len(k) == 1 and v)
    scheduler_class = schedulers[parsed.test]
    scheduler = scheduler_class(**constructor_args)
    args = ", ".join("%s=%r" % (k, v) for k, v in constructor_args.items())
    log.info("Testing: %s(%s)" % (scheduler_class.__name__, args))

    framework = mesos_pb2.FrameworkInfo()
    framework.name = "deimos-test"
    framework.user = ""
    driver = mesos.MesosSchedulerDriver(scheduler, framework, parsed.master)
    code = driver.run()
    log.info(mesos_pb2.Status.Name(code))
    driver.stop()
    ################  2 => driver problem  1 => tests failed  0 => tests passed
    if code != mesos_pb2.DRIVER_STOPPED:
        log.error("Driver died in an anomalous state")
        log.info("Aborted: %s(%s)" % (scheduler_class.__name__, args))
        os._exit(2)
    if any(_ in Scheduler.failed for _ in scheduler.statuses.values()):
        log.error("Test run failed -- not all tasks made it")
        log.info("Failure: %s(%s)" % (scheduler_class.__name__, args))
        os._exit(1)
    log.info("Success: %s(%s)" % (scheduler_class.__name__, args))
    os._exit(0)