Some progress on service configuration
This commit is contained in:
parent
29def452b6
commit
ab7296198a
10 changed files with 138 additions and 84 deletions
|
|
@ -25,6 +25,7 @@ package wa.server.page;
|
|||
import wa.server.WAContext;
|
||||
import wa.server.page.struct.WANavigation;
|
||||
import wa.server.plugin.WAService;
|
||||
import wa.server.plugin.WAServiceStatus;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
|
|
@ -43,16 +44,21 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class ServicePage implements WAPage {
|
||||
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 ArrayList<WAService> plugins;
|
||||
private ArrayList<WAService> services;
|
||||
private ArrayList<ServiceStatusPage> statuses;
|
||||
|
||||
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");
|
||||
for(WAService plugin : plugins)
|
||||
WANavigation nav = new WANavigation(NAVIGATION_NAME, this);
|
||||
for(WAService plugin : services) {
|
||||
nav.addSubNav(new WANavigation(plugin.getName()));
|
||||
statuses.add(new ServiceStatusPage(plugin.getStatus()));
|
||||
}
|
||||
WANavigation.addRootNav(nav);
|
||||
}
|
||||
|
||||
|
|
@ -65,13 +71,17 @@ public class ServicePage implements WAPage {
|
|||
Map<String, String> request) {
|
||||
|
||||
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){
|
||||
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.page.struct.WANavigation;
|
||||
import wa.server.plugin.WAService;
|
||||
import wa.server.plugin.WAServiceStatus;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
|
|
@ -32,6 +32,7 @@ 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;
|
||||
|
|
@ -43,17 +44,21 @@ import java.util.logging.Logger;
|
|||
*/
|
||||
public class ServiceStatusPage implements WAPage {
|
||||
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 ArrayList<WAService> plugins;
|
||||
private ArrayList<WAServiceStatus> services;
|
||||
|
||||
|
||||
public ServiceStatusPage(WAServiceStatus ss){
|
||||
services = new ArrayList<>();
|
||||
services.add(ss);
|
||||
}
|
||||
public ServiceStatusPage(PluginManager pluginManager){
|
||||
this.plugins = pluginManager.toArray(WAService.class);
|
||||
this.services = pluginManager.toArray(WAServiceStatus.class);
|
||||
|
||||
WANavigation nav = new WANavigation("Services");
|
||||
for(WAService plugin : plugins)
|
||||
nav.addSubNav(new WANavigation(plugin.getName()));
|
||||
WANavigation.addRootNav(nav);
|
||||
WANavigation.getRootNav(ServicePage.NAVIGATION_NAME).addSubNav(
|
||||
new WANavigation(NAVIGATION_NAME, this));
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -65,13 +70,9 @@ public class ServiceStatusPage implements WAPage {
|
|||
Map<String, String> request) {
|
||||
|
||||
try {
|
||||
WAService obj = getPlugin(context);
|
||||
|
||||
if (obj != null) {
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
tmpl.set("nav", context.getBreadcrumb().get(1));
|
||||
return tmpl;
|
||||
}
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
tmpl.set("services", services);
|
||||
return tmpl;
|
||||
}catch (IOException e){
|
||||
log.log(Level.SEVERE, null, e);
|
||||
}
|
||||
|
|
@ -83,18 +84,23 @@ public class ServiceStatusPage implements WAPage {
|
|||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request){
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
DataNode root = new DataNode(DataNode.DataType.Map);
|
||||
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");
|
||||
}
|
||||
else {
|
||||
WAServiceStatus service = services.get(index);
|
||||
switch (request.get("ServiceAction")) {
|
||||
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.
|
||||
*/
|
||||
public class StatusPage implements WAPage {
|
||||
public static final String NAVIGATION_NAME = "Status";
|
||||
private ArrayList<WAStatus> plugins;
|
||||
|
||||
public StatusPage(PluginManager pluginManager){
|
||||
this.plugins = pluginManager.toArray(WAStatus.class);
|
||||
|
||||
WANavigation nav = new WANavigation("Status", this);
|
||||
WANavigation nav = new WANavigation(NAVIGATION_NAME, this);
|
||||
for(WAStatus plugin : plugins)
|
||||
nav.addSubNav(new WANavigation(plugin.getName(), plugin));
|
||||
WANavigation.addRootNav(nav);
|
||||
|
|
@ -60,9 +61,7 @@ public class StatusPage implements WAPage {
|
|||
WAStatus obj = getPlugin(context);
|
||||
|
||||
if(obj != null) {
|
||||
Templator tmpl = new Templator(obj.html());
|
||||
tmpl.set("nav", context.getBreadcrumb().get(1));
|
||||
return tmpl;
|
||||
return new Templator(obj.html());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,6 +68,9 @@ public class WANavigation {
|
|||
return null;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
public Object getResource(){
|
||||
return resource;
|
||||
}
|
||||
|
|
@ -93,6 +96,13 @@ public class WANavigation {
|
|||
public static List<WANavigation> getRootNav(){
|
||||
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) {
|
||||
LinkedList list = new LinkedList();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue