コード例 #1
0
ファイル: DataStorageCmd.java プロジェクト: dudzislaw/SORCER
  private void printRecord(Uuid id, Store type) throws RemoteException, MonitorException {
    Exertion xrt = null;
    if (selectedDataStorer >= 0) {
      xrt =
          ((MonitorUIManagement) dataStorers[selectedDataStorer].service)
              .getMonitorableExertion(id, NetworkShell.getPrincipal());
    } else {
      xrt =
          ((MonitorUIManagement) dataStorerMap.get(id).service)
              .getMonitorableExertion(id, NetworkShell.getPrincipal());
    }

    out.println("--------- STORAGE RECORD # " + selectedRecord + " ---------");
    out.println(((ServiceExertion) xrt).describe());
  }
コード例 #2
0
ファイル: DirCmd.java プロジェクト: mwsobol/iGrid
 public static boolean changeDir(String dirName, boolean echoSuccess, PrintStream out)
     throws Throwable {
   boolean changed = false;
   if (dirName.startsWith("..")) {
     dirName =
         NetworkShell.getInstance().getCurrentDir().getAbsolutePath() + File.separator + dirName;
   }
   if (dirName.equals("~")) {
     dirName = NetworkShell.getInstance().getHomeDir();
   }
   /* See if the passed in property is a complete directory */
   File dir = new File(dirName);
   /* If its not, it may be a relative path */
   if (!dir.exists()) {
     dir =
         new File(
             NetworkShell.getInstance().getCurrentDir().getAbsolutePath()
                 + File.separator
                 + dirName);
     if (!dir.exists()) {
       out.println(dirName + ": No such file or directory");
     }
   }
   if (dir.isDirectory()) {
     try {
       NetworkShell.getInstance().setCurrentDir(dir.getCanonicalFile());
       if (echoSuccess) {
         out.println("Command successful " + dir.getCanonicalPath());
       }
     } catch (IOException e) {
       e.printStackTrace();
     }
     changed = true;
   } else {
     out.println(dirName + ": Not a directory");
   }
   return (changed);
 }
コード例 #3
0
ファイル: DataStorageCmd.java プロジェクト: dudzislaw/SORCER
  public void execute() throws RemoteException, MonitorException {
    out = NetworkShell.getShellOutputStream();
    WhitespaceTokenizer myTk = NetworkShell.getShellTokenizer();
    int numTokens = myTk.countTokens();
    int myIdx = 0;
    String next = null;
    Store storeType = null;

    if (numTokens == 0) {
      printStorageServices();
      return;
    } else if (numTokens == 1) {
      next = myTk.nextToken();
      if (next.equals("-v")) {
        if (selectedDataStorer >= 0) {
          describeStorer(selectedDataStorer);
        } else out.println("No selected data storage");
        return;
      } else if (next.equals("-l")) {
        printRecords(Store.all);
      } else if (next.equals("-s")) {
        showStorageServices();
        selectedDataStorer = -1;
        // remove storage selection
      } else if (next.equals("-x")) {
        selectedDataStorer = -1;
      } else if (next.equals("-r")) {
        if (selectedRecord >= 0) {
          ObjectInfo recordInfo = recordInfos[selectedRecord];
          //					printRecord(recordInfo.uuid, recordInfo.type);
        }
      } else {
        try {
          myIdx = Integer.parseInt(next);
          selectedRecord = myIdx;
        } catch (NumberFormatException e) {
          selectedRecord = selectRecordByName(next);
        }
        if (selectedRecord < 0 || selectedRecord >= recordInfos.length)
          out.println("No such REcord for: " + next);
        else out.println(recordInfos[selectedRecord]);
      }
    } else if (numTokens == 2) {
      next = myTk.nextToken();
      if (next.equals("-s")) {
        try {
          next = myTk.nextToken();
          myIdx = Integer.parseInt(next);
          selectedDataStorer = myIdx;
        } catch (NumberFormatException e) {
          selectedDataStorer = selectMonitorByName(next);
          if (selectedDataStorer < 0) out.println("No such data storage for: " + next);
        }
        if (selectedDataStorer >= 0) {
          describeStorer(selectedDataStorer, "SELECTED");
        } else {
          out.println("No such data storage for: " + selectedDataStorer);
        }
        return;
      } else if (next.equals("-l")) {
        try {
          next = myTk.nextToken();
          myIdx = Integer.parseInt(next);
          selectedRecord = myIdx;
        } catch (NumberFormatException e) {
          selectedRecord = selectRecordByName(next);
          if (selectedRecord < 0) out.println("No such Record for: " + next);
        }
        if (selectedRecord >= 0 && selectedRecord < recordInfos.length) {
          ObjectInfo recordInfo = recordInfos[selectedRecord];
          //					printRecord(recordInfo.uuid, recordInfo.type);
        } else out.println("No such Record for: " + selectedRecord);
      }
    } else {
      out.println(COMMAND_USAGE);
      return;
    }
  }
