本文整理了Java中io.fabric8.kubernetes.client.utils.Utils
类的一些代码示例,展示了Utils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils
类的具体详情如下:
包路径:io.fabric8.kubernetes.client.utils.Utils
类名称:Utils
暂无
代码示例来源:origin: fabric8io/kubernetes-client
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;
}
代码示例来源:origin: fabric8io/kubernetes-client
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);
}
}
代码示例来源:origin: fabric8io/kubernetes-client
public static void configFromSysPropsOrEnvVars(Config config) {
config.setTrustCerts(Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY, config.isTrustCerts()));
config.setDisableHostnameVerification(Utils.getSystemPropertyOrEnvVar(KUBERNETES_DISABLE_HOSTNAME_VERIFICATION_SYSTEM_PROPERTY, config.isDisableHostnameVerification()));
config.setMasterUrl(Utils.getSystemPropertyOrEnvVar(KUBERNETES_MASTER_SYSTEM_PROPERTY, config.getMasterUrl()));
config.setApiVersion(Utils.getSystemPropertyOrEnvVar(KUBERNETES_API_VERSION_SYSTEM_PROPERTY, config.getApiVersion()));
config.setNamespace(Utils.getSystemPropertyOrEnvVar(KUBERNETES_NAMESPACE_SYSTEM_PROPERTY, config.getNamespace()));
config.setCaCertFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getCaCertFile()));
config.setCaCertData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CA_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getCaCertData()));
config.setClientCertFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_CERTIFICATE_FILE_SYSTEM_PROPERTY, config.getClientCertFile()));
config.setClientCertData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_CERTIFICATE_DATA_SYSTEM_PROPERTY, config.getClientCertData()));
config.setClientKeyFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_FILE_SYSTEM_PROPERTY, config.getClientKeyFile()));
config.setClientKeyData(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_DATA_SYSTEM_PROPERTY, config.getClientKeyData()));
config.setClientKeyAlgo(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_ALGO_SYSTEM_PROPERTY, config.getClientKeyAlgo()));
config.setClientKeyPassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_CLIENT_KEY_PASSPHRASE_SYSTEM_PROPERTY, new String(config.getClientKeyPassphrase())));
config.setUserAgent(Utils.getSystemPropertyOrEnvVar(KUBERNETES_USER_AGENT, config.getUserAgent()));
config.setTrustStorePassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUSTSTORE_PASSPHRASE_PROPERTY, config.getTrustStorePassphrase()));
config.setTrustStoreFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_TRUSTSTORE_FILE_PROPERTY, config.getTrustStoreFile()));
config.setKeyStorePassphrase(Utils.getSystemPropertyOrEnvVar(KUBERNETES_KEYSTORE_PASSPHRASE_PROPERTY, config.getKeyStorePassphrase()));
config.setKeyStoreFile(Utils.getSystemPropertyOrEnvVar(KUBERNETES_KEYSTORE_FILE_PROPERTY, config.getKeyStoreFile()));
config.setOauthToken(Utils.getSystemPropertyOrEnvVar(KUBERNETES_OAUTH_TOKEN_SYSTEM_PROPERTY, config.getOauthToken()));
config.setUsername(Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_BASIC_USERNAME_SYSTEM_PROPERTY, config.getUsername()));
config.setPassword(Utils.getSystemPropertyOrEnvVar(KUBERNETES_AUTH_BASIC_PASSWORD_SYSTEM_PROPERTY, config.getPassword()));
config.setImpersonateUsername(Utils.getSystemPropertyOrEnvVar(KUBERNETES_IMPERSONATE_USERNAME, config.getImpersonateUsername()));
String configuredImpersonateGroups = Utils.getSystemPropertyOrEnvVar(KUBERNETES_IMPERSONATE_GROUP, config.getImpersonateGroup());
String configuredWatchReconnectInterval = Utils.getSystemPropertyOrEnvVar(KUBERNETES_WATCH_RECONNECT_INTERVAL_SYSTEM_PROPERTY);
代码示例来源:origin: fabric8io/kubernetes-client
public static String getSystemPropertyOrEnvVar(String systemPropertyName, String defaultValue) {
return getSystemPropertyOrEnvVar(systemPropertyName, convertSystemPropertyNameToEnvVar(systemPropertyName), defaultValue);
}
代码示例来源:origin: fabric8io/kubernetes-client
public static String getProperty(Map<String, Object> properties, String propertyName, String defaultValue) {
String answer = (String) properties.get(propertyName);
if (!isNullOrEmpty(answer)) {
return answer;
}
return getSystemPropertyOrEnvVar(propertyName, defaultValue);
}
代码示例来源:origin: fabric8io/kubernetes-client
@Override
public void visit(ObjectMetaBuilder builder) {
if (Utils.isNotNullOrEmpty(explicitNamespace)) {
builder.withNamespace(explicitNamespace);
} else if (Utils.isNullOrEmpty(builder.getNamespace())) {
builder.withNamespace(fallbackNamespace);
}
}
}
代码示例来源:origin: fabric8io/kubernetes-client
if (Utils.isNotNullOrEmpty(labelQueryParam)) {
httpUrlBuilder.addQueryParameter("labelSelector", labelQueryParam);
if (Utils.isNotNullOrEmpty(fieldQueryString)) {
httpUrlBuilder.addQueryParameter("fieldSelector", fieldQueryString);
if (this.resourceVersion.get() != null) {
httpUrlBuilder.addQueryParameter("resourceVersion", this.resourceVersion.get());
.get()
.url(httpUrlBuilder.build())
.addHeader("Origin", requestUrl.getProtocol() + "://" + requestUrl.getHost() + ":" + requestUrl.getPort())
.build();
代码示例来源:origin: fabric8io/kubernetes-client
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);
}
}
代码示例来源:origin: io.fabric8.pipeline/kubernetes-pipeline-arquillian-steps
protected URL toURL(String url) {
if (Utils.isNullOrEmpty(url)) {
return null;
}
try {
return new URL(url);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("Specified url:["+url+"] is malformed");
}
}
代码示例来源:origin: fabric8io/kubernetes-client
final AtomicReference<Integer> replicasRef = new AtomicReference<>(0);
ScheduledFuture poller = executor.scheduleWithFixedDelay(tPoller, 0, POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);
try {
if (Utils.waitUntilReady(queue, rollingTimeout, rollingTimeUnit)) {
Log.debug("{}/{} pod(s) ready for {}: {} in namespace: {}.",
replicasRef.get(), count, getType().getSimpleName(), name, namespace);
} else {
Log.error("{}/{} pod(s) ready for {}: {} in namespace: {} after waiting for {} seconds so giving up",
replicasRef.get(), count, getType().getSimpleName(), name, namespace, rollingTimeUnit.toSeconds(rollingTimeout));
代码示例来源:origin: io.fabric8/fabric8-arquillian
/**
* Applies the kubernetes json url to the configuration.
*
* @param map The arquillian configuration.
*/
private static URL getKubernetesConfigurationUrl(Map<String, String> map) throws MalformedURLException {
if (map.containsKey(ENVIRONMENT_CONFIG_URL)) {
return new URL(map.get(ENVIRONMENT_CONFIG_URL));
} else if (map.containsKey(ENVIRONMENT_CONFIG_RESOURCE_NAME)) {
String resourceName = map.get(ENVIRONMENT_CONFIG_RESOURCE_NAME);
return findConfigResource(resourceName);
} else if (Strings.isNotBlank(Utils.getSystemPropertyOrEnvVar(ENVIRONMENT_CONFIG_URL, ""))) {
return new URL(Utils.getSystemPropertyOrEnvVar(ENVIRONMENT_CONFIG_URL, ""));
} else {
String defaultValue = "/" + DEFAULT_CONFIG_FILE_NAME;
String resourceName = Utils.getSystemPropertyOrEnvVar(ENVIRONMENT_CONFIG_RESOURCE_NAME, defaultValue);
URL answer = findConfigResource(resourceName);
if (answer == null) {
}
return answer;
}
}
代码示例来源:origin: org.eclipse.che.infrastructure/infrastructure-openshift
@Override
protected Interceptor buildKubernetesInterceptor(Config config) {
final String oauthToken;
if (Utils.isNotNullOrEmpty(config.getUsername())
&& Utils.isNotNullOrEmpty(config.getPassword())) {
synchronized (getHttpClient()) {
try {
OkHttpClient clone = builder.build();
String credential = Credentials.basic(config.getUsername(), config.getPassword());
URL url = new URL(URLUtils.join(config.getMasterUrl(), AUTHORIZE_PATH));
Response response =
clone
oauthToken = token;
} catch (Exception e) {
throw KubernetesClientException.launderThrowable(e);
} else if (Utils.isNotNullOrEmpty(config.getOauthToken())) {
oauthToken = config.getOauthToken();
} else {
if (isNotNullOrEmpty(oauthToken)) {
Request authReq =
chain.request().newBuilder().addHeader("Authorization", "Bearer " + oauthToken).build();
代码示例来源:origin: fabric8io/kubernetes-client
String token = null;
if (Utils.isNotNullOrEmpty(oauthToken.get()) && Utils.isNullOrEmpty(request.header(AUTHORIZATION))) {
token = oauthToken.get();
} else if (Utils.isNotNullOrEmpty(config.getUsername()) && Utils.isNotNullOrEmpty(config.getPassword())) {
token = acquireNewToken();
} else if (Utils.isNotNullOrEmpty(config.getOauthToken())) {
token = config.getOauthToken();
oauthToken.set(token);
if (Utils.isNotNullOrEmpty(token) && Utils.isNullOrEmpty(request.header(AUTHORIZATION))) {
setAuthHeader(builder, token);
} else if (Utils.isNotNullOrEmpty(config.getUsername()) && Utils.isNotNullOrEmpty(config.getPassword())) {
token = acquireNewToken();
} else if (Utils.isNotNullOrEmpty(config.getOauthToken())) {
token = config.getOauthToken();
oauthToken.set(token);
if (Utils.isNotNullOrEmpty(token)) {
代码示例来源:origin: fabric8io/kubernetes-client
final AtomicReference<Integer> replicasRef = new AtomicReference<>(0);
ScheduledFuture poller = executor.scheduleWithFixedDelay(deploymentPoller, 0, POLL_INTERVAL_MS, TimeUnit.MILLISECONDS);
try {
if (Utils.waitUntilReady(queue, getConfig().getScaleTimeout(), TimeUnit.MILLISECONDS)) {
LOG.debug("{}/{} pod(s) ready for Deployment: {} in namespace: {}.",
replicasRef.get(), count, name, namespace);
} else {
LOG.error("{}/{} pod(s) ready for Deployment: {} in namespace: {} after waiting for {} seconds so giving up",
replicasRef.get(), count, name, namespace, TimeUnit.MILLISECONDS.toSeconds(getConfig().getScaleTimeout()));
代码示例来源:origin: fabric8io/kubernetes-client
private String getQueryParameters() throws MalformedURLException {
StringBuilder sb = new StringBuilder();
sb.append(URLUtils.join(getResourceUrl().toString(), "instantiatebinary"));
if (Utils.isNullOrEmpty(message)) {
sb.append("?commit=");
} else {
sb.append("?commit=").append(message);
}
if (!Utils.isNullOrEmpty(authorName)) {
sb.append("&revision.authorName=").append(authorName);
}
if (!Utils.isNullOrEmpty(authorEmail)) {
sb.append("&revision.authorEmail=").append(authorEmail);
}
if (!Utils.isNullOrEmpty(committerName)) {
sb.append("&revision.committerName=").append(committerName);
}
if (!Utils.isNullOrEmpty(committerEmail)) {
sb.append("&revision.committerEmail=").append(committerEmail);
}
if (!Utils.isNullOrEmpty(commit)) {
sb.append("&revision.commit=").append(commit);
}
if (!Utils.isNullOrEmpty(asFile)) {
sb.append("&asFile=").append(asFile);
}
return sb.toString();
}
代码示例来源:origin: io.fabric8/fabric8-karaf-cm
private void updateConfig(ConfigMap map) {
Long ver = Long.parseLong(map.getMetadata().getResourceVersion());
String pid = map.getMetadata().getLabels().get(pidLabel);
String[] p = parsePid(pid);
final Configuration config = getConfiguration(configAdmin.get(), pid, p[0], p[1]);
final Map<String, String> configMapData = map.getData();
if (Utils.isNotNullOrEmpty(cfgString)) {
java.util.Properties cfg = new java.util.Properties();
cfg.load(new StringReader(cfgString));
configMapCfg.put(FABRIC8_PID, pid);
configMapCfg.put(FABRIC8_K8S_META_RESOURCE_VERSION, ver);
configMapCfg.put(FABRIC8_K8S_META_NAME, map.getMetadata().getName());
configMapCfg.put(FABRIC8_K8S_META_NAMESPACE, map.getMetadata().getNamespace());
代码示例来源:origin: fabric8io/kubernetes-client
@Override
public AttributeSet extract(HasMetadata o) {
AttributeSet attributes = new AttributeSet();
if (!Utils.isNullOrEmpty(o.getKind())) {
attributes = attributes.add(new Attribute(KIND, o.getKind().toLowerCase()));
}
if (!Utils.isNullOrEmpty(o.getMetadata().getName())) {
attributes = attributes.add(new Attribute(NAME, o.getMetadata().getName()));
}
if (!Utils.isNullOrEmpty(o.getMetadata().getNamespace())) {
attributes = attributes.add(new Attribute(NAMESPACE, o.getMetadata().getNamespace()));
}
if (o.getMetadata().getLabels() != null) {
for (Map.Entry<String, String> label : o.getMetadata().getLabels().entrySet()) {
attributes = attributes.add(new Attribute(LABEL_KEY_PREFIX + label.getKey(), label.getValue()));
}
}
return attributes;
}
代码示例来源:origin: fabric8io/kubernetes-client
private static String display(HasMetadata item) {
StringBuilder sb = new StringBuilder();
sb.append("[ ");
if (Utils.isNotNullOrEmpty(item.getKind())) {
sb.append("Kind:").append(item.getKind());
}
if (Utils.isNotNullOrEmpty(item.getMetadata().getName())) {
sb.append("Name:").append(item.getMetadata().getName());
}
if (item.getMetadata().getLabels()!=null && !item.getMetadata().getLabels().isEmpty()) {
sb.append("Lables: [ ");
for (Map.Entry<String,String> entry : item.getMetadata().getLabels().entrySet()) {
sb.append(entry.getKey()).append(":").append(entry.getValue()).append(" ");
}
sb.append("]");
}
sb.append(" ]");
return sb.toString();
}
}
代码示例来源:origin: fabric8io/kubernetes-client
public KubernetesList processLocally(Map<String, String> valuesMap) {
String namespace = getItem() != null ? getItem().getMetadata().getNamespace() : getNamespace();
if (namespace == null) {
namespace = getConfig().getNamespace();
String name = getItem() != null ? getItem().getMetadata().getName() : getName();
if (valuesMap.containsKey(parameterName)) {
parameterValue = valuesMap.get(parameterName);
} else if (Utils.isNotNullOrEmpty(parameter.getValue())) {
parameterValue = parameter.getValue();
} else if (EXPRESSION.equals(parameter.getGenerate())) {
throw KubernetesClientException.launderThrowable(e);
代码示例来源:origin: fabric8io/kubernetes-client
@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 + ".");
}
内容来源于网络,如有侵权,请联系作者删除!