Package org.apache.stratos.lb.common.conf

Examples of org.apache.stratos.lb.common.conf.LoadBalancerConfiguration


    }

    @Override
    public void run() {
        // grab the lb configuration instance
        LoadBalancerConfiguration lbconfig = LoadBalancerConfiguration.getInstance();

        // FIXME Currently there has to be at least one dummy cluster defined in the loadbalancer
        // conf
        // in order to proper initialization of TribesClusteringAgent.
        generateGroupMgtAgents(lbconfig);

        // this thread should run for ever, untill terminated.
        while (true) {
            try {

                // grabs a message or waits till the queue is non-empty
                String message = sharedQueue.take();
//                ConfigHolder data = ConfigHolder.getInstance();

                // this message needs attention only if it's not same as the previous message and
                // not null of course.
//                if (data.getPreviousMsg() == null || !data.getPreviousMsg().equals(message)) {

                    // reset the previous message
//                    data.setPreviousMsg(message);

                    // build the nginx format of this message, and get the Node object
                    Node topologyNode = NodeBuilder.buildNode(message);

                    // reset service configurations
//                    lbconfig.resetData();
                    // create new service configurations
                    List<ServiceConfiguration> currentServiceConfigs = lbconfig.createServicesConfig(topologyNode);
                   
                    generateGroupMgtAgents(lbconfig);
                   
                    removeGroupMgtAgents(lbconfig, currentServiceConfigs);
View Full Code Here


      throw new SynapseException(msg);
    }

    handler.removeHostContext(hostName);
   
    LoadBalancerConfiguration lbConfig = ConfigHolder.getInstance().getLbConfig();
   
    lbConfig.removeServiceConfiguration(domain, subDomain);
   
  }
View Full Code Here

    lbConfig.removeServiceConfiguration(domain, subDomain);
   
  }
   
    private void createOrUpdateServiceConfig(ClusterDomain cluster, HostContext ctxt) {
        LoadBalancerConfiguration lbConfig = ConfigHolder.getInstance().getLbConfig();
       
        String domain = cluster.getDomain();
        String subDomain = cluster.getSubDomain();
       
        if (subDomain == null || subDomain.isEmpty()) {
            // uses default sub domain
            subDomain = Constants.DEFAULT_SUB_DOMAIN;
        }
       
        String hostName = cluster.getHostName();
        String tenantRange = cluster.getTenantRange();
        int minInstances = cluster.getMinInstances();
        int maxInstances = cluster.getMaxInstances();
        String service = cluster.getServiceName();
        int maxRequestsPerSecond = cluster.getMaxRequestsPerSecond();
      int roundsToAverage = cluster.getRoundsToAverage();
      double alarmingUpperRate = cluster.getAlarmingUpperRate();
      double alarmingLowerRate = cluster.getAlarmingLowerRate();
      double scaleDownFactor = cluster.getScaleDownFactor();
       
        ServiceConfiguration serviceConfig ;
       
        if((serviceConfig = lbConfig.getServiceConfig(domain, subDomain)) == null){
            serviceConfig = lbConfig.new ServiceConfiguration();
        }
       
        // we simply override the attributes with new values
        serviceConfig.setDomain(domain);
        serviceConfig.setSub_domain(subDomain);
        serviceConfig.setTenant_range(tenantRange);
        serviceConfig.setHosts(hostName);
        serviceConfig.setMin_app_instances(minInstances);
        serviceConfig.setMax_app_instances(maxInstances);
        serviceConfig.setMax_requests_per_second(maxRequestsPerSecond);
        serviceConfig.setRounds_to_average(roundsToAverage);
        serviceConfig.setAlarming_upper_rate(alarmingUpperRate);
        serviceConfig.setAlarming_lower_rate(alarmingLowerRate);
        serviceConfig.setScale_down_factor(scaleDownFactor);
       
        // add to host name tracker
        lbConfig.addToHostNameTrackerMap(service, serviceConfig.getHosts());
       
        // add to host contexts
        lbConfig.addToHostContextMap(hostName, ctxt);
       
        // finally add this service config
        lbConfig.addServiceConfiguration(serviceConfig);
    }
