本文整理汇总了Java中io.fabric8.kubernetes.api.model.Endpoints类的典型用法代码示例。如果您正苦于以下问题:Java Endpoints类的具体用法?Java Endpoints怎么用?Java Endpoints使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Endpoints类属于io.fabric8.kubernetes.api.model包,在下文中一共展示了Endpoints类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: update
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
private void update(Endpoints endpoints) {
List<EquivalentAddressGroup> servers = new ArrayList<>();
endpoints.getSubsets().stream().forEach(subset -> {
long matchingPorts = subset.getPorts().stream().filter(p -> {
return p.getPort() == port;
}).count();
if (matchingPorts > 0) {
subset.getAddresses().stream().map(address -> {
return new EquivalentAddressGroup(new InetSocketAddress(address.getIp(), port));
}).forEach(address -> {
servers.add(address);
});
}
});
listener.onAddresses(servers, Attributes.EMPTY);
}
开发者ID:saturnism,项目名称:grpc-java-by-example,代码行数:18,代码来源:KubernetesNameResolver.java
示例2: build
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
@Override
public Endpoints build() {
if (endpointIPs.isEmpty() || ports.isEmpty()) {
throw new IllegalStateException("IP list and port list must be non-empty");
}
EndpointSubsetBuilder subset = new EndpointSubsetBuilder()
.withAddresses(endpointIPs.stream().map(ip ->
new EndpointAddressBuilder()
.withIp(ip).build()
).collect(Collectors.toList()))
.withPorts(ports.stream().map(port ->
new EndpointPortBuilder()
.withPort(port.getFirst())
.withProtocol(port.getSecond().toString())
.build()
).collect(Collectors.toList()));
return new io.fabric8.kubernetes.api.model.EndpointsBuilder()
.withMetadata(metadataBuilder().build())
.withSubsets(subset.build()).build();
}
开发者ID:xtf-cz,项目名称:xtf,代码行数:23,代码来源:EndpointBuilder.java
示例3: refresh
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
@Override
@GuardedBy("this")
public void refresh() {
if (refreshing) return;
try {
refreshing = true;
Endpoints endpoints = kubernetesClient.endpoints().inNamespace(namespace)
.withName(name)
.get();
if (endpoints == null) {
// Didn't find anything, retrying
ScheduledExecutorService timerService = SharedResourceHolder.get(timerServiceResource);
timerService.schedule(() -> {
refresh();
}, 30, TimeUnit.SECONDS);
return;
}
update(endpoints);
watch();
} finally {
refreshing = false;
}
}
开发者ID:saturnism,项目名称:grpc-java-by-example,代码行数:27,代码来源:KubernetesNameResolver.java
示例4: getLocalServiceInstance
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
@Override
public ServiceInstance getLocalServiceInstance() {
String serviceName = properties.getServiceName();
String podName = System.getenv(HOSTNAME);
ServiceInstance defaultInstance = new DefaultServiceInstance(serviceName, "localhost", 8080, false);
Endpoints endpoints = client.endpoints().withName(serviceName).get();
if (Utils.isNullOrEmpty(podName) || endpoints == null) {
return defaultInstance;
}
try {
return endpoints.getSubsets()
.stream()
.filter(s -> s.getAddresses().get(0).getTargetRef().getName().equals(podName))
.map(s -> (ServiceInstance) new KubernetesServiceInstance(serviceName,
s.getAddresses().stream().findFirst().orElseThrow(IllegalStateException::new),
s.getPorts().stream().findFirst().orElseThrow(IllegalStateException::new),
false))
.findFirst().orElse(defaultInstance);
} catch (Throwable t) {
return defaultInstance;
}
}
开发者ID:fabric8io,项目名称:spring-cloud-kubernetes,代码行数:24,代码来源:KubernetesDiscoveryClient.java
示例5: getEndpoints
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
@Override
public EndpointsList getEndpoints(@QueryParam("namespace") String namespace) {
EndpointsList answer = new EndpointsList();
List<Endpoints> list = new ArrayList<>();
answer.setItems(list);
ServiceList services = getServices(namespace);
if (services != null) {
List<Pod> pods = getPods(namespace).getItems();
List<Service> items = notNullList(services.getItems());
for (Service service : items) {
Endpoints endpoints = createEndpointsForService(service, pods);
if (endpoints != null) {
list.add(endpoints);
}
}
}
return answer;
}
开发者ID:fabric8io,项目名称:jube,代码行数:20,代码来源:ApiMasterService.java
示例6: podsOf
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
/**
* Finds the pod that correspond to the specified resource.
*
* @param resource The resource.
* @return The podList with the matching pods.
*/
public static <T extends HasMetadata> PodList podsOf(KubernetesClient client, T resource) {
if (resource instanceof Pod) {
return new PodListBuilder().withItems((Pod) resource).build();
} else if (resource instanceof Endpoints) {
return podsOf(client, client.services()
.inNamespace(resource.getMetadata().getNamespace())
.withName(resource.getMetadata().getName())
.get());
} else if (resource instanceof Service) {
return client.pods()
.inNamespace(resource.getMetadata().getNamespace())
.withLabels(((Service) resource).getSpec().getSelector())
.list();
} else if (resource instanceof ReplicationController) {
return client.pods()
.inNamespace(resource.getMetadata().getNamespace())
.withLabels(((ReplicationController) resource).getSpec().getSelector())
.list();
} else if (resource instanceof Deployment) {
return findMatching(client, (Deployment) resource);
} else if (resource instanceof DeploymentConfig) {
return client.pods().inNamespace(resource.getMetadata().getNamespace()).withLabel("deploymentconfig",
resource.getMetadata().getName()).list();
} else {
return new PodListBuilder().build();
}
}
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:34,代码来源:FeedbackUtils.java
示例7: getInstances
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
private static List<ServiceInstance> getInstances(KubernetesClient client, String name, String namespace) {
Assert.notNull(name, "[Assertion failed] - the service name must not be null");
return Optional.ofNullable(client.endpoints().inNamespace(namespace).withName(name).get())
.orElse(new Endpoints())
.getSubsets()
.stream()
.flatMap(s -> s.getAddresses().stream().map(a -> (ServiceInstance) new KubernetesServiceInstance(name, a ,s.getPorts().stream().findFirst().orElseThrow(IllegalStateException::new), false)))
.collect(Collectors.toList());
}
开发者ID:fabric8io,项目名称:spring-cloud-kubernetes,代码行数:11,代码来源:ZipkinKubernetesAutoConfiguration.java
示例8: getInstances
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
@Override
public List<ServiceInstance> getInstances(String serviceId) {
Assert.notNull(serviceId, "[Assertion failed] - the object argument must be null");
return Optional.ofNullable(client.endpoints().withName(serviceId).get()).orElse(new Endpoints())
.getSubsets()
.stream()
.flatMap(s -> s.getAddresses().stream().map(a -> (ServiceInstance) new KubernetesServiceInstance(serviceId, a ,s.getPorts().stream().findFirst().orElseThrow(IllegalStateException::new), false)))
.collect(Collectors.toList());
}
开发者ID:fabric8io,项目名称:spring-cloud-kubernetes,代码行数:11,代码来源:KubernetesDiscoveryClient.java
示例9: getUpdatedListOfServers
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
public List<ServiceCallServer> getUpdatedListOfServers(String name) {
LOG.debug("Discovering endpoints from namespace: {} with name: {}", getNamespace(), name);
Endpoints endpoints = client.endpoints().inNamespace(getNamespace()).withName(name).get();
List<ServiceCallServer> result = new ArrayList<>();
if (endpoints != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Found {} endpoints in namespace: {} for name: {} and portName: {}",
endpoints.getSubsets().size(), getNamespace(), name, getPortName());
}
for (EndpointSubset subset : endpoints.getSubsets()) {
if (subset.getPorts().size() == 1) {
addServers(result, subset.getPorts().get(FIRST), subset);
} else {
final List<EndpointPort> ports = subset.getPorts();
final int portSize = ports.size();
EndpointPort port;
for (int p = 0; p < portSize; p++) {
port = ports.get(p);
if (ObjectHelper.isEmpty(getPortName()) || getPortName().endsWith(port.getName())) {
addServers(result, port, subset);
}
}
}
}
}
return result;
}
开发者ID:HydAu,项目名称:Camel,代码行数:30,代码来源:KubernetesServiceCallServerListStrategies.java
示例10: getDiscoveryNodes
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
private List<DiscoveryNode> getDiscoveryNodes(EndpointsList endpointsInNamespace) {
if (endpointsInNamespace == null) {
return Collections.emptyList();
}
List<DiscoveryNode> discoveredNodes = new ArrayList<DiscoveryNode>();
for (Endpoints endpoints : endpointsInNamespace.getItems()) {
discoveredNodes.addAll(getSimpleDiscoveryNodes(endpoints));
}
return discoveredNodes;
}
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:11,代码来源:ServiceEndpointResolver.java
示例11: getSimpleDiscoveryNodes
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
private List<DiscoveryNode> getSimpleDiscoveryNodes(Endpoints endpoints) {
if (endpoints == null) {
return Collections.emptyList();
}
List<EndpointSubset> endpointsSubsets = endpoints.getSubsets();
if (endpointsSubsets == null) {
return Collections.emptyList();
}
List<DiscoveryNode> discoveredNodes = new ArrayList<DiscoveryNode>();
for (EndpointSubset endpointSubset : endpointsSubsets) {
resolveNotReadyAddresses(discoveredNodes, endpointSubset);
resolveAddresses(discoveredNodes, endpointSubset);
}
return discoveredNodes;
}
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:16,代码来源:ServiceEndpointResolver.java
示例12: resolveWithNamespaceAndNodeInNamespace
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
private void resolveWithNamespaceAndNodeInNamespace(final int port, final int expectedPort) {
Endpoints discoveryNode = createEndpoints(1);
nodesInNamespace.getItems().add(discoveryNode);
ServiceEndpointResolver sut = new ServiceEndpointResolver(LOGGER, SERVICE_NAME, port, null, null, NAMESPACE, null, KUBERNETES_MASTER_URL, API_TOKEN);
List<DiscoveryNode> nodes = sut.resolve();
assertEquals(1, nodes.size());
assertEquals(expectedPort, nodes.get(0).getPrivateAddress().getPort());
}
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:11,代码来源:ServiceEndpointResolverTest.java
示例13: resolveWithNamespaceAndNodeInNamespaceWithNoReadyPods
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
@Test
public void resolveWithNamespaceAndNodeInNamespaceWithNoReadyPods() {
Endpoints discoveryNode = createEndpoints(1);
discoveryNode.getSubsets().get(0).setAddresses(null);
nodesInNamespace.getItems().add(discoveryNode);
ServiceEndpointResolver sut = new ServiceEndpointResolver(LOGGER, SERVICE_NAME, 0, null, null, NAMESPACE, null, KUBERNETES_MASTER_URL, API_TOKEN);
List<DiscoveryNode> nodes = sut.resolve();
assertEquals(0, nodes.size());
}
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:12,代码来源:ServiceEndpointResolverTest.java
示例14: resolveWithNamespaceAndNodeInNamespaceWithNoSubsets
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
@Test
public void resolveWithNamespaceAndNodeInNamespaceWithNoSubsets() {
Endpoints discoveryNode = createEndpoints(1);
discoveryNode.setSubsets(null);
nodesInNamespace.getItems().add(discoveryNode);
ServiceEndpointResolver sut = new ServiceEndpointResolver(LOGGER, SERVICE_NAME, 0, null, null, NAMESPACE, null, KUBERNETES_MASTER_URL, API_TOKEN);
List<DiscoveryNode> nodes = sut.resolve();
assertEquals(0, nodes.size());
}
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:12,代码来源:ServiceEndpointResolverTest.java
示例15: resolveWithServiceLabelAndNodeWithServiceLabel
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
@Test
public void resolveWithServiceLabelAndNodeWithServiceLabel() {
nodesInNamespace.getItems().add(createEndpoints(1));
Endpoints discoveryNode = createEndpoints(2);
nodesWithLabel.getItems().add(discoveryNode);
ServiceEndpointResolver sut = new ServiceEndpointResolver(LOGGER, SERVICE_NAME, 0, SERVICE_LABEL, SERVICE_LABEL_VALUE, NAMESPACE, null, KUBERNETES_MASTER_URL, API_TOKEN);
List<DiscoveryNode> nodes = sut.resolve();
assertEquals(1, nodes.size());
assertEquals(2, nodes.get(0).getPrivateAddress().getPort());
}
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:13,代码来源:ServiceEndpointResolverTest.java
示例16: createEndpoints
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
private Endpoints createEndpoints(int id) {
Endpoints endpoints = new Endpoints();
EndpointSubset subset = new EndpointSubset();
endpoints.getSubsets().add(subset);
EndpointAddress address = new EndpointAddress();
subset.getAddresses().add(address);
address.setIp("1.1.1.1");
address.getAdditionalProperties().put("hazelcast-service-port", String.valueOf(id));
return endpoints;
}
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:11,代码来源:ServiceEndpointResolverTest.java
示例17: createNotReadyEndpoints
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
private Endpoints createNotReadyEndpoints(int id) {
Endpoints endpoints = new Endpoints();
EndpointSubset subset = new EndpointSubset();
endpoints.getSubsets().add(subset);
EndpointAddress address = new EndpointAddress();
subset.getNotReadyAddresses().add(address);
address.setIp("1.1.1.1");
address.getAdditionalProperties().put("hazelcast-service-port", String.valueOf(id));
return endpoints;
}
开发者ID:hazelcast,项目名称:hazelcast-kubernetes,代码行数:11,代码来源:ServiceEndpointResolverTest.java
示例18: buildEndpoints
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
public List<Endpoints> buildEndpoints() {
return externalServices.stream().map(x -> x.getEndpoints(this)).collect(Collectors.toList());
}
开发者ID:xtf-cz,项目名称:xtf,代码行数:4,代码来源:ApplicationBuilder.java
示例19: endpointsForService
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的package包/类
@Override
public Endpoints endpointsForService(@NotNull String serviceId, String namespace) {
List<Pod> pods = podList();
Service service = getService(serviceId);
return createEndpointsForService(service, pods);
}
开发者ID:fabric8io,项目名称:jube,代码行数:7,代码来源:ApiMasterService.java
示例20: createEndpointsForService
import io.fabric8.kubernetes.api.model.Endpoints; //导入依赖的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.Endpoints类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论