当前位置: 首页>>代码示例>>Java>>正文


Java ContainerInfo.Builder方法代码示例

本文整理汇总了Java中org.apache.mesos.Protos.ContainerInfo.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerInfo.Builder方法的具体用法?Java ContainerInfo.Builder怎么用?Java ContainerInfo.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mesos.Protos.ContainerInfo的用法示例。


在下文中一共展示了ContainerInfo.Builder方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
}
 
开发者ID:Praqma,项目名称:mesos-kibana,代码行数:24,代码来源:TaskInfoFactory.java

示例2: 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);
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:56,代码来源:SingularityMesosTaskBuilder.java

示例3: 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();
}
 
开发者ID:PacktPublishing,项目名称:Mastering-Mesos,代码行数:79,代码来源:Utils.java


注:本文中的org.apache.mesos.Protos.ContainerInfo.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。