Search in sources :

Example 1 with TestCaseExecutionQueueToTreat

use of org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat in project cerberus-source by cerberustesting.

the class TestCaseExecutionQueueDAO method readByVarious2.

@Override
public AnswerList readByVarious2(List<String> stateList) throws CerberusException {
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    AnswerList answer = new AnswerList();
    final StringBuilder query = new StringBuilder();
    query.append("SELECT exq.id, exq.manualexecution, app.System, cea.environment, cea.country, cea.application, cea.poolsize, exq.robotIP, rbt.host, exq.DebugFlag, app.type ");
    query.append("from testcaseexecutionqueue exq ");
    query.append("left join testcase tec on tec.test=exq.test and tec.testcase=exq.testcase ");
    query.append("left join application app on app.application=tec.application ");
    query.append("left join robot rbt on rbt.robot=exq.robot ");
    query.append("left join countryenvironmentparameters cea on cea.system=app.system and cea.environment=exq.environment and cea.country=exq.country and cea.application=tec.application ");
    query.append("WHERE 1=1 ");
    query.append(SqlUtil.createWhereInClause(" AND exq.state", stateList, true));
    query.append("order by exq.priority, exq.id asc;");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
    }
    List<TestCaseExecutionQueueToTreat> testCaseExecutionInQueueList = new ArrayList<TestCaseExecutionQueueToTreat>();
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    testCaseExecutionInQueueList.add(loadQueueToTreatFromResultSet(resultSet));
                }
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecutionInQueue").replace("%OPERATION%", "SELECT"));
                answer = new AnswerList(testCaseExecutionInQueueList, testCaseExecutionInQueueList.size());
            } catch (SQLException exception) {
                LOG.error("Unable to execute query : " + exception.toString());
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
                testCaseExecutionInQueueList = null;
            } finally {
                resultSet.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
            testCaseExecutionInQueueList = null;
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
        testCaseExecutionInQueueList = null;
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to retrieve the list of entries!"));
        }
    }
    answer.setResultMessage(msg);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) TestCaseExecutionQueueToTreat(org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat)

Example 2 with TestCaseExecutionQueueToTreat

use of org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat in project cerberus-source by cerberustesting.

the class TestCaseExecutionQueueDAO method loadQueueToTreatFromResultSet.

private TestCaseExecutionQueueToTreat loadQueueToTreatFromResultSet(ResultSet resultSet) throws SQLException {
    TestCaseExecutionQueueToTreat inQueue = new TestCaseExecutionQueueToTreat();
    try {
        inQueue.setId(resultSet.getInt("exq.id"));
        inQueue.setManualExecution(resultSet.getString("exq.manualexecution"));
        inQueue.setSystem(resultSet.getString("app.system"));
        inQueue.setEnvironment(resultSet.getString("cea.environment"));
        inQueue.setCountry(resultSet.getString("cea.country"));
        inQueue.setApplication(resultSet.getString("cea.application"));
        inQueue.setPoolSizeApplication(resultSet.getInt("cea.poolsize"));
        inQueue.setDebugFlag(resultSet.getString("exq.DebugFlag"));
        /**
         * Robot host is feed only if application type really required a
         * robot. data comes from robot by priority or exe when exist.
         */
        String robotHost = "";
        String appType = resultSet.getString("app.type");
        if (appType == null) {
            appType = "";
        }
        // If application type require a selenium/appium/sikuli server, we get the robot host from robot and not execution queue.
        if ((appType.equals(Application.TYPE_APK)) || (appType.equals(Application.TYPE_GUI)) || (appType.equals(Application.TYPE_FAT)) || (appType.equals(Application.TYPE_IPA))) {
            robotHost = resultSet.getString("rbt.host");
            if (StringUtil.isNullOrEmpty(robotHost)) {
                robotHost = resultSet.getString("exq.robotIP");
            }
        }
        inQueue.setRobotHost(robotHost);
    } catch (Exception e) {
        LOG.debug("Exception in load queue from resultset : " + e.toString());
    }
    return inQueue;
}
Also used : TestCaseExecutionQueueToTreat(org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat) SQLException(java.sql.SQLException) FactoryCreationException(org.cerberus.exception.FactoryCreationException) CerberusException(org.cerberus.exception.CerberusException)

Example 3 with TestCaseExecutionQueueToTreat

use of org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat in project cerberus-source by cerberustesting.

the class ExecutionThreadPoolService method executeNextInQueue.

