Search in sources :

Example 16 with ApiException

use of io.kubernetes.client.ApiException in project seldon-core by SeldonIO.

the class KubeCRDHandlerImpl method getOwnedDeployments.

@Override
public ExtensionsV1beta1DeploymentList getOwnedDeployments(String seldonDeploymentName) {
    try {
        ApiClient client = Config.defaultClient();
        ExtensionsV1beta1Api api = new ExtensionsV1beta1Api(client);
        ExtensionsV1beta1DeploymentList l = api.listNamespacedDeployment(namespace, null, null, null, false, Constants.LABEL_SELDON_ID + "=" + seldonDeploymentName, 1, null, null, false);
        return l;
    } catch (IOException e) {
        logger.error("Failed to get deployment list for " + seldonDeploymentName, e);
        return null;
    } catch (ApiException e) {
        logger.error("Failed to get deployment list for " + seldonDeploymentName, e);
        return null;
    }
}
Also used : ExtensionsV1beta1DeploymentList(io.kubernetes.client.models.ExtensionsV1beta1DeploymentList) ExtensionsV1beta1Api(io.kubernetes.client.apis.ExtensionsV1beta1Api) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient) ApiException(io.kubernetes.client.ApiException)

Example 17 with ApiException

use of io.kubernetes.client.ApiException in project java by kubernetes-client.

the class PortForwardExample method main.

public static void main(String[] args) throws IOException, ApiException, InterruptedException {
    ApiClient client = Config.defaultClient();
    Configuration.setDefaultApiClient(client);
    PortForward forward = new PortForward();
    List<Integer> ports = new ArrayList<>();
    ports.add(8080);
    ports.add(80);
    final PortForward.PortForwardResult result = forward.forward("default", "nginx-d5dc44cf7-x7475", ports);
    ServerSocket ss = new ServerSocket(8080);
    final Socket s = ss.accept();
    System.out.println("Connected!");
    new Thread(new Runnable() {

        public void run() {
            try {
                ByteStreams.copy(result.getInputStream(80), s.getOutputStream());
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }).start();
    new Thread(new Runnable() {

        public void run() {
            try {
                ByteStreams.copy(s.getInputStream(), result.getOutboundStream(80));
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }).start();
    Thread.sleep(10 * 1000);
    System.exit(0);
}
Also used : ArrayList(java.util.ArrayList) PortForward(io.kubernetes.client.PortForward) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) ApiClient(io.kubernetes.client.ApiClient) ServerSocket(java.net.ServerSocket) Socket(java.net.Socket) ApiException(io.kubernetes.client.ApiException) IOException(java.io.IOException)

Example 18 with ApiException

use of io.kubernetes.client.ApiException in project incubator-heron by apache.

the class AppsV1beta1Controller method submit.

@Override
boolean submit(PackingPlan packingPlan) {
    final String topologyName = getTopologyName();
    if (!topologyName.equals(topologyName.toLowerCase())) {
        throw new TopologySubmissionException("K8S scheduler does not allow upper case topologies.");
    }
    final Resource containerResource = getContainerResource(packingPlan);
    // find the max number of instances in a container so we can open
    // enough ports if remote debugging is enabled.
    int numberOfInstances = 0;
    for (PackingPlan.ContainerPlan containerPlan : packingPlan.getContainers()) {
        numberOfInstances = Math.max(numberOfInstances, containerPlan.getInstances().size());
    }
    final V1beta1StatefulSet statefulSet = createStatefulSet(containerResource, numberOfInstances);
    try {
        final Response response = client.createNamespacedStatefulSetCall(getNamespace(), statefulSet, null, null, null).execute();
        if (!response.isSuccessful()) {
            LOG.log(Level.SEVERE, "Error creating topology message: " + response.message());
            KubernetesUtils.logResponseBodyIfPresent(LOG, response);
            // construct a message based on the k8s api server response
            throw new TopologySubmissionException(KubernetesUtils.errorMessageFromResponse(response));
        }
    } catch (IOException | ApiException e) {
        KubernetesUtils.logExceptionWithDetails(LOG, "Error creating topology", e);
        throw new TopologySubmissionException(e.getMessage());
    }
    return true;
}
Also used : TopologySubmissionException(com.twitter.heron.scheduler.TopologySubmissionException) Response(com.squareup.okhttp.Response) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource) IOException(java.io.IOException) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) ApiException(io.kubernetes.client.ApiException)

Example 19 with ApiException

use of io.kubernetes.client.ApiException in project incubator-heron by apache.

the class AppsV1beta1Controller method addContainers.

@Override
public Set<PackingPlan.ContainerPlan> addContainers(Set<PackingPlan.ContainerPlan> containersToAdd) {
    final V1beta1StatefulSet statefulSet;
    try {
        statefulSet = getStatefulSet();
    } catch (ApiException ae) {
        final String message = ae.getMessage() + "\ndetails:" + ae.getResponseBody();
        throw new TopologyRuntimeManagementException(message, ae);
    }
    final int currentContainerCount = statefulSet.getSpec().getReplicas();
    final int newContainerCount = currentContainerCount + containersToAdd.size();
    final V1beta1StatefulSetSpec newSpec = new V1beta1StatefulSetSpec();
    newSpec.setReplicas(newContainerCount);
    try {
        doPatch(newSpec);
    } catch (ApiException ae) {
        throw new TopologyRuntimeManagementException(ae.getMessage() + "\ndetails\n" + ae.getResponseBody());
    }
    return containersToAdd;
}
Also used : TopologyRuntimeManagementException(com.twitter.heron.scheduler.TopologyRuntimeManagementException) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) V1beta1StatefulSetSpec(io.kubernetes.client.models.V1beta1StatefulSetSpec) ApiException(io.kubernetes.client.ApiException)

