You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nutch.apache.org by le...@apache.org on 2014/06/26 02:44:44 UTC

svn commit: r1605644 [2/2] - in /nutch/branches/2.x: ./ ivy/ src/java/org/apache/nutch/api/ src/java/org/apache/nutch/api/impl/ src/java/org/apache/nutch/api/impl/db/ src/java/org/apache/nutch/api/misc/ src/java/org/apache/nutch/api/model/ src/java/org...

Added: nutch/branches/2.x/src/java/org/apache/nutch/api/resources/JobResource.java
URL: http://svn.apache.org/viewvc/nutch/branches/2.x/src/java/org/apache/nutch/api/resources/JobResource.java?rev=1605644&view=auto
==============================================================================
--- nutch/branches/2.x/src/java/org/apache/nutch/api/resources/JobResource.java (added)
+++ nutch/branches/2.x/src/java/org/apache/nutch/api/resources/JobResource.java Thu Jun 26 00:44:43 2014
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package org.apache.nutch.api.resources;
+
+import java.util.Collection;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+
+import org.apache.nutch.api.model.request.JobConfig;
+import org.apache.nutch.api.model.response.JobInfo;
+import org.apache.nutch.api.model.response.JobInfo.State;
+
+@Path(value = "/job")
+public class JobResource extends AbstractResource {
+
+  @GET
+  @Path(value = "/")
+  public Collection<JobInfo> getJobs(@QueryParam("crawlId") String crawlId) {
+    return jobManager.list(crawlId, State.ANY);
+  }
+
+  @GET
+  @Path(value = "/{id}")
+  public JobInfo getInfo(@PathParam("id") String id,
+      @QueryParam("crawlId") String crawlId) {
+    return jobManager.get(crawlId, id);
+  }
+
+  @GET
+  @Path(value = "/{id}/stop")
+  public boolean stop(@PathParam("id") String id,
+      @QueryParam("crawlId") String crawlId) {
+    return jobManager.stop(crawlId, id);
+  }
+
+  @GET
+  @Path(value = "/{id}/abort")
+  public boolean abort(@PathParam("id") String id,
+      @QueryParam("crawlId") String crawlId) {
+    return jobManager.abort(crawlId, id);
+  }
+
+  @POST
+  @Path(value = "/create")
+  @Consumes(MediaType.APPLICATION_JSON)
+  public String create(JobConfig config) {
+    if (config == null) {
+      throwBadRequestException("Job configuration is required!");
+    }
+    return jobManager.create(config);
+  }
+}