Skip to content

Commit

Permalink
add stub graph updater status web service. #1722
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed Jan 28, 2015
1 parent 7ef10d8 commit 1d44c31
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.opentripplanner.api.resource;

import com.oracle.deploy.update.Updater;
import org.opentripplanner.common.geometry.DistanceLibrary;
import org.opentripplanner.common.geometry.SphericalDistanceLibrary;
import org.opentripplanner.routing.graph.GraphIndex;
import org.opentripplanner.routing.services.StreetVertexIndexService;
import org.opentripplanner.standalone.OTPServer;
import org.opentripplanner.standalone.Router;
import org.opentripplanner.updater.GraphUpdaterManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.*;
import javax.ws.rs.core.*;
import javax.ws.rs.core.Response;

/**
* Report the status of the graph updaters via a web service.
*/
@Path("/routers/{routerId}/updaters")
@Produces(MediaType.APPLICATION_JSON)
public class UpdaterStatusResource {

private static final Logger LOG = LoggerFactory.getLogger(UpdaterStatusResource.class);

/** Choose short or long form of results. */
@QueryParam("detail") private boolean detail = false;

Router router;

public UpdaterStatusResource (@Context OTPServer otpServer, @PathParam("routerId") String routerId) {
router = otpServer.getRouter(routerId);
}

/** Return a list of all agencies in the graph. */
@GET
public Response getUpdaters () {
GraphUpdaterManager updaterManager = router.graph.updaterManager;
if (updaterManager == null) {
return Response.status(Response.Status.NOT_FOUND).entity("No updaters running.").build();
}
return Response.status(Response.Status.OK).entity(updaterManager.getUpdaterClasses()).build();
}

}
20 changes: 2 additions & 18 deletions src/main/java/org/opentripplanner/standalone/OTPApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,7 @@
import org.glassfish.jersey.server.filter.RolesAllowedDynamicFeature;
import org.opentripplanner.api.common.OTPExceptionMapper;
import org.opentripplanner.api.model.JSONObjectMapperProvider;
import org.opentripplanner.api.resource.AlertPatcher;
import org.opentripplanner.api.resource.BikeRental;
import org.opentripplanner.api.resource.ExternalGeocoderResource;
import org.opentripplanner.api.resource.GraphInspectorTileResource;
import org.opentripplanner.api.resource.Metadata;
import org.opentripplanner.api.resource.Planner;
import org.opentripplanner.api.resource.PointSetResource;
import org.opentripplanner.api.resource.ProfileResource;
import org.opentripplanner.api.resource.Routers;
import org.opentripplanner.api.resource.ServerInfo;
import org.opentripplanner.api.resource.LIsochrone;
import org.opentripplanner.api.resource.LegendResource;
import org.opentripplanner.api.resource.Raster;
import org.opentripplanner.api.resource.SIsochrone;
import org.opentripplanner.api.resource.SimpleIsochrone;
import org.opentripplanner.api.resource.SurfaceResource;
import org.opentripplanner.api.resource.TileService;
import org.opentripplanner.api.resource.TimeGridWs;
import org.opentripplanner.api.resource.*;
import org.opentripplanner.index.GeocoderResource;
import org.opentripplanner.index.IndexAPI;
import org.slf4j.bridge.SLF4JBridgeHandler;
Expand Down Expand Up @@ -108,6 +91,7 @@ public Set<Class<?>> getClasses() {
SurfaceResource.class,
PointSetResource.class,
GraphInspectorTileResource.class,
UpdaterStatusResource.class,
/* Features and Filters: extend Jersey, manipulate requests and responses. */
CorsFilter.class
));
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/opentripplanner/updater/GraphUpdaterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ the License, or (at your option) any later version.

package org.opentripplanner.updater;

import com.beust.jcommander.internal.Lists;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -202,4 +203,16 @@ public int size() {
return updaterList.size();
}

/**
* Just an example of fetching status information from the graph updater manager to expose it in a web service.
* More useful stuff should be added later.
*/
public List<Class> getUpdaterClasses() {
List<Class> ret = Lists.newArrayList();
for (GraphUpdater updater : updaterList) {
ret.add(updater.getClass());
}
return ret;
}

}

0 comments on commit 1d44c31

Please sign in to comment.