本文整理汇总了Java中io.fabric8.kubernetes.api.model.ServicePort类的典型用法代码示例。如果您正苦于以下问题:Java ServicePort类的具体用法?Java ServicePort怎么用?Java ServicePort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServicePort类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了ServicePort类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public void initService() {
final ObjectMeta buildmyTestService = new ObjectMetaBuilder().addToLabels("test", "test").withName("myTestService").build();
final ServicePort portmyTestService = new ServicePortBuilder().withPort(8080).withProtocol("http").build();
final ServiceSpec specmyTestService = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.1").withPorts(portmyTestService).build();
final ObjectMeta buildmyTestService2 = new ObjectMetaBuilder().addToLabels("test", "test2").withName("myTestService2").build();
final ServicePort portmyTestService2 = new ServicePortBuilder().withPort(9080).withProtocol("http").build();
final ServiceSpec specmyTestService2 = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.2").withPorts(portmyTestService2).build();
final Service servicemyTestService = new ServiceBuilder().withMetadata(buildmyTestService).withSpec(specmyTestService).build();
final Service servicemyTestService2 = new ServiceBuilder().withMetadata(buildmyTestService2).withSpec(specmyTestService2).build();
server.expect().withPath("/api/v1/namespaces/default/services").andReturn(200, new ServiceListBuilder().addToItems(servicemyTestService,servicemyTestService2).build()).times(2);
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:17,代码来源:ResolveServicesByNameTest.java
示例2: initService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public void initService() {
final ObjectMeta buildmyTestService = new ObjectMetaBuilder().addToLabels("name", "myTestService").addToLabels("version", "v1").withName("myTestService").build();
final ServicePort portmyTestService = new ServicePortBuilder().withPort(8080).withProtocol("http").build();
final ServiceSpec specmyTestService = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.1").withPorts(portmyTestService).build();
final ObjectMeta buildmyTestService2 = new ObjectMetaBuilder().addToLabels("name", "myTestService").addToLabels("version", "v2").withName("myTestService2").build();
final ServicePort portmyTestService2 = new ServicePortBuilder().withPort(9080).withProtocol("http").build();
final ServiceSpec specmyTestService2 = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.2").withPorts(portmyTestService2).build();
final Service servicemyTestService = new ServiceBuilder().withMetadata(buildmyTestService).withSpec(specmyTestService).build();
final Service servicemyTestService2 = new ServiceBuilder().withMetadata(buildmyTestService2).withSpec(specmyTestService2).build();
server.expect().withPath("/api/v1/namespaces/default/services?labelSelector=name%3DmyTestService,version%3Dv1").andReturn(200, new ServiceListBuilder().addToItems(servicemyTestService).build()).times(1);
server.expect().withPath("/api/v1/namespaces/default/services?labelSelector=name%3DmyTestService,version%3Dv2").andReturn(200, new ServiceListBuilder().addToItems(servicemyTestService2).build()).times(1);
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:18,代码来源:ResolveServicesByLabelsConfigAndPortOKOfflineTest.java
示例3: initService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public void initService() {
final ObjectMeta buildmyTestService = new ObjectMetaBuilder().addToLabels("test", "test").withName("myTestService").build();
final ServicePort portmyTestService_1 = new ServicePortBuilder().withName("mainhttp").withPort(8080).withProtocol("http").build();
final ServicePort portmyTestService_2 = new ServicePortBuilder().withName("mytcp").withPort(9090).withProtocol("tcp").build();
final ServiceSpec specmyTestService = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.1").withPorts(portmyTestService_1,portmyTestService_2).build();
final ObjectMeta buildmyTestService2 = new ObjectMetaBuilder().addToLabels("test", "test2").withName("myTestService2").build();
final ServicePort portmyTestService2_1 = new ServicePortBuilder().withPort(9080).withProtocol("http").build();
final ServicePort portmyTestService2_2 = new ServicePortBuilder().withName("test").withPort(9090).withProtocol("http").build();
final ServiceSpec specmyTestService2 = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.2").withPorts(portmyTestService2_1,portmyTestService2_2).build();
final Service servicemyTestService = new ServiceBuilder().withMetadata(buildmyTestService).withSpec(specmyTestService).build();
final Service servicemyTestService2 = new ServiceBuilder().withMetadata(buildmyTestService2).withSpec(specmyTestService2).build();
server.expect().withPath("/api/v1/namespaces/default/services").andReturn(200, new ServiceListBuilder().addToItems(servicemyTestService,servicemyTestService2).build()).times(2);
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:19,代码来源:ResolveServicesByLAbelsWithPortNameTest.java
示例4: initService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public void initService() {
final ObjectMeta buildmyTestService = new ObjectMetaBuilder().addToLabels("name", "myTestService").addToLabels("version", "v1").withName("myTestService").build();
final ServicePort portmyTestService = new ServicePortBuilder().withPort(8080).withProtocol("http").build();
final ServiceSpec specmyTestService = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.1").withPorts(portmyTestService).build();
final ObjectMeta buildmyTestService2 = new ObjectMetaBuilder().addToLabels("name", "myTestService").addToLabels("version", "v2").withName("myTestService2").build();
final ServicePort portmyTestService2 = new ServicePortBuilder().withPort(9080).withProtocol("http").build();
final ServiceSpec specmyTestService2 = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.2").withPorts(portmyTestService2).build();
final Service servicemyTestService = new ServiceBuilder().withMetadata(buildmyTestService).withSpec(specmyTestService).build();
final Service servicemyTestService2 = new ServiceBuilder().withMetadata(buildmyTestService2).withSpec(specmyTestService2).build();
server.expect().withPath("/api/v1/namespaces/default/services?labelSelector=name%3DmyTestService").andReturn(200, new ServiceListBuilder().addToItems(servicemyTestService,servicemyTestService2).build()).times(2);
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:17,代码来源:ResolveServicesByLabelsTooManyNOKTest.java
示例5: initService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public void initService() {
final ObjectMeta buildmyTestService = new ObjectMetaBuilder().addToLabels("name", "myTestService").addToLabels("version", "v1").withName("myTestService").build();
final ServicePort portmyTestService = new ServicePortBuilder().withPort(8080).withProtocol("http").build();
final ServiceSpec specmyTestService = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.1").withPorts(portmyTestService).build();
final ObjectMeta buildmyTestService2 = new ObjectMetaBuilder().addToLabels("name", "myTestService").addToLabels("version", "v2").withName("myTestService2").build();
final ServicePort portmyTestService2 = new ServicePortBuilder().withPort(9080).withProtocol("http").build();
final ServiceSpec specmyTestService2 = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.2").withPorts(portmyTestService2).build();
final Service servicemyTestService = new ServiceBuilder().withMetadata(buildmyTestService).withSpec(specmyTestService).build();
final Service servicemyTestService2 = new ServiceBuilder().withMetadata(buildmyTestService2).withSpec(specmyTestService2).build();
server.expect().withPath("/api/v1/namespaces/default/services?labelSelector=version%3Dv1").andReturn(200, new ServiceListBuilder().addToItems(servicemyTestService).build()).times(1);
server.expect().withPath("/api/v1/namespaces/default/services?labelSelector=version%3Dv2").andReturn(200, new ServiceListBuilder().addToItems(servicemyTestService2).build()).times(1);
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:18,代码来源:ResolveServicesByLabelOKTest.java
示例6: initService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public void initService() {
final ObjectMeta buildmyTestService = new ObjectMetaBuilder().addToLabels("name", "myTestService").addToLabels("version", "v1").withName("myTestService").build();
final ServicePort portmyTestService = new ServicePortBuilder().withPort(8080).withProtocol("http").build();
final ServiceSpec specmyTestService = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.1").withPorts(portmyTestService).build();
final ObjectMeta buildmyTestService2 = new ObjectMetaBuilder().addToLabels("name", "myTestService").addToLabels("version", "v2").withName("myTestService2").build();
final ServicePort portmyTestService2 = new ServicePortBuilder().withPort(9080).withProtocol("http").build();
final ServiceSpec specmyTestService2 = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.2").withPorts(portmyTestService2).build();
final Service servicemyTestService = new ServiceBuilder().withMetadata(buildmyTestService).withSpec(specmyTestService).build();
final Service servicemyTestService2 = new ServiceBuilder().withMetadata(buildmyTestService2).withSpec(specmyTestService2).build();
server.expect().withPath("/api/v1/namespaces/default/services?labelSelector=service1x.name%3Dservice1x.value").andReturn(200, new ServiceListBuilder().build()).times(1);
server.expect().withPath("/api/v1/namespaces/default/services?labelSelector=service2x.name%3Dservice2x.value").andReturn(200, new ServiceListBuilder().build()).times(1);
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:18,代码来源:ResolveServicesByLabelWithConfigNOKTest.java
示例7: ServiceInstance
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public ServiceInstance(Service service) {
this.service = service;
this.id = getName(service);
ServiceSpec spec = KubernetesHelper.getOrCreateSpec(service);
List<ServicePort> ports = spec.getPorts();
if (spec.getPortalIP().equals(HEADLESS_PORTAL_IP)) {
//do nothing service is headless
} else if (ports != null && !ports.isEmpty()) {
for (ServicePort servicePort : ports) {
servicePorts.add(toNamedServicePort(id, servicePort));
}
} else {
throw new IllegalArgumentException("Service: " + id + " doesn't have a valid port configuration.");
}
this.selector = KubernetesHelper.getSelector(service);
Objects.notNull(this.selector, "No selector for service " + id);
if (selector.isEmpty()) {
throw new IllegalArgumentException("Empty selector for service " + id);
}
this.filter = KubernetesHelper.createPodFilter(selector);
// TODO should we use some service metadata to choose the load balancer?
this.loadBalancer = new RoundRobinLoadBalancer();
}
开发者ID:fabric8io,项目名称:jube,代码行数:25,代码来源:ServiceInstance.java
示例8: ContainerService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public ContainerService(ServicePort servicePort, Pod pod) throws URISyntaxException {
this.servicePort = servicePort;
this.pod = pod;
int serviceContainerPort = KubernetesHelper.intOrStringToInteger(servicePort.getTargetPort(), this.toString());
int port = NodeHelper.findHostPortForService(pod, serviceContainerPort);
// lets get host / port of the container
String host = null;
PodStatus currentState = pod.getStatus();
if (currentState != null) {
host = currentState.getHostIP();
if (Strings.isBlank(host)) {
host = currentState.getPodIP();
}
}
if (Strings.isBlank(host)) {
throw new IllegalArgumentException("No host for pod " + KubernetesHelper.getName(pod) + " so cannot use it with service port: " + servicePort.getName());
} else {
uri = new URI("tcp://" + host + ":" + port);
}
}
开发者ID:fabric8io,项目名称:jube,代码行数:22,代码来源:ContainerService.java
示例9: createService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
protected Service createService(String hostName, String port) {
Service service = new Service();
ServiceSpec spec = getOrCreateSpec(service);
try {
Integer portNumber = Integer.parseInt(port);
if (portNumber != null) {
List<ServicePort> ports = new ArrayList<>();
ServicePort servicePort = new ServicePort();
servicePort.setPort(portNumber);
IntOrString containerPort = new IntOrString();
containerPort.setIntVal(portNumber);
servicePort.setTargetPort(containerPort);
ports.add(servicePort);
spec.setPorts(ports);
}
} catch (NumberFormatException e) {
LOG.warn("Failed to parse port text: " + port + ". " + e, e);
}
spec.setPortalIP(hostName);
return service;
}
开发者ID:fabric8io,项目名称:jube,代码行数:23,代码来源:ApiMasterService.java
示例10: createServiceSpec
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
protected ServiceSpec createServiceSpec(final Map<String, String> labels) {
final ServiceSpec serviceSpec = new ServiceSpec();
serviceSpec.setType("ClusterIP");
final ServicePort servicePort = new ServicePort();
servicePort.setName(DEFAULT_NAME);
servicePort.setPort(Integer.valueOf(44134));
servicePort.setTargetPort(new IntOrString(DEFAULT_NAME));
serviceSpec.setPorts(Arrays.asList(servicePort));
serviceSpec.setSelector(normalizeLabels(labels));
return serviceSpec;
}
开发者ID:microbean,项目名称:microbean-helm,代码行数:14,代码来源:TillerInstaller.java
示例11: build
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
@Override
public ServicePort build() {
if (targetPort == 0) {
throw new IllegalStateException("targetPort must be set for service");
}
ServicePortBuilder servicePort = new ServicePortBuilder();
if (StringUtils.isNotBlank(getName())) { servicePort.withName(getName()); }
servicePort.withProtocol(protocol.uppercase())
.withPort(port)
.withNewTargetPort(targetPort);
return servicePort.build();
}
开发者ID:xtf-cz,项目名称:xtf,代码行数:13,代码来源:PortBuilder.java
示例12: testUpdate
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public void testUpdate() throws ResourceException {
// Check that the service doesn't exist already
Service serviceV1 = KubernetesClientUtil.retrieveService(kubernetesClient, serviceResourceV1);
assertNull(serviceV1);
// Create service
serviceResourceV1.create();
// Retrieve service v1
serviceV1 = KubernetesClientUtil.retrieveService(kubernetesClient, serviceResourceV1);
// Update service
serviceResourceV2.update();
// Retrieve service v2
Service serviceV2 = KubernetesClientUtil.retrieveService(kubernetesClient, serviceResourceV1);
// Check service
assertFalse(serviceV1.equals(serviceV2));
List<ServicePort> portsV1 = serviceV1.getSpec().getPorts();
List<ServicePort> portsV2 = serviceV2.getSpec().getPorts();
assertEquals(1, portsV1.size());
assertEquals(1, portsV2.size());
assertEquals(new Integer(8761), portsV1.get(0).getPort());
assertEquals(new Integer(8762), portsV2.get(0).getPort());
}
开发者ID:qaware,项目名称:gradle-cloud-deployer,代码行数:28,代码来源:ServiceResourceIntegrationTest.java
示例13: testEmptyUpdate
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
public void testEmptyUpdate() throws ResourceException {
// Check that the service doesn't exist already
Service serviceV1 = KubernetesClientUtil.retrieveService(kubernetesClient, serviceResourceV1);
assertNull(serviceV1);
// Create service
serviceResourceV1.create();
// Retrieve service v1
serviceV1 = KubernetesClientUtil.retrieveService(kubernetesClient, serviceResourceV1);
// Update service v1
serviceResourceV1.update();
// Retrieve service v2
Service serviceV2 = KubernetesClientUtil.retrieveService(kubernetesClient, serviceResourceV1);
// Check service
assertEquals(serviceV1.getMetadata().getUid(), serviceV2.getMetadata().getUid());
assertEquals(serviceV1.getMetadata().getCreationTimestamp(), serviceV2.getMetadata().getCreationTimestamp());
List<ServicePort> portsV1 = serviceV1.getSpec().getPorts();
List<ServicePort> portsV2 = serviceV2.getSpec().getPorts();
assertEquals(1, portsV1.size());
assertEquals(1, portsV2.size());
assertEquals(new Integer(8761), portsV1.get(0).getPort());
assertEquals(new Integer(8761), portsV2.get(0).getPort());
}
开发者ID:qaware,项目名称:gradle-cloud-deployer,代码行数:29,代码来源:ServiceResourceIntegrationTest.java
示例14: getHostString
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
private static String getHostString(
Service serviceEntry, JsonObject env, Field serviceNameField) {
String hostString = "";
final String clusterIP = serviceEntry.getSpec().getClusterIP();
final List<ServicePort> ports = serviceEntry.getSpec().getPorts();
if (serviceNameField.isAnnotationPresent(PortName.class)) {
hostString = resolveServiceWithPortName(env, serviceNameField, clusterIP, ports);
} else {
hostString = resolveService(hostString, clusterIP, ports);
}
return hostString;
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:13,代码来源:KubeDiscovery.java
示例15: resolveService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
private static String resolveService(
String hostString, String clusterIP, List<ServicePort> ports) {
if (ports.size() >= 1) {
final ServicePort servicePort = ports.get(0);
final String protocol = servicePort.getProtocol();
hostString = buildServiceHostString(clusterIP, servicePort, protocol);
}
return hostString;
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:10,代码来源:KubeDiscovery.java
示例16: resolveServiceWithPortName
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
private static String resolveServiceWithPortName(
JsonObject env, Field serviceNameField, String clusterIP, List<ServicePort> ports) {
String hostString = null;
final PortName portNameAnnotation = serviceNameField.getAnnotation(PortName.class);
final String portName = resolveProperty(env, portNameAnnotation.value());
final Optional<ServicePort> portMatch = findPortByName(ports, portName);
if (portMatch.isPresent()) {
final ServicePort port = portMatch.get();
final String protocol = port.getProtocol();
hostString = buildServiceHostString(clusterIP, port, protocol);
}
return hostString;
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:14,代码来源:KubeDiscovery.java
示例17: buildServiceHostString
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
private static String buildServiceHostString(
String clusterIP, ServicePort port, String protocol) {
String hostString;
if (StringUtil.isNullOrEmpty(protocol)) {
hostString = clusterIP + SEPERATOR + port.getPort();
} else {
hostString = protocol + "://" + clusterIP + SEPERATOR + port.getPort();
}
return hostString;
}
开发者ID:amoAHCP,项目名称:vxms,代码行数:11,代码来源:KubeDiscovery.java
示例18: exposePort
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的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
示例19: mockService
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
private static Service mockService() {
final Service service = mock(Service.class);
final ServiceSpec spec = mock(ServiceSpec.class);
mockName(SERVICE_NAME, service);
when(service.getSpec()).thenReturn(spec);
when(spec.getSelector()).thenReturn(ImmutableMap.of(POD_SELECTOR, POD_NAME));
final ServicePort sp1 =
new ServicePortBuilder().withTargetPort(intOrString(EXPOSED_PORT_1)).build();
final ServicePort sp2 =
new ServicePortBuilder().withTargetPort(intOrString(EXPOSED_PORT_2)).build();
when(spec.getPorts()).thenReturn(ImmutableList.of(sp1, sp2));
return service;
}
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:OpenShiftInternalRuntimeTest.java
示例20: toNamedServicePort
import io.fabric8.kubernetes.api.model.ServicePort; //导入依赖的package包/类
private static ServicePort toNamedServicePort(String serviceId, ServicePort servicePort) {
String portName = servicePort.getName();
String protocol = servicePort.getProtocol();
Integer nodePort = servicePort.getNodePort();
IntOrString targetPort = servicePort.getTargetPort();
String name = !Strings.isNullOrBlank(portName) ? portName : serviceId + "-" + targetPort.toString();
int port = KubernetesHelper.intOrStringToInteger(targetPort, "service: " + name);
return new ServicePort(name, nodePort, port, protocol, targetPort);
}
开发者ID:fabric8io,项目名称:jube,代码行数:10,代码来源:ServiceInstance.java
注:本文中的io.fabric8.kubernetes.api.model.ServicePort类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论