public URL getNamespacedUrl(String namespace) throws MalformedURLException { URL requestUrl = getRootUrl(); if (!isResourceNamespaced()) { //if resource is not namespaced don't even bother to check the namespace. } else if (Utils.isNotNullOrEmpty(namespace)) { requestUrl = new URL(URLUtils.join(requestUrl.toString(), "namespaces", namespace)); } requestUrl = new URL(URLUtils.join(requestUrl.toString(), resourceT)); return requestUrl; }
private URL getProcessUrl() throws MalformedURLException { URL requestUrl = getRootUrl(); if (getNamespace() != null) { requestUrl = new URL(URLUtils.join(requestUrl.toString(), "namespaces" , getNamespace())); } requestUrl = new URL(URLUtils.join(requestUrl.toString(), "processedtemplates")); return requestUrl; }
@Override public Status list(Integer limitVal, String continueVal) { try { URL requestUrl = getNamespacedUrl(); if(limitVal != null) { requestUrl = new URL(URLUtils.join(requestUrl.toString(), "?limit=" + limitVal.toString())); } else if(continueVal != null) { requestUrl = new URL(URLUtils.join(requestUrl.toString(), "?limit=" + limitVal.toString() + "&continue=" + continueVal)); } Request.Builder requestBuilder = new Request.Builder().get().url(requestUrl); return handleResponse(requestBuilder, Status.class); } catch (InterruptedException | ExecutionException | IOException e) { throw KubernetesClientException.launderThrowable(e); } }
public VersionInfo fetchVersion() { try { Request.Builder requestBuilder = new Request.Builder() .get() .url(URLUtils.join(config.getMasterUrl(), versionEndpoint)); Response response = client.newCall(requestBuilder.build()).execute(); ObjectMapper objectMapper = new ObjectMapper(); Map<String, String> myMap = objectMapper.readValue(response.body().string(), HashMap.class); return new VersionInfo(myMap); } catch(Exception e) { KubernetesClientException.launderThrowable(e); } return null; } }
public L list(Integer limitVal, String continueVal) throws KubernetesClientException { try { URL url = getNamespacedUrl(); if(limitVal != null && continueVal == null) { url = new URL(URLUtils.join(url.toString(), "?limit=" + limitVal.toString())); } else if(continueVal != null) { url = new URL(URLUtils.join(url.toString(), "?continue=" + continueVal + "&limit=" + limitVal.toString() )); } return listRequestHelper(url); } catch (MalformedURLException e) { throw KubernetesClientException.launderThrowable(forOperationType("list"), e); } }
public URL getRootUrl() { try { if (!Utils.isNullOrEmpty(apiGroupName)) { return new URL(URLUtils.join(config.getMasterUrl().toString(), "apis", apiGroupName, apiGroupVersion)); } return new URL(URLUtils.join(config.getMasterUrl().toString(), "api", apiGroupVersion)); } catch (MalformedURLException e) { throw KubernetesClientException.launderThrowable(e); } }
public URL getResourceUrl(String namespace, String name) throws MalformedURLException { if (name == null) { return getNamespacedUrl(namespace); } return new URL(URLUtils.join(getNamespacedUrl(namespace).toString(), name)); }
public URL getResourceUrl() throws MalformedURLException { if (name == null) { return getNamespacedUrl(); } return new URL(URLUtils.join(getNamespacedUrl().toString(), name)); }
@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); } }
protected ResponseBody doGetLog(){ try { URL url = new URL(URLUtils.join(getResourceUrl().toString(), getLogParameters())); Request.Builder requestBuilder = new Request.Builder().get().url(url); Request request = requestBuilder.build(); Response response = client.newCall(request).execute(); ResponseBody body = response.body(); assertResponseCode(request, response); return body; } catch (Throwable t) { throw KubernetesClientException.launderThrowable(forOperationType("doGetLog"), t); } }
protected ResponseBody doGetLog(){ try { URL url = new URL(URLUtils.join(getResourceUrl().toString(), getLogParameters())); Request.Builder requestBuilder = new Request.Builder().get().url(url); Request request = requestBuilder.build(); Response response = client.newCall(request).execute(); ResponseBody body = response.body(); assertResponseCode(request, response); return body; } catch (Throwable t) { throw KubernetesClientException.launderThrowable(forOperationType("doGetLog"), t); } }
@Override public LogWatch watchLog(OutputStream out) { try { URL url = new URL(URLUtils.join(getResourceUrl().toString(), getLogParameters() + "&follow=true")); Request request = new Request.Builder().url(url).get().build(); final LogWatchCallback callback = new LogWatchCallback(out); OkHttpClient clone = client.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build(); clone.newCall(request).enqueue(callback); callback.waitUntilReady(); return callback; } catch (Throwable t) { throw KubernetesClientException.launderThrowable(forOperationType("watchLog"), t); } }
@Override public LogWatch watchLog(OutputStream out) { try { URL url = new URL(URLUtils.join(getResourceUrl().toString(), getLogParameters() + "&follow=true")); Request request = new Request.Builder().url(url).get().build(); final LogWatchCallback callback = new LogWatchCallback(out); OkHttpClient clone = client.newBuilder().readTimeout(0, TimeUnit.MILLISECONDS).build(); clone.newCall(request).enqueue(callback); callback.waitUntilReady(); return callback; } catch (Throwable t) { throw KubernetesClientException.launderThrowable(forOperationType("watchLog"), t); } }
@Buildable(builderPackage = "io.fabric8.kubernetes.api.builder", editableEnabled = false, refs = {@BuildableReference(Config.class)}) public OpenShiftConfig(String openShiftUrl, String oapiVersion, String masterUrl, String apiVersion, String namespace, Boolean trustCerts, Boolean disableHostnameVerification, String caCertFile, String caCertData, String clientCertFile, String clientCertData, String clientKeyFile, String clientKeyData, String clientKeyAlgo, String clientKeyPassphrase, String username, String password, String oauthToken, int watchReconnectInterval, int watchReconnectLimit, int connectionTimeout, int requestTimeout, long rollingTimeout, long scaleTimeout, int loggingInterval, Integer maxConcurrentRequestsPerHost, String httpProxy, String httpsProxy, String[] noProxy, Map<Integer, String> errorMessages, String userAgent, TlsVersion[] tlsVersions, long buildTimeout, long websocketTimeout, long websocketPingInterval, String proxyUsername, String proxyPassword, String trustStoreFile, String trustStorePassphrase, String keyStoreFile, String keyStorePassphrase, String impersonateUsername, String[] impersonateGroups, Map<String, List<String>> impersonateExtras) { super(masterUrl, apiVersion, namespace, trustCerts, disableHostnameVerification, caCertFile, caCertData, clientCertFile, clientCertData, clientKeyFile, clientKeyData, clientKeyAlgo, clientKeyPassphrase, username, password, oauthToken, watchReconnectInterval, watchReconnectLimit, connectionTimeout, requestTimeout, rollingTimeout, scaleTimeout, loggingInterval, maxConcurrentRequestsPerHost, httpProxy, httpsProxy, noProxy, errorMessages, userAgent, tlsVersions, websocketTimeout, websocketPingInterval, proxyUsername, proxyPassword, trustStoreFile, trustStorePassphrase, keyStoreFile, keyStorePassphrase, impersonateUsername, impersonateGroups, impersonateExtras); this.oapiVersion = oapiVersion; this.openShiftUrl = openShiftUrl; this.buildTimeout = buildTimeout; if (this.openShiftUrl == null || this.openShiftUrl.isEmpty()) { this.openShiftUrl = URLUtils.join(getMasterUrl(), "oapi", this.oapiVersion); } if (!this.openShiftUrl.endsWith("/")) { this.openShiftUrl = this.openShiftUrl + "/"; } }
private static String getDefaultOpenShiftUrl(Config config) { String openshiftUrl = Utils.getSystemPropertyOrEnvVar(OPENSHIFT_URL_SYTEM_PROPERTY); if (openshiftUrl != null) { // The OPENSHIFT_URL environment variable may be set to the root url (i.e. without the '/oapi/version' path) in some configurations if (isRootURL(openshiftUrl)) { openshiftUrl = URLUtils.join(openshiftUrl, "oapi", getDefaultOapiVersion(config)); } return openshiftUrl; } else { return URLUtils.join(config.getMasterUrl(), "oapi", getDefaultOapiVersion(config)); } }
@Test public void shouldJoinUrlWithoutQueryParams() { // Given String masterUrl = "https://oso-master-url:8888/kubernetes"; // When final String fullUrl = URLUtils.join(masterUrl, "api"); // Then assertThat(fullUrl, is("https://oso-master-url:8888/kubernetes/api")); }
@Test public void shouldAppendUrlWithMultipleQueryParams() { // Given String masterUrl = "https://oso-master-url:8888/kubernetes?param1=value"; // When final String fullUrl = URLUtils.join(masterUrl, "port?port=port", "host=host"); // Then assertThat(fullUrl, is("https://oso-master-url:8888/kubernetes/port?port=port&host=host¶m1=value")); }
@Test public void shouldAppendUrlWithQueryParams() { // Given String masterUrl = "https://oso-master-url:8888/kubernetes?param1=value"; // When final String fullUrl = URLUtils.join(masterUrl, "port?port=port"); // Then assertThat(fullUrl, is("https://oso-master-url:8888/kubernetes/port?port=port¶m1=value")); }
@Test public void shouldJoinNoneUrl() { // Given String masterUrl = "images.openshift.io"; // When final String fullUrl = URLUtils.join(masterUrl, "api"); // Then assertThat(fullUrl, is("images.openshift.io/api")); }
@Test public void shouldJoinUrlWithQueryParams() { // Given String masterUrl = "https://oso-master-url:8888/kubernetes?key=value"; // When final String fullUrl = URLUtils.join(masterUrl, "api"); // Then assertThat(fullUrl, is("https://oso-master-url:8888/kubernetes/api?key=value")); }