Package com.ikanow.infinit.e.data_model.api.ResponsePojo

Examples of com.ikanow.infinit.e.data_model.api.ResponsePojo.ResponseObject


         
          if (tryToKillJob) {
            // (ie is running and updating it to mean don't run anymore .. that 4e12 number is 2099 in ms, anything bigger than that is assumed to mean "don't run)
            CustomProcessingController pxController = new CustomProcessingController();
            if (pxController.killRunningJob(cmr)) {           
              rp.setResponse(new ResponseObject("Update MapReduce Job",true,"Killed job, may take a few moments for the status to update."));
            }
            else {
              rp.setResponse(new ResponseObject("Update MapReduce Job",false,"Failed to kill the job - it may not have started yet, try again in a few moments."));
            }             
            return rp;
          }//TODO (INF-2395): TOTEST
          else {
            rp.setResponse(new ResponseObject("Update MapReduce Job",false,"Job is currently running (or not yet marked as completed).  Please wait until the job completes to update it."));
            return rp;
          }
        }
        if (cmr.jobidS != null) { // (must be checking completion, ie in bug state, so reset...)
          cmr.jobidS = null;
          cmr.jobidN = 0;
        }
        //check each variable to see if its needs/can be updated
        if ( (null != communityIds) && !communityIds.equals("null") )
        {
          List<ObjectId> commids = new ArrayList<ObjectId>();
          for ( String s : communityIds.split(","))
            commids.add(new ObjectId(s));
          boolean bAdmin = RESTTools.adminLookup(userid);
          //make sure user is allowed to submit on behalf of the commids given
          if ( bAdmin || isInAllCommunities(commids, userid) )
          {
            ElasticSearchManager customIndex = CustomOutputIndexingEngine.getExistingIndex(cmr);
            if (null != customIndex) {
              CustomOutputIndexingEngine.swapAliases(customIndex, commids, true)
            }//TESTED (by hand - removal and deletion)           
           
            cmr.communityIds = commids;
          }
          else
          {
            rp.setResponse(new ResponseObject("Update MapReduce Job",false,"You do have permissions for all the communities given."));
            return rp;
          }
        }
        if ( (null != inputColl) && !inputColl.equals("null"))
        {
          //make sure user can use the input collection
          String inputCollection = getStandardInputCollection(inputColl);     
          if ( inputCollection != null )
          {
            cmr.isCustomTable = false;
          }
          else
          {
            inputCollection = getCustomInputCollection(inputColl, cmr.communityIds);
            cmr.isCustomTable = true;
          }
          if ( inputCollection != null)
          {
            cmr.inputCollection = inputCollection;
          }
          else
          {
            rp.setResponse(new ResponseObject("Update MapReduce Job",false,"You do not have permission to use the given input collection."));
            return rp;
          }
        }
        try
        {
          if ( (null != title) && !title.equals("null"))
          {
            // If this is indexed then can't change the title
            if (null != CustomOutputIndexingEngine.getExistingIndex(cmr)) {
              rp.setResponse(new ResponseObject("Update MapReduce Job",false,"You cannot change the title of a non-empty indexed job - you can turn indexing off and then change the title"));
              return rp;             
            }//TESTED (by hand)
           
            cmr.jobtitle = title;
            //make sure the new title hasn't been used before
            DBObject dbo1 = DbManager.getCustom().getLookup().findOne(new BasicDBObject("jobtitle",title));
            if ( dbo1 != null )
            {
              rp.setResponse(new ResponseObject("Update MapReduce Job",false,"A job already matches that title, please choose another title"));
              return rp;
            }
          }
          if ( (null != desc) && !desc.equals("null"))
          {
            cmr.jobdesc = desc;
          }
          if ( (null != jarURL) && !jarURL.equals("null"))
          {
            cmr.jarURL = jarURL;
          }
          if ( (null != nextRunTime) && !nextRunTime.equals("null"))
          {
            cmr.nextRunTime = Long.parseLong(nextRunTime);
            long nNow = new Date().getTime();
            cmr.firstSchedule = new Date(cmr.nextRunTime);
            if (cmr.nextRunTime < nNow) { // ie leave firstSchedule alone since that affects when we next run, but just set this to now...
              cmr.nextRunTime = nNow - 1;
            }//TESTED
            cmr.timesRan = 0;
            cmr.timesFailed = 0;
          }
          if ( (null != schedFreq) && !schedFreq.equals("null"))
          {
            cmr.scheduleFreq = SCHEDULE_FREQUENCY.valueOf(schedFreq);
          }
          if ( (null != mapperClass) && !mapperClass.equals("null"))
          {
            cmr.mapper = mapperClass;
          }
          if ( (null != reducerClass) && !reducerClass.equals("null"))
          {
            cmr.reducer = reducerClass;
          }
          if ( (null != combinerClass) && !combinerClass.equals("null"))
          {
            cmr.combiner = combinerClass;
          }
          if ( (null != query) && !query.equals("null"))
          {
            boolean wasIndexed = CustomOutputIndexingEngine.isIndexed(cmr);
           
            if ( !query.isEmpty() )
              cmr.query = query;
            else
              cmr.query = "{}";
           
            // If we're in indexing mode, check if the index has been turned off, in which case delete the index
            if (wasIndexed && !CustomOutputIndexingEngine.isIndexed(cmr)) {
              CustomOutputIndexingEngine.deleteOutput(cmr)
            }//TESTED (by hand)
          }
          if (null == cmr.jarURL) { // (if in savedQuery mode, force types to be Text/BSONWritable)
            // Force the types:
            outputKey = "org.apache.hadoop.io.Text";
            outputValue = "com.mongodb.hadoop.io.BSONWritable";           
          }
          if ( (null != outputKey) && !outputKey.equals("null"))
          {
            cmr.outputKey = outputKey;
          }
          if ( (null != outputValue) && !outputValue.equals("null"))
          {
            cmr.outputValue = outputValue;
          }
          if ( (null != appendResults) && !appendResults.equals("null"))
          {
            try
            {
              cmr.appendResults = Boolean.parseBoolean(appendResults);
            }
            catch (Exception ex)
            {
              cmr.appendResults = false;
            }
          }
          if ( (null != ageOutInDays) && !ageOutInDays.equals("null"))
          {
            try
            {
              cmr.appendAgeOutInDays = Double.parseDouble(ageOutInDays);
            }
            catch (Exception ex)
            {
              cmr.appendAgeOutInDays = 0.0;
            }
          }
          if (null != incrementalMode)
          {
            cmr.incrementalMode = incrementalMode;
          }
          if (null != selfMerge)
          {
            cmr.selfMerge = selfMerge;
          }
         
          if (null != exportToHdfs) {
            cmr.exportToHdfs = exportToHdfs;
          }
         
          //try to work out dependencies, error out if they fail
          if ( (null != jobsToDependOn) && !jobsToDependOn.equals("null"))
          {
            try
            {
              cmr.jobDependencies = getJobDependencies(jobsToDependOn);
              cmr.waitingOn = cmr.jobDependencies;
            }
            catch (Exception ex)
            {
              rp.setResponse(new ResponseObject("Update MapReduce Job",false,"Error parsing the job dependencies, did a title or id get set incorrectly or did a job not exist?"));
              return rp;
            }
          }
          if ( json != null && !json.equals("null"))
          {
            cmr.arguments = json;
          }
          else
          {
            cmr.arguments = null;
          }
          if ((null == cmr.jarURL) && (null != cmr.arguments) && !cmr.arguments.isEmpty()) {
            // In saved query, if arguments is valid BSON then copy over query
            try {
              Object tmpQuery = com.mongodb.util.JSON.parse(cmr.arguments);
              if (tmpQuery instanceof BasicDBObject) {
                cmr.query = cmr.arguments;
              }
            }
            catch (Exception e) {} // fine just carry on
          }
          else if ((null == cmr.jarURL)) { // ie args == null, copy from query
            cmr.arguments = cmr.query;
          }
         
        }
        catch (IllegalArgumentException e)
        {
          // If an exception occurs log the error
          logger.error("Exception Message: " + e.getMessage(), e);
          rp.setResponse(new ResponseObject("Update MapReduce Job",false,"Illegal arg (enum needs to be DAILY/WEEKLY/MONTHLY/NONE?): " + e.getMessage()));
          return rp;
        }
        catch (Exception e)
        {
          // If an exception occurs log the error
          logger.error("Exception Message: " + e.getMessage(), e);
          rp.setResponse(new ResponseObject("Update MapReduce Job",false,"error scheduling job: " + e.getMessage()));
          return rp;
        }

        // Setup post-processing
       
        String nextRunString = new Date(cmr.nextRunTime).toString();
        boolean bRunNowIfPossible = false;
        if ( cmr.nextRunTime < new Date().getTime() ) {
          nextRunString = "next available timeslot";
          bRunNowIfPossible = true;
        }
       
        rp.setResponse(new ResponseObject("Update MapReduce Job",true,"Job updated successfully, will run on: " + nextRunString));
        rp.setData(cmr._id.toString(), null);

        if (bRunNowIfPossible) {
          runJobAndWaitForCompletion(cmr, bQuickRun);
        }//TESTED
        else {
          DbManager.getCustom().getLookup().save(cmr.toDb());         
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Update MapReduce Job", false, "You do not have permission to submit this job"));
      }
    }
    else
    {
      rp.setResponse(new ResponseObject("Update MapReduce Job", false, "No jobs with this ID exist"));
    }
    return rp;
  }
