Package com.netflix.genie.common.model

Examples of com.netflix.genie.common.model.Job


            this.jobManagerFactory.getJobManager(job).launch();

            // update entity in DB
            // TODO This udpate runs into deadlock issue, either add manual retries
            // or Spring retries.
            final Job runningJob = this.jobRepo.findOne(job.getId());
            runningJob.setUpdated(new Date());
            return runningJob;
        } catch (final GenieException e) {
            LOG.error("Failed to run job: ", e);
            final Job failedJob = this.jobRepo.findOne(job.getId());
            // update db
            failedJob.setJobStatus(JobStatus.FAILED, e.getMessage());
            // increment counter for failed jobs
            this.stats.incrGenieFailedJobs();
            throw e;
        }
    }
View Full Code Here


        final List<ClusterCriteria> clusterCriterias = new ArrayList<>();
        final Set<String> commandCriteria = new HashSet<>();
        clusterCriterias.add(criteria);
        commandCriteria.add("hive");

        Job job = new Job(
                userName,
                jobName,
                "-f hive.q",
                commandCriteria,
                clusterCriterias,
                null);

        job.setDescription("This is a test");

        // Add some tags for metadata about the job. This really helps for reporting on
        // the jobs and categorization.
        Set<String> jobTags = new HashSet<>();
        jobTags.add("testgenie");
        jobTags.add("sample");

        job.setTags(jobTags);

        // send the query as an attachment
        final File query = File.createTempFile("hive", ".q");
        try (PrintWriter pw = new PrintWriter(query, "UTF-8")) {
            pw.println("select count(*) from counters where dateint=20120430 and hour=10;");
        }
        final Set<FileAttachment> attachments = new HashSet<>();
        final FileAttachment attachment = new FileAttachment();
        attachment.setName("hive.q");

        FileInputStream fin = null;
        ByteArrayOutputStream bos = null;
        try {
            fin = new FileInputStream(query);
            bos = new ByteArrayOutputStream();
            final byte[] buf = new byte[4096];
            int read;
            while ((read = fin.read(buf)) != -1) {
                bos.write(buf, 0, read);
            }
            attachment.setData(bos.toByteArray());
        } finally {
            if (fin != null) {
                fin.close();
            }
            if (bos != null) {
                bos.close();
            }
        }
        attachments.add(attachment);
        job.setAttachments(attachments);
        job = client.submitJob(job);

        final String jobID = job.getId();
        final String outputURI = job.getOutputURI();
        LOG.info("Job ID: " + jobID);
        LOG.info("Output URL: " + outputURI);

        LOG.info("Getting jobInfo by jobID");
        job = client.getJob(jobID);
        LOG.info(job.toString());

        LOG.info("Waiting for job to finish");
        job = client.waitForCompletion(jobID, 600000, 5000);
        LOG.info("Job status: " + job.getStatus());

        LOG.info("Killing jobs using jobID");
        final Job killedJob = client.killJob(jobID);
        LOG.info("Job status: " + killedJob.getStatus());

        LOG.info("Done");
    }
View Full Code Here

    @Test
    public void testChooseClusterForJob() throws GenieException {
        final List<Cluster> clusters = this.service.chooseClusterForJob(JOB_1_ID);
        Assert.assertEquals(1, clusters.size());
        Assert.assertEquals(CLUSTER_1_ID, clusters.get(0).getId());
        final Job job = this.jobService.getJob(JOB_1_ID);
        final String chosen = job.getChosenClusterCriteriaString();
        Assert.assertEquals(8, chosen.length());
        Assert.assertTrue(chosen.contains("prod"));
        Assert.assertTrue(chosen.contains("pig"));
        Assert.assertTrue(chosen.contains(","));
    }
View Full Code Here

        final Set<String> commandCriteria = new HashSet<>();
        commandCriteria.add(UUID.randomUUID().toString());
        commandCriteria.add(UUID.randomUUID().toString());

        final Job created = this.service.createJob(
                new Job(
                        user,
                        name,
                        commandArgs,
                        commandCriteria,
                        clusterCriterias,
                        version
                )
        );

        final Job job = this.service.getJob(created.getId());
        Assert.assertNotNull(job.getId());
        Assert.assertEquals(name, job.getName());
        Assert.assertEquals(user, job.getUser());
        Assert.assertEquals(version, job.getVersion());
        Assert.assertEquals(commandArgs, job.getCommandArgs());
        Assert.assertEquals(clusterCriterias.size(), job.getClusterCriterias().size());
        Assert.assertEquals(commandCriteria.size(), job.getCommandCriteria().size());
        Assert.assertEquals(commandCriteria.size(), job.getCommandCriteriaString().split(",").length);
        Assert.assertEquals(JobStatus.INIT, job.getStatus());
        Assert.assertNotNull(job.getHostName());
        Assert.assertNotNull(job.getOutputURI());
        Assert.assertNotNull(job.getKillURI());
    }
