本文整理汇总了Java中io.fabric8.kubernetes.api.model.ServiceSpec类的典型用法代码示例。如果您正苦于以下问题:Java ServiceSpec类的具体用法?Java ServiceSpec怎么用?Java ServiceSpec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServiceSpec类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了ServiceSpec类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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);
}
示例2: initService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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);
}
示例3: initService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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);
}
示例4: initService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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);
}
示例5: initService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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);
}
示例6: initService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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);
}
示例7: ServiceInstance
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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();
}
示例8: createService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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;
}
示例9: createServiceSpec
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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;
}
示例10: doCreateService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的package包/类
protected void doCreateService(Exchange exchange, String operation)
throws Exception {
Service service = null;
String serviceName = exchange.getIn().getHeader(
KubernetesConstants.KUBERNETES_SERVICE_NAME, String.class);
String namespaceName = exchange.getIn().getHeader(
KubernetesConstants.KUBERNETES_NAMESPACE_NAME, String.class);
ServiceSpec serviceSpec = exchange.getIn().getHeader(
KubernetesConstants.KUBERNETES_SERVICE_SPEC, ServiceSpec.class);
if (ObjectHelper.isEmpty(serviceName)) {
LOG.error("Create a specific service require specify a service name");
throw new IllegalArgumentException(
"Create a specific service require specify a service name");
}
if (ObjectHelper.isEmpty(namespaceName)) {
LOG.error("Create a specific service require specify a namespace name");
throw new IllegalArgumentException(
"Create a specific service require specify a namespace name");
}
if (ObjectHelper.isEmpty(serviceSpec)) {
LOG.error("Create a specific service require specify a service spec bean");
throw new IllegalArgumentException(
"Create a specific service require specify a service spec bean");
}
Map<String, String> labels = exchange.getIn().getHeader(
KubernetesConstants.KUBERNETES_SERVICE_LABELS, Map.class);
EditableService serviceCreating = new ServiceBuilder()
.withNewMetadata().withName(serviceName).withLabels(labels)
.endMetadata().withSpec(serviceSpec).build();
service = getEndpoint().getKubernetesClient().services()
.inNamespace(namespaceName).create(serviceCreating);
exchange.getOut().setBody(service);
}
示例11: findServices
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的package包/类
@Test
public void findServices() {
final ObjectMeta build = new ObjectMetaBuilder().addToLabels("test", "test").build();
final ServiceSpec spec = new ServiceSpecBuilder().addNewPort().and()
.withClusterIP("192.168.1.1").build();
final Service service = new ServiceBuilder().withMetadata(build).withSpec(spec).build();
server.expect().withPath("/api/v1/namespaces/default/services").andReturn(200, new ServiceListBuilder().addToItems().addToItems(service).build()).once();
KubernetesClient client = this.client;
final ServiceList list = client.services().inNamespace("default").list();
assertNotNull(list);
assertEquals("test", list.getItems().get(0).getMetadata().getLabels().get("test"));
System.out.println(list.getItems().get(0).getSpec().getClusterIP());
}
示例12: putSelector
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的package包/类
/** Adds selector into target OpenShift service. */
public static void putSelector(Service target, String key, String value) {
ServiceSpec spec = target.getSpec();
if (spec == null) {
target.setSpec(spec = new ServiceSpec());
}
Map<String, String> selector = spec.getSelector();
if (selector == null) {
spec.setSelector(selector = new HashMap<>());
}
selector.put(key, value);
}
示例13: mockService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的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;
}
示例14: createEndpointsForService
import io.fabric8.kubernetes.api.model.ServiceSpec; //导入依赖的package包/类
protected static Endpoints createEndpointsForService(Service service, List<Pod> pods) {
if (service == null) {
return null;
}
ServiceSpec serviceSpec = service.getSpec();
if (serviceSpec == null) {
return null;
}
List<EndpointAddress> addresses = new ArrayList<>();
String namespace = KubernetesHelper.getNamespace(service);
String serviceName = getName(service);
String qualifiedServiceName = namespace + ":" + serviceName;
List<ServicePort> ports = serviceSpec.getPorts();
for (ServicePort servicePort : ports) {
IntOrString targetPort = servicePort.getTargetPort();
Integer portNumber = KubernetesHelper.intOrStringToInteger(targetPort, qualifiedServiceName);
if (portNumber != null) {
List<Pod> podsForService = KubernetesHelper.getPodsForService(service, pods);
for (Pod pod : podsForService) {
PodStatus currentState = pod.getStatus();
if (currentState != null) {
String podIP = currentState.getPodIP();
if (podIP != null) {
String url = podIP + ":" + portNumber;
EndpointAddress address = new EndpointAddress();
address.setIp(podIP);
ObjectReference ref = new ObjectReference();
ref.setNamespace(namespace);
ref.setName(getName(pod));
address.setTargetRef(ref);
addresses.add(address);
}
}
}
}
}
EndpointSubset subset = new EndpointSubset();
subset.setAddresses(addresses);
return new EndpointsBuilder().
withNewMetadata().withName(serviceName).withNamespace(namespace).endMetadata().
addToSubsets(subset).
build();
}