Package com.netflix.genie.common.model

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


        LOG.debug("Called");
        if (StringUtils.isBlank(jobId)) {
            throw new GeniePreconditionException("No job id entered. Unable to continue"
            );
        }
        final Job job = this.jobRepo.findOne(jobId);
        if (job == null) {
            throw new GenieNotFoundException("No job with id " + jobId + " exists. Unable to continue."
            );
        }

        final List<ClusterCriteria> clusterCriterias = job.getClusterCriterias();
        final Set<String> commandCriteria = job.getCommandCriteria();

        for (final ClusterCriteria clusterCriteria : clusterCriterias) {
            @SuppressWarnings("unchecked")
            final List<Cluster> clusters = this.clusterRepo.findAll(
                    ClusterSpecs.findByClusterAndCommandCriteria(
                            clusterCriteria,
                            commandCriteria
                    )
            );

            if (!clusters.isEmpty()) {
                // Add the succesfully criteria to the job object in string form.
                job.setChosenClusterCriteriaString(
                        StringUtils.join(
                                clusterCriteria.getTags(),
                                CRITERIA_DELIMITER
                        )
                );
View Full Code Here


     * @return 0 for success, -1 for failure
     * @throws GenieException on issue
     */
    private boolean sendEmail(String emailTo, boolean killed) throws GenieException {
        LOG.debug("called");
        final Job job = this.jobService.getJob(this.jobId);

        if (!this.config.getBoolean("netflix.genie.server.mail.enable", false)) {
            LOG.warn("Email is disabled but user has specified an email address.");
            return false;
        }

        // Sender's email ID
        String fromEmail = this.config.getString("netflix.genie.server.mail.smpt.from", "no-reply-genie@geniehost.com");
        LOG.info("From email address to use to send email: "
                + fromEmail);

        // Set the smtp server hostname. Use localhost as default
        String smtpHost = this.config.getString("netflix.genie.server.mail.smtp.host", "localhost");
        LOG.debug("Email smtp server: "
                + smtpHost);

        // Get system properties
        Properties properties = new Properties();

        // Setup mail server
        properties.setProperty("mail.smtp.host", smtpHost);

        // check whether authentication should be turned on
        Authenticator auth = null;

        if (this.config.getBoolean("netflix.genie.server.mail.smtp.auth", false)) {
            LOG.debug("Email Authentication Enabled");

            properties.put("mail.smtp.starttls.enable", "true");
            properties.put("mail.smtp.auth", "true");

            String userName = config.getString("netflix.genie.server.mail.smtp.user");
            String password = config.getString("netflix.genie.server.mail.smtp.password");

            if ((userName == null) || (password == null)) {
                LOG.error("Authentication is enabled and username/password for smtp server is null");
                return false;
            }
            LOG.debug("Constructing authenticator object with username"
                    + userName
                    + " and password "
                    + password);
            auth = new SMTPAuthenticator(userName,
                    password);
        } else {
            LOG.debug("Email authentication not enabled.");
        }

        // Get the default Session object.
        Session session = Session.getInstance(properties, auth);

        try {
            // Create a default MimeMessage object.
            MimeMessage message = new MimeMessage(session);

            // Set From: header field of the header.
            message.setFrom(new InternetAddress(fromEmail));

            // Set To: header field of the header.
            message.addRecipient(Message.RecipientType.TO,
                    new InternetAddress(emailTo));

            JobStatus jobStatus;

            if (killed) {
                jobStatus = JobStatus.KILLED;
            } else {
                jobStatus = job.getStatus();
            }

            // Set Subject: header field
            message.setSubject("Genie Job "
                    + job.getName()
                    + " completed with Status: "
                    + jobStatus);

            // Now set the actual message
            String body = "Your Genie Job is complete\n\n"
                    + "Job ID: "
                    + job.getId()
                    + "\n"
                    + "Job Name: "
                    + job.getName()
                    + "\n"
                    + "Status: "
                    + job.getStatus()
                    + "\n"
                    + "Status Message: "
                    + job.getStatusMsg()
                    + "\n"
                    + "Output Base URL: "
                    + job.getOutputURI()
                    + "\n";

            message.setText(body);

            // Send message
View Full Code Here

        if (StringUtils.isNotBlank(clientHost)) {
            LOG.debug("called from: " + clientHost);
            job.setClientHost(clientHost);
        }

        final Job createdJob = this.xs.submitJob(job);
        return Response.created(
                uriInfo.getAbsolutePathBuilder().path(createdJob.getId()).build()).
                entity(createdJob).
                build();
    }
View Full Code Here

        }

        final long startTime = System.currentTimeMillis();

        while (true) {
            final Job job = getJob(id);

            // wait for job to finish - and finish time to be updated
            if (!job.getFinished().equals(new Date(0))) {
                return job;
            }

            // block until timeout
            long currTime = System.currentTimeMillis();
View Full Code Here

        // So we log it, to track all requests.
        if (!job.isForwarded()) {
            LOG.info("Received job request:" + job);
        }

        final Job forwardedJob = checkAbilityToRunOrForward(job);

        if (forwardedJob != null) {
            return forwardedJob;
        }

        // At this point we have established that the job can be run on this node.
        // Before running we validate the job and save it in the db if it passes validation.
        final Job savedJob = this.jobService.createJob(job);

        // try to run the job - return success or error
        return this.jobService.runJob(savedJob);
    }
View Full Code Here

    public Job killJob(final String id) throws GenieException {
        if (StringUtils.isBlank(id)) {
            throw new GeniePreconditionException("No id entered unable to kill job.");
        }
        LOG.debug("called for id: " + id);
        final Job job = this.jobRepo.findOne(id);

        // do some basic error handling
        if (job == null) {
            throw new GenieNotFoundException("No job exists for id " + id + ". Unable to kill.");
        }

        // check if it is done already
        if (job.getStatus() == JobStatus.SUCCEEDED
                || job.getStatus() == JobStatus.KILLED
                || job.getStatus() == JobStatus.FAILED) {
            // job already exited, return status to user
            return job;
        } else if (job.getStatus() == JobStatus.INIT
                || job.getProcessHandle() == -1) {
            // can't kill a job if it is still initializing
            throw new GeniePreconditionException("Unable to kill job as it is still initializing");
        }

        // if we get here, job is still running - and can be killed
        // redirect to the right node if killURI points to a different node
        final String killURI = job.getKillURI();
        if (StringUtils.isBlank(killURI)) {
            throw new GeniePreconditionException("Failed to get killURI for jobID: " + id);
        }
        final String localURI = getEndPoint() + "/" + JOB_RESOURCE_PREFIX + "/" + id;

        if (!killURI.equals(localURI)) {
            LOG.debug("forwarding kill request to: " + killURI);
            return forwardJobKill(killURI);
        }

        // if we get here, killURI == localURI, and job should be killed here
        LOG.debug("killing job on same instance: " + id);
        this.jobManagerFactory.getJobManager(job).kill();

        job.setJobStatus(JobStatus.KILLED, "Job killed on user request");
        job.setExitCode(ProcessStatus.JOB_KILLED.getExitCode());

        // increment counter for killed jobs
        this.stats.incrGenieKilledJobs();

        LOG.debug("updating job status to KILLED for: " + id);
        if (!job.isDisableLogArchival()) {
            job.setArchiveLocation(NetUtil.getArchiveURI(id));
        }

        // all good - return results
        return job;
    }
View Full Code Here

     * {@inheritDoc}
     */
    @Override
    @Transactional(rollbackFor = GenieException.class)
    public JobStatus finalizeJob(final String id, final int exitCode) throws GenieException {
        final Job job = this.jobRepo.findOne(id);
        if (job == null) {
            throw new GenieNotFoundException("No job with id " + id + " exists");
        }
        job.setExitCode(exitCode);

        // We check if status code is killed. The kill thread sets this, but just to make sure we set
        // it here again to prevent a race condition problem. This just makes the status message as
        // killed and prevents some jobs that are killed being marked as failed
        if (exitCode == ProcessStatus.JOB_KILLED.getExitCode()) {
            LOG.debug("Process has been killed, therefore setting the appropriate status message.");
            job.setJobStatus(JobStatus.KILLED, "Job killed on user request");
            return JobStatus.KILLED;
        } else {
            if (exitCode != ProcessStatus.SUCCESS.getExitCode()) {
                // all other failures except s3 log archival failure
                LOG.error("Failed to execute job, exit code: "
                        + exitCode);
                String errMsg;
                try {
                    errMsg = ProcessStatus.parse(exitCode).getMessage();
                } catch (final GenieException ge) {
                    errMsg = "Please look at job's stderr for more details";
                }
                job.setJobStatus(JobStatus.FAILED,
                        "Failed to execute job, Error Message: " + errMsg);
                // incr counter for failed jobs
                this.stats.incrGenieFailedJobs();
            } else {
                // success
                job.setJobStatus(JobStatus.SUCCEEDED,
                        "Job finished successfully");
                // incr counter for successful jobs
                this.stats.incrGenieSuccessfulJobs();
            }

            // set the archive location - if needed
            if (!job.isDisableLogArchival()) {
                job.setArchiveLocation(NetUtil.getArchiveURI(job.getId()));
            }

            // set the updated time
            job.setUpdated(new Date());
            return job.getStatus();
        }
    }
View Full Code Here

        job.validate();
        job.setJobStatus(JobStatus.INIT, "Initializing job");

        // Validation successful. init state in DB - return if job already exists
        try {
            final Job persistedJob = this.jobRepo.save(job);
            // if job can be launched, update the URIs
            final String hostName = NetUtil.getHostName();
            persistedJob.setHostName(hostName);
            persistedJob.setOutputURI(
                    getEndPoint(hostName)
                    + "/" + JOB_DIR_PREFIX
                    + "/" + persistedJob.getId()
            );
            persistedJob.setKillURI(
                    getEndPoint(hostName)
                    + "/" + JOB_RESOURCE_PREFIX
                    + "/" + persistedJob.getId()
            );

            // increment number of submitted jobs as we have successfully
            // persisted it in the database.
            this.stats.incrGenieJobSubmissions();
View Full Code Here

    @Transactional(readOnly = true)
    public Job getJob(final String id) throws GenieException {
        LOG.debug("called for id: " + id);
        this.testId(id);

        final Job job = this.jobRepo.findOne(id);
        if (job != null) {
            return job;
        } else {
            throw new GenieNotFoundException(
                    "No job exists for id " + id + ". Unable to retrieve.");
View Full Code Here

            final Set<String> tags) throws GenieException {
        this.testId(id);
        if (tags == null) {
            throw new GeniePreconditionException("No tags entered.");
        }
        final Job job = this.jobRepo.findOne(id);
        if (job != null) {
            job.getTags().addAll(tags);
            return job.getTags();
        } else {
            throw new GenieNotFoundException("No job with id " + id + " exists.");
        }
    }
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.