生成taskInfo

task = mesos_pb2.TaskInfo()
task_id = name
task.task_id.value = task_id
task.slave_id.value = offer.slave_id.value
task.name = name
task.data = "Hello from task {}!".format(task_id)

cpus = task.resources.add()
cpus.name = 'cpus'
cpus.type = mesos_pb2.Value.SCALAR
cpus.scalar.value = float(cpu)

mem = task.resources.add()
mem.name = 'mem'
mem.type = mesos_pb2.Value.SCALAR
mem.scalar.value = 1

disk = task.resources.add()
disk.name = 'disk'
disk.type = mesos_pb2.Value.SCALAR
disk.scalar.value = 1

command = get_command_info("while true; do echo 'hahah'; sleep 2; done")
task.command.MergeFrom(command)

container = get_container_info()
task.container.MergeFrom(container)

函数:

"""
message CommandInfo {
message URI {
required string value = 1;
optional bool executable = 2;

// In case the fetched file is recognized as an archive, extract
// its contents into the sandbox. Note that a cached archive is
// not copied from the cache to the sandbox in case extraction
// originates from an archive in the cache.
optional bool extract = 3 [default = true];

// If this field is "true", the fetcher cache will be used. If not,
// fetching bypasses the cache and downloads directly into the
// sandbox directory, no matter whether a suitable cache file is
// available or not. The former directs the fetcher to download to
// the file cache, then copy from there to the sandbox. Subsequent
// fetch attempts with the same URI will omit downloading and copy
// from the cache as long as the file is resident there. Cache files
// may get evicted at any time, which then leads to renewed
// downloading. See also "docs/fetcher.md" and
// "docs/fetcher-cache-internals.md".
optional bool cache = 4;

// The fetcher's default behavior is to use the URI string's basename to
// name the local copy. If this field is provided, the local copy will be
// named with its value instead. If there is a directory component (which
// must be a relative path), the local copy will be stored in that
// subdirectory inside the sandbox.
optional string output_file = 5;
}

repeated URI uris = 1;

optional Environment environment = 2;

// There are two ways to specify the command:
// 1) If 'shell == true', the command will be launched via shell
// (i.e., /bin/sh -c 'value'). The 'value' specified will be
// treated as the shell command. The 'arguments' will be ignored.
// 2) If 'shell == false', the command will be launched by passing
// arguments to an executable. The 'value' specified will be
// treated as the filename of the executable. The 'arguments'
// will be treated as the arguments to the executable. This is
// similar to how POSIX exec families launch processes (i.e.,
// execlp(value, arguments(0), arguments(1), ...)).
// NOTE: The field 'value' is changed from 'required' to 'optional'
// in 0.20.0. It will only cause issues if a new framework is
// connecting to an old master.
optional bool shell = 6 [default = true];
optional string value = 3;
repeated string arguments = 7;

// Enables executor and tasks to run as a specific user. If the user
// field is present both in FrameworkInfo and here, the CommandInfo
// user value takes precedence.
optional string user = 5;
}
"""
def get_command_info(cmd):
command = mesos_pb2.CommandInfo()
command.value = cmd

return command

"""
/**
* Describes a container configuration and allows extensible
* configurations for different container implementations.
*
* NOTE: `ContainerInfo` may be specified, e.g., by a task, even if no
* container image is provided. In this case neither `MesosInfo` nor
* `DockerInfo` is set, the required `type` must be `MESOS`. This is to
* address a case when a task without an image, e.g., a shell script
* with URIs, wants to use features originally designed for containers,
* for example custom network isolation via `NetworkInfo`.
*/
message ContainerInfo {
// All container implementation types.
enum Type {
DOCKER = 1;
MESOS = 2;
}

message DockerInfo {
// The docker image that is going to be passed to the registry.
required string image = 1;

// Network options.
enum Network {
HOST = 1;
BRIDGE = 2;
NONE = 3;
USER = 4;
}

optional Network network = 2 [default = HOST];

message PortMapping {
required uint32 host_port = 1;
required uint32 container_port = 2;
// Protocol to expose as (ie: tcp, udp).
optional string protocol = 3;
}

repeated PortMapping port_mappings = 3;

optional bool privileged = 4 [default = false];

// Allowing arbitrary parameters to be passed to docker CLI.
// Note that anything passed to this field is not guaranteed
// to be supported moving forward, as we might move away from
// the docker CLI.
repeated Parameter parameters = 5;

// With this flag set to true, the docker containerizer will
// pull the docker image from the registry even if the image
// is already downloaded on the slave.
optional bool force_pull_image = 6;

// The name of volume driver plugin.
optional string volume_driver = 7 [deprecated = true]; // Since 1.0
}

message MesosInfo {
optional Image image = 1;
}

required Type type = 1;
repeated Volume volumes = 2;
optional string hostname = 4;

// Only one of the following *Info messages should be set to match
// the type.
optional DockerInfo docker = 3;
optional MesosInfo mesos = 5;

// A list of network requests. A framework can request multiple IP addresses
// for the container.
repeated NetworkInfo network_infos = 7;

// Linux specific information for the container.
optional LinuxInfo linux_info = 8;

// (POSIX only) rlimits of the container.
optional RLimitInfo rlimit_info = 9;

// If specified a tty will be attached to the container entrypoint.
optional TTYInfo tty_info = 10;
}
"""

