Skip to content

Commit a72acec

Browse files
committed
reformat code
1 parent 0f9042e commit a72acec

File tree

12 files changed

+488
-409
lines changed

12 files changed

+488
-409
lines changed

samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentEvent.java

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,49 @@
66

77
public class DeploymentEvent extends AbstractEvent {
88

9-
private final Watcher.Action action;
10-
private final Deployment deployment;
11-
12-
public DeploymentEvent(Watcher.Action action, Deployment deployment,
13-
DeploymentEventSource deploymentEventSource,
14-
String tomcatUid) {
15-
//TODO: this mapping is really critical and should be made more explicit
16-
super(tomcatUid, deploymentEventSource);
17-
this.action = action;
18-
this.deployment = deployment;
19-
}
20-
21-
public Watcher.Action getAction() {
22-
return action;
23-
}
24-
25-
public String resourceUid() {
26-
return getDeployment().getMetadata().getUid();
27-
}
28-
29-
@Override
30-
public String toString() {
31-
return "CustomResourceEvent{" +
32-
"action=" + action +
33-
", resource=[ name=" + getDeployment().getMetadata().getName() + ", kind=" + getDeployment().getKind() +
34-
", apiVersion=" + getDeployment().getApiVersion() + " ,resourceVersion=" + getDeployment().getMetadata().getResourceVersion() +
35-
", markedForDeletion: " + (getDeployment().getMetadata().getDeletionTimestamp() != null
36-
&& !getDeployment().getMetadata().getDeletionTimestamp().isEmpty()) +
37-
" ]" +
38-
'}';
39-
}
40-
41-
public Deployment getDeployment() {
42-
return deployment;
43-
}
9+
private final Watcher.Action action;
10+
private final Deployment deployment;
11+
12+
public DeploymentEvent(
13+
Watcher.Action action,
14+
Deployment deployment,
15+
DeploymentEventSource deploymentEventSource,
16+
String tomcatUid) {
17+
// TODO: this mapping is really critical and should be made more explicit
18+
super(tomcatUid, deploymentEventSource);
19+
this.action = action;
20+
this.deployment = deployment;
21+
}
22+
23+
public Watcher.Action getAction() {
24+
return action;
25+
}
26+
27+
public String resourceUid() {
28+
return getDeployment().getMetadata().getUid();
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return "CustomResourceEvent{"
34+
+ "action="
35+
+ action
36+
+ ", resource=[ name="
37+
+ getDeployment().getMetadata().getName()
38+
+ ", kind="
39+
+ getDeployment().getKind()
40+
+ ", apiVersion="
41+
+ getDeployment().getApiVersion()
42+
+ " ,resourceVersion="
43+
+ getDeployment().getMetadata().getResourceVersion()
44+
+ ", markedForDeletion: "
45+
+ (getDeployment().getMetadata().getDeletionTimestamp() != null
46+
&& !getDeployment().getMetadata().getDeletionTimestamp().isEmpty())
47+
+ " ]"
48+
+ '}';
49+
}
50+
51+
public Deployment getDeployment() {
52+
return deployment;
53+
}
4454
}

samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/DeploymentEventSource.java

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,51 +13,67 @@
1313
import static java.net.HttpURLConnection.HTTP_GONE;
1414

1515
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);
1717

18-
private final KubernetesClient client;
18+
private final KubernetesClient client;
1919

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+
}
2925

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+
}
3329

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+
}
3738

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());
4346

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;
4654
}
4755

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);
6277
}
78+
}
6379
}

samples/tomcat/src/main/java/io/javaoperatorsdk/operator/sample/Tomcat.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@
44

55
public class Tomcat extends CustomResource {
66

7-
private TomcatSpec spec;
7+
private TomcatSpec spec;
88

9-
private TomcatStatus status;
9+
private TomcatStatus status;
1010

11-
public TomcatSpec getSpec() {
12-
if (spec == null) {
13-
spec = new TomcatSpec();
14-
}
15-
return spec;
11+
public TomcatSpec getSpec() {
12+
if (spec == null) {
13+
spec = new TomcatSpec();
1614
}
15+
return spec;
16+
}
1717

18-
public void setSpec(TomcatSpec spec) {
19-
this.spec = spec;
20-
}
18+
public void setSpec(TomcatSpec spec) {
19+
this.spec = spec;
20+
}
2121

22-
public TomcatStatus getStatus() {
23-
if (status == null) {
24-
status = new TomcatStatus();
25-
}
26-
return status;
22+
public TomcatStatus getStatus() {
23+
if (status == null) {
24+
status = new TomcatStatus();
2725
}
26+
return status;
27+
}
2828

29-
public void setStatus(TomcatStatus status) {
30-
this.status = status;
31-
}
32-
}
29+
public void setStatus(TomcatStatus status) {
30+
this.status = status;
31+
}
32+
}

0 commit comments

Comments
 (0)