Apache Nutch is an extensible and scalable web crawler
Fix for NUTCH-1966 Configuration endpoint for 1x REST API contributed by Sujen Shah <[email protected]> this closes #13.
Chris Mattmann4732de9103a1
diff --git a/CHANGES.txt b/CHANGES.txtindex 05f60730e..83d2298a2 100644--- a/CHANGES.txt+++ b/CHANGES.txt@@ -2,6 +2,8 @@ Nutch Change LogNutch Current Development 1.10-SNAPSHOT+* NUTCH-1966 Configuration endpoint for 1x REST API (Sujen Shah via mattmann)+* NUTCH-1967 Possible SIooBE in MimeAdaptiveFetchSchedule (markus)* NUTCH-1957 FileDumper output file name collisions (Renxia Wang via mattmann)diff --git a/ivy/ivy.xml b/ivy/ivy.xmlindex 10b09388c..3e91458cd 100644--- a/ivy/ivy.xml+++ b/ivy/ivy.xml@@ -71,10 +71,14 @@<dependency org="com.google.guava" name="guava" rev="11.0.2" /><dependency org="com.google.code.crawler-commons" name="crawler-commons"rev="0.5" />-+ <dependency org="org.apache.cxf" name="cxf" rev="3.0.4"/>+ <dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxws" rev="3.0.4"/>+ <dependency org="org.apache.cxf" name="cxf-rt-frontend-jaxrs" rev="3.0.4"/>+ <dependency org="org.apache.cxf" name="cxf-rt-transports-http" rev="3.0.4"/>+ <dependency org="org.apache.cxf" name="cxf-rt-transports-http-jetty" rev="3.0.4"/><dependency org="com.fasterxml.jackson.core" name="jackson-databind" rev="2.5.1" /><dependency org="com.fasterxml.jackson.dataformat" name="jackson-dataformat-cbor" rev="2.5.1" />-+<!--Configuration: test --><!--artifacts needed for testing -->diff --git a/src/bin/nutch b/src/bin/nutchindex 959a7748b..b25ae0fdf 100755--- a/src/bin/nutch+++ b/src/bin/nutch@@ -86,6 +86,7 @@ if [ $# = 0 ]; thenecho " nodedumper dumps the web graph's node scores"echo " plugin load a plugin and run one of its classes main()"echo " junit runs the given JUnit test"+ echo " startserver runs the Nutch Server on localhost:8081"echo " or"echo " CLASSNAME run the class named CLASSNAME"echo "Most commands print help when invoked w/o parameters."@@ -270,6 +271,8 @@ elif [ "$COMMAND" = "plugin" ] ; thenelif [ "$COMMAND" = "junit" ] ; thenCLASSPATH="$CLASSPATH:$NUTCH_HOME/test/classes/"CLASS=org.junit.runner.JUnitCore+elif [ "$COMMAND" = "startserver" ] ; then+ CLASS=org.apache.nutch.service.NutchServerelseCLASS=$COMMANDfidiff --git a/src/java/org/apache/nutch/service/ConfManager.java b/src/java/org/apache/nutch/service/ConfManager.javanew file mode 100644index 000000000..026006d7e--- /dev/null+++ b/src/java/org/apache/nutch/service/ConfManager.java@@ -0,0 +1,39 @@+/**+ * 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.service;++import java.util.Map;+import java.util.Set;++import org.apache.hadoop.conf.Configuration;+import org.apache.nutch.service.model.request.NutchConfig;++public interface ConfManager {++ public Configuration get(String confId);++ public Map<String, String> getAsMap(String confId);++ public void setProperty(String confId, String propName, String propValue);++ public Set<String> list();++ public String create(NutchConfig nutchConfig);++ public void delete(String confId);+}diff --git a/src/java/org/apache/nutch/service/JobManager.java b/src/java/org/apache/nutch/service/JobManager.javanew file mode 100644index 000000000..94123f0de--- /dev/null+++ b/src/java/org/apache/nutch/service/JobManager.java@@ -0,0 +1,40 @@+/**+ * 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.service;++import java.util.Collection;++import org.apache.nutch.service.model.response.JobConfig;+import org.apache.nutch.service.model.response.JobInfo;+import org.apache.nutch.service.model.response.JobInfo.State;++public interface JobManager {++ public static enum JobType{+ INJECT, GENERATE, FETCH, PARSE, UPDATEDB, INDEX, READDB, CLASS+ };+ public Collection<JobInfo> list(String crawlId, State state);++ public JobInfo get(String crawlId, String id);++ public String create(JobConfig jobConfig);++ public boolean abort(String crawlId, String id);++ public boolean stop(String crawlId, String id);+}diff --git a/src/java/org/apache/nutch/service/NutchServer.java b/src/java/org/apache/nutch/service/NutchServer.javanew file mode 100644index 000000000..dbfd355a2--- /dev/null+++ b/src/java/org/apache/nutch/service/NutchServer.java@@ -0,0 +1,153 @@+/**+ * 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.service;+++import java.util.ArrayList;+import java.util.List;++import org.apache.commons.cli.CommandLineParser;+import org.apache.commons.cli.HelpFormatter;+import org.apache.commons.cli.OptionBuilder;+import org.apache.commons.cli.Options;+import org.apache.commons.cli.ParseException;+import org.apache.commons.cli.PosixParser;+import org.apache.commons.cli.CommandLine;+import org.apache.cxf.binding.BindingFactoryManager;+import org.apache.cxf.jaxrs.JAXRSBindingFactory;+import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;+import org.apache.cxf.jaxrs.lifecycle.ResourceProvider;+import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;+import org.apache.nutch.service.impl.ConfManagerImpl;+import org.apache.nutch.service.resources.ConfigResource;+import org.apache.nutch.service.resources.JobResource;+import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider;+import org.slf4j.Logger;+import org.slf4j.LoggerFactory;++public class NutchServer {++ private static final Logger LOG = LoggerFactory.getLogger(NutchServer.class);++ private static final String LOCALHOST = "localhost";+ private static final Integer DEFAULT_PORT = 8081;+ private static final int JOB_CAPACITY = 100;++ private static Integer port = DEFAULT_PORT;++ private static final String CMD_HELP = "help";+ private static final String CMD_PORT = "port";++ private long started;+ private boolean running;+ private ConfManager configManager;+ private JAXRSServerFactoryBean sf;++ private static NutchServer server;++ static {+ server = new NutchServer();+ }++ private NutchServer() {+ configManager = new ConfManagerImpl();++ sf = new JAXRSServerFactoryBean();+ BindingFactoryManager manager = sf.getBus().getExtension(BindingFactoryManager.class);+ JAXRSBindingFactory factory = new JAXRSBindingFactory();+ factory.setBus(sf.getBus());+ manager.registerBindingFactory(JAXRSBindingFactory.JAXRS_BINDING_ID, factory);+ sf.setResourceClasses(getClasses());+ sf.setResourceProviders(getResourceProviders());+ sf.setProvider(new JacksonJaxbJsonProvider());+++ }++ public static NutchServer getInstance() {+ return server;+ }++ private static void startServer() {+ server.start();+ }++ private void start() {+ LOG.info("Starting NutchServer on port: {} ...",port);+ try{+ String address = "http://" + LOCALHOST + ":" + port;+ sf.setAddress(address);+ sf.create();+ }catch(Exception e){+ throw new IllegalStateException("Server could not be started", e);+ }++ started = System.currentTimeMillis();+ running = true;+ LOG.info("Started Nutch Server on port {} at {}", port, started);+ System.out.println("Started Nutch Server on port " + port + " at " + started);+ }++ public List<Class<?>> getClasses() {+ List<Class<?>> resources = new ArrayList<Class<?>>();+ resources.add(JobResource.class);+ resources.add(ConfigResource.class);+ return resources;+ }++ public List<ResourceProvider> getResourceProviders() {+ List<ResourceProvider> resourceProviders = new ArrayList<ResourceProvider>();+ resourceProviders.add(new SingletonResourceProvider(getConfManager()));++ return resourceProviders;+ }++ public ConfManager getConfManager() {+ return configManager;+ }++ public static void main(String[] args) throws ParseException {+ CommandLineParser parser = new PosixParser();+ Options options = createOptions();+ CommandLine commandLine = parser.parse(options, args);+ if (commandLine.hasOption(CMD_HELP)) {+ HelpFormatter formatter = new HelpFormatter();+ formatter.printHelp("NutchServer", options, true);+ return;+ }++ if (commandLine.hasOption(CMD_PORT)) {+ port = Integer.parseInt(commandLine.getOptionValue(CMD_PORT));+ }+ startServer();+ }++ private static Options createOptions() {+ Options options = new Options();++ OptionBuilder.withDescription("Show this help");+ options.addOption(OptionBuilder.create(CMD_HELP));++ OptionBuilder.withArgName("port");+ OptionBuilder.hasOptionalArg();+ OptionBuilder.withDescription("The port to run the Nutch Server. Default port 8081");+ options.addOption(OptionBuilder.create(CMD_PORT));+ return options;+ }++}diff --git a/src/java/org/apache/nutch/service/impl/ConfManagerImpl.java b/src/java/org/apache/nutch/service/impl/ConfManagerImpl.javanew file mode 100644index 000000000..d5da0135e--- /dev/null+++ b/src/java/org/apache/nutch/service/impl/ConfManagerImpl.java@@ -0,0 +1,132 @@+/**+ * 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.service.impl;++import java.util.Collections;+import java.util.Iterator;+import java.util.Map;+import java.util.Map.Entry;+import java.util.Set;+import java.util.concurrent.atomic.AtomicInteger;++import org.apache.commons.collections.MapUtils;+import org.apache.commons.lang.StringUtils;+import org.apache.hadoop.conf.Configuration;+import org.apache.nutch.service.ConfManager;+import org.apache.nutch.service.model.request.NutchConfig;+import org.apache.nutch.service.resources.ConfigResource;+import org.apache.nutch.util.NutchConfiguration;++import com.google.common.collect.Maps;++public class ConfManagerImpl implements ConfManager {+++ private Map<String, Configuration> configurations = Maps.newConcurrentMap();++ private AtomicInteger newConfigId = new AtomicInteger();++ public ConfManagerImpl() {+ configurations.put(ConfigResource.DEFAULT, NutchConfiguration.create());+ }++ /**+ * Returns the configuration associatedConfManagerImpl with the given confId+ */+ public Configuration get(String confId) {+ if (confId == null) {+ return configurations.get(ConfigResource.DEFAULT);+ }+ return configurations.get(confId);+ }++ public Map<String, String> getAsMap(String confId) {+ Configuration configuration = configurations.get(confId);+ if (configuration == null) {+ return Collections.emptyMap();+ }++ Iterator<Entry<String, String>> iterator = configuration.iterator();+ Map<String, String> configMap = Maps.newTreeMap();+ while (iterator.hasNext()) {+ Entry<String, String> entry = iterator.next();+ configMap.put(entry.getKey(), entry.getValue());+ }+ return configMap;+ }++ /**+ * Sets the given property in the configuration associated with the confId+ */+ public void setProperty(String confId, String propName, String propValue) {+ if (!configurations.containsKey(confId)) {+ throw new IllegalArgumentException("Unknown configId '" + confId + "'");+ }+ Configuration conf = configurations.get(confId);+ conf.set(propName, propValue);+ }++ public Set<String> list() {+ return configurations.keySet();+ }++ /**+ * Created a new configuration based on the values provided.+ * @param NutchConfig+ * @return String - confId+ */+ public String create(NutchConfig nutchConfig) {+ if (StringUtils.isBlank(nutchConfig.getConfigId())) {+ nutchConfig.setConfigId(String.valueOf(newConfigId.incrementAndGet()));+ }++ if (!canCreate(nutchConfig)) {+ throw new IllegalArgumentException("Config already exists.");+ }++ createHadoopConfig(nutchConfig);+ return nutchConfig.getConfigId();+ }+++ public void delete(String confId) {+ configurations.remove(confId);+ }++ private boolean canCreate(NutchConfig nutchConfig) {+ if (nutchConfig.isForce()) {+ return true;+ }+ if (!configurations.containsKey(nutchConfig.getConfigId())) {+ return true;+ }+ return false;+ }++ private void createHadoopConfig(NutchConfig nutchConfig) {+ Configuration conf = NutchConfiguration.create();+ configurations.put(nutchConfig.getConfigId(), conf);++ if (MapUtils.isEmpty(nutchConfig.getParams())) {+ return;+ }+ for (Entry<String, String> e : nutchConfig.getParams().entrySet()) {+ conf.set(e.getKey(), e.getValue());+ }+ }++}diff --git a/src/java/org/apache/nutch/service/model/request/NutchConfig.java b/src/java/org/apache/nutch/service/model/request/NutchConfig.javanew file mode 100644index 000000000..ffa9e3e2c--- /dev/null+++ b/src/java/org/apache/nutch/service/model/request/NutchConfig.java@@ -0,0 +1,51 @@+/**+ * 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.service.model.request;++import java.util.Map;++import java.util.Collections;++public class NutchConfig {+ private String configId;+ private boolean force = false;+ private Map<String, String> params = Collections.emptyMap();++ public Map<String, String> getParams() {+ return params;+ }++ public void setParams(Map<String, String> params) {+ this.params = params;+ }++ public String getConfigId() {+ return configId;+ }++ public void setConfigId(String configId) {+ this.configId = configId;+ }++ public boolean isForce() {+ return force;+ }++ public void setForce(boolean force) {+ this.force = force;+ }+}diff --git a/src/java/org/apache/nutch/service/model/response/JobConfig.java b/src/java/org/apache/nutch/service/model/response/JobConfig.javanew file mode 100644index 000000000..c44718421--- /dev/null+++ b/src/java/org/apache/nutch/service/model/response/JobConfig.java@@ -0,0 +1,21 @@+/**+ * 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.service.model.response;++public class JobConfig {++}diff --git a/src/java/org/apache/nutch/service/model/response/JobInfo.java b/src/java/org/apache/nutch/service/model/response/JobInfo.javanew file mode 100644index 000000000..f58b4a3d4--- /dev/null+++ b/src/java/org/apache/nutch/service/model/response/JobInfo.java@@ -0,0 +1,91 @@+/**+ * 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.service.model.response;++import java.util.Map;++import org.apache.nutch.service.JobManager.JobType;++/**+ * This is the response object containing Job information+ *+ *+ */+public class JobInfo {++ public static enum State {+ IDLE, RUNNING, FINISHED, FAILED, KILLED, STOPPING, KILLING, ANY+ };++ private String id;+ private JobType type;+ private String confId;+ private Map<String, Object> args;+ private Map<String, Object> result;+ private State state;+ private String msg;+ private String crawlId;++ public String getId() {+ return id;+ }+ public void setId(String id) {+ this.id = id;+ }+ public JobType getType() {+ return type;+ }+ public void setType(JobType type) {+ this.type = type;+ }+ public String getConfId() {+ return confId;+ }+ public void setConfId(String confId) {+ this.confId = confId;+ }+ public Map<String, Object> getArgs() {+ return args;+ }+ public void setArgs(Map<String, Object> args) {+ this.args = args;+ }+ public Map<String, Object> getResult() {+ return result;+ }+ public void setResult(Map<String, Object> result) {+ this.result = result;+ }+ public State getState() {+ return state;+ }+ public void setState(State state) {+ this.state = state;+ }+ public String getMsg() {+ return msg;+ }+ public void setMsg(String msg) {+ this.msg = msg;+ }+ public String getCrawlId() {+ return crawlId;+ }+ public void setCrawlId(String crawlId) {+ this.crawlId = crawlId;+ }+}diff --git a/src/java/org/apache/nutch/service/resources/AbstractResource.java b/src/java/org/apache/nutch/service/resources/AbstractResource.javanew file mode 100644index 000000000..ed2d53b30--- /dev/null+++ b/src/java/org/apache/nutch/service/resources/AbstractResource.java@@ -0,0 +1,42 @@+/**+ * 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.service.resources;++import javax.ws.rs.Produces;+import javax.ws.rs.WebApplicationException;+import javax.ws.rs.core.MediaType;+import javax.ws.rs.core.Response;+import javax.ws.rs.core.Response.Status;++import org.apache.nutch.service.ConfManager;+import org.apache.nutch.service.JobManager;+import org.apache.nutch.service.NutchServer;++@Produces(MediaType.APPLICATION_JSON)+public abstract class AbstractResource {++ protected JobManager jobManager;+ protected ConfManager configManager;++ public AbstractResource() {+ configManager = NutchServer.getInstance().getConfManager();+ }++ protected void throwBadRequestException(String message) {+ throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(message).build());+ }+}diff --git a/src/java/org/apache/nutch/service/resources/ConfigResource.java b/src/java/org/apache/nutch/service/resources/ConfigResource.javanew file mode 100644index 000000000..2c311a682--- /dev/null+++ b/src/java/org/apache/nutch/service/resources/ConfigResource.java@@ -0,0 +1,79 @@+/**+ * 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.service.resources;+++import java.util.Map;+import java.util.Set;++import javax.ws.rs.Consumes;+import javax.ws.rs.DELETE;+import javax.ws.rs.GET;+import javax.ws.rs.POST;+import javax.ws.rs.Path;+import javax.ws.rs.PathParam;+import javax.ws.rs.WebApplicationException;+import javax.ws.rs.core.GenericEntity;+import javax.ws.rs.core.MediaType;+import javax.ws.rs.core.Response;+import javax.ws.rs.core.Response.Status;++import org.apache.nutch.service.model.request.NutchConfig;+import org.codehaus.jettison.json.JSONObject;++@Path("/config")+public class ConfigResource extends AbstractResource{++ public static final String DEFAULT = "default";++ @GET+ @Path("/")+ public Set<String> getConfigs() {+ return configManager.list();+ }++ @GET+ @Path("/{configId}")+ public Map<String, String> getConfig(@PathParam("configId") String configId) {+ return configManager.getAsMap(configId);+ }++ @GET+ @Path("/{configId}/{propertyId}")+ public String getProperty(@PathParam("configId") String configId,+ @PathParam("propertyId") String propertyId) {+ return configManager.getAsMap(configId).get(propertyId);+ }++ @DELETE+ @Path("/{configId}")+ public void deleteConfig(@PathParam("configId") String configId) {+ configManager.delete(configId);+ }++ @POST+ @Path("/{configId}")+ @Consumes(MediaType.APPLICATION_JSON)+ public String createConfig(NutchConfig newConfig) {+ if (newConfig == null) {+ throw new WebApplicationException(Response.status(Status.BAD_REQUEST)+ .entity("Nutch configuration cannot be empty!").build());+ }+ return configManager.create(newConfig);+ }+}diff --git a/src/java/org/apache/nutch/service/resources/JobResource.java b/src/java/org/apache/nutch/service/resources/JobResource.javanew file mode 100644index 000000000..fbfbee256--- /dev/null+++ b/src/java/org/apache/nutch/service/resources/JobResource.java@@ -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.service.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.service.model.response.JobConfig;+import org.apache.nutch.service.model.response.JobInfo;+import org.apache.nutch.service.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);+ }+}