View Full Code Here


            }
          }
        }
        DBCursor dbc = DbManager.getCustom().getLookup().find(commquery);   
        if ((0 == dbc.count()) && (null != jobIdOrTitle)) {
          rp.setResponse(new ResponseObject("Custom Map Reduce Get Jobs",false,"No jobs to find"));         
        }
        else {
          rp.setResponse(new ResponseObject("Custom Map Reduce Get Jobs",true,"succesfully returned jobs"));
          List<CustomMapReduceJobPojo> jobs = CustomMapReduceJobPojo.listFromDb(dbc, CustomMapReduceJobPojo.listType());
          // Extra bit of code, need to eliminate partial community matches, eg if job belongs to A,B and we only belong to A
          // then obviously we can't see the job since it contains data from B
          Iterator<CustomMapReduceJobPojo> jobsIt = jobs.iterator();
          while (jobsIt.hasNext()) {
            CustomMapReduceJobPojo job = jobsIt.next();
            if (!communities.containsAll(job.communityIds)) {
              jobsIt.remove();
            }
          }//TOTEST
          rp.setData(jobs, new CustomMapReduceJobPojoApiMap(communities));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Custom Map Reduce Get Jobs",false,"error retrieving users communities"));
      }     
    }
    catch (Exception e)
    {
      // If an exception occurs log the error
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Custom Map Reduce Get Jobs",false,"error retrieving jobs"));
    }
    return rp;
  }
