⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cronservice.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                resolvedValue = STAFUtil.resolveRequestVar(                    parsedRequest.optionValue("service"),                    fHandle, info.requestNumber);                if (resolvedValue.rc != 0) return resolvedValue;                service = resolvedValue.result;                pythonService = false;            }            else if (parsedRequest.optionTimes("pythonservice") > 0)            {                service = parsedRequest.optionValue("pythonservice");                pythonService = true;            }            if (parsedRequest.optionTimes("request") > 0)            {                resolvedValue = STAFUtil.resolveRequestVar(                    parsedRequest.optionValue("request"),                    fHandle, info.requestNumber);                if (resolvedValue.rc != 0) return resolvedValue;                request = resolvedValue.result;                pythonRequest = false;            }            else if (parsedRequest.optionTimes("pythonrequest") > 0)            {                request = parsedRequest.optionValue("pythonrequest");                pythonRequest = true;            }            if (parsedRequest.optionTimes("prepare") > 0)            {                prepare = parsedRequest.optionValue("prepare");            }            Vector minute = new Vector();            Vector hour = new Vector();            Vector day = new Vector();            Vector month = new Vector();            Vector weekday = new Vector();            if (parsedRequest.optionTimes(kMinute) > 0)            {                minute = cronParse(parsedRequest.optionValue(kMinute), kMinute);                if (minute == null)                {                    return new STAFResult(                        STAFResult.InvalidValue,                        "Invalid value for " + kMinute + ":  " +                        parsedRequest.optionValue(kMinute));                }            }            if (parsedRequest.optionTimes(kHour) > 0)            {                hour = cronParse(parsedRequest.optionValue(kHour), kHour);                if (hour == null)                {                    return new STAFResult(                        STAFResult.InvalidValue,                        "Invalid value for " + kHour + ":  " +                        parsedRequest.optionValue(kHour));                }            }            if (parsedRequest.optionTimes(kDay) > 0)            {                day = cronParse(parsedRequest.optionValue(kDay), kDay);                if (day == null)                {                    return new STAFResult(                        STAFResult.InvalidValue,                        "Invalid value for " + kDay + ":  " +                        parsedRequest.optionValue(kDay));                }            }            if (parsedRequest.optionTimes(kMonth) > 0)            {                month = cronParse(parsedRequest.optionValue(kMonth), kMonth);                if (month == null)                {                    return new STAFResult(                        STAFResult.InvalidValue,                        "Invalid value for " + kMonth + ":  " +                        parsedRequest.optionValue(kMonth));                }            }            if (parsedRequest.optionTimes(kWeekday) > 0)            {                weekday = cronParse(parsedRequest.optionValue(kWeekday),                                    kWeekday);                if (weekday == null)                {                    return new STAFResult(                        STAFResult.InvalidValue,                        "Invalid value for " + kWeekday + ":  " +                        parsedRequest.optionValue(kWeekday));                }            }            if (parsedRequest.optionTimes("once") > 0)            {                once = true;            }            if (!(prepare.equals("")) || pythonMachine || pythonService ||                pythonRequest)            {                // validate Python code                fPythonInterpreter = new PythonInterpreter();                                if (!(prepare.equals("")))                {                    try                    {                        compileForPython(prepare);                    }                    catch (PyException ex)                    {                        String msg = "Python code compile failed for the " +                            "PREPARE value:\n" + prepare +                            "\n\nPyException:\n" + ex;                        return new STAFResult(PYTHONERROR, msg);                    }                }                if (pythonMachine)                {                    try                    {                        compileForPython(machine);                    }                    catch (PyException ex)                    {                        String msg = "Python code compile failed for the " +                            "MACHINE value:\n" + machine +                            "\n\nPyException:\n" + ex;                            return new STAFResult(PYTHONERROR, msg);                    }                }                if (pythonService)                {                    try                    {                        compileForPython(service);                    }                    catch (PyException ex)                    {                        String msg = "Python code compile failed for the " +                            "SERVICE value:\n" + service +                            "\n\nPyException:\n" + ex;                            return new STAFResult(PYTHONERROR, msg);                    }                }                if (pythonRequest)                {                    try                    {                        compileForPython(request);                    }                    catch (PyException ex)                    {                        String msg = "Python code compile failed for the " +                            "REQUEST value:\n" + request +                            "\n\nPyException:\n" + ex;                            return new STAFResult(PYTHONERROR, msg);                    }                }            }            Integer index = new Integer(fCronID++);            fRegTable.put(                index,                (Object) new CronData1(description, originMachine, machine,                                       pythonMachine, service, pythonService,                                       request, pythonRequest, prepare, minute,                                       hour, day, month, weekday, once));            sResult = new STAFResult(STAFResult.Ok, index.toString());            saveHashtable();            String message = "[ID=" + index + "] [" + info.endpoint + ", " +                info.handleName +                "] Registered a STAF command.\nRegister request: " +                info.request;            fHandle.submit2(                "local", "LOG", "LOG MACHINE LOGNAME " +                fServiceName + " LEVEL info MESSAGE " +                STAFUtil.wrapData(message));        }        catch (Exception e)        {            if (DEBUG)            {                e.printStackTrace();            }            return new STAFResult(STAFResult.JavaError,                                  "Internal Java error.");        }        return sResult;    }    private STAFResult handleUnregister(        STAFServiceInterfaceLevel30.RequestInfo info)    {        STAFResult sResult = new STAFResult(STAFResult.Ok, "");        String service;        String request;        Integer id;        STAFResult resolvedResult = null;        STAFResult resolvedValue = null;        STAFCommandParseResult parsedRequest =            fUnregisterParser.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 4            STAFResult trustResult = STAFUtil.validateTrust(                4, fServiceName, "UNREGISTER", fLocalMachineName, info);            if (trustResult.rc != STAFResult.Ok) return trustResult;            // Process the request            resolvedValue = STAFUtil.resolveRequestVar(                parsedRequest.optionValue("id"), fHandle, info.requestNumber);            if (resolvedValue.rc != 0) return resolvedValue;                        id = new Integer(resolvedValue.result);            if (!fRegTable.containsKey(id))            {                return new STAFResult(STAFResult.DoesNotExist,                                      "ID " + id + " not found");            }            else            {                CronData1 data = (CronData1)fRegTable.get(id);                fRegTable.remove(id);                if (fRegTable.isEmpty())                {                    fCronID = 1;                }                saveHashtable();                String message = "[ID=" + id + "] [" + info.endpoint + ", " +                    info.handleName + "] Unregistered a STAF command.";                fHandle.submit2(                    "local", "LOG", "LOG MACHINE LOGNAME " +                    fServiceName + " level info message " +                    STAFUtil.wrapData(message));            }        }        catch (Exception e)        {            if (DEBUG)            {                e.printStackTrace();            }            return new STAFResult(                STAFResult.JavaError, "Internal Java error.");        }        return sResult;    }    private STAFResult handleVersion(        STAFServiceInterfaceLevel30.RequestInfo info)    {        // Verify the requester has at least trust level 1        STAFResult trustResult = STAFUtil.validateTrust(            1, fServiceName, "VERSION", fLocalMachineName, info);        if (trustResult.rc != STAFResult.Ok) return trustResult;        // Parse the request        STAFCommandParseResult parsedRequest = fVersionParser.parse(            info.request);        if (parsedRequest.rc != STAFResult.Ok)        {            return new STAFResult(STAFResult.InvalidRequestString,                                  parsedRequest.errorBuffer);        }        if (parsedRequest.optionTimes("JYTHON") == 0)        {            // Return the version of the service            return new STAFResult(STAFResult.Ok, kVersion);        }        else        {            // Return the version of Python packaged with the service            return new STAFResult(STAFResult.Ok, fJythonVersion);        }    }    private Vector cronParse(String msg, String type)    {        Vector result = new Vector();                if (msg.equalsIgnoreCase("ANY") || msg.equals("*"))        {            result.add("ANY");            return result;        }                        StringTokenizer options = new StringTokenizer(msg, ",");                    while (options.hasMoreElements())        {            String element = ((String)options.nextElement()).trim();                    // Check if a range was specified:  <start>-<end>            int firstDashIndex = element.indexOf("-");            if (firstDashIndex == -1)            {                // Single value specified.  Verify that it is valid.                                    if (!isValidValue(element, type))                    return null;                if (type.equals(kWeekday))                {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -