use of io.kubernetes.client.openapi.ApiException in project druid by druid-io.
the class DefaultK8sApiClient method listPods.
@Override
public DiscoveryDruidNodeList listPods(String podNamespace, String labelSelector, NodeRole nodeRole) {
try {
V1PodList podList = coreV1Api.listNamespacedPod(podNamespace, null, null, null, null, labelSelector, 0, null, null, null);
Preconditions.checkState(podList != null, "WTH: NULL podList");
Map<String, DiscoveryDruidNode> allNodes = new HashMap();
for (V1Pod podDef : podList.getItems()) {
DiscoveryDruidNode node = getDiscoveryDruidNodeFromPodDef(nodeRole, podDef);
allNodes.put(node.getDruidNode().getHostAndPortToUse(), node);
}
return new DiscoveryDruidNodeList(podList.getMetadata().getResourceVersion(), allNodes);
} catch (ApiException ex) {
throw new RE(ex, "Expection in listing pods, code[%d] and error[%s].", ex.getCode(), ex.getResponseBody());
}
}
use of io.kubernetes.client.openapi.ApiException in project druid by druid-io.
the class DefaultK8sLeaderElectorFactory method create.
@Override
public K8sLeaderElector create(String candidateId, String namespace, String lockResourceName) {
Lock lock = createLock(candidateId, namespace, lockResourceName, realK8sClient);
LeaderElectionConfig leaderElectionConfig = new LeaderElectionConfig(lock, Duration.ofMillis(discoveryConfig.getLeaseDuration().getMillis()), Duration.ofMillis(discoveryConfig.getRenewDeadline().getMillis()), Duration.ofMillis(discoveryConfig.getRetryPeriod().getMillis()));
LeaderElector leaderElector = new LeaderElector(leaderElectionConfig);
return new K8sLeaderElector() {
@Override
public String getCurrentLeader() {
try {
return lock.get().getHolderIdentity();
} catch (ApiException ex) {
throw new RE(ex, "Failed to get current leader for [%s]", lockResourceName);
}
}
@Override
public void run(Runnable startLeadingHook, Runnable stopLeadingHook) {
leaderElector.run(startLeadingHook, stopLeadingHook);
}
};
}
use of io.kubernetes.client.openapi.ApiException in project twister2 by DSC-SPIDAL.
the class WorkerLogger method streamContainerLog.
// Important note. You must close this stream or else you can leak connections.
public InputStream streamContainerLog() throws ApiException, IOException {
Integer sinceSeconds = null;
Integer tailLines = null;
boolean timestamps = false;
Call call = coreV1Api.readNamespacedPodLogCall(podName, namespace, containerName, true, null, "false", false, sinceSeconds, tailLines, timestamps, null);
response = call.execute();
if (!response.isSuccessful()) {
throw new ApiException(response.code(), "Logs request failed: " + response.code());
}
return response.body().byteStream();
}
use of io.kubernetes.client.openapi.ApiException in project twister2 by DSC-SPIDAL.
the class KubernetesController method existPersistentVolumeClaim.
/**
* check whether the given PersistentVolumeClaim exist on Kubernetes master
*/
public boolean existPersistentVolumeClaim(String jobID) {
String pvcName = jobID;
V1PersistentVolumeClaimList pvcList = null;
try {
pvcList = coreApi.listNamespacedPersistentVolumeClaim(namespace, null, null, null, null, null, null, null, null, null);
} catch (ApiException e) {
LOG.log(Level.SEVERE, "Exception when getting PersistentVolumeClaim list.", e);
throw new RuntimeException(e);
}
for (V1PersistentVolumeClaim pvc : pvcList.getItems()) {
if (pvcName.equals(pvc.getMetadata().getName())) {
LOG.severe("There is already a PersistentVolumeClaim with the name: " + pvcName);
return true;
}
}
return false;
}
use of io.kubernetes.client.openapi.ApiException in project twister2 by DSC-SPIDAL.
the class KubernetesController method deleteJobPackage.
/**
* delete job package file from uploader web server pods
* currently it does not delete job package file from multiple uploader pods
* so, It is not in use
*/
public boolean deleteJobPackage(List<String> uploaderPods, String jobPackageName) {
String command = String.format("rm %s", jobPackageName);
String[] fullCommand = { "bash", "-c", command };
boolean allDeleted = true;
for (String uploaderPod : uploaderPods) {
try {
Exec exec = new Exec(getApiClient());
final Process proc = exec.exec(namespace, uploaderPod, fullCommand, false, false);
proc.waitFor();
proc.destroy();
if (proc.exitValue() == 0) {
LOG.info("Deleted job package from uploader web server pod: " + uploaderPod);
} else {
LOG.info("Could not delete the job package from uploader web server pod: " + uploaderPod + ", process exit code: " + proc.exitValue());
allDeleted = false;
}
} catch (ApiException e) {
LOG.log(Level.INFO, String.format("Exception when deleting the job package from uploader web server [%s]", uploaderPod), e);
} catch (IOException e) {
LOG.log(Level.INFO, String.format("Exception when deleting the job package from uploader web server [%s]", uploaderPod), e);
} catch (InterruptedException e) {
LOG.log(Level.INFO, String.format("Exception when deleting the job package from uploader web server [%s]", uploaderPod), e);
}
}
return allDeleted;
}
Aggregations