Example 20 with ApiException

use of io.kubernetes.client.ApiException in project weblogic-kubernetes-operator by oracle.

the class DomainStatusUpdater method doDomainUpdate.

private static NextAction doDomainUpdate(Domain dom, DomainPresenceInfo info, Packet packet, Step conflictStep, Step next) {
    V1ObjectMeta meta = dom.getMetadata();
    NextAction na = new NextAction();
    CallBuilderFactory factory = ContainerResolver.getInstance().getContainer().getSPI(CallBuilderFactory.class);
    na.invoke(factory.create().replaceDomainAsync(meta.getName(), meta.getNamespace(), dom, new ResponseStep<Domain>(next) {

        @Override
        public NextAction onFailure(Packet packet, ApiException e, int statusCode, Map<String, List<String>> responseHeaders) {
            if (statusCode == CallBuilder.NOT_FOUND) {
                // Just ignore update
                return doNext(packet);
            }
            return super.onFailure(conflictStep, packet, e, statusCode, responseHeaders);
        }

        @Override
        public NextAction onSuccess(Packet packet, Domain result, int statusCode, Map<String, List<String>> responseHeaders) {
            info.setDomain(result);
            return doNext(packet);
        }
    }), packet);
    return na;
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) CallBuilderFactory(oracle.kubernetes.operator.helpers.CallBuilderFactory) Domain(oracle.kubernetes.weblogic.domain.v1.Domain) NextAction(oracle.kubernetes.operator.work.NextAction) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) TreeMap(java.util.TreeMap) ResponseStep(oracle.kubernetes.operator.helpers.ResponseStep) ApiException(io.kubernetes.client.ApiException)

Aggregations

ApiException (io.kubernetes.client.ApiException)29 IOException (java.io.IOException)11 CallBuilderFactory (oracle.kubernetes.operator.helpers.CallBuilderFactory)9 V1ObjectMeta (io.kubernetes.client.models.V1ObjectMeta)7 Response (com.squareup.okhttp.Response)5 ApiClient (io.kubernetes.client.ApiClient)5 TopologyRuntimeManagementException (com.twitter.heron.scheduler.TopologyRuntimeManagementException)4 V1DeleteOptions (io.kubernetes.client.models.V1DeleteOptions)3 V1Secret (io.kubernetes.client.models.V1Secret)3 V1beta1StatefulSet (io.kubernetes.client.models.V1beta1StatefulSet)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 JSON (io.kubernetes.client.JSON)2 CustomObjectsApi (io.kubernetes.client.apis.CustomObjectsApi)2 V1Namespace (io.kubernetes.client.models.V1Namespace)2 V1Pod (io.kubernetes.client.models.V1Pod)2 V1PodList (io.kubernetes.client.models.V1PodList)2 V1ServiceAccount (io.kubernetes.client.models.V1ServiceAccount)2 V1ServiceAccountList (io.kubernetes.client.models.V1ServiceAccountList)2