use of io.fabric8.kubernetes.client.dsl.internal.PodOperationsImpl in project syndesis by syndesisio.
the class KubernetesSupport method watchLog.
/*
* Feeds the controller of the given podName to the callback handler for processing.
*
* We do this instead of using the watchLog() feature of the k8s client lib because it really sucks due to:
* 1. You can't configure the timestamps option or the sinceTime option. Need to resume log downloads.
* 2. It seems to need extra threads..
* 3. It might be hiding some of the http failure conditions.
*
*/
protected void watchLog(String podName, Consumer<InputStream> handler, String sinceTime, Executor executor) throws IOException {
try {
PodOperationsImpl pod = (PodOperationsImpl) client.pods().withName(podName);
StringBuilder url = new StringBuilder().append(pod.getResourceUrl().toString()).append("/log?pretty=false&follow=true×tamps=true");
if (sinceTime != null) {
url.append("&sinceTime=");
}
Request request = new Request.Builder().url(new URL(url.toString())).get().build();
OkHttpClient clone = okHttpClient.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build();
clone.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
LOG.info("Failure occurred getting controller for pod: {},", podName, e);
handler.accept(null);
}
@Override
public void onResponse(final Call call, final Response response) throws IOException {
executor.execute(() -> {
try {
if (response.code() == 200) {
handler.accept(response.body().byteStream());
} else {
LOG.info("Failure occurred while processing controller for pod: {}, http status: {}, details: {}", podName, response.code(), response.body().string());
handler.accept(null);
}
} catch (IOException e) {
LOG.error("Unexpected Error", e);
}
});
}
});
} catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") RuntimeException t) {
throw new IOException("Unexpected Error", t);
}
}
use of io.fabric8.kubernetes.client.dsl.internal.PodOperationsImpl in project syndesis by syndesisio.
the class SupportUtil method getLogs.
public Optional<Reader> getLogs(String label, String integrationName) {
return client.pods().list().getItems().stream().filter(pod -> integrationName.equals(pod.getMetadata().getLabels().get(label))).findAny().map(pod -> pod.getMetadata().getName()).flatMap(podName -> {
PodOperationsImpl pod = (PodOperationsImpl) client.pods().withName(podName);
try {
Request request = new Request.Builder().url(pod.getResourceUrl().toString() + "/log?pretty=false×tamps=true").build();
Response response = null;
try {
response = okHttpClient.newCall(request).execute();
if (!response.isSuccessful()) {
throw new IOException("Unexpected response from /log endpoint: " + response);
}
return Optional.of(new RegexBasedMasqueradeReader(new BufferedReader(response.body().charStream()), MASKING_REGEXP));
} catch (IOException e) {
// NOPMD
LOG.error("Error downloading log file for integration {}", integrationName, e);
if (response != null) {
response.close();
}
}
} catch (MalformedURLException e) {
LOG.error("Error downloading log file for integration {}", integrationName, e);
}
return Optional.empty();
});
}
Aggregations