How to use processRequest method of org.cerberus.servlet.zzpublic.ManageV001 class

Best Cerberus-source code snippet using org.cerberus.servlet.zzpublic.ManageV001.processRequest

Source:ManageV001.java Github

copy

Full Screen

...62 * @param response servlet response63 * @throws ServletException if a servlet-specific error occurs64 * @throws IOException if an I/O error occurs65 */66 protected void processRequest(HttpServletRequest request, HttpServletResponse response)67 throws ServletException, IOException {68 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());69 JSONObject data = new JSONObject();70 response.setContentType("application/json");71 response.setCharacterEncoding("utf8");72 try {73 ExecutionUUID euuid = appContext.getBean(ExecutionUUID.class);74 executionThreadPoolService = appContext.getBean(IExecutionThreadPoolService.class);75 parameterService = appContext.getBean(IParameterService.class);76 String token = parameterService.getParameterStringByKey("cerberus_manage_token", "", UUID.randomUUID().toString());77 String message = "";78 if (token.equals(request.getParameter("token"))) {79 int maxIteration = parameterService.getParameterIntegerByKey("cerberus_manage_timeout", "", 300);80 int cntIteration = 0;81 int instancePendingExecutionNb = euuid.size();82 int globalPendingExecutionNb = getNbPendingExecutions(appContext);83 boolean globalActive = parameterService.getParameterBooleanByKey("cerberus_queueexecution_enable", "", true);84 if (request.getParameter("action") != null && request.getParameter("action").equals("stop")) {85 if (request.getParameter("scope") != null && request.getParameter("scope").equals("instance")) {86 /**87 * We desactivate the instance to process new execution.88 */89 executionThreadPoolService.setInstanceActive(false);90 /**91 * We loop every second until maxIteration session in92 * order to wait until no more executions are running on93 * that instance.94 */95 while (instancePendingExecutionNb > 0 && cntIteration <= maxIteration) {96 cntIteration++;97 Thread.sleep(1000);98 instancePendingExecutionNb = euuid.size();99 LOG.info("Stopping instance : Check " + cntIteration + "/" + maxIteration + " on pending executions on that instance. Still running : " + instancePendingExecutionNb);100 }101 data.put("waitedIterations", cntIteration);102 } else if (request.getParameter("scope") != null && request.getParameter("scope").equals("global")) {103 /**104 * We desactivate globally the queue processing accross105 * all instances.106 */107 parameterService.setParameter("cerberus_queueexecution_enable", "", "N");108 /**109 * We loop every second until maxIteration session in110 * order to wait until no more executions are running.111 */112 while (globalPendingExecutionNb > 0 && cntIteration <= maxIteration) {113 cntIteration++;114 Thread.sleep(1000);115 // TODO116 globalPendingExecutionNb = getNbPendingExecutions(appContext);117 LOG.info("Stopping global : Check " + cntIteration + "/" + maxIteration + " on global pending executions. Still running : " + globalPendingExecutionNb);118 }119 data.put("waitedIterations", cntIteration);120 } else {121 message += "Scope parameter 'scope' not defined.";122 }123 }124 if (request.getParameter("action") != null && request.getParameter("action").equals("start")) {125 if (request.getParameter("scope") != null && request.getParameter("scope").equals("instance")) {126 /**127 * We activate the instance to process queue and start128 * new executions.129 */130 executionThreadPoolService.setInstanceActive(true);131 try {132 // Run the Execution pool Job.133 executionThreadPoolService.executeNextInQueueAsynchroneously(false);134 } catch (CerberusException ex) {135 LOG.error("Exception triggering the ThreadPool job.", ex);136 }137 } else if (request.getParameter("scope") != null && request.getParameter("scope").equals("global")) {138 /**139 * We activate the parameter to process queue (that will140 * start new executions).141 */142 parameterService.setParameter("cerberus_queueexecution_enable", "", "Y");143 } else {144 message += "Scope parameter 'scope' not defined.";145 }146 }147 JSONObject instance = new JSONObject();148 JSONObject global = new JSONObject();149 instance.put("active", executionThreadPoolService.isInstanceActive());150 instance.put("runningExecutions", instancePendingExecutionNb);151 instance.put("readyToStop", (instancePendingExecutionNb <= 0));152 data.put("instance", instance);153 global.put("active", globalActive);154 global.put("runningExecutions", globalPendingExecutionNb);155 global.put("readyToStop", (globalPendingExecutionNb <= 0));156 data.put("global", global);157 JSONObject fsSize = new JSONObject();158 fsSize.put("cerberus_exeautomedia_path", getFSSize(parameterService.getParameterStringByKey("cerberus_exeautomedia_path", "", "/")));159 fsSize.put("cerberus_applicationobject_path", getFSSize(parameterService.getParameterStringByKey("cerberus_applicationobject_path", "", "/")));160 fsSize.put("cerberus_exemanualmedia_path", getFSSize(parameterService.getParameterStringByKey("cerberus_exemanualmedia_path", "", "/")));161 fsSize.put("cerberus_ftpfile_path", getFSSize(parameterService.getParameterStringByKey("cerberus_ftpfile_path", "", "/")));162 fsSize.put("cerberus_testdatalibcsv_path", getFSSize(parameterService.getParameterStringByKey("cerberus_testdatalibcsv_path", "", "/")));163 data.put("fileSystemSize", fsSize);164 } else {165 message = "Invalid Token";166 }167 data.put("message", message);168 } catch (JSONException | InterruptedException ex) {169 LOG.error(ex);170 }171 response.getWriter().print(data.toString());172 }173 private int getNbPendingExecutions(ApplicationContext appContext) {174 try {175 tceiqService = appContext.getBean(ITestCaseExecutionQueueService.class);176 // Getting all executions already running in the queue.177 AnswerList<TestCaseExecutionQueueToTreat> answer = tceiqService.readQueueRunning();178 List<TestCaseExecutionQueueToTreat> executionsRunning = answer.getDataList();179 return executionsRunning.size();180 } catch (CerberusException ex) {181 LOG.error(ex);182 }183 return 0;184 }185 private JSONObject getFSSize(String path) {186 JSONObject exeFS = new JSONObject();187 LOG.debug(path);188 try {189 exeFS.put("path", path);190 if (new File(path).exists()) {191 long freeSpace = new File(path).getFreeSpace();192 exeFS.put("freeSpace", freeSpace);193 long totalSpace = new File(path).getTotalSpace();194 exeFS.put("totalSpace", totalSpace);195 if (totalSpace > 0) {196 exeFS.put("perUsed", (totalSpace - freeSpace) * 100 / totalSpace);197 }198 } else {199 exeFS.put("message", "Folder does not Exist.");200 }201 return exeFS;202 } catch (JSONException ex) {203 LOG.error("Exception getting FS space for : " + path, ex);204 } catch (Exception ex) {205 LOG.error("Exception getting FS space for : " + path, ex);206 }207 return exeFS;208 }209 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">210 /**211 * Handles the HTTP <code>GET</code> method.212 *213 * @param request servlet request214 * @param response servlet response215 * @throws ServletException if a servlet-specific error occurs216 * @throws IOException if an I/O error occurs217 */218 @Override219 protected void doGet(HttpServletRequest request, HttpServletResponse response)220 throws ServletException, IOException {221 processRequest(request, response);222 }223 /**224 * Handles the HTTP <code>POST</code> method.225 *226 * @param request servlet request227 * @param response servlet response228 * @throws ServletException if a servlet-specific error occurs229 * @throws IOException if an I/O error occurs230 */231 @Override232 protected void doPost(HttpServletRequest request, HttpServletResponse response)233 throws ServletException, IOException {234 processRequest(request, response);235 }236 /**237 * Returns a short description of the servlet.238 *239 * @return a String containing servlet description240 */241 @Override242 public String getServletInfo() {243 return "Short description";244 }// </editor-fold>245}...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1request = {2 "request": {3 "headers": {4 },5 "body": {6 }7 }8}9response = {10 "response": {11 "headers": {12 },13 "body": {14 }15 }16}17test = {18}19org.cerberus.servlet.zzpublic.ManageV001.processRequest(test)

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.zzpublic.ManageV001;2import org.json.simple.JSONObject;3import org.json.simple.JSONArray;4import java.util.List;5import java.util.Map;6import java.util.HashMap;7JSONObject result = new JSONObject();8JSONArray rows = new JSONArray();9JSONObject row = new JSONObject();10String processRequest = request.getParameter("processRequest");11if (processRequest != null && processRequest.equals("getVersionList")) {12 ManageV001 manageV001 = new ManageV001();13 List<Map<String, String>> versionList = manageV001.getVersionList();14 if (versionList != null) {15 for (Map<String, String> version : versionList) {16 row.put("id", version.get("id"));17 row.put("version", version.get("version"));18 rows.add(row);19 }20 }21 result.put("versionList", rows);22}23response.getWriter().print(result);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful