use of io.kubernetes.client.ApiException in project weblogic-kubernetes-operator by oracle.
the class SecretHelperTest method createSecret.
// Create a named secret with username / password in specified name
private V1Secret createSecret(String name, String namespace) throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
try {
V1Secret existing = factory.create().readSecret(name, namespace);
if (existing != null)
return existing;
} catch (ApiException ignore) {
// Just ignore and try to create it
}
if (isVersion18)
return null;
V1Secret body = new V1Secret();
// Set the required api version and kind of resource
body.setApiVersion("v1");
body.setKind("Secret");
// Setup the standard object metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(name);
meta.setNamespace(namespace);
body.setMetadata(meta);
Map<String, byte[]> data = new HashMap<String, byte[]>();
data.put(SecretHelper.ADMIN_SERVER_CREDENTIALS_USERNAME, USERNAME.getBytes());
data.put(SecretHelper.ADMIN_SERVER_CREDENTIALS_PASSWORD, PASSWORD.getBytes());
body.setData(data);
try {
return factory.create().createSecret(namespace, body);
} catch (Exception e) {
e.printStackTrace(System.out);
throw e;
}
}
use of io.kubernetes.client.ApiException in project weblogic-kubernetes-operator by oracle.
the class SecretHelperTest method createNamespace.
// Create a named namespace
private V1Namespace createNamespace(String name) throws Exception {
CallBuilderFactory factory = new CallBuilderFactory(null);
try {
V1Namespace existing = factory.create().readNamespace(name);
if (existing != null)
return existing;
} catch (ApiException ignore) {
// Just ignore and try to create it
}
V1Namespace body = new V1Namespace();
// Set the required api version and kind of resource
body.setApiVersion("v1");
body.setKind("Namespace");
// Setup the standard object metadata
V1ObjectMeta meta = new V1ObjectMeta();
meta.setName(name);
body.setMetadata(meta);
return factory.create().createNamespace(body);
}
use of io.kubernetes.client.ApiException in project twister2 by DSC-SPIDAL.
the class KubernetesController method createStatefulSetJob.
/**
* create the given service on Kubernetes master
*/
public boolean createStatefulSetJob(String namespace, V1beta2StatefulSet statefulSet) {
String statefulSetName = statefulSet.getMetadata().getName();
try {
Response response = beta2Api.createNamespacedStatefulSetCall(namespace, statefulSet, null, null, null).execute();
if (response.isSuccessful()) {
LOG.log(Level.INFO, "StatefulSet [" + statefulSetName + "] is created for the same named job.");
return true;
} else {
LOG.log(Level.SEVERE, "Error when creating the StatefulSet [" + statefulSetName + "]: " + response);
LOG.log(Level.SEVERE, "Submitted StatefulSet Object: " + statefulSet);
return false;
}
} catch (IOException e) {
LOG.log(Level.SEVERE, "Exception when creating the StatefulSet: " + statefulSetName, e);
} catch (ApiException e) {
LOG.log(Level.SEVERE, "Exception when creating the StatefulSet: " + statefulSetName, e);
}
return false;
}
use of io.kubernetes.client.ApiException in project twister2 by DSC-SPIDAL.
the class KubernetesController method deleteStatefulSetJob.
/**
* delete the given StatefulSet from Kubernetes master
*/
public boolean deleteStatefulSetJob(String namespace, String statefulSetName) {
try {
V1DeleteOptions deleteOptions = new V1DeleteOptions();
deleteOptions.setGracePeriodSeconds(0L);
deleteOptions.setPropagationPolicy(KubernetesConstants.DELETE_OPTIONS_PROPAGATION_POLICY);
Response response = beta2Api.deleteNamespacedStatefulSetCall(statefulSetName, namespace, deleteOptions, null, null, null, null, null, null).execute();
if (response.isSuccessful()) {
LOG.log(Level.INFO, "StatefulSet for the Job [" + statefulSetName + "] is deleted.");
return true;
} else {
if (response.code() == 404 && response.message().equals("Not Found")) {
LOG.log(Level.SEVERE, "There is no StatefulSet for the Job [" + statefulSetName + "] to delete on Kubernetes master. It may have already terminated.");
return true;
}
LOG.log(Level.SEVERE, "Error when deleting the StatefulSet of the job [" + statefulSetName + "]: " + response);
return false;
}
} catch (ApiException e) {
LOG.log(Level.SEVERE, "Exception when deleting the the StatefulSet of the job: " + statefulSetName, e);
return false;
} catch (IOException e) {
LOG.log(Level.SEVERE, "Exception when deleting the the StatefulSet of the job: " + statefulSetName, e);
return false;
}
}
use of io.kubernetes.client.ApiException in project incubator-heron by apache.
the class AppsV1beta1Controller method deleteStatefulSet.
boolean deleteStatefulSet() {
try {
final V1DeleteOptions options = new V1DeleteOptions();
options.setGracePeriodSeconds(0L);
options.setPropagationPolicy(KubernetesConstants.DELETE_OPTIONS_PROPAGATION_POLICY);
final Response response = client.deleteNamespacedStatefulSetCall(getTopologyName(), getNamespace(), options, 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) {
KubernetesUtils.logExceptionWithDetails(LOG, "Error deleting topology", e);
return false;
}
return true;
}
Aggregations