/**
 * {@inheritDoc}
 */
@Override
public void executeNextInQueue(boolean forceExecution) throws CerberusException {
    // Job can be desactivated by parameter.
    if (!(parameterService.getParameterBooleanByKey("cerberus_queueexecution_enable", "", true))) {
        LOG.debug("Queue_Processing_Job disabled by parameter : 'cerberus_queueexecution_enable'.");
        return;
    }
    // We first check that another thread of Cerberus already trigger the job. Only 1 instance of the job is necessary.
    if (!(myVersionService.getMyVersionStringByKey("queueprocessingjobrunning", "N").equals("Y")) || forceExecution) {
        if (forceExecution) {
            LOG.debug("Forcing Start of Queue_Processing_Job.");
        }
        int nbqueuedexe = 0;
        do {
            if (!(parameterService.getParameterBooleanByKey("cerberus_queueexecution_enable", "", true))) {
                LOG.debug("Queue_Processing_Job disabled by parameter : 'cerberus_queueexecution_enable'.");
                return;
            }
            nbqueuedexe = 0;
            // Job is not already running, we can trigger it.
            LOG.debug("Starting Queue_Processing_Job.");
            // Flag in database that job is already running.
            myVersionService.UpdateMyVersionString("queueprocessingjobrunning", "Y");
            myVersionService.UpdateMyVersionString("queueprocessingjobstart", String.valueOf(new Date()));
            String cerberus_url = parameterService.getParameterStringByKey("cerberus_url", "", "");
            // Getting all executions to be treated.
            AnswerList answer = new AnswerList();
            answer = tceiqService.readQueueToTreat();
            List<TestCaseExecutionQueueToTreat> executionsInQueue = (List<TestCaseExecutionQueueToTreat>) answer.getDataList();
            int poolSizeGeneral = parameterService.getParameterIntegerByKey("cerberus_queueexecution_global_threadpoolsize", "", 12);
            int poolSizeRobot = parameterService.getParameterIntegerByKey("cerberus_queueexecution_defaultrobothost_threadpoolsize", "", 10);
            int queueTimeout = parameterService.getParameterIntegerByKey("cerberus_queueexecution_timeout", "", 600000);
            // Init constrain counter.
            int const01_current = 0;
            int const02_current = 0;
            int const03_current = 0;
            HashMap<String, Integer> constrains_current = new HashMap<String, Integer>();
            constrains_current = getCurrentlyRunning();
            // Getting RobotHost PoolSize
            HashMap<String, Integer> robot_poolsize = new HashMap<String, Integer>();
            robot_poolsize = invariantService.readToHashMapGp1IntegerByIdname("ROBOTHOST", poolSizeRobot);
            // Analysing each execution in the database queue.
            for (TestCaseExecutionQueueToTreat exe : executionsInQueue) {
                // Robot PoolSize if retreived from hashmap.
                int robot_poolsize_final = 0;
                if (robot_poolsize.containsKey(exe.getRobotHost())) {
                    robot_poolsize_final = ParameterParserUtil.parseIntegerParam(robot_poolsize.get(exe.getRobotHost()), poolSizeRobot);
                } else {
                    robot_poolsize_final = 0;
                }
                LOG.debug("Analysing Queue : " + exe.getId() + " poolGen " + poolSizeGeneral + " poolApp " + exe.getPoolSizeApplication() + " poolRobot " + robot_poolsize_final);
                String const01_key = TestCaseExecutionQueueToTreat.CONSTRAIN1_GLOBAL;
                String const02_key = TestCaseExecutionQueueToTreat.CONSTRAIN2_APPLICATION + CONST_SEPARATOR + exe.getSystem() + CONST_SEPARATOR + exe.getEnvironment() + CONST_SEPARATOR + exe.getCountry() + CONST_SEPARATOR + exe.getApplication();
                String const03_key = TestCaseExecutionQueueToTreat.CONSTRAIN3_ROBOT + CONST_SEPARATOR + exe.getRobotHost();
                // Eval Constrain 1
                if (constrains_current.containsKey(const01_key)) {
                    const01_current = constrains_current.get(const01_key);
                } else {
                    const01_current = 0;
                }
                // Eval Constrain 1
                boolean constMatch01;
                if (poolSizeGeneral == 0) {
                    // if poolsize == 0, this means no constrain specified.
                    constMatch01 = false;
                } else {
                    constMatch01 = (const01_current >= poolSizeGeneral);
                }
                // Eval Constrain 2
                if (constrains_current.containsKey(const02_key)) {
                    const02_current = constrains_current.get(const02_key);
                } else {
                    const02_current = 0;
                }
                // Eval Constrain 2
                boolean constMatch02;
                if (exe.getPoolSizeApplication() == 0) {
                    // if poolsize == 0, this means no constrain specified.
                    constMatch02 = false;
                } else {
                    constMatch02 = (const02_current >= exe.getPoolSizeApplication());
                }
                // Eval Constrain 3
                if (constrains_current.containsKey(const03_key)) {
                    const03_current = constrains_current.get(const03_key);
                } else {
                    const03_current = 0;
                }
                // Eval Constrain 3
                boolean constMatch03;
                if (robot_poolsize_final == 0) {
                    // if poolsize == 0, this means no constrain specified.
                    constMatch03 = false;
                } else {
                    constMatch03 = (const03_current >= robot_poolsize_final);
                }
                String notTriggeredExeMessage = "";
                boolean triggerExe = false;
                if ((!constMatch01 && !constMatch02 && !constMatch03) || (!constMatch01 && exe.getManualExecution().equals("Y"))) {
                    // Adding execution to queue.
                    if (queueService.updateToWaiting(exe.getId())) {
                        try {
                            ExecutionQueueWorkerThread task = new ExecutionQueueWorkerThread();
                            task.setCerberusExecutionUrl(cerberus_url);
                            task.setQueueId(exe.getId());
                            task.setToExecuteTimeout(queueTimeout);
                            task.setQueueService(queueService);
                            task.setExecThreadPool(threadQueuePool);
                            Future<?> future = threadQueuePool.getExecutor().submit(task);
                            task.setFuture(future);
                            triggerExe = true;
                            nbqueuedexe++;
                            // Debug messages.
                            LOG.debug("result : " + triggerExe + " Const1 " + constMatch01 + " Const2 " + constMatch01 + " Const3 " + constMatch01 + " Manual " + exe.getManualExecution());
                            LOG.debug(" CurConst1 " + const01_current + " CurConst2 " + const02_current + " CurConst3 " + const03_current);
                            // Counter increase
                            constrains_current.put(const01_key, const01_current + 1);
                            if (!exe.getManualExecution().equals("Y")) {
                                // Specific increment only if automatic execution.
                                constrains_current.put(const02_key, const02_current + 1);
                                constrains_current.put(const03_key, const03_current + 1);
                            }
                        } catch (Exception e) {
                            LOG.error("Failed to add Queueid : " + exe.getId() + " into the queue : " + e.getMessage());
                        }
                    }
                } else {
                    if (constMatch03) {
                        notTriggeredExeMessage = "Robot contrain on '" + const03_key + "' reached. " + robot_poolsize_final + " Execution(s) already in pool.";
                    }
                    if (constMatch02) {
                        notTriggeredExeMessage = "Application Environment contrain on '" + const02_key + "' reached . " + exe.getPoolSizeApplication() + " Execution(s) already in pool.";
                    }
                    if (constMatch01) {
                        notTriggeredExeMessage = "Global contrain reached. " + poolSizeGeneral + " Execution(s) already in pool.";
                    }
                    if ((exe.getDebugFlag() != null) && (exe.getDebugFlag().equalsIgnoreCase("Y"))) {
                        queueService.updateComment(exe.getId(), notTriggeredExeMessage);
                    }
                    LOG.debug("result : " + triggerExe + " Const1 " + constMatch01 + " Const2 " + constMatch01 + " Const3 " + constMatch01 + " Manual " + exe.getManualExecution());
                    LOG.debug(" CurConst1 " + const01_current + " CurConst2 " + const02_current + " CurConst3 " + const03_current);
                    LOG.debug(" " + notTriggeredExeMessage);
                }
            }
            // Flag in database that job is finished.
            myVersionService.UpdateMyVersionString("queueprocessingjobrunning", "N");
            LOG.debug("Stoping Queue_Processing_Job - TOTAL Released execution(s) : " + nbqueuedexe);
        } while (nbqueuedexe > 0);
    } else {
        LOG.debug("Queue_Processing_Job not triggered (already running.)");
    }
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) Date(java.util.Date) CerberusException(org.cerberus.exception.CerberusException) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) TestCaseExecutionQueueToTreat(org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat)