View Full Code Here

        final Set<String> commandCriteria = new HashSet<>();
        commandCriteria.add(UUID.randomUUID().toString());
        commandCriteria.add(UUID.randomUUID().toString());

        final Job jobToCreate = new Job(
                user,
                name,
                commandArgs,
                commandCriteria,
                clusterCriterias,
                version
        );
        jobToCreate.setId(id);

        final Job created = this.service.createJob(jobToCreate);

        Assert.assertEquals(id, created.getId());
        final Job job = this.service.getJob(created.getId());
        Assert.assertNotNull(job.getId());
        Assert.assertEquals(name, job.getName());
        Assert.assertEquals(user, job.getUser());
        Assert.assertEquals(version, job.getVersion());
        Assert.assertEquals(commandArgs, job.getCommandArgs());
        Assert.assertEquals(clusterCriterias.size(), job.getClusterCriterias().size());
        Assert.assertEquals(commandCriteria.size(), job.getCommandCriteria().size());
        Assert.assertEquals(commandCriteria.size(), job.getCommandCriteriaString().split(",").length);
        Assert.assertEquals(JobStatus.INIT, job.getStatus());
        Assert.assertNotNull(job.getHostName());
        Assert.assertNotNull(job.getOutputURI());
        Assert.assertNotNull(job.getKillURI());
    }
View Full Code Here

        final Set<String> commandCriteria = new HashSet<>();
        commandCriteria.add(UUID.randomUUID().toString());
        commandCriteria.add(UUID.randomUUID().toString());

        final Job jobToCreate = new Job(
                user,
                name,
                commandArgs,
                commandCriteria,
                clusterCriterias,
                version
        );
        jobToCreate.setId(JOB_1_ID);
        this.service.createJob(jobToCreate);
    }
View Full Code Here

        final JobRepository jobRepo = Mockito.mock(JobRepository.class);
        final GenieNodeStatistics stats = Mockito.mock(GenieNodeStatistics.class);
        final JobManagerFactory jobManagerFactory = Mockito.mock(JobManagerFactory.class);
        final JobServiceJPAImpl impl = new JobServiceJPAImpl(jobRepo, stats, jobManagerFactory);

        final Job job = Mockito.mock(Job.class);
        Mockito.when(job.getId()).thenReturn(JOB_1_ID);
        Mockito.when(jobRepo.exists(JOB_1_ID)).thenReturn(false);
        Mockito.when(jobRepo.save(job)).thenThrow(new RuntimeException("junk"));

        try {
            impl.createJob(job);
View Full Code Here

     *
     * @throws GenieException
     */
    @Test
    public void testGetJob() throws GenieException {
        final Job job1 = this.service.getJob(JOB_1_ID);
        Assert.assertEquals(JOB_1_ID, job1.getId());
        Assert.assertEquals("testPigJob", job1.getName());
        Assert.assertEquals("tgianos", job1.getUser());
        Assert.assertEquals("2.4", job1.getVersion());
        Assert.assertEquals("-f -j", job1.getCommandArgs());
        Assert.assertEquals(JobStatus.INIT, job1.getStatus());
        Assert.assertEquals(3, job1.getTags().size());
        Assert.assertEquals(2, job1.getCommandCriteria().size());
        Assert.assertEquals(3, job1.getClusterCriterias().size());

        final Job job2 = this.service.getJob(JOB_2_ID);
        Assert.assertEquals(JOB_2_ID, job2.getId());
        Assert.assertEquals("testSparkJob", job2.getName());
        Assert.assertEquals("amsharma", job2.getUser());
        Assert.assertEquals("2.4.3", job2.getVersion());
        Assert.assertEquals("-f -j -a", job2.getCommandArgs());
        Assert.assertEquals(JobStatus.FAILED, job2.getStatus());
        Assert.assertEquals(4, job2.getTags().size());
        Assert.assertEquals(2, job2.getCommandCriteria().size());
        Assert.assertEquals(2, job2.getClusterCriterias().size());
    }
View Full Code Here

     */
    @Test
    public void testSetJobStatus() throws GenieException {
        final String msg = UUID.randomUUID().toString();
        this.service.setJobStatus(JOB_1_ID, JobStatus.RUNNING, msg);
        final Job job = this.service.getJob(JOB_1_ID);
        Assert.assertEquals(JobStatus.RUNNING, job.getStatus());
        Assert.assertEquals(msg, job.getStatusMsg());
    }
View Full Code Here

     * @throws GenieException
     */
    @Test
    public void testSetJobStatusNoMessage() throws GenieException {
        this.service.setJobStatus(JOB_1_ID, JobStatus.SUCCEEDED, null);
        final Job job = this.service.getJob(JOB_1_ID);
        Assert.assertEquals(JobStatus.SUCCEEDED, job.getStatus());
        Assert.assertNull(job.getStatusMsg());
    }
View Full Code Here

TOP

Related Classes of com.netflix.genie.common.model.Job

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.