Package com.enioka.jqm.jpamodel

Examples of com.enioka.jqm.jpamodel.Queue


    @Override
    public void setJobQueue(int idJob, int idQueue)
    {
        EntityManager em = null;
        JobInstance ji = null;
        Queue q = null;

        try
        {
            em = getEm();
            q = em.find(Queue.class, idQueue);
View Full Code Here


            n.setRootLogLevel("INFO");
            em.persist(n);
        }

        // Default queue
        Queue q = null;
        long i = (Long) em.createQuery("SELECT COUNT(qu) FROM Queue qu").getSingleResult();
        jqmlogger.info("There are " + i + " queues defined in the database");
        if (i == 0L)
        {
            q = new Queue();
            q.setDefaultQueue(true);
            q.setDescription("default queue");
            q.setTimeToLive(1024);
            q.setName("DEFAULT");
            em.persist(q);

            jqmlogger.info("A default queue was created in the configuration");
        }
        else
        {
            try
            {
                q = em.createQuery("SELECT q FROM Queue q WHERE q.defaultQueue = true", Queue.class).getSingleResult();
                jqmlogger.info("Default queue is named " + q.getName());
            }
            catch (NonUniqueResultException e)
            {
                // Faulty configuration, but why not
                q = em.createQuery("SELECT q FROM Queue q", Queue.class).getResultList().get(0);
                q.setDefaultQueue(true);
                jqmlogger.info("Queue " + q.getName() + " was modified to become the default queue as there were mutliple default queue");
            }
            catch (NoResultException e)
            {
                // Faulty configuration, but why not
                q = em.createQuery("SELECT q FROM Queue q", Queue.class).getResultList().get(0);
                q.setDefaultQueue(true);
                jqmlogger.warn("Queue  " + q.getName() + " was modified to become the default queue as there was no default queue");
            }
        }

        // Global parameters
        initSingleParam("mavenRepo", "http://repo1.maven.org/maven2/", em);
View Full Code Here

        try
        {
            jqmlogger.debug(f.getPath());
            jqmlogger.debug("Working Directory = " + System.getProperty("user.dir"));

            Queue q;

            if (f == null || !f.isFile())
            {
                throw new FileNotFoundException("The XML file " + f + " was not found");
            }

            dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(f);

            doc.getDocumentElement().normalize();
            NodeList nList = doc.getElementsByTagName("jqm");

            // Get the information about the queue
            for (int temp = 0; temp < nList.getLength(); temp++)
            {
                Node nNode = nList.item(temp);
                if (nNode.getNodeType() == Node.ELEMENT_NODE)
                {
                    Element e = (Element) nNode;

                    NodeList nl = e.getElementsByTagName("queue");

                    for (int i = 0; i < nl.getLength(); i++)
                    {
                        Element ee = (Element) nl.item(i);

                        name = ee.getElementsByTagName("name").item(0).getTextContent();
                        description = ee.getElementsByTagName("description").item(0).getTextContent();
                        if (ee.getElementsByTagName("timeToLive").getLength() == 1)
                        {
                            timeToLive = ee.getElementsByTagName("timeToLive").item(0).getTextContent();
                        }
                        else
                        {
                            timeToLive = "0";
                        }

                        jqmlogger.debug("Name: " + name);
                        jqmlogger.debug("Description: " + description);
                        jqmlogger.debug("maxTempInQueue: " + timeToLive);

                        // The list must be purged
                        jobs.clear();

                        NodeList l = ee.getElementsByTagName("applicationName");
                        jqmlogger.debug(l.getLength());

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

                            jqmlogger.debug("Default queue of the job " + t.getTextContent() + " must be changed");
                            jobs.add(t.getTextContent());
                        }

                        // We must check if the queue already exist and add it
                        try
                        {
                            q = em.createQuery("SELECT q FROM Queue q WHERE q.name = :n", Queue.class).setParameter("n", name)
                                    .getSingleResult();
                            jqmlogger.info("The queue " + name + "already exists. It will be overriden");
                            q.setDescription(description);
                            q.setTimeToLive(Integer.parseInt(timeToLive));
                        }
                        catch (NonUniqueResultException s)
                        {
                            jqmlogger.warn("Queue " + name + " is non unique. The admin must change the queue configurations");
                        }
                        catch (NoResultException ss)
                        {
                            jqmlogger.debug("The queue will be created");
                            em.getTransaction().begin();
                            Queue queue = new Queue();

                            queue.setDefaultQueue(false);
                            queue.setDescription(description);
                            queue.setTimeToLive(Integer.parseInt(timeToLive));
                            queue.setName(name);

                            em.persist(queue);
                            em.getTransaction().commit();
                        }

                        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");
View Full Code Here

    }

    void export(String path, String queueName)
    {
        Queue q = null;
        Element root = new Element("jqm");
        Document document = new Document(root);

        Element queues = new Element("queues");
        root.addContent(queues);

        try
        {
            q = em.createQuery("SELECT q FROM Queue q WHERE q.name = :n", Queue.class).setParameter("n", queueName).getSingleResult();
        }
        catch (NonUniqueResultException s)
        {
            jqmlogger.error("Queue " + queueName + " is non unique. The admin must change the queue configurations");
            return;
        }
        catch (NoResultException ss)
        {
            jqmlogger.error("This queue doesn't exist");
            return;
        }

        Element queue = new Element("queue");
        queues.addContent(queue);

        Element name = new Element("name");
        name.setText(q.getName());
        Element description = new Element("description");
        description.setText(q.getDescription());
        Element timeToLive = new Element("timeToLive");
        timeToLive.setText(q.getTimeToLive() + "");

        queue.addContent(name);
        queue.addContent(description);
        queue.addContent(timeToLive);
View Full Code Here

        save(path, document);
    }

    void exportSeveral(String path, List<String> queueNames)
    {
        Queue q = null;
        Element root = new Element("jqm");
        Document document = new Document(root);

        Element queues = new Element("queues");
        root.addContent(queues);

        for (String queueName : queueNames)
        {
            try
            {
                q = em.createQuery("SELECT q FROM Queue q WHERE q.name = :n", Queue.class).setParameter("n", queueName).getSingleResult();
            }
            catch (NonUniqueResultException s)
            {
                jqmlogger.warn("Queue " + queueName + " is non unique. The admin must change the queue configuration");
            }
            catch (NoResultException ss)
            {
                jqmlogger.debug("This queue doesn't exist");
            }
            Element queue = new Element("queue");
            queues.addContent(queue);

            Element name = new Element("name");
            name.setText(q.getName());
            Element description = new Element("description");
            description.setText(q.getDescription());
            Element timeToLive = new Element("timeToLive");
            timeToLive.setText(q.getTimeToLive() + "");

            queue.addContent(name);
            queue.addContent(description);
            queue.addContent(timeToLive);
View Full Code Here

        DocumentBuilder dBuilder;
        Map<String, Queue> createdQueues = new HashMap<String, Queue>();

        boolean canBeRestarted = true;
        String javaClassName = null;
        Queue queue = null;
        String applicationName = null;
        String application = null;
        String module = null;
        String keyword1 = null;
        String keyword2 = null;
        String keyword3 = null;
        boolean highlander = false;
        String jarPath = null;
        String description = null;

        // SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        // Schema schema = null;
        // schema = factory.newSchema(new File("./lib/res.xsd"));
        // Validator validator = schema.newValidator();
        // DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
        // Document document = parser.parse(f);
        // validator.validate(new DOMSource(document));

        try
        {
            dBuilder = dbFactory.newDocumentBuilder();
            Document doc = dBuilder.parse(f);

            doc.getDocumentElement().normalize();
            NodeList nList = doc.getElementsByTagName("jqm");

            em.getTransaction().begin();

            for (int temp = 0; temp < nList.getLength(); temp++)
            {
                Node nNode = nList.item(temp);
                if (nNode.getNodeType() == Node.ELEMENT_NODE)
                {
                    Element e = (Element) nNode;
                    NodeList nl = e.getElementsByTagName("jobDefinition");

                    for (int i = 0; i < nl.getLength(); i++)
                    {
                        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);
                                }
                            }
                        }
View Full Code Here

        return initQueue(name, description, timeToLive, em, false);
    }

    public static Queue initQueue(String name, String description, Integer timeToLive, EntityManager em, boolean defaultQueue)
    {
        Queue q = new Queue();
        EntityTransaction transac = em.getTransaction();
        transac.begin();

        q.setName(name);
        q.setDescription(description);
        q.setTimeToLive(timeToLive);
        q.setDefaultQueue(defaultQueue);

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

        return q;
View Full Code Here

TOP

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

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.