Package com.enioka.jqm.jpamodel

Examples of com.enioka.jqm.jpamodel.History


    @Override
    public int enqueueFromHistory(int jobIdToCopy)
    {
        EntityManager em = null;
        History h = null;
        try
        {
            em = getEm();
            h = em.find(History.class, jobIdToCopy);
            return enqueue(getJobRequest(h));
View Full Code Here


        }

        try
        {
            em.getTransaction().begin();
            History h = new History();
            h.setId(ji.getId());
            h.setJd(ji.getJd());
            h.setSessionId(ji.getSessionID());
            h.setQueue(ji.getQueue());
            h.setMessages(new ArrayList<Message>());
            h.setEnqueueDate(ji.getCreationDate());
            h.setUserName(ji.getUserName());
            h.setEmail(ji.getEmail());
            h.setParentJobId(ji.getParentId());
            h.setApplication(ji.getApplication());
            h.setModule(ji.getModule());
            h.setKeyword1(ji.getKeyword1());
            h.setKeyword2(ji.getKeyword2());
            h.setKeyword3(ji.getKeyword3());
            h.setProgress(ji.getProgress());
            h.setParameters(new ArrayList<JobHistoryParameter>());
            h.setStatus(State.CANCELLED);
            h.setNode(ji.getNode());
            em.persist(h);

            em.createQuery("DELETE FROM MessageJi WHERE jobInstance = :i").setParameter("i", ji).executeUpdate();
            em.createQuery("DELETE FROM JobParameter WHERE jobInstance = :i").setParameter("i", ji).executeUpdate();
            em.createQuery("DELETE FROM JobInstance WHERE id = :i").setParameter("i", ji.getId()).executeUpdate();
View Full Code Here

    public int restartCrashedJob(int idJob)
    {
        EntityManager em = null;

        // History and Job ID have the same ID.
        History h = null;
        try
        {
            em = getEm();
            h = em.find(History.class, idJob);
        }
        catch (NoResultException e)
        {
            closeQuietly(em);
            throw new JqmClientException("You cannot restart a job that is not done or which was purged from history");
        }
        catch (Exception e)
        {
            closeQuietly(em);
            throw new JqmClientException("could not restart a job (internal error)", e);
        }

        if (!h.getState().equals(State.CRASHED))
        {
            closeQuietly(em);
            throw new JqmClientException("You cannot restart a job that has not crashed");
        }

        if (!h.getJd().isCanBeRestarted())
        {
            closeQuietly(em);
            throw new JqmClientException("This type of job was configured to prevent being restarded");
        }
View Full Code Here

    {
        EntityManager em = null;
        try
        {
            em = getEm();
            History h = em.find(History.class, idJob);
            com.enioka.jqm.api.JobInstance res = null;
            if (h != null)
            {
                res = getJob(h);
            }
View Full Code Here

    private InputStream getDeliverableContent(Deliverable deliverable)
    {
        EntityManager em = getEm();
        URL url = null;
        File file = null;
        History h = null;

        try
        {
            h = em.createQuery("SELECT h FROM History h WHERE h.id = :job", History.class).setParameter("job", deliverable.getJobId())
                    .getSingleResult();
        }
        catch (Exception e)
        {
            h = null;
            closeQuietly(em);
            throw new JqmInvalidRequestException("No ended job found with the deliverable ID", e);
        }

        String destDir = System.getProperty("java.io.tmpdir");
        jqmlogger.trace("File will be copied into " + destDir);

        try
        {
            url = new URL("http://" + h.getNode().getDns() + ":" + h.getNode().getPort() + "/getfile?file=" + deliverable.getRandomId());
            jqmlogger.trace("URL: " + url.toString());
        }
        catch (MalformedURLException e)
        {
            throw new JqmClientException("URL is not valid " + url, e);
View Full Code Here

    private InputStream getJobLog(int jobId, String extension, String param)
    {
        // 1: retrieve node to address
        EntityManager em = null;
        History h = null;
        try
        {
            em = getEm();
            h = em.find(History.class, jobId);
            if (h == null)
            {
                throw new NoResultException("No history for this jobId. perhaps the job isn't ended yet");
            }
        }
        catch (Exception e)
        {
            h = null;
            throw new JqmInvalidRequestException("No ended job found with the deliverable ID " + jobId, e);
        }
        finally
        {
            closeQuietly(em);
        }

        // 2: build URL
        URL url = null;
        try
        {
            url = new URL("http://" + h.getNode().getDns() + ":" + h.getNode().getPort() + "/log?" + param + "=" + jobId);
            jqmlogger.trace("URL: " + url.toString());
        }
        catch (MalformedURLException e)
        {
            throw new JqmClientException("URL is not valid " + url, e);
View Full Code Here

        // Update end date
        Calendar endDate = GregorianCalendar.getInstance(Locale.getDefault());

        // Done: put inside history & remove instance from queue.
        em.getTransaction().begin();
        History h = Helpers.createHistory(job, em, status, endDate);
        jqmlogger.trace("An History was just created for job instance " + h.getId());

        // A last message (directly created on History, not JI)
        Message m = new Message();
        m.setHistory(h);
        m.setTextMessage("Status updated: " + status);
View Full Code Here

     * @param em
     * @return
     */
    static History createHistory(JobInstance job, EntityManager em, State finalState, Calendar endDate)
    {
        History h = new History();
        h.setId(job.getId());
        h.setJd(job.getJd());
        h.setSessionId(job.getSessionID());
        h.setQueue(job.getQueue());
        h.setMessages(new ArrayList<Message>());
        h.setEnqueueDate(job.getCreationDate());
        h.setEndDate(endDate);
        h.setAttributionDate(job.getAttributionDate());
        h.setExecutionDate(job.getExecutionDate());
        h.setUserName(job.getUserName());
        h.setEmail(job.getEmail());
        h.setParentJobId(job.getParentId());
        h.setApplication(job.getApplication());
        h.setModule(job.getModule());
        h.setKeyword1(job.getKeyword1());
        h.setKeyword2(job.getKeyword2());
        h.setKeyword3(job.getKeyword3());
        h.setProgress(job.getProgress());
        h.setParameters(new ArrayList<JobHistoryParameter>());
        h.setStatus(finalState);
        h.setNode(job.getNode());

        em.persist(h);

        for (JobParameter j : job.getParameters())
        {
            JobHistoryParameter jp = new JobHistoryParameter();
            jp.setKey(j.getKey());
            jp.setValue(j.getValue());
            em.persist(jp);
            h.getParameters().add(jp);
        }
        for (MessageJi p : job.getMessages())
        {
            Message m = new Message();
            m.setHistory(h);
View Full Code Here

        em.getTransaction().begin();
        for (JobInstance ji : em
                .createQuery("SELECT ji FROM JobInstance ji WHERE ji.node = :node AND (ji.state = 'SUBMITTED' OR ji.state = 'RUNNING')",
                        JobInstance.class).setParameter("node", node).getResultList())
        {
            History h = Helpers.createHistory(ji, em, State.CRASHED, Calendar.getInstance());
            Message m = new Message();
            m.setHistory(h);
            m.setTextMessage("Job was supposed to be running at server startup - usually means it was killed along a server by an admin or a crash");
            em.persist(m);
View Full Code Here

    public static History createhistory(Calendar jobDate, JobDef JobDefId, String sessionId, Queue queue, String msg,
            List<Message> messages, JobInstance jobInstance, Calendar enqueueDate, Calendar executionDate, Calendar endDate,
            String userName, Node node, List<JobHistoryParameter> jhp, EntityManager em)
    {
        History h = new History();

        h.setJd(JobDefId);
        h.setSessionId(sessionId);
        h.setQueue(queue);
        h.setMessages(messages);
        h.setId(jobInstance.getId());
        h.setEnqueueDate(enqueueDate);
        h.setExecutionDate(executionDate);
        h.setEndDate(endDate);
        h.setUserName(userName);
        h.setNode(node);
        h.setParameters(jhp);

        em.persist(h);
        return h;
    }
View Full Code Here

TOP

Related Classes of com.enioka.jqm.jpamodel.History

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.