def get_container_info():
container = mesos_pb2.ContainerInfo()
container.type = 1
container.docker.image = "ubuntu:12.04"
return container

注意:Task should have at least one (but not both) of CommandInfo or ExecutorInfo present

查看执行器日志

stderr:

I0423 13:46:38.657913 59463 exec.cpp:162] Version: 1.2.0
I0423 13:46:38.999876 59469 exec.cpp:237] Executor registered on agent e37a74b8-415d-42ae-85d9-addfc03ef44e-S0
I0423 13:46:39.002205 59469 docker.cpp:850] Running docker -H unix:///var/run/docker.sock run --cpu-shares 512 --memory 33554432 --env-file /tmp/NYLbhc -v /var/run/mesos/slaves/e37a74b8-415d-42ae-85d9-addfc03ef44e-S0/frameworks/e37a74b8-415d-42ae-85d9-addfc03ef44e-0012/executors/m4/runs/a290585b-8783-4597-b9c8-f0ea201806b0:/mnt/mesos/sandbox --net host --entrypoint /bin/sh --name mesos-e37a74b8-415d-42ae-85d9-addfc03ef44e-S0.a290585b-8783-4597-b9c8-f0ea201806b0 ubuntu:12.04 -c while true; do echo 'hahah'; sleep 2; done stdout:
--container="mesos-e37a74b8-415d-42ae-85d9-addfc03ef44e-S0.a290585b-8783-4597-b9c8-f0ea201806b0" --docker="docker" --docker_socket="/var/run/docker.sock" --help="false" --initialize_driver_logging="true" --launcher_dir="/usr/local/libexec/mesos" --logbufsecs="0" --logging_level="INFO" --mapped_directory="/mnt/mesos/sandbox" --quiet="false" --sandbox_directory="/var/run/mesos/slaves/e37a74b8-415d-42ae-85d9-addfc03ef44e-S0/frameworks/e37a74b8-415d-42ae-85d9-addfc03ef44e-0012/executors/m4/runs/a290585b-8783-4597-b9c8-f0ea201806b0" --stop_timeout="0ns"
--container="mesos-e37a74b8-415d-42ae-85d9-addfc03ef44e-S0.a290585b-8783-4597-b9c8-f0ea201806b0" --docker="docker" --docker_socket="/var/run/docker.sock" --help="false" --initialize_driver_logging="true" --launcher_dir="/usr/local/libexec/mesos" --logbufsecs="0" --logging_level="INFO" --mapped_directory="/mnt/mesos/sandbox" --quiet="false" --sandbox_directory="/var/run/mesos/slaves/e37a74b8-415d-42ae-85d9-addfc03ef44e-S0/frameworks/e37a74b8-415d-42ae-85d9-addfc03ef44e-0012/executors/m4/runs/a290585b-8783-4597-b9c8-f0ea201806b0" --stop_timeout="0ns"
Registered docker executor on webtest
Starting task m4
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
hahah
Received killTask for task m4

agent 本地必须有镜像
否则起不来任务

[root@localmesos mini]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
50dc2110aedc ubuntu:12.04 "/bin/sh -c 'while tr" 19 seconds ago Up 17 seconds mesos-3cff5506-ce4f-4bd7-aa35-fc4f83a45b15-S0.d237b778-c8c2-4d8c-bc09-9d18a9b1301e

												

