Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nsqadmin: confirm actions #118

Merged
merged 1 commit into from
Jan 15, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion nsq/api_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ApiRequest(endpoint string) (*simplejson.Json, error) {
statusCode := data.Get("status_code").MustInt()
statusTxt := data.Get("status_txt").MustString()
if statusCode != 200 {
return nil, errors.New(fmt.Sprintf("response status_code = %d, status_txt = %s",
return nil, errors.New(fmt.Sprintf("response status_code = %d, status_txt = %s",
statusCode, statusTxt))
}
return data.Get("data"), nil
Expand Down
4 changes: 2 additions & 2 deletions nsq/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ func (q *Reader) finishLoop(c *nsqConn) {
}

atomic.StoreInt32(&c.backoffCounter, backoffCounter)
// prevent many async failures/successes from immediately resulting in
// max backoff/normal rate (by ensuring that we dont continually incr/decr
// prevent many async failures/successes from immediately resulting in
// max backoff/normal rate (by ensuring that we dont continually incr/decr
// the counter during a backoff period)
if backoffCounter > 0 && backoffUpdated {
backoffDuration := q.backoffDuration(backoffCounter)
Expand Down
36 changes: 18 additions & 18 deletions nsqadmin/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,12 +276,12 @@ func lookupHandler(w http.ResponseWriter, req *http.Request) {
}

func createTopicChannelHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
if req.Method != "POST" {
log.Printf("ERROR: invalid %s to POST only method", req.Method)
http.Error(w, "INVALID_REQUEST", 500)
return
}
reqParams := &util.PostParams{req}

topicName, err := reqParams.Get("topic")
if err != nil || !nsq.IsValidTopicName(topicName) {
Expand Down Expand Up @@ -338,12 +338,12 @@ func createTopicChannelHandler(w http.ResponseWriter, req *http.Request) {
}

func tombstoneTopicProducerHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
if req.Method != "POST" {
log.Printf("ERROR: invalid %s to POST only method", req.Method)
http.Error(w, "INVALID_REQUEST", 500)
return
}
reqParams := &util.PostParams{req}

topicName, err := reqParams.Get("topic")
if err != nil {
Expand Down Expand Up @@ -388,12 +388,12 @@ func tombstoneTopicProducerHandler(w http.ResponseWriter, req *http.Request) {
}

func deleteTopicHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
if req.Method != "POST" {
log.Printf("ERROR: invalid %s to POST only method", req.Method)
http.Error(w, "INVALID_REQUEST", 500)
return
}
reqParams := &util.PostParams{req}

topicName, err := reqParams.Get("topic")
if err != nil {
Expand Down Expand Up @@ -444,12 +444,12 @@ func deleteTopicHandler(w http.ResponseWriter, req *http.Request) {
}

func deleteChannelHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
if req.Method != "POST" {
log.Printf("ERROR: invalid %s to POST only method", req.Method)
http.Error(w, "INVALID_REQUEST", 500)
return
}
reqParams := &util.PostParams{req}

topicName, channelName, err := util.GetTopicChannelArgs(reqParams)
if err != nil {
Expand Down Expand Up @@ -499,12 +499,12 @@ func deleteChannelHandler(w http.ResponseWriter, req *http.Request) {
}

func emptyChannelHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
if req.Method != "POST" {
log.Printf("ERROR: invalid %s to POST only method", req.Method)
http.Error(w, "INVALID_REQUEST", 500)
return
}
reqParams := &util.PostParams{req}

topicName, channelName, err := util.GetTopicChannelArgs(reqParams)
if err != nil {
Expand Down Expand Up @@ -537,12 +537,12 @@ func emptyChannelHandler(w http.ResponseWriter, req *http.Request) {
}

func pauseChannelHandler(w http.ResponseWriter, req *http.Request) {
reqParams, err := util.NewReqParams(req)
if err != nil {
log.Printf("ERROR: failed to parse request params - %s", err.Error())
if req.Method != "POST" {
log.Printf("ERROR: invalid %s to POST only method", req.Method)
http.Error(w, "INVALID_REQUEST", 500)
return
}
reqParams := &util.PostParams{req}

topicName, channelName, err := util.GetTopicChannelArgs(reqParams)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions nsqadmin/templates/channel.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,28 @@ <h4>Notice</h4> No producers exist for this topic/channel.
{{else}}
<div class="row-fluid">
<div class="span2">
<form action="/empty_channel" method="GET">
<form action="/empty_channel" method="POST">
<input type="hidden" name="topic" value="{{.ChannelStats.Topic}}">
<input type="hidden" name="channel" value="{{.ChannelStats.ChannelName}}">
<button class="btn btn-medium btn-warning" type="submit">Empty Queue</button>
</form>
</div>
<div class="span2">
<form action="/delete_channel" method="GET">
<form action="/delete_channel" method="POST">
<input type="hidden" name="topic" value="{{.ChannelStats.Topic}}">
<input type="hidden" name="channel" value="{{.ChannelStats.ChannelName}}">
<button class="btn btn-medium btn-danger" type="submit">Delete Channel</button>
</form>
</div>
<div class="span2">
{{if .ChannelStats.Paused}}
<form action="/unpause_channel" method="GET">
<form action="/unpause_channel" method="POST">
<input type="hidden" name="topic" value="{{.ChannelStats.Topic}}">
<input type="hidden" name="channel" value="{{.ChannelStats.ChannelName}}">
<button class="btn btn-medium btn-success" type="submit">UnPause Channel</button>
</form>
{{else}}
<form action="/pause_channel" method="GET">
<form action="/pause_channel" method="POST">
<input type="hidden" name="topic" value="{{.ChannelStats.Topic}}">
<input type="hidden" name="channel" value="{{.ChannelStats.ChannelName}}">
<button class="btn btn-medium btn-inverse" type="submit">Pause Channel</button>
Expand Down
26 changes: 26 additions & 0 deletions nsqadmin/templates/js.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,30 @@
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<script>
$('.dropdown-toggle').dropdown()

/**
* bootbox.js v3.0.0
*
* http://bootboxjs.com/license.txt
*/
var bootbox=window.bootbox||function(v,n){function h(b,a){null==a&&(a=r);return"string"===typeof l[a][b]?l[a][b]:a!=s?h(b,s):b}var r="en",s="en",t=!0,q="static",u="",g={},m={setLocale:function(b){for(var a in l)if(a==b){r=b;return}throw Error("Invalid locale: "+b);},addLocale:function(b,a){"undefined"===typeof l[b]&&(l[b]={});for(var c in a)l[b][c]=a[c]},setIcons:function(b){g=b;if("object"!==typeof g||null==g)g={}},alert:function(){var b="",a=h("OK"),c=null;switch(arguments.length){case 1:b=arguments[0];
break;case 2:b=arguments[0];"function"==typeof arguments[1]?c=arguments[1]:a=arguments[1];break;case 3:b=arguments[0];a=arguments[1];c=arguments[2];break;default:throw Error("Incorrect number of arguments: expected 1-3");}return m.dialog(b,{label:a,icon:g.OK,callback:c},{onEscape:c||!0})},confirm:function(){var b="",a=h("CANCEL"),c=h("CONFIRM"),e=null;switch(arguments.length){case 1:b=arguments[0];break;case 2:b=arguments[0];"function"==typeof arguments[1]?e=arguments[1]:a=arguments[1];break;case 3:b=
arguments[0];a=arguments[1];"function"==typeof arguments[2]?e=arguments[2]:c=arguments[2];break;case 4:b=arguments[0];a=arguments[1];c=arguments[2];e=arguments[3];break;default:throw Error("Incorrect number of arguments: expected 1-4");}var j=function(){"function"===typeof e&&e(!1)};return m.dialog(b,[{label:a,icon:g.CANCEL,callback:j},{label:c,icon:g.CONFIRM,callback:function(){"function"===typeof e&&e(!0)}}],{onEscape:j})},prompt:function(){var b="",a=h("CANCEL"),c=h("CONFIRM"),e=null,j="";switch(arguments.length){case 1:b=
arguments[0];break;case 2:b=arguments[0];"function"==typeof arguments[1]?e=arguments[1]:a=arguments[1];break;case 3:b=arguments[0];a=arguments[1];"function"==typeof arguments[2]?e=arguments[2]:c=arguments[2];break;case 4:b=arguments[0];a=arguments[1];c=arguments[2];e=arguments[3];break;case 5:b=arguments[0];a=arguments[1];c=arguments[2];e=arguments[3];j=arguments[4];break;default:throw Error("Incorrect number of arguments: expected 1-5");}var d=n("<form></form>");d.append("<input autocomplete=off type=text value='"+
j+"' />");var j=function(){"function"===typeof e&&e(null)},k=m.dialog(d,[{label:a,icon:g.CANCEL,callback:j},{label:c,icon:g.CONFIRM,callback:function(){"function"===typeof e&&e(d.find("input[type=text]").val())}}],{header:b,show:!1,onEscape:j});k.on("shown",function(){d.find("input[type=text]").focus();d.on("submit",function(a){a.preventDefault();k.find(".btn-primary").click()})});k.modal("show");return k},dialog:function(b,a,c){var e="",j=[];c=c||{};null==a?a=[]:"undefined"==typeof a.length&&(a=
[a]);for(var d=a.length;d--;){var k=null,g=null,h=null,l="",m=null;if("undefined"==typeof a[d].label&&"undefined"==typeof a[d]["class"]&&"undefined"==typeof a[d].callback){var k=0,g=null,p;for(p in a[d])if(g=p,1<++k)break;1==k&&"function"==typeof a[d][p]&&(a[d].label=g,a[d].callback=a[d][p])}"function"==typeof a[d].callback&&(m=a[d].callback);a[d]["class"]?h=a[d]["class"]:d==a.length-1&&2>=a.length&&(h="btn-primary");k=a[d].label?a[d].label:"Option "+(d+1);a[d].icon&&(l="<i class='"+a[d].icon+"'></i> ");
g=a[d].href?a[d].href:"javascript:;";e="<a data-handler='"+d+"' class='btn "+h+"' href='"+g+"'>"+l+""+k+"</a>"+e;j[d]=m}d=["<div class='bootbox modal' tabindex='-1' style='overflow:hidden;'>"];if(c.header){h="";if("undefined"==typeof c.headerCloseButton||c.headerCloseButton)h="<a href='javascript:;' class='close'>&times;</a>";d.push("<div class='modal-header'>"+h+"<h3>"+c.header+"</h3></div>")}d.push("<div class='modal-body'></div>");e&&d.push("<div class='modal-footer'>"+e+"</div>");d.push("</div>");
var f=n(d.join("\n"));("undefined"===typeof c.animate?t:c.animate)&&f.addClass("fade");(e="undefined"===typeof c.classes?u:c.classes)&&f.addClass(e);f.find(".modal-body").html(b);f.on("hidden",function(){f.remove()});f.on("keyup.dismiss.modal",function(a){if(27==a.which&&c.onEscape){if("function"===typeof c.onEscape)c.onEscape();f.modal("hide")}});f.on("shown",function(){f.find("a.btn-primary:first").focus()});f.on("click",".modal-footer a, a.close",function(b){var c=n(this).data("handler"),d=j[c],
e=null;"undefined"!==typeof c&&"undefined"!==typeof a[c].href||(b.preventDefault(),"function"==typeof d&&(e=d()),!1!==e&&f.modal("hide"))});n("body").append(f);f.modal({backdrop:"undefined"===typeof c.backdrop?q:c.backdrop,keyboard:!1,show:!1});f.on("show",function(){n(v).off("focusin.modal")});("undefined"===typeof c.show||!0===c.show)&&f.modal("show");return f},modal:function(){var b,a,c,e={onEscape:null,keyboard:!0,backdrop:q};switch(arguments.length){case 1:b=arguments[0];break;case 2:b=arguments[0];
"object"==typeof arguments[1]?c=arguments[1]:a=arguments[1];break;case 3:b=arguments[0];a=arguments[1];c=arguments[2];break;default:throw Error("Incorrect number of arguments: expected 1-3");}e.header=a;c="object"==typeof c?n.extend(e,c):e;return m.dialog(b,[],c)},hideAll:function(){n(".bootbox").modal("hide")},animate:function(b){t=b},backdrop:function(b){q=b},classes:function(b){u=b}},l={en:{OK:"OK",CANCEL:"Cancel",CONFIRM:"OK"},fr:{OK:"OK",CANCEL:"Annuler",CONFIRM:"D'accord"},de:{OK:"OK",CANCEL:"Abbrechen",
CONFIRM:"Akzeptieren"},es:{OK:"OK",CANCEL:"Cancelar",CONFIRM:"Aceptar"},br:{OK:"OK",CANCEL:"Cancelar",CONFIRM:"Sim"},nl:{OK:"OK",CANCEL:"Annuleren",CONFIRM:"Accepteren"},ru:{OK:"OK",CANCEL:"\u041e\u0442\u043c\u0435\u043d\u0430",CONFIRM:"\u041f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c"},it:{OK:"OK",CANCEL:"Annulla",CONFIRM:"Conferma"}};return m}(document,window.jQuery);window.bootbox=bootbox;

$("form").submit(function(ev) {
bootbox.confirm("Are you sure?", function(result) {
if (result) {
ev.target.submit();
}
});
return false;
});
</script>
15 changes: 12 additions & 3 deletions nsqadmin/templates/lookup.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,19 @@ <h4>Notice</h4> nsqadmin is not configured with nsqlookupd hosts
</div>
<ul>
{{range $t, $channels := .TopicMap}}
<li><a href="/topic/{{$t}}">{{$t}}</a> <a href="/delete_topic?topic={{$t}}&rd=/lookup" class="red">✘</a>
<li><form class="form-inline" style="margin:0" action="/delete_topic" method="POST">
<input type="hidden" name="rd" value="/lookup">
<input type="hidden" name="topic" value="{{$t}}">
<button class="btn btn-mini btn-link red" type="submit">✘</button><a href="/topic/{{$t}}">{{$t}}</a>
</form>
<ul>
{{range $channels}}
<li><a href="/topic/{{$t}}/{{.}}">{{.}}</a> <a href="/delete_channel?topic={{$t}}&channel={{.}}&rd=/lookup" class="red">✘</a></li>
<li><form class="form-inline" style="margin:0" action="/delete_channel" method="POST">
<input type="hidden" name="rd" value="/lookup">
<input type="hidden" name="topic" value="{{$t}}">
<input type="hidden" name="channel" value="{{.}}">
<button class="btn btn-mini btn-link red" type="submit">✘</button><a href="/topic/{{$t}}/{{.}}">{{.}}</a>
</form></li>
{{end}}
</ul>
</li>
Expand All @@ -51,7 +60,7 @@ <h4>Notice</h4> nsqadmin is not configured with nsqlookupd hosts

<div class="row-fluid">
<div class="span4">
<form class="form" action="/create_topic_channel" method="GET">
<form class="form" action="/create_topic_channel" method="POST">
<fieldset>
<legend>Create Topic/Channel</legend>
<div class="alert alert-info">
Expand Down
11 changes: 9 additions & 2 deletions nsqadmin/templates/topic.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</div>

<div class="row-fluid"><div class="span2">
<form action="/delete_topic" method="GET">
<form action="/delete_topic" method="POST">
<input type="hidden" name="topic" value="{{.Topic}}">
<button class="btn btn-medium btn-danger" type="submit">Delete Topic</button>
</form>
Expand All @@ -42,7 +42,14 @@ <h4>Topic Message Queue</h4>
</tr>
{{range .TopicHostStats}}
<tr>
<td><a href="/tombstone_topic_producer?topic={{.Topic}}&node={{.HostAddress}}&rd=/topic/{{.Topic}}" class="red">✘</a> {{.HostAddress}}</td>
<td>
<form class="form-inline" style="margin:0" action="/tombstone_topic_producer" method="POST">
<input type="hidden" name="rd" value="/topic/{{.Topic}}">
<input type="hidden" name="topic" value="{{.Topic}}">
<input type="hidden" name="node" value="{{.HostAddress}}">
<button class="btn btn-mini btn-link red" type="submit">✘</button>{{.HostAddress}}
</form>
</td>
<td>
{{if $g.Enabled}}<a href="{{.LargeGraph $g "depth"}}"><img width="120" src="{{.Sparkline $g "depth"}}"></a>{{end}}
{{.Depth | commafy}}</td>
Expand Down
2 changes: 1 addition & 1 deletion nsqd/diskqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func TestDiskQueueEmpty(t *testing.T) {

func TestDiskQueueCorruption(t *testing.T) {
log.SetOutput(ioutil.Discard)
log.SetOutput(os.Stdout)
defer log.SetOutput(os.Stdout)

dqName := "test_disk_queue_corruption" + strconv.Itoa(int(time.Now().Unix()))
dq := NewDiskQueue(dqName, os.TempDir(), 1000, 5)
Expand Down
8 changes: 8 additions & 0 deletions util/req_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,11 @@ func (r *ReqParams) GetAll(key string) ([]string, error) {
}
return v, nil
}

type PostParams struct {
*http.Request
}

func (p *PostParams) Get(key string) (string, error) {
return p.Request.FormValue(key), nil
}
6 changes: 5 additions & 1 deletion util/topic_channel_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import (
"errors"
)

func GetTopicChannelArgs(rp *ReqParams) (string, string, error) {
type Getter interface {
Get(key string) (string, error)
}

func GetTopicChannelArgs(rp Getter) (string, string, error) {
topicName, err := rp.Get("topic")
if err != nil {
return "", "", errors.New("MISSING_ARG_TOPIC")
Expand Down