use of com.predic8.membrane.core.Router in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleNodeSessionsRequest.
@Mapping("/admin/node/sessions/?(\\?.*)?")
public Response handleNodeSessionsRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
StringWriter writer = new StringWriter();
return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {
@Override
protected int getSelectedTab() {
return TAB_ID_LOAD_BALANCING;
}
@Override
protected void createTabContent() throws Exception {
h2().text("Node " + params.get("host") + ":" + params.get("port")).end();
h3().text("Sessions").end();
createSessionsTable(BalancerUtil.lookupBalancer(router, getBalancerParam(params)).getSessionsByNode(params.get("cluster"), new Node(params.get("host"), Integer.parseInt(params.get("port")))));
}
}.createPage());
}
use of com.predic8.membrane.core.Router in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleSystemRequest.
@Mapping("/admin/system/?(\\?.*)?")
public Response handleSystemRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
StringWriter writer = new StringWriter();
return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {
static final int mb = 1024 * 1024;
final DecimalFormat formatter = new DecimalFormat("#.00");
private String formatMemoryValue(float value) {
float newValue = value / (float) mb;
String unit = "MB";
if (newValue > 1024)
unit = "GB";
return formatter.format(newValue) + " " + unit;
}
@Override
protected int getSelectedTab() {
return TAB_ID_SYSTEM;
}
@Override
protected void createTabContent() {
h2().text("System").end();
p().text("Availabe system memory: " + formatMemoryValue(Runtime.getRuntime().totalMemory())).end();
p().text("Free system memory: " + formatMemoryValue(Runtime.getRuntime().freeMemory())).end();
p().text("Membrane version: " + Constants.VERSION).end();
// createLogConfigurationEditor();
}
}.createPage());
}
use of com.predic8.membrane.core.Router in project service-proxy by membrane.
the class DynamicAdminPageInterceptor method handleServiceProxyShowRequest.
@Mapping("/admin/service-proxy/show/?(\\?.*)?")
public Response handleServiceProxyShowRequest(final Map<String, String> params, final String relativeRootPath) throws Exception {
final StringWriter writer = new StringWriter();
final AbstractServiceProxy rule = (AbstractServiceProxy) RuleUtil.findRuleByIdentifier(router, params.get("name"));
return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {
@Override
protected int getSelectedTab() {
return TAB_ID_SERVICE_PROXIES;
}
@Override
protected String getTitle() {
return super.getTitle() + " " + rule.toString() + " ServiceProxy";
}
@Override
protected void createTabContent() throws Exception {
h1().text(rule.toString() + " ServiceProxy").end();
script().raw("$(function() {\r\n" + " $( \"#subtab\" ).tabs();\r\n" + " });").end();
div().id("subtab");
ul();
li().a().href("#tab1").text("Visualization").end(2);
li().a().href("#tab2").text("Statistics").end(2);
// li().a().href("#tab3").text("XML Configuration").end(2);
end();
div().id("tab1");
createServiceProxyVisualization(rule, relativeRootPath);
end();
div().id("tab2");
createStatusCodesTable(rule.getStatisticsByStatusCodes());
br();
createButton("View Messages", "calls", null, createQueryString("proxy", rule.toString()));
end();
end();
}
}.createPage());
}
use of com.predic8.membrane.core.Router in project service-proxy by membrane.
the class EtcdRegistryApiConfig method findAdminConsole.
private EtcdNodeInformation findAdminConsole() {
Object routerObj = context.getBean(Router.class);
if (routerObj == null)
throw new RuntimeException("Router not found, cannot publish admin console");
Router router = (Router) routerObj;
for (Rule r : router.getRuleManager().getRules()) {
if (!(r instanceof AbstractServiceProxy))
continue;
for (Interceptor i : r.getInterceptors()) {
if (i instanceof AdminConsoleInterceptor) {
String name = r.getName();
String host = ((ServiceProxy) r).getExternalHostname();
if (host == null)
host = getLocalHostname();
String port = Integer.toString(((AbstractServiceProxy) r).getPort());
EtcdNodeInformation node = new EtcdNodeInformation(null, null, host, port, name);
return node;
}
}
}
throw new RuntimeException("Admin console not found but is needed. Add a service proxy with an admin console.");
}
use of com.predic8.membrane.core.Router in project service-proxy by membrane.
the class EtcdRegistryApiConfig method start.
@Override
public void start() {
Object routerObj = context.getBean(Router.class);
if (routerObj == null)
throw new RuntimeException("Router cannot be found");
Router router = (Router) routerObj;
membraneId = router.getId();
try {
log.info("Started membrane publishing");
ExponentialBackoff.retryAfter(retryDelayMin, retryDelayMax, expDelayFactor, "First publish from thread", jobPublisher);
} catch (InterruptedException ignored) {
}
initAmc();
if (!publisher.isAlive()) {
publisher.start();
}
}
Aggregations