本文整理汇总了Java中io.fabric8.kubernetes.client.Watcher类的典型用法代码示例。如果您正苦于以下问题:Java Watcher类的具体用法?Java Watcher怎么用?Java Watcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Watcher类属于io.fabric8.kubernetes.client包,在下文中一共展示了Watcher类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResource
import io.fabric8.kubernetes.client.Watcher; //导入依赖的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: tryPollPods
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
private synchronized void tryPollPods() {
final Set<WorkflowInstance> runningWorkflowInstances = getRunningWorkflowInstances();
final PodList list = client.pods().list();
examineRunningWFISandAssociatedPods(runningWorkflowInstances, list);
for (Pod pod : list.getItems()) {
logEvent(Watcher.Action.MODIFIED, pod, list.getMetadata().getResourceVersion(), true);
final Optional<WorkflowInstance> workflowInstance = readPodWorkflowInstance(pod);
if (!workflowInstance.isPresent()) {
continue;
}
final Optional<RunState> runState = lookupPodRunState(pod, workflowInstance.get());
if (runState.isPresent()) {
emitPodEvents(Watcher.Action.MODIFIED, pod, runState.get());
cleanupWithRunState(workflowInstance.get(), pod.getMetadata().getName());
} else {
cleanupWithoutRunState(workflowInstance.get(), pod.getMetadata().getName());
}
}
}
示例3: emitPodEvents
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
private void emitPodEvents(Watcher.Action action, Pod pod, RunState runState) {
final List<Event> events = translate(runState.workflowInstance(), runState, action, pod, stats);
for (Event event : events) {
if (event.accept(new PullImageErrorMatcher())) {
stats.recordPullImageError();
}
try {
stateManager.receive(event);
} catch (IsClosedException isClosedException) {
LOG.warn("Could not receive kubernetes event", isClosedException);
throw new RuntimeException(isClosedException);
}
}
}
示例4: getResource
import io.fabric8.kubernetes.client.Watcher; //导入依赖的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);
}
}
};
}
示例5: onWatchEvent
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
protected void onWatchEvent(io.fabric8.kubernetes.client.Watcher.Action action, HasMetadata entity, NotifyConfig notifyConfig) {
if (!notifyConfig.isEnabled(action)) {
return;
}
String kind = KubernetesHelper.getKind(entity);
String name = KubernetesHelper.getName(entity);
String namespace = getNamespace();
String actionText = action.toString().toLowerCase();
String room = this.roomExpression.replace("${namespace}", namespace).replace("${kind}", kind).replace("${name}", name);
String postfix = "";
if (action.equals(Watcher.Action.ADDED) || action.equals(Watcher.Action.MODIFIED)) {
if (Strings.isNotBlank(consoleLink)) {
postfix += " " + consoleLink + "/kubernetes/namespace/" + namespace + "/" + kind.toLowerCase() + "s/" + name;
}
}
String message = actionText + " " + decapitalize(kind) + " " + namespace + " / " + name + postfix;
notifier.notifyRoom(room, message);
}
示例6: findMatching
import io.fabric8.kubernetes.client.Watcher; //导入依赖的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();
}
示例7: logEvent
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
private void logEvent(Watcher.Action action, Pod pod, String resourceVersion,
boolean polled) {
final String podName = pod.getMetadata().getName();
final String workflowInstance = pod.getMetadata().getAnnotations()
.getOrDefault(KubernetesDockerRunner.STYX_WORKFLOW_INSTANCE_ANNOTATION, "N/A");
final String status = readStatus(pod);
LOG.info("{}Pod event for {} at resource version {}, action: {}, workflow instance: {}, status: {}",
polled ? "Polled: " : "", podName, resourceVersion, action, workflowInstance, status);
}
示例8: shouldIgnoreDeletedEvents
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
@Test
public void shouldIgnoreDeletedEvents() throws Exception {
pod.setStatus(terminated("Succeeded", 0, null));
RunState state = RunState.create(WFI, RunState.State.TERMINATED);
List<Event> events = translate(WFI, state, Watcher.Action.DELETED, pod, Stats.NOOP);
assertThat(events, empty());
}
示例9: assertGeneratesEventsAndTransitions
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
private void assertGeneratesEventsAndTransitions(
RunState.State initialState,
Pod pod,
Event... expectedEvents) {
RunState state = RunState.create(WFI, initialState);
List<Event> events = translate(WFI, state, Watcher.Action.MODIFIED, pod, Stats.NOOP);
assertThat(events, contains(expectedEvents));
// ensure no exceptions are thrown when transitioning
for (Event event : events) {
state = state.transition(event);
}
}
示例10: assertGeneratesNoEvents
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
private void assertGeneratesNoEvents(
RunState.State initialState,
Pod pod) {
RunState state = RunState.create(WFI, initialState);
List<Event> events = translate(WFI, state, Watcher.Action.MODIFIED, pod, Stats.NOOP);
assertThat(events, empty());
}
示例11: shouldCompleteWithStatusCodeOnSucceeded
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
@Test
public void shouldCompleteWithStatusCodeOnSucceeded() throws Exception {
createdPod.setStatus(terminated("Succeeded", 20, null));
podWatcher.eventReceived(Watcher.Action.MODIFIED, createdPod);
assertThat(stateManager.get(WORKFLOW_INSTANCE).data().lastExit(), hasValue(20));
}
示例12: shouldFailOnErrImagePull
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
@Test
public void shouldFailOnErrImagePull() throws Exception {
createdPod.setStatus(waiting("Pending", "ErrImagePull"));
podWatcher.eventReceived(Watcher.Action.MODIFIED, createdPod);
assertThat(stateManager.get(WORKFLOW_INSTANCE).state(), is(RunState.State.FAILED));
}
示例13: shouldSendStatsOnErrImagePull
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
@Test
public void shouldSendStatsOnErrImagePull() throws Exception {
createdPod.setStatus(waiting("Pending", "ErrImagePull"));
podWatcher.eventReceived(Watcher.Action.MODIFIED, createdPod);
verify(stats, times(1)).recordPullImageError();
assertThat(stateManager.get(WORKFLOW_INSTANCE).state(), is(RunState.State.FAILED));
}
示例14: shouldNotSendStatsOnOtherError
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
@Test
public void shouldNotSendStatsOnOtherError() throws Exception {
createdPod.setStatus(podStatusNoContainer("Succeeded"));
podWatcher.eventReceived(Watcher.Action.MODIFIED, createdPod);
verifyNoMoreInteractions(stats);
assertThat(stateManager.get(WORKFLOW_INSTANCE).state(), is(RunState.State.FAILED));
}
示例15: shouldFailOnUnknownPhaseEntered
import io.fabric8.kubernetes.client.Watcher; //导入依赖的package包/类
@Test
public void shouldFailOnUnknownPhaseEntered() throws Exception {
createdPod.setStatus(podStatusNoContainer("Unknown"));
podWatcher.eventReceived(Watcher.Action.MODIFIED, createdPod);
assertThat(stateManager.get(WORKFLOW_INSTANCE).state(), is(RunState.State.FAILED));
}