use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.
the class KubernetesController method getConfigMapParams.
/**
* return all configMap parameters for the given jobID
* if there is no ConfigMap, throw an exception
*/
public Map<String, String> getConfigMapParams(String jobID) {
String configMapName = jobID;
V1ConfigMap configMap = getJobConfigMap(jobID);
if (configMap == null) {
throw new RuntimeException("Could not get ConfigMap from K8s master: " + configMapName);
}
Map<String, String> pairs = configMap.getData();
if (pairs == null) {
throw new RuntimeException("Could not get data from ConfigMap");
}
return pairs;
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.
the class KubernetesLauncher method launch.
/**
* Launch the processes according to the resource plan.
*
* @return true if the request is granted
*/
@Override
public Twister2JobState launch(JobAPI.Job job) {
Twister2JobState state = new Twister2JobState(false);
if (!configParametersOK(job)) {
return state;
}
String jobID = job.getJobId();
String jobPackageFile = SchedulerContext.temporaryPackagesPath(config) + "/" + SchedulerContext.jobPackageFileName(config);
File jobFile = new File(jobPackageFile);
if (!jobFile.exists()) {
LOG.log(Level.SEVERE, "Can not access job package file: " + jobPackageFile + "\n++++++++++++++++++ Aborting submission ++++++++++++++++++");
return state;
}
long jobFileSize = jobFile.length();
// check all relevant entities on Kubernetes master
boolean allEntitiesOK = checkEntitiesForJob(job);
if (!allEntitiesOK) {
return state;
}
long jobSubmitTime = System.currentTimeMillis();
String encodedNodeList = getNodeInfoList();
RequestObjectBuilder.init(config, job.getJobId(), jobFileSize, jobSubmitTime, encodedNodeList);
JobMasterRequestObject.init(config, job.getJobId());
// initialize the service in Kubernetes master
boolean servicesCreated = initServices(jobID);
if (!servicesCreated) {
clearupWhenSubmissionFails(jobID);
return state;
}
// create the ConfigMap
V1ConfigMap configMap = RequestObjectBuilder.createConfigMap(job);
boolean cmCreated = controller.createConfigMap(configMap);
if (cmCreated) {
jobSubmissionStatus.setConfigMapCreated(true);
} else {
LOG.severe("Following ConfigMap could not be created: " + configMap.getMetadata().getName() + "\n++++++++++++++++++ Aborting submission ++++++++++++++++++");
clearupWhenSubmissionFails(jobID);
return state;
}
// if persistent volume is requested, create a persistent volume claim
if (SchedulerContext.persistentVolumeRequested(config)) {
// create pvc
if (!CheckpointingContext.startingFromACheckpoint(config) || !CheckpointingContext.isNfsUsed(config)) {
boolean volumesSetup = initPersistentVolumeClaim(job);
if (!volumesSetup) {
clearupWhenSubmissionFails(jobID);
return state;
}
}
}
// initialize StatefulSets for this job
boolean statefulSetInitialized = initStatefulSets(job);
if (!statefulSetInitialized) {
clearupWhenSubmissionFails(jobID);
return state;
}
// start the Job Master locally if requested
if (JobMasterContext.jobMasterRunsInClient(config)) {
boolean jobMasterCompleted = startJobMasterOnClient(job);
if (!jobMasterCompleted) {
LOG.log(Level.SEVERE, "JobMaster can not be started. " + "\n++++++++++++++++++ Aborting submission ++++++++++++++++++");
clearupWhenSubmissionFails(jobID);
return state;
}
}
if (KubernetesContext.logInClient(config)) {
jobLogger = new JobLogger(namespace, job);
jobLogger.start();
}
state.setRequestGranted(true);
return state;
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.
the class KubernetesController method existConfigMap.
/**
* return true if there is already a ConfigMap object with the same name on Kubernetes master,
* otherwise return false
*/
public boolean existConfigMap(String jobID) {
String configMapName = jobID;
V1ConfigMapList configMapList = null;
try {
configMapList = coreApi.listNamespacedConfigMap(namespace, null, null, null, null, null, null, null, null, null);
} catch (ApiException e) {
LOG.log(Level.SEVERE, "Exception when getting ConfigMap list.", e);
throw new RuntimeException(e);
}
for (V1ConfigMap configMap : configMapList.getItems()) {
if (configMapName.equals(configMap.getMetadata().getName())) {
return true;
}
}
return false;
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.
the class K8sControllerExample method createCM.
public static void createCM(KubernetesController controller, JobAPI.Job job) {
Config cnfg = Config.newBuilder().put("nothing", "nothing").build();
RequestObjectBuilder.init(cnfg, job.getJobId(), 0, 0, null);
V1ConfigMap cm = RequestObjectBuilder.createConfigMap(job);
controller.createConfigMap(cm);
}
use of io.kubernetes.client.openapi.models.V1ConfigMap in project twister2 by DSC-SPIDAL.
the class K8sControllerExample method main.
public static void main(String[] args) throws InterruptedException {
KubernetesController controller = KubernetesController.init("default");
if (args.length != 1) {
LOG.severe("Provide jobID as a parameter.");
return;
}
String jobID = args[0];
String configDir = "";
String twister2Home = Paths.get(configDir).toAbsolutePath().toString();
Config config = ConfigLoader.loadConfig(twister2Home, "conf", "kubernetes");
LOG.info("Loaded: " + config.size() + " configuration parameters.");
testUploader(config, controller, jobID);
if (config != null) {
controller.close();
return;
}
int numberOfWorkers = 4;
Twister2Job twister2Job = Twister2Job.newBuilder().setJobName("hello-world-job").setWorkerClass(HelloWorld.class).addComputeResource(.2, 128, numberOfWorkers).setConfig(new JobConfig()).build();
twister2Job.setUserName("au");
JobAPI.Job job = twister2Job.serialize();
LOG.info("jobID: " + job.getJobId());
V1ConfigMap cm = controller.getJobConfigMap(job.getJobId());
if (cm == null) {
LOG.info("there is no cm for this job on k8s");
} else {
LOG.info("cm: " + cm.getMetadata().getName());
}
// testPVC(config, controller, jobID);
createCM(controller, job);
getJobFromConfigMap(controller, job.getJobId());
// testWorker(controller, jobID, 0);
// testWorker(controller, jobID, 1);
// testWorker(controller, jobID, 3);
// testJM(controller, jobID);
// controller.addParamToConfigMap(jobID, "KILL_JOB", "true");
// Thread.sleep(5000);
// createCMWatcher(controller, jobID);
// Thread.sleep(5000);
controller.deleteConfigMap(job.getJobId());
controller.close();
}
Aggregations