Package org.xadoop.servlet.actions.results

Examples of org.xadoop.servlet.actions.results.Failure


    // get required parameters
    PostRequest postReq = new PostRequest();
    try {
      postReq.parse(req, null, false);
    } catch (Exception e) {
      return new Failure(e.getMessage());
    }
    String username = postReq.getFormField(LoginPage.USERNAME);
    String enteredPw = postReq.getFormField(LoginPage.PASSWORD);
    if (username == null) {
      return new Failure("No username given.");
    }
    if (username.length() > 40) {
      return new Failure("Too long username entered.");
    }
    if (enteredPw == null) {
      return new Failure("No password given.");
    }

    // lookup user
    HttpSession session = req.getSession();
    ServletContext ctx = session.getServletContext();
    XadoopConfig config = (XadoopConfig) ctx.getAttribute(XadoopConstants.CTX_CONFIG);
    HashMap<String, String> userMap = config.getUserMap();
    String storedPw = userMap.get(username);
    if (storedPw != null) {
      if (storedPw.equals(enteredPw)) {

        // store login in session and return success (null)
        session.setAttribute(SessionAttrs.USERNAME, username);
        return new Success("");
      } else {
        return new Failure("Wrong password for user " + username + " entered.");
      }
    } else {
      return new Failure("Username does not exist.");
    }
  }
View Full Code Here


    // get required parameters
    PostRequest postReq = new PostRequest();
    try {
      postReq.parse(req, pathUploadDir, true);
    } catch (Exception e) {
      return new Failure(e.getMessage());
    }
    String xqueryengine = postReq.getFormField(XQueryMRPage.XMLPARSER);
    String querytext = postReq.getFormField(XQueryMRPage.QUERYTEXT);
    String streamingEnabled = postReq.getFormField(XQueryMRPage.STREAMING_SUPPORT);
    String datatext = postReq.getFormField(XQueryMRPage.DATATEXT);
    String dataExists = postReq.getFormField(XQueryMRPage.DATAEXISTS);
    String datafile = postReq.getFormField(XQueryMRPage.DATAFILE);
    String datapath = postReq.getFormField(XQueryMRPage.DATAPATH);
    String numTasksMapStr = postReq.getFormField(XQueryMRPage.NUMTASKSMAP);
    String numTasksRedStr = postReq.getFormField(XQueryMRPage.NUMTASKSRED);
   
    // execution directory
    Date now = new Date();
    String pathExecDir = pathUploadDir + execDirFormat.format(now) + "/";
    File execDir = new File(pathExecDir);
    execDir.mkdir();

    // query
    if (querytext.trim().length() > 0) {
      File queryFile = new File(pathExecDir + FILENAME_QUERY);
      try {
        FileWriter writer = new FileWriter(queryFile);
        writer.write(querytext);
        writer.close();
      } catch (IOException e) {
        return new Failure("Failure writing query file: " + e.getMessage());
      }
    }

    // data
    // if text is given use text,
    // otherwise test if path to file is given,
    // otherwise test for a given file
    if (datatext.trim().length() > 0) {
      File dataFile = new File(pathExecDir + FILENAME_DATA);
      try {
        FileWriter writer = new FileWriter(dataFile);
        writer.write(datatext);
        writer.close();
      } catch (IOException e) {
        return new Failure("Failure writing data file: " + e.getMessage());
      }
    //if path to input data is given
    } else if (datapath.trim().length() > 0) {
      //if the data does not yet exist in the system
      if (!dataExists.equals("true")) {
        Runtime rt = Runtime.getRuntime();
        try {
          //create a symbolic link
          rt.exec("ln -s "+datapath.trim()+" "+pathExecDir+FILENAME_DATA);
        } catch (IOException e) {
          System.err.println(e.getMessage());
        }
      }
    //if input file is provided via browser mask
    } else if (datafile != null) {
      File dataFileOrg = new File(pathUploadDir + datafile);
      File dataFileDst = new File(pathExecDir + FILENAME_DATA);
      if (!dataFileOrg.renameTo(dataFileDst)) {
        return new Failure("Could not move data file to execution directory.");
      }
    } else if (dataExists.equals("false")) {
      return new Failure("No data given.");
    }

    // number of tasks
    int numTasksMap = 1;
    int numTasksReduce = 1;
    if (numTasksMapStr != null) {
      try {
        numTasksMap = Integer.parseInt(numTasksMapStr);
      } catch (Exception e) {
      }
    }
    if (numTasksRedStr == null) {
      numTasksReduce = numTasksMap;
    } else {
      try {
        numTasksReduce = Integer.parseInt(numTasksRedStr);
      } catch (Exception e) {
      }
    }

    // conf file
    Pipeline pipeline = null;
    HadoopConfFile confFileObj = null;
    if (xqueryengine.equals("zorba")) {
      pipeline = new Pipeline(querytext, XadoopConstants.PIPELINE_MAPPREFIX);
      XQueryMRZorbaConfFile confFileObjTmp = new XQueryMRZorbaConfFile(config);
      confFileObjTmp.setPipeline(pipeline.toString());
      System.out.println(pipeline.toString());
      confFileObjTmp.setQueryFile("/" + FILENAME_QUERY);
      confFileObj = confFileObjTmp;
    } else if (xqueryengine.equals("saxon")){
      pipeline = new Pipeline(querytext, XadoopConstants.SAXON_PIPELINE_MAPPREFIX);
      XQueryMRSaxonConfFile confFileObjTmp = new XQueryMRSaxonConfFile(config);
      confFileObjTmp.setPipeline(pipeline.toString());
      confFileObjTmp.setProlog("/" + FILENAME_QUERY);
     
      confFileObjTmp.setStreamEnabled(streamingEnabled);
     
      confFileObj = confFileObjTmp;
    } else {
      pipeline = new Pipeline(querytext, XadoopConstants.XQUERYMR_PIPELINE_MAPPREFIX);
      XQueryMRConfFile confFileObjTmp = new XQueryMRConfFile();
      confFileObjTmp.setPipeline(pipeline.toString());
      confFileObjTmp.setProlog("/" + FILENAME_QUERY);
      confFileObj = confFileObjTmp;
    }
   
    int numMapTasks = numTasksMap;
    int numReduceTasks = numTasksReduce;
    confFileObj.setMapredMapTasks(numMapTasks);
    confFileObj.setMapredReduceTasks(numReduceTasks);
    File confFile = new File(pathExecDir + FILENAME_CONF);
    try {
      FileWriter writer = new FileWriter(confFile);
      writer.write(confFileObj.toXml());
      writer.close();
    } catch (IOException e) {
      return new Failure("Failure writing conf file: " + e.getMessage());
    }

    // commands
    String pathJar = null;
    if (xqueryengine.equals("zorba")) {
View Full Code Here

TOP

Related Classes of org.xadoop.servlet.actions.results.Failure

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.