Search in sources :

Example 31 with Port

use of com.predic8.wsdl.Port in project service-proxy by membrane.

the class LoadBalancingWithClusterManagerTest method startNode.

private DummyWebServiceInterceptor startNode(HttpRouter node, int port) throws Exception {
    DummyWebServiceInterceptor service1 = new DummyWebServiceInterceptor();
    node.addUserFeatureInterceptor(service1);
    node.getRuleManager().addProxyAndOpenPortIfNew(new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80));
    node.init();
    return service1;
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) DummyWebServiceInterceptor(com.predic8.membrane.core.services.DummyWebServiceInterceptor)

Example 32 with Port

use of com.predic8.wsdl.Port in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleProxySaveRequest.

@Mapping("/admin/proxy/save/?(\\?.*)?")
public Response handleProxySaveRequest(Map<String, String> params, String relativeRootPath) throws Exception {
    if (readOnly)
        return createReadOnlyErrorResponse();
    log.debug("adding proxy rule");
    log.debug("name: " + params.get("name"));
    log.debug("port: " + params.get("port"));
    Rule r = new ProxyRule(new ProxyRuleKey(Integer.parseInt(params.get("port")), null));
    r.setName(params.get("name"));
    router.getRuleManager().addProxyAndOpenPortIfNew(r);
    return respond(getProxyPage(params, relativeRootPath));
}
Also used : ProxyRule(com.predic8.membrane.core.rules.ProxyRule) ProxyRuleKey(com.predic8.membrane.core.rules.ProxyRuleKey) ProxyRule(com.predic8.membrane.core.rules.ProxyRule) Rule(com.predic8.membrane.core.rules.Rule)

Example 33 with Port

use of com.predic8.wsdl.Port in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleNodeShowRequest.

@Mapping("/admin/node/show/?(\\?.*)?")
public Response handleNodeShowRequest(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 {
            String balancer = getBalancerParam(params);
            h2().text("Node " + params.get("host") + ":" + params.get("port") + " (" + "Cluster " + params.get("cluster") + " of Balancer " + balancer + ")").end();
            h3().text("Status Codes").end();
            Node n = BalancerUtil.lookupBalancer(router, balancer).getNode(params.get("cluster"), params.get("host"), Integer.parseInt(params.get("port")));
            createStatusCodesTable(n.getStatisticsByStatusCodes());
            p().text("Total requests: " + n.getCounter()).end();
            p().text("Current threads: " + n.getThreads()).end();
            p().text("Requests without responses: " + n.getLost()).end();
            span().classAttr("mb-button");
            createLink("Reset Counter", "node", "reset", createQueryString("balancer", balancer, "cluster", params.get("cluster"), "host", n.getHost(), "port", "" + n.getPort()));
            end();
            span().classAttr("mb-button");
            createLink("Show Sessions", "node", "sessions", createQueryString("balancer", balancer, "cluster", params.get("cluster"), "host", n.getHost(), "port", "" + n.getPort()));
            end();
        }
    }.createPage());
}
Also used : StringWriter(java.io.StringWriter) Node(com.predic8.membrane.core.interceptor.balancer.Node) URLParamUtil.createQueryString(com.predic8.membrane.core.util.URLParamUtil.createQueryString)

Example 34 with Port

use of com.predic8.wsdl.Port in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handlePruleShowRequest.

@Mapping("/admin/proxy/show/?(\\?.*)?")
public Response handlePruleShowRequest(final Map<String, String> params, String relativeRootPath) throws Exception {
    StringWriter writer = new StringWriter();
    final ProxyRule rule = (ProxyRule) RuleUtil.findRuleByIdentifier(router, params.get("name"));
    return respond(new AdminPageBuilder(writer, router, relativeRootPath, params, readOnly) {

        @Override
        protected int getSelectedTab() {
            return TAB_ID_PROXIES;
        }

        @Override
        protected String getTitle() {
            return super.getTitle() + " " + rule.toString() + " Proxy";
        }

        @Override
        protected void createTabContent() throws Exception {
            h1().text(rule.toString() + " Proxy").end();
            if (rule.getKey().getPort() != -1) {
                table();
                createTr("Listen Port", "" + rule.getKey().getPort());
                end();
            }
            h2().text("Status Codes").end();
            createStatusCodesTable(rule.getStatisticsByStatusCodes());
            h2().text("Interceptors").end();
            createInterceptorTable(rule.getInterceptors());
        }
    }.createPage());
}
Also used : StringWriter(java.io.StringWriter) ProxyRule(com.predic8.membrane.core.rules.ProxyRule)

Example 35 with Port

use of com.predic8.wsdl.Port in project service-proxy by membrane.

the class DynamicAdminPageInterceptor method handleServiceProxySaveRequest.

@Mapping("/admin/service-proxy/save/?(\\?.*)?")
public Response handleServiceProxySaveRequest(Map<String, String> params, String relativeRootPath) throws Exception {
    if (readOnly)
        return createReadOnlyErrorResponse();
    logAddFwdRuleParams(params);
    Rule r = new ServiceProxy(new ServiceProxyKey("*", params.get("method"), ".*", getPortParam(params), null), params.get("targetHost"), getTargetPortParam(params));
    r.setName(params.get("name"));
    try {
        router.getRuleManager().addProxyAndOpenPortIfNew(r);
    } catch (PortOccupiedException e) {
        return Response.internalServerError("The port could not be opened: Either it is occupied or Membrane does " + "not have enough privileges to do so.").build();
    }
    return respond(getServiceProxyPage(params, relativeRootPath));
}
Also used : ServiceProxyKey(com.predic8.membrane.core.rules.ServiceProxyKey) ServiceProxy(com.predic8.membrane.core.rules.ServiceProxy) AbstractServiceProxy(com.predic8.membrane.core.rules.AbstractServiceProxy) PortOccupiedException(com.predic8.membrane.core.transport.PortOccupiedException) ProxyRule(com.predic8.membrane.core.rules.ProxyRule) Rule(com.predic8.membrane.core.rules.Rule)

Aggregations

ServiceProxy (com.predic8.membrane.core.rules.ServiceProxy)9 Test (org.junit.Test)7 ServiceProxyKey (com.predic8.membrane.core.rules.ServiceProxyKey)6 StringWriter (java.io.StringWriter)6 Exchange (com.predic8.membrane.core.exchange.Exchange)5 Rule (com.predic8.membrane.core.rules.Rule)5 Process2 (com.predic8.membrane.examples.Process2)5 File (java.io.File)5 ProxyRule (com.predic8.membrane.core.rules.ProxyRule)4 HttpRouter (com.predic8.membrane.core.HttpRouter)3 Request (com.predic8.membrane.core.http.Request)3 Response (com.predic8.membrane.core.http.Response)3 LoadBalancingInterceptor (com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor)3 Node (com.predic8.membrane.core.interceptor.balancer.Node)3 Definitions (com.predic8.wsdl.Definitions)3 Port (com.predic8.wsdl.Port)3 ArrayList (java.util.ArrayList)3 EtcdNodeInformation (com.predic8.membrane.core.cloud.etcd.EtcdNodeInformation)2 IPortChangeListener (com.predic8.membrane.core.model.IPortChangeListener)2 AbstractServiceProxy (com.predic8.membrane.core.rules.AbstractServiceProxy)2