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;
}
}
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);
}
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;
}
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;
}
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;
}
Aggregations