Permalink
Browse files

Added tracking info to be logged when nodes are modified.

  • Loading branch information...
1 parent 6ed0e11 commit c71db55858063ed160e1d7d9b25f983499c08432 @Randgalt Randgalt committed May 4, 2012
@@ -29,6 +29,7 @@
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
+import javax.ws.rs.HeaderParam;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
@@ -69,11 +70,20 @@ public static String bytesToString(byte[] bytes)
@DELETE
@Path("znode/{path:.*}")
@Produces("application/json")
- public Response deleteNode(@PathParam("path") String path)
+ public Response deleteNode
+ (
+ @PathParam("path") String path,
+ @HeaderParam("netflix-user-name") String trackingUserName,
+ @HeaderParam("netflix-ticket-number") String trackingTicketNumber,
+ @HeaderParam("netflix-reason") String trackingReason
+ )
{
Response response;
do
{
+ path = "/" + path;
+ context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("Delete node request received. Path [%s], Username [%s], Ticket Number [%s], Reason [%s]", path, trackingUserName, trackingTicketNumber, trackingReason));
+
if ( !context.getExhibitor().nodeMutationsAllowed() )
{
response = Response.status(Response.Status.FORBIDDEN).build();
@@ -82,7 +92,7 @@ public Response deleteNode(@PathParam("path") String path)
try
{
- recursivelyDelete("/" + path);
+ recursivelyDelete(path);
}
catch ( Exception e )
{
@@ -105,24 +115,34 @@ private void recursivelyDelete(String path) throws Exception
}
context.getExhibitor().getLocalConnection().delete().forPath(path);
+ context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("deleteNode() deleted node [%s]", path));
}
@PUT
@Path("znode/{path:.*}")
@Produces("application/json")
@Consumes("application/json")
- public Response createNode(@PathParam("path") String path, String data)
+ public Response createNode
+ (
+ @PathParam("path") String path,
+ @HeaderParam("netflix-user-name") String trackingUserName,
+ @HeaderParam("netflix-ticket-number") String trackingTicketNumber,
+ @HeaderParam("netflix-reason") String trackingReason,
+ String data
+ )
{
Response response;
do
{
+ path = "/" + path;
+ context.getExhibitor().getLog().add(ActivityLog.Type.INFO, String.format("Create/update node request received. Path [%s], Username [%s], Ticket Number [%s], Reason [%s]", path, trackingUserName, trackingTicketNumber, trackingReason));
+
if ( !context.getExhibitor().nodeMutationsAllowed() )
{
response = Response.status(Response.Status.FORBIDDEN).build();
break;
}
- path = "/" + path;
try
{
try
@@ -429,7 +429,18 @@ fieldset
padding: 1px 3px 1px 3px;
}
-#get-node-data-dialog label
+#get-node-data-dialog fieldset
+{
+ margin-top: 8px;
+}
+
+#get-node-data-dialog fieldset label
+{
+ float: left;
+ width: 90px;
+}
+
+#get-node-data-dialog div label
{
float: left;
width: 70px;
@@ -438,4 +449,4 @@ fieldset
#node-name-container
{
margin-bottom: 3px;
-}
+}
@@ -234,7 +234,16 @@
<div id="node-name-container">
<label for="node-name">Name </label><input type="text" id="node-name" name="node-name" size="10"><br clear="all"/>
</div>
- <label for="node-data">Data </label><input type="text" id="node-data" name="node-data" size="30"><br clear="all"/>
+ <div id="node-data-container">
+ <label for="node-data">Data </label><input type="text" id="node-data" name="node-data" size="30"><br clear="all"/>
+ </div>
+
+ <fieldset>
+ <legend>Tracking</legend>
+ <label for="node-data-user">Username</label><input type="text" id="node-data-user" name="node-data-user" size="10" title="Your username"><br clear="all"/>
+ <label for="node-data-ticket">Ticket</label><input type="text" id="node-data-ticket" name="node-data-ticket" size="10" title="Ticket/tag number for this operation"><br clear="all"/>
+ <label for="node-data-reason">Reason</label><input type="text" id="node-data-reason" name="node-data-reason" size="25" title="Reason for the change"><br clear="all"/>
+ </fieldset>
</div>
<div id="index-query-dialog" class="ui-helper-hidden">
@@ -1,82 +1,99 @@
var explorerSelectedPath = null;
-function continueModifyFromExplorer(action, n)
+function continueModifyFromExplorer(action)
{
- if ( n == 0 )
+ var nodeName = $('#node-name').val().trim();
+ if ( (action === "create") && (nodeName.length == 0) )
{
- okCancelDialog("Are You Sure?", "Are you sure you want to do this. It cannot be undone and could irreparably harm the ZooKeeper data.", function(){
- continueModifyFromExplorer(action, 1)
- });
+ messageDialog("Error", "The node name is required.");
+ return;
}
- else
+
+ var userName = $('#node-data-user').val().trim();
+ var ticketNumber = $('#node-data-ticket').val().trim();
+ var reason = $('#node-data-reason').val().trim();
+ if ( (userName.length == 0) || (ticketNumber.length == 0) || (reason.length == 0) )
{
- okCancelDialog("Are You Really Sure?", 'Please confirm one more time that you want to make this modification to "' + explorerSelectedPath + '"', function(){
- var method = (action === "delete") ? "DELETE" : "PUT";
- var data = $('#node-data').val().trim();
- var localPath = explorerSelectedPath;
- if ( action === "create" )
+ messageDialog("Error", "The tracking fields are required.");
+ return;
+ }
+
+ okCancelDialog("Are You Sure?", "Are you sure you want to do this. It cannot be undone and could irreparably harm the ZooKeeper data.", function(){
+ var method = (action === "delete") ? "DELETE" : "PUT";
+ var data = $('#node-data').val().trim();
+ var localPath = explorerSelectedPath;
+ if ( action === "create" )
+ {
+ if ( localPath != "/" )
{
- localPath += "/" + $('#node-name').val().trim();
+ localPath += "/";
}
+ localPath += nodeName;
+ }
- $.ajax({
- type: method,
- url: URL_EXPLORER_ZNODE_BASE + localPath,
- data: data,
- contentType: 'application/json',
- success:function(data)
+ $.ajax({
+ type: method,
+ url: URL_EXPLORER_ZNODE_BASE + localPath,
+ data: data,
+ contentType: 'application/json',
+ headers: {
+ 'netflix-user-name': userName,
+ 'netflix-ticket-number': ticketNumber,
+ 'netflix-reason': reason
+ },
+ success:function(data)
+ {
+ if ( data.succeeded )
{
- if ( data.succeeded )
- {
- $("#tree").dynatree("getTree").reload();
- messageDialog("Success", "The change has been made.");
- }
- else
- {
- messageDialog("Error", data.message);
- }
+ $("#tree").dynatree("getTree").reload();
+ messageDialog("Success", "The change has been made.");
+ }
+ else
+ {
+ messageDialog("Error", data.message);
}
- });
+ }
});
- }
+ });
}
function modifyFromExplorer(action)
{
- if ( action != "delete" )
+ if ( (action != "create") && (explorerSelectedPath === "/") )
{
- if ( action === "create" )
- {
- $('#node-name-container').show();
- }
- else
- {
- $('#node-name-container').hide();
- }
+ messageDialog("Error", "You cannot modify the root node.");
+ return;
+ }
- $("#get-node-data-dialog").dialog("option", "buttons", {
- 'Cancel': function (){
- $(this).dialog("close");
- },
+ if ( action === "create" )
+ {
+ $('#node-name-container').show();
+ $('#node-data-container').show();
+ }
+ else if ( action === "update" )
+ {
+ $('#node-name-container').hide();
+ $('#node-data-container').show();
+ }
+ else // delete
+ {
+ $('#node-name-container').hide();
+ $('#node-data-container').hide();
+ }
- 'OK': function (){
- $(this).dialog("close");
+ $("#get-node-data-dialog").dialog("option", "buttons", {
+ 'Cancel': function (){
+ $(this).dialog("close");
+ },
- if ( (action === "create") && ($('#node-name').val().trim().length == 0) )
- {
- return;
- }
+ 'Next...': function (){
+ $(this).dialog("close");
- continueModifyFromExplorer(action, 0);
- }
+ continueModifyFromExplorer(action);
}
- );
- $("#get-node-data-dialog").dialog("open");
- }
- else
- {
- continueModifyFromExplorer(action, 0);
- }
+ }
+ );
+ $("#get-node-data-dialog").dialog("open");
}
function initExplorer()

0 comments on commit c71db55

Please sign in to comment.