@Override public T replace(T item) { throw new KubernetesClientException("Cannot update read-only resources"); }
@Override public T patch(T item) { throw new KubernetesClientException("Cannot update read-only resources"); }
@Override public D edit() throws KubernetesClientException { throw new KubernetesClientException("Cannot edit read-only resources"); }
public static RuntimeException launderThrowable(String message, Throwable cause) { if (cause instanceof RuntimeException) { return ((RuntimeException) cause); } else if (cause instanceof Error) { throw ((Error) cause); } else if (cause instanceof InterruptedException) { Thread.currentThread().interrupt(); } throw new KubernetesClientException(message, cause); }
@Override public void onClosed(WebSocket webSocket, int code, String reason) { logger.debug("WebSocket close received. code: {}, reason: {}", code, reason); if (forceClosed.get()) { logger.debug("Ignoring onClose for already closed/closing websocket"); return; } if (currentReconnectAttempt.get() >= reconnectLimit && reconnectLimit >= 0) { closeEvent(new KubernetesClientException("Connection unexpectedly closed")); return; } scheduleReconnect(); } });
public static KubernetesClientException requestException(Request request, Exception e) { StringBuilder sb = new StringBuilder(); sb.append("Error executing: ").append(request.method()) .append(" at: ").append(request.url().toString()) .append(". Cause: ").append(e.getMessage()); return new KubernetesClientException(sb.toString(), e); }
public static KubernetesClientException requestFailure(Request request, Status status) { StringBuilder sb = new StringBuilder(); sb.append("Failure executing: ").append(request.method()) .append(" at: ").append(request.url().toString()).append("."); if (status.getMessage() != null && !status.getMessage().isEmpty()) { sb.append(" Message: ").append(status.getMessage()).append("."); } if (status != null && !status.getAdditionalProperties().containsKey(CLIENT_STATUS_FLAG)) { sb.append(" Received status: ").append(status).append("."); } return new KubernetesClientException(sb.toString(), status.getCode(), status); }
public NamespaceVisitFromServerGetWatchDeleteRecreateWaitApplicableImpl(OkHttpClient client, Config config, String namespace, String explicitNamespace, Boolean fromServer, Boolean deletingExisting, List<Visitor> visitors, Object item, long gracePeriodSeconds, Boolean cascading) { super(client, config, null, null, null, null, null); this.fallbackNamespace = namespace; this.explicitNamespace = explicitNamespace; this.fromServer = fromServer; this.deletingExisting = deletingExisting; this.visitors = visitors != null ? new ArrayList<>(visitors) : new ArrayList<Visitor>(); this.item = item; this.handler = handlerOf(item); this.cascading = cascading; if (handler == null) { throw new KubernetesClientException("No handler found for object:" + item); } this.gracePeriodSeconds = gracePeriodSeconds; this.visitors.add(new ChangeNamespace(explicitNamespace, fallbackNamespace)); }
public DefaultOpenShiftClient(OkHttpClient httpClient, OpenShiftConfig config) throws KubernetesClientException { super(httpClient, config); try { this.httpClient = clientWithOpenShiftOAuthInterceptor(httpClient); this.delegate = new DefaultKubernetesClient(this.httpClient, config); this.openShiftUrl = new URL(config.getOpenShiftUrl()); } catch (MalformedURLException e) { throw new KubernetesClientException("Could not create client", e); } }
public DefaultOpenShiftClient(final OpenShiftConfig config) throws KubernetesClientException { super(config); try { this.httpClient = clientWithOpenShiftOAuthInterceptor(this.httpClient); this.delegate = new DefaultKubernetesClient(this.httpClient, config); this.openShiftUrl = new URL(config.getOpenShiftUrl()); } catch (MalformedURLException e) { throw new KubernetesClientException("Could not create client", e); } }
@Override public void onFailure(WebSocket webSocket, Throwable t, Response response) { //If we already called onClosed() or onFailed() before, we need to abort. if (explicitlyClosed.get() || closed.get() || !failed.compareAndSet(false, true) ) { //We are not going to notify the listener, sicne we've already called onClose(), so let's log a debug/warning. if (LOGGER.isDebugEnabled()) { LOGGER.warn("Received [" + t.getClass().getCanonicalName() + "], with message:[" + t.getMessage() + "] after ExecWebSocketListener is closed, Ignoring."); } return; } try { Status status = OperationSupport.createStatus(response); LOGGER.error("Exec Failure: HTTP:" + status.getCode() + ". Message:" + status.getMessage(), t); //We only need to queue startup failures. if (!started.get()) { queue.add(new KubernetesClientException(status)); } cleanUpOnce(); } finally { if (listener != null) { listener.onFailure(t, response); } } }
protected <T> String checkNamespace(T item) { String operationNs = getNamespace(); String itemNs = (item instanceof HasMetadata && ((HasMetadata)item).getMetadata() != null) ? ((HasMetadata) item).getMetadata().getNamespace() : null; if (Utils.isNullOrEmpty(operationNs) && Utils.isNullOrEmpty(itemNs)) { if (!isResourceNamespaced()) { return null; } else { throw new KubernetesClientException("Namespace not specified. But operation requires namespace."); } } else if (Utils.isNullOrEmpty(itemNs)) { return operationNs; } else if (Utils.isNullOrEmpty(operationNs)) { return itemNs; } else if (itemNs.equals(operationNs)) { return itemNs; } throw new KubernetesClientException("Namespace mismatch. Item namespace:" + itemNs + ". Operation namespace:" + operationNs + "."); }
public BaseClient(final OkHttpClient httpClient, Config config) throws KubernetesClientException { try { this.httpClient = httpClient; this.namespace = config.getNamespace(); this.configuration = config; this.apiVersion = config.getApiVersion(); if (config.getMasterUrl() == null) { throw new KubernetesClientException("Unknown Kubernetes master URL - " + "please set with the builder, or set with either system property \"" + Config.KUBERNETES_MASTER_SYSTEM_PROPERTY + "\"" + " or environment variable \"" + Utils.convertSystemPropertyNameToEnvVar(Config.KUBERNETES_MASTER_SYSTEM_PROPERTY) + "\""); } this.masterUrl = new URL(config.getMasterUrl()); } catch (Exception e) { throw KubernetesClientException.launderThrowable(e); } }
protected <T> String checkName(T item) { String operationName = getName(); String itemName = item instanceof HasMetadata ? ((HasMetadata) item).getMetadata().getName() : null; if (Utils.isNullOrEmpty(operationName) && Utils.isNullOrEmpty(itemName)) { return null; } else if (Utils.isNullOrEmpty(itemName)) { return operationName; } else if (Utils.isNullOrEmpty(operationName)) { return itemName; } else if (itemName.equals(operationName)) { return itemName; } throw new KubernetesClientException("Name mismatch. Item name:" + itemName + ". Operation name:" + operationName + "."); }
@Override public void onOpen(WebSocket webSocket, Response response) { try { if (in instanceof PipedInputStream && input != null) { input.connect((PipedInputStream) in); } if (out instanceof PipedOutputStream && output != null) { output.connect((PipedOutputStream) out); } if (err instanceof PipedOutputStream && error != null) { error.connect((PipedOutputStream) err); } if (errChannel instanceof PipedOutputStream && errorChannel != null) { errorChannel.connect((PipedOutputStream) errChannel); } webSocketRef.set(webSocket); executorService.submit(pumper); started.set(true); queue.add(true); } catch (IOException e) { queue.add(new KubernetesClientException(OperationSupport.createStatus(response))); } finally { if (listener != null) { listener.onOpen(response); } } }
@Override protected <T> String checkNamespace(T item) { String operationNs = getNamespace(); String itemNs = (item instanceof HasMetadata && ((HasMetadata)item).getMetadata() != null) ? ((HasMetadata) item).getMetadata().getNamespace() : null; if (Utils.isNullOrEmpty(operationNs) && Utils.isNullOrEmpty(itemNs)) { return null; } else if (Utils.isNullOrEmpty(itemNs)) { return operationNs; } else if (Utils.isNullOrEmpty(operationNs)) { return itemNs; } else if (itemNs.equals(operationNs)) { return itemNs; } throw new KubernetesClientException("Namespace mismatch. Item namespace:" + itemNs + ". Operation namespace:" + operationNs + "."); }
@Override public StatefulSet updateImage(String image) { StatefulSet oldRC = get(); if (oldRC == null) { throw new KubernetesClientException("Existing StatefulSet doesn't exist"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() > 1) { throw new KubernetesClientException("Image update is not supported for multicontainer pods"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() == 0) { throw new KubernetesClientException("Pod has no containers!"); } Container updatedContainer = new ContainerBuilder(oldRC.getSpec().getTemplate().getSpec().getContainers().iterator().next()).withImage(image).build(); StatefulSetBuilder newRCBuilder = new StatefulSetBuilder(oldRC); newRCBuilder.editMetadata().withResourceVersion(null).endMetadata() .editSpec().editTemplate().editSpec().withContainers(Collections.singletonList(updatedContainer)) .endSpec().endTemplate().endSpec(); return new StatefulSetRollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build()); }
@Override public ReplicaSet updateImage(String image) { ReplicaSet oldRC = get(); if (oldRC == null) { throw new KubernetesClientException("Existing replica set doesn't exist"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() > 1) { throw new KubernetesClientException("Image update is not supported for multicontainer pods"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() == 0) { throw new KubernetesClientException("Pod has no containers!"); } Container updatedContainer = new ContainerBuilder(oldRC.getSpec().getTemplate().getSpec().getContainers().iterator().next()).withImage(image).build(); ReplicaSetBuilder newRCBuilder = new ReplicaSetBuilder(oldRC); newRCBuilder.editMetadata().withResourceVersion(null).endMetadata() .editSpec().editTemplate().editSpec().withContainers(Collections.singletonList(updatedContainer)) .endSpec().endTemplate().endSpec(); return new ReplicaSetRollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build()); }
@Override public ReplicationController updateImage(String image) { ReplicationController oldRC = get(); if (oldRC == null) { throw new KubernetesClientException("Existing replication controller doesn't exist"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() > 1) { throw new KubernetesClientException("Image update is not supported for multicontainer pods"); } if (oldRC.getSpec().getTemplate().getSpec().getContainers().size() == 0) { throw new KubernetesClientException("Pod has no containers!"); } Container updatedContainer = new ContainerBuilder(oldRC.getSpec().getTemplate().getSpec().getContainers().iterator().next()).withImage(image).build(); ReplicationControllerBuilder newRCBuilder = new ReplicationControllerBuilder(oldRC); newRCBuilder.editMetadata().withResourceVersion(null).endMetadata() .editSpec().editTemplate().editSpec().withContainers(Collections.singletonList(updatedContainer)) .endSpec().endTemplate().endSpec(); return new ReplicationControllerRollingUpdater(client, config, namespace).rollUpdate(oldRC, newRCBuilder.build()); }
@Override public HasMetadata createOrReplace() { HasMetadata meta = acceptVisitors(asHasMetadata(item), visitors); ResourceHandler<HasMetadata, HasMetadataVisitiableBuilder> h = handlerOf(meta); HasMetadata r = h.reload(client, config, meta.getMetadata().getNamespace(), meta); String namespaceToUse = meta.getMetadata().getNamespace(); if (r == null) { return h.create(client, config, namespaceToUse, meta); } else if (deletingExisting) { Boolean deleted = h.delete(client, config, namespaceToUse, meta); if (!deleted) { throw new KubernetesClientException("Failed to delete existing item:" + meta); } return h.create(client, config, namespaceToUse, meta); } else if (ResourceCompare.equals(r, meta)) { LOGGER.debug("Item has not changed. Skipping"); return meta; } else { return h.replace(client, config, namespaceToUse, meta); } }