本文整理汇总了Java中org.apache.mesos.Protos.ContainerInfo方法的典型用法代码示例。如果您正苦于以下问题:Java Protos.ContainerInfo方法的具体用法?Java Protos.ContainerInfo怎么用?Java Protos.ContainerInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mesos.Protos
的用法示例。
在下文中一共展示了Protos.ContainerInfo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setCommand
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public TaskBuilder setCommand(Job job, Application application, String defaultUnixUser) {
Protos.CommandInfo commandInfo = appToCommandInfo(application, job, assigned.ports(), defaultUnixUser);
builder.setCommand(commandInfo);
if (application.container() instanceof DockerContainer) {
Protos.ContainerInfo containerInfo = appToContainerInfo(application);
builder.setContainer(containerInfo);
} else if (!(application.container() instanceof MesosContainer)) {
LOG.error("Unknown container: {}", application.container());
throw new AssertionError();
}
if (application.getGracePeriod() > 0) {
// seconds to nanoseconds
long d = 1000000000L * application.getGracePeriod();
builder.setKillPolicy(Protos.KillPolicy.newBuilder()
.setGracePeriod(Protos.DurationInfo.newBuilder().setNanoseconds(d)));
}
return this;
}
示例2: testSuccessKeystore
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testSuccessKeystore() throws Exception {
ArrayList<TransportEncryptionSpec> transportEncryptionSpecs = new ArrayList<>();
transportEncryptionSpecs.add(new DefaultTransportEncryptionSpec.Builder()
.name("test-tls")
.type(TransportEncryptionSpec.Type.KEYSTORE)
.build());
Protos.Offer offer = OfferTestUtils.getOffer(ResourceTestUtils.getUnreservedCpus(2.0));
PodInfoBuilder podInfoBuilder = getPodInfoBuilderForTransportEncryption(transportEncryptionSpecs);
EvaluationOutcome outcome = tlsEvaluationStage.evaluate(
new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Assert.assertTrue(outcome.isPassing());
// Check that TLS update was invoked
verify(mockTLSArtifactsUpdater).update(Matchers.any(), Matchers.any(), Matchers.eq("test-tls"));
Protos.ContainerInfo executorContainer =
podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getExecutor().getContainer();
Assert.assertEquals(0, executorContainer.getVolumesCount());
Protos.ContainerInfo taskContainer = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getContainer();
assertKeystoreArtifacts(taskContainer, tlsArtifactPaths, "test-tls");
}
示例3: testArtifactsExist
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testArtifactsExist() throws Exception {
ArrayList<TransportEncryptionSpec> transportEncryptionSpecs = new ArrayList<>();
transportEncryptionSpecs.add(new DefaultTransportEncryptionSpec
.Builder()
.name("test-tls")
.type(TransportEncryptionSpec.Type.TLS)
.build());
Protos.Offer offer = OfferTestUtils.getOffer(ResourceTestUtils.getUnreservedCpus(2.0));
PodInfoBuilder podInfoBuilder = getPodInfoBuilderForTransportEncryption(transportEncryptionSpecs);
EvaluationOutcome outcome = tlsEvaluationStage.evaluate(
new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Assert.assertTrue(outcome.isPassing());
// Check that TLS update was invoked
verify(mockTLSArtifactsUpdater).update(Matchers.any(), Matchers.any(), Matchers.eq("test-tls"));
Protos.ContainerInfo executorContainer =
podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getExecutor().getContainer();
Assert.assertEquals(0, executorContainer.getVolumesCount());
Protos.ContainerInfo taskContainer = podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getContainer();
assertTLSArtifacts(taskContainer, tlsArtifactPaths, "test-tls");
}
示例4: assertTLSArtifacts
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private void assertTLSArtifacts(Protos.ContainerInfo container, TLSArtifactPaths secretPaths, String encryptionSpecName) {
Protos.Volume volume = findVolumeWithContainerPath(container, TLSArtifact.CERTIFICATE.getMountPath(encryptionSpecName)).get();
Assert.assertEquals(
volume.getSource().getSecret().getReference().getName(),
secretPaths.getSecretStorePath(TLSArtifact.CERTIFICATE, encryptionSpecName));
volume = findVolumeWithContainerPath(container, TLSArtifact.CA_CERTIFICATE.getMountPath(encryptionSpecName)).get();
Assert.assertEquals(
volume.getSource().getSecret().getReference().getName(),
secretPaths.getSecretStorePath(TLSArtifact.CA_CERTIFICATE, encryptionSpecName));
volume = findVolumeWithContainerPath(container, TLSArtifact.PRIVATE_KEY.getMountPath(encryptionSpecName)).get();
Assert.assertEquals(
volume.getSource().getSecret().getReference().getName(),
secretPaths.getSecretStorePath(TLSArtifact.PRIVATE_KEY, encryptionSpecName));
Assert.assertFalse(findVolumeWithContainerPath(container, TLSArtifact.KEYSTORE.getMountPath(encryptionSpecName)).isPresent());
Assert.assertFalse(findVolumeWithContainerPath(container, TLSArtifact.TRUSTSTORE.getMountPath(encryptionSpecName)).isPresent());
}
示例5: testSuccessTLS
import org.apache.mesos.Protos; //导入方法依赖的package包/类
@Test
public void testSuccessTLS() throws Exception {
ArrayList<TransportEncryptionSpec> transportEncryptionSpecs = new ArrayList<>();
transportEncryptionSpecs.add(new DefaultTransportEncryptionSpec
.Builder()
.name("test-tls")
.type(TransportEncryptionSpec.Type.TLS)
.build());
Protos.Offer offer = OfferTestUtils.getOffer(ResourceTestUtils.getUnreservedCpus(2.0));
PodInfoBuilder podInfoBuilder = getPodInfoBuilderForTransportEncryption(transportEncryptionSpecs);
EvaluationOutcome outcome = tlsEvaluationStage.evaluate(
new MesosResourcePool(offer, Optional.of(Constants.ANY_ROLE)), podInfoBuilder);
Assert.assertTrue(outcome.isPassing());
// Check that TLS update was invoked
verify(mockTLSArtifactsUpdater).update(Matchers.any(), Matchers.any(), Matchers.eq("test-tls"));
Protos.ContainerInfo executorContainer =
podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getExecutor().getContainer();
Assert.assertEquals(0, executorContainer.getVolumesCount());
Protos.ContainerInfo taskContainer =
podInfoBuilder.getTaskBuilder(TestConstants.TASK_NAME).getContainer();
assertTLSArtifacts(taskContainer, tlsArtifactPaths, "test-tls");
}
示例6: assertKeystoreArtifacts
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private void assertKeystoreArtifacts(Protos.ContainerInfo container, TLSArtifactPaths secretPaths, String encryptionSpecName) {
Protos.Volume volume = findVolumeWithContainerPath(container, TLSArtifact.KEYSTORE.getMountPath(encryptionSpecName)).get();
Assert.assertEquals(
volume.getSource().getSecret().getReference().getName(),
secretPaths.getSecretStorePath(TLSArtifact.KEYSTORE, encryptionSpecName));
volume = findVolumeWithContainerPath(container, TLSArtifact.TRUSTSTORE.getMountPath(encryptionSpecName)).get();
Assert.assertEquals(
volume.getSource().getSecret().getReference().getName(),
secretPaths.getSecretStorePath(TLSArtifact.TRUSTSTORE, encryptionSpecName));
Assert.assertFalse(findVolumeWithContainerPath(container, TLSArtifact.CERTIFICATE.getMountPath(encryptionSpecName)).isPresent());
Assert.assertFalse(findVolumeWithContainerPath(container, TLSArtifact.CA_CERTIFICATE.getMountPath(encryptionSpecName)).isPresent());
Assert.assertFalse(findVolumeWithContainerPath(container, TLSArtifact.PRIVATE_KEY.getMountPath(encryptionSpecName)).isPresent());
}
示例7: appToContainerInfo
import org.apache.mesos.Protos; //导入方法依赖的package包/类
public static Protos.ContainerInfo appToContainerInfo(Application application) {
Container container = application.container();
DockerContainer c = (DockerContainer) container;
Protos.ContainerInfo.Builder builder = Protos.ContainerInfo.newBuilder().setMesos(
Protos.ContainerInfo.MesosInfo.newBuilder()
.setImage(Protos.Image.newBuilder()
.setType(Protos.Image.Type.DOCKER)
.setDocker(Protos.Image.Docker.newBuilder()
.setName(c.image()))))
.setType(Protos.ContainerInfo.Type.MESOS);
for (DockerVolume volume : c.volumes()) {
Protos.Volume.Source.DockerVolume.Builder dvb = Protos.Volume.Source.DockerVolume.newBuilder()
.setDriver(volume.driver()) // like "nfs"
.setName(volume.name()); // like "192.168.204.222/"
Protos.Parameters.Builder p = Protos.Parameters.newBuilder();
for (Object key : volume.options().keySet()) {
p.addParameter(Protos.Parameter.newBuilder()
.setKey((String) key)
.setValue(volume.options().getProperty((String) key))
.build());
}
if (!p.getParameterList().isEmpty()) {
dvb.setDriverOptions(p.build());
}
Protos.Volume.Builder vb = Protos.Volume.newBuilder()
.setContainerPath(volume.containerPath()) // target path to mount inside container
.setSource(Protos.Volume.Source.newBuilder()
.setType(Protos.Volume.Source.Type.DOCKER_VOLUME)
.setDockerVolume(dvb.build()));
switch (volume.mode()) {
case RW:
vb.setMode(Protos.Volume.Mode.RW);
break;
case RO:
default:
vb.setMode(Protos.Volume.Mode.RO);
}
builder.addVolumes(vb);
}
return builder.build();
}
示例8: getContainerInfo
import org.apache.mesos.Protos; //导入方法依赖的package包/类
/**
* Get the ContainerInfo for either an Executor or a Task. Since we support both default and custom executors at
* the moment, there is some conditional logic in here -- with the default executor, things like rlimits and images
* must be specified at the task level only, while secrets volumes must be specified at the executor level.
*
* @param podSpec The Spec for the task or executor that this container is being attached to
* @param addExtraParameters Add rlimits and docker image (if task), or secrets volumes if executor
* @param isTaskContainer Whether this container is being attached to a TaskInfo rather than ExecutorInfo
* @return the ContainerInfo to be attached
*/
private Protos.ContainerInfo getContainerInfo(
PodSpec podSpec, boolean addExtraParameters, boolean isTaskContainer) {
Collection<Protos.Volume> secretVolumes = getExecutorInfoSecretVolumes(podSpec.getSecrets());
Protos.ContainerInfo.Builder containerInfo = Protos.ContainerInfo.newBuilder()
.setType(Protos.ContainerInfo.Type.MESOS);
if (isTaskContainer) {
containerInfo.getLinuxInfoBuilder().setSharePidNamespace(podSpec.getSharePidNamespace());
}
if (!podSpec.getImage().isPresent()
&& podSpec.getNetworks().isEmpty()
&& podSpec.getRLimits().isEmpty()
&& secretVolumes.isEmpty()) {
// Nothing left to do.
return containerInfo.build();
}
boolean shouldAddImage =
podSpec.getImage().isPresent() &&
addExtraParameters &&
((isTaskContainer && useDefaultExecutor) || (!isTaskContainer && !useDefaultExecutor));
if (shouldAddImage) {
containerInfo.getMesosBuilder().getImageBuilder()
.setType(Protos.Image.Type.DOCKER)
.getDockerBuilder().setName(podSpec.getImage().get());
}
// With the default executor, all NetworkInfos must be defined on the executor itself rather than individual
// tasks. This check can be made much less ugly once the custom executor no longer need be supported.
if (!podSpec.getNetworks().isEmpty() && (!useDefaultExecutor || !isTaskContainer)) {
containerInfo.addAllNetworkInfos(
podSpec.getNetworks().stream().map(PodInfoBuilder::getNetworkInfo).collect(Collectors.toList()));
}
if (!podSpec.getRLimits().isEmpty() && addExtraParameters) {
containerInfo.setRlimitInfo(getRLimitInfo(podSpec.getRLimits()));
}
if (addExtraParameters) {
for (Protos.Volume secretVolume : secretVolumes) {
containerInfo.addVolumes(secretVolume);
}
}
return containerInfo.build();
}
示例9: findVolumeWithContainerPath
import org.apache.mesos.Protos; //导入方法依赖的package包/类
private Optional<Protos.Volume> findVolumeWithContainerPath(Protos.ContainerInfo container, String path) {
return container.getVolumesList().stream()
.filter(volume -> volume.getContainerPath().equals(path))
.findAny();
}