Package com.enioka.jqm.jpamodel

Examples of com.enioka.jqm.jpamodel.JobDef


    @Override
    public int enqueue(JobRequest jd)
    {
        jqmlogger.trace("BEGINING ENQUEUE");
        EntityManager em = getEm();
        JobDef job = null;
        try
        {
            job = em.createQuery(
                    "SELECT j FROM JobDef j LEFT JOIN FETCH j.queue LEFT JOIN FETCH j.parameters WHERE j.applicationName = :name",
                    JobDef.class).setParameter("name", jd.getApplicationName()).getSingleResult();
        }
        catch (NoResultException ex)
        {
            jqmlogger.error("Job definition named " + jd.getApplicationName() + " does not exist");
            closeQuietly(em);
            throw new JqmInvalidRequestException("no job definition named " + jd.getApplicationName());
        }

        jqmlogger.trace("Job to enqueue is from JobDef " + job.getId());
        Integer hl = null;
        List<JobParameter> jps = overrideParameter(job, jd, em);

        // Begin transaction (that will hold a lock in case of Highlander)
        try
        {
            em.getTransaction().begin();

            if (job.isHighlander())
            {
                hl = highlanderMode(job, em);
            }

            if (hl != null)
            {
                jqmlogger.trace("JI won't actually be enqueued because a job in highlander mode is currently submitted: " + hl);
                closeQuietly(em);
                return hl;
            }
            jqmlogger.trace("Not in highlander mode or no currently enqueued instance");
        }
        catch (Exception e)
        {
            closeQuietly(em);
            throw new JqmClientException("Could not do highlander analysis", e);
        }

        try
        {
            JobInstance ji = new JobInstance();
            ji.setJd(job);
            ji.setSessionID(jd.getSessionID());
            ji.setUserName(jd.getUser());
            ji.setState(State.SUBMITTED);
            ji.setQueue(job.getQueue());
            ji.setNode(null);
            // Can be null (if no email is asked for)
            ji.setEmail(jd.getEmail());
            ji.setCreationDate(Calendar.getInstance());
            if (jd.getParentID() != null)
View Full Code Here


    @Override
    public JobDef getRowData(String rowKey)
    {
        EntityManager em = Db.getEm();
        JobDef jd = em.find(JobDef.class, Integer.parseInt(rowKey));
        em.close();
        return jd;
    }
View Full Code Here

                        for (String n : jobs)
                        {
                            jqmlogger.debug("The jobs will be changed");
                            try
                            {
                                JobDef j = em.createQuery("SELECT j FROM JobDef j WHERE j.applicationName = :n", JobDef.class)
                                        .setParameter("n", n).getSingleResult();
                                Queue queue = em.createQuery("SELECT q FROM Queue q WHERE q.name = :n", Queue.class)
                                        .setParameter("n", name).getSingleResult();
                                em.getTransaction().begin();
                                j.setQueue(queue);
                                em.getTransaction().commit();
                                jqmlogger.debug("New configurations applied");
                            }
                            catch (NonUniqueResultException s)
                            {
View Full Code Here

                        Element ee = (Element) nl.item(i);

                        canBeRestarted = ("true".equals(ee.getElementsByTagName("canBeRestarted").item(0).getTextContent())) ? true : false;
                        javaClassName = ee.getElementsByTagName("javaClassName").item(0).getTextContent();

                        JobDef jd;
                        TypedQuery<JobDef> q = em.createQuery("SELECT j FROM JobDef j WHERE j.applicationName = :n", JobDef.class);
                        q.setParameter("n", ee.getElementsByTagName("name").item(0).getTextContent());
                        if (q.getResultList().size() == 1)
                        {
                            jd = q.getResultList().get(0);
                            jd.getParameters().clear();
                        }
                        else
                        {
                            jd = new JobDef();
                        }

                        // Queue
                        if (jd.getQueue() == null && ee.getElementsByTagName("queue").getLength() != 0)
                        {
                            // Specified inside the XML. Does the queue already exist?
                            String qname = ee.getElementsByTagName("queue").item(0).getTextContent();
                            try
                            {
                                queue = em.createQuery("SELECT q FROM Queue q WHERE q.name = :name", Queue.class)
                                        .setParameter("name", qname).getSingleResult();
                                // The queue exists
                            }
                            catch (NoResultException noe)
                            {
                                // The queue must be created.
                                if (createdQueues.containsKey(qname))
                                {
                                    queue = createdQueues.get(qname);
                                }
                                else
                                {
                                    queue = new Queue();
                                    queue.setDescription("Created from a jobdef import. Description should be set later");
                                    queue.setName(qname);
                                    em.persist(queue);
                                    createdQueues.put(qname, queue);
                                }
                            }
                        }
                        else
                        {
                            // Not specified => default queue
                            queue = em.createQuery("SELECT q FROM Queue q WHERE q.defaultQueue = true", Queue.class).getSingleResult();
                        }

                        // Easy attributes
                        description = ee.getElementsByTagName("description").item(0).getTextContent();
                        applicationName = ee.getElementsByTagName("name").item(0).getTextContent();
                        application = ee.getElementsByTagName("application").item(0).getTextContent();
                        module = ee.getElementsByTagName("module").item(0).getTextContent();
                        // Keyword used to be called "other". We allow both for ascending compatibility. ("other" is deprecated - don't use)
                        if (ee.getElementsByTagName("other1").getLength() > 0 && ee.getElementsByTagName("other2").getLength() > 0
                                && ee.getElementsByTagName("other3").getLength() > 0)
                        {
                            keyword1 = ee.getElementsByTagName("other1").item(0).getTextContent();
                            keyword2 = ee.getElementsByTagName("other2").item(0).getTextContent();
                            keyword3 = ee.getElementsByTagName("other3").item(0).getTextContent();
                        }
                        else if (ee.getElementsByTagName("keyword1").getLength() > 0 && ee.getElementsByTagName("keyword2").getLength() > 0
                                && ee.getElementsByTagName("keyword3").getLength() > 0)
                        {
                            keyword1 = ee.getElementsByTagName("keyword1").item(0).getTextContent();
                            keyword2 = ee.getElementsByTagName("keyword2").item(0).getTextContent();
                            keyword3 = ee.getElementsByTagName("keyword3").item(0).getTextContent();
                        }
                        highlander = ("true".equals(ee.getElementsByTagName("highlander").item(0).getTextContent())) ? true : false;
                        jarPath = e.getElementsByTagName("path").item(0).getTextContent();

                        NodeList l = ee.getElementsByTagName("parameter");

                        for (int j = 0; j < l.getLength(); j++)
                        {
                            Element t = (Element) l.item(j);

                            JobDefParameter jdp = new JobDefParameter();
                            jdp.setKey(t.getElementsByTagName("key").item(0).getTextContent());
                            jdp.setValue(t.getElementsByTagName("value").item(0).getTextContent());
                            jd.getParameters().add(jdp);
                        }

                        jd.setCanBeRestarted(canBeRestarted);
                        jd.setJavaClassName(javaClassName);
                        jd.setQueue(queue);
                        jd.setApplicationName(applicationName);
                        jd.setApplication(application);
                        jd.setModule(module);
                        jd.setKeyword1(keyword1);
                        jd.setKeyword2(keyword2);
                        jd.setKeyword3(keyword3);
                        jd.setHighlander(highlander);
                        jd.setJarPath(jarPath);
                        jd.setDescription(description);

                        em.persist(jd);
                        jqmlogger.info("Imported application " + applicationName);
                    }
                }
View Full Code Here

    // ------------------ JOBDEFINITION ------------------------

    public static JobDef initJobDefinition(String javaClassName, Queue queue, EntityManager em)
    {
        JobDef j = new JobDef();
        EntityTransaction transac = em.getTransaction();
        transac.begin();

        j.setJavaClassName(javaClassName);
        j.setQueue(queue);

        em.persist(j);
        transac.commit();

        return j;
View Full Code Here

    public static JobDef createJobDef(String descripton, boolean canBeRestarted, String javaClassName, List<JobDefParameter> jps,
            String jp, Queue queue, Integer maxTimeRunning, String applicationName, String application, String module, String keyword1,
            String keyword2, String keyword3, boolean highlander, EntityManager em)
    {
        JobDef j = new JobDef();
        EntityTransaction transac = em.getTransaction();
        transac.begin();

        // ------------------

        j.setDescription(descripton);
        j.setCanBeRestarted(canBeRestarted);
        j.setJavaClassName(javaClassName);
        j.setParameters(jps);
        j.setQueue(queue);
        j.setApplicationName(applicationName);
        j.setApplication(application);
        j.setModule(module);
        j.setKeyword1(keyword1);
        j.setKeyword2(keyword2);
        j.setKeyword3(keyword3);
        j.setHighlander(highlander);
        j.setJarPath(jp);

        em.persist(j);
        transac.commit();

        return j;
View Full Code Here

TOP

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

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.