Search in sources :

Example 1 with RemoveLocationMessage

use of com.yahoo.documentapi.messagebus.protocol.RemoveLocationMessage in project vespa by vespa-engine.

the class VespaFeedHandlerRemoveLocation method handle.

@Override
public HttpResponse handle(HttpRequest request) {
    MessagePropertyProcessor.PropertySetter properties = getPropertyProcessor().buildPropertySetter(request);
    FeedResponse response;
    if (request.getProperty("route") == null) {
        if (context.getClusterList().getStorageClusters().size() == 0) {
            return new FeedResponse(null).addError("No storage clusters configured and no alternate route specified.");
        } else if (context.getClusterList().getStorageClusters().size() > 1) {
            return new FeedResponse(null).addError("More than one storage cluster configured and no route specified.");
        } else {
            properties.setRoute(Route.parse(context.getClusterList().getStorageClusters().get(0).getName()));
        }
    }
    response = new FeedResponse(new RouteMetricSet(properties.getRoute().toString(), null));
    SingleSender sender = new SingleSender(response, getSharedSender(properties.getRoute().toString()));
    sender.addMessageProcessor(properties);
    String user = request.getProperty("user");
    String group = request.getProperty("group");
    String selection = request.getProperty("selection");
    boolean oneFound = (user != null) ^ (group != null) ^ (selection != null);
    if (!oneFound) {
        response.addError("Exactly one of \"user\", \"group\" or \"selection\" must be specified for removelocation");
        return response;
    }
    if (user != null) {
        selection = "id.user=" + user;
    }
    if (group != null) {
        selection = "id.group=\"" + group + "\"";
    }
    sender.send(new RemoveLocationMessage(selection));
    sender.done();
    long millis = getTimeoutMillis(request);
    boolean completed = sender.waitForPending(millis);
    if (!completed)
        response.addError(Error.TIMEOUT, "Timed out after " + millis + " ms waiting for responses");
    return response;
}
Also used : RemoveLocationMessage(com.yahoo.documentapi.messagebus.protocol.RemoveLocationMessage) RouteMetricSet(com.yahoo.clientmetrics.RouteMetricSet) SingleSender(com.yahoo.feedapi.SingleSender) MessagePropertyProcessor(com.yahoo.feedapi.MessagePropertyProcessor)

Aggregations

RouteMetricSet (com.yahoo.clientmetrics.RouteMetricSet)1 RemoveLocationMessage (com.yahoo.documentapi.messagebus.protocol.RemoveLocationMessage)1 MessagePropertyProcessor (com.yahoo.feedapi.MessagePropertyProcessor)1 SingleSender (com.yahoo.feedapi.SingleSender)1