Refactoring of WANavigation and i,plementation of Service Status
This commit is contained in:
parent
e201f9ce4c
commit
b115a9cb4f
14 changed files with 101 additions and 91 deletions
|
|
@ -7,6 +7,7 @@ body{
|
|||
/*margin-bottom: 30px; /* Margin bottom by footer height */
|
||||
}
|
||||
table{
|
||||
font-family: sans-serif;
|
||||
font-size: 100%;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<div class="col-md-12"><div class="panel panel-default">
|
||||
<div class="panel-heading">Service Status</div>
|
||||
<div class="panel-body">
|
||||
<table class="table small hdd-detail">
|
||||
<table class="table hdd-detail">
|
||||
<thead><tr>
|
||||
<th data-field="service">Service</th>
|
||||
<th data-field="status">Status</th>
|
||||
|
|
@ -9,14 +9,14 @@
|
|||
</tr></thead>
|
||||
{{#services}}
|
||||
<tr>
|
||||
<td>{{.name}}</td>
|
||||
<td>{{.getName()}}</td>
|
||||
<td>
|
||||
{{#.isRunning()}}<span class="label label-success">Running</span>{{/.isRunning()}}
|
||||
{{#.isUnresponsive()}}<span class="label label-warning">Unresponsive</span>{{/.isUnresponsive()}}
|
||||
{{#.isStopped()}}<span class="label label-danger">Stopped</span>{{/.isStopped()}}
|
||||
{{#.isUnknown()}}<span class="label label-default">Unknown</span>{{/.isUnknown()}}
|
||||
</td>
|
||||
<td><input type="checkbox" class="switch" checked></td>
|
||||
<td><input type="checkbox" class="switch" data-size="mini" checked></td>
|
||||
</tr>
|
||||
{{/services}}
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
<script src="js/bootstrap-switch.min.js"></script>
|
||||
|
||||
<script>
|
||||
$.(function(){
|
||||
$("input .switch[type='checkbox']").bootstrapSwitch();
|
||||
$(function() {
|
||||
$(".switch[type='checkbox']").bootstrapSwitch();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
|
@ -30,21 +30,21 @@
|
|||
<a class="navbar-brand" href="#">{{title}}</a>
|
||||
<ul class="nav navbar-nav">
|
||||
{{#top-nav}}
|
||||
{{^.sub_navs.length}}
|
||||
{{^.subNav.length}}
|
||||
<li><a href="{{.url}}">{{.name}}</a></li>
|
||||
{{/.sub_navs.length}}
|
||||
{{#.sub_navs.length}}
|
||||
{{/.subNav.length}}
|
||||
{{#.subNav.length}}
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
|
||||
{{.name}} <b class="caret"></b>
|
||||
</a>
|
||||
<ul class="dropdown-menu">
|
||||
{{#.sub_navs}}
|
||||
{{#.subNav}}
|
||||
<li><a href="{{.url}}">{{.name}}</a></li>
|
||||
{{/.sub_navs}}
|
||||
{{/.subNav}}
|
||||
</ul>
|
||||
</li>
|
||||
{{/.sub_navs.length}}
|
||||
{{/.subNav.length}}
|
||||
{{/top-nav}}
|
||||
</ul>
|
||||
</nav>
|
||||
|
|
@ -55,21 +55,21 @@
|
|||
<div id="side-bar" class="col-md-2">
|
||||
<ul class="side-menu nav nav-pills nav-stacked">
|
||||
{{#side-nav}}
|
||||
{{^.sub_navs.length}}
|
||||
{{^.subNavs.length}}
|
||||
<li><a href="{{.url}}">{{.name}}</a></li>
|
||||
{{/.sub_navs.length}}
|
||||
{{#.sub_nav.length}}
|
||||
{{/.subNavs.length}}
|
||||
{{#.subNav.length}}
|
||||
<li class="">
|
||||
<a data-toggle="collapse" data-parent="#side-bar" href="#{{.name}}_collapse">
|
||||
{{.name}} <b class="caret"></b>
|
||||
</a>
|
||||
<ul id="{{.name}}_collapse" class="side-sub-menu collapse nav nav-pills nav-stacked ">
|
||||
{{#.sub_navs}}
|
||||
{{#.subNavs}}
|
||||
<li><a href="{{.url}}">{{.name}}</a></li>
|
||||
{{/.sub_navs}}
|
||||
{{/.subNavs}}
|
||||
</ul>
|
||||
</li>
|
||||
{{/.sub_nav.length}}
|
||||
{{/.subNav.length}}
|
||||
{{/side-nav}}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
@ -46,7 +46,7 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class WAAbstractPage implements HttpPage{
|
||||
private static final Logger log = LogUtil.getLogger();
|
||||
private static final String TMPL_FILE = "WebContent/index.tmpl";
|
||||
private static final String TMPL_FILE = "WebContent/page/index.tmpl";
|
||||
|
||||
private List<WAPage> pages;
|
||||
private Templator tmpl;
|
||||
|
|
@ -100,7 +100,7 @@ public class WAAbstractPage implements HttpPage{
|
|||
tmpl.set("top-nav", context.getNavigation());
|
||||
tmpl.set("side-nav-show", true);
|
||||
if(breadcrumb.size() >= 1)
|
||||
tmpl.set("side-nav", breadcrumb.get(0).getSubNav());
|
||||
tmpl.set("side-nav", breadcrumb.get(0).getSubNavs());
|
||||
tmpl.set("breadcrumb", breadcrumb);
|
||||
tmpl.set("alerts", context.getAlerts());
|
||||
//tmpl.set("footer", null);
|
||||
|
|
@ -109,7 +109,8 @@ public class WAAbstractPage implements HttpPage{
|
|||
if(page != null)
|
||||
content = page.htmlResponse(context, client_info, session, cookie, request);
|
||||
if(content != null) {
|
||||
content.set("nav", context.getBreadcrumb().get(1));
|
||||
if(!breadcrumb.isEmpty())
|
||||
content.set("nav", breadcrumb.get(breadcrumb.size() - 1));
|
||||
tmpl.set("content", content.compile());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import wa.server.page.struct.WAAlert;
|
|||
import wa.server.page.struct.WANavigation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
|
@ -44,7 +43,7 @@ public class WAContext {
|
|||
nav = WANavigation.getRootNav();
|
||||
|
||||
// Breadcrumb
|
||||
breadcrumb = WANavigation.getNavResource(request);
|
||||
breadcrumb = WANavigation.getNavBreadcrumb(request);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -48,21 +48,25 @@ public class ServicePage implements WAPage {
|
|||
private static final String TMPL_FILE = "WebContent/page/ServicePage.tmpl";
|
||||
|
||||
private ArrayList<WAService> services;
|
||||
private ArrayList<ServiceStatusPage> statuses;
|
||||
private ServiceStatusPage rootStatusPage;
|
||||
private ArrayList<ServiceStatusPage> statusPages;
|
||||
|
||||
public ServicePage(PluginManager pluginManager){
|
||||
this.services = pluginManager.toArray(WAService.class);
|
||||
this.statuses = new ArrayList<>();
|
||||
this.rootStatusPage = new ServiceStatusPage(pluginManager);
|
||||
this.statusPages = new ArrayList<>();
|
||||
|
||||
WANavigation nav = new WANavigation(NAVIGATION_NAME, this);
|
||||
WANavigation nav = WANavigation.getRootNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
for(WAService plugin : services) {
|
||||
statuses.add(new ServiceStatusPage(plugin.getStatus()));
|
||||
nav.addSubNav(new WANavigation(plugin.getName(), plugin));
|
||||
for(WAServiceConfig conf : plugin.getConfigurations()){
|
||||
statusPages.add(new ServiceStatusPage(plugin.getStatus()));
|
||||
|
||||
WANavigation serviceNav = nav.getSubNav(plugin.getName());
|
||||
serviceNav.setResource(plugin);
|
||||
for(WAServiceConfig conf : plugin.getConfigurations()){
|
||||
//serviceNav.getSubNav(conf.getName()).setResource(conf);
|
||||
}
|
||||
}
|
||||
WANavigation.addRootNav(nav);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -74,16 +78,20 @@ public class ServicePage implements WAPage {
|
|||
Map<String, String> request) {
|
||||
|
||||
try {
|
||||
int index = services.indexOf(context.getBreadcrumb().get(1).getResource());
|
||||
if(index < 0)
|
||||
return null;
|
||||
WAService obj = services.get(index);
|
||||
ServiceStatusPage statusPage = statuses.get(index);
|
||||
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
tmpl.set("service_status",
|
||||
statusPage.htmlResponse(context, client_info, session, cookie, request).compile());
|
||||
return tmpl;
|
||||
int index = services.indexOf(context.getBreadcrumb().get(1).getResource());
|
||||
if (index >= 0) {
|
||||
WAService obj = services.get(index);
|
||||
ServiceStatusPage statusPage = statusPages.get(index);
|
||||
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
tmpl.set("service_status",
|
||||
statusPage.htmlResponse(context, client_info, session, cookie, request).compile());
|
||||
return tmpl;
|
||||
}
|
||||
else{ // root page
|
||||
return rootStatusPage.htmlResponse(context, client_info, session, cookie, request);
|
||||
}
|
||||
|
||||
}catch (IOException e){
|
||||
log.log(Level.SEVERE, null, e);
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@ import zutil.parser.DataNode;
|
|||
import zutil.parser.Templator;
|
||||
import zutil.plugin.PluginManager;
|
||||
|
||||
import javax.xml.crypto.Data;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
|
@ -57,8 +56,8 @@ public class ServiceStatusPage implements WAPage {
|
|||
public ServiceStatusPage(PluginManager pluginManager){
|
||||
this.services = pluginManager.toArray(WAServiceStatus.class);
|
||||
|
||||
WANavigation.getRootNav(ServicePage.NAVIGATION_NAME).addSubNav(
|
||||
new WANavigation(NAVIGATION_NAME, this));
|
||||
WANavigation nav = WANavigation.getRootNav(ServicePage.NAVIGATION_NAME).getSubNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -44,10 +44,10 @@ public class StatusPage implements WAPage {
|
|||
public StatusPage(PluginManager pluginManager){
|
||||
this.plugins = pluginManager.toArray(WAStatus.class);
|
||||
|
||||
WANavigation nav = new WANavigation(NAVIGATION_NAME, this);
|
||||
WANavigation nav = WANavigation.getRootNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
for(WAStatus plugin : plugins)
|
||||
nav.addSubNav(new WANavigation(plugin.getName(), plugin));
|
||||
WANavigation.addRootNav(nav);
|
||||
nav.getSubNav(plugin.getName()).setResource(plugin);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -27,46 +27,49 @@ import java.util.*;
|
|||
/**
|
||||
* Created by Ziver on 2015-04-02.
|
||||
*/
|
||||
public class WANavigation {
|
||||
private static int nextId;
|
||||
private static List<WANavigation> root_nav = new ArrayList<WANavigation>();
|
||||
private static HashMap<Integer, WANavigation> nav_map = new HashMap<Integer, WANavigation>();
|
||||
public class WANavigation implements Iterable{
|
||||
private static int nextId = 0;
|
||||
private static HashMap<Integer, WANavigation> navMap = new HashMap<Integer, WANavigation>();
|
||||
private static WANavigation rootNav = new WANavigation(null);
|
||||
|
||||
private int id;
|
||||
private String url;
|
||||
private String name;
|
||||
private ArrayList<WANavigation> sub_navs;
|
||||
private ArrayList<WANavigation> subNav;
|
||||
|
||||
private WANavigation parent_nav;
|
||||
private WANavigation parentNav;
|
||||
private Object resource;
|
||||
|
||||
|
||||
public WANavigation(String name) {
|
||||
private WANavigation(String name) {
|
||||
this.id = nextId++;
|
||||
this.nav_map.put(this.id, this);
|
||||
this.navMap.put(this.id, this);
|
||||
this.url = "?i="+this.id;
|
||||
this.name = name;
|
||||
this.sub_navs = new ArrayList<>();
|
||||
}
|
||||
public WANavigation(String name, Object resource) {
|
||||
this(name);
|
||||
this.setResource(resource);
|
||||
this.subNav = new ArrayList<>();
|
||||
}
|
||||
|
||||
|
||||
public void addSubNav(WANavigation subNav) {
|
||||
this.sub_navs.add(subNav);
|
||||
@Override
|
||||
public Iterator iterator() {
|
||||
return subNav.iterator();
|
||||
}
|
||||
public List<WANavigation> getSubNavs() {
|
||||
return subNav;
|
||||
}
|
||||
public WANavigation getSubNav(String name) {
|
||||
for(WANavigation nav : subNav) {
|
||||
if(nav.equals(name))
|
||||
return nav;
|
||||
}
|
||||
WANavigation nav = new WANavigation(name);
|
||||
this.addSubNav(nav);
|
||||
return nav;
|
||||
}
|
||||
private void addSubNav(WANavigation subNav) {
|
||||
this.subNav.add(subNav);
|
||||
subNav.setParentNav(this );
|
||||
}
|
||||
public List<WANavigation> getSubNav() {
|
||||
return sub_navs;
|
||||
}
|
||||
public Object getSubNav(String name) {
|
||||
int index = sub_navs.indexOf(name);
|
||||
if(index >= 0)
|
||||
return sub_navs.get(index);
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
|
|
@ -79,9 +82,10 @@ public class WANavigation {
|
|||
}
|
||||
|
||||
private void setParentNav(WANavigation nav){
|
||||
this.parent_nav = nav;
|
||||
this.parentNav = nav;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o){
|
||||
if(o instanceof String)
|
||||
return this.name.equals(o);
|
||||
|
|
@ -90,27 +94,20 @@ public class WANavigation {
|
|||
}
|
||||
|
||||
|
||||
public static void addRootNav(WANavigation nav){
|
||||
getRootNav().add(nav);
|
||||
}
|
||||
public static List<WANavigation> getRootNav(){
|
||||
return root_nav;
|
||||
return rootNav.getSubNavs();
|
||||
}
|
||||
public static WANavigation getRootNav(String name){
|
||||
for(WANavigation nav : root_nav){
|
||||
if(nav.getName().equals(name))
|
||||
return nav;
|
||||
}
|
||||
return null;
|
||||
return rootNav.getSubNav(name);
|
||||
}
|
||||
|
||||
public static List<WANavigation> getNavResource(Map<String, String> request) {
|
||||
public static List<WANavigation> getNavBreadcrumb(Map<String, String> request) {
|
||||
LinkedList list = new LinkedList();
|
||||
if(request.containsKey("i")){
|
||||
WANavigation current = nav_map.get(Integer.parseInt(request.get("i")));
|
||||
while(current != null){
|
||||
WANavigation current = navMap.get(Integer.parseInt(request.get("i")));
|
||||
while(current != null && current != rootNav){
|
||||
list.addFirst(current);
|
||||
current = current.parent_nav;
|
||||
current = current.parentNav;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ public class ApacheConfig implements WAServiceConfig {
|
|||
vhosts = new LinkedList<ApacheConfigVirtualHost>();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void read() throws SQLException {
|
||||
DBConnection db = WAConstants.getDB();
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ import java.util.logging.Logger;
|
|||
|
||||
public class ApacheStatus extends WAServiceStatus {
|
||||
private static final Logger log = LogUtil.getLogger();
|
||||
private static final String PID_FILE = "/var/run/apache2.pid";
|
||||
private static final String PID_FILE_PATH = "/var/run/apache2.pid";
|
||||
|
||||
private static OSAbstractionLayer os = OSAbstractionLayer.getInstance();
|
||||
|
||||
|
|
@ -58,11 +58,14 @@ public class ApacheStatus extends WAServiceStatus {
|
|||
@Override
|
||||
public ServiceStatusType getStatus() {
|
||||
try {
|
||||
int pid = Integer.parseInt(
|
||||
FileUtil.getContent(new File(PID_FILE)));
|
||||
if(Ps.isRunning(pid))
|
||||
return ServiceStatusType.RUNNING;
|
||||
return ServiceStatusType.STOPPED;
|
||||
File pidFile = new File(PID_FILE_PATH);
|
||||
if(pidFile.exists()) {
|
||||
int pid = Integer.parseInt(
|
||||
FileUtil.getContent(pidFile));
|
||||
if (Ps.isRunning(pid))
|
||||
return ServiceStatusType.RUNNING;
|
||||
return ServiceStatusType.STOPPED;
|
||||
}
|
||||
}catch(IOException e){
|
||||
log.log(Level.WARNING, null, e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
"version": "1.0",
|
||||
"name": "Apache Web Server",
|
||||
"interfaces": {
|
||||
"wa.server.plugin.WAService": "wa.server.plugin.apache.ApacheService"
|
||||
"wa.server.plugin.WAService": "wa.server.plugin.apache.ApacheService",
|
||||
"wa.server.plugin.WAServiceStatus": "wa.server.plugin.apache.ApacheStatus"
|
||||
}
|
||||
}
|
||||
|
|
@ -103,7 +103,9 @@ function updateNet(){
|
|||
$(element).find(".net-total-tx").html(byteToString(net.total_tx));
|
||||
$(element).find(".net-dropped").html(net.dropped);
|
||||
$(element).find(".net-error").html(net.error);
|
||||
$(element).find(".net-up").html( (net.up ? "<b class='green'>UP</b>" : "<b class='red'>DOWN</b>") );
|
||||
$(element).find(".net-up").html( (net.up ?
|
||||
"<span class='label label-success'>UP</span>" :
|
||||
"<span class='label label-danger'>DOWN</span>") );
|
||||
$(element).find(".net-ip").html(net.ip);
|
||||
$(element).find(".net-netmask").html(net.netmask);
|
||||
$(element).find(".net-mac").html(net.mac);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue