use of io.kubernetes.client.ApiClient in project weblogic-kubernetes-operator by oracle.
the class CallBuilder method listService.
/* Services */
/**
* List services
* @param namespace Namespace
* @return List of services
* @throws ApiException API Exception
*/
public V1ServiceList listService(String namespace) throws ApiException {
String _continue = "";
ApiClient client = helper.take();
try {
return new CoreV1Api(client).listNamespacedService(namespace, pretty, _continue, fieldSelector, includeUninitialized, labelSelector, limit, resourceVersion, timeoutSeconds, watch);
} finally {
helper.recycle(client);
}
}
use of io.kubernetes.client.ApiClient in project seldon-core by SeldonIO.
the class SeldonDeploymentWatcher method watchSeldonMLDeployments.
public int watchSeldonMLDeployments(int resourceVersion, int resourceVersionProcessed) throws ApiException, JsonProcessingException, IOException {
String rs = null;
if (resourceVersion > 0)
rs = "" + resourceVersion;
ApiClient client = Config.defaultClient();
CustomObjectsApi api = new CustomObjectsApi(client);
String namespace = StringUtils.isEmpty(this.clusterManagerProperites.getNamespace()) ? "default" : this.clusterManagerProperites.getNamespace();
logger.debug("Watching with rs " + rs + " in namespace " + namespace);
Watch<Object> watch = Watch.createWatch(client, api.listNamespacedCustomObjectCall("machinelearning.seldon.io", "v1alpha1", namespace, "seldondeployments", null, null, rs, true, null, null), new TypeToken<Watch.Response<Object>>() {
}.getType());
int maxResourceVersion = resourceVersion;
try {
for (Watch.Response<Object> item : watch) {
Gson gson = new GsonBuilder().create();
String jsonInString = gson.toJson(item.object);
logger.debug(String.format("%s\n : %s%n", item.type, jsonInString));
ObjectMapper mapper = new ObjectMapper();
JsonFactory factory = mapper.getFactory();
JsonParser parser = factory.createParser(jsonInString);
JsonNode actualObj = mapper.readTree(parser);
if (actualObj.has("kind") && actualObj.get("kind").asText().equals("Status")) {
logger.warn("Possible old resource version found - resetting");
return 0;
} else {
int resourceVersionNew = actualObj.get("metadata").get("resourceVersion").asInt();
if (resourceVersionNew <= resourceVersionProcessed) {
logger.warn("Looking at already processed request - skipping");
} else {
if (resourceVersionNew > maxResourceVersion)
maxResourceVersion = resourceVersionNew;
try {
this.processWatch(SeldonDeploymentUtils.jsonToSeldonDeployment(jsonInString), item.type);
} catch (InvalidProtocolBufferException e) {
// TODO : update status of seldondeployment to show error
logger.warn("Failed to parse SeldonDelployment " + jsonInString, e);
}
}
}
}
} catch (RuntimeException e) {
if (e.getCause() instanceof SocketTimeoutException)
return maxResourceVersion;
else
throw e;
} finally {
watch.close();
}
return maxResourceVersion;
}
use of io.kubernetes.client.ApiClient in project seldon-core by SeldonIO.
the class DeploymentWatcher method watchDeployments.
public int watchDeployments(int resourceVersion, int resourceVersionProcessed) throws ApiException, IOException {
String rs = null;
if (resourceVersion > 0)
rs = "" + resourceVersion;
logger.debug("Watching with rs " + rs);
int maxResourceVersion = resourceVersion;
ApiClient client = Config.defaultClient();
ExtensionsV1beta1Api api = new ExtensionsV1beta1Api(client);
Watch<ExtensionsV1beta1Deployment> watch = Watch.createWatch(client, api.listNamespacedDeploymentCall(namespace, null, null, null, false, SeldonDeploymentOperatorImpl.LABEL_SELDON_TYPE_KEY + "=" + SeldonDeploymentOperatorImpl.LABEL_SELDON_TYPE_VAL, null, rs, 10, true, null, null), new TypeToken<Watch.Response<ExtensionsV1beta1Deployment>>() {
}.getType());
try {
for (Watch.Response<ExtensionsV1beta1Deployment> item : watch) {
int resourceVersionNew = Integer.parseInt(item.object.getMetadata().getResourceVersion());
if (resourceVersionNew <= resourceVersionProcessed) {
logger.warn("Looking at already processed request - skipping");
} else {
if (resourceVersionNew > maxResourceVersion)
maxResourceVersion = resourceVersionNew;
if (item.object.getMetadata().getOwnerReferences() == null) {
logger.warn("Found possible seldon controlled deployment which has no owner reference. Ignoring.");
} else {
switch(item.type) {
case "ADDED":
case "MODIFIED":
for (V1OwnerReference ownerRef : item.object.getMetadata().getOwnerReferences()) {
if (ownerRef.getKind().equals(KubeCRDHandlerImpl.KIND) && item.object.getStatus() != null) {
String mlDepName = ownerRef.getName();
String depName = item.object.getMetadata().getName();
statusUpdater.updateStatus(mlDepName, depName, item.object.getStatus().getReplicas(), item.object.getStatus().getReadyReplicas());
}
}
break;
case "DELETED":
for (V1OwnerReference ownerRef : item.object.getMetadata().getOwnerReferences()) {
if (ownerRef.getKind().equals(KubeCRDHandlerImpl.KIND) && item.object.getStatus() != null) {
String mlDepName = ownerRef.getName();
String depName = item.object.getMetadata().getName();
statusUpdater.removeStatus(mlDepName, depName);
}
}
break;
default:
logger.error("Unknown type " + item.type);
}
// for modified get owner reference and determine which predictor it is
// get the MLDeployment from API or local cache and update status
// put this logic in new class
}
}
}
} catch (RuntimeException e) {
if (e.getCause() instanceof SocketTimeoutException)
return maxResourceVersion;
else
throw e;
} finally {
watch.close();
}
return maxResourceVersion;
}
Aggregations