本文整理汇总了Java中org.apache.mesos.Protos.ContainerInfo类的典型用法代码示例。如果您正苦于以下问题:Java ContainerInfo类的具体用法?Java ContainerInfo怎么用?Java ContainerInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ContainerInfo类属于org.apache.mesos.Protos包,在下文中一共展示了ContainerInfo类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDockerTaskWithoutExecutor
import org.apache.mesos.Protos.ContainerInfo; //导入依赖的package包/类
@Test
public void testDockerTaskWithoutExecutor() {
AssignedTask builder = TASK.newBuilder();
builder.getTask()
.setContainer(Container.docker(new DockerContainer()
.setImage("hello-world")))
.unsetExecutorConfig();
TaskInfo task = getDockerTaskInfo(IAssignedTask.build(builder));
assertTrue(task.hasCommand());
assertFalse(task.getCommand().getShell());
assertFalse(task.hasData());
ContainerInfo expectedContainer = ContainerInfo.newBuilder()
.setType(Type.DOCKER)
.setDocker(DockerInfo.newBuilder()
.setImage("hello-world"))
.build();
assertEquals(expectedContainer, task.getContainer());
checkDiscoveryInfoUnset(task);
}
示例2: buildContainerInfo
import org.apache.mesos.Protos.ContainerInfo; //导入依赖的package包/类
public static CommandInfo.ContainerInfo buildContainerInfo(Configuration conf) {
String containerImage = conf.get("mapred.mesos.container.image");
String[] containerOptions = conf.getStrings("mapred.mesos.container.options");
CommandInfo.ContainerInfo.Builder containerInfo =
CommandInfo.ContainerInfo.newBuilder();
if (containerImage != null) {
containerInfo.setImage(containerImage);
}
if (containerOptions != null) {
for (int i = 0; i < containerOptions.length; i++) {
containerInfo.addOptions(containerOptions[i]);
}
}
return containerInfo.build();
}
示例3: buildContainerInfo
import org.apache.mesos.Protos.ContainerInfo; //导入依赖的package包/类
/**
* Prepares the Docker ContainerInfo, adding a PortMapping to Kibana for the given host port
*
* @param port the host port to direct to Kibana
* @return the Docker ContainerInfo
*/
private static ContainerInfo buildContainerInfo(long port) {
DockerInfo.PortMapping.Builder portMappingBuilder = DockerInfo.PortMapping.newBuilder();
portMappingBuilder.setHostPort((int) port);
portMappingBuilder.setContainerPort(5601);
portMappingBuilder.setProtocol("tcp");
DockerInfo.Builder dockerInfo = DockerInfo.newBuilder();
dockerInfo.setImage(SchedulerConfiguration.getDockerImageName());
dockerInfo.addPortMappings(portMappingBuilder.build());
dockerInfo.setNetwork(ContainerInfo.DockerInfo.Network.BRIDGE);
dockerInfo.build();
ContainerInfo.Builder containerInfo = ContainerInfo.newBuilder();
containerInfo.setType(ContainerInfo.Type.DOCKER);
containerInfo.setDocker(dockerInfo);
return containerInfo.build();
}
示例4: getDockerContainerInfo
import org.apache.mesos.Protos.ContainerInfo; //导入依赖的package包/类
private ContainerInfo getDockerContainerInfo(IDockerContainer config) {
Iterable<Protos.Parameter> parameters = Iterables.transform(config.getParameters(),
item -> Protos.Parameter.newBuilder().setKey(item.getName())
.setValue(item.getValue()).build());
ContainerInfo.DockerInfo.Builder dockerBuilder = ContainerInfo.DockerInfo.newBuilder()
.setImage(config.getImage()).addAllParameters(parameters);
return ContainerInfo.newBuilder()
.setType(ContainerInfo.Type.DOCKER)
.setDocker(dockerBuilder.build())
.addAllVolumes(executorSettings.getExecutorConfig().getVolumeMounts())
.build();
}
示例5: buildTask
import org.apache.mesos.Protos.ContainerInfo; //导入依赖的package包/类
/**
* Creates a new task and registers it with the configuration, ready for launch.
*
* @param requirement the task requirement
* @param offer the offer the task will use to run
* @param configuration the scheduler's configuration, used to register the task with
* @return a new task, ready for launch
*/
public static TaskInfo buildTask(Map.Entry<String, Integer> requirement, Offer offer, SchedulerConfiguration configuration) {
TaskID taskId = generateTaskId();
long port = configuration.pickAndRegisterPortNumber(taskId, offer);
ContainerInfo container = buildContainerInfo(port);
Environment environment = buildEnvironment(requirement.getKey());
CommandInfo command = buildCommandInfo(environment);
List<Resource> resources = buildResources(configuration, port); //DCOS-06 Scheduler MUST only use the necessary fraction of an offer.
return buildTaskInfo(taskId, offer, container, command, resources);
}
示例6: buildTaskInfo
import org.apache.mesos.Protos.ContainerInfo; //导入依赖的package包/类
/**
* Prepares the TaskInfo for the Kibana task
*
* @param taskId the tasks' ID
* @param offer the offer with which to run the task
* @param containerInfo the tasks' ContainerInfo
* @param commandInfo the tasks' CommandInfo
* @param resources the tasks' resources
* @return the TaskInfo
*/
private static TaskInfo buildTaskInfo(TaskID taskId, Offer offer, ContainerInfo containerInfo, CommandInfo commandInfo, List<Resource> resources) {
TaskInfo.Builder task = TaskInfo.newBuilder()
.setName(taskId.getValue())
.setTaskId(taskId)
.setSlaveId(offer.getSlaveId())
.setContainer(containerInfo)
.setCommand(commandInfo)
.addAllResources(resources);
return task.build();
}
示例7: prepareContainerInfo
import org.apache.mesos.Protos.ContainerInfo; //导入依赖的package包/类
private void prepareContainerInfo(final Offer offer, final SingularityTaskId taskId, final TaskInfo.Builder bldr, final SingularityContainerInfo containerInfo, final Optional<long[]> ports) {
ContainerInfo.Builder containerBuilder = ContainerInfo.newBuilder();
containerBuilder.setType(ContainerInfo.Type.valueOf(containerInfo.getType().toString()));
final Optional<SingularityDockerInfo> dockerInfo = containerInfo.getDocker();
if (dockerInfo.isPresent()) {
final DockerInfo.Builder dockerInfoBuilder = DockerInfo.newBuilder();
dockerInfoBuilder.setImage(dockerInfo.get().getImage());
if (dockerInfo.get().getNetwork().isPresent()) {
dockerInfoBuilder.setNetwork(DockerInfo.Network.valueOf(dockerInfo.get().getNetwork().get().toString()));
}
if ((dockerInfo.get().hasAllLiteralHostPortMappings() || ports.isPresent()) && !dockerInfo.get().getPortMappings().isEmpty()) {
for (SingularityDockerPortMapping singularityDockerPortMapping : dockerInfo.get().getPortMappings()) {
final Optional<DockerInfo.PortMapping> maybePortMapping = buildPortMapping(singularityDockerPortMapping, ports);
if (maybePortMapping.isPresent()) {
dockerInfoBuilder.addPortMappings(maybePortMapping.get());
}
}
}
if (!dockerInfo.get().getParameters().isEmpty()) {
List<Parameter> parameters = new ArrayList<>();
for (Map.Entry<String, String> entry : dockerInfo.get().getParameters().entrySet()) {
parameters.add(Parameter.newBuilder().setKey(entry.getKey()).setValue(entry.getValue()).build());
}
dockerInfoBuilder.addAllParameters(parameters);
}
dockerInfoBuilder.setPrivileged(dockerInfo.get().isPrivileged());
dockerInfoBuilder.setForcePullImage(dockerInfo.get().isForcePullImage());
containerBuilder.setDocker(dockerInfoBuilder);
}
for (SingularityVolume volumeInfo : containerInfo.getVolumes().or(Collections.<SingularityVolume>emptyList())) {
final Volume.Builder volumeBuilder = Volume.newBuilder();
volumeBuilder.setContainerPath(fillInTaskIdValues(volumeInfo.getContainerPath(), offer, taskId));
if (volumeInfo.getHostPath().isPresent()) {
volumeBuilder.setHostPath(fillInTaskIdValues(volumeInfo.getHostPath().get(), offer, taskId));
}
if (volumeInfo.getMode().isPresent()) {
volumeBuilder.setMode(Volume.Mode.valueOf(volumeInfo.getMode().get().toString()));
} else {
volumeBuilder.setMode(Volume.Mode.RO);
}
containerBuilder.addVolumes(volumeBuilder);
}
bldr.setContainer(containerBuilder);
}
示例8: buildDockerContainerInfo
import org.apache.mesos.Protos.ContainerInfo; //导入依赖的package包/类
public static ContainerInfo buildDockerContainerInfo(Configuration conf) {
ContainerInfo.Builder containerInfoBuilder = ContainerInfo.newBuilder();
DockerInfo.Builder dockerInfoBuilder = DockerInfo.newBuilder();
dockerInfoBuilder.setImage(conf.get("mapred.mesos.docker.image"));
switch (conf.getInt("mapred.mesos.docker.network", 1)) {
case 1:
dockerInfoBuilder.setNetwork(DockerInfo.Network.HOST);
case 2:
dockerInfoBuilder.setNetwork(DockerInfo.Network.BRIDGE);
case 3:
dockerInfoBuilder.setNetwork(DockerInfo.Network.NONE);
default:
dockerInfoBuilder.setNetwork(DockerInfo.Network.HOST);
}
dockerInfoBuilder.setPrivileged(conf.getBoolean("mapred.mesos.docker.privileged", false));
dockerInfoBuilder.setForcePullImage(conf.getBoolean("mapred.mesos.docker.force_pull_image", false));
// Parse out any additional docker CLI params
String[] params = conf.getStrings("mapred.mesos.docker.parameters");
if (params != null && params.length > 0) {
// Make sure we have an even number of parameters
if ((params.length % 2) != 0) {
throw new IllegalArgumentException("The number of parameters should be even, k/v pairs");
}
Parameter.Builder paramBuilder = null;
for (int i = 0; i < params.length; i++) {
if (paramBuilder == null) {
paramBuilder = Parameter.newBuilder();
paramBuilder.setKey(params[i]);
} else {
paramBuilder.setValue(params[i]);
dockerInfoBuilder.addParameters(paramBuilder.build());
paramBuilder = null;
}
}
}
// Parse out any volumes that have been defined
String[] volumes = conf.getStrings("mapred.mesos.docker.volumes");
if (volumes != null && volumes.length > 0) {
for (int i = 0; i < volumes.length; i++) {
String[] parts = volumes[i].split(":");
if (parts.length <= 1 || parts.length > 3) {
throw new IllegalArgumentException("Invalid volume configuration (host_path:container_path:[rw|ro])");
}
Volume.Mode mode = Volume.Mode.RW;
if (parts[parts.length - 1].equalsIgnoreCase("ro")) {
mode = Volume.Mode.RO;
}
if (parts.length == 2) {
containerInfoBuilder.addVolumes(
Volume.newBuilder()
.setContainerPath(parts[0])
.setMode(mode)
.build());
} else {
containerInfoBuilder.addVolumes(
Volume.newBuilder()
.setHostPath(parts[0])
.setContainerPath(parts[1])
.setMode(mode)
.build());
}
}
}
containerInfoBuilder.setType(ContainerInfo.Type.DOCKER);
containerInfoBuilder.setDocker(dockerInfoBuilder.build());
return containerInfoBuilder.build();
}
示例9: matches
import org.apache.mesos.Protos.ContainerInfo; //导入依赖的package包/类
private boolean matches(Offer offer, Request request) {
double cpus = -1;
double mem = -1;
List<Range> ports = null;
for (Resource resource : offer.getResourcesList()) {
String resourceRole = resource.getRole();
String expectedRole = mesosCloud.getRole();
if (! (resourceRole.equals(expectedRole) || resourceRole.equals("*"))) {
LOGGER.warning("Resource role " + resourceRole +
" doesn't match expected role " + expectedRole);
continue;
}
if (resource.getName().equals("cpus")) {
if (resource.getType().equals(Value.Type.SCALAR)) {
cpus = resource.getScalar().getValue();
} else {
LOGGER.severe("Cpus resource was not a scalar: " + resource.getType().toString());
}
} else if (resource.getName().equals("mem")) {
if (resource.getType().equals(Value.Type.SCALAR)) {
mem = resource.getScalar().getValue();
} else {
LOGGER.severe("Mem resource was not a scalar: " + resource.getType().toString());
}
} else if (resource.getName().equals("disk")) {
LOGGER.fine("Ignoring disk resources from offer");
} else if (resource.getName().equals("ports")) {
if (resource.getType().equals(Value.Type.RANGES)) {
ports = resource.getRanges().getRangeList();
} else {
LOGGER.severe("Ports resource was not a range: " + resource.getType().toString());
}
} else {
LOGGER.warning("Ignoring unknown resource type: " + resource.getName());
}
}
if (cpus < 0) LOGGER.fine("No cpus resource present");
if (mem < 0) LOGGER.fine("No mem resource present");
MesosSlaveInfo.ContainerInfo containerInfo = request.request.slaveInfo.getContainerInfo();
boolean hasPortMappings = containerInfo != null ? containerInfo.hasPortMappings() : false;
boolean hasPortResources = ports != null && !ports.isEmpty();
if (hasPortMappings && !hasPortResources) {
LOGGER.severe("No ports resource present");
}
// Check for sufficient cpu and memory resources in the offer.
double requestedCpus = request.request.cpus;
double requestedMem = (1 + JVM_MEM_OVERHEAD_FACTOR) * request.request.mem;
// Get matching slave attribute for this label.
JSONObject slaveAttributes = getMesosCloud().getSlaveAttributeForLabel(request.request.slaveInfo.getLabelString());
if (requestedCpus <= cpus
&& requestedMem <= mem
&& !(hasPortMappings && !hasPortResources)
&& slaveAttributesMatch(offer, slaveAttributes)) {
return true;
} else {
String requestedPorts = containerInfo != null
? StringUtils.join(containerInfo.getPortMappings().toArray(), "/")
: "";
LOGGER.fine(
"Offer not sufficient for slave request:\n" +
offer.getResourcesList().toString() +
"\n" + offer.getAttributesList().toString() +
"\nRequested for Jenkins slave:\n" +
" cpus: " + requestedCpus + "\n" +
" mem: " + requestedMem + "\n" +
" ports: " + requestedPorts + "\n" +
" attributes: " + (slaveAttributes == null ? "" : slaveAttributes.toString()));
return false;
}
}