-
Notifications
You must be signed in to change notification settings - Fork 0
/
aeroview.php
219 lines (174 loc) · 6.84 KB
/
aeroview.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/**
* index.php
*
* PHP version 5.3
*
* @category AeroView
* @package Application
* @author Chris Maynard <[email protected]>
*/
class AeroView
{
/**
* Create a valid query string
*
* @param none
* @return string
*/
public function buildQueryString() {
$queryString = array();
$string = "?";
$host = $namespace = $set = "";
if (isset($_GET['host'])) {
$string = $string . "host=" . $_GET['host'] . "&";
$host = $_GET['host'];
}
if (isset($_GET['namespace'])) {
$string = $string . "namespace=" . $_GET['namespace'] . "&";
$namespace = $_GET['namespace'];
}
if (isset($_GET['set'])) {
$string = $string . "set=" . $_GET['set'];
$set = $_GET['set'];
}
$queryString['qs'] = $string;
$queryString['host'] = $host;
$queryString['namespace'] = $namespace;
$queryString['set'] = $set;
return $queryString;
}
/**
* Validate query string, connect to aspike
*
* @param boolean $host
* @param boolean $namespace
* @param boolean $set
* @return array
*/
public function validateQueryString($qs, $host = false, $namespace = false, $set = false) {
$finalhosts = array();
if ($host && isset($_GET['host'])) {
$hostarr = explode(",", $_GET['host']);
foreach ($hostarr as $h) {
$finalhosts[] = array("addr" => $h, "port" => 3000);
}
} else {
echo "<div class='alert alert-info'><strong>Missing Host!</strong> Please select a <a href='/index.php";
echo $qs['qs'] . "'>Host</a> to view explore namespaces.</div>";
}
if ($namespace && !isset($_GET['namespace'])) {
echo "<div class='alert alert-info'><strong>Missing Namespace!</strong> Please select a <a href='/namespaces.php";
echo $qs['qs'] . "'>namespace</a> to view explore sets.</div>";
}
if ($set && !isset($_GET['set'])) {
echo "<div class='alert alert-info'><strong>Missing Set!</strong> Please select a <a href='/sets.php";
echo $qs['qs'] . "'>set</a> to view explore records.</div>";
}
return $finalhosts;
}
/**
* Validate query string, connect to aspike
*
* @param array $hosts
* @return array
*/
public function connectAero($hosts) {
$config = array("hosts"=> $hosts);
$opts = array(Aerospike::OPT_CONNECT_TIMEOUT => 1000000, Aerospike::OPT_WRITE_TIMEOUT => 2500);
$db = new Aerospike($config, true, $opts);
if (!$db->isConnected()) {
echo "<div class='alert alert-danger'><strong>Aerospike Error!</strong> " . $db->errorno() ." : " . $db->error() . "</div>";
exit(1);
}
return $db;
}
/**
* Call aspike info for namespaces
*
* @param array $db
* @return array
*/
public function getNamespaces($db) {
$namespaces = array();
$status = $db->info('namespaces', $response);
if ($status == Aerospike::OK) {
$namespaces = explode(";",str_replace("namespaces", "", $response));
}
return $namespaces;
}
/**
* Format for set names and object count
*
* @param array $allNodes
* @return array
*/
public function getNodeSetsAndObjectCount($allNodes) {
$final = array();
//infoMany returns values for each node in the cluster
foreach ($allNodes as $node) {
$nodeSets = explode(";", $node);
//iterate over this node's sets
foreach ($nodeSets as $set) {
$setInfo = explode(":", $set);
if (isset($setInfo[1]) && isset($setInfo[2])) {
$setKey = str_replace("set_name=", "", $setInfo[1]);
//add the object count to the result set or if it's new create a key for the set name
if (isset($final[$setKey])) {
$newCount = (int) $final[$setKey] + (int) str_replace("n_objects=", "", $setInfo[2]);
$final[$setKey] = $newCount;
} else {
$final[$setKey] = (int) str_replace("n_objects=", "", $setInfo[2]);
}
}
}
}
return $final;
}
/**
* Dynamic Top and Left Nav
*
* @param array $qs
* @param string $active
* @return string
*/
public function loadNavigationView($qs, $active, $config) {
$hostli = "<li><a href='index.php" . $qs['qs'] ."'><i class='fa fa-fw fa-server aeroview-green'></i> <span class='aeroqsinfo'>" . array_search ($qs['host'], $config) . "</span></a></li>";
$namespaceli = "<li><a href='namespaces.php" . $qs['qs'] . "'><i class='fa fa-fw fa-database aeroview-green'></i> <span class='aeroqsinfo'>" . $qs['namespace'] . "</span></a></li>";
$setli = "<li><a href='sets.php" . $qs['qs'] . "'><i class='fa fa-fw fa-table aeroview-green'></i> <span class='aeroqsinfo'>" . $qs['set'] . "</span></a></li>";
$html = '<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand aeroview-green" href="index.php">AeroView</a>
</div>
<ul class="nav navbar-right top-nav">
'. (isset($qs['host']) && !empty($qs['host']) ? "$hostli" : "") .''.
(isset($qs['namespace']) && !empty($qs['namespace']) ? "$namespaceli" : "").''.
(isset($qs['set']) && !empty($qs['set']) ? "$setli" : "").'
</ul>
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li class="'. ($active == "hosts" ? "active": "") .'">
<a href="index.php' . $qs["qs"] .'"><i class="fa fa-fw fa-server"></i> Hosts</a>
</li>
<li class="'. ($active == "namespaces" ? "active": "") .'">
<a href="namespaces.php' . $qs["qs"] .'"><i class="fa fa-fw fa-database"></i> Namespaces</a>
</li>
<li class="'. ($active == "sets" ? "active": "") .'">
<a href="sets.php' . $qs["qs"] .'"><i class="fa fa-fw fa-table"></i> Sets</a>
</li>
<li class="'. ($active == "records" ? "active": "") .'">
<a href="records.php' . $qs["qs"] .'"><i class="fa fa-fw fa-file-o"></i> Records</a>
</li>
</ul>
</div>
</nav>';
return $html;
}
}
?>