log.error(msg);
throw new PolicyValidationException(msg);
}
String clusterId = cluster.getClusterId();
LbClusterMonitor clusterMonitor =
new LbClusterMonitor(clusterId,
cluster.getServiceName(),
deploymentPolicy, policy);
// partition group = network partition context
for (PartitionGroup partitionGroup : deploymentPolicy.getPartitionGroups()) {
NetworkPartitionLbHolder networkPartitionLbHolder =
PartitionManager.getInstance()
.getNetworkPartitionLbHolder(partitionGroup.getId());
// PartitionManager.getInstance()
// .getNetworkPartitionLbHolder(partitionGroup.getId());
// FIXME pick a random partition
Partition partition =
partitionGroup.getPartitions()[new Random().nextInt(partitionGroup.getPartitions().length)];
PartitionContext partitionContext = new PartitionContext(partition);
partitionContext.setServiceName(cluster.getServiceName());
partitionContext.setProperties(cluster.getProperties());
partitionContext.setNetworkPartitionId(partitionGroup.getId());
partitionContext.setMinimumMemberCount(1);//Here it hard codes the minimum value as one for LB cartridge partitions
NetworkPartitionContext networkPartitionContext = new NetworkPartitionContext(partitionGroup.getId(),
partitionGroup.getPartitionAlgo(), partitionGroup.getPartitions()) ;
for (Member member : cluster.getMembers()) {
String memberId = member.getMemberId();
if (member.getNetworkPartitionId().equalsIgnoreCase(networkPartitionContext.getId())) {
MemberContext memberContext = new MemberContext();
memberContext.setClusterId(member.getClusterId());
memberContext.setMemberId(memberId);
memberContext.setPartition(partition);
if (MemberStatus.Activated.equals(member.getStatus())) {
partitionContext.addActiveMember(memberContext);
// networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(), 1);
// partitionContext.incrementCurrentActiveMemberCount(1);
} else if (MemberStatus.Created.equals(member.getStatus()) ||
MemberStatus.Starting.equals(member.getStatus())) {
partitionContext.addPendingMember(memberContext);
// networkPartitionContext.increaseMemberCountOfPartition(partition.getNetworkPartitionId(), 1);
} else if (MemberStatus.Suspended.equals(member.getStatus())) {
// partitionContext.addFaultyMember(memberId);
}
partitionContext.addMemberStatsContext(new MemberStatsContext(memberId));
if(log.isInfoEnabled()){
log.info(String.format("Member stat context has been added: [member] %s", memberId));
}
}
}
networkPartitionContext.addPartitionContext(partitionContext);
// populate lb cluster id in network partition context.
java.util.Properties props = cluster.getProperties();
// get service type of load balanced cluster
String loadBalancedServiceType = props.getProperty(Constants.LOAD_BALANCED_SERVICE_TYPE);
if(props.containsKey(Constants.LOAD_BALANCER_REF)) {
String value = props.getProperty(Constants.LOAD_BALANCER_REF);
if (value.equals(org.apache.stratos.messaging.util.Constants.DEFAULT_LOAD_BALANCER)) {
networkPartitionLbHolder.setDefaultLbClusterId(clusterId);
} else if (value.equals(org.apache.stratos.messaging.util.Constants.SERVICE_AWARE_LOAD_BALANCER)) {
String serviceName = cluster.getServiceName();
// TODO: check if this is correct
networkPartitionLbHolder.addServiceLB(serviceName, clusterId);
if (loadBalancedServiceType != null && !loadBalancedServiceType.isEmpty()) {
networkPartitionLbHolder.addServiceLB(loadBalancedServiceType, clusterId);
if (log.isDebugEnabled()) {
log.debug("Added cluster id " + clusterId + " as the LB cluster id for service type " + loadBalancedServiceType);
}
}
}
}
clusterMonitor.addNetworkPartitionCtxt(networkPartitionContext);
}
log.info("LB Cluster monitor created: "+clusterMonitor.toString());
return clusterMonitor;
}