Skip to content

Commit

Permalink
fixup! Make OpenShiftClient one per che server
Browse files Browse the repository at this point in the history
  • Loading branch information
akorneta committed Nov 30, 2017
1 parent 080ec34 commit 89f3a19
Showing 1 changed file with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import io.fabric8.openshift.client.DefaultOpenShiftClient;
import io.fabric8.openshift.client.OpenShiftClient;
import io.fabric8.openshift.client.OpenShiftConfig;
import io.fabric8.openshift.client.OpenShiftConfigBuilder;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
Expand All @@ -30,7 +31,7 @@ public class OpenShiftClientFactory {

private static final Logger LOG = LoggerFactory.getLogger(OpenShiftClientFactory.class);

private final OpenShiftClient client;
private final UnclosedOpenShiftClient client;

@Inject
public OpenShiftClientFactory(
Expand Down Expand Up @@ -59,7 +60,7 @@ public OpenShiftClientFactory(
if (doTrustCerts != null) {
configBuilder.withTrustCerts(doTrustCerts);
}
this.client = new DefaultOpenShiftClient(configBuilder.build());
this.client = new UnclosedOpenShiftClient(configBuilder.build());
}

/**
Expand All @@ -74,9 +75,24 @@ public OpenShiftClient create() throws InfrastructureException {
@PreDestroy
public void cleanup() {
try {
client.close();
client.doClose();
} catch (RuntimeException ex) {
LOG.error(ex.getMessage());
}
}

/** Decorates the {@link DefaultOpenShiftClient} so that it can not be closed from the outside. */
private static class UnclosedOpenShiftClient extends DefaultOpenShiftClient {

public UnclosedOpenShiftClient(OpenShiftConfig build) {
super(build);
}

@Override
public void close() {}

void doClose() {
super.close();
}
}
}

0 comments on commit 89f3a19

Please sign in to comment.