/** * Returns a Job by the provided sid. * * @param sid The sid for a job. * @return A Job. */ public Job getJob(String sid) { return new Job(this, JobCollection.REST_PATH + "/" + sid); }
/** * Returns an array of search jobs created from this saved search. * * @return An array of search jobs. */ public Job[] history() { ResponseMessage response = service.get(actionPath("history")); AtomFeed feed; try { feed = AtomFeed.parseStream(response.getContent()); } catch (Exception e) { throw new RuntimeException(e); } int count = feed.entries.size(); Job[] result = new Job[count]; for (int i = 0; i < count; ++i) { String sid = feed.entries.get(i).title; result[i] = new Job(service, JobCollection.REST_PATH + "/" + sid); } return result; }
/** * Creates a search. * <p> * <b>Note:</b> You can't create a "oneshot" search using this method. * Instead, use the {@link Service#oneshotSearch} method. * * @param query The search query. * @param args Additional arguments for this job (see {@link JobArgs}). * @return The unique search identifier (SID). */ public Job create(String query, Map args) { if (args != null && args.containsKey("exec_mode")) { if (args.get("exec_mode").equals("oneshot")) throw new RuntimeException(oneShotNotAllowed); } args = Args.create(args).add("search", query); ResponseMessage response = service.post(path, args); assert(response.getStatus() == 201); String sid = Xml.parse(response.getContent()) .getElementsByTagName("sid") .item(0) .getTextContent(); Job job = new Job(service, REST_PATH + "/" + sid); job.refresh(); return job; }
/** * Runs the saved search using dispatch arguments. * * @param args Dispatch arguments: <ul> * <li>"dispatch.now": A time string that is used to dispatch the search as * though the specified time were the current time.</li> * <li>"dispatch.*": Overwrites the value of the search field specified in * "*".</li> * <li>"trigger_actions": A Boolean that indicates whether to trigger alert * actions.</li> * <li>"force_dispatch": A Boolean that indicates whether to start a new * search if another instance of this search is already running.</li></ul> * @return The search job. */ public Job dispatch(Map args) throws InterruptedException { ResponseMessage response = service.post(actionPath("dispatch"), args); invalidate(); String sid = Job.getSid(response); Job job = service.getJob(sid); // if job not yet scheduled, create an empty job object if (job == null) { job = new Job(service, JobCollection.REST_PATH + "/" + sid); } return job; }