Search in sources :

Example 11 with Router

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());
}
Also used : StringWriter(java.io.StringWriter) Node(com.predic8.membrane.core.interceptor.balancer.Node)

Example 12 with Router

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());
}
Also used : StringWriter(java.io.StringWriter) DecimalFormat(java.text.DecimalFormat) URLParamUtil.createQueryString(com.predic8.membrane.core.util.URLParamUtil.createQueryString)

Example 13 with Router

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());
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) StringWriter(java.io.StringWriter)

Example 14 with Router

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.");
}
Also used : AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) AdminConsoleInterceptor(com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) EtcdNodeInformation(com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation) Router(com.predic8.membrane.core.Router) Rule(com.predic8.membrane.core.rules.Rule) Interceptor(com.predic8.membrane.core.interceptor.Interceptor) AdminConsoleInterceptor(com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor)

Example 15 with Router

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();
    }
}
Also used : Router(com.predic8.membrane.core.Router)

Aggregations

HttpRouter (com.predic8.membrane.core.HttpRouter)24 ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)21 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)19 Before (org.junit.Before)18 Rule (com.predic8.membrane.core.rules.Rule)16 IOException (java.io.IOException)9 Router (com.predic8.membrane.core.Router)8 Exchange (com.predic8.membrane.core.exchange.Exchange)6 AbstractInterceptor (com.predic8.membrane.core.interceptor.AbstractInterceptor)5 Outcome (com.predic8.membrane.core.interceptor.Outcome)5 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)5 StringWriter (java.io.StringWriter)5 Test (org.junit.Test)5 Interceptor (com.predic8.membrane.core.interceptor.Interceptor)3 Node (com.predic8.membrane.core.interceptor.balancer.Node)3 Mapping (com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.Mapping)3 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)3 ProxyRuleKey (com.predic8.membrane.core.rules.ProxyRuleKey)3 HttpClientConfiguration (com.predic8.membrane.core.transport.http.client.HttpClientConfiguration)3 File (java.io.File)3