private boolean doProcess(ClusterCreatedEvent event, Topology topology) { Cluster cluster = event.getCluster(); String applicationId = cluster.getAppId(); String serviceName = cluster.getServiceName(); String clusterId = cluster.getClusterId(); // Apply application filter if (TopologyApplicationFilter.apply(applicationId)) { return false; } // Apply service filter if (TopologyServiceFilter.apply(serviceName)) { return false; } // Apply cluster filter if (TopologyClusterFilter.apply(clusterId)) { return false; } // Validate event against the existing topology Service service = topology.getService(serviceName); if (service == null) { if (log.isWarnEnabled()) { log.warn(String.format("Service does not exist: [service] %s", serviceName)); } return false; } if (service.clusterExists(clusterId)) { if (log.isDebugEnabled()) { log.debug( String.format( "Cluster already exists in service: [service] %s " + "[cluster] %s", serviceName, clusterId)); } } else { // Apply changes to the topology service.addCluster(cluster); if (log.isInfoEnabled()) { log.info(String.format("Cluster created: %s", cluster.toString())); } } // Notify event listeners notifyEventListeners(event); return true; }
private boolean doProcess(MemberMaintenanceModeEvent event, Topology topology) { String serviceName = event.getServiceName(); String clusterId = event.getClusterId(); // Apply service filter if (TopologyServiceFilter.apply(serviceName)) { return false; } // Apply cluster filter if (TopologyClusterFilter.apply(clusterId)) { return false; } // Validate event against the existing topology Service service = topology.getService(event.getServiceName()); if (service == null) { if (log.isWarnEnabled()) { log.warn(String.format("Service does not exist: [service] %s", event.getServiceName())); } return false; } Cluster cluster = service.getCluster(event.getClusterId()); if (cluster == null) { if (log.isWarnEnabled()) { log.warn( String.format( "Cluster does not exist: [service] %s [cluster] %s", event.getServiceName(), event.getClusterId())); } return false; } // Apply application filter if (TopologyApplicationFilter.apply(cluster.getAppId())) { return false; } Member member = cluster.getMember(event.getMemberId()); if (member == null) { if (log.isWarnEnabled()) { log.warn( String.format( "Member does not exist: [service] %s [cluster] %s [member] %s", event.getServiceName(), event.getClusterId(), event.getMemberId())); } return false; } // Apply member filter if (TopologyMemberFilter.apply(member.getLbClusterId(), member.getNetworkPartitionId())) { return false; } if (member.getStatus() == MemberStatus.In_Maintenance) { if (log.isDebugEnabled()) { log.debug( String.format( "Member already updated as In_Maintenance: " + "[service] %s [cluster] %s [member] %s", event.getServiceName(), event.getClusterId(), event.getMemberId())); } } else { // Apply changes to the topology if (!member.isStateTransitionValid(MemberStatus.In_Maintenance)) { log.error( "Invalid State Transition from " + member.getStatus() + " to " + MemberStatus.In_Maintenance); } member.setStatus(MemberStatus.In_Maintenance); if (log.isInfoEnabled()) { log.info( String.format( "Member updated as In_Maintenance: [service] %s [cluster] %s [member] %s", event.getServiceName(), event.getClusterId(), event.getMemberId())); } } // Notify event listeners notifyEventListeners(event); return true; }