View Full Code Here

            if ( removeJar )
            {
              ResponsePojo sharerp = removeJarFile(cmr.jarURL, cmr.submitterID.toString());
              if ( sharerp.getResponse().isSuccess() )
              {
                rp.setResponse(new ResponseObject("Remove Custom Map Reduce Job",true,"Job, results, and jar removed successfully."));
              }
              else
              {
                rp.setResponse(new ResponseObject("Remove Custom Map Reduce Job",true,"Job and results removed successfully.  Removing the jar had an error: " + sharerp.getResponse().getMessage()));
              }
            }
            else
            {
              rp.setResponse(new ResponseObject("Remove Custom Map Reduce Job",true,"Job and results removed successfully.  Manually remove the jar if you are done with it."));
            }
          }
          else
          {
            rp.setResponse(new ResponseObject("Remove Custom Map Reduce Job",false,"Job is currently running (or not yet marked as completed).  Please wait until the job completes to update it."));
          }
        }
        else
        {
          rp.setResponse(new ResponseObject("Remove Custom Map Reduce Job",false,"User must have submitter or admin permissions to remove jobs"));
        }
      }
      else
      {
        rp.setResponse(new ResponseObject("Remove Custom Map Reduce Job",false,"Job does not exist"));
      }
    }
    catch (Exception e)
    {
      // If an exception occurs log the error
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Remove Custom Map Reduce Job",false,"error retrieving job info"));
    }
    return rp;
  }
