📄 cronservice.java
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2002, 2004, 2005 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/package com.ibm.staf.service.cron;import com.ibm.staf.*;import com.ibm.staf.service.*;import java.util.*;import java.io.*;import org.python.util.PythonInterpreter;import org.python.core.*;public class CronService implements STAFServiceInterfaceLevel30, Runnable{ private STAFHandle fHandle; private final String kVersion = "3.2.1"; // Version of STAF (or later) required for this service private final String kRequiredSTAFVersion = "3.1.0"; private STAFCommandParser fParmsParser = new STAFCommandParser(); private STAFCommandParser fRegisterParser; private STAFCommandParser fListParser; private STAFCommandParser fTriggerParser; private STAFCommandParser fVersionParser; private STAFMapClassDefinition fCronIDMapClass; private STAFMapClassDefinition fCronIDLongMapClass; private STAFMapClassDefinition fCronIDShortMapClass; private STAFMapClassDefinition fTriggerMapClass; private Hashtable fRegTable; private static boolean DEBUG = true; private Thread fQueueThread; private STAFCommandParser fUnregisterParser; private int fCronID = 1; private String fLineSep; private String fCronServiceMachine = ""; private String fServiceName = ""; private String fJythonVersion = ""; private PythonInterpreter fPythonInterpreter; private String fHashtableFileDirectory; private String fHashtableFileName; private String fLocalMachineName; private final String kMinute = "minute"; private final String kHour = "hour"; private final String kDay = "day"; private final String kMonth = "month"; private final String kWeekday = "weekday"; private HashMap fSubmittedRequests = new HashMap(); private HashMap fRequestsAndIDs = new HashMap(); // key=<machine>:<reqNum>, value=ID private HashMap fProcessHandlesAndRequests = new HashMap(); // key=<machine>:<handle>, value=<machine>:<reqNum> static final String sQueueTypeEnd = "STAF/Service/Cron/End"; private String fServiceHandleName = ""; public static final int PYTHONERROR = 4001; private static final String PYTHONERRORInfo = "Python error"; private static final String PYTHONERRORDesc = "A Python error occurred while evaluating the request to be submitted."; public static final int REQUESTNOTSUBMITTED = 4002; private static final String REQUESTNOTSUBMITTEDInfo = "Request not submitted"; private static final String REQUESTNOTSUBMITTEDDesc = "The request was not submitted because the value of " + "STAFCronSubmit was not set to true."; public CronService() { } public STAFResult init(STAFServiceInterfaceLevel30.InitInfo info) { int rc = STAFResult.Ok; try { STAFResult res = new STAFResult(); fServiceHandleName = "STAF/SERVICE/" + info.name; fHandle = new STAFHandle(fServiceHandleName); fServiceName = info.name; // Resolve the machine name variable for the local machine res = STAFUtil.resolveInitVar("{STAF/Config/Machine}", fHandle); if (res.rc != STAFResult.Ok) return res; fLocalMachineName = res.result; // Resolve the line separator variable for the local machine res = STAFUtil.resolveInitVar("{STAF/Config/Sep/Line}", fHandle); if (res.rc != STAFResult.Ok) return res; fLineSep = res.result; // Verify that the required version of STAF is running on the // local service machine. // Note: Method compareSTAFVersion was added in STAF V3.1.0 try { res = STAFUtil.compareSTAFVersion( "local", fHandle, kRequiredSTAFVersion); if (res.rc != STAFResult.Ok) { if (res.rc == STAFResult.InvalidSTAFVersion) { return new STAFResult( STAFResult.ServiceConfigurationError, "Minimum required STAF version for this service " + "is not running." + fLineSep + res.result); } else { return new STAFResult( STAFResult.ServiceConfigurationError, "Error verifying the STAF version. RC: " + res.rc + ", Additional info: " + res.result); } } } catch (Error err) { return new STAFResult( STAFResult.ServiceConfigurationError, "This service requires STAF Version " + kRequiredSTAFVersion + " or later."); } if (info.serviceJar != null) { // Create the Jython Library directory if it doesn't exist yet // from the jython library data in the service's jarfile. // Set the classpath to point to the service's jar file and to // the jython.jar. res = STAFServiceSharedJython.setupJython( info.serviceJar, fHandle, info.writeLocation); if (res.rc != 0) { System.out.println(res.result); return res; } // Get the version of Jython distributed with the Cron service fJythonVersion = STAFServiceSharedJython.getJythonVersion(); // Initialize the PythonInterpreter's python.home to point to the // shared jython installation. Properties p = new Properties(); p.setProperty("python.home", STAFServiceSharedJython.getJythonDirName()); PythonInterpreter.initialize(System.getProperties(), p, null); } // instantiate parsers as not case sensitive fRegisterParser = new STAFCommandParser(0, false); fListParser = new STAFCommandParser(0, false); fTriggerParser = new STAFCommandParser(0, false); fUnregisterParser = new STAFCommandParser(0, false); fVersionParser = new STAFCommandParser(0, false); fRegisterParser.addOption("REGISTER", 1, STAFCommandParser.VALUENOTALLOWED); fRegisterParser.addOption("DESCRIPTION", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("MACHINE", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("PYTHONMACHINE", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOptionGroup("MACHINE PYTHONMACHINE", 1, 1); fRegisterParser.addOption("SERVICE", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("PYTHONSERVICE", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOptionGroup("SERVICE PYTHONSERVICE", 1, 1); fRegisterParser.addOption("REQUEST", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("PYTHONREQUEST", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOptionGroup("REQUEST PYTHONREQUEST", 1, 1); fRegisterParser.addOption("PREPARE", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("MINUTE", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("HOUR", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("DAY", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("MONTH", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("WEEKDAY", 1, STAFCommandParser.VALUEREQUIRED); fRegisterParser.addOption("ONCE", 1, STAFCommandParser.VALUENOTALLOWED); // Require at least one time interval option to be specified fRegisterParser.addOptionGroup( "MINUTE HOUR DAY MONTH WEEKDAY", 1, 5); fUnregisterParser.addOption("UNREGISTER", 1, STAFCommandParser.VALUENOTALLOWED); fUnregisterParser.addOption("ID", 1, STAFCommandParser.VALUEREQUIRED); fUnregisterParser.addOptionNeed("UNREGISTER", "ID"); fListParser.addOption("LIST", 1, STAFCommandParser.VALUENOTALLOWED); fListParser.addOption("MACHINE", 1, STAFCommandParser.VALUEREQUIRED); fListParser.addOption("LONG", 1, STAFCommandParser.VALUENOTALLOWED); fListParser.addOption("SHORT", 1, STAFCommandParser.VALUENOTALLOWED); fListParser.addOptionGroup("LONG SHORT", 0, 1); fTriggerParser.addOption("TRIGGER", 1, STAFCommandParser.VALUENOTALLOWED); fTriggerParser.addOption("ID", 1, STAFCommandParser.VALUEREQUIRED); fTriggerParser.addOptionNeed("TRIGGER", "ID"); fTriggerParser.addOption("SCRIPT", 0, STAFCommandParser.VALUEREQUIRED); fVersionParser.addOption("VERSION", 1, STAFCommandParser.VALUENOTALLOWED); fVersionParser.addOption("JYTHON", 1, STAFCommandParser.VALUENOTALLOWED); fVersionParser.addOptionGroup("VERSION", 1, 1); fVersionParser.addOptionNeed("JYTHON", "VERSION"); fCronIDMapClass = new STAFMapClassDefinition( "STAF/Service/Cron/CronID"); fCronIDMapClass.addKey("cronID", "ID"); fCronIDMapClass.addKey("description", "Description"); fCronIDMapClass.setKeyProperty("description", "display-short-name", "Desc"); fCronIDMapClass.addKey("machine", "Machine"); fCronIDMapClass.addKey("service", "Service"); fCronIDMapClass.addKey("request", "Request"); fCronIDMapClass.addKey("minute", "Minute"); fCronIDMapClass.addKey("hour", "Hour"); fCronIDMapClass.addKey("dayOfMonth", "Day of Month"); fCronIDMapClass.setKeyProperty("dayOfMonth", "display-short-name", "Day"); fCronIDMapClass.addKey("month", "Month"); fCronIDMapClass.addKey("dayOfWeek", "Day of Week"); fCronIDMapClass.setKeyProperty("dayOfWeek", "display-short-name", "Weekday"); fCronIDMapClass.addKey("once", "Once"); fCronIDShortMapClass = new STAFMapClassDefinition( "STAF/Service/Cron/CronIDShort"); fCronIDShortMapClass.addKey("cronID", "ID"); fCronIDShortMapClass.addKey("description", "Description"); fCronIDShortMapClass.setKeyProperty("description", "display-short-name", "Desc"); fCronIDShortMapClass.addKey("machine", "Machine"); fCronIDShortMapClass.addKey("service", "Service"); fCronIDShortMapClass.addKey("request", "Request"); fCronIDLongMapClass = new STAFMapClassDefinition( "STAF/Service/Cron/CronIDLong"); fCronIDLongMapClass.addKey("cronID", "ID"); fCronIDLongMapClass.addKey("description", "Description"); fCronIDLongMapClass.addKey("machine", "Machine"); fCronIDLongMapClass.addKey("machineType", "Machine Type"); fCronIDLongMapClass.addKey("service", "Service"); fCronIDLongMapClass.addKey("serviceType", "Service Type"); fCronIDLongMapClass.addKey("request", "Request"); fCronIDLongMapClass.addKey("requestType","Request Type"); fCronIDLongMapClass.addKey("prepareScript", "Prepare Script"); fCronIDLongMapClass.addKey("minute", "Minute"); fCronIDLongMapClass.addKey("hour", "Hour"); fCronIDLongMapClass.addKey("dayOfMonth", "Day of Month"); fCronIDLongMapClass.addKey("month", "Month"); fCronIDLongMapClass.addKey("dayOfWeek", "Day of Week"); fCronIDLongMapClass.addKey("once", "Once"); // Construct map class for a TRIGGER request fTriggerMapClass = new STAFMapClassDefinition( "STAF/Service/Cron/Trigger"); fTriggerMapClass.addKey("machine", "Machine"); fTriggerMapClass.addKey("requestNumber", "Request Number"); // Resolve the file separator variable for the local machine res = STAFUtil.resolveInitVar("{STAF/Config/Sep/File}", fHandle); if (res.rc != STAFResult.Ok) return res; String fileSep = res.result; // Store data for the cron service in directory: // <STAF writeLocation>/service/<cron service name (lower-case)> fHashtableFileDirectory = info.writeLocation; if (!fHashtableFileDirectory.endsWith(fileSep)) { fHashtableFileDirectory += fileSep; } fHashtableFileDirectory = fHashtableFileDirectory + "service" + fileSep + fServiceName.toLowerCase(); File dir = new File(fHashtableFileDirectory); if (!dir.exists()) { dir.mkdirs(); } fHashtableFileName = fHashtableFileDirectory + fileSep + "cron.ser"; loadHashtable(); /* Register RCs with the HELP service */ rc = this.registerHelp(info.name); if (rc != STAFResult.Ok)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -