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


Java ServiceSpec类代码示例

本文整理汇总了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);

}
 
开发者ID:amoAHCP,项目名称:vxms,代码行数:17,代码来源:ResolveServicesByNameTest.java

示例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);

}
 
开发者ID:amoAHCP,项目名称:vxms,代码行数:18,代码来源:ResolveServicesByLabelsConfigAndPortOKOfflineTest.java

示例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);

}
 
开发者ID:amoAHCP,项目名称:vxms,代码行数:19,代码来源:ResolveServicesByLAbelsWithPortNameTest.java

示例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);

}
 
开发者ID:amoAHCP,项目名称:vxms,代码行数:17,代码来源:ResolveServicesByLabelsTooManyNOKTest.java

示例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);

}
 
开发者ID:amoAHCP,项目名称:vxms,代码行数:18,代码来源:ResolveServicesByLabelOKTest.java

示例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);

}
 
开发者ID:amoAHCP,项目名称:vxms,代码行数:18,代码来源:ResolveServicesByLabelWithConfigNOKTest.java

示例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();
}
 
开发者ID:fabric8io,项目名称:jube,代码行数:25,代码来源:ServiceInstance.java

示例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;
}
 
开发者ID:fabric8io,项目名称:jube,代码行数:23,代码来源:ApiMasterService.java

示例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;
}
 
开发者ID:microbean,项目名称:microbean-helm,代码行数:14,代码来源:TillerInstaller.java

示例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);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:34,代码来源:KubernetesServicesProducer.java

示例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());
}
 
开发者ID:amoAHCP,项目名称:vxms,代码行数:14,代码来源:KubernetesMockTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:che,代码行数:16,代码来源:OpenShiftObjectUtil.java

示例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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:14,代码来源:OpenShiftInternalRuntimeTest.java

示例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();
}
 
开发者ID:fabric8io,项目名称:jube,代码行数:46,代码来源:ApiMasterService.java


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