コード例 #4
0
ファイル: DirCmd.java プロジェクト: mwsobol/iGrid
  public void execute() throws Throwable {
    NetworkShell shell = NetworkShell.getInstance();
    BufferedReader br = NetworkShell.getShellInputStream();
    out = NetworkShell.getShellOutputStream();
    input = shell.getCmd();
    if (out == null) throw new NullPointerException("Must have an output PrintStream");
    if (input.startsWith("ls") || input.startsWith("dir")) {
      File d = NetworkShell.getInstance().getCurrentDir();
      boolean details = false;
      StringTokenizer tok = new StringTokenizer(input);
      if (tok.countTokens() > 1) {
        /* First token is "ls" */
        tok.nextToken();
        String option = tok.nextToken();

        // list the content of the CatalogercatalogInfo
        if (option.equals("--c")) {
          catalogInfo();
          return;
        } else if (option.equals("--p")) {
          listCatalog();
          return;
        }

        if (option.equals("-l")) details = true;
        else {
          File temp = new File(d + File.separator + option);
          if (temp.isDirectory()) {
            d = temp;
          } else {
            out.println("Bad option " + option);
            return;
          }
        }
      }
      File[] files = d.listFiles();
      if (files == null) {
        String path = NetworkShell.getInstance().getCurrentDir().getAbsolutePath();
        try {
          path = NetworkShell.getInstance().getCurrentDir().getCanonicalPath();
        } catch (IOException e) {
          /* ignore */
        }
        out.println("No files for current working directory \"" + path + "\"");
        return;
      }
      int sum = 0;
      for (File file : files) {
        sum += file.length();
      }

      out.println("total " + sum);
      File parent = d.getParentFile();
      if (parent != null && details) {
        Date fileDate = new Date(parent.lastModified());
        out.println(
            getPerms(parent) + "   " + parent.length() + "\t" + fileDate.toString() + "\t" + "..");
      }
      for (File file : files) {
        if (details) {
          String tabs = "\t";
          if (file.length() < 10) tabs = tabs + "\t";
          String perms = getPerms(file);
          Date fileDate = new Date(file.lastModified());
          out.println(
              perms + "   " + file.length() + tabs + fileDate.toString() + "\t" + file.getName());
        } else {
          out.println(file.getName());
        }
      }
    } else if (input.equals("pwd")) {
      try {
        out.println(
            "\""
                + NetworkShell.getInstance().getCurrentDir().getCanonicalPath()
                + "\" "
                + "is the current working directory");
      } catch (IOException e) {
        out.println(
            "\""
                + NetworkShell.getInstance().getCurrentDir().getAbsolutePath()
                + "\" "
                + "is the current working directory");
      }
    } else {
      StringTokenizer tok = new StringTokenizer(input);
      if (tok.countTokens() > 1) {
        /* First token is "cd" */
        tok.nextToken();
        String value = tok.nextToken();
        if (!value.endsWith("*")) changeDir(value, out);
      } else {
        out.print("(enter a directory to change to) ");
        try {
          String response = br.readLine();
          if (response.length() == 0) {
            out.println("usage: cd directory");
          } else {
            changeDir(response, out);
          }
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
    return;
  }