Ejemplo n.º 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);
 }
Ejemplo n.º 2
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);
            }
        }