Author: ivol37 at gmail.com
Date: Tue Jan 11 16:38:01 2011
New Revision: 597
Log:
added ring topology info
Added:
sandbox/ivol/cassandra-gadget/install.txt
Modified:
sandbox/ivol/cassandra-gadget/src/main/java/org/amdatu/cassandra/gadget/service/CassandraClientGadgetImpl.java
sandbox/ivol/cassandra-gadget/src/main/resources/jsp/CassandraClientGadget.jsp
Added: sandbox/ivol/cassandra-gadget/install.txt
==============================================================================
--- (empty file)
+++ sandbox/ivol/cassandra-gadget/install.txt Tue Jan 11 16:38:01 2011
@@ -0,0 +1,7 @@
+Windows:
+
+install
file:D:\Amdatu-svn\sandbox\ivol\cassandra-gadget\org.amdatu.cassandra.gadget-0.1.0-SNAPSHOT.jar
+
+Linux:
+
+install
file:/vol/users/ivol/amdatu/sandbox-ivol/cassandra-gadget/target/org.amdatu.cassandra.gadget-0.1.0-SNAPSHOT.jar
Modified:
sandbox/ivol/cassandra-gadget/src/main/java/org/amdatu/cassandra/gadget/service/CassandraClientGadgetImpl.java
==============================================================================
---
sandbox/ivol/cassandra-gadget/src/main/java/org/amdatu/cassandra/gadget/service/CassandraClientGadgetImpl.java
(original)
+++
sandbox/ivol/cassandra-gadget/src/main/java/org/amdatu/cassandra/gadget/service/CassandraClientGadgetImpl.java
Tue Jan 11 16:38:01 2011
@@ -23,7 +23,9 @@
import java.util.List;
import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
@@ -35,6 +37,7 @@
import org.amdatu.opensocial.shindig.GadgetDefinition;
import org.amdatu.web.httpcontext.HttpContextServiceFactory;
import org.amdatu.web.httpcontext.ResourceProvider;
+import org.apache.cassandra.service.StorageService;
import org.apache.cassandra.thrift.ColumnParent;
import org.apache.cassandra.thrift.ConsistencyLevel;
import org.apache.cassandra.thrift.InvalidRequestException;
@@ -127,32 +130,76 @@
return html;
}
catch (TException e) {
- e.printStackTrace();
+ m_logService.log(LogService.LOG_ERROR, "Could not retrieve
Cassandra data", e);
throw new WebApplicationException(e);
}
catch (InvalidRequestException e) {
- e.printStackTrace();
+ m_logService.log(LogService.LOG_ERROR, "Could not retrieve
Cassandra data", e);
throw new WebApplicationException(e);
}
catch (NotFoundException e) {
- e.printStackTrace();
+ m_logService.log(LogService.LOG_ERROR, "Could not retrieve
Cassandra data", e);
throw new WebApplicationException(e);
}
catch (UnsupportedEncodingException e) {
- e.printStackTrace();
+ m_logService.log(LogService.LOG_ERROR, "Could not retrieve
Cassandra data", e);
throw new WebApplicationException(e);
}
catch (UnavailableException e) {
- e.printStackTrace();
+ m_logService.log(LogService.LOG_ERROR, "Could not retrieve
Cassandra data", e);
throw new WebApplicationException(e);
}
catch (TimedOutException e) {
- e.printStackTrace();
+ m_logService.log(LogService.LOG_ERROR, "Could not retrieve
Cassandra data", e);
throw new WebApplicationException(e);
}
}
+ /**
+ * This method can be used to check the availability of the Login Service.
+ *
+ * @return The text "Login service online"
+ */
+ @GET
+ @Path("topology")
+ @Produces( { MediaType.TEXT_HTML })
+ public String getRingTopology() {
+ String load = StorageService.instance.getLoadString();
+ int clusterSize = StorageService.instance.getLiveNodes().size();
+ String token = StorageService.instance.getToken();
+ String nodes = "";
+ for (String node : StorageService.instance.getLiveNodes()) {
+ nodes += node + "<br/>";
+ }
+
+ String html = "<table
border=\"1\"><tr><th>Property</th><th>Value</th>";
+ html += "<tr><td># Cluster nodes</td><td>" + clusterSize +
"</td></tr>";
+ html += "<tr><td>Cluster nodes</td><td>" + nodes + "</td></tr>";
+ html += "<tr><td>Load of this node</td><td>" + load + "</td></tr>";
+ html += "<tr><td>Token</td><td>" + token + "</td></tr>";
+ html += "</table";
+ return html;
+ }
+
+ @PUT
+ @Produces( { MediaType.TEXT_HTML })
+ @Path("rf/{replicationfactor}")
+ public String updateReplicationFactor(@PathParam("replicationfactor")
final String replicationfactor) {
+ int replicationFactor = Integer.parseInt(replicationfactor);
+ try {
+ m_daemon.setReplicationFactor(replicationFactor);
+ m_logService.log(LogService.LOG_INFO, "Replication factor changed
to " + replicationFactor);
+ }
+ catch (InvalidRequestException e) {
+ m_logService.log(LogService.LOG_ERROR, "Could not update
replication factor to " + replicationFactor, e);
+ }
+ catch (TException e) {
+ m_logService.log(LogService.LOG_ERROR, "Could not update
replication factor to " + replicationFactor, e);
+ }
+ return "New replication factor: " + replicationFactor;
+ }
+
// Maximum amount of rows to retrieve in queries
private final static int ROW_LIMIT = 1000000;
@@ -162,9 +209,6 @@
// Empty byte array
private final static ByteBuffer EMPTY = ByteBuffer.wrap(new byte[0]);
- // Investigation pointed out that retrying succeeds after about 10 times.
- private final static int MAX_RETRIES = 10;
-
/**
* Returns all keys for a certain ColumnFamily (think of all primary keys
of all records in a certain table)
* @throws TException
Modified:
sandbox/ivol/cassandra-gadget/src/main/resources/jsp/CassandraClientGadget.jsp
==============================================================================
---
sandbox/ivol/cassandra-gadget/src/main/resources/jsp/CassandraClientGadget.jsp
(original)
+++
sandbox/ivol/cassandra-gadget/src/main/resources/jsp/CassandraClientGadget.jsp
Tue Jan 11 16:38:01 2011
@@ -42,9 +42,50 @@
<script type="text/javascript"
src="/dashboard/static/js/lib/jquery-1.4.2.min.js"></script>
<script type="text/javascript"
src="/dashboard/static/js/lib/jquery-ui-1.8.2.custom.min.js"></script>
- <div id="result"></div>
+ <html>
+ <body>
+ <fieldset>
+ <legend>Ring topology</legend>
+ <p>
+ <div id="topology"></div>
+ </p>
+ </fieldset>
+
+ <fieldset>
+ <legend>Replication factor</legend>
+ <p>
+ Change the replication factor to:
+ <input type="text" id="rf" value="1"/>
+ <input type="submit" value="Change"
onclick="javascript:changeReplicationFactor()" />
+ <div id="rfresult"></div>
+ </p>
+ </fieldset>
+
+ <fieldset>
+ <legend>Cassandra data</legend>
+ <p>
+ <div id="result"></div>
+ </p>
+ </fieldset>
+ </body>
+ </html>
<script type="text/javascript">
+ function getTopology() {
+ var url = "${baseRestUrl}/topology";
+ jQuery.ajax({
+ url: url,
+ type: "GET",
+ dataType: "html",
+ async:true,
+ success: function(response) {
+ document.getElementById("topology").innerHTML = response;
+ gadgets.window.adjustHeight();
+ }
+ }
+ );
+ }
+
function getAll() {
var url = "${baseRestUrl}";
jQuery.ajax({
@@ -60,6 +101,22 @@
);
}
+ function changeReplicationFactor() {
+ var url = "${baseRestUrl}/rf/" + document.getElementById("rf").value;
+ jQuery.ajax({
+ url: url,
+ type: "PUT",
+ dataType: "html",
+ async:true,
+ success: function(response) {
+ document.getElementById("rfresult").innerHTML = response;
+ gadgets.window.adjustHeight();
+ }
+ }
+ );
+ }
+
+ getTopology();
getAll();
</script>
]]>