View Full Code Here

        SynapseEnvironment synapseEnv = (SynapseEnvironment) synEnv.getValue();

        /** Initializing autoscaleIn and autoscaleOut Mediators.**/

        LoadBalancerConfiguration lbConfig = AutoscalerTaskDSHolder.getInstance().getWholeLoadBalancerConfig();
        // check whether autoscaling is enabled
        if (lbConfig.getLoadBalancerConfig().isAutoscaleEnabled()) {

            // get the main sequence mediator
            SequenceMediator mainSequence =
                    (SequenceMediator) synapseEnv.getSynapseConfiguration().getSequence("main");

            // iterate through its child mediators
            for (Mediator child : mainSequence.getList()) {

                // find the InMediator
                if (child instanceof InMediator) {
                    InMediator inSequence = (InMediator) child;

                    // if the first child of InMediator isn't an AutoscaleInMediator
                    if (!(inSequence.getList().get(0) instanceof AutoscaleInMediator)) {

                        // we gonna add it!
                        inSequence.getList().add(0, new AutoscaleInMediator());
                        if (log.isDebugEnabled()) {
                            log.debug("Added Mediator: " + inSequence.getChild(0) + "" +
                                    " to InMediator. Number of child mediators in InMediator" + " is " +
                                    inSequence.getList().size() + ".");
                        }
                    }

                }

                // find the OutMediator
                if (child instanceof OutMediator) {

                    OutMediator outSequence = (OutMediator) child;

                    // if the first child of OutMediator isn't an AutoscaleOutMediator
                    if (!(outSequence.getList().get(0) instanceof AutoscaleOutMediator)) {

                        // we gonna add it!
                        outSequence.getList().add(0, new AutoscaleOutMediator());

                        if (log.isDebugEnabled()) {
                            log.debug("Added Mediator: " + outSequence.getChild(0) + "" +
                                    " to OutMediator. Number of child mediators in OutMediator" +
                                    " is " + outSequence.getList().size() + ".");
                        }

                    }
                }
            }

            /** Initializing Autoscaler Task **/

            BundleContext bundleContext = context.getBundleContext();
            if (log.isDebugEnabled()) {
                log.debug("Initiating Autoscaler task service component");
            }

            if (bundleContext.getServiceReference(TaskManagementService.class.getName()) != null) {
                bundleContext.registerService(TaskManagementService.class.getName(),
                        new AutoscalerTaskMgmtAdminService(), null);
            }


            AutoscalerTaskInitializer listener = new AutoscalerTaskInitializer();

            if (bundleContext.getServiceReference(Axis2ConfigurationContextObserver.class.getName()) != null) {
                bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(),
                        listener, null);
            }

            if (configurationContext != null) {
                TaskScheduler scheduler =
                        (TaskScheduler) configurationContext.getProperty(AutoscalerTaskInitializer.CARBON_TASK_SCHEDULER);
                if (scheduler == null) {
                    scheduler = new TaskScheduler(TaskConstants.TASK_SCHEDULER);
                    scheduler.init(null);
                    configurationContext.setProperty(AutoscalerTaskInitializer.CARBON_TASK_SCHEDULER,
                            scheduler);
                } else if (!scheduler.isInitialized()) {
                    scheduler.init(null);
                }
            }
           
            String autoscalerClass = lbConfig.getLoadBalancerConfig().getAutoscalerTaskClass();
            Task task;
            if (autoscalerClass != null) {
                try {
                    task = (Task) Class.forName(autoscalerClass).newInstance();
                } catch (Exception e) {
View Full Code Here

   
  }
 
  public void run() {

      LoadBalancerConfiguration lbconfig = LoadBalancerConfiguration.getInstance();
     
      //FIXME Currently there has to be at least one dummy cluster defined in the loadbalancer conf
      // in order to proper initialization of TribesClusteringAgent.
      generateGroupMgtAgents(lbconfig);
     
        while (true) {
            try {

                Object obj;
                String msg = null;

                obj = sharedQueue.take();
                msg = (String) obj;

                ConfigHolder data = ConfigHolder.getInstance();

                Node topologyNode = NodeBuilder.buildNode(msg);

                List<ServiceConfiguration> currentServiceConfigs = lbconfig.createServicesConfig(topologyNode);

                data.setServiceConfigs(lbconfig.getServiceNameToServiceConfigurations());
                generateGroupMgtAgents(lbconfig);
                resetGroupMgtAgents(lbconfig, currentServiceConfigs);

            } catch (InterruptedException ignore) {
            }
View Full Code Here

TOP

Related Classes of org.apache.stratos.lb.common.conf.LoadBalancerConfiguration

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.