Some progress on service configuration
This commit is contained in:
parent
29def452b6
commit
ab7296198a
10 changed files with 138 additions and 84 deletions
|
|
@ -108,8 +108,10 @@ public class WAAbstractPage implements HttpPage{
|
||||||
Templator content = null;
|
Templator content = null;
|
||||||
if(page != null)
|
if(page != null)
|
||||||
content = page.htmlResponse(context, client_info, session, cookie, request);
|
content = page.htmlResponse(context, client_info, session, cookie, request);
|
||||||
if(content != null)
|
if(content != null) {
|
||||||
|
tmpl.set("nav", context.getBreadcrumb().get(1));
|
||||||
tmpl.set("content", content.compile());
|
tmpl.set("content", content.compile());
|
||||||
|
}
|
||||||
|
|
||||||
out.print(tmpl.compile());
|
out.print(tmpl.compile());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@ public class WebAdminServer {
|
||||||
|
|
||||||
HttpServer http = new HttpServer(80);
|
HttpServer http = new HttpServer(80);
|
||||||
http.setPage("/", new WAAbstractPage(pluginManager));
|
http.setPage("/", new WAAbstractPage(pluginManager));
|
||||||
|
//http.setPage("status", new StatusPage(pluginManager));
|
||||||
|
//http.setPage("service", new ServicePage(pluginManager));
|
||||||
|
//http.setPage("servicestatus", new ServiceStatusPage(pluginManager));
|
||||||
http.setDefaultPage(new HttpFilePage(FileUtil.find("WebContent/")));
|
http.setDefaultPage(new HttpFilePage(FileUtil.find("WebContent/")));
|
||||||
http.start();
|
http.start();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ package wa.server.page;
|
||||||
import wa.server.WAContext;
|
import wa.server.WAContext;
|
||||||
import wa.server.page.struct.WANavigation;
|
import wa.server.page.struct.WANavigation;
|
||||||
import wa.server.plugin.WAService;
|
import wa.server.plugin.WAService;
|
||||||
|
import wa.server.plugin.WAServiceStatus;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
import zutil.net.http.HttpHeaderParser;
|
import zutil.net.http.HttpHeaderParser;
|
||||||
|
|
@ -43,16 +44,21 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
public class ServicePage implements WAPage {
|
public class ServicePage implements WAPage {
|
||||||
private static final Logger log = LogUtil.getLogger();
|
private static final Logger log = LogUtil.getLogger();
|
||||||
|
public static final String NAVIGATION_NAME = "Services";
|
||||||
private static final String TMPL_FILE = "WebContent/page/ServicePage.tmpl";
|
private static final String TMPL_FILE = "WebContent/page/ServicePage.tmpl";
|
||||||
|
|
||||||
private ArrayList<WAService> plugins;
|
private ArrayList<WAService> services;
|
||||||
|
private ArrayList<ServiceStatusPage> statuses;
|
||||||
|
|
||||||
public ServicePage(PluginManager pluginManager){
|
public ServicePage(PluginManager pluginManager){
|
||||||
this.plugins = pluginManager.toArray(WAService.class);
|
this.services = pluginManager.toArray(WAService.class);
|
||||||
|
this.statuses = new ArrayList<>();
|
||||||
|
|
||||||
WANavigation nav = new WANavigation("Services");
|
WANavigation nav = new WANavigation(NAVIGATION_NAME, this);
|
||||||
for(WAService plugin : plugins)
|
for(WAService plugin : services) {
|
||||||
nav.addSubNav(new WANavigation(plugin.getName()));
|
nav.addSubNav(new WANavigation(plugin.getName()));
|
||||||
|
statuses.add(new ServiceStatusPage(plugin.getStatus()));
|
||||||
|
}
|
||||||
WANavigation.addRootNav(nav);
|
WANavigation.addRootNav(nav);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,13 +71,17 @@ public class ServicePage implements WAPage {
|
||||||
Map<String, String> request) {
|
Map<String, String> request) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
WAService obj = getPlugin(context);
|
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;
|
||||||
|
|
||||||
if (obj != null) {
|
|
||||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
|
||||||
tmpl.set("nav", context.getBreadcrumb().get(1));
|
|
||||||
return tmpl;
|
|
||||||
}
|
|
||||||
}catch (IOException e){
|
}catch (IOException e){
|
||||||
log.log(Level.SEVERE, null, e);
|
log.log(Level.SEVERE, null, e);
|
||||||
}
|
}
|
||||||
|
|
@ -88,13 +98,4 @@ public class ServicePage implements WAPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private WAService getPlugin(WAContext context){
|
|
||||||
if(context.getBreadcrumb().size() >= 2){
|
|
||||||
int i = plugins.indexOf(context.getBreadcrumb().get(1).getResource());
|
|
||||||
if(i >= 0)
|
|
||||||
return plugins.get(i);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ package wa.server.page;
|
||||||
|
|
||||||
import wa.server.WAContext;
|
import wa.server.WAContext;
|
||||||
import wa.server.page.struct.WANavigation;
|
import wa.server.page.struct.WANavigation;
|
||||||
import wa.server.plugin.WAService;
|
import wa.server.plugin.WAServiceStatus;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.log.LogUtil;
|
import zutil.log.LogUtil;
|
||||||
import zutil.net.http.HttpHeaderParser;
|
import zutil.net.http.HttpHeaderParser;
|
||||||
|
|
@ -32,6 +32,7 @@ import zutil.parser.DataNode;
|
||||||
import zutil.parser.Templator;
|
import zutil.parser.Templator;
|
||||||
import zutil.plugin.PluginManager;
|
import zutil.plugin.PluginManager;
|
||||||
|
|
||||||
|
import javax.xml.crypto.Data;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -43,17 +44,21 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
public class ServiceStatusPage implements WAPage {
|
public class ServiceStatusPage implements WAPage {
|
||||||
private static final Logger log = LogUtil.getLogger();
|
private static final Logger log = LogUtil.getLogger();
|
||||||
|
public static final String NAVIGATION_NAME = "Service Status";
|
||||||
private static final String TMPL_FILE = "WebContent/page/ServiceStatusPage.tmpl";
|
private static final String TMPL_FILE = "WebContent/page/ServiceStatusPage.tmpl";
|
||||||
|
|
||||||
private ArrayList<WAService> plugins;
|
private ArrayList<WAServiceStatus> services;
|
||||||
|
|
||||||
|
|
||||||
|
public ServiceStatusPage(WAServiceStatus ss){
|
||||||
|
services = new ArrayList<>();
|
||||||
|
services.add(ss);
|
||||||
|
}
|
||||||
public ServiceStatusPage(PluginManager pluginManager){
|
public ServiceStatusPage(PluginManager pluginManager){
|
||||||
this.plugins = pluginManager.toArray(WAService.class);
|
this.services = pluginManager.toArray(WAServiceStatus.class);
|
||||||
|
|
||||||
WANavigation nav = new WANavigation("Services");
|
WANavigation.getRootNav(ServicePage.NAVIGATION_NAME).addSubNav(
|
||||||
for(WAService plugin : plugins)
|
new WANavigation(NAVIGATION_NAME, this));
|
||||||
nav.addSubNav(new WANavigation(plugin.getName()));
|
|
||||||
WANavigation.addRootNav(nav);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -65,13 +70,9 @@ public class ServiceStatusPage implements WAPage {
|
||||||
Map<String, String> request) {
|
Map<String, String> request) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
WAService obj = getPlugin(context);
|
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||||
|
tmpl.set("services", services);
|
||||||
if (obj != null) {
|
return tmpl;
|
||||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
|
||||||
tmpl.set("nav", context.getBreadcrumb().get(1));
|
|
||||||
return tmpl;
|
|
||||||
}
|
|
||||||
}catch (IOException e){
|
}catch (IOException e){
|
||||||
log.log(Level.SEVERE, null, e);
|
log.log(Level.SEVERE, null, e);
|
||||||
}
|
}
|
||||||
|
|
@ -83,18 +84,23 @@ public class ServiceStatusPage implements WAPage {
|
||||||
Map<String, Object> session,
|
Map<String, Object> session,
|
||||||
Map<String, String> cookie,
|
Map<String, String> cookie,
|
||||||
Map<String, String> request){
|
Map<String, String> request){
|
||||||
|
DataNode root = new DataNode(DataNode.DataType.Map);
|
||||||
return null;
|
if (request.containsKey("service_id") && request.containsKey("service_action")) {
|
||||||
}
|
int index = Integer.parseInt(request.get("ServiceId"));
|
||||||
|
if(0 > index || index > services.size()) {
|
||||||
|
root.set("error", "Invalid service_id");
|
||||||
private WAService getPlugin(WAContext context){
|
}
|
||||||
if(context.getBreadcrumb().size() >= 2){
|
else {
|
||||||
int i = plugins.indexOf(context.getBreadcrumb().get(1).getResource());
|
WAServiceStatus service = services.get(index);
|
||||||
if(i >= 0)
|
switch (request.get("ServiceAction")) {
|
||||||
return plugins.get(i);
|
case "start": service.start(); break;
|
||||||
|
case "stop": service.stop(); break;
|
||||||
|
default:
|
||||||
|
root.set("error", "Unknown action");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,13 @@ import java.util.Map;
|
||||||
* Created by Ziver on 2015-04-06.
|
* Created by Ziver on 2015-04-06.
|
||||||
*/
|
*/
|
||||||
public class StatusPage implements WAPage {
|
public class StatusPage implements WAPage {
|
||||||
|
public static final String NAVIGATION_NAME = "Status";
|
||||||
private ArrayList<WAStatus> plugins;
|
private ArrayList<WAStatus> plugins;
|
||||||
|
|
||||||
public StatusPage(PluginManager pluginManager){
|
public StatusPage(PluginManager pluginManager){
|
||||||
this.plugins = pluginManager.toArray(WAStatus.class);
|
this.plugins = pluginManager.toArray(WAStatus.class);
|
||||||
|
|
||||||
WANavigation nav = new WANavigation("Status", this);
|
WANavigation nav = new WANavigation(NAVIGATION_NAME, this);
|
||||||
for(WAStatus plugin : plugins)
|
for(WAStatus plugin : plugins)
|
||||||
nav.addSubNav(new WANavigation(plugin.getName(), plugin));
|
nav.addSubNav(new WANavigation(plugin.getName(), plugin));
|
||||||
WANavigation.addRootNav(nav);
|
WANavigation.addRootNav(nav);
|
||||||
|
|
@ -60,9 +61,7 @@ public class StatusPage implements WAPage {
|
||||||
WAStatus obj = getPlugin(context);
|
WAStatus obj = getPlugin(context);
|
||||||
|
|
||||||
if(obj != null) {
|
if(obj != null) {
|
||||||
Templator tmpl = new Templator(obj.html());
|
return new Templator(obj.html());
|
||||||
tmpl.set("nav", context.getBreadcrumb().get(1));
|
|
||||||
return tmpl;
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,9 @@ public class WANavigation {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName(){
|
||||||
|
return name;
|
||||||
|
}
|
||||||
public Object getResource(){
|
public Object getResource(){
|
||||||
return resource;
|
return resource;
|
||||||
}
|
}
|
||||||
|
|
@ -93,6 +96,13 @@ public class WANavigation {
|
||||||
public static List<WANavigation> getRootNav(){
|
public static List<WANavigation> getRootNav(){
|
||||||
return root_nav;
|
return root_nav;
|
||||||
}
|
}
|
||||||
|
public static WANavigation getRootNav(String name){
|
||||||
|
for(WANavigation nav : root_nav){
|
||||||
|
if(nav.getName().equals(name))
|
||||||
|
return nav;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static List<WANavigation> getNavResource(Map<String, String> request) {
|
public static List<WANavigation> getNavResource(Map<String, String> request) {
|
||||||
LinkedList list = new LinkedList();
|
LinkedList list = new LinkedList();
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,34 @@
|
||||||
|
|
||||||
package wa.server.plugin;
|
package wa.server.plugin;
|
||||||
|
|
||||||
public interface WAServiceStatus {
|
public abstract class WAServiceStatus {
|
||||||
public enum ServiceStatusType{
|
public enum ServiceStatusType{
|
||||||
RUNNING,
|
RUNNING,
|
||||||
NOT_RESPONDING,
|
UNRESPONSIVE,
|
||||||
STOPPED,
|
STOPPED,
|
||||||
UNKNOWN
|
UNKNOWN
|
||||||
}
|
};
|
||||||
|
|
||||||
public void start();
|
|
||||||
public void stop();
|
public boolean isRunning(){
|
||||||
public ServiceStatusType getStatus();
|
return getStatus() == ServiceStatusType.RUNNING;
|
||||||
|
}
|
||||||
|
public boolean isUnresponsive(){
|
||||||
|
return getStatus() == ServiceStatusType.UNRESPONSIVE;
|
||||||
|
}
|
||||||
|
public boolean isStopped(){
|
||||||
|
return getStatus() == ServiceStatusType.STOPPED;
|
||||||
|
}
|
||||||
|
public boolean isUnknown(){
|
||||||
|
return getStatus() == ServiceStatusType.UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public abstract String getName();
|
||||||
|
|
||||||
|
public abstract void start();
|
||||||
|
public abstract void stop();
|
||||||
|
|
||||||
|
public abstract ServiceStatusType getStatus();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,14 @@ import java.util.logging.Logger;
|
||||||
*/
|
*/
|
||||||
public class ApacheService implements WAService {
|
public class ApacheService implements WAService {
|
||||||
private static Logger log = LogUtil.getLogger();
|
private static Logger log = LogUtil.getLogger();
|
||||||
|
public static final String SERVICE_NAME = "Apache2";
|
||||||
|
|
||||||
private ApacheStatus status;
|
private ApacheStatus status;
|
||||||
private ApacheInstaller installer;
|
private ApacheInstaller installer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Apache2";
|
return SERVICE_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,18 @@ import java.io.IOException;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class ApacheStatus implements WAServiceStatus {
|
public class ApacheStatus extends WAServiceStatus {
|
||||||
private static final Logger log = LogUtil.getLogger();
|
private static final Logger log = LogUtil.getLogger();
|
||||||
private static OSAbstractionLayer os = OSAbstractionLayer.getInstance();
|
|
||||||
private static final String PID_FILE = "/var/run/apache2.pid";
|
private static final String PID_FILE = "/var/run/apache2.pid";
|
||||||
|
|
||||||
|
private static OSAbstractionLayer os = OSAbstractionLayer.getInstance();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return ApacheService.SERVICE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start() {
|
public void start() {
|
||||||
os.runCommand("service apache2 start");
|
os.runCommand("service apache2 start");
|
||||||
|
|
|
||||||
|
|
@ -60,35 +60,41 @@ public class HDDStatus implements WAStatus {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void jsonUpdate(Map<String, String> request, DataNode root) {
|
public void jsonUpdate(Map<String, String> request, DataNode root) {
|
||||||
DataNode hdd_root = new DataNode(DataNode.DataType.List);
|
if (request.containsKey("hdd")) {
|
||||||
root.set("hdd", hdd_root);
|
DataNode hdd_root = new DataNode(DataNode.DataType.List);
|
||||||
Sigar sigar = new Shell().getSigar();
|
root.set("hdd", hdd_root);
|
||||||
try {
|
Sigar sigar = new Shell().getSigar();
|
||||||
FileSystem[] hdds = sigar.getFileSystemList();
|
try {
|
||||||
for (FileSystem hdd : hdds) {
|
FileSystem[] hdds = sigar.getFileSystemList();
|
||||||
if (hdd.getType() != FileSystem.TYPE_LOCAL_DISK)
|
for (FileSystem hdd : hdds) {
|
||||||
continue;
|
if (hdd.getType() != FileSystem.TYPE_LOCAL_DISK)
|
||||||
DataNode node = new DataNode(DataNode.DataType.Map);
|
continue;
|
||||||
|
DataNode node = new DataNode(DataNode.DataType.Map);
|
||||||
|
|
||||||
String device = new String(hdd.getDevName().getBytes(), "UTF-8");
|
String device = new String(hdd.getDevName().getBytes(), "UTF-8");
|
||||||
node.set("device", device);
|
node.set("device", device);
|
||||||
node.set("filesystem", hdd.getSysTypeName());
|
node.set("filesystem", hdd.getSysTypeName());
|
||||||
node.set("mount", hdd.getDirName());
|
node.set("mount", hdd.getDirName());
|
||||||
|
|
||||||
if(idMap.containsKey(device))
|
if (idMap.containsKey(device))
|
||||||
node.set("id", idMap.get(device));
|
node.set("id", idMap.get(device));
|
||||||
else{
|
else {
|
||||||
idMap.put(device, nextId);
|
idMap.put(device, nextId);
|
||||||
node.set("id", nextId++);
|
node.set("id", nextId++);
|
||||||
|
}
|
||||||
|
|
||||||
|
FileSystemUsage hdd_use = sigar.getFileSystemUsage(hdd.getDirName());
|
||||||
|
node.set("size_total", hdd_use.getTotal() * 1000);
|
||||||
|
node.set("size_used", (hdd_use.getTotal() - hdd_use.getFree()) * 1000);
|
||||||
|
node.set("size_free", hdd_use.getFree() * 1000);
|
||||||
|
|
||||||
|
hdd_root.add(node);
|
||||||
}
|
}
|
||||||
|
} catch (SigarException e) {
|
||||||
FileSystemUsage hdd_use = sigar.getFileSystemUsage(hdd.getDirName());
|
e.printStackTrace();
|
||||||
node.set("size_total", hdd_use.getTotal() * 1000);
|
} catch (UnsupportedEncodingException e) {
|
||||||
node.set("size_used", (hdd_use.getTotal() - hdd_use.getFree())*1000);
|
e.printStackTrace();
|
||||||
node.set("size_free", hdd_use.getFree() * 1000);
|
|
||||||
|
|
||||||
hdd_root.add(node);
|
|
||||||
}
|
}
|
||||||
}catch(SigarException e){} catch (UnsupportedEncodingException e) {}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue