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


Java Watcher类代码示例

本文整理汇总了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());
        }
    };
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:18,代码来源:PodSenseSubscriptionConfig.java

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

示例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);
    }
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:17,代码来源:KubernetesDockerRunner.java

示例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);
            }
        }
    };
}
 
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:19,代码来源:TestSubscriptionConfig.java

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

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

示例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);
}
 
开发者ID:spotify,项目名称:styx,代码行数:11,代码来源:KubernetesDockerRunner.java

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

示例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);
  }
}
 
开发者ID:spotify,项目名称:styx,代码行数:15,代码来源:KubernetesPodEventTranslatorTest.java

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

示例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));
}
 
开发者ID:spotify,项目名称:styx,代码行数:8,代码来源:KubernetesDockerRunnerTest.java

示例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));
}
 
开发者ID:spotify,项目名称:styx,代码行数:8,代码来源:KubernetesDockerRunnerTest.java

示例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));
}
 
开发者ID:spotify,项目名称:styx,代码行数:9,代码来源:KubernetesDockerRunnerTest.java

示例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));
}
 
开发者ID:spotify,项目名称:styx,代码行数:9,代码来源:KubernetesDockerRunnerTest.java

示例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));
}
 
开发者ID:spotify,项目名称:styx,代码行数:8,代码来源:KubernetesDockerRunnerTest.java


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