Skip to content

Commit a25c4bd

Browse files
committed
fix: applying to other classes
1 parent 722c30c commit a25c4bd

File tree

4 files changed

+129
-24
lines changed

4 files changed

+129
-24
lines changed

olm/catalogsource.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
apiVersion: operators.coreos.com/v1alpha1
22
kind: CatalogSource
33
metadata:
4-
name: rhoas-operators2
4+
name: rhoas-operators-s
55
namespace: openshift-marketplace
66
spec:
77
displayName: RHOAS Operators
88
icon:
99
base64data: ""
1010
mediatype: ""
11-
image: quay.io/rhoas/service-operator-registry:autolatest
11+
image: quay.io/secondsun/service-operator-registry:autolatest
1212
priority: -400
1313
publisher: RHOAS
1414
sourceType: grpc

source/rhoas/src/main/java/com/openshift/cloud/controllers/CloudServiceAccountRequestController.java

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,35 @@
55
import com.openshift.cloud.beans.KafkaK8sClients;
66
import com.openshift.cloud.utils.InvalidUserInputException;
77
import com.openshift.cloud.v1alpha.models.CloudServiceAccountRequest;
8+
import io.fabric8.kubernetes.client.WatcherException;
89
import io.javaoperatorsdk.operator.api.*;
10+
import io.javaoperatorsdk.operator.processing.event.DefaultEventSourceManager;
11+
import io.javaoperatorsdk.operator.processing.event.EventSourceManager;
12+
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventSource;
13+
import io.quarkus.runtime.Quarkus;
14+
import io.quarkus.scheduler.Scheduled;
15+
import java.lang.reflect.Field;
916
import java.time.Instant;
1017
import javax.inject.Inject;
18+
import org.jboss.logging.Logger;
19+
import org.jboss.logging.Logger.Level;
1120

