Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/java/org/apache/nutch/api/model/response/NutchStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,109 @@
import org.apache.commons.collections.CollectionUtils;
import org.apache.nutch.api.model.response.JobInfo.State;

/**
* Information object for status of {@link org.apache.nutch.api.NutchServer}.
* Gives information about when server is started, its configurations, jobs, running jobs
* and active configuration id.
*
* @see org.apache.nutch.api.NutchServer
*/
public class NutchStatus {
private Date startDate;
private Set<String> configuration;
private Collection<JobInfo> jobs;
private Collection<JobInfo> runningJobs;
private String activeConfId;

/**
* Gets start date of the {@link org.apache.nutch.api.NutchServer}
*
* @return start date of the server
*/
public Date getStartDate() {
return startDate;
}

/**
* Sets start date of the {@link org.apache.nutch.api.NutchServer}
*
* @param startDate start date
*/
public void setStartDate(Date startDate) {
this.startDate = startDate;
}

/**
* Gets configuration ids
*
* @return configuration ids
*/
public Set<String> getConfiguration() {
return configuration;
}

/**
* Sets configuration ids
*
* @param configuration configuration ids
*/
public void setConfiguration(Set<String> configuration) {
this.configuration = configuration;
}

/**
* Gets jobs
*
* @return jobs
*/
public Collection<JobInfo> getJobs() {
return jobs;
}

/**
* Sets jobs
* @param jobs jobs
*/
public void setJobs(Collection<JobInfo> jobs) {
this.jobs = jobs;
}

/**
* Gets running jobs
*
* @return running jobs
*/
public Collection<JobInfo> getRunningJobs() {
return purgeFinishedFailedJobs(runningJobs);
}

/**
* Sets running jobs
*
* @param runningJobs running jobs
*/
public void setRunningJobs(Collection<JobInfo> runningJobs) {
this.runningJobs = runningJobs;
}

/**
* Gets active configuration id
*
* @return active configuration id
*/
public String getActiveConfId() {
return activeConfId;
}

/**
* Sets active configuration id
*
* @param activeConfId active configuration id
*/
public void setActiveConfId(String activeConfId) {
this.activeConfId = activeConfId;
}

private Collection<JobInfo> purgeFinishedFailedJobs(
Collection<JobInfo> runningJobColl) {
if (CollectionUtils.isNotEmpty(runningJobColl)) {
Expand Down
14 changes: 14 additions & 0 deletions src/java/org/apache/nutch/api/resources/AbstractResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,34 @@
import org.apache.nutch.api.NutchServer;
import org.restlet.Context;

/**
* Abstract base class for {@link NutchServer} REST APIs.
*/
@Produces({ MediaType.APPLICATION_JSON })
public abstract class AbstractResource {

protected ConfManager configManager;
protected JobManager jobManager;
protected String activeConfId;
protected NutchServer server;

/**
* Constructor method for {@link AbstractResource}
* Retrieves {@link org.apache.nutch.api.NutchServer} information from {@link org.restlet.Context}
*/
public AbstractResource() {
server = (NutchServer) Context.getCurrent().getAttributes()
.get(NutchServer.NUTCH_SERVER);
configManager = server.getConfMgr();
jobManager = server.getJobMgr();
activeConfId = server.getActiveConfId();
}

/**
* Throws HTTP 400 Bad Request Exception with given message
*
* @param message message to be placed at exception
*/
protected void throwBadRequestException(String message) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST)
.entity(message).build());
Expand Down
1 change: 1 addition & 0 deletions src/java/org/apache/nutch/api/resources/AdminResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public NutchStatus getNutchStatus(@Context HttpHeaders headers) {
status.setConfiguration(configManager.list());
status.setJobs(jobManager.list(null, State.ANY));
status.setRunningJobs(jobManager.list(null, State.RUNNING));
status.setActiveConfId(activeConfId);

return status;
}
Expand Down