use of io.kubernetes.client.ApiException in project incubator-heron by apache.
the class AppsV1beta1Controller method removeContainers.
@Override
public void removeContainers(Set<PackingPlan.ContainerPlan> containersToRemove) {
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 - containersToRemove.size();
final V1beta1StatefulSetSpec newSpec = new V1beta1StatefulSetSpec();
newSpec.setReplicas(newContainerCount);
try {
doPatch(newSpec);
} catch (ApiException e) {
throw new TopologyRuntimeManagementException(e.getMessage() + "\ndetails\n" + e.getResponseBody());
}
}
use of io.kubernetes.client.ApiException in project incubator-heron by apache.
the class KubernetesCompat method killTopology.
boolean killTopology(String kubernetesUri, String topology, String namespace) {
final CoreV1Api client = new CoreV1Api(new ApiClient().setBasePath(kubernetesUri));
// old version deployed topologies as naked pods
try {
final String labelSelector = KubernetesConstants.LABEL_TOPOLOGY + "=" + topology;
final Response response = client.deleteCollectionNamespacedPodCall(namespace, null, null, null, null, labelSelector, null, null, null, null, null, null).execute();
if (!response.isSuccessful()) {
LOG.log(Level.SEVERE, "Error killing topology message: " + response.message());
KubernetesUtils.logResponseBodyIfPresent(LOG, response);
throw new TopologyRuntimeManagementException(KubernetesUtils.errorMessageFromResponse(response));
}
} catch (IOException | ApiException e) {
LOG.log(Level.SEVERE, "Error killing topology " + e.getMessage());
if (e instanceof ApiException) {
LOG.log(Level.SEVERE, "Error details:\n" + ((ApiException) e).getResponseBody());
}
return false;
}
return true;
}
use of io.kubernetes.client.ApiException in project seldon-core by SeldonIO.
the class SeldonDeploymentControllerImpl method createOrReplaceSeldonDeployment.
@Override
public void createOrReplaceSeldonDeployment(SeldonDeployment mlDep) {
if (mlDep.hasStatus() && mlDep.getStatus().hasState() && mlDep.getStatus().getState().equals(FAILED_STATE_MSG)) {
logger.warn("Ignoring failed deployment " + mlDep.getMetadata().getName());
return;
}
try {
SeldonDeployment existing = mlCache.get(mlDep.getMetadata().getName());
if (existing == null || !existing.getSpec().equals(mlDep.getSpec())) {
logger.debug("Running updates for " + mlDep.getMetadata().getName());
SeldonDeployment mlDep2 = operator.defaulting(mlDep);
operator.validate(mlDep2);
mlCache.put(mlDep2);
DeploymentResources resources = operator.createResources(mlDep2);
ProtoClient client = clientProvider.getProtoClient();
String namespace = getNamespace(mlDep2);
createDeployments(client, namespace, resources.deployments);
removeDeployments(client, namespace, mlDep2, resources.deployments);
createService(client, namespace, resources.service);
if (!mlDep.getSpec().equals(mlDep2.getSpec())) {
logger.debug("Pushing updated SeldonDeployment " + mlDep2.getMetadata().getName() + " back to kubectl");
crdHandler.updateSeldonDeployment(mlDep2);
} else
logger.debug("Not pushing an update as no change to spec for SeldonDeployment " + mlDep2.getMetadata().getName());
} else {
mlCache.put(mlDep);
logger.debug("Only updated cache for " + mlDep.getMetadata().getName());
}
} catch (SeldonDeploymentException e) {
logger.error("Failed to create deployment ", e);
failDeployment(mlDep, e);
} catch (ApiException e) {
logger.error("Kubernetes API exception deploying code:" + e.getCode() + "message:" + e.getResponseBody(), e);
failDeployment(mlDep, e);
} catch (IOException e) {
logger.error("IOException during createReplace ", e);
failDeployment(mlDep, e);
}
}
use of io.kubernetes.client.ApiException in project seldon-core by SeldonIO.
the class KubeCRDHandlerImpl method updateSeldonDeployment.
@Override
public void updateSeldonDeployment(SeldonDeployment mldep) {
try {
// Need to remove resourceVersion from the representation used for last-applied-configuration otherwise you will errors subsequently using kubectl
SeldonDeployment mlDepTmp = SeldonDeployment.newBuilder(mldep).setMetadata(ObjectMeta.newBuilder(mldep.getMetadata()).clearResourceVersion().removeAnnotations("kubectl.kubernetes.io/last-applied-configuration").build()).build();
// Create string representation of JSON to add as annotation to allow declarative "kubectl apply" commands to work otherwise a replace
// would remove the last-applied-configuration that kubectl adds.
String json = SeldonDeploymentUtils.toJson(mlDepTmp, true);
// Create final version of deployment with annotation
SeldonDeployment mlDeployment = SeldonDeployment.newBuilder(mldep).setMetadata(ObjectMeta.newBuilder(mldep.getMetadata()).putAnnotations("kubectl.kubernetes.io/last-applied-configuration", json + "\n")).build();
json = SeldonDeploymentUtils.toJson(mlDeployment, false);
logger.debug("Updating seldondeployment " + mlDeployment.getMetadata().getName());
ApiClient client = Config.defaultClient();
CustomObjectsApi api = new CustomObjectsApi(client);
api.replaceNamespacedCustomObject(GROUP, VERSION, namespace, KIND_PLURAL, mlDeployment.getMetadata().getName(), json.getBytes());
} catch (InvalidProtocolBufferException e) {
logger.error("Failed to update deployment in kubernetes ", e);
} catch (ApiException e) {
logger.error("Failed to update deployment in kubernetes ", e);
} catch (IOException e) {
logger.error("Failed to get client ", e);
} finally {
}
}
use of io.kubernetes.client.ApiException in project seldon-core by SeldonIO.
the class KubeCRDHandlerImpl method getSeldonDeployment.
@Override
public SeldonDeployment getSeldonDeployment(String name) {
try {
ApiClient client = Config.defaultClient();
CustomObjectsApi api = new CustomObjectsApi(client);
Object resp = api.getNamespacedCustomObject(GROUP, VERSION, namespace, KIND_PLURAL, name);
Gson gson = new GsonBuilder().create();
String json = gson.toJson(resp);
try {
return SeldonDeploymentUtils.jsonToSeldonDeployment(json);
} catch (InvalidProtocolBufferException e) {
logger.error("Failed to parse " + json, e);
return null;
}
} catch (ApiException e) {
return null;
} catch (IOException e) {
logger.error("Failed to get client", e);
return null;
}
}
Aggregations