View Full Code Here

        //remove the jar
        return new ShareHandler().removeShare(ownerid, jarid);
      }
      else
      {
        return new ResponsePojo(new ResponseObject("removejar", false, "More than 1 job use this jar, could not remove."));
      }
    }
    return new ResponsePojo(new ResponseObject("removejar", false, "Jar URL is not an infinite share, could not remove."));
  }
View Full Code Here

     {
       cookieLookup = RESTTools.cookieLookup(cookie);
       if ( cookieLookup == null )
       {
         rp = new ResponsePojo();
         rp.setResponse(new ResponseObject("Cookie Lookup",false,"Cookie session expired or never existed, please login first"));
       }
       else
       {
         if ( action.equals("getresults") )
         {
           rp = this.customhandler.getJobResults(cookieLookup, jobid, limit, json, findStr, sortStr);
         }
         else if ( action.equals("schedule"))
         {
           rp = this.customhandler.scheduleJob(cookieLookup, title, desc, communityIds, jarURL, nextRunTime, freqSched, mapperClass, reducerClass, combinerClass, query, inputColl, outputKey, outputValue,appendResults,ageOutInDays,jsonPojo.incrementalMode,jobsToDependOn,jsonPojo.arguments, jsonPojo.exportToHdfs, bQuickRun, jsonPojo.selfMerge);
         }
         else if ( action.equals("update") )
         {
           rp = this.customhandler.updateJob(cookieLookup, (jobid==null)?(title):(jobid), title, desc, communityIds, jarURL, nextRunTime, freqSched, mapperClass, reducerClass, combinerClass, query, inputColl, outputKey, outputValue,appendResults,ageOutInDays,jsonPojo.incrementalMode,jobsToDependOn,jsonPojo.arguments, jsonPojo.exportToHdfs, bQuickRun, jsonPojo.selfMerge);
         }
         else if ( action.equals("getjobs"))
         {
           rp = this.customhandler.getJobOrJobs(cookieLookup, jobid);
         }
         else if ( action.equals("removejob") )
         {
           rp = CustomHandler.removeJob(cookieLookup, jobid, shouldRemoveJar, false);
         }
         else if (action.equals("failed")) {
           rp.setResponse(new ResponseObject("Schedule/Update MapReduce Job", false, "Failed to parse POSTed content"));
         }
       }      
     }    
     else
     {
View Full Code Here

        } catch (InterruptedException e) {
          //(that's fine just carry on)
          lockAcquired = false;
        }
        if (!lockAcquired) {
          rp.setResponse(new ResponseObject("Query", false, "Query engine busy, please try again later."));
          return rp;
        }
       
        scoreStats.setAliasLookupTable(_aliasLookup);
        docs = scoreStats.calcTFIDFAndFilter(DbManager.getDocument().getMetadata(),
                              docs0, query.score, query.output, stats, bLowAccuracyDecay,
                                nRecordsToSkip, nRecordsToOutput,
                                  communityIdStrs,
                                  tempFilterInfo.entityTypeFilterStrings, tempFilterInfo.assocVerbFilterStrings,
                                  standaloneEvents,
                                  lowAccuracyAggregatedEntities,
                                  lowAccuracyAggregatedGeo, extraAliasAggregatedGeo,
                                          lowAccuracyAggregatedEvents, lowAccuracyAggregatedFacts);
      }
      finally {
        scoreStats.clearAsMuchMemoryAsPossible();
        this.releaseConcurrentAccessLock();
      }     
      nProcTime += (System.currentTimeMillis() - nProcTime_tmp);
    }
    else {
      nMongoTime = 0;
    }
    //TESTED (all queries)
   
  // 0.9] Output:

    rp.setResponse(new ResponseObject("Query", true, querySummary.toString()));
   
    // 0.9.1] Stats:
    stats.resetArrays();
    rp.setStats(stats); // (only actually uses the response pojo, but get rid of big fields anyway...)