mesos无执行器启动docker的更多相关文章

  1. Mesos+Zookeeper+Marathon的Docker管理平台部署记录(1)

    随着"互联网+"时代的业务增长.变化速度及大规模计算的需求,廉价的.高可扩展的分布式x86集群已成为标准解决方案,如Google已经在几千万台服务器上部署分布式系统.Docker及 ...

  2. 使用Mesos和Marathon管理Docker集群

    分布式系统是难于理解.设计.构建 和管理的,他们将比单个机器成倍还要多的变量引入到设计中,使应用程序的根源问题更难发现.SLA(服务水平协议)是衡量停机和/或性能下降的标准,大多数现代应用程序有一个期 ...

  3. Mesos+Zookeeper+Marathon的Docker管理平台部署记录(2)- 负载均衡marathon-lb

    之前介绍了Mesos+Zookeeper+Marathon的Docker管理平台部署记录(1)的操作,多余的废话不说了,下面接着说下在该集群环境下的负载均衡marathon-lb的部署过程: 默认情况 ...

  4. docker集群——搭建Mesos+Zookeeper+Marathon的Docker管理平台

    服务器架构 机器信息: 这里部属的机器为3个Master控制节点,3个slave运行节点,其中: zookeeper.Mesos-master.marathon运行在Master端:Mesos-sla ...

  5. mac 启动 docker daemon

    我是用virtualbox安装的. 有一个小问题就是启动docker服务时会检查boot2docker是不是最新的. 由于github被封了,所以只能手动下 https://github.com/bo ...

  6. Virtualbox网络设置和无UI启动

    因工作需要,在Macbook上安装Ubuntu 14.04.2虚拟机,需要ssh连接操作. 一番查找资料,实践后可以正常工作了,记录一些信息以备用 无UI启动虚拟机,可使用以下命令: VBoxMana ...

  7. centos7 启动docker失败的解决

    控制端使用yum install docker安装完成docker后启动docker失败,出现以下信息: Job for docker.service failed because the contr ...

  8. Centos 配置开机启动脚本启动 docker 容器

    Centos 配置开机启动脚本启动 docker 容器 Intro 我们的 Centos 服务器上部署了好多个 docker 容器,因故重启的时候就会导致还得手动去手动重启这些 docker 容器,为 ...

  9. windows 2008 开机启动 Docker Toolbox 并运行容器

    新建 docker-startup.bat @echo off REM Set the name of the VM configuration where dockerd will be hoste ...

随机推荐

  1. 【Spring环境搭建】在Myeclipse下搭建Spring环境-web开发

    <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" ...

  2. java操作Excel之POI(5)利用POI实现使用模板批量导出数据

    后台导出方法: 在源文件夹src下面放个准备好的模板:/com/cy/template/userExportTemplate.xls,这个模板有头部一行: /** * 后台导出方法 * 利用POI实现 ...

  3. 实验十一 C的指针

    指针编程 11.1 #include<stdio.h> int main() { ]={,,,,,,,,,},i,*p,sum=; ],i=;i<;i++,p++) { ==) su ...

  4. 手贱,写个call玩玩.

    今天在睡觉醒时,突然感觉对call和apply有了点理解,但是又不好表达出来.就随便写几个例子. function say() { return this.role; } function Fathe ...

  5. storm的代码实现

    先模拟产生一些数据 我把这些数据摘一部分下来 2017-06-10 18:25:56,092 [main] [org.apache.kafka.common.utils.AppInfoParser] ...

  6. NOIP考前复习-数制转换,数论模板与文件读写

    数制转换有两种题型,一般一题,分值1.5分. 题型一:R进制转十进制 解法就是:按权展开,但要注意各个位的权,最低位(最右边)的权是0次方,权值为1. 纯整数的情况: (11010110)2 = 1× ...

  7. 序列化 ,hashlib ,configparser ,logging ,collections模块

    # 实例化 归一化 初始化 序列化 # 列表 元组 字符串# 字符串# .......得到一个字符串的结果 过程就叫序列化# 字典 / 列表 / 数字 /对象 -序列化->字符串# 为什么要序列 ...

  8. 内置锁(三)synchronized的几个要注意的对象监视器

    前言    经过前面的两篇文章的介绍,可以清楚知道,synchronized可以用于修饰一个方法 或者 代码块,线程要访问这些临界区代码,则要先获取对应的 对象监视器 ,从而使多个线程互斥访问临界区. ...

  9. node实现缓存

    内容: 1.缓存基本原理 2.node实现缓存 1.缓存基本原理 第一重要.缓存策略: cache-control:用于控制缓存,常见的取值有private.no-cache.max-age.must ...

  10. 通过python给mysql建表

    一.python连接mysql from sqlalchemy import create_engine # 数据库数据 HOSTNAME = '127.0.0.1' # linux本地 PORT = ...