Skip to content

armgit / nutch

Public Imported from GitHub
0

Apache Nutch is an extensible and scalable web crawler

NUTCH-2086 Nutch 1.X Webui this closes #61

Lewis John McGibbney40f2218d772b
diff --git a/ivy/ivy.xml b/ivy/ivy.xml
index e886e0f48..9428fe0be 100644
--- a/ivy/ivy.xml
+++ b/ivy/ivy.xml
@@ -91,17 +91,28 @@
<!--artifacts needed for testing -->
<dependency org="junit" name="junit" rev="4.11" conf="test->default" />
- <!--dependency org="org.apache.hadoop" name="hadoop-test" rev="1.2.0" conf="test->default" /-->
<dependency org="org.mortbay.jetty" name="jetty-client" rev="6.1.22" conf="test->default" />
<dependency org="org.mortbay.jetty" name="jetty" rev="6.1.22" conf="test->default" />
<dependency org="org.mortbay.jetty" name="jetty-util" rev="6.1.22" conf="test->default" />
<!-- end of test artifacts -->
+ <!-- web app dependencies -->
- <dependency org="org.mortbay.jetty" name="jetty-client" rev="6.1.22" conf="test->default" />
+ <dependency org="org.apache.commons" name="commons-collections4" rev="4.0" conf="*->default" />
+ <dependency org="org.springframework" name="spring-core" rev="4.0.4.RELEASE" conf="*->default" />
+ <dependency org="org.springframework" name="spring-context" rev="4.0.4.RELEASE" conf="*->default" />
+ <dependency org="org.springframework" name="spring-web" rev="4.0.4.RELEASE" conf="*->default" />
- <dependency org="org.mortbay.jetty" name="jetty" rev="6.1.22" conf="test->default" />
- <dependency org="org.mortbay.jetty" name="jetty-util" rev="6.1.22" conf="test->default" />
+ <dependency org="com.sun.jersey" name="jersey-client" rev="1.8" conf="*->default" />
+
+ <dependency org="com.j256.ormlite" name="ormlite-jdbc" rev="4.48" conf="*->default" />
+ <dependency org="com.h2database" name="h2" rev="1.4.180" conf="*->default" />
+ <dependency org="org.eclipse.persistence" name="javax.persistence" rev="2.0.0" conf="*->default" />
+
+ <dependency org="org.apache.wicket" name="wicket-core" rev="6.16.0" conf="*->default" />
+ <dependency org="org.apache.wicket" name="wicket-spring" rev="6.16.0" conf="*->default" />
+ <dependency org="de.agilecoders.wicket" name="wicket-bootstrap-core" rev="0.9.2" conf="*->default" />
+ <dependency org="de.agilecoders.wicket" name="wicket-bootstrap-extensions" rev="0.9.2" conf="*->default" />
<!--global exclusion -->
<exclude module="jmxtools" />
diff --git a/src/bin/nutch b/src/bin/nutch
index a55bab450..0b39d3499 100755
--- a/src/bin/nutch
+++ b/src/bin/nutch
@@ -86,8 +86,9 @@ if [ $# = 0 ]; then
echo " 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 " warc exports crawled data from segments at the WARC format"
+ echo " startserver runs the Nutch Server on localhost:8081"
+ echo " webapp run a local Nutch Web Application on locahost:8080"
+ echo " warc exports crawled data from segments at the WARC format"
echo " or"
echo " CLASSNAME run the class named CLASSNAME"
echo "Most commands print help when invoked w/o parameters."
@@ -279,6 +280,8 @@ elif [ "$COMMAND" = "junit" ] ; then
CLASS=org.junit.runner.JUnitCore
elif [ "$COMMAND" = "startserver" ] ; then
CLASS=org.apache.nutch.service.NutchServer
+elif [ "$COMMAND" = "webapp" ] ; then
+ CLASS=org.apache.nutch.webui.NutchUiServer
elif [ "$COMMAND" = "warc" ] ; then
CLASS=org.apache.nutch.tools.warc.WARCExporter
else
diff --git a/src/java/org/apache/nutch/service/model/request/SeedList.java b/src/java/org/apache/nutch/service/model/request/SeedList.java
index 91dd1bbc8..bbb3e2a1f 100644
--- a/src/java/org/apache/nutch/service/model/request/SeedList.java
+++ b/src/java/org/apache/nutch/service/model/request/SeedList.java
@@ -19,12 +19,18 @@ package org.apache.nutch.service.model.request;
import java.io.Serializable;
import java.util.Collection;
+import org.apache.commons.collections4.CollectionUtils;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonManagedReference;
+
public class SeedList implements Serializable {
private Long id;
private String name;
+ @JsonManagedReference
private Collection<SeedUrl> seedUrls;
public Long getId() {
@@ -51,6 +57,14 @@ public class SeedList implements Serializable {
this.name = name;
}
+ @JsonIgnore
+ public int getSeedUrlsCount() {
+ if (CollectionUtils.isEmpty(seedUrls)) {
+ return 0;
+ }
+ return seedUrls.size();
+ }
+
@Override
public int hashCode() {
final int prime = 31;
diff --git a/src/java/org/apache/nutch/service/model/request/SeedUrl.java b/src/java/org/apache/nutch/service/model/request/SeedUrl.java
index c04864caa..b1c93a8dd 100644
--- a/src/java/org/apache/nutch/service/model/request/SeedUrl.java
+++ b/src/java/org/apache/nutch/service/model/request/SeedUrl.java
@@ -18,10 +18,14 @@ package org.apache.nutch.service.model.request;
import java.io.Serializable;
+import com.fasterxml.jackson.annotation.JsonBackReference;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
public class SeedUrl implements Serializable {
private Long id;
+ @JsonBackReference
private SeedList seedList;
private String url;
@@ -48,10 +52,12 @@ public class SeedUrl implements Serializable {
this.url = url;
}
+ @JsonIgnore
public SeedList getSeedList() {
return seedList;
}
+ @JsonIgnore
public void setSeedList(SeedList seedList) {
this.seedList = seedList;
}
diff --git a/src/java/org/apache/nutch/webui/NutchUiApplication.java b/src/java/org/apache/nutch/webui/NutchUiApplication.java
new file mode 100644
index 000000000..6fd239624
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/NutchUiApplication.java
@@ -0,0 +1,75 @@
+/**
+ * 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.webui;
+
+import org.apache.nutch.webui.pages.DashboardPage;
+import org.apache.nutch.webui.pages.assets.NutchUiCssReference;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+import de.agilecoders.wicket.core.Bootstrap;
+import de.agilecoders.wicket.core.markup.html.themes.bootstrap.BootstrapCssReference;
+import de.agilecoders.wicket.core.settings.BootstrapSettings;
+import de.agilecoders.wicket.core.settings.SingleThemeProvider;
+import de.agilecoders.wicket.core.settings.Theme;
+import de.agilecoders.wicket.extensions.markup.html.bootstrap.icon.FontAwesomeCssReference;
+
+@Component
+public class NutchUiApplication extends WebApplication implements
+ ApplicationContextAware {
+ private static final String THEME_NAME = "bootstrap";
+ private ApplicationContext context;
+
+ /**
+ * @see org.apache.wicket.Application#getHomePage()
+ */
+ @Override
+ public Class<? extends WebPage> getHomePage() {
+ return DashboardPage.class;
+ }
+
+ /**
+ * @see org.apache.wicket.Application#init()
+ */
+ @Override
+ public void init() {
+ super.init();
+ BootstrapSettings settings = new BootstrapSettings();
+ Bootstrap.install(this, settings);
+ configureTheme(settings);
+
+ getComponentInstantiationListeners().add(
+ new SpringComponentInjector(this, context));
+ }
+
+ private void configureTheme(BootstrapSettings settings) {
+ Theme theme = new Theme(THEME_NAME, BootstrapCssReference.instance(),
+ FontAwesomeCssReference.instance(), NutchUiCssReference.instance());
+ settings.setThemeProvider(new SingleThemeProvider(theme));
+ }
+
+ @Override
+ public void setApplicationContext(ApplicationContext applicationContext)
+ throws BeansException {
+ this.context = applicationContext;
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/NutchUiApplication.properties b/src/java/org/apache/nutch/webui/NutchUiApplication.properties
new file mode 100644
index 000000000..4c6293933
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/NutchUiApplication.properties
@@ -0,0 +1,63 @@
+#############################################################################
+#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.
+#############################################################################
+
+navbar.menu.dashboard = Dashboard
+navbar.menu.statistics = Statistics
+navbar.menu.instances = Instances
+navbar.menu.settings = Settings
+navbar.menu.crawls = Crawls
+navbar.menu.scheduling = Scheduling
+navbar.menu.search = Search
+navbar.menu.url = URLs upload
+navbar.menu.seedLists = Seed lists
+
+page.header.seedList = Seed list
+
+navbar.userMenu.settings = Settings
+navbar.userMenu.logout = Log out
+
+menu.settings=Settings
+menu.instances=Instances
+
+connected=Connected
+disconnected=Disconnected
+
+##ENUMS
+ConnectionStatus.CONNECTING=Connecting
+ConnectionStatus.CONNECTED=Connected
+ConnectionStatus.DISCONNECTED=Disconnected
+
+CrawlStatus.NEW=New
+CrawlStatus.ERROR=Error
+CrawlStatus.CRAWLING=Crawling
+CrawlStatus.FINISHED=Finished
+
+instances=Instances
+instances.header.name=Instance name
+instances.header.hostname=Hostname
+instances.header.status=Status
+instances.header.username=Username
+instances.label.name=Instance name
+instances.label.hostname=Hostname
+instances.label.port=Port
+instances.label.username=Username
+instances.label.password=Password
+instances.buttons.addInstance=Add instance
+
+settings=Settings
+settings.header.name = Name
+settings.header.value = Value
\ No newline at end of file
diff --git a/src/java/org/apache/nutch/webui/NutchUiServer.java b/src/java/org/apache/nutch/webui/NutchUiServer.java
new file mode 100644
index 000000000..d534b8f95
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/NutchUiServer.java
@@ -0,0 +1,104 @@
+/**
+ * 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.webui;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.Options;
+import org.apache.hadoop.util.StringUtils;
+import org.apache.wicket.protocol.http.WicketFilter;
+import org.apache.wicket.spring.SpringWebApplicationFactory;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.servlet.Context;
+import org.mortbay.jetty.servlet.DefaultServlet;
+import org.mortbay.jetty.servlet.FilterHolder;
+import org.springframework.web.context.ContextLoaderListener;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.request.RequestContextListener;
+import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
+
+public class NutchUiServer {
+ private static final String APP_FACTORY_NAME = SpringWebApplicationFactory.class
+ .getName();
+ private static final String CONFIG_LOCATION = "org.apache.nutch.webui";
+ private static final String CMD_PORT = "port";
+ private static Integer port = 8080;
+
+ public static void main(String[] args) throws Exception {
+ CommandLineParser parser = new GnuParser();
+ Options options = createWebAppOptions();
+ CommandLine commandLine = null;
+ HelpFormatter formatter = new HelpFormatter();
+ try {
+ commandLine = parser.parse(options, args);
+ } catch (Exception e) {
+ formatter.printHelp("NutchUiServer", options, true);
+ StringUtils.stringifyException(e);
+ }
+
+ if (commandLine.hasOption("help")) {
+ formatter.printHelp("NutchUiServer", options, true);
+ return;
+ }
+ if (commandLine.hasOption(CMD_PORT)) {
+ port = Integer.parseInt(commandLine.getOptionValue(CMD_PORT));
+ }
+ startServer();
+ }
+
+ private static void startServer() throws Exception, InterruptedException {
+ Server server = new Server(port);
+ Context context = new Context(server, "/", Context.SESSIONS);
+ context.addServlet(DefaultServlet.class, "/*");
+
+ context.addEventListener(new ContextLoaderListener(getContext()));
+ context.addEventListener(new RequestContextListener());
+
+ WicketFilter filter = new WicketFilter();
+ filter.setFilterPath("/");
+ FilterHolder holder = new FilterHolder(filter);
+ holder.setInitParameter("applicationFactoryClassName", APP_FACTORY_NAME);
+ context.addFilter(holder, "/*", Handler.DEFAULT);
+
+ server.setHandler(context);
+ server.start();
+ server.join();
+ }
+
+ private static WebApplicationContext getContext() {
+ AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
+ context.setConfigLocation(CONFIG_LOCATION);
+ return context;
+ }
+
+ private static Options createWebAppOptions() {
+ Options options = new Options();
+ Option helpOpt = new Option("h", "help", false, "show this help message");
+ OptionBuilder.withDescription("Port to run the WebApplication on.");
+ OptionBuilder.hasOptionalArg();
+ OptionBuilder.withArgName("port number");
+ options.addOption(OptionBuilder.create(CMD_PORT));
+ options.addOption(helpOpt);
+ return options;
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/client/NutchClient.java b/src/java/org/apache/nutch/webui/client/NutchClient.java
new file mode 100644
index 000000000..3f8887d1f
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/NutchClient.java
@@ -0,0 +1,49 @@
+/**
+ * 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.webui.client;
+
+import java.util.Map;
+
+import org.apache.nutch.webui.client.model.ConnectionStatus;
+import org.apache.nutch.webui.client.model.JobConfig;
+import org.apache.nutch.webui.client.model.JobInfo;
+import org.apache.nutch.webui.client.model.NutchStatus;
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.model.SeedList;
+
+public interface NutchClient {
+
+ public NutchInstance getNutchInstance();
+
+ public NutchStatus getNutchStatus();
+
+ public ConnectionStatus getConnectionStatus();
+
+ public String executeJob(JobConfig jobConfig);
+
+ public JobInfo getJobInfo(String jobId);
+
+ public Map<String, String> getNutchConfig(String config);
+
+ /**
+ * Create seed list and return seed directory location
+ *
+ * @param seedList
+ * @return
+ */
+ public String createSeed(SeedList seedList);
+}
diff --git a/src/java/org/apache/nutch/webui/client/NutchClientFactory.java b/src/java/org/apache/nutch/webui/client/NutchClientFactory.java
new file mode 100644
index 000000000..32da00e82
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/NutchClientFactory.java
@@ -0,0 +1,52 @@
+/**
+ * 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.webui.client;
+
+import java.util.concurrent.ExecutionException;
+
+import org.apache.nutch.webui.client.impl.NutchClientImpl;
+import org.apache.nutch.webui.model.NutchInstance;
+import org.springframework.stereotype.Component;
+
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
+
+@Component
+public class NutchClientFactory {
+ private LoadingCache<NutchInstance, NutchClient> cache;
+
+ public NutchClientFactory() {
+ cache = CacheBuilder.newBuilder().build(new NutchClientCacheLoader());
+ }
+
+ public NutchClient getClient(NutchInstance instance) {
+ try {
+ return cache.get(instance);
+ } catch (ExecutionException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+
+ private static class NutchClientCacheLoader extends
+ CacheLoader<NutchInstance, NutchClient> {
+ @Override
+ public NutchClient load(NutchInstance key) throws Exception {
+ return new NutchClientImpl(key);
+ }
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/client/impl/CrawlingCycle.java b/src/java/org/apache/nutch/webui/client/impl/CrawlingCycle.java
new file mode 100644
index 000000000..2482c0679
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/impl/CrawlingCycle.java
@@ -0,0 +1,82 @@
+/**
+ * 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.webui.client.impl;
+
+import java.util.List;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.nutch.webui.client.model.Crawl;
+import org.apache.nutch.webui.client.model.JobInfo;
+import org.apache.nutch.webui.client.model.JobInfo.State;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.collect.Lists;
+
+/**
+ * This class implements crawl cycle as in crawl script
+ *
+ * @author feodor
+ *
+ */
+public class CrawlingCycle {
+ private Logger log = LoggerFactory.getLogger(CrawlingCycle.class);
+
+ private CrawlingCycleListener listener;
+ private RemoteCommandExecutor executor;
+ private Crawl crawl;
+
+ private List<RemoteCommand> remoteCommands;
+ private List<RemoteCommand> executedCommands = Lists.newArrayList();
+
+ public CrawlingCycle(CrawlingCycleListener listener,
+ RemoteCommandExecutor executor, Crawl crawl, List<RemoteCommand> commands) {
+ this.listener = listener;
+ this.executor = executor;
+ this.crawl = crawl;
+ this.remoteCommands = commands;
+ }
+
+ public synchronized void executeCrawlCycle() {
+ listener.crawlingStarted(crawl);
+
+ for (RemoteCommand command : remoteCommands) {
+ JobInfo jobInfo = executor.executeRemoteJob(command);
+ command.setJobInfo(jobInfo);
+
+ log.info("Executed remote command data: {}", command);
+
+ if (jobInfo.getState() == State.FAILED) {
+ listener.onCrawlError(crawl, jobInfo.getMsg());
+ return;
+ }
+
+ executedCommands.add(command);
+ listener.commandExecuted(crawl, command, calculateProgress());
+ }
+ listener.crawlingFinished(crawl);
+ }
+
+ private int calculateProgress() {
+ if (CollectionUtils.isEmpty(remoteCommands)) {
+ return 0;
+ }
+ return (int) ((float) executedCommands.size()
+ / (float) remoteCommands.size() * 100);
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/client/impl/CrawlingCycleListener.java b/src/java/org/apache/nutch/webui/client/impl/CrawlingCycleListener.java
new file mode 100644
index 000000000..c2abde528
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/impl/CrawlingCycleListener.java
@@ -0,0 +1,31 @@
+/**
+ * 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.webui.client.impl;
+
+import org.apache.nutch.webui.client.model.Crawl;
+
+public interface CrawlingCycleListener {
+
+ void crawlingStarted(Crawl crawl);
+
+ void onCrawlError(Crawl crawl, String msg);
+
+ void commandExecuted(Crawl crawl, RemoteCommand command, int progress);
+
+ void crawlingFinished(Crawl crawl);
+
+}
diff --git a/src/java/org/apache/nutch/webui/client/impl/NutchClientImpl.java b/src/java/org/apache/nutch/webui/client/impl/NutchClientImpl.java
new file mode 100644
index 000000000..1a577f97b
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/impl/NutchClientImpl.java
@@ -0,0 +1,99 @@
+/**
+ * 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.webui.client.impl;
+
+import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
+
+import java.util.Map;
+
+import org.apache.nutch.webui.client.NutchClient;
+import org.apache.nutch.webui.client.model.ConnectionStatus;
+import org.apache.nutch.webui.client.model.JobConfig;
+import org.apache.nutch.webui.client.model.JobInfo;
+import org.apache.nutch.webui.client.model.NutchStatus;
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.model.SeedList;
+
+import com.sun.jersey.api.client.Client;
+import com.sun.jersey.api.client.WebResource;
+import com.sun.jersey.api.client.config.ClientConfig;
+import com.sun.jersey.api.client.config.DefaultClientConfig;
+import com.sun.jersey.api.json.JSONConfiguration;
+
+public class NutchClientImpl implements NutchClient {
+ private Client client;
+ private WebResource nutchResource;
+ private NutchInstance instance;
+
+ public NutchClientImpl(NutchInstance instance) {
+ this.instance = instance;
+ createClient();
+ }
+
+ public void createClient() {
+ ClientConfig clientConfig = new DefaultClientConfig();
+ clientConfig.getFeatures()
+ .put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
+ this.client = Client.create(clientConfig);
+ this.nutchResource = client.resource(instance.getUrl());
+ }
+
+ @Override
+ public NutchStatus getNutchStatus() {
+ return nutchResource.path("/admin").type(APPLICATION_JSON)
+ .get(NutchStatus.class);
+ }
+
+ @Override
+ public ConnectionStatus getConnectionStatus() {
+
+ getNutchStatus();
+ return ConnectionStatus.CONNECTED;
+ // TODO implement disconnected status
+ }
+
+ @Override
+ public String executeJob(JobConfig jobConfig) {
+ JobInfo jobInfo = nutchResource.path("/job/create").type(APPLICATION_JSON)
+ .post(JobInfo.class, jobConfig);
+ return jobInfo.getId();
+ }
+
+ @Override
+ public JobInfo getJobInfo(String jobId) {
+ return nutchResource.path("/job/" + jobId).type(APPLICATION_JSON)
+ .get(JobInfo.class);
+ }
+
+ @Override
+ public NutchInstance getNutchInstance() {
+ return instance;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public Map<String, String> getNutchConfig(String config) {
+ return nutchResource.path("/config/" + config).type(APPLICATION_JSON)
+ .get(Map.class);
+ }
+
+ @Override
+ public String createSeed(SeedList seedList) {
+ return nutchResource.path("/seed/create").type(APPLICATION_JSON)
+ .post(String.class, seedList);
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/client/impl/RemoteCommand.java b/src/java/org/apache/nutch/webui/client/impl/RemoteCommand.java
new file mode 100644
index 000000000..ea19a8a68
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/impl/RemoteCommand.java
@@ -0,0 +1,76 @@
+/**
+ * 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.webui.client.impl;
+
+import java.io.Serializable;
+import java.text.MessageFormat;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.nutch.webui.client.model.JobConfig;
+import org.apache.nutch.webui.client.model.JobInfo;
+import org.joda.time.Duration;
+
+public class RemoteCommand implements Serializable {
+ private JobConfig jobConfig;
+ private JobInfo jobInfo = new JobInfo();
+ private Duration timeout;
+
+ /**
+ * Use {@link RemoteCommandBuilder} instead
+ */
+ @SuppressWarnings("unused")
+ private RemoteCommand() {
+ }
+
+ public RemoteCommand(JobConfig jobConfig) {
+ this.jobConfig = jobConfig;
+ }
+
+ public JobConfig getJobConfig() {
+ return jobConfig;
+ }
+
+ public void setJobConfig(JobConfig jobConfig) {
+ this.jobConfig = jobConfig;
+ }
+
+ public JobInfo getJobInfo() {
+ return jobInfo;
+ }
+
+ public void setJobInfo(JobInfo jobInfo) {
+ this.jobInfo = jobInfo;
+ }
+
+ public Duration getTimeout() {
+ return timeout;
+ }
+
+ public void setTimeout(Duration timeout) {
+ this.timeout = timeout;
+ }
+
+ @Override
+ public String toString() {
+ String statusInfo = StringUtils.EMPTY;
+ if (jobInfo != null) {
+ statusInfo = MessageFormat.format("{0}", jobInfo.getState());
+ }
+ return MessageFormat.format("{0} status: {1}", jobConfig.getType(),
+ statusInfo);
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/client/impl/RemoteCommandBuilder.java b/src/java/org/apache/nutch/webui/client/impl/RemoteCommandBuilder.java
new file mode 100644
index 000000000..d6b176757
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/impl/RemoteCommandBuilder.java
@@ -0,0 +1,64 @@
+/**
+ * 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.webui.client.impl;
+
+import org.apache.nutch.webui.client.model.JobConfig;
+import org.apache.nutch.webui.client.model.JobInfo.JobType;
+import org.joda.time.Duration;
+
+public class RemoteCommandBuilder {
+ private JobConfig jobConfig = new JobConfig();
+ private Duration timeout = Duration.standardSeconds(10);
+
+ private RemoteCommandBuilder() {
+ }
+
+ public static RemoteCommandBuilder instance(JobType jobType) {
+ return new RemoteCommandBuilder().withJobType(jobType);
+ }
+
+ public RemoteCommandBuilder withJobType(JobType jobType) {
+ jobConfig.setType(jobType);
+ return this;
+ }
+
+ public RemoteCommandBuilder withConfigId(String configId) {
+ jobConfig.setConfId(configId);
+ return this;
+ }
+
+ public RemoteCommandBuilder withCrawlId(String crawlId) {
+ jobConfig.setCrawlId(crawlId);
+ return this;
+ }
+
+ public RemoteCommandBuilder withArgument(String key, String value) {
+ jobConfig.setArgument(key, value);
+ return this;
+ }
+
+ public RemoteCommandBuilder withTimeout(Duration timeout) {
+ this.timeout = timeout;
+ return this;
+ }
+
+ public RemoteCommand build() {
+ RemoteCommand remoteCommand = new RemoteCommand(jobConfig);
+ remoteCommand.setTimeout(timeout);
+ return remoteCommand;
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/client/impl/RemoteCommandExecutor.java b/src/java/org/apache/nutch/webui/client/impl/RemoteCommandExecutor.java
new file mode 100644
index 000000000..e1eefc2e9
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/impl/RemoteCommandExecutor.java
@@ -0,0 +1,110 @@
+/**
+ * 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.webui.client.impl;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang3.exception.ExceptionUtils;
+import org.apache.nutch.webui.client.NutchClient;
+import org.apache.nutch.webui.client.model.JobInfo;
+import org.apache.nutch.webui.client.model.JobInfo.State;
+import org.joda.time.DateTimeConstants;
+import org.joda.time.Duration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class executes remote job and waits for success/failure result
+ *
+ * @author feodor
+ *
+ */
+public class RemoteCommandExecutor {
+ private Logger log = LoggerFactory.getLogger(RemoteCommandExecutor.class);
+
+ private static final int DEFAULT_TIMEOUT_SEC = 60;
+ private Duration requestDelay = new Duration(500);
+
+ private NutchClient client;
+ private ExecutorService executor;
+
+ public RemoteCommandExecutor(NutchClient client) {
+ this.client = client;
+ this.executor = Executors.newSingleThreadExecutor();
+ }
+
+ public JobInfo executeRemoteJob(RemoteCommand command) {
+ try {
+ String jobId = client.executeJob(command.getJobConfig());
+ Future<JobInfo> chekerFuture = executor
+ .submit(new JobStateChecker(jobId));
+ return chekerFuture.get(getTimeout(command), TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ log.error("Remote command failed", e);
+ JobInfo jobInfo = new JobInfo();
+ jobInfo.setState(State.FAILED);
+ jobInfo.setMsg(ExceptionUtils.getStackTrace(e));
+ return jobInfo;
+ }
+ }
+
+ private long getTimeout(RemoteCommand command) {
+ if (command.getTimeout() == null) {
+ return DEFAULT_TIMEOUT_SEC * DateTimeConstants.MILLIS_PER_SECOND;
+ }
+ return command.getTimeout().getMillis();
+ }
+
+ public void setRequestDelay(Duration requestDelay) {
+ this.requestDelay = requestDelay;
+ }
+
+ public class JobStateChecker implements Callable<JobInfo> {
+
+ private String jobId;
+
+ public JobStateChecker(String jobId) {
+ this.jobId = jobId;
+ }
+
+ @Override
+ public JobInfo call() throws Exception {
+ while (!Thread.interrupted()) {
+ JobInfo jobInfo = client.getJobInfo(jobId);
+ checkState(jobInfo != null, "Cannot get job info!");
+
+ State state = jobInfo.getState();
+ checkState(state != null, "Unknown job state!");
+
+ if (state == State.RUNNING || state == State.ANY || state == State.IDLE) {
+ Thread.sleep(requestDelay.getMillis());
+ continue;
+ }
+
+ return jobInfo;
+ }
+ return null;
+ }
+
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/client/impl/RemoteCommandsBatchFactory.java b/src/java/org/apache/nutch/webui/client/impl/RemoteCommandsBatchFactory.java
new file mode 100644
index 000000000..cef56a5b9
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/impl/RemoteCommandsBatchFactory.java
@@ -0,0 +1,97 @@
+/**
+ * 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.webui.client.impl;
+
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.nutch.webui.client.model.Crawl;
+import org.apache.nutch.webui.client.model.JobInfo.JobType;
+import org.joda.time.Duration;
+import org.springframework.beans.factory.config.BeanDefinition;
+import org.springframework.context.annotation.Scope;
+import org.springframework.stereotype.Component;
+
+import com.google.common.collect.Lists;
+
+@Component
+@Scope(BeanDefinition.SCOPE_PROTOTYPE)
+public class RemoteCommandsBatchFactory {
+
+ private List<RemoteCommand> remoteCommands;
+ private Crawl crawl;
+
+ private String batchId;
+
+ public List<RemoteCommand> createCommands(Crawl crawl) {
+ this.crawl = crawl;
+ this.remoteCommands = Lists.newArrayList();
+
+ remoteCommands.add(inject());
+ for (int i = 0; i < crawl.getNumberOfRounds(); i++) {
+ remoteCommands.addAll(createBatchCommands());
+ }
+ return remoteCommands;
+ }
+
+ private List<RemoteCommand> createBatchCommands() {
+ this.batchId = UUID.randomUUID().toString();
+ List<RemoteCommand> batchCommands = Lists.newArrayList();
+
+ batchCommands.add(createGenerateCommand());
+ batchCommands.add(createFetchCommand());
+ batchCommands.add(createParseCommand());
+ batchCommands.add(createUpdateDbCommand());
+ batchCommands.add(createIndexCommand());
+
+ return batchCommands;
+ }
+
+ private RemoteCommand inject() {
+ RemoteCommandBuilder builder = RemoteCommandBuilder
+ .instance(JobType.INJECT).withCrawlId(crawl.getCrawlId())
+ .withArgument("url_dir", crawl.getSeedDirectory());
+ return builder.build();
+ }
+
+ private RemoteCommand createGenerateCommand() {
+ return createBuilder(JobType.GENERATE).build();
+ }
+
+ private RemoteCommand createFetchCommand() {
+ return createBuilder(JobType.FETCH).withTimeout(
+ Duration.standardSeconds(50)).build();
+ }
+
+ private RemoteCommand createParseCommand() {
+ return createBuilder(JobType.PARSE).build();
+ }
+
+ private RemoteCommand createIndexCommand() {
+ return createBuilder(JobType.INDEX).build();
+ }
+
+ private RemoteCommand createUpdateDbCommand() {
+ return createBuilder(JobType.UPDATEDB).build();
+ }
+
+ private RemoteCommandBuilder createBuilder(JobType jobType) {
+ return RemoteCommandBuilder.instance(jobType)
+ .withCrawlId(crawl.getCrawlId()).withArgument("batch", batchId);
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/client/model/ConnectionStatus.java b/src/java/org/apache/nutch/webui/client/model/ConnectionStatus.java
new file mode 100644
index 000000000..d834612d9
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/model/ConnectionStatus.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.webui.client.model;
+
+public enum ConnectionStatus {
+ CONNECTING, CONNECTED, DISCONNECTED;
+}
\ No newline at end of file
diff --git a/src/java/org/apache/nutch/webui/client/model/Crawl.java b/src/java/org/apache/nutch/webui/client/model/Crawl.java
new file mode 100644
index 000000000..6057f7fab
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/model/Crawl.java
@@ -0,0 +1,126 @@
+/**
+ * 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.webui.client.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.apache.nutch.webui.model.SeedList;
+
+import com.j256.ormlite.field.DatabaseField;
+
+@Entity
+public class Crawl implements Serializable {
+ public enum CrawlStatus {
+ NEW, CRAWLING, FINISHED, ERROR
+ }
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column
+ private String crawlId;
+
+ @Column
+ private String crawlName;
+
+ @Column
+ private CrawlStatus status = CrawlStatus.NEW;
+
+ @Column
+ private Integer numberOfRounds = 1;
+
+ @Column
+ @DatabaseField(foreign = true, foreignAutoRefresh = true)
+ private SeedList seedList;
+
+ @Column
+ private String seedDirectory;
+
+ @Column
+ private int progress;
+
+ public Integer getNumberOfRounds() {
+ return numberOfRounds;
+ }
+
+ public void setNumberOfRounds(Integer numberOfRounds) {
+ this.numberOfRounds = numberOfRounds;
+ }
+
+ public String getCrawlId() {
+ return crawlId;
+ }
+
+ public void setCrawlId(String crawlId) {
+ this.crawlId = crawlId;
+ }
+
+ public CrawlStatus getStatus() {
+ return status;
+ }
+
+ public void setStatus(CrawlStatus status) {
+ this.status = status;
+ }
+
+ public String getCrawlName() {
+ return crawlName;
+ }
+
+ public void setCrawlName(String crawlName) {
+ this.crawlName = crawlName;
+ }
+
+ public SeedList getSeedList() {
+ return seedList;
+ }
+
+ public void setSeedList(SeedList seedList) {
+ this.seedList = seedList;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getSeedDirectory() {
+ return seedDirectory;
+ }
+
+ public void setSeedDirectory(String seedDirectory) {
+ this.seedDirectory = seedDirectory;
+ }
+
+ public int getProgress() {
+ return progress;
+ }
+
+ public void setProgress(int progress) {
+ this.progress = progress;
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/client/model/JobConfig.java b/src/java/org/apache/nutch/webui/client/model/JobConfig.java
new file mode 100644
index 000000000..80df2796f
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/model/JobConfig.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.webui.client.model;
+
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.nutch.webui.client.model.JobInfo.JobType;
+
+import com.google.common.collect.Maps;
+
+public class JobConfig implements Serializable {
+ private String crawlId;
+ private JobType type;
+ private String confId = "default";
+ private String jobClassName;
+ private Map<String, Object> args = Maps.newHashMap();
+
+ public void setArgument(String key, String value) {
+ args.put(key, value);
+ }
+
+ public String getCrawlId() {
+ return crawlId;
+ }
+
+ public void setCrawlId(String crawlId) {
+ this.crawlId = crawlId;
+ }
+
+ 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 Collections.unmodifiableMap(args);
+ }
+
+ public void setArgs(Map<String, Object> args) {
+ this.args = args;
+ }
+
+ public String getJobClassName() {
+ return jobClassName;
+ }
+
+ public void setJobClassName(String jobClass) {
+ this.jobClassName = jobClass;
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/client/model/JobInfo.java b/src/java/org/apache/nutch/webui/client/model/JobInfo.java
new file mode 100644
index 000000000..312118ae0
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/model/JobInfo.java
@@ -0,0 +1,104 @@
+/*******************************************************************************
+ * 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.webui.client.model;
+
+import java.io.Serializable;
+import java.util.Map;
+
+public class JobInfo implements Serializable {
+ public static enum JobType {
+ INJECT, GENERATE, FETCH, PARSE, UPDATEDB, INDEX, READDB, CLASS
+ };
+
+ public static enum State {
+ IDLE, RUNNING, FINISHED, FAILED, KILLED, STOPPING, KILLING, ANY
+ };
+
+ private String id;
+ private String 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 getMsg() {
+ return msg;
+ }
+
+ public void setMsg(String msg) {
+ this.msg = msg;
+ }
+
+ public State getState() {
+ return state;
+ }
+
+ public void setState(State state) {
+ this.state = state;
+ }
+
+ public Map<String, Object> getResult() {
+ return result;
+ }
+
+ public void setResult(Map<String, Object> result) {
+ this.result = result;
+ }
+
+ public Map<String, Object> getArgs() {
+ return args;
+ }
+
+ public void setArgs(Map<String, Object> args) {
+ this.args = args;
+ }
+
+ public String getConfId() {
+ return confId;
+ }
+
+ public void setConfId(String confId) {
+ this.confId = confId;
+ }
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getCrawlId() {
+ return crawlId;
+ }
+
+ public void setCrawlId(String crawlId) {
+ this.crawlId = crawlId;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/client/model/NutchStatus.java b/src/java/org/apache/nutch/webui/client/model/NutchStatus.java
new file mode 100644
index 000000000..0c5c4250c
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/client/model/NutchStatus.java
@@ -0,0 +1,62 @@
+/*******************************************************************************
+ * 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.webui.client.model;
+
+import java.io.Serializable;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Set;
+
+public class NutchStatus implements Serializable {
+
+ private Date startDate;
+ private Set<String> configuration;
+ private Collection<JobInfo> jobs;
+ private Collection<JobInfo> runningJobs;
+
+ public Date getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(Date startDate) {
+ this.startDate = startDate;
+ }
+
+ public Set<String> getConfiguration() {
+ return configuration;
+ }
+
+ public void setConfiguration(Set<String> configuration) {
+ this.configuration = configuration;
+ }
+
+ public Collection<JobInfo> getJobs() {
+ return jobs;
+ }
+
+ public void setJobs(Collection<JobInfo> jobs) {
+ this.jobs = jobs;
+ }
+
+ public Collection<JobInfo> getRunningJobs() {
+ return runningJobs;
+ }
+
+ public void setRunningJobs(Collection<JobInfo> runningJobs) {
+ this.runningJobs = runningJobs;
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/config/CustomDaoFactory.java b/src/java/org/apache/nutch/webui/config/CustomDaoFactory.java
new file mode 100644
index 000000000..09c2d6aeb
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/config/CustomDaoFactory.java
@@ -0,0 +1,58 @@
+/**
+ * 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.webui.config;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import com.j256.ormlite.dao.Dao;
+import com.j256.ormlite.spring.DaoFactory;
+import com.j256.ormlite.support.ConnectionSource;
+
+public class CustomDaoFactory {
+ private ConnectionSource connectionSource;
+ private List<Dao<?, ?>> registredDaos = Collections
+ .synchronizedList(new ArrayList<Dao<?, ?>>());
+
+ public CustomDaoFactory(ConnectionSource connectionSource) {
+ this.connectionSource = connectionSource;
+ }
+
+ public <T, ID> Dao<T, ID> createDao(Class<T> clazz) {
+ try {
+ Dao<T, ID> dao = DaoFactory.createDao(connectionSource, clazz);
+ register(dao);
+ return dao;
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private <T, ID> void register(Dao<T, ID> dao) {
+ synchronized (registredDaos) {
+ registredDaos.add(dao);
+ }
+ }
+
+ public List<Dao<?, ?>> getCreatedDaos() {
+ synchronized (registredDaos) {
+ return Collections.unmodifiableList(registredDaos);
+ }
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/config/CustomTableCreator.java b/src/java/org/apache/nutch/webui/config/CustomTableCreator.java
new file mode 100644
index 000000000..9b31d7311
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/config/CustomTableCreator.java
@@ -0,0 +1,83 @@
+/**
+ * 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.webui.config;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import com.j256.ormlite.dao.BaseDaoImpl;
+import com.j256.ormlite.dao.Dao;
+import com.j256.ormlite.support.ConnectionSource;
+import com.j256.ormlite.table.DatabaseTableConfig;
+import com.j256.ormlite.table.TableUtils;
+
+public class CustomTableCreator {
+
+ private ConnectionSource connectionSource;
+ private List<Dao<?, ?>> configuredDaos;
+
+ public CustomTableCreator(ConnectionSource connectionSource,
+ List<Dao<?, ?>> configuredDaos) {
+ this.connectionSource = connectionSource;
+ this.configuredDaos = configuredDaos;
+ initialize();
+ }
+
+ private void initialize() {
+ if (configuredDaos == null) {
+ throw new IllegalStateException("configuredDaos was not set in "
+ + getClass().getSimpleName());
+ }
+
+ for (Dao<?, ?> dao : configuredDaos) {
+ createTableForDao(dao);
+ }
+ }
+
+ private void createTableForDao(Dao<?, ?> dao) {
+ DatabaseTableConfig<?> tableConfig = getTableConfig(dao);
+ createTableIfNotExists(tableConfig);
+ }
+
+ private DatabaseTableConfig<?> getTableConfig(Dao<?, ?> dao) {
+ Class<?> clazz = dao.getDataClass();
+ DatabaseTableConfig<?> tableConfig = null;
+ if (dao instanceof BaseDaoImpl) {
+ tableConfig = ((BaseDaoImpl<?, ?>) dao).getTableConfig();
+ }
+ if (tableConfig == null) {
+ return getConfigFromClass(clazz);
+ }
+ return tableConfig;
+ }
+
+ private DatabaseTableConfig<?> getConfigFromClass(Class<?> clazz) {
+ try {
+ return DatabaseTableConfig.fromClass(connectionSource, clazz);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void createTableIfNotExists(DatabaseTableConfig<?> tableConfig) {
+ try {
+ TableUtils.createTableIfNotExists(connectionSource, tableConfig);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/config/NutchGuiConfiguration.java b/src/java/org/apache/nutch/webui/config/NutchGuiConfiguration.java
new file mode 100644
index 000000000..8b76440e9
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/config/NutchGuiConfiguration.java
@@ -0,0 +1,33 @@
+/**
+ * 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.webui.config;
+
+import java.util.List;
+
+import org.apache.nutch.webui.model.NutchInstance;
+
+public class NutchGuiConfiguration {
+ private List<NutchInstance> instances;
+
+ public List<NutchInstance> getInstances() {
+ return instances;
+ }
+
+ public void setInstances(List<NutchInstance> instances) {
+ this.instances = instances;
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/config/SpringConfiguration.java b/src/java/org/apache/nutch/webui/config/SpringConfiguration.java
new file mode 100644
index 000000000..1687cee41
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/config/SpringConfiguration.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.webui.config;
+
+import java.sql.SQLException;
+import java.util.concurrent.Executor;
+
+import org.apache.nutch.webui.client.model.Crawl;
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.model.SeedList;
+import org.apache.nutch.webui.model.SeedUrl;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.AsyncConfigurer;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import com.j256.ormlite.dao.Dao;
+import com.j256.ormlite.db.H2DatabaseType;
+import com.j256.ormlite.jdbc.JdbcConnectionSource;
+
+@Configuration
+@EnableAsync
+public class SpringConfiguration implements AsyncConfigurer {
+
+ @Override
+ public Executor getAsyncExecutor() {
+ // TODO move magic numbers to properties file
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ executor.setCorePoolSize(7);
+ executor.setMaxPoolSize(42);
+ executor.setQueueCapacity(11);
+ executor.setThreadNamePrefix("SpringExecutor-");
+ executor.initialize();
+ return executor;
+ }
+
+ @Bean
+ public JdbcConnectionSource getConnectionSource() throws SQLException {
+ JdbcConnectionSource source = new JdbcConnectionSource(
+ "jdbc:h2:~/.nutch/config", new H2DatabaseType());
+ source.initialize();
+ return source;
+ }
+
+ @Bean
+ public CustomDaoFactory getDaoFactory() throws SQLException {
+ return new CustomDaoFactory(getConnectionSource());
+ }
+
+ @Bean
+ public Dao<NutchInstance, Long> createNutchDao() throws SQLException {
+ return getDaoFactory().createDao(NutchInstance.class);
+ }
+
+ @Bean
+ public Dao<SeedList, Long> createSeedListDao() throws SQLException {
+ return getDaoFactory().createDao(SeedList.class);
+ }
+
+ @Bean
+ public Dao<SeedUrl, Long> createSeedUrlDao() throws SQLException {
+ return getDaoFactory().createDao(SeedUrl.class);
+ }
+
+ @Bean
+ public Dao<Crawl, Long> createCrawlDao() throws SQLException {
+ return getDaoFactory().createDao(Crawl.class);
+ }
+
+ @Bean
+ public CustomTableCreator createTableCreator() throws SQLException {
+ return new CustomTableCreator(getConnectionSource(), getDaoFactory()
+ .getCreatedDaos());
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/model/NutchConfig.java b/src/java/org/apache/nutch/webui/model/NutchConfig.java
new file mode 100644
index 000000000..2106d2322
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/model/NutchConfig.java
@@ -0,0 +1,24 @@
+package org.apache.nutch.webui.model;
+
+import java.io.Serializable;
+
+public class NutchConfig implements Serializable {
+ private String name = "name";
+ private String value;
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/model/NutchInstance.java b/src/java/org/apache/nutch/webui/model/NutchInstance.java
new file mode 100644
index 000000000..2c1f1c525
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/model/NutchInstance.java
@@ -0,0 +1,118 @@
+/**
+ * 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.webui.model;
+
+import java.io.Serializable;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.apache.nutch.webui.client.model.ConnectionStatus;
+
+@Entity
+public class NutchInstance implements Serializable {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column
+ private String name = "localhost";
+
+ @Column
+ private String host = "localhost";
+
+ @Column
+ private Integer port = 8081;
+
+ @Column
+ private String username;
+
+ @Column
+ private String password;
+
+ private ConnectionStatus connectionStatus;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getHost() {
+ return host;
+ }
+
+ public void setUsername(String username) {
+ this.username = username;
+ }
+
+ public String getUsername() {
+ return username;
+ }
+
+ public void setHost(String host) {
+ this.host = host;
+ }
+
+ public Integer getPort() {
+ return port;
+ }
+
+ public void setPort(Integer port) {
+ this.port = port;
+ }
+
+ public ConnectionStatus getConnectionStatus() {
+ return connectionStatus;
+ }
+
+ public void setConnectionStatus(ConnectionStatus connectionStatus) {
+ this.connectionStatus = connectionStatus;
+ }
+
+ public URI getUrl() {
+ try {
+ return new URI("http", null, host, port, null, null, null);
+ } catch (URISyntaxException e) {
+ throw new IllegalStateException("Cannot parse url parameters", e);
+ }
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/model/SeedList.java b/src/java/org/apache/nutch/webui/model/SeedList.java
new file mode 100644
index 000000000..72d3d7573
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/model/SeedList.java
@@ -0,0 +1,106 @@
+/**
+ * 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.webui.model;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.OneToMany;
+
+import org.apache.commons.collections4.CollectionUtils;
+import org.codehaus.jackson.annotate.JsonIgnore;
+
+import com.fasterxml.jackson.annotation.JsonManagedReference;
+import com.j256.ormlite.field.ForeignCollectionField;
+
+@Entity
+public class SeedList implements Serializable {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column
+ private String name;
+
+ @OneToMany
+ @ForeignCollectionField(eager = true)
+ @JsonManagedReference
+ private Collection<SeedUrl> seedUrls;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ @JsonIgnore
+ public int getSeedUrlsCount() {
+ if (CollectionUtils.isEmpty(seedUrls)) {
+ return 0;
+ }
+ return seedUrls.size();
+ }
+
+ public Collection<SeedUrl> getSeedUrls() {
+ return seedUrls;
+ }
+
+ public void setSeedUrls(Collection<SeedUrl> seedUrls) {
+ this.seedUrls = seedUrls;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SeedList other = (SeedList) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/model/SeedUrl.java b/src/java/org/apache/nutch/webui/model/SeedUrl.java
new file mode 100644
index 000000000..5f892418e
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/model/SeedUrl.java
@@ -0,0 +1,96 @@
+/**
+ * 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.webui.model;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import org.codehaus.jackson.annotate.JsonIgnore;
+
+import com.fasterxml.jackson.annotation.JsonBackReference;
+import com.j256.ormlite.field.DatabaseField;
+
+@Entity
+public class SeedUrl implements Serializable {
+
+ @Id
+ @GeneratedValue
+ private Long id;
+
+ @Column
+ @DatabaseField(foreign = true, foreignAutoCreate = true, foreignAutoRefresh = true)
+ @JsonBackReference
+ private SeedList seedList;
+
+ @Column
+ private String url;
+
+ public Long getId() {
+ return id;
+ }
+
+ public void setId(Long id) {
+ this.id = id;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ public void setUrl(String url) {
+ this.url = url;
+ }
+
+ @JsonIgnore
+ public SeedList getSeedList() {
+ return seedList;
+ }
+
+ @JsonIgnore
+ public void setSeedList(SeedList seedList) {
+ this.seedList = seedList;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ SeedUrl other = (SeedUrl) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/pages/AbstractBasePage.html b/src/java/org/apache/nutch/webui/pages/AbstractBasePage.html
new file mode 100644
index 000000000..101a0f3e8
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/AbstractBasePage.html
@@ -0,0 +1,33 @@
+<!-- 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. -->
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+<meta charset="utf-8">
+<meta http-equiv="X-UA-Compatible" content="IE=edge">
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<meta name="description" content="">
+<meta name="author" content="">
+<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
+
+<title>Apache Nutch</title>
+
+</head>
+<body>
+ <div id="wrapper">
+ <nav wicket:id="navigation" class="bs-docs-nav"></nav>
+ <div id="page-wrapper">
+ <div wicket:id="globalNotificationPanel"></div>
+ <wicket:child></wicket:child>
+ </div>
+ </div>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/java/org/apache/nutch/webui/pages/AbstractBasePage.java b/src/java/org/apache/nutch/webui/pages/AbstractBasePage.java
new file mode 100644
index 000000000..22b851ce0
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/AbstractBasePage.java
@@ -0,0 +1,181 @@
+/**
+ * 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.webui.pages;
+
+import static de.agilecoders.wicket.core.markup.html.bootstrap.navbar.Navbar.ComponentPosition.LEFT;
+import static de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarComponents.transform;
+
+import java.util.List;
+
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.pages.crawls.CrawlsPage;
+import org.apache.nutch.webui.pages.instances.InstancesPage;
+import org.apache.nutch.webui.pages.menu.VerticalMenu;
+import org.apache.nutch.webui.pages.seed.SeedListsPage;
+import org.apache.nutch.webui.pages.settings.SettingsPage;
+import org.apache.nutch.webui.service.NutchInstanceService;
+import org.apache.nutch.webui.service.NutchService;
+import org.apache.wicket.Component;
+import org.apache.wicket.Page;
+import org.apache.wicket.markup.html.GenericWebPage;
+import org.apache.wicket.markup.html.link.AbstractLink;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.model.PropertyModel;
+import org.apache.wicket.model.ResourceModel;
+import org.apache.wicket.spring.injection.annot.SpringBean;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.button.dropdown.DropDownButton;
+import de.agilecoders.wicket.core.markup.html.bootstrap.button.dropdown.MenuBookmarkablePageLink;
+import de.agilecoders.wicket.core.markup.html.bootstrap.button.dropdown.MenuDivider;
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+import de.agilecoders.wicket.core.markup.html.bootstrap.image.IconType;
+import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.Navbar.ComponentPosition;
+import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.Navbar.Position;
+import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarButton;
+import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarComponents;
+import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.NavbarDropDownButton;
+import de.agilecoders.wicket.extensions.markup.html.bootstrap.icon.FontAwesomeIconType;
+
+public abstract class AbstractBasePage<T> extends GenericWebPage<T> {
+ @SpringBean
+ private NutchService service;
+
+ @SpringBean
+ private NutchInstanceService instanceService;
+
+ private VerticalMenu navbar;
+
+ protected IModel<NutchInstance> currentInstance = new InstanceModel();
+
+ public AbstractBasePage() {
+ navbar = new VerticalMenu("navigation");
+ navbar.brandName(Model.of("Apache Nutch GUI"));
+ navbar.setInverted(true);
+ navbar.setPosition(Position.TOP);
+ add(navbar);
+
+ addMenuItem(DashboardPage.class, "navbar.menu.dashboard",
+ FontAwesomeIconType.dashboard);
+ addMenuItem(StatisticsPage.class, "navbar.menu.statistics",
+ FontAwesomeIconType.bar_chart_o);
+ addMenuItem(InstancesPage.class, "navbar.menu.instances",
+ FontAwesomeIconType.gears);
+ addMenuItem(SettingsPage.class, "navbar.menu.settings",
+ FontAwesomeIconType.wrench);
+ addMenuItem(CrawlsPage.class, "navbar.menu.crawls",
+ FontAwesomeIconType.refresh);
+ addMenuItem(SchedulingPage.class, "navbar.menu.scheduling",
+ FontAwesomeIconType.clock_o);
+ addMenuItem(SearchPage.class, "navbar.menu.search",
+ FontAwesomeIconType.search);
+ addMenuItem(SeedListsPage.class, "navbar.menu.seedLists",
+ FontAwesomeIconType.file);
+
+ navbar.addComponents(transform(ComponentPosition.RIGHT,
+ addInstancesMenuMenu()));
+ navbar.addComponents(transform(ComponentPosition.RIGHT, addUserMenu()));
+
+ add(new NotificationPanel("globalNotificationPanel"));
+
+ if (currentInstance.getObject() == null && !(this instanceof InstancesPage)) {
+ getSession().error("No running instances found!");
+ setResponsePage(InstancesPage.class);
+ }
+ }
+
+ protected Component addUserMenu() {
+ DropDownButton userMenu = new NavbarDropDownButton(Model.of("Username")) {
+ @Override
+ protected List<AbstractLink> newSubMenuButtons(final String buttonMarkupId) {
+ List<AbstractLink> subMenu = Lists.newArrayList();
+ subMenu.add(new MenuBookmarkablePageLink<Void>(UserSettingsPage.class,
+ new ResourceModel("navbar.userMenu.settings"))
+ .setIconType(FontAwesomeIconType.gear));
+ subMenu.add(new MenuDivider());
+ subMenu.add(new MenuBookmarkablePageLink<Void>(LogOutPage.class,
+ new ResourceModel("navbar.userMenu.logout"))
+ .setIconType(FontAwesomeIconType.power_off));
+ return subMenu;
+ }
+ }.setIconType(FontAwesomeIconType.user);
+ return userMenu;
+ }
+
+ protected Component addInstancesMenuMenu() {
+ IModel<String> instanceName = PropertyModel.of(currentInstance, "name");
+ DropDownButton instancesMenu = new NavbarDropDownButton(instanceName) {
+
+ @Override
+ protected List<AbstractLink> newSubMenuButtons(String buttonMarkupId) {
+ List<NutchInstance> instances = instanceService.getInstances();
+ List<AbstractLink> subMenu = Lists.newArrayList();
+ for (NutchInstance instance : instances) {
+ subMenu.add(new Link<NutchInstance>(buttonMarkupId, Model
+ .of(instance)) {
+ @Override
+ public void onClick() {
+ currentInstance.setObject(getModelObject());
+ setResponsePage(DashboardPage.class);
+ }
+ }.setBody(Model.of(instance.getName())));
+ }
+ return subMenu;
+ }
+ }.setIconType(FontAwesomeIconType.gears);
+
+ return instancesMenu;
+ }
+
+ private <P extends Page> void addMenuItem(Class<P> page, String label,
+ IconType icon) {
+ Component button = new NavbarButton<Void>(page, Model.of(getString(label)))
+ .setIconType(icon);
+ navbar.addComponents(NavbarComponents.transform(LEFT, button));
+ }
+
+ protected NutchInstance getCurrentInstance() {
+ return currentInstance.getObject();
+ }
+
+ private class InstanceModel extends LoadableDetachableModel<NutchInstance> {
+
+ @Override
+ public void setObject(NutchInstance instance) {
+ super.setObject(instance);
+ getSession().setAttribute("instanceId", instance.getId());
+ }
+
+ @Override
+ protected NutchInstance load() {
+ Long instanceId = (Long) getSession().getAttribute("instanceId");
+ if (instanceId == null) {
+ return getFirstInstance();
+ }
+ return instanceService.getInstance(instanceId);
+ }
+
+ private NutchInstance getFirstInstance() {
+ return Iterables.getFirst(instanceService.getInstances(), null);
+ }
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/pages/DashboardPage.html b/src/java/org/apache/nutch/webui/pages/DashboardPage.html
new file mode 100644
index 000000000..b6d542631
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/DashboardPage.html
@@ -0,0 +1,52 @@
+<!-- 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. -->
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+<meta charset="utf-8" />
+<title>Wicket extend</title>
+</head>
+
+<body>
+ <wicket:extend>
+ <h2>
+ <wicket:message key="navbar.menu.dashboard">Instances</wicket:message>
+ </h2>
+ <div class="row">
+ <div class="col-lg-3">
+ <div class="panel panel-info">
+ <div wicket:id="panel" class="panel-heading">
+ <div class="row">
+ <div class="col-xs-6">
+ <i class="fa fa-gears fa-5x"></i>
+ </div>
+ <div class="col-xs-6 text-right">
+ <p class="announcement-heading" wicket:id="jobsRunning">2</p>
+ <p class="announcement-text">Jobs running</p>
+ </div>
+ </div>
+ </div>
+ <a href="#non-existing-id" wicket:id="viewInstances">
+ <div class="panel-footer announcement-bottom">
+ <div class="row">
+ <div class="col-xs-6">View instances</div>
+ <div class="col-xs-6 text-right">
+ <i class="fa fa-arrow-circle-right"></i>
+ </div>
+ </div>
+ </div>
+ </a>
+ </div>
+ </div>
+ </div>
+ </wicket:extend>
+</body>
+</html>
diff --git a/src/java/org/apache/nutch/webui/pages/DashboardPage.java b/src/java/org/apache/nutch/webui/pages/DashboardPage.java
new file mode 100644
index 000000000..e370d6e20
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/DashboardPage.java
@@ -0,0 +1,56 @@
+/**
+ * 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.webui.pages;
+
+import org.apache.nutch.webui.client.model.NutchStatus;
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.pages.instances.InstancesPage;
+import org.apache.nutch.webui.service.NutchService;
+import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.spring.injection.annot.SpringBean;
+import org.apache.wicket.util.time.Duration;
+
+public class DashboardPage extends AbstractBasePage<Object> {
+ @SpringBean
+ private NutchService nutchService;
+
+ private WebMarkupContainer panel;
+
+ public DashboardPage() {
+ panel = new WebMarkupContainer("panel");
+ panel.setOutputMarkupId(true);
+ panel.add(new AjaxSelfUpdatingTimerBehavior(Duration.ONE_SECOND));
+ panel.add(new Label("jobsRunning", new JobsModel()));
+ add(panel);
+ add(new BookmarkablePageLink<Void>("viewInstances", InstancesPage.class));
+
+ }
+
+ private class JobsModel extends LoadableDetachableModel<Integer> {
+ @Override
+ protected Integer load() {
+ NutchInstance currentInstance = getCurrentInstance();
+ Long id = currentInstance.getId();
+ NutchStatus nutchStatus = nutchService.getNutchStatus(id);
+ return nutchStatus.getRunningJobs().size();
+ }
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/pages/LogOutPage.java b/src/java/org/apache/nutch/webui/pages/LogOutPage.java
new file mode 100644
index 000000000..9d0298fac
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/LogOutPage.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.webui.pages;
+
+public class LogOutPage extends AbstractBasePage {
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/SchedulingPage.java b/src/java/org/apache/nutch/webui/pages/SchedulingPage.java
new file mode 100644
index 000000000..54876a46c
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/SchedulingPage.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.webui.pages;
+
+public class SchedulingPage extends AbstractBasePage {
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/SearchPage.java b/src/java/org/apache/nutch/webui/pages/SearchPage.java
new file mode 100644
index 000000000..4a5a7363b
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/SearchPage.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.webui.pages;
+
+public class SearchPage extends AbstractBasePage {
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/StatisticsPage.java b/src/java/org/apache/nutch/webui/pages/StatisticsPage.java
new file mode 100644
index 000000000..048fb3c09
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/StatisticsPage.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.webui.pages;
+
+public class StatisticsPage extends AbstractBasePage {
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/UrlsUploadPage.java b/src/java/org/apache/nutch/webui/pages/UrlsUploadPage.java
new file mode 100644
index 000000000..e7c1b28f0
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/UrlsUploadPage.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.webui.pages;
+
+public class UrlsUploadPage extends AbstractBasePage {
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/UserSettingsPage.java b/src/java/org/apache/nutch/webui/pages/UserSettingsPage.java
new file mode 100644
index 000000000..3e6496386
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/UserSettingsPage.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.webui.pages;
+
+public class UserSettingsPage extends AbstractBasePage {
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/assets/NutchUiCssReference.java b/src/java/org/apache/nutch/webui/pages/assets/NutchUiCssReference.java
new file mode 100644
index 000000000..52fe98e1e
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/assets/NutchUiCssReference.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.webui.pages.assets;
+
+import org.apache.wicket.request.resource.CssResourceReference;
+
+public class NutchUiCssReference extends CssResourceReference {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Singleton instance of this reference
+ */
+ private static final NutchUiCssReference INSTANCE = new NutchUiCssReference();
+
+ public static NutchUiCssReference instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Private constructor.
+ */
+ private NutchUiCssReference() {
+ super(NutchUiCssReference.class, "nutch-style.css");
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/pages/assets/nutch-style.css b/src/java/org/apache/nutch/webui/pages/assets/nutch-style.css
new file mode 100644
index 000000000..8cc01ac09
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/assets/nutch-style.css
@@ -0,0 +1,149 @@
+/**
+ * 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.
+ */
+@CHARSET "UTF-8";
+
+body {
+ margin-top: 50px;
+}
+
+#wrapper {
+ padding-left: 0;
+}
+
+#page-wrapper {
+ width: 100%;
+ padding: 5px 15px;
+}
+
+/* Nav Messages */
+.messages-dropdown .dropdown-menu .message-preview .avatar,.messages-dropdown .dropdown-menu .message-preview .name,.messages-dropdown .dropdown-menu .message-preview .message,.messages-dropdown .dropdown-menu .message-preview .time
+ {
+ display: block;
+}
+
+.messages-dropdown .dropdown-menu .message-preview .avatar {
+ float: left;
+ margin-right: 15px;
+}
+
+.messages-dropdown .dropdown-menu .message-preview .name {
+ font-weight: bold;
+}
+
+.messages-dropdown .dropdown-menu .message-preview .message {
+ font-size: 12px;
+}
+
+.messages-dropdown .dropdown-menu .message-preview .time {
+ font-size: 12px;
+}
+
+/* Nav Announcements */
+.announcement-heading {
+ font-size: 50px;
+ margin: 0;
+}
+
+.announcement-text {
+ margin: 0;
+}
+
+/* Table Headers */
+table.tablesorter thead {
+ cursor: pointer;
+}
+
+table.tablesorter thead tr th:hover {
+ background-color: #f5f5f5;
+}
+
+/* Flot Chart Containers */
+.flot-chart {
+ display: block;
+ height: 400px;
+}
+
+.flot-chart-content {
+ width: 100%;
+ height: 100%;
+}
+
+/* Edit Below to Customize Widths > 768px */
+@media ( min-width :768px) {
+ /* Wrappers */
+ #wrapper {
+ padding-left: 225px;
+ }
+ #page-wrapper {
+ padding: 15px 25px;
+ }
+
+ /* Side Nav */
+ .side-nav {
+ margin-left: -225px;
+ left: 225px;
+ width: 225px;
+ position: fixed;
+ top: 50px;
+ height: 100%;
+ border-radius: 0;
+ border: none;
+ background-color: #222222;
+ overflow-y: auto;
+ }
+
+ /* Bootstrap Default Overrides - Customized Dropdowns for the Side Nav */
+ .side-nav>li.dropdown>ul.dropdown-menu {
+ position: relative;
+ min-width: 225px;
+ margin: 0;
+ padding: 0;
+ border: none;
+ border-radius: 0;
+ background-color: transparent;
+ box-shadow: none;
+ -webkit-box-shadow: none;
+ }
+ .side-nav>li.dropdown>ul.dropdown-menu>li>a {
+ color: #999999;
+ padding: 15px 15px 15px 25px;
+ }
+ .side-nav>li.dropdown>ul.dropdown-menu>li>a:hover,.side-nav>li.dropdown>ul.dropdown-menu>li>a.active,.side-nav>li.dropdown>ul.dropdown-menu>li>a:focus
+ {
+ color: #fff;
+ background-color: #080808;
+ }
+ .side-nav>li>a {
+ width: 225px;
+ }
+ .navbar-inverse .navbar-nav>li>a:hover,.navbar-inverse .navbar-nav>li>a:focus
+ {
+ background-color: #080808;
+ }
+
+ /* Nav Messages */
+ .messages-dropdown .dropdown-menu {
+ min-width: 300px;
+ }
+ .messages-dropdown .dropdown-menu li a {
+ white-space: normal;
+ }
+ .navbar-collapse {
+ padding-left: 15px !important;
+ padding-right: 15px !important;
+ }
+}
\ No newline at end of file
diff --git a/src/java/org/apache/nutch/webui/pages/components/ColorEnumLabel.java b/src/java/org/apache/nutch/webui/pages/components/ColorEnumLabel.java
new file mode 100644
index 000000000..f509bd524
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/components/ColorEnumLabel.java
@@ -0,0 +1,71 @@
+/**
+ * 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.webui.pages.components;
+
+import java.util.Map;
+
+import org.apache.wicket.markup.html.basic.EnumLabel;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.model.IModel;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelBehavior;
+import de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelType;
+
+/**
+ * Label which renders connection status as bootstrap label
+ *
+ * @author feodor
+ *
+ */
+public class ColorEnumLabel<E extends Enum<E>> extends EnumLabel<E> {
+ private Map<E, LabelType> labelTypeMap;
+
+ ColorEnumLabel(String id, IModel<E> model, Map<E, LabelType> labelTypeMap) {
+ super(id, model);
+ this.labelTypeMap = labelTypeMap;
+ }
+
+ @Override
+ protected void onInitialize() {
+ super.onInitialize();
+ setOutputMarkupId(true);
+ add(new LabelBehavior(new EnumCssModel(getModel())));
+ }
+
+ private class EnumCssModel extends AbstractReadOnlyModel<LabelType> {
+ private IModel<E> model;
+
+ public EnumCssModel(IModel<E> model) {
+ this.model = model;
+ }
+
+ @Override
+ public LabelType getObject() {
+ LabelType labelType = labelTypeMap.get(model.getObject());
+ if (labelType == null) {
+ return LabelType.Default;
+ }
+ return labelType;
+ }
+ }
+
+ public static <E extends Enum<E>> ColorEnumLabelBuilder<E> getBuilder(
+ String id) {
+ return new ColorEnumLabelBuilder<E>(id);
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/components/ColorEnumLabelBuilder.java b/src/java/org/apache/nutch/webui/pages/components/ColorEnumLabelBuilder.java
new file mode 100644
index 000000000..3ddaede7a
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/components/ColorEnumLabelBuilder.java
@@ -0,0 +1,49 @@
+/**
+ * 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.webui.pages.components;
+
+import java.util.Map;
+
+import org.apache.wicket.model.IModel;
+
+import com.google.common.collect.Maps;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelType;
+
+public class ColorEnumLabelBuilder<E extends Enum<E>> {
+ private Map<E, LabelType> labelTypeMap = Maps.newHashMap();
+ private IModel<E> model;
+ private String id;
+
+ public ColorEnumLabelBuilder(String id) {
+ this.id = id;
+ }
+
+ public ColorEnumLabelBuilder<E> withModel(IModel<E> model) {
+ this.model = model;
+ return this;
+ }
+
+ public ColorEnumLabelBuilder<E> withEnumColor(E e, LabelType type) {
+ labelTypeMap.put(e, type);
+ return this;
+ }
+
+ public ColorEnumLabel<E> build() {
+ return new ColorEnumLabel<E>(id, model, labelTypeMap);
+ }
+}
\ No newline at end of file
diff --git a/src/java/org/apache/nutch/webui/pages/components/CpmIteratorAdapter.java b/src/java/org/apache/nutch/webui/pages/components/CpmIteratorAdapter.java
new file mode 100644
index 000000000..91874c3ea
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/components/CpmIteratorAdapter.java
@@ -0,0 +1,41 @@
+/**
+ * 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.webui.pages.components;
+
+import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+
+/**
+ * This is iterator adapter, which wraps iterable items with
+ * CompoundPropertyModel.
+ *
+ * @author feodor
+ *
+ * @param <T>
+ */
+public class CpmIteratorAdapter<T> extends ModelIteratorAdapter<T> {
+ public CpmIteratorAdapter(Iterable<T> iterable) {
+ super(iterable);
+ }
+
+ @Override
+ protected IModel<T> model(T object) {
+ return new CompoundPropertyModel<T>(object);
+ }
+
+}
\ No newline at end of file
diff --git a/src/java/org/apache/nutch/webui/pages/crawls/CrawlPanel.html b/src/java/org/apache/nutch/webui/pages/crawls/CrawlPanel.html
new file mode 100644
index 000000000..81095f011
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/crawls/CrawlPanel.html
@@ -0,0 +1,58 @@
+<!-- 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. -->
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+<meta charset="utf-8" />
+<title>Wicket extend</title>
+</head>
+
+<body>
+ <wicket:extend>
+ <div wicket:id="notificationPanel"></div>
+
+ <form class="form-horizontal" wicket:id="crawlForm">
+ <div class="form-group">
+ <label for="inputEmail" class="control-label col-xs-2">Crawl id</label>
+ <div class="col-xs-10">
+ <span wicket:id="crawlId">123-1321-123</span>
+ </div>
+ </div>
+ <div class="form-group">
+ <label for="seedDir" class="control-label col-xs-2">Crawl name</label>
+ <div class="col-xs-10">
+ <input class="form-control" id="seedDir" wicket:id="crawlName" placeholder="Crawl name">
+ </div>
+ </div>
+ <div class="form-group">
+ <label for="seedDir" class="control-label col-xs-2">Seed list</label>
+ <div class="col-xs-10">
+ <select wicket:id="seedList">
+ <option>Google list</option>
+ <option>Yahoo list</option>
+ </select>
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label for="numberOfRounds" class="control-label col-xs-2">Rounds</label>
+ <div class="col-xs-10">
+ <select wicket:id="numberOfRounds">
+ <option>1</option>
+ <option>2</option>
+ </select>
+ </div>
+ </div>
+ </form>
+
+ </wicket:extend>
+</body>
+</html>
diff --git a/src/java/org/apache/nutch/webui/pages/crawls/CrawlPanel.java b/src/java/org/apache/nutch/webui/pages/crawls/CrawlPanel.java
new file mode 100644
index 000000000..be2cf42c4
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/crawls/CrawlPanel.java
@@ -0,0 +1,98 @@
+/**
+ * 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.webui.pages.crawls;
+
+import java.util.List;
+
+import org.apache.nutch.webui.client.model.Crawl;
+import org.apache.nutch.webui.model.SeedList;
+import org.apache.nutch.webui.service.CrawlService;
+import org.apache.nutch.webui.service.SeedListService;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.ChoiceRenderer;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.spring.injection.annot.SpringBean;
+
+import com.google.common.collect.Lists;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
+import de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapForm;
+
+public class CrawlPanel extends Modal {
+ private static final int MAX_ROUNDS = 10;
+
+ private BootstrapForm<Crawl> form;
+
+ @SpringBean
+ private CrawlService crawlService;
+
+ @SpringBean
+ private SeedListService seedListService;
+
+ private NotificationPanel notificationPanel;
+
+ public CrawlPanel(String markupId) {
+ super(markupId);
+ header(Model.of("Crawl"));
+
+ notificationPanel = new NotificationPanel("notificationPanel");
+ notificationPanel.setOutputMarkupId(true);
+ add(notificationPanel);
+
+ form = new BootstrapForm<Crawl>("crawlForm");
+ form.add(new Label("crawlId"));
+ form.add(new TextField<String>("crawlName").setRequired(true));
+
+ form.add(new DropDownChoice<Integer>("numberOfRounds", getNumbersOfRounds()));
+ form.add(new DropDownChoice<SeedList>("seedList",
+ seedListService.findAll(), new ChoiceRenderer<SeedList>("name"))
+ .setRequired(true));
+
+ addButton(new AjaxSubmitLink("button", form) {
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> ajaxForm) {
+ crawlService.saveCrawl(form.getModelObject());
+ target.add(this.getPage());
+ }
+
+ protected void onError(AjaxRequestTarget target, Form<?> form) {
+ target.add(notificationPanel);
+ };
+ }.setBody(Model.of("Save")));
+ add(form);
+ }
+
+ public void setModel(IModel<Crawl> model) {
+ form.setModel(model);
+ }
+
+ private List<Integer> getNumbersOfRounds() {
+ List<Integer> numbers = Lists.newArrayList();
+ for (int i = 1; i <= MAX_ROUNDS; i++) {
+ numbers.add(i);
+ }
+ return numbers;
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/crawls/CrawlsPage.html b/src/java/org/apache/nutch/webui/pages/crawls/CrawlsPage.html
new file mode 100644
index 000000000..3c5d789ac
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/crawls/CrawlsPage.html
@@ -0,0 +1,90 @@
+<!-- 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. -->
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+<meta charset="utf-8" />
+<title>Wicket extend</title>
+</head>
+
+<body>
+ <wicket:extend>
+ <h2>
+ <wicket:message key="navbar.menu.crawls">Crawls</wicket:message>
+ </h2>
+
+ <div class="row">
+ <div class="col-lg-8">
+ <div class="row">
+ <div class="col-lg-8 col-md-offset-10">
+ <button class="btn btn-success btn-default" wicket:id="newCrawl">
+ <i class="fa fa-plus"></i> Add new crawl
+ </button>
+ </div>
+ </div>
+ <table class="table table-hover table-striped tablesorter">
+ <thead>
+ <tr>
+ <th class="header col-md-2">Crawl name</th>
+ <th class="header col-md-2">Seed list</th>
+ <th class="header col-md-2">Status</th>
+ <th class="header col-md-2">Progress</th>
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody wicket:id="crawlsTable">
+ <tr wicket:id="crawls">
+ <td>
+ <a href="#" data-toggle="modal" data-target="#crawlInfo" wicket:id="edit">
+ <span wicket:id="crawlName">Crawl name</span>
+ </a>
+ </td>
+ <td>
+ <span wicket:id="seedList.name">Google list</span>
+ </td>
+ <td>
+ <span wicket:id="status" class="label">Finished</span>
+ </td>
+ <td>
+ <span wicket:id="progress">50</span>
+ %
+
+ </td>
+
+ <td>
+ <button class="btn btn-sm btn-default" type="button" wicket:id="start">
+ <span class="fa fa-play"></span>
+ </button>
+ <button class="btn btn-sm btn-danger" type="button" wicket:id="delete">
+ <span class="fa fa-trash-o"></span>
+ </button>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <div wicket:id="crawl"></div>
+ </div>
+ <div class="col-lg-4">
+ <div class="panel panel-primary">
+ <div class="panel-heading">
+ <h3 class="panel-title">Help</h3>
+ </div>
+ <div class="panel-body">
+ <p>Some help about crawling</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ <!--row-->
+ </wicket:extend>
+</body>
+</html>
diff --git a/src/java/org/apache/nutch/webui/pages/crawls/CrawlsPage.java b/src/java/org/apache/nutch/webui/pages/crawls/CrawlsPage.java
new file mode 100644
index 000000000..5117520c5
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/crawls/CrawlsPage.java
@@ -0,0 +1,139 @@
+/**
+ * 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.webui.pages.crawls;
+
+import static de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelType.Danger;
+import static de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelType.Default;
+import static de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelType.Info;
+import static de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelType.Success;
+import static org.apache.nutch.webui.client.model.Crawl.CrawlStatus.CRAWLING;
+import static org.apache.nutch.webui.client.model.Crawl.CrawlStatus.ERROR;
+import static org.apache.nutch.webui.client.model.Crawl.CrawlStatus.FINISHED;
+import static org.apache.nutch.webui.client.model.Crawl.CrawlStatus.NEW;
+
+import java.util.Iterator;
+
+import org.apache.nutch.webui.client.model.Crawl;
+import org.apache.nutch.webui.client.model.Crawl.CrawlStatus;
+import org.apache.nutch.webui.pages.AbstractBasePage;
+import org.apache.nutch.webui.pages.components.ColorEnumLabelBuilder;
+import org.apache.nutch.webui.pages.components.CpmIteratorAdapter;
+import org.apache.nutch.webui.service.CrawlService;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.EnumLabel;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.RefreshingView;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.spring.injection.annot.SpringBean;
+import org.apache.wicket.util.time.Duration;
+
+/**
+ * This page is for crawls management
+ *
+ * @author feodor
+ *
+ */
+public class CrawlsPage extends AbstractBasePage<Void> {
+
+ private static final Duration UPDATE_TIMEOUT = Duration.seconds(2);
+
+ @SpringBean
+ private CrawlService crawlService;
+
+ private WebMarkupContainer crawlsTable;
+ private CrawlPanel crawlPanel;
+
+ public CrawlsPage() {
+ crawlsTable = new WebMarkupContainer("crawlsTable");
+ crawlsTable.setOutputMarkupId(true);
+ crawlsTable.add(new AjaxSelfUpdatingTimerBehavior(UPDATE_TIMEOUT));
+
+ RefreshingView<Crawl> crawls = new RefreshingView<Crawl>("crawls") {
+
+ @Override
+ protected Iterator<IModel<Crawl>> getItemModels() {
+ return new CpmIteratorAdapter<Crawl>(crawlService.getCrawls());
+ }
+
+ @Override
+ protected void populateItem(Item<Crawl> item) {
+ populateCrawlRow(item);
+ }
+ };
+
+ crawlsTable.add(crawls);
+ add(crawlsTable);
+
+ crawlPanel = new CrawlPanel("crawl");
+ add(crawlPanel);
+
+ add(new AjaxLink<Crawl>("newCrawl") {
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ editCrawl(target, new CompoundPropertyModel<Crawl>(createNewCrawl()));
+ }
+ });
+ }
+
+ private void populateCrawlRow(Item<Crawl> item) {
+ item.add(new AjaxLink<Crawl>("edit", item.getModel()) {
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ editCrawl(target, getModel());
+ }
+ }.add(new Label("crawlName")));
+ item.add(new Label("seedList.name"));
+
+ item.add(new Label("progress"));
+ item.add(createStatusLabel());
+ item.add(new Link<Crawl>("start", item.getModel()) {
+ @Override
+ public void onClick() {
+ crawlService.startCrawl(getModelObject().getId(), getCurrentInstance());
+ }
+ });
+
+ item.add(new Link<Crawl>("delete", item.getModel()) {
+ @Override
+ public void onClick() {
+ crawlService.deleteCrawl(getModelObject().getId());
+ }
+ });
+ }
+
+ private void editCrawl(AjaxRequestTarget target, IModel<Crawl> model) {
+ crawlPanel.setModel(model);
+ target.add(crawlPanel);
+ crawlPanel.appendShowDialogJavaScript(target);
+ }
+
+ private Crawl createNewCrawl() {
+ return new Crawl();
+ }
+
+ private EnumLabel<CrawlStatus> createStatusLabel() {
+ return new ColorEnumLabelBuilder<CrawlStatus>("status")
+ .withEnumColor(NEW, Default).withEnumColor(ERROR, Danger)
+ .withEnumColor(FINISHED, Success).withEnumColor(CRAWLING, Info).build();
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/pages/instances/InstancePanel.html b/src/java/org/apache/nutch/webui/pages/instances/InstancePanel.html
new file mode 100644
index 000000000..cdbc24244
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/instances/InstancePanel.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Insert title here</title>
+</head>
+<body>
+ <wicket:extend>
+ <div wicket:id="notificationPanel"></div>
+ <form class="form-horizontal" wicket:id="instanceForm">
+ <div class="form-group">
+ <label class="control-label col-xs-2"><wicket:message key="instances.label.name">Instance name</wicket:message></label>
+ <div class="col-xs-10">
+ <input class="form-control" wicket:id="name" placeholder="Localhost instance">
+ </div>
+ </div>
+ <div class="form-group">
+ <label class="control-label col-xs-2"><wicket:message key="instances.label.hostname">Host</wicket:message></label>
+ <div class="col-xs-10">
+ <input class="form-control" wicket:id="host" placeholder="http://localhost:8080">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="control-label col-xs-2"><wicket:message key="instances.label.port">Port</wicket:message></label>
+ <div class="col-xs-10">
+ <input class="form-control" wicket:id="port" placeholder="http://localhost:8080">
+ </div>
+ </div>
+
+ <div class="form-group">
+ <label class="control-label col-xs-2"><wicket:message key="instances.label.username">Username</wicket:message></label>
+ <div class="col-xs-10">
+ <input class="form-control" wicket:id="username" placeholder="">
+ </div>
+ </div>
+ <div class="form-group">
+ <label class="control-label col-xs-2"><wicket:message key="instances.label.password">Password</wicket:message></label>
+ <div class="col-xs-10">
+ <input class="form-control" type="password" wicket:id="password" placeholder="">
+ </div>
+ </div>
+ </form>
+ </wicket:extend>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/java/org/apache/nutch/webui/pages/instances/InstancePanel.java b/src/java/org/apache/nutch/webui/pages/instances/InstancePanel.java
new file mode 100644
index 000000000..a03ec1d65
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/instances/InstancePanel.java
@@ -0,0 +1,62 @@
+package org.apache.nutch.webui.pages.instances;
+
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.service.NutchInstanceService;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.PasswordTextField;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.spring.injection.annot.SpringBean;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.common.NotificationPanel;
+import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
+import de.agilecoders.wicket.core.markup.html.bootstrap.form.BootstrapForm;
+
+public class InstancePanel extends Modal {
+
+ private BootstrapForm<NutchInstance> form;
+
+ private NotificationPanel notificationPanel;
+
+ @SpringBean
+ private NutchInstanceService instanceService;
+
+ public InstancePanel(String markupId) {
+ super(markupId);
+ header(Model.of("Instance"));
+
+ notificationPanel = new NotificationPanel("notificationPanel");
+ notificationPanel.setOutputMarkupId(true);
+ add(notificationPanel);
+
+ form = new BootstrapForm<NutchInstance>("instanceForm");
+ form.add(new TextField<String>("name").setRequired(true));
+ form.add(new TextField<String>("host").setRequired(true));
+ form.add(new TextField<Integer>("port").setRequired(true));
+ form.add(new TextField<String>("username"));
+ form.add(new PasswordTextField("password").setResetPassword(false)
+ .setRequired(false));
+
+ addButton(new AjaxSubmitLink("button", form) {
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> ajaxForm) {
+ instanceService.saveInstance(form.getModelObject());
+ target.add(this.getPage());
+
+ }
+
+ protected void onError(AjaxRequestTarget target, Form<?> form) {
+ target.add(notificationPanel);
+ };
+ }.setBody(Model.of("Save")));
+ add(form);
+ }
+
+ public void setModel(IModel<NutchInstance> model) {
+ form.setModel(model);
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/instances/InstancesPage.html b/src/java/org/apache/nutch/webui/pages/instances/InstancesPage.html
new file mode 100644
index 000000000..15e6ed80f
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/instances/InstancesPage.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="UTF-8">
+<title>Instances</title>
+</head>
+<body>
+ <wicket:extend>
+ <h2>
+ <wicket:message key="navbar.menu.instances">Instances</wicket:message>
+ </h2>
+ <div class="row">
+ <div class="col-lg-8">
+ <table class="table table-hover table-striped tablesorter">
+ <thead>
+ <tr>
+ <th class="header col-md-2"><wicket:message key="instances.header.name">Name</wicket:message></th>
+ <th class="header col-md-2"><wicket:message key="instances.header.hostname">Host</wicket:message></th>
+ <th class="header col-md-2"><wicket:message key="instances.header.username">Username</wicket:message></th>
+ <th class="header col-md-2"><wicket:message key="instances.header.status">Status</wicket:message></th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody wicket:id="instancesTable">
+ <tr wicket:id="instances">
+ <td>
+ <a href="#" data-toggle="modal" data-target="#instanceInfo" wicket:id="editInstance">
+ <span wicket:id="name">Instance name</span>
+ </a>
+ </td>
+ <td>
+ <span wicket:id="host">Host</span>
+ </td>
+ <td>
+ <span wicket:id="username">Username</span>
+ </td>
+ <td>
+ <span wicket:id="connectionStatus" class="label">Status</span>
+ </td>
+ <td>
+ <button class="btn btn-sm btn-danger" type="button" wicket:id="instanceDelete">
+ <span class="fa fa-trash-o"></span>
+ </button>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <div wicket:id="instanceForm"></div>
+ <button class="btn btn-sm btn-primary" wicket:id="addInstance">
+ <i class="fa fa-plus"></i> <wicket:message key="instances.buttons.addInstance">Add instance</wicket:message>
+ </button>
+ </div>
+ <div class="col-lg-4">
+ <div class="panel panel-primary">
+ <div class="panel-heading">
+ <h3 class="panel-title">Help</h3>
+ </div>
+ <div class="panel-body">
+ <p>Some help about crawling</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ </wicket:extend>
+</body>
+</html>
\ No newline at end of file
diff --git a/src/java/org/apache/nutch/webui/pages/instances/InstancesPage.java b/src/java/org/apache/nutch/webui/pages/instances/InstancesPage.java
new file mode 100644
index 000000000..10db153da
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/instances/InstancesPage.java
@@ -0,0 +1,111 @@
+package org.apache.nutch.webui.pages.instances;
+
+import static de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelType.Danger;
+import static de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelType.Info;
+import static de.agilecoders.wicket.core.markup.html.bootstrap.block.LabelType.Success;
+import static org.apache.nutch.webui.client.model.ConnectionStatus.CONNECTED;
+import static org.apache.nutch.webui.client.model.ConnectionStatus.CONNECTING;
+import static org.apache.nutch.webui.client.model.ConnectionStatus.DISCONNECTED;
+
+import java.util.Iterator;
+
+import org.apache.nutch.webui.client.model.ConnectionStatus;
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.pages.AbstractBasePage;
+import org.apache.nutch.webui.pages.components.ColorEnumLabel;
+import org.apache.nutch.webui.pages.components.ColorEnumLabelBuilder;
+import org.apache.nutch.webui.pages.components.CpmIteratorAdapter;
+import org.apache.nutch.webui.service.NutchInstanceService;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.RefreshingView;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.spring.injection.annot.SpringBean;
+import org.apache.wicket.util.time.Duration;
+
+public class InstancesPage extends AbstractBasePage<Void> {
+ @SpringBean
+ private NutchInstanceService instanceService;
+
+ private InstancePanel instancePanel;
+
+ private WebMarkupContainer instancesTable;
+ private static final Duration UPDATE_TIMEOUT = Duration.seconds(1);
+
+ public InstancesPage() {
+
+ instancesTable = new WebMarkupContainer("instancesTable");
+ instancesTable.setOutputMarkupId(true);
+ instancesTable.add(new AjaxSelfUpdatingTimerBehavior(UPDATE_TIMEOUT));
+
+ instancePanel = new InstancePanel("instanceForm");
+
+ RefreshingView<NutchInstance> instances = refreshingView();
+ instancesTable.add(instances);
+ add(instancesTable);
+ add(instancePanel);
+ add(addInstanceButton());
+ }
+
+ private RefreshingView<NutchInstance> refreshingView() {
+ RefreshingView<NutchInstance> instances = new RefreshingView<NutchInstance>(
+ "instances") {
+
+ @Override
+ protected Iterator<IModel<NutchInstance>> getItemModels() {
+ return new CpmIteratorAdapter<NutchInstance>(
+ instanceService.getInstances());
+ }
+
+ @Override
+ protected void populateItem(Item<NutchInstance> item) {
+ populateInstanceRow(item);
+ }
+ };
+ return instances;
+ }
+
+ private AjaxLink<NutchInstance> addInstanceButton() {
+ return new AjaxLink<NutchInstance>("addInstance") {
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ instancePanel.setModel(new CompoundPropertyModel<NutchInstance>(
+ new NutchInstance()));
+ target.add(instancePanel);
+ instancePanel.appendShowDialogJavaScript(target);
+ }
+ };
+ }
+
+ private void populateInstanceRow(final Item<NutchInstance> item) {
+ item.add(new AjaxLink<NutchInstance>("editInstance") {
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ instancePanel.setModel(item.getModel());
+ target.add(instancePanel);
+ instancePanel.appendShowDialogJavaScript(target);
+ }
+ }.add(new Label("name")));
+ item.add(new Label("host"));
+ item.add(new Label("username"));
+ item.add(createStatusLabel());
+ item.add(new AjaxLink<NutchInstance>("instanceDelete", item.getModel()) {
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ instanceService.removeInstance(getModelObject().getId());
+ target.add(instancesTable);
+ }
+ });
+ }
+
+ private ColorEnumLabel<ConnectionStatus> createStatusLabel() {
+ return new ColorEnumLabelBuilder<ConnectionStatus>("connectionStatus")
+ .withEnumColor(CONNECTED, Success).withEnumColor(CONNECTING, Info)
+ .withEnumColor(DISCONNECTED, Danger).build();
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/pages/menu/VerticalMenu.html b/src/java/org/apache/nutch/webui/pages/menu/VerticalMenu.html
new file mode 100644
index 000000000..32d6e01f6
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/menu/VerticalMenu.html
@@ -0,0 +1,48 @@
+<!-- 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. -->
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+<title>Navbar</title>
+</head>
+<body>
+ <wicket:panel>
+ <div class="fluid-container" wicket:id="container">
+ <!-- Brand and toggle get grouped for better mobile display -->
+ <div class="navbar-header">
+ <button type="button" class="navbar-toggle" data-toggle="collapse"
+ wicket:id="collapseButton">
+ <span class="sr-only" wicket:id="toggleNavigationLabel">[[CONTENT]]</span>
+ <span class="icon-bar"></span> <span class="icon-bar"></span> <span
+ class="icon-bar"></span>
+ </button>
+ <a wicket:id="brandName" class="navbar-brand" href="#"> <img
+ wicket:id="brandImage" /> <span wicket:id="brandLabel"></span>
+ </a>
+ </div>
+
+ <div class="collapse navbar-collapse navbar-ex1-collapse"
+ role="navigation" wicket:id="collapse">
+ <ul class="nav navbar-nav side-nav">
+ <li wicket:id="navLeftList">
+ <div wicket:id="component">[[CONTENT]]</div>
+ </li>
+ </ul>
+ <ul wicket:enclosure="navRightList"
+ class="nav navbar-nav navbar-right">
+ <li wicket:id="navRightList">
+ <div wicket:id="component">[[CONTENT]]</div>
+ </li>
+ </ul>
+ </div>
+ </div>
+ </wicket:panel>
+</body>
+</html>
diff --git a/src/java/org/apache/nutch/webui/pages/menu/VerticalMenu.java b/src/java/org/apache/nutch/webui/pages/menu/VerticalMenu.java
new file mode 100644
index 000000000..9783d47eb
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/menu/VerticalMenu.java
@@ -0,0 +1,28 @@
+/**
+ * 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.webui.pages.menu;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.navbar.Navbar;
+
+public class VerticalMenu extends Navbar {
+
+ public VerticalMenu(String componentId) {
+ super(componentId);
+ // TODO Auto-generated constructor stub
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/seed/SeedListsPage.html b/src/java/org/apache/nutch/webui/pages/seed/SeedListsPage.html
new file mode 100644
index 000000000..f9aff875f
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/seed/SeedListsPage.html
@@ -0,0 +1,75 @@
+<!-- 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. -->
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+<meta charset="utf-8" />
+<title>Wicket extend</title>
+</head>
+
+<body>
+ <wicket:extend>
+ <h2>
+ <wicket:message key="navbar.menu.seedLists">Seed lists</wicket:message>
+ </h2>
+
+ <div class="row">
+ <div class="col-lg-8">
+ <div class="row">
+ <div class="col-lg-8 col-md-offset-10">
+ <button class="btn btn-success btn-default" wicket:id="newSeedList">
+ <i class="fa fa-plus"></i> Add new list
+ </button>
+ </div>
+ </div>
+ <table class="table table-hover table-striped tablesorter">
+ <thead>
+ <tr>
+ <th class="header col-md-3">Name</th>
+ <th class="header col-md-2">Urls</th>
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody>
+ <tr wicket:id="seedLists">
+ <td>
+ <a href="#" wicket:id="edit">
+ <span wicket:id="name">List name</span>
+ </a>
+ </td>
+ <td>
+ <span wicket:id="seedUrlsCount">10</span>
+ </td>
+ <td>
+ <button class="btn btn-sm btn-danger" type="button" wicket:id="delete">
+ <span class="fa fa-trash-o"></span>
+ </button>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ <div class="col-lg-4">
+ <div class="panel panel-primary">
+ <div class="panel-heading">
+ <h3 class="panel-title">Help</h3>
+ </div>
+ <div class="panel-body">
+ <p>Some help about seed lists</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ <!--row-->
+ </wicket:extend>
+</body>
+</html>
diff --git a/src/java/org/apache/nutch/webui/pages/seed/SeedListsPage.java b/src/java/org/apache/nutch/webui/pages/seed/SeedListsPage.java
new file mode 100644
index 000000000..c5ac288c7
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/seed/SeedListsPage.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.webui.pages.seed;
+
+import java.util.Iterator;
+
+import org.apache.nutch.webui.model.SeedList;
+import org.apache.nutch.webui.pages.AbstractBasePage;
+import org.apache.nutch.webui.pages.components.CpmIteratorAdapter;
+import org.apache.nutch.webui.service.SeedListService;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.link.BookmarkablePageLink;
+import org.apache.wicket.markup.html.link.Link;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.RefreshingView;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.spring.injection.annot.SpringBean;
+
+/**
+ * This page is for seed lists management
+ *
+ * @author feodor
+ *
+ */
+public class SeedListsPage extends AbstractBasePage<Void> {
+
+ @SpringBean
+ private SeedListService seedListService;
+
+ public SeedListsPage() {
+
+ RefreshingView<SeedList> seedLists = new RefreshingView<SeedList>(
+ "seedLists") {
+
+ @Override
+ protected Iterator<IModel<SeedList>> getItemModels() {
+ return new CpmIteratorAdapter<SeedList>(seedListService.findAll());
+ }
+
+ @Override
+ protected void populateItem(final Item<SeedList> item) {
+ PageParameters params = new PageParameters();
+ params.add("id", item.getModelObject().getId());
+
+ Link<Void> edit = new BookmarkablePageLink<Void>("edit",
+ SeedPage.class, params);
+ edit.add(new Label("name"));
+ item.add(edit);
+
+ item.add(new Label("seedUrlsCount"));
+
+ item.add(new Link<SeedList>("delete", item.getModel()) {
+ @Override
+ public void onClick() {
+ seedListService.delete(item.getModelObject().getId());
+ }
+ });
+ }
+ };
+
+ add(seedLists);
+ add(new BookmarkablePageLink<Void>("newSeedList", SeedPage.class));
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/pages/seed/SeedPage.html b/src/java/org/apache/nutch/webui/pages/seed/SeedPage.html
new file mode 100644
index 000000000..d6f33a39a
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/seed/SeedPage.html
@@ -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. -->
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+<meta charset="utf-8" />
+<title>Wicket extend</title>
+</head>
+
+<body>
+ <wicket:extend>
+ <h2>
+ <wicket:message key="page.header.seedList">Seed list</wicket:message>
+ </h2>
+
+ <div class="row">
+ <div class="col-lg-8">
+ <form class="form-horizontal" wicket:id="seedList">
+ <fieldset>
+ <!-- Text input-->
+ <div class="form-group">
+ <label class="col-md-4 control-label" for="textinput">Seed list name</label>
+ <div class="col-md-4">
+ <input wicket:id="name" name="textinput" class="form-control input-md" type="text">
+ </div>
+ </div>
+ <div class="form-group">
+ <div class="col-md-offset-4 col-md-4">
+ <button type="submit" class="btn btn-primary">Save</button>
+ </div>
+ </div>
+ </fieldset>
+ </form>
+ <h3>Seed urls</h3>
+ <table class="table table-hover table-striped tablesorter">
+ <thead>
+ <tr>
+ <th class="header col-md-3">Url</th>
+ <th></th>
+ </tr>
+ </thead>
+
+ <tbody wicket:id="seedUrlsTable">
+ <tr wicket:id="seedUrls">
+ <td>
+ <span wicket:id="url">http://google.com</span>
+ </td>
+ <td>
+ <button wicket:id="delete" class="btn btn-sm btn-danger" type="button">
+ <span class="fa fa-trash-o"></span>
+ </button>
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ <form class="form-horizontal" wicket:id="urlForm">
+ <fieldset>
+ <div class="form-group">
+ <div class="col-md-4">
+ <input wicket:id="url" name="textinput" class="form-control input-md" type="text">
+ </div>
+ <div>
+ <button wicket:id="addUrl" class="btn btn-primary">Add url</button>
+ </div>
+ </div>
+ </fieldset>
+ </form>
+ </div>
+ <div class="col-lg-4">
+ <div class="panel panel-primary">
+ <div class="panel-heading">
+ <h3 class="panel-title">Help</h3>
+ </div>
+ <div class="panel-body">
+ <p>Some help about seed management</p>
+ </div>
+ </div>
+ </div>
+ </div>
+ <!--row-->
+ </wicket:extend>
+</body>
+</html>
diff --git a/src/java/org/apache/nutch/webui/pages/seed/SeedPage.java b/src/java/org/apache/nutch/webui/pages/seed/SeedPage.java
new file mode 100644
index 000000000..fba07abda
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/seed/SeedPage.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.webui.pages.seed;
+
+import java.util.Iterator;
+
+import org.apache.nutch.webui.model.SeedList;
+import org.apache.nutch.webui.model.SeedUrl;
+import org.apache.nutch.webui.pages.AbstractBasePage;
+import org.apache.nutch.webui.pages.components.CpmIteratorAdapter;
+import org.apache.nutch.webui.service.SeedListService;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.ajax.markup.html.form.AjaxSubmitLink;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.RefreshingView;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.spring.injection.annot.SpringBean;
+
+import com.google.common.collect.Lists;
+
+/**
+ * This page is for seed urls management
+ *
+ * @author feodor
+ *
+ */
+public class SeedPage extends AbstractBasePage<SeedList> {
+
+ @SpringBean
+ private SeedListService seedListService;
+
+ private Form<SeedUrl> urlForm;
+
+ private WebMarkupContainer seedUrlsTable;
+
+ public SeedPage() {
+ SeedList list = new SeedList();
+ list.setSeedUrls(Lists.<SeedUrl> newArrayList());
+ initPage(Model.of(list));
+ }
+
+ public SeedPage(final PageParameters parameters) {
+ initPage(new LoadableDetachableModel<SeedList>() {
+
+ @Override
+ protected SeedList load() {
+ Long seedListId = parameters.get("id").toLongObject();
+ return seedListService.getSeedList(seedListId);
+ }
+ });
+ }
+
+ public void initPage(IModel<SeedList> model) {
+ setModel(new CompoundPropertyModel<SeedList>(model));
+
+ addBaseForm();
+ addSeedUrlsList();
+ addUrlForm();
+ }
+
+ private void addBaseForm() {
+ Form<SeedList> form = new Form<SeedList>("seedList", getModel()) {
+ @Override
+ protected void onSubmit() {
+ seedListService.save(getModelObject());
+ setResponsePage(SeedListsPage.class);
+ }
+ };
+ form.add(new TextField<String>("name"));
+ add(form);
+ }
+
+ private void addSeedUrlsList() {
+ seedUrlsTable = new WebMarkupContainer("seedUrlsTable");
+ seedUrlsTable.setOutputMarkupId(true);
+
+ RefreshingView<SeedUrl> seedUrls = new RefreshingView<SeedUrl>("seedUrls") {
+
+ @Override
+ protected Iterator<IModel<SeedUrl>> getItemModels() {
+ return new CpmIteratorAdapter<SeedUrl>(getModelObject().getSeedUrls());
+ }
+
+ @Override
+ protected void populateItem(Item<SeedUrl> item) {
+ item.add(new Label("url"));
+ item.add(new AjaxLink<SeedUrl>("delete", item.getModel()) {
+
+ @Override
+ public void onClick(AjaxRequestTarget target) {
+ deleteSeedUrl(getModelObject());
+ target.add(seedUrlsTable);
+ }
+ });
+ }
+ };
+ seedUrlsTable.add(seedUrls);
+ add(seedUrlsTable);
+ }
+
+ private void addUrlForm() {
+ urlForm = new Form<SeedUrl>("urlForm", CompoundPropertyModel.of(Model
+ .of(new SeedUrl())));
+ urlForm.setOutputMarkupId(true);
+ urlForm.add(new TextField<String>("url"));
+ urlForm.add(new AjaxSubmitLink("addUrl", urlForm) {
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ addSeedUrl();
+ urlForm.setModelObject(new SeedUrl());
+ target.add(urlForm);
+ target.add(seedUrlsTable);
+ }
+ });
+ add(urlForm);
+ }
+
+ private void addSeedUrl() {
+ SeedUrl url = urlForm.getModelObject();
+ SeedList seedList = getModelObject();
+ url.setSeedList(seedList);
+ seedList.getSeedUrls().add(url);
+ }
+
+ private void deleteSeedUrl(SeedUrl url) {
+ SeedList seedList = getModelObject();
+ seedList.getSeedUrls().remove(url);
+ }
+
+}
diff --git a/src/java/org/apache/nutch/webui/pages/settings/SettingsPage.html b/src/java/org/apache/nutch/webui/pages/settings/SettingsPage.html
new file mode 100644
index 000000000..88103712c
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/settings/SettingsPage.html
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html xmlns:wicket="http://wicket.apache.org">
+<head>
+<meta charset="utf-8" />
+<title>Wicket extend</title>
+</head>
+
+<body>
+ <wicket:extend>
+ <h2>
+ <wicket:message key="settings">Settings</wicket:message>
+ </h2>
+ <div class="row">
+ <div class="col-lg-12">
+ <table class="table table-hover tablesorter table-bordered">
+ <thead>
+ <tr>
+ <th class="header col-lg-3">
+ <wicket:message key="settings.header.name">Name</wicket:message>
+ </th>
+ <th class="header col-lg-9">
+ <wicket:message key="settings.header.value">Value</wicket:message>
+ </th>
+ </tr>
+ </thead>
+ <tbody wicket:id="settingsTable">
+ <tr wicket:id="settings">
+ <td>
+ <span wicket:id="name">Name</span>
+ </td>
+ <td>
+<!-- <span wicket:id="value">Value</span> -->
+ <input class="col-lg-12" wicket:id="value" placeholder="http://localhost:8080">
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </wicket:extend>
+
+</body>
+</html>
diff --git a/src/java/org/apache/nutch/webui/pages/settings/SettingsPage.java b/src/java/org/apache/nutch/webui/pages/settings/SettingsPage.java
new file mode 100644
index 000000000..29e46f7a9
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/pages/settings/SettingsPage.java
@@ -0,0 +1,59 @@
+package org.apache.nutch.webui.pages.settings;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.nutch.webui.model.NutchConfig;
+import org.apache.nutch.webui.pages.AbstractBasePage;
+import org.apache.nutch.webui.pages.components.CpmIteratorAdapter;
+import org.apache.nutch.webui.service.NutchService;
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.RefreshingView;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.spring.injection.annot.SpringBean;
+
+public class SettingsPage extends AbstractBasePage<Void> {
+ @SpringBean
+ private NutchService nutchService;
+
+ private WebMarkupContainer settingsTable;
+
+ public SettingsPage() {
+ settingsTable = new WebMarkupContainer("settingsTable");
+ settingsTable.setOutputMarkupId(true);
+ RefreshingView<NutchConfig> nutchConfig = new RefreshingView<NutchConfig>(
+ "settings") {
+
+ @Override
+ protected Iterator<IModel<NutchConfig>> getItemModels() {
+ return new CpmIteratorAdapter<NutchConfig>(
+ convertNutchConfig(nutchService.getNutchConfig(getCurrentInstance()
+ .getId())));
+ }
+
+ @Override
+ protected void populateItem(Item<NutchConfig> item) {
+ item.add(new Label("name"));
+ item.add(new TextField<String>("value"));
+ }
+ };
+ settingsTable.add(nutchConfig);
+ add(settingsTable);
+ }
+
+ private List<NutchConfig> convertNutchConfig(Map<String, String> map) {
+ List<NutchConfig> listNutchConfigs = new LinkedList<NutchConfig>();
+ for (String key : map.keySet()) {
+ NutchConfig conf = new NutchConfig();
+ conf.setName(key);
+ conf.setValue(map.get(key));
+ listNutchConfigs.add(conf);
+ }
+ return listNutchConfigs;
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/service/CrawlService.java b/src/java/org/apache/nutch/webui/service/CrawlService.java
new file mode 100644
index 000000000..c742b48c9
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/service/CrawlService.java
@@ -0,0 +1,33 @@
+/**
+ * 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.webui.service;
+
+import java.util.List;
+
+import org.apache.nutch.webui.client.model.Crawl;
+import org.apache.nutch.webui.model.NutchInstance;
+
+public interface CrawlService {
+
+ public void saveCrawl(Crawl crawl);
+
+ public List<Crawl> getCrawls();
+
+ void startCrawl(Long crawlId, NutchInstance instance);
+
+ void deleteCrawl(Long crawlId);
+}
diff --git a/src/java/org/apache/nutch/webui/service/NutchInstanceService.java b/src/java/org/apache/nutch/webui/service/NutchInstanceService.java
new file mode 100644
index 000000000..23f27e84d
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/service/NutchInstanceService.java
@@ -0,0 +1,33 @@
+/**
+ * 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.webui.service;
+
+import java.util.List;
+
+import org.apache.nutch.webui.model.NutchInstance;
+
+public interface NutchInstanceService {
+
+ public List<NutchInstance> getInstances();
+
+ public void saveInstance(NutchInstance instance);
+
+ public void removeInstance(Long id);
+
+ public NutchInstance getInstance(Long id);
+
+}
diff --git a/src/java/org/apache/nutch/webui/service/NutchService.java b/src/java/org/apache/nutch/webui/service/NutchService.java
new file mode 100644
index 000000000..643236aa3
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/service/NutchService.java
@@ -0,0 +1,31 @@
+/**
+ * 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.webui.service;
+
+import java.util.Map;
+
+import org.apache.nutch.webui.client.model.ConnectionStatus;
+import org.apache.nutch.webui.client.model.NutchStatus;
+
+public interface NutchService {
+ public ConnectionStatus getConnectionStatus(Long instanceId);
+
+ public Map<String, String> getNutchConfig(Long instanceId);
+
+ public NutchStatus getNutchStatus(Long instanceId);
+
+}
diff --git a/src/java/org/apache/nutch/webui/service/SeedListService.java b/src/java/org/apache/nutch/webui/service/SeedListService.java
new file mode 100644
index 000000000..dda8c7185
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/service/SeedListService.java
@@ -0,0 +1,33 @@
+/**
+ * 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.webui.service;
+
+import java.util.List;
+
+import org.apache.nutch.webui.model.SeedList;
+
+public interface SeedListService {
+
+ public void save(SeedList seedList);
+
+ public void delete(Long seedListId);
+
+ public List<SeedList> findAll();
+
+ public SeedList getSeedList(Long seedListId);
+
+}
diff --git a/src/java/org/apache/nutch/webui/service/impl/CrawlServiceImpl.java b/src/java/org/apache/nutch/webui/service/impl/CrawlServiceImpl.java
new file mode 100644
index 000000000..7bb133b49
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/service/impl/CrawlServiceImpl.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.webui.service.impl;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.nutch.webui.client.NutchClient;
+import org.apache.nutch.webui.client.NutchClientFactory;
+import org.apache.nutch.webui.client.impl.CrawlingCycle;
+import org.apache.nutch.webui.client.impl.RemoteCommandsBatchFactory;
+import org.apache.nutch.webui.client.impl.CrawlingCycleListener;
+import org.apache.nutch.webui.client.impl.RemoteCommand;
+import org.apache.nutch.webui.client.impl.RemoteCommandExecutor;
+import org.apache.nutch.webui.client.model.Crawl;
+import org.apache.nutch.webui.client.model.Crawl.CrawlStatus;
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.service.CrawlService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import com.j256.ormlite.dao.Dao;
+
+@Service
+public class CrawlServiceImpl implements CrawlService, CrawlingCycleListener {
+ private Logger log = LoggerFactory.getLogger(CrawlServiceImpl.class);
+
+ @Resource
+ private Dao<Crawl, Long> crawlDao;
+
+ @Resource
+ private NutchClientFactory nutchClientFactory;
+
+ @Resource
+ private RemoteCommandsBatchFactory commandFactory;
+
+ @Override
+ @Async
+ public void startCrawl(Long crawlId, NutchInstance instance) {
+ Crawl crawl = null;
+ try {
+ crawl = crawlDao.queryForId(crawlId);
+ if(crawl.getCrawlId()==null) {
+ crawl.setCrawlId("crawl-" + crawlId.toString());
+ }
+ NutchClient client = nutchClientFactory.getClient(instance);
+ String seedDirectory = client.createSeed(crawl.getSeedList());
+ crawl.setSeedDirectory(seedDirectory);
+
+ List<RemoteCommand> commands = commandFactory.createCommands(crawl);
+ RemoteCommandExecutor executor = new RemoteCommandExecutor(client);
+
+ CrawlingCycle cycle = new CrawlingCycle(this, executor, crawl, commands);
+ cycle.executeCrawlCycle();
+
+ } catch (Exception e) {
+ crawl.setStatus(CrawlStatus.ERROR);
+ saveCrawl(crawl);
+ log.error("exception occured", e);
+ }
+ }
+
+ @Override
+ public List<Crawl> getCrawls() {
+ try {
+ return crawlDao.queryForAll();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void saveCrawl(Crawl crawl) {
+ try {
+ crawlDao.createOrUpdate(crawl);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void deleteCrawl(Long crawlId) {
+ try {
+ crawlDao.deleteById(crawlId);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void crawlingStarted(Crawl crawl) {
+ crawl.setStatus(CrawlStatus.CRAWLING);
+ crawl.setProgress(0);
+ saveCrawl(crawl);
+ }
+
+ @Override
+ public void onCrawlError(Crawl crawl, String msg) {
+ crawl.setStatus(CrawlStatus.ERROR);
+ saveCrawl(crawl);
+ }
+
+ @Override
+ public void commandExecuted(Crawl crawl, RemoteCommand command, int progress) {
+ crawl.setProgress(progress);
+ saveCrawl(crawl);
+ }
+
+ @Override
+ public void crawlingFinished(Crawl crawl) {
+ crawl.setStatus(CrawlStatus.FINISHED);
+ saveCrawl(crawl);
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/service/impl/NutchInstanceServiceImpl.java b/src/java/org/apache/nutch/webui/service/impl/NutchInstanceServiceImpl.java
new file mode 100644
index 000000000..e100054c9
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/service/impl/NutchInstanceServiceImpl.java
@@ -0,0 +1,76 @@
+/**
+ * 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.webui.service.impl;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.nutch.webui.client.NutchClientFactory;
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.service.NutchInstanceService;
+import org.springframework.stereotype.Service;
+
+import com.j256.ormlite.dao.Dao;
+
+@Service
+public class NutchInstanceServiceImpl implements NutchInstanceService {
+
+ @Resource
+ private NutchClientFactory nutchClientFactory;
+
+ @Resource
+ private Dao<NutchInstance, Long> instancesDao;
+
+ @Override
+ public List<NutchInstance> getInstances() {
+ try {
+ return instancesDao.queryForAll();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ @Override
+ public NutchInstance getInstance(Long id) {
+ try {
+ return instancesDao.queryForId(id);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void saveInstance(NutchInstance instance) {
+ try {
+ instancesDao.createOrUpdate(instance);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void removeInstance(Long id) {
+ try {
+ instancesDao.deleteById(id);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/service/impl/NutchServiceImpl.java b/src/java/org/apache/nutch/webui/service/impl/NutchServiceImpl.java
new file mode 100644
index 000000000..db989cfb7
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/service/impl/NutchServiceImpl.java
@@ -0,0 +1,82 @@
+/**
+ * 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.webui.service.impl;
+
+import java.net.ConnectException;
+import java.util.Collections;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.apache.nutch.webui.client.NutchClientFactory;
+import org.apache.nutch.webui.client.model.ConnectionStatus;
+import org.apache.nutch.webui.client.model.NutchStatus;
+import org.apache.nutch.webui.model.NutchInstance;
+import org.apache.nutch.webui.service.NutchInstanceService;
+import org.apache.nutch.webui.service.NutchService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Service;
+
+import com.sun.jersey.api.client.ClientHandlerException;
+
+@Service
+public class NutchServiceImpl implements NutchService {
+ private static final Logger logger = LoggerFactory
+ .getLogger(NutchServiceImpl.class);
+
+ @Resource
+ private NutchClientFactory nutchClientFactory;
+
+ @Resource
+ private NutchInstanceService instanceService;
+
+ @Override
+ public ConnectionStatus getConnectionStatus(Long instanceId) {
+ NutchInstance instance = instanceService.getInstance(instanceId);
+ try {
+ NutchStatus nutchStatus = nutchClientFactory.getClient(instance)
+ .getNutchStatus();
+ if (nutchStatus.getStartDate() != null) {
+ return ConnectionStatus.CONNECTED;
+ }
+ } catch (Exception e) {
+ if (e.getCause() instanceof ConnectException) {
+ return ConnectionStatus.DISCONNECTED;
+ }
+
+ logger.error("Cannot connect to nutch server!", e);
+ }
+ return null;
+ }
+
+ @Override
+ public Map<String, String> getNutchConfig(Long instanceId) {
+ NutchInstance instance = instanceService.getInstance(instanceId);
+ try {
+ return nutchClientFactory.getClient(instance).getNutchConfig("default");
+ } catch (ClientHandlerException exception) {
+ return Collections.emptyMap();
+ }
+ }
+
+ @Override
+ public NutchStatus getNutchStatus(Long instanceId) {
+ NutchInstance instance = instanceService.getInstance(instanceId);
+ return nutchClientFactory.getClient(instance).getNutchStatus();
+ }
+}
diff --git a/src/java/org/apache/nutch/webui/service/impl/SeedListServiceImpl.java b/src/java/org/apache/nutch/webui/service/impl/SeedListServiceImpl.java
new file mode 100644
index 000000000..fced2d3b8
--- /dev/null
+++ b/src/java/org/apache/nutch/webui/service/impl/SeedListServiceImpl.java
@@ -0,0 +1,77 @@
+/**
+ * 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.webui.service.impl;
+
+import java.sql.SQLException;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.nutch.webui.model.SeedList;
+import org.apache.nutch.webui.model.SeedUrl;
+import org.apache.nutch.webui.service.SeedListService;
+import org.springframework.stereotype.Service;
+
+import com.j256.ormlite.dao.Dao;
+
+@Service
+public class SeedListServiceImpl implements SeedListService {
+
+ @Resource
+ private Dao<SeedList, Long> seedListDao;
+
+ @Resource
+ private Dao<SeedUrl, Long> seedUrlDao;
+
+ @Override
+ public void save(SeedList seedList) {
+ try {
+ seedListDao.createOrUpdate(seedList);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void delete(Long seedListId) {
+ try {
+ seedListDao.deleteById(seedListId);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ @Override
+ public List<SeedList> findAll() {
+ try {
+ return seedListDao.queryForAll();
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public SeedList getSeedList(Long seedListId) {
+ try {
+ return seedListDao.queryForId(seedListId);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+}