public static DocConstants Get() { if (m_docConstants == null) { m_docConstants = new DocConstants(); } return(m_docConstants); }
public static renderStorage Get() { if (m_renderStorageInstance == null) { m_renderStorageInstance = new renderStorage(DocConstants.Get().ConnectionString); } return(m_renderStorageInstance); }
static public string GetDeploymentInfo() { string x_ms_version = "2009-10-01"; string deploymentSlot = "Production"; string requestUri = "https://management.core.windows.net/" + DocConstants.Get().SubscriptionId + "/services/hostedservices/" + DocConstants.Get().ServiceName + "/deploymentslots/" + deploymentSlot; HttpWebRequest restRequest = (HttpWebRequest)HttpWebRequest.Create(requestUri); NameValueCollection requestHeaders = new NameValueCollection(); requestHeaders.Add("x-ms-version", x_ms_version); X509Certificate cert = LookupCertificate(); restRequest.ClientCertificates.Add(cert); restRequest.Method = "GET"; WebResponse restResponse = default(WebResponse); restRequest.ContentType = "text/xml"; if (requestHeaders != null) { restRequest.Headers.Add(requestHeaders); } restResponse = restRequest.GetResponse(); string responseBody = string.Empty; if (restResponse != null) { using (StreamReader restResponseStream = new StreamReader(restResponse.GetResponseStream(), true)) { // Deployment DeploymentConfiguration = (Deployment)xmls.Deserialize(RestResponseStream); responseBody = restResponseStream.ReadToEnd(); restResponseStream.Close(); } } return(responseBody); }
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; }
public static bool CheckLoginCorrect(string login, string password) { bool isCorrect = false; using (SqlConnection connection = new SqlConnection(DocConstants.Get().DBConnectionString)) { //name of db table is taking from config file, made by deployer string comStr = "select * from " + DocConstants.Get().DBTableName + " where name = @login and password = @password"; SqlCommand comm = new SqlCommand(comStr, connection); comm.Parameters.AddWithValue("@login", login); //adding parameters to query comm.Parameters.AddWithValue("@password", password); connection.Open(); object obj = comm.ExecuteScalar(); if (null != obj) { isCorrect = true; } } return(isCorrect); }
//zipArchive - blob with scene zip file private void extractArchive(string zipArchive) { Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(DocConstants.Get().ConnectionString); CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient(); CloudBlobContainer driveContainer = blobClient.GetContainerReference(BlobName.SCENE_BLOB);//sceneBlob = "scenegallery" CloudBlockBlob blockBlob = driveContainer.GetBlockBlobReference(zipArchive); string zipPath = m_directory.FullName + blockBlob.Name; Utils.DownloadBlobToFile(blockBlob, zipPath); //download scene zip file to zipPath try { FastZip zip = new FastZip(); zip.ExtractZip(zipPath, m_directory.FullName, null); //extract from zipPath to Directory } catch (Exception e) { string msg = "Extract archive error: " + e.Message; throw new Exception(msg); } }
static public void ChangeConfigFile(string configXML) { ChangeConfigFile(DocConstants.Get().SubscriptionId, DocConstants.Get().ServiceName, "Production", configXML); }
/// <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); } }