use of org.apache.mesos.v1.Protos.Parameters in project Singularity by HubSpot.
the class SingularityMesosTaskBuilder method prepareContainerInfo.
private void prepareContainerInfo(final SingularityOfferHolder offerHolder, 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()));
}
final List<SingularityDockerPortMapping> portMappings = dockerInfo.get().getPortMappings();
final boolean isBridged = SingularityDockerNetworkType.BRIDGE.equals(dockerInfo.get().getNetwork().orNull());
if ((dockerInfo.get().hasAllLiteralHostPortMappings() || ports.isPresent()) && !portMappings.isEmpty()) {
for (SingularityDockerPortMapping singularityDockerPortMapping : portMappings) {
final Optional<DockerInfo.PortMapping> maybePortMapping = buildPortMapping(singularityDockerPortMapping, ports);
if (maybePortMapping.isPresent()) {
dockerInfoBuilder.addPortMappings(maybePortMapping.get());
}
}
} else if (configuration.getNetworkConfiguration().isDefaultPortMapping() && isBridged && portMappings.isEmpty() && ports.isPresent()) {
for (long longPort : ports.get()) {
int port = Ints.checkedCast(longPort);
dockerInfoBuilder.addPortMappings(DockerInfo.PortMapping.newBuilder().setHostPort(port).setContainerPort(port).build());
}
}
if (!dockerInfo.get().getDockerParameters().isEmpty()) {
List<Parameter> parameters = new ArrayList<>();
for (SingularityDockerParameter parameter : dockerInfo.get().getDockerParameters()) {
parameters.add(Parameter.newBuilder().setKey(parameter.getKey()).setValue(parameter.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(), offerHolder, taskId));
if (volumeInfo.getHostPath().isPresent()) {
volumeBuilder.setHostPath(fillInTaskIdValues(volumeInfo.getHostPath().get(), offerHolder, taskId));
}
if (volumeInfo.getMode().isPresent()) {
volumeBuilder.setMode(Volume.Mode.valueOf(volumeInfo.getMode().get().toString()));
} else {
volumeBuilder.setMode(Volume.Mode.RO);
}
if (volumeInfo.getSource().isPresent()) {
final Volume.Source.Builder sourceBuilder = Volume.Source.newBuilder();
final SingularityVolumeSource source = volumeInfo.getSource().get();
sourceBuilder.setType(Volume.Source.Type.valueOf(source.getType().toString()));
if (source.getDockerVolume().isPresent()) {
final Volume.Source.DockerVolume.Builder dockerVolumeBuilder = Volume.Source.DockerVolume.newBuilder();
final SingularityDockerVolume dockerVolume = source.getDockerVolume().get();
if (dockerVolume.getDriver().isPresent()) {
dockerVolumeBuilder.setDriver(dockerVolume.getDriver().get());
}
if (dockerVolume.getName().isPresent()) {
dockerVolumeBuilder.setName(dockerVolume.getName().get().replace("%i", Integer.toString(taskId.getInstanceNo())));
}
if (!dockerVolume.getDriverOptions().isEmpty()) {
final Parameters.Builder parameters = Parameters.newBuilder();
for (Entry<String, String> option : dockerVolume.getDriverOptions().entrySet()) {
parameters.addParameter(Parameter.newBuilder().setKey(option.getKey()).setValue(option.getValue()).build());
}
dockerVolumeBuilder.setDriverOptions(parameters.build());
}
sourceBuilder.setDockerVolume(dockerVolumeBuilder.build());
}
volumeBuilder.setSource(sourceBuilder.build());
}
containerBuilder.addVolumes(volumeBuilder);
}
prepareMesosInfo(containerBuilder, containerInfo);
prepareNetworkInfos(containerBuilder, containerInfo, ports);
bldr.setContainer(containerBuilder);
}
Aggregations