1221
/** Controller for CloudServiceAccountRequest CRs */
1322
@Controller
1423
public class CloudServiceAccountRequestController
1524
extends AbstractCloudServicesController<CloudServiceAccountRequest> {
1625

26+
private static final Logger LOG =
27+
Logger.getLogger(CloudServiceAccountRequestController.class.getName());
28+
1729
@Inject AccessTokenSecretTool accessTokenSecretTool;
1830

1931
@Inject KafkaK8sClients kafkaClientFactory;
2032

2133
@Inject KafkaApiClient apiClient;
2234

35+
private EventSourceManager eventSourceManager;
36+
2337
@Override
2438
void doCreateOrUpdateResource(
2539
CloudServiceAccountRequest resource, Context<CloudServiceAccountRequest> context)
@@ -45,6 +59,43 @@ void doCreateOrUpdateResource(
4559
resource.setStatus(status);
4660
}
4761

62+
@Override
63+
public void init(EventSourceManager eventSourceManager) {
64+
this.eventSourceManager = eventSourceManager;
65+
LOG.info("Init! This is where we would add watches for child resources");
66+
}
67+
68+
@Scheduled(every = "600s")
69+
public void reconnect() {
70+
LOG.info("Begin reconnect");
71+
DefaultEventSourceManager x = (DefaultEventSourceManager) this.eventSourceManager;
72+
Field f;
73+
if (x != null) {
74+
try {
75+
f = x.getClass().getDeclaredField("customResourceEventSource");
76+
f.setAccessible(true);
77+
CustomResourceEventSource cre = (CustomResourceEventSource) f.get(x);
78+
LOG.info("Reconnecting");
79+
cre.onClose(
80+
new WatcherException("Hack Exception") {
81+
@Override
82+
public boolean isHttpGone() {
83+
return true;
84+
}
85+
});
86+
} catch (NoSuchFieldException
87+
| SecurityException
88+
| IllegalArgumentException
89+
| IllegalAccessException e) {
90+
// TODO Auto-generated catch block
91+
LOG.log(Level.ERROR, "Failed to get customResourceEventSource", e);
92+
} catch (Exception e) {
93+
LOG.log(Level.ERROR, "Reconnect failed, exiting", e);
94+
Quarkus.asyncExit(1);
95+
}
96+
}
97+
}
98+
4899
void validateResource(CloudServiceAccountRequest resource) throws InvalidUserInputException {
49100
ConditionUtil.assertNotNull(resource.getSpec(), "spec");
50101
ConditionUtil.assertNotNull(

source/rhoas/src/main/java/com/openshift/cloud/controllers/CloudServicesRequestController.java

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
import com.openshift.cloud.utils.InvalidUserInputException;
77
import com.openshift.cloud.v1alpha.models.CloudServicesRequest;
88
import com.openshift.cloud.v1alpha.models.UserKafka;
9-
109
import io.fabric8.kubernetes.client.WatcherException;
1110
import io.javaoperatorsdk.operator.api.*;
1211
import io.javaoperatorsdk.operator.processing.event.DefaultEventSourceManager;
1312
import io.javaoperatorsdk.operator.processing.event.EventSourceManager;
1413
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventSource;
14+
import io.quarkus.runtime.Quarkus;
1515
import io.quarkus.scheduler.Scheduled;
16-
1716
import java.lang.reflect.Field;
1817
import java.util.ArrayList;
1918
import java.util.logging.Logger;
2019
import javax.inject.Inject;
20+
import org.jboss.logmanager.Level;
2121

2222
@Controller
2323
public class CloudServicesRequestController
@@ -43,28 +43,35 @@ public void init(EventSourceManager eventSourceManager) {
4343
LOG.info("Init! This is where we would add watches for child resources");
4444
}
4545

46-
@Scheduled(every = "600s")
47-
public void reconnect() {
48-
DefaultEventSourceManager x = (DefaultEventSourceManager) this.eventSourceManager;
49-
Field f;
50-
if (x != null)
51-
try {
52-
f = x.getClass().getDeclaredField("customResourceEventSource");
53-
f.setAccessible(true);
54-
CustomResourceEventSource cre = (CustomResourceEventSource) f.get(x);
55-
cre.onClose(new WatcherException("Hack Exception"){
56-
@Override
57-
public boolean isHttpGone() {
58-
return true;
46+
@Scheduled(every = "600s")
47+
public void reconnect() {
48+
LOG.info("Begin reconnect");
49+
DefaultEventSourceManager x = (DefaultEventSourceManager) this.eventSourceManager;
50+
Field f;
51+
if (x != null)
52+
try {
53+
f = x.getClass().getDeclaredField("customResourceEventSource");
54+
f.setAccessible(true);
55+
CustomResourceEventSource cre = (CustomResourceEventSource) f.get(x);
56+
LOG.info("Reconnecting");
57+
cre.onClose(
58+
new WatcherException("Hack Exception") {
59+
@Override
60+
public boolean isHttpGone() {
61+
return true;
62+
}
63+
});
64+
} catch (NoSuchFieldException
65+
| SecurityException
66+
| IllegalArgumentException
67+
| IllegalAccessException e) {
68+
// TODO Auto-generated catch block
69+
LOG.log(Level.ERROR, "Failed to get customResourceEventSource", e);
70+
} catch (Exception e) {
71+
LOG.log(Level.ERROR, "Reconnect failed, exiting", e);
72+
Quarkus.asyncExit(1);
5973
}
60-
});
61-
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
62-
// TODO Auto-generated catch block
63-
e.printStackTrace();
6474
}
65-
66-
67-
}
6875

6976
@Override
7077
void doCreateOrUpdateResource(

source/rhoas/src/main/java/com/openshift/cloud/controllers/KafkaConnectionController.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,16 @@
55
import com.openshift.cloud.utils.ConnectionResourcesMetadata;
66
import com.openshift.cloud.utils.InvalidUserInputException;
77
import com.openshift.cloud.v1alpha.models.KafkaConnection;
8+
import io.fabric8.kubernetes.client.WatcherException;
89
import io.javaoperatorsdk.operator.api.*;
10+
import io.javaoperatorsdk.operator.processing.event.DefaultEventSourceManager;
11+
import io.javaoperatorsdk.operator.processing.event.EventSourceManager;
12+
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEventSource;
13+
import io.quarkus.runtime.Quarkus;
14+
import io.quarkus.scheduler.Scheduled;
15+
import java.lang.reflect.Field;
916
import java.time.Instant;
17+
import java.util.logging.Level;
1018
import java.util.logging.Logger;
1119
import javax.inject.Inject;
1220

@@ -19,6 +27,8 @@ public class KafkaConnectionController extends AbstractCloudServicesController<K
1927

2028
@Inject AccessTokenSecretTool accessTokenSecretTool;
2129

30+
private EventSourceManager eventSourceManager;
31+
2232
@Override
2333
void doCreateOrUpdateResource(KafkaConnection resource, Context<KafkaConnection> context)
2434
throws ConditionAwareException, InvalidUserInputException {
@@ -46,6 +56,43 @@ void doCreateOrUpdateResource(KafkaConnection resource, Context<KafkaConnection>
4656
status.setMetadata(ConnectionResourcesMetadata.buildKafkaMetadata(kafkaId));
4757
}
4858

59+
@Override
60+
public void init(EventSourceManager eventSourceManager) {
61+
this.eventSourceManager = eventSourceManager;
62+
LOG.info("Init! This is where we would add watches for child resources");
63+
}
64+
65+
@Scheduled(every = "600s")
66+
public void reconnect() {
67+
LOG.info("Begin reconnect");
68+
DefaultEventSourceManager x = (DefaultEventSourceManager) this.eventSourceManager;
69+
Field f;
70+
if (x != null) {
71+
try {
72+
f = x.getClass().getDeclaredField("customResourceEventSource");
73+
f.setAccessible(true);
74+
CustomResourceEventSource cre = (CustomResourceEventSource) f.get(x);
75+
LOG.info("Reconnecting");
76+
cre.onClose(
77+
new WatcherException("Hack Exception") {
78+
@Override
79+
public boolean isHttpGone() {
80+
return true;
81+
}
82+
});
83+
} catch (NoSuchFieldException
84+
| SecurityException
85+
| IllegalArgumentException
86+
| IllegalAccessException e) {
87+
// TODO Auto-generated catch block
88+
LOG.log(Level.SEVERE, "Failed to get customResourceEventSource", e);
89+
} catch (Exception e) {
90+
LOG.log(Level.SEVERE, "Reconnect failed, exiting", e);
91+
Quarkus.asyncExit(1);
92+
}
93+
}
94+
}
95+
4996
void validateResource(KafkaConnection resource) throws InvalidUserInputException {
5097
ConditionUtil.assertNotNull(resource.getSpec(), "spec");
5198
ConditionUtil.assertNotNull(

0 commit comments

Comments
 (0)