Backend implementation of config objects
This commit is contained in:
parent
224372f0ad
commit
2d1a7d647c
13 changed files with 215 additions and 131 deletions
41
src/wa/server/page/ConfigPage.java
Normal file → Executable file
41
src/wa/server/page/ConfigPage.java
Normal file → Executable file
|
|
@ -23,9 +23,11 @@
|
|||
package wa.server.page;
|
||||
|
||||
import wa.server.WAContext;
|
||||
import wa.server.plugin.WAConfigEntry;
|
||||
import wa.server.plugin.WAServiceConfig;
|
||||
import wa.server.plugin.apache.ApacheConfigVirtualHost;
|
||||
import zutil.db.bean.Configurator;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
|
|
@ -65,14 +67,36 @@ public class ConfigPage implements WAPage{
|
|||
Map<String, String> request) {
|
||||
try {
|
||||
List<?> confObjs = config.getConfigData();
|
||||
ArrayList<Configurator> confList = new ArrayList<>();
|
||||
ArrayList<Configurator<WAConfigEntry>> confList = new ArrayList<>();
|
||||
for(Object obj : confObjs){
|
||||
confList.add(new Configurator(obj));
|
||||
}
|
||||
confList.add(new Configurator(new ApacheConfigVirtualHost.ApacheVirtualHostData()));
|
||||
confList.add(new Configurator(new ApacheConfigVirtualHost.ApacheVirtualHostData()));
|
||||
confList.add(new Configurator(new ApacheConfigVirtualHost.ApacheVirtualHostData()));
|
||||
|
||||
// Actions
|
||||
int index = Integer.parseInt(request.get("id"));
|
||||
Configurator<WAConfigEntry> target = findObj(confList, index);
|
||||
switch (request.get("action")){
|
||||
case "create":
|
||||
target = new Configurator(config.createConfig());
|
||||
case "modify":
|
||||
for(Configurator.ConfigurationParam param : target.getConfiguration()){
|
||||
if(request.containsKey(param.getName()))
|
||||
param.setValue(request.get(param.getName()));
|
||||
}
|
||||
target.applyConfiguration();
|
||||
break;
|
||||
case "delete":
|
||||
config.deleteConfig(index);
|
||||
break;
|
||||
case "enable":
|
||||
target.getObject().setEnabled(true);
|
||||
break;
|
||||
case "disable":
|
||||
target.getObject().setEnabled(false);
|
||||
break;
|
||||
}
|
||||
|
||||
// Prepare Output
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
tmpl.set("params", Configurator.getConfiguration(
|
||||
config.getConfigClass()));
|
||||
|
|
@ -92,4 +116,13 @@ public class ConfigPage implements WAPage{
|
|||
Map<String, String> request) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private static Configurator<WAConfigEntry> findObj(List<Configurator<WAConfigEntry>> list, int id){
|
||||
for (Configurator<WAConfigEntry> conf : list) {
|
||||
if(conf.getObject().getId() == id)
|
||||
return conf;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
177
src/wa/server/page/WALogPage.java → src/wa/server/page/LogPage.java
Normal file → Executable file
177
src/wa/server/page/WALogPage.java → src/wa/server/page/LogPage.java
Normal file → Executable file
|
|
@ -1,85 +1,92 @@
|
|||
/*
|
||||
* Copyright (c) 2015 ezivkoc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package wa.server.page;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
import zutil.net.http.HttpPage;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.parser.DataNode;
|
||||
import zutil.parser.json.JSONWriter;
|
||||
import zutil.struct.CircularBuffer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-09-22.
|
||||
*/
|
||||
public class WALogPage extends Handler implements HttpPage {
|
||||
private CircularBuffer<LogRecord> logBuffer;
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if(super.isLoggable(record)){
|
||||
logBuffer.add(record);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void flush() {}
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void respond(HttpPrintStream out,
|
||||
HttpHeaderParser client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) throws IOException {
|
||||
|
||||
DataNode logNode = new DataNode(DataNode.DataType.List);
|
||||
Iterator<LogRecord> it = logBuffer.iterator();
|
||||
for(int i=0; i<20 && it.hasNext(); ++i){
|
||||
LogRecord record = it.next();
|
||||
DataNode node = new DataNode(DataNode.DataType.Map);
|
||||
node.set("timestamp", record.getMillis());
|
||||
node.set("source", record.getLoggerName());
|
||||
node.set("msg", record.getMessage());
|
||||
logNode.add(node);
|
||||
}
|
||||
|
||||
DataNode root = new DataNode(DataNode.DataType.Map);
|
||||
root.add(logNode);
|
||||
JSONWriter writer = new JSONWriter(out);
|
||||
writer.write(root);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright (c) 2015 ezivkoc
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
package wa.server.page;
|
||||
|
||||
import sun.reflect.generics.reflectiveObjects.NotImplementedException;
|
||||
import wa.server.plugin.WALog;
|
||||
import zutil.net.http.HttpHeaderParser;
|
||||
import zutil.net.http.HttpPage;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.parser.DataNode;
|
||||
import zutil.parser.json.JSONWriter;
|
||||
import zutil.struct.CircularBuffer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
/**
|
||||
* Created by Ziver on 2015-09-22.
|
||||
*/
|
||||
public class LogPage extends Handler implements HttpPage {
|
||||
private CircularBuffer<LogRecord> logBuffer;
|
||||
private WALog log;
|
||||
|
||||
public LogPage(WALog log) {
|
||||
logBuffer = new CircularBuffer<>(500);
|
||||
this.log = log;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord record) {
|
||||
if(super.isLoggable(record)){
|
||||
logBuffer.add(record);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void flush() {}
|
||||
@Override
|
||||
public void close() throws SecurityException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void respond(HttpPrintStream out,
|
||||
HttpHeaderParser client_info,
|
||||
Map<String, Object> session,
|
||||
Map<String, String> cookie,
|
||||
Map<String, String> request) throws IOException {
|
||||
|
||||
DataNode logNode = new DataNode(DataNode.DataType.List);
|
||||
Iterator<LogRecord> it = logBuffer.iterator();
|
||||
for(int i=0; i<20 && it.hasNext(); ++i){
|
||||
LogRecord record = it.next();
|
||||
DataNode node = new DataNode(DataNode.DataType.Map);
|
||||
node.set("timestamp", record.getMillis());
|
||||
node.set("source", record.getLoggerName());
|
||||
node.set("msg", record.getMessage());
|
||||
logNode.add(node);
|
||||
}
|
||||
|
||||
DataNode root = new DataNode(DataNode.DataType.Map);
|
||||
root.add(logNode);
|
||||
JSONWriter writer = new JSONWriter(out);
|
||||
writer.write(root);
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
14
src/wa/server/page/ServicePage.java
Normal file → Executable file
14
src/wa/server/page/ServicePage.java
Normal file → Executable file
|
|
@ -50,18 +50,21 @@ public class ServicePage implements WAPage {
|
|||
private ServiceStatusPage rootStatusPage;
|
||||
private ArrayList<WAService> services;
|
||||
private ArrayList<ServiceStatusPage> statusPages;
|
||||
private ArrayList<LogPage> logPages;
|
||||
private ArrayList<ConfigPage> configPages;
|
||||
|
||||
public ServicePage(PluginManager pluginManager){
|
||||
this.services = pluginManager.toArray(WAService.class);
|
||||
this.rootStatusPage = new ServiceStatusPage(pluginManager);
|
||||
this.statusPages = new ArrayList<>();
|
||||
this.logPages = new ArrayList<>();
|
||||
this.configPages = new ArrayList<>();
|
||||
|
||||
WANavigation nav = WANavigation.createRootNav(NAVIGATION_NAME);
|
||||
nav.setResource(this);
|
||||
for(WAService plugin : services) {
|
||||
statusPages.add(new ServiceStatusPage(plugin.getStatus()));
|
||||
logPages.add(new LogPage(plugin.getLog()));
|
||||
|
||||
WANavigation serviceNav = nav.createSubNav(plugin.getName());
|
||||
serviceNav.setResource(plugin);
|
||||
|
|
@ -91,12 +94,15 @@ public class ServicePage implements WAPage {
|
|||
else if ((index = services.indexOf(resource)) >= 0) {
|
||||
WAService obj = services.get(index);
|
||||
ServiceStatusPage statusPage = statusPages.get(index);
|
||||
LogPage logPage = logPages.get(index);
|
||||
|
||||
Templator tmpl = new Templator(FileUtil.find(TMPL_FILE));
|
||||
tmpl.set("service_status",
|
||||
statusPage.htmlResponse(context, client_info, session, cookie, request).compile());
|
||||
//tmpl.set("service_logs",
|
||||
// statusPage.htmlResponse(context, client_info, session, cookie, request).compile());
|
||||
if(statusPage != null)
|
||||
tmpl.set("service_status",
|
||||
statusPage.htmlResponse(context, client_info, session, cookie, request));
|
||||
if(logPage != null)
|
||||
tmpl.set("service_logs",
|
||||
statusPage.htmlResponse(context, client_info, session, cookie, request));
|
||||
return tmpl;
|
||||
}
|
||||
else{ // root page
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue