本文整理汇总了Java中io.fabric8.kubernetes.client.Watch类的典型用法代码示例。如果您正苦于以下问题:Java Watch类的具体用法?Java Watch怎么用?Java Watch使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Watch类属于io.fabric8.kubernetes.client包,在下文中一共展示了Watch类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResource
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
@Override
public Resource<Pod> getResource(ObserverKey observerKey, KubernetesClient client) {
return new Resource<Pod>() {
@Override
public Watch watchResources(Watcher watcher) {
return client.pods().inNamespace(client.getNamespace()).withLabels(observerKey.getLabelFilter()).watch(watcher);
}
@Override
public Set<Pod> listResources() {
return client.pods().inNamespace(client.getNamespace()).withLabels(observerKey.getLabelFilter()).list().getItems().stream()
.filter(pod -> filterPod(observerKey, pod))
.map(Pod::new)
.collect(Collectors.toSet());
}
};
}
示例2: getResource
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
@Override
public Resource<TestResource> getResource(ObserverKey observerKey, KubernetesClient client) {
return new Resource<TestResource>() {
@Override
public Watch watchResources(Watcher watcher) {
return testWatch;
}
@Override
public Set<TestResource> listResources() {
try {
return stream.take();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
};
}
示例3: doDelete
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
private CompletableFuture<Void> doDelete(String name) throws InfrastructureException {
try {
final PodResource<Pod, DoneablePod> podResource =
clientFactory.create().pods().inNamespace(namespace).withName(name);
final CompletableFuture<Void> deleteFuture = new CompletableFuture<>();
final Watch watch = podResource.watch(new DeleteWatcher(deleteFuture));
podResource.delete();
return deleteFuture.whenComplete(
(v, e) -> {
if (e != null) {
LOG.warn("Failed to remove pod {} cause {}", name, e.getMessage());
}
watch.close();
});
} catch (KubernetesClientException ex) {
throw new InfrastructureException(ex.getMessage(), ex);
}
}
示例4: findMatching
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
/**
* Returns the {@link PodList} that match the specified {@link Deployment}.
*
* @param deployment The {@link Deployment}
*/
public static PodList findMatching(KubernetesClient client, Deployment deployment) {
FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> podLister =
client.pods().inNamespace(deployment.getMetadata().getNamespace());
if (deployment.getSpec().getSelector().getMatchLabels() != null) {
podLister.withLabels(deployment.getSpec().getSelector().getMatchLabels());
}
if (deployment.getSpec().getSelector().getMatchExpressions() != null) {
for (LabelSelectorRequirement req : deployment.getSpec().getSelector().getMatchExpressions()) {
switch (req.getOperator()) {
case "In":
podLister.withLabelIn(req.getKey(), req.getValues().toArray(new String[]{}));
break;
case "NotIn":
podLister.withLabelNotIn(req.getKey(), req.getValues().toArray(new String[]{}));
break;
case "DoesNotExist":
podLister.withoutLabel(req.getKey());
break;
case "Exists":
podLister.withLabel(req.getKey());
break;
}
}
}
return podLister.list();
}
示例5: stop
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
public synchronized void stop() {
if (relister != null && !relister.isDone()) {
relister.cancel(true);
relister = null;
}
for (Map.Entry<String, Watch> entry : watches.entrySet()) {
entry.getValue().close();
watches.remove(entry.getKey());
}
}
示例6: unwatch
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
@PreDestroy
public void unwatch() {
if (this.watches != null) {
for (Map.Entry<String, Watch> entry : this.watches.entrySet()) {
try {
log.debug("Closing the watch {}", entry.getKey());
entry.getValue().close();
} catch (Exception e) {
log.error("Error while closing the watch connection", e);
}
}
}
}
开发者ID:fabric8io,项目名称:spring-cloud-kubernetes,代码行数:15,代码来源:EventBasedConfigurationChangeDetector.java
示例7: registerWatcher
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
private Watch registerWatcher() {
return kubernetesClient.pods().watch(new Watcher<Pod>() {
@Override
public void eventReceived(Action eventAction, Pod eventPod) {
boolean continueBlocking = continueBlocking(eventAction, eventPod);
if (!continueBlocking)
block[0] = false;
}
@Override
public void onClose(KubernetesClientException e) {
}
});
}
示例8: getServicesByLabel
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
private static ServiceList getServicesByLabel(Map<String, String> labels, KubernetesClient client)
throws KubernetesClientException {
Objects.requireNonNull(client, "no client available");
final MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>>
services = client.services();
final FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>>
listable = createLabelFilterQuery(labels, services);
return listable.list();
}
示例9: createLabelFilterQuery
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
private static FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>>
createLabelFilterQuery(
Map<String, String> labels,
MixedOperation<Service, ServiceList, DoneableService, Resource<Service, DoneableService>>
services) {
FilterWatchListDeletable<Service, ServiceList, Boolean, Watch, Watcher<Service>> listable =
null;
for (Entry<String, String> entry : labels.entrySet()) {
listable =
listable == null
? services.withLabel(entry.getKey(), entry.getValue())
: listable.withLabel(entry.getKey(), entry.getValue());
}
return listable;
}
示例10: BaseWatcher
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
@SuppressFBWarnings("EI_EXPOSE_REP2")
public BaseWatcher(String[] namespaces) {
this.namespaces = namespaces;
watches = new HashMap<String, Watch>();
}
示例11: watchPods
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
public Watch watchPods(String namespace, Watcher<Pod> podWatcher) {
return client.pods().inNamespace(namespace).watch(podWatcher);
}
示例12: watchResources
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
@Override
public Watch watchResources(Watcher watcher) {
return () -> {};
}
示例13: watchResources
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
@Override
public Watch watchResources(io.fabric8.kubernetes.client.Watcher watcher) {
return client.pods().withLabels(labelFilter).watch(watcher);
}
示例14: addClient
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
protected void addClient(Watch watch) {
watches.add(watch);
}
示例15: print
import io.fabric8.kubernetes.client.Watch; //导入依赖的package包/类
private static List<String> print(FilterWatchListDeletable<Pod, PodList, Boolean, Watch, Watcher<Pod>> pods) {
return pods.list().getItems().stream()
.map(pod -> String.format("%s (%s)", pod.getMetadata().getName(), pod.getStatus().getPhase()))
.collect(Collectors.toList());
}