本文整理汇总了Java中org.apache.mesos.Protos.Parameter类的典型用法代码示例。如果您正苦于以下问题:Java Parameter类的具体用法?Java Parameter怎么用?Java Parameter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Parameter类属于org.apache.mesos.Protos包,在下文中一共展示了Parameter类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDockerContainerWithParameters
import org.apache.mesos.Protos.Parameter; //导入依赖的package包/类
@Test
public void testDockerContainerWithParameters() {
DockerInfo docker = getDockerTaskInfo(TASK_WITH_DOCKER_PARAMS).getExecutor().getContainer()
.getDocker();
Parameter parameters = Parameter.newBuilder().setKey("label").setValue("testparameter").build();
assertEquals(ImmutableList.of(parameters), docker.getParametersList());
}
示例2: getDockerParameters
import org.apache.mesos.Protos.Parameter; //导入依赖的package包/类
public List<String> getDockerParameters() {
List<String> args = new ArrayList<>();
for (Parameter parameter : taskInfo.getContainer().getDocker().getParametersList()) {
args.add(toCmdLineArg(parameter));
}
return args;
}
示例3: isDockerWorkdirOverriden
import org.apache.mesos.Protos.Parameter; //导入依赖的package包/类
public boolean isDockerWorkdirOverriden() {
for (Parameter parameter : taskInfo.getContainer().getDocker().getParametersList()) {
if (parameter.hasKey() && (parameter.getKey().equals("w") || parameter.getKey().equals("workdir"))) {
return true;
}
}
return false;
}
示例4: toCmdLineArg
import org.apache.mesos.Protos.Parameter; //导入依赖的package包/类
private String toCmdLineArg(Parameter parameter) {
if (parameter.hasKey() && parameter.getKey().length() > 1) {
if (parameter.hasValue() && !Strings.isNullOrEmpty(parameter.getValue())) {
return String.format("--%s=%s", parameter.getKey(), parameter.getValue());
} else {
return String.format("--%s", parameter.getKey());
}
} else {
if (parameter.hasValue() && !Strings.isNullOrEmpty(parameter.getValue())) {
return String.format("-%s=%s", parameter.getKey(), parameter.getValue());
} else {
return String.format("-%s", parameter.getKey());
}
}
}
示例5: prepareContainerInfo
import org.apache.mesos.Protos.Parameter; //导入依赖的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);
}
示例6: testDockerTask
import org.apache.mesos.Protos.Parameter; //导入依赖的package包/类
@Test
public void testDockerTask() {
taskResources = new Resources(1, 1, 1);
final Protos.Resource portsResource = Protos.Resource.newBuilder()
.setName("ports")
.setType(Protos.Value.Type.RANGES)
.setRanges(Protos.Value.Ranges.newBuilder()
.addRange(Protos.Value.Range.newBuilder()
.setBegin(31000)
.setEnd(31000).build()).build()).build();
final SingularityDockerPortMapping literalMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 80, Optional.of(SingularityPortMappingType.LITERAL), 8080, Optional.<String>absent());
final SingularityDockerPortMapping offerMapping = new SingularityDockerPortMapping(Optional.<SingularityPortMappingType>absent(), 81, Optional.of(SingularityPortMappingType.FROM_OFFER), 0, Optional.of("udp"));
final SingularityRequest request = new SingularityRequestBuilder("test", RequestType.WORKER).build();
final SingularityContainerInfo containerInfo = new SingularityContainerInfo(
SingularityContainerType.DOCKER,
Optional.of(Arrays.asList(
new SingularityVolume("/container", Optional.of("/host"), SingularityDockerVolumeMode.RW),
new SingularityVolume("/container/${TASK_REQUEST_ID}/${TASK_DEPLOY_ID}", Optional.of("/host/${TASK_ID}"), SingularityDockerVolumeMode.RO))),
Optional.of(new SingularityDockerInfo("docker-image", true, SingularityDockerNetworkType.BRIDGE, Optional.of(Arrays.asList(literalMapping, offerMapping)), Optional.of(false), Optional.<Map<String, String>>of(ImmutableMap.of("env", "var=value")) )));
final SingularityDeploy deploy = new SingularityDeployBuilder("test", "1")
.setContainerInfo(Optional.of(containerInfo))
.setCommand(Optional.of("/bin/echo"))
.setArguments(Optional.of(Collections.singletonList("wat")))
.build();
final SingularityTaskRequest taskRequest = new SingularityTaskRequest(request, deploy, pendingTask);
final SingularityTask task = builder.buildTask(offer, Collections.singletonList(portsResource), taskRequest, taskResources, executorResources);
assertEquals("/bin/echo", task.getMesosTask().getCommand().getValue());
assertEquals(1, task.getMesosTask().getCommand().getArgumentsCount());
assertEquals("wat", task.getMesosTask().getCommand().getArguments(0));
assertFalse(task.getMesosTask().getCommand().getShell());
assertEquals(Type.DOCKER, task.getMesosTask().getContainer().getType());
assertEquals("docker-image", task.getMesosTask().getContainer().getDocker().getImage());
assertTrue(task.getMesosTask().getContainer().getDocker().getPrivileged());
assertEquals("/container", task.getMesosTask().getContainer().getVolumes(0).getContainerPath());
assertEquals("/host", task.getMesosTask().getContainer().getVolumes(0).getHostPath());
assertEquals(Mode.RW, task.getMesosTask().getContainer().getVolumes(0).getMode());
Parameter envParameter = Parameter.newBuilder().setKey("env").setValue("var=value").build();
assertTrue(task.getMesosTask().getContainer().getDocker().getParametersList().contains(envParameter));
assertEquals(String.format("/container/%s/%s", task.getTaskRequest().getDeploy().getRequestId(), task.getTaskRequest().getDeploy().getId()), task.getMesosTask().getContainer().getVolumes(1).getContainerPath());
assertEquals(String.format("/host/%s", task.getMesosTask().getTaskId().getValue()), task.getMesosTask().getContainer().getVolumes(1).getHostPath());
assertEquals(Mode.RO, task.getMesosTask().getContainer().getVolumes(1).getMode());
assertEquals(80, task.getMesosTask().getContainer().getDocker().getPortMappings(0).getContainerPort());
assertEquals(8080, task.getMesosTask().getContainer().getDocker().getPortMappings(0).getHostPort());
assertEquals("tcp", task.getMesosTask().getContainer().getDocker().getPortMappings(0).getProtocol());
assertTrue(MesosUtils.getAllPorts(task.getMesosTask().getResourcesList()).contains(8080L));
assertEquals(81, task.getMesosTask().getContainer().getDocker().getPortMappings(1).getContainerPort());
assertEquals(31000, task.getMesosTask().getContainer().getDocker().getPortMappings(1).getHostPort());
assertEquals("udp", task.getMesosTask().getContainer().getDocker().getPortMappings(1).getProtocol());
assertEquals(Protos.ContainerInfo.DockerInfo.Network.BRIDGE, task.getMesosTask().getContainer().getDocker().getNetwork());
}
示例7: buildDockerContainerInfo
import org.apache.mesos.Protos.Parameter; //导入依赖的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();
}