public static <T> String asJson(T object) throws KubernetesClientException { try { return JSON_MAPPER.writeValueAsString(object); } catch (JsonProcessingException e) { throw KubernetesClientException.launderThrowable(e); } }
public static <T> String asYaml(T object) throws KubernetesClientException { try { return YAML_MAPPER.writeValueAsString(object); } catch (JsonProcessingException e) { throw KubernetesClientException.launderThrowable(e); } }
public static RuntimeException launderThrowable(OperationInfo spec, Throwable cause) { if (cause instanceof KubernetesClientException) { return launderThrowable(spec, ((KubernetesClientException)cause).getStatus(), cause); } return launderThrowable(describeOperation(spec)+ " failed.", cause); }
@Override public RecreateFromServerGettable<KubernetesList, KubernetesList, DoneableKubernetesList> load(File file) { try (FileInputStream fis = new FileInputStream(file)) { return load(fis); } catch (IOException e) { throw KubernetesClientException.launderThrowable(e); } }
public InputStream createInputStream(InputStream is) { try { String json = IOHelpers.readFully(is); String replaced = replaceValues(json); return new ByteArrayInputStream(replaced.getBytes()); } catch (IOException e) { throw KubernetesClientException.launderThrowable(e); } }
@Override public Build instantiate(BuildRequest request) { try { updateApiVersion(request); URL instantiationUrl = new URL(URLUtils.join(getResourceUrl().toString(), "instantiate")); RequestBody requestBody = RequestBody.create(JSON, BaseOperation.JSON_MAPPER.writer().writeValueAsString(request)); Request.Builder requestBuilder = new Request.Builder().post(requestBody).url(instantiationUrl); return handleResponse(requestBuilder, Build.class); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } }
@Override public KubernetesList processLocally(File f) { try (FileInputStream is = new FileInputStream(f)) { return processLocally(is); } catch (IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("processLocally"), e); } }
@Override public String getLog() { try(ResponseBody body = doGetLog()) { return body.string(); } catch (IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("getLog"), e); } }
public static RuntimeException launderThrowable(OperationInfo spec, Status status, Throwable cause) { StringBuilder sb = new StringBuilder(); sb.append(describeOperation(spec)+ " failed."); if (status != null && Utils.isNotNullOrEmpty(status.getMessage())) { sb.append("Reason: ").append(status.getMessage()); } return launderThrowable(sb.toString(), cause); }
@Override public T apply(T resource) { try { return create(resource); } catch (Exception e) { throw KubernetesClientException.launderThrowable(forOperationType("create"), e); } } };
@Override public T apply(T resource) { try { return handlePatch(got, resource); } catch (Exception e) { throw KubernetesClientException.launderThrowable(forOperationType("patch"), e); } } };
@Override public T apply(T resource) { try { return createOrReplace(resource); } catch (Exception e) { throw KubernetesClientException.launderThrowable(forOperationType("create or replace"), e); } } };
@Override public URL getRootUrl() { try { return new URL(OpenShiftConfig.wrap(getConfig()).getOpenShiftUrl()); } catch (MalformedURLException e) { throw KubernetesClientException.launderThrowable(e); } }
@Override public URL getRootUrl() { try { return new URL(OpenShiftConfig.wrap(getConfig()).getOpenShiftUrl()); } catch (MalformedURLException e) { throw KubernetesClientException.launderThrowable(e); } }
public L list() throws KubernetesClientException { try { return listRequestHelper(getNamespacedUrl()); } catch (IOException e) { throw KubernetesClientException.launderThrowable(forOperationType("list"), e); } }
@Override public void visit(T t) { try { getRollingUpdater(rollingTimeout, rollingTimeUnit).rollUpdate(getMandatory(), t); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } } };
@Override public T apply(T resource) { try { resource.getMetadata().setResourceVersion(resourceVersion); return handleReplace(resource); } catch (Exception e) { throw KubernetesClientException.launderThrowable(forOperationType("replace"), e); } } };
@Override public Watchable<Watch, Watcher<T>> withResourceVersion(String resourceVersion) { try { return getClass() .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), resourceVersion, isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); } catch (Throwable t) { throw KubernetesClientException.launderThrowable(t); } }
@Override public Deletable<Boolean> withGracePeriod(long gracePeriodSeconds) { try { return getClass() .getConstructor(OkHttpClient.class, getConfigType(), String.class, String.class, String.class, String.class, Boolean.class, getType(), String.class, Boolean.class, long.class, Map.class, Map.class, Map.class, Map.class, Map.class) .newInstance(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), getItem(), getResourceVersion(), isReloadingFromServer(), gracePeriodSeconds, getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); } catch (Throwable t) { throw KubernetesClientException.launderThrowable(t); } }
@Override public Resource<CronJob, DoneableCronJob> load(InputStream is) { try { CronJob item = unmarshal(is, CronJob.class); return new CronJobOperationsImpl(client, getConfig(), getAPIGroup(), getAPIVersion(), getNamespace(), getName(), isCascading(), item, getResourceVersion(), isReloadingFromServer(), getGracePeriodSeconds(), getLabels(), getLabelsNot(), getLabelsIn(), getLabelsNotIn(), getFields()); } catch (Throwable t) { throw KubernetesClientException.launderThrowable(t); } } }