001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.search.admin.util;
007:
008: import java.util.*;
009: import java.io.*;
010: import java.lang.*;
011: import com.sun.portal.search.admin.CSConfig;
012: import com.sun.portal.search.util.SearchConfig;
013: import com.sun.portal.search.admin.cli.RunImportAgent;
014:
015: public class WinOSTask implements Task {
016: static {
017: System.loadLibrary("scheduleTask");
018: }
019:
020: static public void main(String[] args) {
021: if (args.length < 5) {
022: System.out.println("Usage:CronController action");
023: return;
024: }
025: CSConfig
026: .init("C:/Sun/PortalServer/https-YODA.india.sun.com/portal");
027: WinOSTask cron = new WinOSTask();
028: cron.init(args[0]);
029: cron.setValue(HOURS, args[2]);
030: cron.setValue(MINUTES, args[3]);
031: cron.setValue(DAYS_OF_WEEK, args[4]);
032: cron.Update();
033: }
034:
035: HashMap valuesMap = new HashMap();
036: String name = null;
037:
038: public WinOSTask() {
039: }
040:
041: public void init(String name) {
042: System.out.println("init:" + name);
043: this .name = name;
044:
045: boolean success = getScheduledTask(name, valuesMap);
046: if (success)
047: return;
048: String serverRootWinOSStyle = CSConfig.getServerRoot().replace(
049: '/', '\\');
050: String cmd = serverRootWinOSStyle + File.separator + name
051: + ".bat"; //For StartRobot and StopRobot only
052: if (name.compareTo("StartImport") == 0) {
053: String csid = SearchConfig.getSearchConfig().getValue(
054: SearchConfig.CSID);
055: cmd = serverRootWinOSStyle + File.separator
056: + "run-cs-cli.bat " + RunImportAgent.IMPORTMGR_CMD
057: + " -c " + "config\\" + SearchConfig.SEARCH_CONF
058: + " " + csid + " run all > logs" + File.separator
059: + "import.log";
060: }
061: setValue(COMMAND, cmd);
062: setValue(DIR, serverRootWinOSStyle);
063: }
064:
065: public void Remove() {
066: Update(true);
067: }
068:
069: public void Update() {
070: Update(false);
071: }
072:
073: private void Update(boolean isDelete) {
074: if (isDelete) {
075: System.out.println("Deleting task:" + name);
076: deleteScheduledTask(name);
077: } else {
078: System.out.println("Updating task:" + name);
079: scheduleTask(name, valuesMap);
080: }
081: }
082:
083: /**
084: * Find a configuration parameter
085: */
086: public String getValue(String param) {
087: return (String) valuesMap.get(param);
088: }
089:
090: /**
091: * sets a value in the cron
092: */
093: public void setValue(String key, String value) {
094: if (valuesMap != null) {
095: if (valuesMap.containsKey(key)) {
096: valuesMap.remove(key);
097: }
098: valuesMap.put(key, value);
099: }
100: }
101:
102: native static boolean scheduleTask(String taskName,
103: HashMap valuesMap);
104:
105: native static boolean getScheduledTask(String taskName,
106: HashMap valuesMap);
107:
108: native static boolean deleteScheduledTask(String taskName);
109: }
|