Search in sources :

Example 6 with LoadbalanceEndpoint

use of org.apache.synapse.endpoints.LoadbalanceEndpoint in project wso2-synapse by wso2.

the class LoadbalanceEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof LoadbalanceEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) endpoint;
    serializeCommonAttributes(endpoint, endpointElement);
    OMElement loadbalanceElement = fac.createOMElement("loadbalance", SynapseConstants.SYNAPSE_OMNAMESPACE);
    endpointElement.addChild(loadbalanceElement);
    loadbalanceElement.addAttribute(XMLConfigConstants.LOADBALANCE_ALGORITHM, loadbalanceEndpoint.getAlgorithm().getClass().getName(), null);
    // set if failover is turned off in the endpoint
    if (!loadbalanceEndpoint.isFailover()) {
        loadbalanceElement.addAttribute("failover", "false", null);
    }
    if (loadbalanceEndpoint.isBuildMessageAtt()) {
        loadbalanceElement.addAttribute(XMLConfigConstants.BUILD_MESSAGE, Boolean.toString(loadbalanceEndpoint.isBuildMessageAtt()), null);
    }
    // Serialize endpoint elements which are children of the loadbalance element
    if (loadbalanceEndpoint.getChildren() != null) {
        for (Endpoint childEndpoint : loadbalanceEndpoint.getChildren()) {
            loadbalanceElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
        }
    } else {
        for (Member member : loadbalanceEndpoint.getMembers()) {
            OMElement memberEle = fac.createOMElement("member", SynapseConstants.SYNAPSE_OMNAMESPACE, loadbalanceElement);
            memberEle.addAttribute(fac.createOMAttribute("hostName", null, member.getHostName()));
            memberEle.addAttribute(fac.createOMAttribute("httpPort", null, String.valueOf(member.getHttpPort())));
            memberEle.addAttribute(fac.createOMAttribute("httpsPort", null, String.valueOf(member.getHttpsPort())));
            loadbalanceElement.addChild(memberEle);
        }
    }
    // serialize the parameters
    serializeProperties(loadbalanceEndpoint, endpointElement);
    return endpointElement;
}
Also used : LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) OMElement(org.apache.axiom.om.OMElement) Member(org.apache.axis2.clustering.Member)

Example 7 with LoadbalanceEndpoint

use of org.apache.synapse.endpoints.LoadbalanceEndpoint in project wso2-synapse by wso2.

the class SendMediatorSerializationTest method testNestedLoadbalanceFailoverSendSerialization.

public void testNestedLoadbalanceFailoverSendSerialization() {
    String sendConfig = "<send xmlns=\"http://ws.apache.org/ns/synapse\">" + "<endpoint>" + "<loadbalance>" + "<endpoint>" + "<address uri=\"http://localhost:9001/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<failover>" + "<endpoint>" + "<address uri=\"http://localhost:9002/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<address uri=\"http://localhost:9003/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "</failover>" + "</endpoint>" + "</loadbalance>" + "</endpoint>" + "</send>";
    OMElement config1 = createOMElement(sendConfig);
    SendMediator send1 = (SendMediator) factory.createMediator(config1, new Properties());
    OMElement config2 = serializer.serializeMediator(null, send1);
    SendMediator send2 = (SendMediator) factory.createMediator(config2, new Properties());
    assertTrue("Top level endpoint should be a load balance endpoint.", send2.getEndpoint() instanceof LoadbalanceEndpoint);
    LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) send2.getEndpoint();
    List children = loadbalanceEndpoint.getChildren();
    assertEquals("Top level endpoint should have 2 child endpoints.", children.size(), 2);
    assertTrue("First child should be a address endpoint", children.get(0) instanceof AddressEndpoint);
    assertTrue("Second child should be a fail over endpoint", children.get(1) instanceof FailoverEndpoint);
    FailoverEndpoint failoverEndpoint = (FailoverEndpoint) children.get(1);
    List children2 = failoverEndpoint.getChildren();
    assertEquals("Fail over endpoint should have 2 children.", children2.size(), 2);
    assertTrue("Children of the fail over endpoint should be address endpoints.", children2.get(0) instanceof AddressEndpoint);
    assertTrue("Children of the fail over endpoint should be address endpoints.", children2.get(1) instanceof AddressEndpoint);
}
Also used : LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) OMElement(org.apache.axiom.om.OMElement) List(java.util.List) SendMediator(org.apache.synapse.mediators.builtin.SendMediator) Properties(java.util.Properties) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint)

Example 8 with LoadbalanceEndpoint

use of org.apache.synapse.endpoints.LoadbalanceEndpoint in project wso2-synapse by wso2.

the class WeightedRRLCAlgorithmTest method testInitialization.

public void testInitialization() {
    LoadbalanceEndpoint endpoint = createLoadBalanceEndpoint();
    LoadbalanceAlgorithm algo = endpoint.getAlgorithm();
    assert algo instanceof WeightedRRLCAlgorithm;
    WeightedRRLCAlgorithm algorithm = (WeightedRRLCAlgorithm) algo;
    assertEquals(6 + 5 + 3 + 2 + 1, algorithm.getTotalWeight());
    assertEquals(0, algorithm.getTotalConnections());
    assertEquals(0, algorithm.getEndpointCursor());
    assertEquals(2, algorithm.getRoundsPerRecalculation());
}
Also used : LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint)

Example 9 with LoadbalanceEndpoint

use of org.apache.synapse.endpoints.LoadbalanceEndpoint in project wso2-synapse by wso2.

the class WeightedRRLCAlgorithmTest method createLoadBalanceEndpoint.

private LoadbalanceEndpoint createLoadBalanceEndpoint() {
    LoadbalanceEndpoint loadbalanceEndpoint = new LoadbalanceEndpoint();
    List<Endpoint> endpoints = createEndpoints();
    WeightedRRLCAlgorithm algorithm = new WeightedRRLCAlgorithm();
    MediatorProperty property = new MediatorProperty();
    property.setName(WeightedRRLCAlgorithm.LB_WEIGHTED_RRLC_ROUNDS_PER_RECAL);
    property.setValue("2");
    loadbalanceEndpoint.addProperty(property);
    algorithm.setEndpoints(endpoints);
    algorithm.setLoadBalanceEndpoint(loadbalanceEndpoint);
    loadbalanceEndpoint.setChildren(endpoints);
    loadbalanceEndpoint.setAlgorithm(algorithm);
    SynapseEnvironment env = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), new SynapseConfiguration());
    loadbalanceEndpoint.init(env);
    return loadbalanceEndpoint;
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) MediatorProperty(org.apache.synapse.mediators.MediatorProperty) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Aggregations

LoadbalanceEndpoint (org.apache.synapse.endpoints.LoadbalanceEndpoint)9 OMElement (org.apache.axiom.om.OMElement)6 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)6 List (java.util.List)5 Properties (java.util.Properties)4 Endpoint (org.apache.synapse.endpoints.Endpoint)4 FailoverEndpoint (org.apache.synapse.endpoints.FailoverEndpoint)2 CallMediator (org.apache.synapse.mediators.builtin.CallMediator)2 SendMediator (org.apache.synapse.mediators.builtin.SendMediator)2 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 Member (org.apache.axis2.clustering.Member)1 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)1 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)1 MessageContext (org.apache.synapse.MessageContext)1 SynapseException (org.apache.synapse.SynapseException)1 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)1 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1