View Full Code Here

          } catch (InterruptedException e) {
            //(that's fine just carry on)
            lockAcquired = false;
          }
          if (!lockAcquired) {
            rp.setResponse(new ResponseObject("Query", false, "Query engine busy, please try again later."));
            return rp;
          }
          scoreStats.setAliasLookupTable(_aliasLookup);
          docs = scoreStats.calcTFIDFAndFilter(DbManager.getDocument().getMetadata(),
                              dbc, query.score, query.output, stats, false,
                              query.output.docs.skip, query.output.docs.numReturn,
                                    communityIdStrs,
                                    null, null,
                                    null,
                                    null,
                                    null, null,
                                    null, null);
        }
        finally {
          scoreStats.clearAsMuchMemoryAsPossible();
          this.releaseConcurrentAccessLock();
        }
        rp = new ResponsePojo();
        rp.setResponse(new ResponseObject("Query", true, "Saved Query: " + share.getTitle()));
        rp.setStats(stats);
        if ((null != docs) && (docs.size() > 0)) {
          rp.setData(docs, (BasePojoApiMap<BasicDBObject>)null);
        }
        else { // (ensure there's always an empty list)
View Full Code Here

   */
  public ResponsePojo getPerson(String id, Boolean isPublicRequest)
  {
    //TODO (INF-502): there is no public vs private currently
    if ( isPublicRequest )
      return new ResponsePojo(new ResponseObject("Person Info",false,"There is no public get person info call currently, coming soon!"));
   
   
    ResponsePojo rp = new ResponsePojo();
   
    try
    {
      // Set up the query
      PersonPojo personQuery = new PersonPojo();
      try {
        personQuery.set_id(new ObjectId(id));
      }
      catch (Exception e) { // Not an id, try email
        personQuery.setEmail(id);
      }
     
      BasicDBObject dbo = (BasicDBObject) DbManager.getSocial().getPerson().findOne(personQuery.toDb());
      PersonPojo person = PersonPojo.fromDb(dbo, PersonPojo.class);
     
      rp.setData(person, new PersonPojoApiMap());
      rp.setResponse(new ResponseObject("Person Info", true, "Person info returned successfully"))
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Person Info", false, "Error returning person info: " + e.getMessage()
          + " - " + e.getStackTrace().toString()));
    }
    return rp;
 
View Full Code Here

     
     
      if (dbc.count() > 0)
      {
        rp.setData(PersonPojo.listFromDb(dbc, PersonPojo.listType()), new PersonPojoApiMap());
        rp.setResponse(new ResponseObject("People List", true, "List returned successfully"));       
      }
      else
      {
        rp.setResponse(new ResponseObject("People List", true, "No list to return returned"))
      }
     
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Person List", false, "Error returning person list: " + e.getMessage()
          + " - " + e.getStackTrace().toString()));
    }
    return rp;
  }
View Full Code Here

      DBCursor dbc = DbManager.getSocial().getPerson().find();
     
      if (dbc.count() > 0)
      {
        rp.setData(PersonPojo.listFromDb(dbc, PersonPojo.listType()), new PersonPojoApiMap());
        rp.setResponse(new ResponseObject("People Info", true, "Info returned successfully"));       
      }
      else
      {
        rp.setResponse(new ResponseObject("People Info", true, "No info returned"))
      }
     
    }
    catch (Exception e)
    {
      logger.error("Exception Message: " + e.getMessage(), e);
      rp.setResponse(new ResponseObject("Person Info", false, "Error returning person info: " + e.getMessage()
          + " - " + e.getStackTrace().toString()));
    }
    return rp;
  }
View Full Code Here

TOP

Related Classes of com.ikanow.infinit.e.data_model.api.ResponsePojo.ResponseObject

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.