Example 4 with TestCaseExecutionQueueToTreat

use of org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat in project cerberus-source by cerberustesting.

the class ExecutionThreadPoolService method getCurrentlyToTreat.

@Override
public HashMap<String, Integer> getCurrentlyToTreat() throws CerberusException {
    AnswerList answer = new AnswerList();
    HashMap<String, Integer> constrains_current = new HashMap<String, Integer>();
    // Getting all executions to be treated.
    answer = tceiqService.readQueueToTreat();
    List<TestCaseExecutionQueueToTreat> executionsToTreat = (List<TestCaseExecutionQueueToTreat>) answer.getDataList();
    // Calculate constrain values.
    for (TestCaseExecutionQueueToTreat exe : executionsToTreat) {
        String const01_key = TestCaseExecutionQueueToTreat.CONSTRAIN1_GLOBAL;
        String const02_key = TestCaseExecutionQueueToTreat.CONSTRAIN2_APPLICATION + CONST_SEPARATOR + exe.getSystem() + CONST_SEPARATOR + exe.getEnvironment() + CONST_SEPARATOR + exe.getCountry() + CONST_SEPARATOR + exe.getApplication();
        String const03_key = TestCaseExecutionQueueToTreat.CONSTRAIN3_ROBOT + CONST_SEPARATOR + exe.getRobotHost();
        if (constrains_current.containsKey(const01_key)) {
            constrains_current.put(const01_key, constrains_current.get(const01_key) + 1);
        } else {
            constrains_current.put(const01_key, 1);
        }
        if (constrains_current.containsKey(const02_key)) {
            constrains_current.put(const02_key, constrains_current.get(const02_key) + 1);
        } else {
            constrains_current.put(const02_key, 1);
        }
        if (constrains_current.containsKey(const03_key)) {
            constrains_current.put(const03_key, constrains_current.get(const03_key) + 1);
        } else {
            constrains_current.put(const03_key, 1);
        }
    }
    return constrains_current;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) TestCaseExecutionQueueToTreat(org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat)

