本文整理了Java中io.fabric8.kubernetes.client.utils.Utils.isNotNullOrEmpty()
方法的一些代码示例,展示了Utils.isNotNullOrEmpty()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.isNotNullOrEmpty()
方法的具体详情如下:
包路径:io.fabric8.kubernetes.client.utils.Utils
类名称:Utils
方法名:isNotNullOrEmpty
暂无
代码示例来源:origin: fabric8io/kubernetes-client
public static String getSystemPropertyOrEnvVar(String systemPropertyName, String envVarName, String defaultValue) {
String answer = System.getProperty(systemPropertyName);
if (isNotNullOrEmpty(answer)) {
return answer;
}
answer = System.getenv(envVarName);
if (isNotNullOrEmpty(answer)) {
return answer;
}
return defaultValue;
}
代码示例来源:origin: fabric8io/kubernetes-client
public static String getEnvVar(String envVarName, String defaultValue) {
String answer = System.getenv(envVarName);
return isNotNullOrEmpty(answer) ? answer : defaultValue;
}
代码示例来源:origin: fabric8io/kubernetes-client
public static KeyManager[] keyManagers(String certData, String certFile, String keyData, String keyFile, String algo, String passphrase, String keyStoreFile, String keyStorePassphrase) throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, CertificateException, InvalidKeySpecException, IOException {
KeyManager[] keyManagers = null;
if ((Utils.isNotNullOrEmpty(certData) || Utils.isNotNullOrEmpty(certFile)) && (Utils.isNotNullOrEmpty(keyData) || Utils.isNotNullOrEmpty(keyFile))) {
KeyStore keyStore = createKeyStore(certData, certFile, keyData, keyFile, algo, passphrase, keyStoreFile, keyStorePassphrase);
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
kmf.init(keyStore, passphrase.toCharArray());
keyManagers = kmf.getKeyManagers();
}
return keyManagers;
}
代码示例来源:origin: fabric8io/kubernetes-client
/**
* Validates name of Kubernetes Resource name, label or annotation based on Kubernetes regex
*
* @param name Name of resource/label/annotation
* @return
*/
public static boolean isValidName(String name) {
return Utils.isNotNullOrEmpty(name) &&
name.length() < KUBERNETES_DNS1123_LABEL_MAX_LENGTH &&
KUBERNETES_DNS1123_LABEL_REGEX.matcher(name).matches();
}
代码示例来源:origin: fabric8io/kubernetes-client
private static File getDefaultTrustStoreFile() {
String securityDirectory =
System.getProperty("java.home") + File.separator + "lib" + File.separator + "security" + File.separator;
String trustStorePath = System.getProperty(TRUST_STORE_SYSTEM_PROPERTY);
if (Utils.isNotNullOrEmpty(trustStorePath)) {
return new File(trustStorePath);
}
File jssecacertsFile = new File(securityDirectory + "jssecacerts");
if (jssecacertsFile.exists() && jssecacertsFile.isFile()) {
return jssecacertsFile;
}
return new File(securityDirectory + "cacerts");
}
代码示例来源:origin: fabric8io/kubernetes-client
private void addQueryStringParam(HttpUrl.Builder requestUrlBuilder, String name, String value) {
if(Utils.isNotNullOrEmpty(value)) {
requestUrlBuilder.addQueryParameter(name, value);
}
}
代码示例来源:origin: fabric8io/kubernetes-client
private static void loadDefaultKeyStoreFile(KeyStore keyStore, char[] keyStorePassphrase)
throws CertificateException, NoSuchAlgorithmException, IOException {
String keyStorePath = System.getProperty(KEY_STORE_SYSTEM_PROPERTY);
if (Utils.isNotNullOrEmpty(keyStorePath)) {
File keyStoreFile = new File(keyStorePath);
if (loadDefaultStoreFile(keyStore, keyStoreFile, keyStorePassphrase)) {
return;
}
}
keyStore.load(null);
}
代码示例来源:origin: fabric8io/kubernetes-client
public static KeyStore createTrustStore(InputStream pemInputStream, String trustStoreFile, char[] trustStorePassphrase) throws IOException, CertificateException, KeyStoreException, NoSuchAlgorithmException {
KeyStore trustStore = KeyStore.getInstance("JKS");
if (Utils.isNotNullOrEmpty(trustStoreFile)) {
trustStore.load(new FileInputStream(trustStoreFile), trustStorePassphrase);
} else {
loadDefaultTrustStoreFile(trustStore, trustStorePassphrase);
}
while (pemInputStream.available() > 0) {
CertificateFactory certFactory = CertificateFactory.getInstance("X509");
X509Certificate cert = (X509Certificate) certFactory.generateCertificate(pemInputStream);
String alias = cert.getSubjectX500Principal().getName();
trustStore.setCertificateEntry(alias, cert);
}
return trustStore;
}
代码示例来源:origin: fabric8io/kubernetes-client
private static final String describeOperation(OperationInfo operation) {
StringBuilder sb = new StringBuilder();
sb.append("Operation");
if (Utils.isNotNullOrEmpty(operation.getOperationType())) {
sb.append(": [").append(operation.getOperationType() + "]");
}
sb.append(" ");
sb.append(" for kind: [").append(operation.getKind()).append("] ");
sb.append(" with name: [").append(operation.getName()).append("] ");
sb.append(" in namespace: [").append(operation.getNamespace()).append("] ");
return sb.toString();
}
}
代码示例来源:origin: fabric8io/kubernetes-client
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
if (Utils.isNotNullOrEmpty(config.getUsername()) && Utils.isNotNullOrEmpty(config.getPassword())) {
Request authReq = chain.request().newBuilder().addHeader("Authorization", Credentials.basic(config.getUsername(), config.getPassword())).build();
return chain.proceed(authReq);
} else if (Utils.isNotNullOrEmpty(config.getOauthToken())) {
Request authReq = chain.request().newBuilder().addHeader("Authorization", "Bearer " + config.getOauthToken()).build();
return chain.proceed(authReq);
}
return chain.proceed(request);
}
}).addInterceptor(new ImpersonatorInterceptor(config))
代码示例来源:origin: fabric8io/kubernetes-client
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);
}
代码示例来源: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
private void storeSystemProperty(String systemProperty) {
String value = System.getProperty(systemProperty);
if (Utils.isNotNullOrEmpty(value)) {
systemProperties.put(systemProperty, value);
}
}
代码示例来源: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
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
/**
* Returns the api version falling back to the items apiGroupVersion if not null.
* @param <T>
* @param item
* @param apiVersion
* @return
*/
public static <T> String apiVersion(T item, String apiVersion) {
if (item instanceof HasMetadata && Utils.isNotNullOrEmpty(((HasMetadata) item).getApiVersion())) {
return trimVersion(((HasMetadata) item).getApiVersion());
} else if (apiVersion != null && !apiVersion.isEmpty()) {
return trimVersion(apiVersion);
}
return null;
}
代码示例来源:origin: fabric8io/kubernetes-client
/**
* Extracts apiGroupName from apiGroupVersion when in resource for apiGroupName/apiGroupVersion combination
* @param item resource which is being used
* @param apiGroup apiGroupName present if any
* @return Just the apiGroupName part without apiGroupVersion
*/
public static <T> String apiGroup(T item, String apiGroup) {
if (item instanceof HasMetadata && Utils.isNotNullOrEmpty(((HasMetadata) item).getApiVersion())) {
return trimGroupOrNull(((HasMetadata) item).getApiVersion());
} else if (apiGroup != null && !apiGroup.isEmpty()) {
return trimGroup(apiGroup);
}
return null;
}
代码示例来源:origin: fabric8io/spring-cloud-kubernetes
@Bean
public ZipkinSpanReporter reporter(KubernetesClient client, KubernetesZipkinDiscoveryProperties discoveryProperties, SpanMetricReporter spanMetricReporter, ZipkinProperties zipkin) {
String serviceName = discoveryProperties.getServiceName();
String serviceNamespace = Utils.isNotNullOrEmpty(discoveryProperties.getServiceNamespace()) ? discoveryProperties.getServiceNamespace() : client.getNamespace();
List<ServiceInstance> services = getInstances(client, serviceName, serviceNamespace);
String serviceUrl = services.stream()
.findFirst()
.map(s -> s.getUri().toString())
.orElse(null);
return serviceUrl == null || serviceUrl.isEmpty()
? new NullZipkinSpanReporter()
: new HttpZipkinSpanReporter(serviceUrl, zipkin.getFlushInterval(), zipkin.getCompression().isEnabled(), spanMetricReporter);
}
代码示例来源: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
@Override
public void visit(ObjectMetaBuilder builder) {
if (Utils.isNotNullOrEmpty(explicitNamespace)) {
builder.withNamespace(explicitNamespace);
} else if (Utils.isNullOrEmpty(builder.getNamespace())) {
builder.withNamespace(fallbackNamespace);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!