// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/mgm/RestJRMgmBaseAction.java
// public abstract class RestJRMgmBaseAction extends BaseRestHandler {
// 
// 	protected RestJRMgmBaseAction(Settings settings, Client client, RestController controller) {
// 		super(settings, controller, client);
// 	}
// 
// 	/**
// 	 * Prepare base REST URL for Sysinfo river management operations. <code>riverName</code> request parameter is defined
// 	 * here.
// 	 * 
// 	 * @return base REST management url ending by <code>/</code>
// 	 */
// 	protected String baseRestMgmUrl() {
// 		return "/" + RiverIndexName.Conf.indexName(settings) + "/{riverName}/_mgm_sr/";
// 	}
// 
// }
// 
// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/mgm/RestXContentBuilder.java
// public class RestXContentBuilder {
// 
// 	public static XContentBuilder restContentBuilder(RestRequest request) throws IOException {
// 		XContentType contentType = XContentType
// 				.fromRestContentType(request.param("format", request.header("Content-Type")));
// 		if (contentType == null) {
// 			// default to JSON
// 			contentType = XContentType.JSON;
// 		}
// 		XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), new BytesStreamOutput());
// 		if (request.paramAsBoolean("pretty", false)) {
// 			builder.prettyPrint().lfAtEnd();
// 		}
// 		String casing = request.param("case");
// 		if (casing != null && "camelCase".equals(casing)) {
// 			builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE);
// 		} else {
// 			// we expect all REST interfaces to write results in underscore casing, so
// 			// no need for double casing
// 			builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE);
// 		}
// 		return builder;
// 	}
// 
// 	public static XContentBuilder emptyBuilder(RestRequest request) throws IOException {
// 		return restContentBuilder(request).startObject().endObject();
// 	}
// 
// }


import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestStatus;
import org.jboss.elasticsearch.river.sysinfo.mgm.RestJRMgmBaseAction;
import org.jboss.elasticsearch.river.sysinfo.mgm.RestXContentBuilder;
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 */
package org.jboss.elasticsearch.river.sysinfo.mgm.riverslist;



/**
 * REST action handler for Sysinfo river get state operation.
 * 
 * @author Vlastimil Elias (velias at redhat dot com)
 */
public class RestListRiversAction extends RestJRMgmBaseAction {

	@Inject
	protected RestListRiversAction(Settings settings, Client client, RestController controller) {
		super(settings, client, controller);
		controller.registerHandler(org.elasticsearch.rest.RestRequest.Method.GET, "/_sysinfo_river/list", this);
	}

	@Override
	public void handleRequest(final RestRequest restRequest, final RestChannel restChannel, Client client) {

		ListRiversRequest actionRequest = new ListRiversRequest();

		logger.debug("Go to look for Sysinfo rivers in cluster");
		client.admin().cluster()
				.execute(ListRiversAction.INSTANCE, actionRequest, new ActionListener<ListRiversResponse>() {

					@Override
					public void onResponse(ListRiversResponse response) {
						try {
							Set<String> allRivers = new HashSet<String>();
							for (NodeListRiversResponse node : response.getNodes()) {
								if (node.riverNames != null) {
									allRivers.addAll(node.riverNames);
								}
							}

							XContentBuilder builder = RestXContentBuilder.restContentBuilder(restRequest);
// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/mgm/RestJRMgmBaseAction.java
// public abstract class RestJRMgmBaseAction extends BaseRestHandler {
// 
// 	protected RestJRMgmBaseAction(Settings settings, Client client, RestController controller) {
// 		super(settings, controller, client);
// 	}
// 
// 	/**
// 	 * Prepare base REST URL for Sysinfo river management operations. <code>riverName</code> request parameter is defined
// 	 * here.
// 	 * 
// 	 * @return base REST management url ending by <code>/</code>
// 	 */
// 	protected String baseRestMgmUrl() {
// 		return "/" + RiverIndexName.Conf.indexName(settings) + "/{riverName}/_mgm_sr/";
// 	}
// 
// }
// 
// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/mgm/RestXContentBuilder.java
// public class RestXContentBuilder {
// 
// 	public static XContentBuilder restContentBuilder(RestRequest request) throws IOException {
// 		XContentType contentType = XContentType
// 				.fromRestContentType(request.param("format", request.header("Content-Type")));
// 		if (contentType == null) {
// 			// default to JSON
// 			contentType = XContentType.JSON;
// 		}
// 		XContentBuilder builder = new XContentBuilder(XContentFactory.xContent(contentType), new BytesStreamOutput());
// 		if (request.paramAsBoolean("pretty", false)) {
// 			builder.prettyPrint().lfAtEnd();
// 		}
// 		String casing = request.param("case");
// 		if (casing != null && "camelCase".equals(casing)) {
// 			builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.CAMELCASE);
// 		} else {
// 			// we expect all REST interfaces to write results in underscore casing, so
// 			// no need for double casing
// 			builder.fieldCaseConversion(XContentBuilder.FieldCaseConversion.NONE);
// 		}
// 		return builder;
// 	}
// 
// 	public static XContentBuilder emptyBuilder(RestRequest request) throws IOException {
// 		return restContentBuilder(request).startObject().endObject();
// 	}
// 
// }


// Path: src/main/java/org/jboss/elasticsearch/river/sysinfo/mgm/riverslist/RestListRiversAction.java
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel;
import org.elasticsearch.rest.RestController;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestStatus;
import org.jboss.elasticsearch.river.sysinfo.mgm.RestJRMgmBaseAction;
import org.jboss.elasticsearch.river.sysinfo.mgm.RestXContentBuilder;

/*
 * JBoss, Home of Professional Open Source
 * Copyright 2012 Red Hat Inc. and/or its affiliates and other contributors
 * as indicated by the @authors tag. All rights reserved.
 */
package org.jboss.elasticsearch.river.sysinfo.mgm.riverslist;



/**
 * REST action handler for Sysinfo river get state operation.
 * 
 * @author Vlastimil Elias (velias at redhat dot com)
 */
public class RestListRiversAction extends RestJRMgmBaseAction {

	@Inject
	protected RestListRiversAction(Settings settings, Client client, RestController controller) {
		super(settings, client, controller);
		controller.registerHandler(org.elasticsearch.rest.RestRequest.Method.GET, "/_sysinfo_river/list", this);
	}

	@Override
	public void handleRequest(final RestRequest restRequest, final RestChannel restChannel, Client client) {

		ListRiversRequest actionRequest = new ListRiversRequest();

		logger.debug("Go to look for Sysinfo rivers in cluster");
		client.admin().cluster()
				.execute(ListRiversAction.INSTANCE, actionRequest, new ActionListener<ListRiversResponse>() {

					@Override
					public void onResponse(ListRiversResponse response) {
						try {
							Set<String> allRivers = new HashSet<String>();
							for (NodeListRiversResponse node : response.getNodes()) {
								if (node.riverNames != null) {
									allRivers.addAll(node.riverNames);
								}
							}

							XContentBuilder builder = RestXContentBuilder.restContentBuilder(restRequest);
							builder.startObject();