private string ListWorkerRoles() { var current = RoleEnvironment.CurrentRoleInstance; var endPoints = current.Role.Instances .Select(instance => instance.InstanceEndpoints["ElasticCloudServiceEndpoint"]).ToArray(); if (!endPoints.Any()) { DiagnosticsHelper.TraceInformation("no endpoints found"); return(String.Empty); } var builder = new StringBuilder(); foreach (var endPointString in endPoints.Select(endPoint => String.Format("{0}:{1}", endPoint.IPEndpoint.Address, endPoint.IPEndpoint.Port))) { if (builder.Length > 0) { builder.Append(", "); } builder.Append(endPointString); DiagnosticsHelper.TraceInformation("endpoint:" + endPointString); } DiagnosticsHelper.TraceInformation("endpoints:" + builder); return(builder.ToString()); }
/// <summary> /// Run method to start tomcat process in the worker role instances /// </summary> public override void Run() { // This is a sample worker implementation. Replace with your logic. DiagnosticsHelper.TraceInformation("ElasticSearch entry point called"); DiagnosticsHelper.TraceInformation("Configuring Elastic Search"); ConfigureElasticSearch(); DiagnosticsHelper.TraceInformation("Configured Elastic Search"); while (true) { Thread.Sleep(10000); Trace.WriteLine("Working", "Information"); try { if ((_process != null) && _process.HasExited) { DiagnosticsHelper.TraceInformation("ElasticSearch Process Exited. Hence recycling role."); RoleEnvironment.RequestRecycle(); return; } } catch (Exception ex) { DiagnosticsHelper.TraceError(ex.Message + " " + ex.StackTrace); throw new ApplicationException("Elastic Search Quit: " + ex.Message); } } }
/// <summary> /// Function to run setupTomcat.bat which in runnin TomcatConfigManager.exe /// </summary> /// <param name="batchFile"></param> /// <param name="esLocation"></param> /// <param name="port"></param> /// <param name="appRoot"></param> /// <returns></returns> private string RunCommand(string batchFile, string esLocation, string port, string appRoot) { // initiating process var newProc = new Process(); // initiating stream reader to get the output details // string variable to store the output details try { // setting the required properties for the process newProc.StartInfo.UseShellExecute = false; newProc.StartInfo.RedirectStandardOutput = true; newProc.StartInfo.RedirectStandardError = true; newProc.StartInfo.RedirectStandardOutput = true; #if DEBUG newProc.StartInfo.CreateNoWindow = false; #endif #if !DEBUG newProc.StartInfo.CreateNoWindow = true; #endif newProc.EnableRaisingEvents = false; var esHome = esLocation.Substring(0, esLocation.Length - 1); // setting the localsource path tomcatlocation to the environment variable catalina_home newProc.StartInfo.EnvironmentVariables.Add("ES_HOME", esHome); // set the batchFile setupTomcat.bat in approot directory as process filename newProc.StartInfo.FileName = batchFile; // set the follwing three arguments for the process {0} catalina_home - environment variable which has the localresource path // {1} - port in which the tomcat has to be run and which needs to be changed in the server xml // {2} - approot path newProc.StartInfo.Arguments = String.Format("{0} {1} \"{2}\"", esHome, port, appRoot); DiagnosticsHelper.TraceInformation("Arguments: " + newProc.StartInfo.Arguments); // starting the process newProc.Start(); newProc.OutputDataReceived += processToExecuteCommand_OutputDataReceived; newProc.ErrorDataReceived += processToExecuteCommand_ErrorDataReceived; newProc.BeginOutputReadLine(); newProc.BeginErrorReadLine(); newProc.WaitForExit(); newProc.Close(); } catch (Exception ex) { Trace.TraceError(ex.Message); throw; } return(String.Empty); }
/// <summary> /// Function to start Tomcat Process /// </summary> /// <param name="esLocation">The es location.</param> /// <param name="cacheLocation">The cache location.</param> /// <param name="workerIPs">The worker IP's.</param> /// <returns></returns> private Process StartESProcess(string esLocation, string cacheLocation, string workerIPs) { DiagnosticsHelper.TraceInformation("ElasticSearch - starting pricess at esLocation:" + esLocation + ",cacheLocation:" + cacheLocation + ",workerIPs:" + workerIPs); // initiating process var newProc = new Process(); // stream reader to get the output details of the running command try { //setting the required properties for the process newProc.StartInfo.UseShellExecute = false; newProc.StartInfo.RedirectStandardOutput = true; newProc.StartInfo.RedirectStandardError = true; newProc.StartInfo.RedirectStandardOutput = true; #if DEBUG newProc.StartInfo.CreateNoWindow = false; #endif #if !DEBUG newProc.StartInfo.CreateNoWindow = true; #endif newProc.EnableRaisingEvents = false; newProc.StartInfo.EnvironmentVariables.Remove("JAVA_HOME"); newProc.StartInfo.EnvironmentVariables.Add("JAVA_HOME", Path.Combine(esLocation, "jre7")); // setting the localsource path tomcatlocation to the environment variable catalina_home newProc.StartInfo.EnvironmentVariables.Add("ES_DATA", Path.Combine(Path.Combine(cacheLocation, "ElasticStorage"), "data")); newProc.StartInfo.EnvironmentVariables.Add("ES_HOSTS", workerIPs); // setting the file name bin\startup.bat in tomcatlocation of localresourcepath newProc.StartInfo.FileName = Path.Combine(esLocation, Settings.ElasticStartApp); DiagnosticsHelper.TraceInformation("ElasticSearch start command line: " + newProc.StartInfo.FileName); // starting process newProc.Start(); DiagnosticsHelper.TraceInformation("Done - Starting ElasticSearch"); newProc.OutputDataReceived += processToExecuteCommand_OutputDataReceived; newProc.ErrorDataReceived += processToExecuteCommand_ErrorDataReceived; newProc.BeginOutputReadLine(); newProc.BeginErrorReadLine(); newProc.Exited += Process_Exited; } catch (Exception ex) { // Logging the exceptiom DiagnosticsHelper.TraceError(ex.Message); throw; } return(newProc); }
private string GetElasticDataDirectory() { DiagnosticsHelper.TraceInformation("Getting db path"); var roleId = RoleEnvironment.CurrentRoleInstance.Id; var containerName = ContainerNameFromRoleId(roleId); var dataDrivePath = Utilities.GetMountedPathFromBlob( Constants.LocalCacheSetting, containerName, Constants.ElasticSearchBlobName, Settings.DefaultDriveSize, out _elasticStorageDrive); DiagnosticsHelper.TraceInformation("Obtained data drive as {0}", dataDrivePath); return(dataDrivePath); }
public void Dispose() { try { if (_elasticStorageDrive != null) { DiagnosticsHelper.TraceInformation("Unmount called on data drive"); _elasticStorageDrive.Unmount(); } DiagnosticsHelper.TraceInformation("Unmount completed on data drive"); } catch (Exception e) { //Ignore any and all exceptions here DiagnosticsHelper.TraceWarning( "Exception in onstop - unmount failed with {0} {1}", e.Message, e.StackTrace); } }
private void CreateElasticStoragerDirs(String vhdPath) { DiagnosticsHelper.TraceInformation("ElasticSearch - creating Cache Directories, path=" + vhdPath); var elasticStorageDir = Path.Combine(vhdPath, "ElasticStorage"); var elasticDataDir = Path.Combine(elasticStorageDir, "data"); DiagnosticsHelper.TraceInformation("ElasticSearch - elasticStorageDir=" + elasticStorageDir); DiagnosticsHelper.TraceInformation("ElasticSearch - elasticDataDir=" + elasticDataDir); if (Directory.Exists(elasticStorageDir) == false) { Directory.CreateDirectory(elasticStorageDir); } if (Directory.Exists(elasticDataDir) == false) { Directory.CreateDirectory(elasticDataDir); } DiagnosticsHelper.TraceInformation("ElasticSearch - done creating Cache Directories, path=" + vhdPath); }
private void ConfigureElasticSearch() { try { // Initializing RunES _elastic = new RunES(); var workerIPs = ListWorkerRoles(); DiagnosticsHelper.TraceInformation("OnStart workerIPs: " + workerIPs); DiagnosticsHelper.TraceInformation("OnStart CacheLocation: " + Settings.CacheDir); _process = _elastic.StartES(Settings.CacheDir, Settings.DefaultElasticPort, workerIPs); } catch (Exception ex) { DiagnosticsHelper.TraceInformation(ex.Message + " " + ex.StackTrace); DiagnosticsHelper.TraceError(ex.Message + " " + ex.StackTrace); Trace.Flush(); throw new ApplicationException("Can't configure Elastic Search: " + ex.Message); } }
public override void OnStop() { DiagnosticsHelper.TraceInformation("ElasticWorkerRole OnStop() called", "Information"); if (_process != null) { try { _process.Kill(); _process.WaitForExit(2000); } catch { } } if (_elastic != null) { _elastic.Dispose(); } base.OnStop(); }
void Process_Exited(object sender, EventArgs e) { DiagnosticsHelper.TraceInformation("ElasticSearch Exited"); RoleEnvironment.RequestRecycle(); }
internal static string GetMountedPathFromBlob( string localCachePath, string containerName, string blobName, int driveSize, out CloudDrive elasticDrive) { DiagnosticsHelper.TraceInformation( "In mounting cloud drive for on {0} with {1}", containerName, blobName); var connectionString = RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"); connectionString = connectionString.Replace("DefaultEndpointsProtocol=https", "DefaultEndpointsProtocol=http"); var storageAccount = CloudStorageAccount.Parse(connectionString); var blobClient = storageAccount.CreateCloudBlobClient(); DiagnosticsHelper.TraceInformation("Get container"); // this should be the name of your replset var driveContainer = blobClient.GetContainerReference(containerName); // create blob container (it has to exist before creating the cloud drive) try { driveContainer.CreateIfNotExist(); } catch (StorageException e) { DiagnosticsHelper.TraceInformation( "Container creation failed with {0} {1}", e.Message, e.StackTrace); } var blobUri = blobClient.GetContainerReference(containerName).GetPageBlobReference(blobName).Uri.ToString(); DiagnosticsHelper.TraceInformation("Blob uri obtained {0}", blobUri); // create the cloud drive elasticDrive = storageAccount.CreateCloudDrive(blobUri); try { elasticDrive.CreateIfNotExist(driveSize); } catch (CloudDriveException e) { DiagnosticsHelper.TraceInformation( "Drive creation failed with {0} {1}", e.Message, e.StackTrace); } DiagnosticsHelper.TraceInformation("Initialize cache"); var localStorage = RoleEnvironment.GetLocalResource(localCachePath); CloudDrive.InitializeCache(localStorage.RootPath.TrimEnd('\\'), localStorage.MaximumSizeInMegabytes); // mount the drive and get the root path of the drive it's mounted as try { DiagnosticsHelper.TraceInformation( "Trying to mount blob as azure drive"); var driveLetter = elasticDrive.Mount(localStorage.MaximumSizeInMegabytes, DriveMountOptions.None); DiagnosticsHelper.TraceInformation( "Write lock acquired on azure drive, mounted as {0}", driveLetter); return driveLetter; } catch (CloudDriveException e) { DiagnosticsHelper.TraceCritical( "Failed to mount cloud drive with {0} {1}", e.Message, e.StackTrace); throw; } }