Search in sources :

Example 1 with KubernetesController

use of edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController in project twister2 by DSC-SPIDAL.

the class K8sControllerExample method test1.

/**
 * test method
 */
public static void test1(JobAPI.Job job) {
    String jobID = "ft-job";
    String jobID2 = "ft-job-2";
    Config cnfg = Config.newBuilder().put("nothing", "nothing").build();
    RequestObjectBuilder.init(cnfg, jobID, 0, 0, null);
    V1ConfigMap cm = RequestObjectBuilder.createConfigMap(job);
    RequestObjectBuilder.init(cnfg, jobID2, 0, 0, null);
    V1ConfigMap cm2 = RequestObjectBuilder.createConfigMap(job);
    KubernetesController controller = KubernetesController.init("default");
    String key0 = KubernetesUtils.createRestartWorkerKey(0);
    String key1 = KubernetesUtils.createRestartJobMasterKey();
    if (controller.existConfigMap(cm2.getMetadata().getName())) {
        controller.deleteConfigMap(cm2.getMetadata().getName());
    } else {
        controller.createConfigMap(cm2);
        int restartCount = controller.getRestartCount(jobID2, key0);
        LOG.info("restartCount: " + restartCount);
        controller.addConfigMapParam(jobID2, key0, 0 + "");
        LOG.info("added restartCount: " + controller.getRestartCount(jobID2, key0));
        if (controller.updateConfigMapParam(jobID2, key0, 1 + "")) {
            LOG.info("updated restartCount: " + controller.getRestartCount(jobID2, key0));
        } else {
            LOG.info("Cannot update restartCount");
            LOG.info("restartCount: " + controller.getRestartCount(jobID2, key0));
        }
        if (controller.updateConfigMapParam(jobID2, key1, 10 + "")) {
            LOG.info("updated restartCount: " + controller.getRestartCount(jobID2, key1));
        } else {
            LOG.info("Cannot update restartCount");
            LOG.info("restartCount: " + controller.getRestartCount(jobID2, key1));
        }
        if (controller.removeRestartCount(jobID2, key0)) {
            LOG.info("removed restartCount: " + controller.getRestartCount(jobID2, key0));
        } else {
            LOG.info("cannot remove restartCount: " + controller.getRestartCount(jobID2, key0));
        }
    }
    if (controller.existConfigMap(cm.getMetadata().getName())) {
        controller.deleteConfigMap(cm.getMetadata().getName());
    } else {
        controller.createConfigMap(cm);
        int restartCount = controller.getRestartCount(jobID, key0);
        LOG.info("restartCount: " + restartCount);
    }
    LOG.info("done");
}
Also used : Config(edu.iu.dsc.tws.api.config.Config) JobConfig(edu.iu.dsc.tws.api.JobConfig) KubernetesController(edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap)

Example 2 with KubernetesController

use of edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController in project twister2 by DSC-SPIDAL.

the class Twister2Submitter method clearJob.

public static void clearJob(String jobID, Config config) {
    deleteJobDir(jobID, config);
    // close the controller
    if (KubernetesContext.isKubernetesCluster(config)) {
        KubernetesController controller = KubernetesController.init(KubernetesContext.namespace(config));
        controller.deletePersistentVolumeClaim(jobID);
        KubernetesController.close();
    }
// todo: need to delete checkpointed data in other clusters and on HDFS
}
Also used : KubernetesController(edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController)

Example 3 with KubernetesController

use of edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController in project twister2 by DSC-SPIDAL.

the class K8sUploader method initialize.

@Override
public void initialize(Config cnfg, String jbID) {
    KubernetesController controller = KubernetesController.init(KubernetesContext.namespace(cnfg));
    List<String> webServerPodNames = controller.getUploaderWebServerPods(KubernetesContext.uploaderWebServerLabel(cnfg));
    if (webServerPodNames.size() == 0) {
        // set upload method in RequestObjectBuilder
        RequestObjectBuilder.setUploadMethod("client-to-pods");
        uploader = new DirectUploader();
    } else {
        uploader = new UploaderToWebServers(webServerPodNames);
    }
    uploader.initialize(cnfg, jbID);
}
Also used : KubernetesController(edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController)

Example 4 with KubernetesController

use of edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController in project twister2 by DSC-SPIDAL.

the class JobMasterExample method main.

/**
 * this main method is for locally testing only
 * A JobMaster instance is started locally on the default port:
 * edu.iu.dsc.tws.master.JobMasterContext.JOB_MASTER_PORT_DEFAULT = 11011
 * <p>
 * numberOfWorkers to join is expected as a parameter
 * <p>
 * When all workers joined and all have sent completed messages,
 * this server also completes and exits
 * <p>
 * En example usage of JobMaster can be seen in:
 * edu.iu.dsc.tws.rsched.schedulers.k8s.master.JobMasterStarter
 */
