Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishapi
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishapi
Commits
bfd63ec9
Commit
bfd63ec9
authored
Aug 21, 2018
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add vsm Status struct and method.
parent
b70e72db
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
0 deletions
+112
-0
e2e_test.go
internal/pkg/vsm/e2e_test.go
+53
-0
vsm.go
internal/pkg/vsm/vsm.go
+59
-0
No files found.
internal/pkg/vsm/e2e_test.go
View file @
bfd63ec9
...
@@ -149,3 +149,56 @@ func TestPointer(t *testing.T) {
...
@@ -149,3 +149,56 @@ func TestPointer(t *testing.T) {
t
.
Error
(
"expected uninitialized.VSM == nil"
)
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"
)
}
}
internal/pkg/vsm/vsm.go
View file @
bfd63ec9
...
@@ -34,6 +34,27 @@ package vsm
...
@@ -34,6 +34,27 @@ package vsm
#cgo pkg-config: varnishapi
#cgo pkg-config: varnishapi
#include <stdint.h>
#include <stdint.h>
#include <vapi/vsm.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"
import
"C"
...
@@ -139,6 +160,44 @@ func (v *VSM) Attach(name string) error {
...
@@ -139,6 +160,44 @@ func (v *VSM) Attach(name string) error {
return
nil
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) {
func (v *VSM) Get(class string, ident string) (string, error) {
var vf C.struct_vsm_fantom
var vf C.struct_vsm_fantom
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment