📄 cronservice.java
字号:
Integer id; STAFCommandParseResult parsedRequest = fTriggerParser.parse(info.request); if (parsedRequest.rc != STAFResult.Ok) { return new STAFResult( STAFResult.InvalidRequestString, parsedRequest.errorBuffer); } try { // Verify the requester has at least trust level 5 STAFResult trustResult = STAFUtil.validateTrust( 5, fServiceName, "TRIGGER", fLocalMachineName, info); if (trustResult.rc != STAFResult.Ok) return trustResult; // Resolve the ID option resolvedValue = STAFUtil.resolveRequestVarAndCheckInt( "id", parsedRequest.optionValue("id"), fHandle, info.requestNumber); if (resolvedValue.rc != 0) return resolvedValue; id = new Integer(resolvedValue.result); // Check if registration table contains the ID if (!fRegTable.containsKey(id)) { return new STAFResult( STAFResult.DoesNotExist, "ID " + id + " not found"); } else { // Create a marshalling context and set any map classes (if any) STAFMarshallingContext mc = new STAFMarshallingContext(); mc.setMapClassDefinition(fTriggerMapClass); // Create an empty result map to contain the result Map resultMap = fTriggerMapClass.createInstance(); // Handle any SCRIPT options int scriptCount = parsedRequest.optionTimes("script"); LinkedList scripts = new LinkedList(); if (scriptCount > 0) { for (int i = 1; i <= scriptCount; i++) { resolvedValue = STAFUtil.resolveRequestVar( parsedRequest.optionValue("script", i), fHandle, info.requestNumber); scripts.add(resolvedValue.result); } } String triggerMsg = "[ID=" + id + "] [" + info.endpoint + ", " + info.handleName + "] Triggering a STAF command.\n" + info.request; fHandle.submit2("local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL info MESSAGE " + STAFUtil.wrapData(triggerMsg)); CronData1 theData = (CronData1)fRegTable.get(id); // create new Python Interpreter for each Cron fPythonInterpreter = new PythonInterpreter(); String regInfoMsg = " ID: " + id.toString() + "\n machine: " + theData.fMachine + "\n service: " + theData.fService + "\n request: " + theData.fRequest + "\n prepare: " + theData.fPrepare; // First execute any SCRIPT options for (int j = 0; j < scripts.size(); j++) { String script = (String)scripts.get(j); try { pyExec(script); } catch (PyException e) { String pythonError = "Python error in the " + "SCRIPT value.\n\nSCRIPT:\n" + script + "\n\nPyException:\n" + e + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } } pySetVar("STAFCronSubmit", "true"); String prepare = theData.fPrepare; if (prepare != null && !prepare.equals("")) { try { pyExec(prepare); } catch (PyException ex) { String pythonError = "Python error in the " + "PREPARE value.\n\nPREPARE:\n" + prepare + "\n\nPyException:\n" + ex + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } Object submit = pyGetVar("STAFCronSubmit"); if ((submit == null) || (!submit.toString().equals("true"))) { // Do not submit the request for this registration return new STAFResult(REQUESTNOTSUBMITTED, "STAFCronSubmit=" + submit.toString()); } } boolean pythonMachine = theData.fPythonMachine; boolean pythonService = theData.fPythonService; boolean pythonRequest = theData.fPythonRequest; String machine = ""; String service = ""; String request = ""; if (pythonMachine) { try { machine = pyStringEval(theData.fMachine); } catch (PyException ex) { String pythonError = "Python error in the " + "PYTHONMACHINE value.\n\nPYTHONMACHINE: " + theData.fMachine + "\n\nPyException:\n" + ex + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } } else { machine = theData.fMachine; } if (pythonService) { try { service = pyStringEval(theData.fService); } catch (PyException ex) { String pythonError = "Python error in the " + "PYTHONSERVICE value.\n\nPYTHONSERVICE: " + theData.fService + "\n\nPyException:\n" + ex + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } } else { service = theData.fService; } if (pythonRequest) { try { request = pyStringEval(theData.fRequest); } catch (PyException ex) { String pythonError = "Python error in the " + "PYTHONREQUEST value.\n\nPYTHONREQUEST: " + theData.fRequest + "\n\nPyException:\n" + ex + "\nProcessing registration:\n" + regInfoMsg; String msg = "[ID=" + id + "] " + pythonError; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL error MESSAGE " + STAFUtil.wrapData(msg)); return new STAFResult(PYTHONERROR, pythonError); } } else { request = theData.fRequest; } STAFResult matchResult = fHandle.submit2( STAFHandle.ReqQueue, machine, service, request); sResult.result = matchResult.result; fSubmittedRequests.put( matchResult.result, "machine=" + machine + " service=" + service + " request=" + request); STAFResult varRequest = fHandle.submit2(machine, "VAR", "RESOLVE STRING {STAF/Config/Machine}"); String machineName = varRequest.result; fRequestsAndIDs.put(machineName + ":" + matchResult.result, id.toString()); String message = "[ID=" + id.toString() + "] " + "[" + machineName + ":" + matchResult.result + "] Submitted a STAF command.\n" + "Triggered manually"+ "\nSubmitted STAF command: STAF " + machine + " " + service + " " + request; fHandle.submit2( "local", "LOG", "LOG MACHINE LOGNAME " + fServiceName + " LEVEL info MESSAGE " + STAFUtil.wrapData(message)); resultMap.put("machine", machineName); resultMap.put("requestNumber", matchResult.result); // Set the result map as the root object for the marshalling // context and return the marshalled result mc.setRootObject(resultMap); return new STAFResult(STAFResult.Ok, mc.marshall()); } } catch (Exception e) { if (DEBUG) { e.printStackTrace(); } return new STAFResult(STAFResult.JavaError, "Internal Java error."); } } private STAFResult handleRegister( STAFServiceInterfaceLevel30.RequestInfo info) { STAFResult sResult = new STAFResult(STAFResult.Ok, ""); String description = ""; String originMachine = info.endpoint; String machine = ""; boolean pythonMachine = true; String service = ""; boolean pythonService = true; String request = ""; boolean pythonRequest = true; String prepare = ""; boolean once = false; STAFResult resolvedResult = null; STAFResult resolvedValue = null; STAFCommandParseResult parsedRequest = fRegisterParser.parse(info.request); if (parsedRequest.rc != STAFResult.Ok) { return new STAFResult(STAFResult.InvalidRequestString, parsedRequest.errorBuffer); } // For each option, if the user has specified a value, set the // corresponding local variable to the user-specified value. try { // Verify the requester has at least trust level 5 STAFResult trustResult = STAFUtil.validateTrust( 5, fServiceName, "REGISTER", fLocalMachineName, info); if (trustResult.rc != STAFResult.Ok) return trustResult; // Process the request if (parsedRequest.optionTimes("description") > 0) { resolvedValue = STAFUtil.resolveRequestVar( parsedRequest.optionValue("description"), fHandle, info.requestNumber); description = resolvedValue.result; } if (parsedRequest.optionTimes("machine") > 0) { resolvedValue = STAFUtil.resolveRequestVar( parsedRequest.optionValue("machine"), fHandle, info.requestNumber); if (resolvedValue.rc != 0) return resolvedValue; machine = resolvedValue.result; pythonMachine = false; } else if (parsedRequest.optionTimes("pythonmachine") > 0) { machine = parsedRequest.optionValue("pythonmachine"); pythonMachine = true; } if (parsedRequest.optionTimes("service") > 0) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -