当前位置: 首页>>代码示例>>Java>>正文


Java KubernetesClientException类代码示例

本文整理汇总了Java中io.fabric8.kubernetes.client.KubernetesClientException的典型用法代码示例。如果您正苦于以下问题:Java KubernetesClientException类的具体用法?Java KubernetesClientException怎么用?Java KubernetesClientException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


KubernetesClientException类属于io.fabric8.kubernetes.client包,在下文中一共展示了KubernetesClientException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onRequest

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Namespace, NamespaceList, ?, ?>> ctx = createContext(request.getIntent(), session);
    LOGGER.info("Listing all namespaces.");

    try {
        List<String> namespaces = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (namespaces.isEmpty()) {
            return newResponse("No namespaces found.");
        } else {
            return newResponse("The available namespaces are: " + join(namespaces, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:21,代码来源:GetNamespaces.java

示例2: onRequest

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    if (!getKubernetesClient().isAdaptable(OpenShiftClient.class)) {
        return newFailureNotice("Your cluster is not Openshift!");
    }

    IntentContext<BaseOperation<DeploymentConfig, DeploymentConfigList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all deployment configs for namespace:" + namespace);

    try {
        List<String> deployments = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (deployments.isEmpty()) {
            return newResponse("No deployment configs found.");
        } else {
            return newResponse("The available deployment configs are: " + join(deployments, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:26,代码来源:GetDeploymentConfigs.java

示例3: onRequest

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all failing pods for namespace:" + namespace);

    try {
        List<String> pods = list(ctx)
                .getItems()
                .stream()
                .filter(p -> FAILED_PHASE.equalsIgnoreCase(p.getStatus().getPhase()))
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (pods.isEmpty()) {
            return newResponse("No failing pods found in namespace " + namespace);
        } else {
            return newResponse("The failing pods in namespace " + namespace + " are: " + join(pods, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:23,代码来源:GetFailingPods.java

示例4: onRequest

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Deployment, DeploymentList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all deployments for namespace:" + namespace);

    try {
        List<String> deployments = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (deployments.isEmpty()) {
            return newResponse("No deployments found.");
        } else {
            return newResponse("The available deployments are: " + join(deployments, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:22,代码来源:GetDeployments.java

示例5: onRequest

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Pod, PodList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all pods for namespace:" + namespace);

    try {
        List<String> pods = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (pods.isEmpty()) {
            return newResponse("No pods found in namespace " + namespace);
        } else {
            return newResponse("The available pods in namespace " + namespace + " are: " + join(pods, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:22,代码来源:GetPods.java

示例6: onRequest

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Namespace, NamespaceList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, null);
    if (Utils.isNullOrEmpty(namespace)) {
        throw new IllegalStateException("Namespace needs to be specified either via intent slots, or via session attributes.");
    }
    try {
        LOGGER.info("Create namespace:" + namespace);

        newOperation().create(new NamespaceBuilder()
                .withNewMetadata()
                .withName(namespace)
                .endMetadata()
                .build());


        return newResponse("Successfully created namespace " + namespace);
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:23,代码来源:CreateNamespace.java

示例7: onRequest

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    IntentContext<BaseOperation<Service, ServiceList, ?, ?>> ctx = createContext(request.getIntent(), session);
    String namespace = ctx.getVariable(Variable.Namespace, getKubernetesClient().getNamespace());
    LOGGER.info("Listing all services for namespace:" + namespace);

    try {
        List<String> services = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (services.isEmpty()) {
            return newResponse("No services found in namespace " + namespace);
        } else {
            return newResponse("The available services in namespace " + namespace + " are: " + join(services, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:22,代码来源:GetServices.java

示例8: onRequest

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
@Override
public SpeechletResponse onRequest(IntentRequest request, Session session) throws SpeechletException {
    if (!getKubernetesClient().isAdaptable(OpenShiftClient.class)) {
        return newFailureNotice("Your cluster is not Openshift!");
    }

    IntentContext<BaseOperation<Project, ProjectList, ?, ?>> ctx = createContext(request.getIntent(), session);
    LOGGER.info("Listing all projects.");

    try {
        List<String> projects = list(ctx)
                .getItems()
                .stream()
                .map(d -> d.getMetadata().getName()).collect(Collectors.toList());

        if (projects.isEmpty()) {
            return newResponse("No projects found.");
        } else {
            return newResponse("The available projects are: " + join(projects, ","));
        }
    } catch (KubernetesClientException e) {
        return newFailureNotice(e.getStatus().getMessage());
    }
}
 
开发者ID:fabric8io,项目名称:kubernetes-alexa,代码行数:25,代码来源:GetProjects.java

示例9: execute

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
@Override
public StatusUpdate execute(Integration integration) {
    try {
        openShiftService().scale(integration.getName(), 0);
        logInfo(integration,"Deactivated");
    } catch (KubernetesClientException e) {
        // Ignore 404 errors, means the deployment does not exist for us
        // to scale down
        if( e.getCode() != 404 ) {
            throw e;
        }
    }

    Integration.Status currentStatus = openShiftService().isScaled(integration.getName(), 0)
        ? Integration.Status.Deactivated
            : Integration.Status.Pending;

    return new StatusUpdate(currentStatus);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:20,代码来源:DeactivateHandler.java

示例10: getPodsByName

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
private KubernetesPod getPodsByName(String namespace, String name) throws VmidcException {
    KubernetesPod resultPod = null;

    try {
        Pod pod = getKubernetesClient().pods().inNamespace(namespace).withName(name).get();

        if (pod != null) {
            resultPod = new KubernetesPod(pod.getMetadata().getName(), pod.getMetadata().getNamespace(), pod.getMetadata().getUid(),
                    pod.getSpec().getNodeName());
        }

    } catch (KubernetesClientException e) {
        throw new VmidcException("Failed to get Pods");
    }

    return resultPod;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:18,代码来源:KubernetesPodApi.java

示例11: deleteDeployment

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
/**
 * Deletes the deployment with the given uid, namespace and name. If the targeted deployment is not found, no-op.
 * <p>
 * The additional parameters namespace and name are needed because K8s APIs
 * do not support queries by uid
 *
 * @param uid  the unique identifier of the deployment to be deleted
 * @param namespace  the namespace of the deployment to be deleted
 * @param name  the name of the deployment to be deleted
 * @throws VmidcException  if a K8s SDK specific exception is caught
 */
public void deleteDeployment(String uid, String namespace, String name) throws VmidcException {
    if (uid == null) {
        throw new IllegalArgumentException("Uid should not be null");
    }

    if (name == null) {
        throw new IllegalArgumentException("Name should not be null");
    }

    if (namespace == null) {
        throw new IllegalArgumentException("Namespace should not be null");
    }

    KubernetesDeployment deployment = getDeploymentById(uid, namespace, name);
    if (deployment == null) {
        LOG.info(String.format("The deployment with id %s, name %s and namespace %s was not found. Nothing to do.", uid, name, namespace));
        return;
    }

    try {
        getKubernetesClient().resource(deployment.getDeploymentResource()).delete();
    } catch (KubernetesClientException e) {
        throw new VmidcException("Failed to delete the deployment");
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:37,代码来源:KubernetesDeploymentApi.java

示例12: getDeploymentByName

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
private KubernetesDeployment getDeploymentByName(String namespace, String name) throws VmidcException {
    KubernetesDeployment resultDeployment = null;

    try {
        Deployment deployment = getKubernetesClient().extensions().deployments().inNamespace(namespace).withName(name).get();

        if (deployment != null) {
            resultDeployment = new KubernetesDeployment(
                    deployment.getMetadata().getName(),
                    deployment.getMetadata().getNamespace(),
                    deployment.getMetadata().getUid(),
                    deployment.getSpec().getReplicas(),
                    deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImage(),
                    deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getImagePullPolicy());
            resultDeployment.setDeploymentResource(deployment);
            Integer availableReplicas = deployment.getStatus().getAvailableReplicas();
            resultDeployment.setAvailableReplicaCount(availableReplicas == null ? 0 : availableReplicas.intValue());
        }

    } catch (KubernetesClientException e) {
        throw new VmidcException("Failed to get the deployment");
    }

    return resultDeployment;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:26,代码来源:KubernetesDeploymentApi.java

示例13: stopWatching

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
private final void stopWatching(@Observes @BeforeDestroyed(ApplicationScoped.class) @Priority(LIBRARY_BEFORE) final Object event) throws Exception {
  final Closeable watch = this.watch;
  if (watch != null) {
    KubernetesClientException closeException = this.closeException;
    try {
      watch.close();
    } catch (final Exception everything) {
      if (closeException != null) {
        closeException.addSuppressed(everything);
        throw closeException;
      } else {
        throw everything;
      }
    }
    if (closeException != null) {
      throw closeException;
    }
  }
}
 
开发者ID:microbean,项目名称:microbean-kubernetes-client-cdi,代码行数:20,代码来源:KubernetesClientExtension.java

示例14: savePodLog

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
public Path savePodLog(final Pod pod, final String phase) {
	Path logFile = null;
	try {
		final Path logDir = getPodLogsDir().resolve(
				TestParent.getCurrentTestClass());
		logDir.toFile().mkdirs();
		logFile = (phase == null) ? Files.createFile(logDir.resolve(String
				.format("%s.log", pod.getMetadata().getName()))) : Files
				.createFile(logDir.resolve(String.format("%s-%s.log",
						phase, pod.getMetadata().getName())));
	} catch (IOException | KubernetesClientException ex) {
		LOGGER.debug("Unable to create log file", ex);
		return null;
	}
	try {
		List<String> podLog = Arrays.asList(getRuntimeLog(pod).split("\n"));
		Files.write(logFile, podLog, Charset.defaultCharset());
		return logFile;
	} catch (Throwable t) {
		LOGGER.warn("Unable to save logs for pod: {}", pod.getMetadata().getName());
		LOGGER.debug("Stacktrace: ", t);
		return null;
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:25,代码来源:OpenshiftUtil.java

示例15: savePodLogWithObserver

import io.fabric8.kubernetes.client.KubernetesClientException; //导入依赖的package包/类
public Path savePodLogWithObserver(final Pod pod, final String phase) {
	Path logFile = null;
	try {
		final Path logDir = getPodLogsDir().resolve(
				TestParent.getCurrentTestClass());
		logDir.toFile().mkdirs();
		logFile = (phase == null) ? Files.createFile(logDir.resolve(String
				.format("%s.log", pod.getMetadata().getName()))) : Files
				.createFile(logDir.resolve(String.format("%s-%s.log",
						phase, pod.getMetadata().getName())));
	} catch (IOException | KubernetesClientException ex) {
		LOGGER.debug("Unable to create log file", ex);
		return null;
	}
	try {
		List<String> podLog = new ArrayList<>();
		observeRuntimeLog(pod).forEach(podLog::add);
		Files.write(logFile, podLog, Charset.defaultCharset());
		return logFile;
	} catch (Throwable t) {
		LOGGER.warn("Unable to save logs for pod: {}", pod.getMetadata().getName());
		LOGGER.debug("Stacktrace: ", t);
		return null;
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:26,代码来源:OpenshiftUtil.java


注:本文中的io.fabric8.kubernetes.client.KubernetesClientException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。