public static void main(String[] args) {
    if (args.length != 1) {
        LOG.info("usage: java JobMasterExample numberOfWorkers");
        return;
    }
    int numberOfWorkers = Integer.parseInt(args[0]);
    String host = "0.0.0.0";
    // we assume that the twister2Home is the current directory
    // String configDir = "../twister2/config/src/yaml/";
    String configDir = "";
    String twister2Home = Paths.get(configDir).toAbsolutePath().toString();
    Config config = ConfigLoader.loadConfig(twister2Home, "conf", "kubernetes");
    config = JobMasterClientExample.updateConfig(config, config, host);
    LOG.info("Loaded: " + config.size() + " configuration parameters.");
    // Twister2Job twister2Job = Twister2Job.loadTwister2Job(config, null);
    Twister2Job twister2Job = Twister2Job.newBuilder().setJobName("hello-world-job").setWorkerClass(HelloWorld.class).addComputeResource(.2, 128, numberOfWorkers).build();
    twister2Job.setUserName(System.getProperty("user.name"));
    JobAPI.Job job = twister2Job.serialize();
    LOG.info("JobID: " + job.getJobId());
    JobMasterAPI.JobMasterState initialState = JobMasterAPI.JobMasterState.JM_STARTED;
    JobMasterStarter.job = job;
    if (ZKContext.isZooKeeperServerUsed(config)) {
        if ("start".equalsIgnoreCase(args[0])) {
            JobMasterStarter.initializeZooKeeper(config, job.getJobId(), host, initialState);
        } else if ("restart".equalsIgnoreCase(args[0])) {
            initialState = JobMasterAPI.JobMasterState.JM_RESTARTED;
            JobMasterStarter.initializeZooKeeper(config, job.getJobId(), host, initialState);
            job = JobMasterStarter.job;
        } else {
            LOG.info("usage: java JobMasterExample start/restart");
            return;
        }
    }
    // write jobID to file
    String dir = System.getProperty("user.home") + "/.twister2";
    if (!FileUtils.isDirectoryExists(dir)) {
        FileUtils.createDirectory(dir);
    }
    String filename = dir + "/last-job-id.txt";
    FileUtils.writeToFile(filename, (job.getJobId() + "").getBytes(), true);
    LOG.info("Written jobID to file: " + job.getJobId());
    String ip = null;
    try {
        ip = Inet4Address.getLocalHost().getHostAddress();
    } catch (UnknownHostException e) {
        LOG.log(Level.SEVERE, e.getMessage(), e);
        return;
    }
    JobMasterAPI.NodeInfo jobMasterNode = NodeInfoUtils.createNodeInfo(ip, null, null);
    KubernetesController controller = KubernetesController.init("default");
    K8sScaler k8sScaler = new K8sScaler(config, job, controller);
    IJobTerminator jobTerminator = new NullTerminator();
    JobMaster jobMaster = new JobMaster(config, host, jobTerminator, job, jobMasterNode, k8sScaler, initialState);
    try {
        // jobMaster.startJobMasterThreaded();
        jobMaster.startJobMasterBlocking();
    } catch (Twister2Exception e) {
        LOG.log(Level.SEVERE, "Exception when starting Job master: ", e);
        throw new RuntimeException(e);
    }
    LOG.info("Threaded Job Master started:" + "\nnumberOfWorkers: " + job.getNumberOfWorkers() + "\njobID: " + job.getJobId());
}
Also used : JobMaster(edu.iu.dsc.tws.master.server.JobMaster) Twister2Exception(edu.iu.dsc.tws.api.exceptions.Twister2Exception) UnknownHostException(java.net.UnknownHostException) Config(edu.iu.dsc.tws.api.config.Config) KubernetesController(edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController) JobAPI(edu.iu.dsc.tws.proto.system.job.JobAPI) Twister2Job(edu.iu.dsc.tws.api.Twister2Job) K8sScaler(edu.iu.dsc.tws.rsched.schedulers.k8s.driver.K8sScaler) JobMasterAPI(edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI) IJobTerminator(edu.iu.dsc.tws.master.IJobTerminator) NullTerminator(edu.iu.dsc.tws.rsched.schedulers.NullTerminator)

Example 5 with KubernetesController

use of edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController 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();
}
Also used : KubernetesController(edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController) Config(edu.iu.dsc.tws.api.config.Config) JobConfig(edu.iu.dsc.tws.api.JobConfig) JobAPI(edu.iu.dsc.tws.proto.system.job.JobAPI) Twister2Job(edu.iu.dsc.tws.api.Twister2Job) JobConfig(edu.iu.dsc.tws.api.JobConfig) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) HelloWorld(edu.iu.dsc.tws.examples.basic.HelloWorld)

Aggregations

KubernetesController (edu.iu.dsc.tws.rsched.schedulers.k8s.KubernetesController)9 Config (edu.iu.dsc.tws.api.config.Config)4 JobConfig (edu.iu.dsc.tws.api.JobConfig)2 Twister2Job (edu.iu.dsc.tws.api.Twister2Job)2 Twister2Exception (edu.iu.dsc.tws.api.exceptions.Twister2Exception)2 JobMaster (edu.iu.dsc.tws.master.server.JobMaster)2 JobMasterAPI (edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI)2 JobAPI (edu.iu.dsc.tws.proto.system.job.JobAPI)2 K8sScaler (edu.iu.dsc.tws.rsched.schedulers.k8s.driver.K8sScaler)2 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)2 UnknownHostException (java.net.UnknownHostException)2 HelloWorld (edu.iu.dsc.tws.examples.basic.HelloWorld)1 IJobTerminator (edu.iu.dsc.tws.master.IJobTerminator)1 JobMasterState (edu.iu.dsc.tws.proto.jobmaster.JobMasterAPI.JobMasterState)1 NullTerminator (edu.iu.dsc.tws.rsched.schedulers.NullTerminator)1 InetAddress (java.net.InetAddress)1 LinkedList (java.util.LinkedList)1