Example #1
0
 /// <summary>
 ///
 /// </summary>
 /// <returns>true if deleted successfully</returns>
 public bool Clear()
 {
     try
     {
         lock (m_requestLock)
         {
             string deploymentInfo = AzureRESTMgmtHelper.GetDeploymentInfo();
             string svcconfig      = AzureRESTMgmtHelper.GetServiceConfig(deploymentInfo);
             string UpdatedSvcConfig;
             UpdatedSvcConfig = AzureRESTMgmtHelper.ChangeInstanceCount(svcconfig, DocConstants.MERGER_NAME, DocConstants.InititalInstancesCount);
             UpdatedSvcConfig = AzureRESTMgmtHelper.ChangeInstanceCount(UpdatedSvcConfig, DocConstants.WORKER_NAME, DocConstants.InititalInstancesCount);
             AzureRESTMgmtHelper.ChangeConfigFile(UpdatedSvcConfig); //deallocating instances
             m_scalePerforming        = true;
             m_instancesTimer.Enabled = true;
         }
     }
     catch (Exception e)
     {
         m_log.Error("Error when deleting instances: " + e.Message);
         return(false);
     }
     m_mergerCount     = 1;
     m_workerCount     = 1;
     m_mergerFreeCount = 1;
     m_workerFreeCount = 1;
     return(true);
 }
Example #2
0
        InstanceManager(RenderLog log)
        {
            m_log = log;
            m_log.Info("INSTANCE_MANAGER: Initializing instance manager");
            m_requestLock = new Object();
            //timer initialization
            m_instancesTimer          = new System.Timers.Timer(DocConstants.WAIT_AFTER_SCALE_REQUEST);
            m_instancesTimer.Elapsed += new ElapsedEventHandler(scaleFinished);
            m_instancesTimer.Enabled  = false;
            m_timer          = new System.Timers.Timer(RenderUtils.DocConstants.INSTANCES_REMOVING_INTERVAL);
            m_timer.Elapsed += new ElapsedEventHandler(timerElapsed);
            m_timer.Enabled  = true;
            if (DocConstants.Get().ConnectionString != DocConstants.DEBUG_CONNECTION_STRING)
            {
                string deploymentInfo = AzureRESTMgmtHelper.GetDeploymentInfo();
                string svcconfig      = AzureRESTMgmtHelper.GetServiceConfig(deploymentInfo);                                 //get azure config XML
                Int32.TryParse(AzureRESTMgmtHelper.GetInstanceCount(svcconfig, DocConstants.WORKER_NAME), out m_workerCount); //get number of
                if (m_workerCount <= 0)
                {
                    m_log.Warning("INSTANCE_MANAGER: Azure returned worker instance number as: " + m_workerCount);
                    m_workerCount = 1;
                }
                else
                {
                    m_log.Info("INSTANCE_MANAGER: initial worker count is: " + m_workerCount);
                }
                Int32.TryParse(AzureRESTMgmtHelper.GetInstanceCount(svcconfig, DocConstants.MERGER_NAME), out m_mergerCount);
                if (m_mergerCount <= 0)
                {
                    m_log.Warning("INSTANCE_MANAGER: Azure returned merger instance number as: " + m_workerCount);
                    m_mergerCount = 1;
                }
                else
                {
                    m_log.Info("INSTANCE_MANAGER: initial merger count is: " + m_mergerCount);
                }

                m_workerFreeCount = m_workerCount;
                m_mergerFreeCount = m_mergerCount;
            }
            m_scalePerforming = false;
        }
Example #3
0
        /// <summary>
        /// Send request to azure to allocate new worker and merger instances if needed
        /// </summary>
        /// <param name="workerRequestCount">Nunber of required worker instances</param>
        /// <returns>true if operation was a success</returns>
        public bool Require(int workerRequestCount)
        {
            if (DocConstants.Get().ConnectionString == DocConstants.DEBUG_CONNECTION_STRING)
            {
                return(true);
            }
            int workerBackupCount     = m_workerCount;
            int workerFreeBackupCount = m_workerFreeCount;
            int mergerBackupCount     = m_mergerCount;

            try
            {
                lock (m_requestLock)
                {
                    bool changeConf = false;
                    m_log.Info("INSTANCE_MANAGER: getting deployment info");
                    string deploymentInfo   = AzureRESTMgmtHelper.GetDeploymentInfo();
                    string svcconfig        = AzureRESTMgmtHelper.GetServiceConfig(deploymentInfo);
                    string UpdatedSvcConfig = svcconfig;
                    if (m_mergerFreeCount < 1)
                    {
                        //adding merger instance to config
                        ++m_mergerCount;
                        m_log.Info("INSTANCE_MANAGER: requesting new merger. Now mergers count: " + m_mergerCount.ToString());
                        changeConf       = true;
                        UpdatedSvcConfig = AzureRESTMgmtHelper.ChangeInstanceCount(svcconfig, DocConstants.MERGER_NAME, m_mergerCount.ToString());
                    }
                    else //there is at least one free merger
                    {
                        --m_mergerFreeCount;
                    }
                    if (m_workerFreeCount < workerRequestCount)
                    {
                        //adding new workers to config
                        int toAllocWorkerCount = workerRequestCount - m_workerFreeCount;
                        m_workerCount    += toAllocWorkerCount;
                        m_workerFreeCount = 0;
                        m_log.Info("INSTANCE_MANAGER: requesting new workers. Now workers count: " + m_workerCount.ToString());
                        changeConf       = true;
                        UpdatedSvcConfig = AzureRESTMgmtHelper.ChangeInstanceCount(UpdatedSvcConfig, DocConstants.WORKER_NAME, m_workerCount.ToString());
                    }
                    else
                    {
                        m_workerFreeCount -= workerRequestCount;
                    }
                    while (m_scalePerforming)     //wait while last request is being performed
                    {
                        System.Threading.Thread.Sleep(10000);
                        continue;
                    }
                    if (changeConf)
                    {
                        m_scalePerforming = true;
                        AzureRESTMgmtHelper.ChangeConfigFile(UpdatedSvcConfig);     //allocating instances
                        m_instancesTimer.Enabled = true;
                        m_log.Info("INSTANCE_MANAGER: Timer turned on. Waiting for allocation");
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                m_log.Error("INSTANCE_MANAGER: Error when allocating instances: " + e.Message + " Request was reversed.");
                m_workerCount     = workerBackupCount;
                m_workerFreeCount = workerFreeBackupCount;
                if (m_mergerCount != mergerBackupCount)
                {
                    --m_mergerCount;
                }
                else
                {
                    ++m_mergerFreeCount;
                }
                return(false);
            }
        }