Commit bfd63ec9 authored by Geoff Simmons's avatar Geoff Simmons

Add vsm Status struct and method.

parent b70e72db
......@@ -149,3 +149,56 @@ func TestPointer(t *testing.T) {
t.Error("expected uninitialized.VSM == nil")
}
}
func TestStatus(t *testing.T) {
v := New()
defer v.Destroy()
if v.VSM == nil {
t.Fatal("VSM handle is nil")
return
}
if err := v.Attach(""); err != nil {
t.Fatal("Attach(default):", err)
return
}
status, err := v.Status()
if err != nil {
t.Error("Status():", err)
}
vsmerr := v.Error()
if vsmerr != "No VSM error" {
t.Errorf("Error() after Status() want='No VSM Error' got='%v'",
vsmerr)
}
unattached := New()
defer unattached.Destroy()
if unattached.VSM == nil {
t.Fatal("VSM handle is nil")
return
}
status, err = unattached.Status()
if err != nil {
t.Error("unattached.Status():", err)
}
if status.MgtRunning {
t.Error("unattached.Status().MgtRunning == true")
}
if status.WrkRunning {
t.Error("unattached.Status().WrkRunning == true")
}
vsmerr = unattached.Error()
if vsmerr == "No VSM error" {
t.Error("Error() after unattached.Status():", vsmerr)
}
var n *VSM
if status, err = n.Status(); err == nil {
t.Error("expected nil.Status() to fail")
}
uninit := new(VSM)
if status, err = uninit.Status(); err == nil {
t.Error("expected uninitialized.Status() to fail")
}
}
......@@ -34,6 +34,27 @@ package vsm
#cgo pkg-config: varnishapi
#include <stdint.h>
#include <vapi/vsm.h>
struct status {
unsigned mgt_running;
unsigned mgt_changed;
unsigned mgt_restarted;
unsigned wrk_running;
unsigned wrk_changed;
unsigned wrk_restarted;
};
void
status(struct vsm *vsm, struct status *status)
{
unsigned bits = VSM_Status(vsm);
status->mgt_running = bits & VSM_MGT_RUNNING;
status->mgt_changed = bits & VSM_MGT_CHANGED;
status->mgt_restarted = bits & VSM_MGT_RESTARTED;
status->wrk_running = bits & VSM_WRK_RUNNING;
status->wrk_changed = bits & VSM_WRK_CHANGED;
status->wrk_restarted = bits & VSM_WRK_RESTARTED;
}
*/
import "C"
......@@ -139,6 +160,44 @@ func (v *VSM) Attach(name string) error {
return nil
}
// A Status contains information about the state of the Varnish
// management and child processes since the last time Status() was
// called, or since the VSM client attached.
//
// For the two processes: whether the process is running, whether it
// was restarted, or whether the internal mappings have changed (for
// example, when statistics have been added or removed at runtime).
type Status struct {
MgtRunning bool
MgtChanged bool
MgtRestarted bool
WrkRunning bool
WrkChanged bool
WrkRestarted bool
}
// Status returns a Status object describing the state of the Varnish
// management and worker processes, and whether internal mappings have
// changed since the last invocation of Status(), or (if it was never
// called) since the instance was attached.
func (v *VSM) Status() (Status, error) {
errStatus := Status{}
if err := v.checkNil(); err != nil {
return errStatus, err
}
var cstatus C.struct_status
C.VSM_ResetError(v.VSM)
C.status(v.VSM, &cstatus)
return Status{
MgtRunning: cstatus.mgt_running != 0,
MgtChanged: cstatus.mgt_changed != 0,
MgtRestarted: cstatus.mgt_restarted != 0,
WrkRunning: cstatus.wrk_running != 0,
WrkChanged: cstatus.wrk_changed != 0,
WrkRestarted: cstatus.wrk_restarted != 0,
}, nil
}
/*
func (v *VSM) Get(class string, ident string) (string, error) {
var vf C.struct_vsm_fantom
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment