Package org.apache.stratos.messaging.domain.topology

Examples of org.apache.stratos.messaging.domain.topology.Cluster


    }

    public static org.apache.stratos.rest.endpoint.bean.topology.Cluster getCluster (String cartridgeType, String subscriptionAlias, ConfigurationContext configurationContext) throws RestAPIException {

        Cluster cluster = TopologyClusterInformationModel.getInstance().getCluster(ApplicationManagementUtil.getTenantId(configurationContext)
                ,cartridgeType , subscriptionAlias);
        if(cluster == null) {
            throw new RestAPIException("No matching cluster found for [cartridge type]: "+cartridgeType+ " [alias] "+subscriptionAlias);
        } else{
            return PojoConverter.populateClusterPojos(cluster);
View Full Code Here


        // register service cartridge subscription
        return registerCartridgeSubscription(serviceCartridgeSubscription, serviceCartridgeSubscriptionProperties);
    }

    private boolean activeInstancesAvailable(SubscriptionData subscriptionData) {
      Cluster cluster = TopologyClusterInformationModel.getInstance().getCluster(subscriptionData.getCartridgeType());
      int activeMemberCount = 0;
      if(cluster != null) {
          Collection<Member> members = cluster.getMembers();
          for (Member member : members) {
        if(member.isActive()) {
          activeMemberCount++;
        }
      }
View Full Code Here

                String serviceType = clustercreatedEvent.getServiceName();
                //acquire read lock
                TopologyManager.acquireReadLock();

                try {
                    Cluster cluster = TopologyManager.getTopology().getService(serviceType).getCluster(clustercreatedEvent.getClusterId());
                    TopologyClusterInformationModel.getInstance().addCluster(cluster);

                } finally {
                    //release read lock
                    TopologyManager.releaseReadLock();
                }

            }
        });


        //Cluster Removed event listner
        topologyEventReceiver.addEventListener(new ClusterRemovedEventListener() {
            @Override
            protected void onEvent(Event event) {

                log.info("[ClusterRemovedEventListener] Received: " + event.getClass());

                ClusterRemovedEvent clusterRemovedEvent = (ClusterRemovedEvent) event;
                TopologyClusterInformationModel.getInstance().removeCluster(clusterRemovedEvent.getClusterId());
            }
        });
       
       
      //Instance Spawned event listner
        topologyEventReceiver.addEventListener(new InstanceSpawnedEventListener() {

            @Override
            protected void onEvent(Event event) {

                log.info("[InstanceSpawnedEventListener] Received: " + event.getClass());

                InstanceSpawnedEvent instanceSpawnedEvent = (InstanceSpawnedEvent) event;

                String clusterDomain = instanceSpawnedEvent.getClusterId();

                String serviceType = instanceSpawnedEvent.getServiceName();
                //acquire read lock
                TopologyManager.acquireReadLock();

                try {
                    Cluster cluster = TopologyManager.getTopology().getService(serviceType).getCluster(clusterDomain);
                    TopologyClusterInformationModel.getInstance().addCluster(cluster);
                } finally {
                    //release read lock
                    TopologyManager.releaseReadLock();
                }
            }
        });

        //Member Started event listner
        topologyEventReceiver.addEventListener(new MemberStartedEventListener() {
            @Override
            protected void onEvent(Event event) {

                log.info("[MemberStartedEventListener] Received: " + event.getClass());

                MemberStartedEvent memberStartedEvent = (MemberStartedEvent) event;

                String clusterDomain = memberStartedEvent.getClusterId();

                String serviceType = memberStartedEvent.getServiceName();
                //acquire read lock
                TopologyManager.acquireReadLock();

                try {
                    Cluster cluster = TopologyManager.getTopology().getService(serviceType).getCluster(clusterDomain);
                    TopologyClusterInformationModel.getInstance().addCluster(cluster);
                } finally {
                    //release read lock
                    TopologyManager.releaseReadLock();
                }

            }
        });

        //Member Activated event listner
        topologyEventReceiver.addEventListener(new MemberActivatedEventListener() {
            @Override
            protected void onEvent(Event event) {

                log.info("[MemberActivatedEventListener] Received: " + event.getClass());

                MemberActivatedEvent memberActivatedEvent = (MemberActivatedEvent) event;

                String clusterDomain = memberActivatedEvent.getClusterId();

                String serviceType = memberActivatedEvent.getServiceName();
                //acquire read lock
                TopologyManager.acquireReadLock();

                try {
                    Cluster cluster = TopologyManager.getTopology().getService(serviceType).getCluster(clusterDomain);
                    TopologyClusterInformationModel.getInstance().addCluster(cluster);
                } finally {
                    //release read lock
                    TopologyManager.releaseReadLock();
                }
            }
        });

        //Member Suspended event listner
        topologyEventReceiver.addEventListener(new MemberSuspendedEventListener() {
            @Override
            protected void onEvent(Event event) {

                log.info("[MemberSuspendedEventListener] Received: " + event.getClass());

                MemberSuspendedEvent memberSuspendedEvent = (MemberSuspendedEvent) event;

                String clusterDomain = memberSuspendedEvent.getClusterId();

                String serviceType = memberSuspendedEvent.getServiceName();
                //acquire read lock
                TopologyManager.acquireReadLock();

                try {
                    Cluster cluster = TopologyManager.getTopology().getService(serviceType).getCluster(clusterDomain);
                    TopologyClusterInformationModel.getInstance().addCluster(cluster);

                } finally {
                    //release read lock
                    TopologyManager.releaseReadLock();
                }
            }
        });

        //Member Terminated event listner
        topologyEventReceiver.addEventListener(new MemberTerminatedEventListener() {
            @Override
            protected void onEvent(Event event) {

                log.info("[MemberTerminatedEventListener] Received: " + event.getClass());

                MemberTerminatedEvent memberTerminatedEvent = (MemberTerminatedEvent) event;

                String clusterDomain = memberTerminatedEvent.getClusterId();

                String serviceType = memberTerminatedEvent.getServiceName();
                //acquire read lock
                TopologyManager.acquireReadLock();

                try {
                    Cluster cluster = TopologyManager.getTopology().getService(serviceType).getCluster(clusterDomain);

                    // check and remove terminated member
                    if (cluster.memberExists(memberTerminatedEvent.getMemberId())) {
                        // release the read lock and acquire the write lock
                        TopologyManager.releaseReadLock();
                        TopologyManager.acquireWriteLock();

                        try {
                            // re-check the state; another thread might have acquired the write lock and modified
                            if (cluster.memberExists(memberTerminatedEvent.getMemberId())) {
                                // remove the member from the cluster
                                Member terminatedMember = cluster.getMember(memberTerminatedEvent.getMemberId());
                                cluster.removeMember(terminatedMember);
                                if (log.isDebugEnabled()) {
                                    log.debug("Removed the terminated member with id " + memberTerminatedEvent.getMemberId() + " from the cluster");
                                }
                            }
View Full Code Here

    }  

    public Cluster getCluster (int tenantId, String cartridgeType, String subscriptionAlias) {

      String clusterId = dataInsertionNRetrievalMgr.getCartridgeSubscription(tenantId, subscriptionAlias).getClusterDomain();
      Cluster cluster = clusterIdToClusterMap.get(clusterId);
      if(log.isDebugEnabled()) {
        log.debug(" Found cluster ["+cluster+"] with id ["+clusterId+"] ");
      }
      return cluster;
    }
View Full Code Here

    }
   
    public Cluster getCluster (String cartridgeType) {

      Service service;
      Cluster cluster = null;
    try {
      service = dataInsertionNRetrievalMgr.getService(cartridgeType);
    } catch (PersistenceManagerException e) {
      log.error("Exception occurred when retrieving service [" + cartridgeType +"] ");
      return null;
View Full Code Here

        // TODO  -- check this. Sometimes getting clusterId some non-meaningful value
        String clusterId = cartridgeSubscription.getClusterDomain();
        if(log.isDebugEnabled()) {
          log.info("Finding cluster with id ["+clusterId+"] ");
        }
        Cluster foundCluster = clusterIdToClusterMap.get(clusterId);
        if (foundCluster != null) {
          clusterSet.add(foundCluster);
        }
      }
    }
View Full Code Here

                        return;
                    }
                    // Cluster not found in load balancer context, add it
                    Service service = TopologyManager.getTopology().getService(memberActivatedEvent.getServiceName());
                    if (service != null) {
                        Cluster cluster = service.getCluster(memberActivatedEvent.getClusterId());
                        if (cluster != null) {
                            LoadBalancerContextUtil.addClusterToLbContext(cluster);
                        } else {
                            if (log.isErrorEnabled()) {
                                log.error(String.format("Cluster not found in topology: [service] %s [cluster] %s",
                                        memberActivatedEvent.getServiceName(), memberActivatedEvent.getClusterId()));
                            }
                        }
                    } else {
                        if (log.isErrorEnabled()) {
                            log.error(String.format("Service not found in topology: [service] %s", memberActivatedEvent.getServiceName()));
                        }
                    }
                } catch (Exception e) {
                    log.error("Error processing event", e);
                } finally {
                    TopologyManager.releaseReadLock();
                }
            }
        });
        topologyEventReceiver.addEventListener(new ClusterRemovedEventListener() {
            @Override
            protected void onEvent(Event event) {
                try {
                    TopologyManager.acquireReadLock();

                    // Remove cluster from context
                    ClusterRemovedEvent clusterRemovedEvent = (ClusterRemovedEvent) event;
                    Cluster cluster = LoadBalancerContext.getInstance().getClusterIdClusterMap().getCluster(clusterRemovedEvent.getClusterId());
                    if (cluster != null) {
                        LoadBalancerContextUtil.removeClusterFromLbContext(cluster.getClusterId());
                    } else {
                        if (log.isWarnEnabled()) {
                            log.warn(String.format("Cluster not found in load balancer context: [service] %s [cluster] %s",
                                    clusterRemovedEvent.getServiceName(), clusterRemovedEvent.getClusterId()));
                        }
                    }
                } catch (Exception e) {
                    log.error("Error processing event", e);
                } finally {
                    TopologyManager.releaseReadLock();
                }
            }
        });
        topologyEventReceiver.addEventListener(new ServiceRemovedEventListener() {
            @Override
            protected void onEvent(Event event) {
                try {
                    TopologyManager.acquireReadLock();

                    // Remove all clusters of given service from context
                    ServiceRemovedEvent serviceRemovedEvent = (ServiceRemovedEvent) event;
                    Service service = TopologyManager.getTopology().getService(serviceRemovedEvent.getServiceName());
                    if (service != null) {
                        for (Cluster cluster : service.getClusters()) {
                            LoadBalancerContextUtil.removeClusterFromLbContext(cluster.getClusterId());
                        }
                    } else {
                        if (log.isWarnEnabled()) {
                            log.warn(String.format("Service not found in topology: [service] %s", serviceRemovedEvent.getServiceName()));
                        }
View Full Code Here

            }
        }
    }

    public static void removeClusterFromLbContext(String clusterId) {
        Cluster cluster = LoadBalancerContext.getInstance().getClusterIdClusterMap().getCluster(clusterId);
        if (cluster == null) {
            return;
        }

        Service service = TopologyManager.getTopology().getService(cluster.getServiceName());
        if (service == null) {
            throw new RuntimeException(String.format("Service not found: [cluster] %s", cluster.getClusterId()));
        }

        // Remove cluster from HostNameClusterMap
        for (String hostName : cluster.getHostNames()) {
            if (LoadBalancerContext.getInstance().getHostNameClusterMap().containsCluster(hostName)) {
                LoadBalancerContext.getInstance().getHostNameClusterMap().removeCluster(hostName);
                if (log.isDebugEnabled()) {
                    log.debug(String.format("Cluster removed from hostname -> cluster map: [hostname] %s [cluster] %s ", hostName, cluster.getClusterId()));
                }
            }
        }

        // Remove cluster from ClusterIdClusterMap
        LoadBalancerContext.getInstance().getClusterIdClusterMap().removeCluster(clusterId);
        if (log.isDebugEnabled()) {
            log.debug(String.format("Cluster removed from cluster-id -> cluster map: [cluster] %s ", cluster.getClusterId()));
        }
    }
View Full Code Here

        if (hostName == null)
            return null;

        long startTime = System.currentTimeMillis();

        Cluster cluster = LoadBalancerContext.getInstance().getHostNameClusterMap().getCluster(hostName);
        if (cluster != null) {
            Member member = findNextMemberInCluster(cluster);
            if (member != null) {
                if (log.isDebugEnabled()) {
                    long endTime = System.currentTimeMillis();
View Full Code Here

    public Member findNextMemberFromTenantId(String hostName, int tenantId) {
        long startTime = System.currentTimeMillis();

        // Find cluster from host name and tenant id
        Cluster cluster = LoadBalancerContext.getInstance().getMultiTenantClusterMap().getCluster(hostName, tenantId);
        if (cluster != null) {
            Member member = findNextMemberInCluster(cluster);
            if (member != null) {
                if (log.isDebugEnabled()) {
                    long endTime = System.currentTimeMillis();
View Full Code Here

TOP

Related Classes of org.apache.stratos.messaging.domain.topology.Cluster

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.