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;
}
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);
}
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());
}
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;
}
Aggregations