Example 5 with TestCaseExecutionQueueToTreat

use of org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat in project cerberus-source by cerberustesting.

the class ExecutionThreadPoolService method getCurrentlyRunning.

@Override
public HashMap<String, Integer> getCurrentlyRunning() throws CerberusException {
    AnswerList answer = new AnswerList();
    HashMap<String, Integer> constrains_current = new HashMap<String, Integer>();
    // Getting all executions already running in the queue.
    answer = tceiqService.readQueueRunning();
    List<TestCaseExecutionQueueToTreat> executionsRunning = (List<TestCaseExecutionQueueToTreat>) answer.getDataList();
    // Calculate constrain values.
    for (TestCaseExecutionQueueToTreat exe : executionsRunning) {
        String const01_key = TestCaseExecutionQueueToTreat.CONSTRAIN1_GLOBAL;
        String const02_key = TestCaseExecutionQueueToTreat.CONSTRAIN2_APPLICATION + CONST_SEPARATOR + exe.getSystem() + CONST_SEPARATOR + exe.getEnvironment() + CONST_SEPARATOR + exe.getCountry() + CONST_SEPARATOR + exe.getApplication();
        String const03_key = TestCaseExecutionQueueToTreat.CONSTRAIN3_ROBOT + CONST_SEPARATOR + exe.getRobotHost();
        if (constrains_current.containsKey(const01_key)) {
            constrains_current.put(const01_key, constrains_current.get(const01_key) + 1);
        } else {
            constrains_current.put(const01_key, 1);
        }
        if (constrains_current.containsKey(const02_key)) {
            constrains_current.put(const02_key, constrains_current.get(const02_key) + 1);
        } else {
            constrains_current.put(const02_key, 1);
        }
        if (constrains_current.containsKey(const03_key)) {
            constrains_current.put(const03_key, constrains_current.get(const03_key) + 1);
        } else {
            constrains_current.put(const03_key, 1);
        }
    }
    return constrains_current;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) HashMap(java.util.HashMap) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) TestCaseExecutionQueueToTreat(org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat)

Aggregations

TestCaseExecutionQueueToTreat (org.cerberus.engine.threadpool.entity.TestCaseExecutionQueueToTreat)6 AnswerList (org.cerberus.util.answer.AnswerList)5 HashMap (java.util.HashMap)4 List (java.util.List)4 SQLException (java.sql.SQLException)2 CerberusException (org.cerberus.exception.CerberusException)2 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 MessageEvent (org.cerberus.engine.entity.MessageEvent)1 FactoryCreationException (org.cerberus.exception.FactoryCreationException)1