|
13 | 13 | import static java.net.HttpURLConnection.HTTP_GONE;
|
14 | 14 |
|
15 | 15 | public class DeploymentEventSource extends AbstractEventSource implements Watcher<Deployment> {
|
16 |
| - private final static Logger log = LoggerFactory.getLogger(DeploymentEventSource.class); |
| 16 | + private static final Logger log = LoggerFactory.getLogger(DeploymentEventSource.class); |
17 | 17 |
|
18 |
| - private final KubernetesClient client; |
| 18 | + private final KubernetesClient client; |
19 | 19 |
|
20 |
| - public static DeploymentEventSource createAndRegisterWatch(KubernetesClient client) { |
21 |
| - DeploymentEventSource deploymentEventSource = new DeploymentEventSource(client); |
22 |
| - deploymentEventSource.registerWatch(); |
23 |
| - return deploymentEventSource; |
24 |
| - } |
25 |
| - |
26 |
| - private DeploymentEventSource(KubernetesClient client) { |
27 |
| - this.client = client; |
28 |
| - } |
| 20 | + public static DeploymentEventSource createAndRegisterWatch(KubernetesClient client) { |
| 21 | + DeploymentEventSource deploymentEventSource = new DeploymentEventSource(client); |
| 22 | + deploymentEventSource.registerWatch(); |
| 23 | + return deploymentEventSource; |
| 24 | + } |
29 | 25 |
|
30 |
| - private void registerWatch() { |
31 |
| - client.apps().deployments().inAnyNamespace().withLabel("managed-by", "tomcat-operator").watch(this); |
32 |
| - } |
| 26 | + private DeploymentEventSource(KubernetesClient client) { |
| 27 | + this.client = client; |
| 28 | + } |
33 | 29 |
|
34 |
| - @Override |
35 |
| - public void eventReceived(Action action, Deployment deployment) { |
36 |
| - log.info("Event received for action: {}, Deployment: {} (rr={})", action.name(), deployment.getMetadata().getName(), deployment.getStatus().getReadyReplicas()); |
| 30 | + private void registerWatch() { |
| 31 | + client |
| 32 | + .apps() |
| 33 | + .deployments() |
| 34 | + .inAnyNamespace() |
| 35 | + .withLabel("managed-by", "tomcat-operator") |
| 36 | + .watch(this); |
| 37 | + } |
37 | 38 |
|
38 |
| - if (action == Action.ERROR) { |
39 |
| - log.warn("Skipping {} event for custom resource uid: {}, version: {}", action, |
40 |
| - getUID(deployment), getVersion(deployment)); |
41 |
| - return; |
42 |
| - } |
| 39 | + @Override |
| 40 | + public void eventReceived(Action action, Deployment deployment) { |
| 41 | + log.info( |
| 42 | + "Event received for action: {}, Deployment: {} (rr={})", |
| 43 | + action.name(), |
| 44 | + deployment.getMetadata().getName(), |
| 45 | + deployment.getStatus().getReadyReplicas()); |
43 | 46 |
|
44 |
| - eventHandler.handleEvent(new DeploymentEvent(action, deployment, this, |
45 |
| - deployment.getMetadata().getOwnerReferences().get(0).getUid())); |
| 47 | + if (action == Action.ERROR) { |
| 48 | + log.warn( |
| 49 | + "Skipping {} event for custom resource uid: {}, version: {}", |
| 50 | + action, |
| 51 | + getUID(deployment), |
| 52 | + getVersion(deployment)); |
| 53 | + return; |
46 | 54 | }
|
47 | 55 |
|
48 |
| - @Override |
49 |
| - public void onClose(KubernetesClientException e) { |
50 |
| - if (e == null) { |
51 |
| - return; |
52 |
| - } |
53 |
| - if (e.getCode() == HTTP_GONE) { |
54 |
| - log.warn("Received error for watch, will try to reconnect.", e); |
55 |
| - registerWatch(); |
56 |
| - } else { |
57 |
| - // Note that this should not happen normally, since fabric8 client handles reconnect. |
58 |
| - // In case it tries to reconnect this method is not called. |
59 |
| - log.error("Unexpected error happened with watch. Will exit.", e); |
60 |
| - System.exit(1); |
61 |
| - } |
| 56 | + eventHandler.handleEvent( |
| 57 | + new DeploymentEvent( |
| 58 | + action, |
| 59 | + deployment, |
| 60 | + this, |
| 61 | + deployment.getMetadata().getOwnerReferences().get(0).getUid())); |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public void onClose(KubernetesClientException e) { |
| 66 | + if (e == null) { |
| 67 | + return; |
| 68 | + } |
| 69 | + if (e.getCode() == HTTP_GONE) { |
| 70 | + log.warn("Received error for watch, will try to reconnect.", e); |
| 71 | + registerWatch(); |
| 72 | + } else { |
| 73 | + // Note that this should not happen normally, since fabric8 client handles reconnect. |
| 74 | + // In case it tries to reconnect this method is not called. |
| 75 | + log.error("Unexpected error happened with watch. Will exit.", e); |
| 76 | + System.exit(1); |
62 | 77 | }
|
| 78 | + } |
63 | 79 | }
|
0 commit comments