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


Java ContainerPortBuilder类代码示例

本文整理汇总了Java中io.fabric8.kubernetes.api.model.ContainerPortBuilder的典型用法代码示例。如果您正苦于以下问题:Java ContainerPortBuilder类的具体用法?Java ContainerPortBuilder怎么用?Java ContainerPortBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContainerPortBuilder类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了ContainerPortBuilder类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldNotAddAdditionalContainerPortWhenItIsAlreadyExposed

import io.fabric8.kubernetes.api.model.ContainerPortBuilder; //导入依赖的package包/类
@Test
public void shouldNotAddAdditionalContainerPortWhenItIsAlreadyExposed() {
  // given
  ServerConfigImpl httpServerConfig =
      new ServerConfigImpl("8080/tcp", "http", "/api", ATTRIBUTES_MAP);
  Map<String, ServerConfigImpl> serversToExpose =
      ImmutableMap.of("http-server", httpServerConfig);
  container.setPorts(
      singletonList(
          new ContainerPortBuilder()
              .withName("port-8080")
              .withContainerPort(8080)
              .withProtocol("TCP")
              .build()));

  // when
  serverExposer.expose(serversToExpose);

  // then
  assertThatExternalServerIsExposed(
      MACHINE_NAME,
      "http-server",
      "tcp",
      8080,
      new ServerConfigImpl(httpServerConfig).withAttributes(ATTRIBUTES_MAP));
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:ServerExposerTest.java

示例2: exposePort

import io.fabric8.kubernetes.api.model.ContainerPortBuilder; //导入依赖的package包/类
private Map<String, ServicePort> exposePort(Collection<? extends ServerConfig> serverConfig) {
  Map<String, ServicePort> exposedPorts = new HashMap<>();
  Set<String> portsToExpose =
      serverConfig.stream().map(ServerConfig::getPort).collect(Collectors.toSet());

  for (String portToExpose : portsToExpose) {
    String[] portProtocol = portToExpose.split("/");
    int port = parseInt(portProtocol[0]);
    String protocol = portProtocol.length > 1 ? portProtocol[1].toUpperCase() : "TCP";
    Optional<ContainerPort> exposedOpt =
        container
            .getPorts()
            .stream()
            .filter(p -> p.getContainerPort().equals(port) && protocol.equals(p.getProtocol()))
            .findAny();
    ContainerPort containerPort;

    if (exposedOpt.isPresent()) {
      containerPort = exposedOpt.get();
    } else {
      containerPort =
          new ContainerPortBuilder().withContainerPort(port).withProtocol(protocol).build();
      container.getPorts().add(containerPort);
    }

    exposedPorts.put(
        portToExpose,
        new ServicePortBuilder()
            .withName("server-" + containerPort.getContainerPort())
            .withPort(containerPort.getContainerPort())
            .withProtocol(protocol)
            .withNewTargetPort(containerPort.getContainerPort())
            .build());
  }
  return exposedPorts;
}
 
开发者ID:eclipse,项目名称:che,代码行数:37,代码来源:ServerExposer.java

示例3: mockContainer

import io.fabric8.kubernetes.api.model.ContainerPortBuilder; //导入依赖的package包/类
private static Container mockContainer(String name, int... ports) {
  final Container container = mock(Container.class);
  when(container.getName()).thenReturn(name);
  final List<ContainerPort> containerPorts = new ArrayList<>(ports.length);
  for (int port : ports) {
    containerPorts.add(new ContainerPortBuilder().withContainerPort(port).build());
  }
  when(container.getPorts()).thenReturn(containerPorts);
  return container;
}
 
开发者ID:eclipse,项目名称:che,代码行数:11,代码来源:OpenShiftInternalRuntimeTest.java

示例4: shouldAddAdditionalContainerPortWhenThereIsTheSameButWithDifferentProtocol

import io.fabric8.kubernetes.api.model.ContainerPortBuilder; //导入依赖的package包/类
@Test
public void shouldAddAdditionalContainerPortWhenThereIsTheSameButWithDifferentProtocol() {
  // given
  ServerConfigImpl udpServerConfig =
      new ServerConfigImpl("8080/udp", "udp", "/api", ATTRIBUTES_MAP);
  Map<String, ServerConfigImpl> serversToExpose = ImmutableMap.of("server", udpServerConfig);
  container.setPorts(
      new ArrayList<>(
          singletonList(
              new ContainerPortBuilder()
                  .withName("port-8080")
                  .withContainerPort(8080)
                  .withProtocol("TCP")
                  .build())));

  // when
  serverExposer.expose(serversToExpose);

  // then
  assertEquals(container.getPorts().size(), 2);
  assertEquals(container.getPorts().get(1).getContainerPort(), new Integer(8080));
  assertEquals(container.getPorts().get(1).getProtocol(), "UDP");
  assertThatExternalServerIsExposed(
      MACHINE_NAME,
      "server",
      "udp",
      8080,
      new ServerConfigImpl(udpServerConfig).withAttributes(ATTRIBUTES_MAP));
}
 
开发者ID:eclipse,项目名称:che,代码行数:30,代码来源:ServerExposerTest.java

示例5: toContainerPort

import io.fabric8.kubernetes.api.model.ContainerPortBuilder; //导入依赖的package包/类
public ContainerPort toContainerPort() {
    return new ContainerPortBuilder().withName(getName()).withContainerPort(port).build();
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:4,代码来源:Port.java

示例6: getOpenContainerPorts

import io.fabric8.kubernetes.api.model.ContainerPortBuilder; //导入依赖的package包/类
public List<ContainerPort> getOpenContainerPorts() {
    List<ContainerPort> ports = new ArrayList<>();
    openPorts.forEach(e -> ports.add(new ContainerPortBuilder().withContainerPort(e).build()));
    return Collections.unmodifiableList(ports);
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:6,代码来源:NodeStack.java

示例7: build

import io.fabric8.kubernetes.api.model.ContainerPortBuilder; //导入依赖的package包/类
public Container build() {
	io.fabric8.kubernetes.api.model.ContainerBuilder builder = new io.fabric8.kubernetes.api.model.ContainerBuilder();

	Stream<EnvVar> definedVars = envVars.entrySet().stream().map(entry -> new EnvVar(entry.getKey(), entry.getValue(), null));
	Stream<EnvVar> referredVars = referredEnvVars.entrySet().stream().map(entry -> new EnvVar(entry.getKey(), null, new EnvVarSource(new ConfigMapKeySelectorBuilder().withKey(entry.getValue().getSecond()).withName(entry.getValue().getFirst()).build(), null, null, null)));
	builder.withEnv(Stream.concat(definedVars, referredVars).collect(Collectors.toList()));
	builder.withImage(imageName);
	builder.withImagePullPolicy("Always");

	if (command != null) {
		builder.withCommand(command);
	}

	if (livenessProbe != null) {
		builder.withLivenessProbe(livenessProbe.build());
	}

	builder.withName(name);

	builder.withPorts(ports.stream().map(port -> {
		ContainerPortBuilder portBuilder = new ContainerPortBuilder();
		portBuilder.withContainerPort(port.getContainerPort());
		if (port.getProtocol() != null) {
			portBuilder.withProtocol(port.getProtocol().uppercase());
		}
		if (port.getName() != null) {
			portBuilder.withName(port.getName());
		}

		return portBuilder.build();
	}).collect(Collectors.toList()));

	if (preStopHandler != null) {
		builder.withNewLifecycle()
				.withPreStop(preStopHandler.build())
				.endLifecycle();
	}

	if (privileged) {
		builder.withNewSecurityContext().withPrivileged(true).endSecurityContext();
	}

	if (readinessProbe != null) {
		builder.withReadinessProbe(readinessProbe.build());
	}

	builder.withVolumeMounts(volumeMounts.stream().map(item -> new VolumeMountBuilder()
			.withName(item.getName())
			.withMountPath(item.getMountPath())
			.withReadOnly(item.isReadOnly())
			.build()).collect(Collectors.toList()));

	final List<ComputingResource> requests = computingResources.values().stream().filter(x -> x.getRequests() != null).collect(Collectors.toList());
	final List<ComputingResource> limits = computingResources.values().stream().filter(x -> x.getLimits() != null).collect(Collectors.toList());
	if (!requests.isEmpty() || !limits.isEmpty())
	{
		ResourcesNested<io.fabric8.kubernetes.api.model.ContainerBuilder> resources = builder.withNewResources();
		if (!requests.isEmpty()) {
			resources.withRequests(
					requests.stream().collect(Collectors.toMap(
							ComputingResource::resourceIdentifier, x -> new Quantity(x.getRequests())
					)));
		}
		if (!limits.isEmpty()) {
			resources.withLimits(
					limits.stream().collect(Collectors.toMap(
							ComputingResource::resourceIdentifier, x -> new Quantity(x.getLimits())
					)));
		}
		resources.endResources();
	}
	// args
	// capabilities
	// command
	// lifecycle
	// resources
	// securityContext
	// terminationMessagePath
	// workingDir
	return builder.build();
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:82,代码来源:ContainerBuilder.java

示例8: newContainerPort

import io.fabric8.kubernetes.api.model.ContainerPortBuilder; //导入依赖的package包/类
private ContainerPort newContainerPort(final int port) {
    return new ContainerPortBuilder().withContainerPort(port).build();
}
 
开发者ID:fabzo,项目名称:kraken,代码行数:4,代码来源:KubernetesLifecycleHandler.java


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