Exemple #1
0
        private static String CreateSolrStorageVhd()
        {
            CloudStorageAccount storageAccount;
            LocalResource       localCache;
            CloudBlobClient     client;
            CloudBlobContainer  drives;

            localCache = RoleEnvironment.GetLocalResource("AzureDriveCache");
            Log(String.Format(CultureInfo.InvariantCulture, "AzureDriveCache {0} {1} MB", localCache.RootPath, localCache.MaximumSizeInMegabytes - 50), "Information");
            CloudDrive.InitializeCache(localCache.RootPath.TrimEnd('\\'), localCache.MaximumSizeInMegabytes - 50);

            storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));
            client         = storageAccount.CreateCloudBlobClient();

            string roleId           = RoleEnvironment.CurrentRoleInstance.Id;
            string containerAddress = ContainerNameFromRoleId(roleId);

            drives = client.GetContainerReference(containerAddress);

            try { drives.CreateIfNotExist(); }
            catch (StorageClientException) { };

            string vhdName = string.Format(CultureInfo.InvariantCulture, "SolrStorage_{0}.vhd", RoleEnvironment.GetConfigurationSettingValue("SolrMajorVersion"));
            var    vhdUrl  = client.GetContainerReference(containerAddress).GetBlobReference(vhdName).Uri.ToString();

            Log(String.Format(CultureInfo.InvariantCulture, "{0} {1}", vhdName, vhdUrl), "Information");
            _solrStorageDrive = storageAccount.CreateCloudDrive(vhdUrl);

            int cloudDriveSizeInMB = int.Parse(RoleEnvironment.GetConfigurationSettingValue("CloudDriveSize"), CultureInfo.InvariantCulture);

            try { _solrStorageDrive.Create(cloudDriveSizeInMB); }
            catch (CloudDriveException) { }

            Log(String.Format(CultureInfo.InvariantCulture, "CloudDriveSize {0} MB", cloudDriveSizeInMB), "Information");

            var dataPath = _solrStorageDrive.Mount(localCache.MaximumSizeInMegabytes - 50, DriveMountOptions.Force);

            Log(String.Format(CultureInfo.InvariantCulture, "Mounted as {0}", dataPath), "Information");

            return(dataPath);
        }
Exemple #2
0
        public UnsubscribeController()
        {
            var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            // If this is running in a Windows Azure Web Site (not a Cloud Service) use the Web.config file:
            //    var storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);

            // Get context object for working with tables.
            var tableClient = storageAccount.CreateCloudTableClient();

            mailingListTable = tableClient.GetTableReference("mailinglist");
        }
Exemple #3
0
        /// <summary>
        /// This is where we get the role instance configured and ready to begin processing
        /// STAHC jobs
        /// </summary>
        /// <returns>True if succesfully configured. False otherwise</returns>
        public override bool OnStart()
        {
            ServicePointManager.DefaultConnectionLimit = 64;

            DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();

            config.PerformanceCounters.DataSources.Add(
                new PerformanceCounterConfiguration()
            {
                CounterSpecifier = @"\Processor(_Total)\% Processor Time",
                SampleRate       = TimeSpan.FromSeconds(30)
            });

            config.PerformanceCounters.DataSources.Add(
                new PerformanceCounterConfiguration()
            {
                CounterSpecifier = @"\Network Interface(*)\Bytes Total/sec",
                SampleRate       = TimeSpan.FromSeconds(30)
            });

            config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod         = System.TimeSpan.FromMinutes(5);
            config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Error;
            config.Logs.ScheduledTransferPeriod                = System.TimeSpan.FromMinutes(5);
            config.Logs.ScheduledTransferLogLevelFilter        = LogLevel.Verbose;
            config.PerformanceCounters.ScheduledTransferPeriod = System.TimeSpan.FromMinutes(1);
            config.WindowsEventLog.ScheduledTransferPeriod     = System.TimeSpan.FromMinutes(5);

            DiagnosticMonitor.Start("DiagnosticsConnectionString", config);

            // restart the role upon all configuration changes
            RoleEnvironment.Changing += RoleEnvironmentChanging;

            // read storage account configuration settings
            CloudStorageAccount.SetConfigurationSettingPublisher((configName, configSetter) =>
            {
                configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
            });

            // get the scratch path
            scratchPath = RoleEnvironment.GetLocalResource(Constants.AzureScratchName).RootPath;

            // get the time to sleep between runs of the queue monitoring loop
            queueSleepTime = int.Parse(
                RoleEnvironment.GetConfigurationSettingValue("QueueSleepTime"),
                CultureInfo.InvariantCulture);

            // get the max time (seconds) that the server should take to process a queue job
            maxJobLength = int.Parse(
                RoleEnvironment.GetConfigurationSettingValue("MaxJobLength"),
                CultureInfo.InvariantCulture);

            // get the storage container to be used for processing job data
            jobContainer = RoleEnvironment.GetConfigurationSettingValue("JobContainer");

            // get queue data/configuration
            storageAccount = CloudStorageAccount.FromConfigurationSetting("DataConnectionString");

            // get the name of the queue used for this job set
            var queueName = RoleEnvironment.GetConfigurationSettingValue("StachQueueName");

            // get the queues
            CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();

            queueStorage.RetryPolicy = RetryPolicies.RetryExponential(3, TimeSpan.FromSeconds(10));

            stahcJobQueue = queueStorage.GetQueueReference(queueName);
            stahcJobQueue.CreateIfNotExist();

            // report on read values
            Trace.WriteLine(string.Format("QueueSleepTime: '{0}'",
                                          queueSleepTime.ToString(CultureInfo.InvariantCulture)), "Verbose");
            Trace.WriteLine(string.Format("MaxJobLength: '{0}'",
                                          maxJobLength.ToString(CultureInfo.InvariantCulture)), "Verbose");
            Trace.WriteLine(string.Format("JobContainer: '{0}'", jobContainer), "Verbose");
            Trace.WriteLine(string.Format("StachQueueName: '{0}'", queueName), "Verbose");

            // read-in/download all source files
            DownloadStagingFiles();

            // loop through and execute each of the actions (if any) provided in the staging file
            var stagingControlFile = Path.Combine(
                scratchPath,
                Constants.StagingActionsFileName);

            if (File.Exists(stagingControlFile))
            {
                var sucessful = RunStagingActions(stagingControlFile);

                if (!sucessful)
                {
                    Trace.TraceError(
                        "Unable to complete staging actions. Review logs for more detail.");
                    return(sucessful);
                }
            }

            return(base.OnStart());
        }
Exemple #4
0
 private BrightstarCluster()
 {
     try
     {
         CloudStorageAccount.SetConfigurationSettingPublisher((key, publisher) => publisher(RoleEnvironment.GetConfigurationSettingValue(key)));
         _clients = new List <Tuple <string, IStoreWorkerService> >();
         UpdateClientList();
         var storageAccount = CloudStorageAccount.FromConfigurationSetting(AzureConstants.BlockStoreConnectionStringName);
         _blobClient = storageAccount.CreateCloudBlobClient();
         RoleEnvironment.Changing += HandleRoleEnvironmentChanging;
         _jobQueue =
             new SqlJobQueue(
                 RoleEnvironment.GetConfigurationSettingValue(AzureConstants.ManagementDatabaseConnectionStringName),
                 RoleEnvironment.CurrentRoleInstance.Id);
     }
     catch (Exception ex)
     {
         Trace.TraceError("Error initializing BrightstarCluster: {0}", ex);
     }
 }
        public bool Initialize()
        {
            Trace.TraceInformation("HybrisPlugin: Initializing.");
            this.Status        = AzurePluginStatus.Initializing;
            this.StatusMessage = string.Empty;

            // 1. create necessary directories for usage by hybris
            #region Directories
            string workBaseDirectory = null;
            try
            {
                workBaseDirectory = RoleEnvironment.GetLocalResource("HybrisOnAzure.WorkBase").RootPath;
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error initializing: Could not retrieve local resource for workBaseDirectory. " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error initializing: Could not retrieve local resource for workBaseDirectory. ";
                return(false);
            }

            //    a directory for "working" purposes mapped to a drive letter
            string workDrive = null;
            try
            {
                Trace.TraceInformation("HybrisPlugin: Initializing work-Drive.");
                if (!Directory.Exists(Path.Combine(workBaseDirectory, "work")))
                {
                    Directory.CreateDirectory(Path.Combine(workBaseDirectory, "work"));
                }
                workDrive = DrivePathManager.Map(Path.Combine(workBaseDirectory, "work"), "Work");
                if (!workDrive.EndsWith("\\"))
                {
                    workDrive = workDrive + "\\";
                }
                Trace.TraceInformation("HybrisPlugin: mapped work directory to " + workDrive);
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error initializing: Could not map work drive. " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error initializing: Could not map work drive.";
                return(false);
            }

            //    a directory for "temp" purposes mapped to a drive letter
            string tempDrive = null;
            try
            {
                Trace.TraceInformation("HybrisPlugin: Initializing temp-Drive.");
                if (!Directory.Exists(Path.Combine(workBaseDirectory, "temp")))
                {
                    Directory.CreateDirectory(Path.Combine(workBaseDirectory, "temp"));
                }
                tempDrive = DrivePathManager.Map(Path.Combine(workBaseDirectory, "temp"), "Temp");
                if (!tempDrive.EndsWith("\\"))
                {
                    tempDrive = tempDrive + "\\";
                }
                Trace.TraceInformation("HybrisPlugin: mapped temp directory to " + tempDrive);
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error initializing: Could not map temp drive. " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error initializing: Could not map temp drive.";
                return(false);
            }

            //    a directory for "data" purposes mapped to a drive letter
            string dataDrive = null;
            try
            {
                Trace.TraceInformation("HybrisPlugin: Initializing data-Drive.");
                if (!Directory.Exists(Path.Combine(workBaseDirectory, "data")))
                {
                    Directory.CreateDirectory(Path.Combine(workBaseDirectory, "data"));
                }
                dataDrive = DrivePathManager.Map(Path.Combine(workBaseDirectory, "data"), "Data");
                if (!dataDrive.EndsWith("\\"))
                {
                    dataDrive = dataDrive + "\\";
                }
                Trace.TraceInformation("HybrisPlugin: mapped data directory to " + dataDrive);
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error initializing: Could not map data drive. " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error initializing: Could not map data drive.";
                return(false);
            }
            #endregion
            #region Subdirectories for direct use by hybris
            Trace.TraceInformation("HybrisPlugin: Initializing subdirectories.");
            string hybrisWorkDirectory = null;
            string hybrisTempDirectory = null;
            string sharedTempDirectory = null;
            string hybrisDataDirectory = null;
            string hybrisLogsDirectory = null;
            try
            {
                // Work Directory = Z:\hybris
                hybrisWorkDirectory = Path.Combine(workDrive, "hybris");
                if (!Directory.Exists(hybrisWorkDirectory))
                {
                    Directory.CreateDirectory(hybrisWorkDirectory);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Could not create directory " + hybrisWorkDirectory + ": " + ex.ToString());
            }
            try
            {
                // Temp Directory = Y:\hybris
                hybrisTempDirectory = Path.Combine(tempDrive, "hybris");
                if (!Directory.Exists(hybrisTempDirectory))
                {
                    Directory.CreateDirectory(hybrisTempDirectory);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Could not create directory " + hybrisTempDirectory + ": " + ex.ToString());
            }
            try
            {
                // Shared Temp Directory = Y:\shared
                sharedTempDirectory = Path.Combine(tempDrive, "shared");
                if (!Directory.Exists(sharedTempDirectory))
                {
                    Directory.CreateDirectory(sharedTempDirectory);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Could not create directory " + sharedTempDirectory + ": " + ex.ToString());
            }
            try
            {
                // Data Directory = S:\hybris on BackOfficeWorker, X:\hybris otherwise
                if (IsBackOfficeWorker)
                {
                    var driveLetter = hybrisDataDirectory = RoleEnvironment.GetConfigurationSettingValue("HybrisOnAzure.BackOfficeShare.DesiredDrive");
                    if (!driveLetter.EndsWith("\\"))
                    {
                        driveLetter = driveLetter + "\\";
                    }
                    hybrisDataDirectory = Path.Combine(driveLetter, "hybris");
                }

                else
                {
                    hybrisDataDirectory = Path.Combine(dataDrive, "hybris");
                }
                if (!Directory.Exists(hybrisDataDirectory))
                {
                    Directory.CreateDirectory(hybrisDataDirectory);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Could not create directory " + hybrisDataDirectory + ": " + ex.ToString());
            }
            try
            {
                // Logs Directory = X:\Logs\hybris
                hybrisLogsDirectory = Path.Combine(dataDrive, "logs", "hybris");
                if (!Directory.Exists(hybrisLogsDirectory))
                {
                    Directory.CreateDirectory(hybrisLogsDirectory);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Could not create directory " + hybrisLogsDirectory + ": " + ex.ToString());
            }
            #endregion


            // 2. Build hybris configuration files
            #region Calculates instance numbers
            string role       = "";
            string rolenumber = "";
            Trace.TraceInformation("HybrisPlugin: Calculate instance numbers.");
            try
            {
                // This will have values like "BackOfficeWorker_IN_0" or "FrontendWorker_IN_0"
                string instanceName = RoleEnvironment.CurrentRoleInstance.Id;
                if (!string.IsNullOrEmpty(instanceName) && instanceName.Contains('_'))
                {
                    role = instanceName.Split('_').FirstOrDefault();
                    if (!string.IsNullOrEmpty(role))
                    {
                        role = role.ToLower();
                    }
                    try
                    {
                        int _rolenumber = Convert.ToInt32(instanceName.Split('_').LastOrDefault());
                        rolenumber = _rolenumber.ToString(CultureInfo.InvariantCulture);
                    }
                    catch (FormatException)
                    {
                        // do nothing
                    }
                    catch (OverflowException)
                    {
                        // do nothing
                    }
                }
                if (string.IsNullOrEmpty(role))
                {
                    role = "unknown";
                }
                if (string.IsNullOrEmpty(rolenumber))
                {
                    rolenumber = "0";
                }
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error calculating role numbers: " + ex.Message);
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error calculating role numbers";
                return(false);
            }
            #endregion

            #region local.properties file
            // Build hybris configuration user.properties file
            Trace.TraceInformation("HybrisPlugin: Updating local.properties file.");
            string hybrisRoot             = Path.Combine(BaseDirectory, "hybris");
            string hybrisWorkingDirectory = Path.Combine(hybrisRoot, "bin", "platform");
            try
            {
                string userPropertiesFile        = Path.Combine(hybrisRoot, "config", "local.properties");
                string userPropertiesFileContent = System.IO.File.Exists(userPropertiesFile) ? System.IO.File.ReadAllText(userPropertiesFile) : string.Empty;

                // Set the tomcat TCP port and binding information
                IPEndPoint tomcatHttpIPEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TomcatHttp"].IPEndpoint;
                userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "tomcat.http.listenaddress", tomcatHttpIPEndpoint.Address.ToString());
                userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "tomcat.http.port", tomcatHttpIPEndpoint.Port.ToString(CultureInfo.InvariantCulture));
                IPEndPoint tomcatHttpsIPEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["TomcatHttps"].IPEndpoint;
                userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "tomcat.https.listenaddress", tomcatHttpsIPEndpoint.Address.ToString());
                userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "tomcat.https.port", tomcatHttpsIPEndpoint.Port.ToString(CultureInfo.InvariantCulture));

                // Set the JGroups TCP port and binding information
                IPEndPoint invalidationIPEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["InvalidateJGroup"].IPEndpoint;
                userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "cluster.broadcast.method.jgroups.tcp.bind_addr", invalidationIPEndpoint.Address.ToString());
                userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "cluster.broadcast.method.jgroups.tcp.bind_port", invalidationIPEndpoint.Port.ToString(CultureInfo.InvariantCulture));

                // Set the cluster id and node id
                // For a FrontendWorker, the cluster ID is calculated based on its IP Address (whilst the BackOfficeWorker has the ClusterId 0)
                //       See FrontendHybrisPlugin.cs Line 111
                IPAddress managementEndpointAddress = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Management"].IPEndpoint.Address;
                byte[]    addressBytes = managementEndpointAddress.GetAddressBytes();
                int       clusterId    = IsBackOfficeWorker ? 0 : addressBytes[addressBytes.Length - 1];

                userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "cluster.maxid", "256");
                userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "cluster.id", clusterId.ToString(CultureInfo.InvariantCulture));
                userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "node.id", clusterId.ToString(CultureInfo.InvariantCulture));


                // Change media.default.url.strategy when being on backoffice worker
                if (RoleEnvironment.CurrentRoleInstance.Role.Name.ToLower().Contains("backoffice"))
                {
                    //userPropertiesFileContent = PatchProperty(userPropertiesFileContent, "media.default.url.strategy", "windowsAzureBlobURLStrategy");
                }

                // Update work path settings
                userPropertiesFileContent = userPropertiesFileContent.Replace(@"{instanceworkdir}", hybrisWorkDirectory.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)); // INFO: Was instanceWorkDirectory
                userPropertiesFileContent = userPropertiesFileContent.Replace(@"{workdir}", hybrisWorkDirectory.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
                userPropertiesFileContent = userPropertiesFileContent.Replace(@"{logsdir}", hybrisLogsDirectory.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
                userPropertiesFileContent = userPropertiesFileContent.Replace(@"{datadir}", hybrisDataDirectory.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));
                userPropertiesFileContent = userPropertiesFileContent.Replace(@"{tempdir}", hybrisTempDirectory.Replace(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar));

                // Update the user.properties file
                File.WriteAllText(userPropertiesFile, userPropertiesFileContent);
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error creating user.properties file: " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error creating user.properties file";
                return(false);
            }
            #endregion

            // 3. Create hybris commands
            #region build command
            // Read the standard PATH environment variable
            string searchPath = Environment.GetEnvironmentVariable("path", EnvironmentVariableTarget.Machine);

            string hybrisBuildCommandFileName = Path.Combine(hybrisWorkingDirectory, "hybris-build.cmd");
            try
            {
                Trace.TraceInformation("HybrisPlugin: Create hybris build command.");

                // Build hybris build command
                var hybrisBuildCommandBuilder = new StringBuilder();
                hybrisBuildCommandBuilder.AppendLine(@"@echo off");
                hybrisBuildCommandBuilder.AppendLine(@"set path=" + Path.Combine(JavaHomeDirectory, @"bin") + ";" + searchPath);
                hybrisBuildCommandBuilder.AppendLine(@"set java_home=" + JavaHomeDirectory);
                hybrisBuildCommandBuilder.AppendLine(@"set temp=" + sharedTempDirectory);
                hybrisBuildCommandBuilder.AppendLine(@"set tmp=" + sharedTempDirectory);
                hybrisBuildCommandBuilder.AppendLine();
                hybrisBuildCommandBuilder.AppendLine(@"set HYBRIS_DATA_DIR=" + hybrisDataDirectory);
                hybrisBuildCommandBuilder.AppendLine(@"set HYBRIS_TEMP_DIR=" + hybrisTempDirectory);
                hybrisBuildCommandBuilder.AppendLine(@"set HYBRIS_WORK_DIR=" + hybrisWorkDirectory);
                hybrisBuildCommandBuilder.AppendLine(@"set HYBRIS_LOG_DIR=" + hybrisLogsDirectory);
                hybrisBuildCommandBuilder.AppendLine(@"set HYBRIS_LOGS_DIR=" + hybrisLogsDirectory);
                hybrisBuildCommandBuilder.AppendLine();
                hybrisBuildCommandBuilder.AppendLine(@"cd " + hybrisWorkingDirectory);
                hybrisBuildCommandBuilder.AppendLine(@"call setantenv.bat");
                hybrisBuildCommandBuilder.AppendLine();
                //hybrisBuildCommandBuilder.AppendLine(@"cd " + Path.Combine(hybrisWorkingDirectory, @"..\..\build"));
                //hybrisBuildCommandBuilder.AppendLine(@"call ant config -Denv=" + DeploymentName + " -Drole=" + RoleName + " -Drolenumber=" + rolenumber);
                //hybrisBuildCommandBuilder.AppendLine();
                //hybrisBuildCommandBuilder.AppendLine(@"cd " + hybrisWorkingDirectory);
                hybrisBuildCommandBuilder.AppendLine(@"call ant");
                File.WriteAllText(hybrisBuildCommandFileName, hybrisBuildCommandBuilder.ToString());
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error creating hybris build command: " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error creating hybris build command";
                return(false);
            }
            #endregion

            #region start command
            // Build hybris start command
            string hybrisStartCommandFileName = Path.Combine(hybrisWorkingDirectory, "hybris-start.cmd");
            try
            {
                Trace.TraceInformation("HybrisPlugin: Generate hybris start command");
                var hybrisStartCommandBuilder = new StringBuilder();
                hybrisStartCommandBuilder.AppendLine(@"@echo off");
                hybrisStartCommandBuilder.AppendLine(@"set path=" + Path.Combine(JavaHomeDirectory, @"bin") + ";" + searchPath);
                hybrisStartCommandBuilder.AppendLine(@"set java_home=" + JavaHomeDirectory);
                hybrisStartCommandBuilder.AppendLine(@"set temp=" + sharedTempDirectory);
                hybrisStartCommandBuilder.AppendLine(@"set tmp=" + sharedTempDirectory);
                hybrisStartCommandBuilder.AppendLine();
                hybrisStartCommandBuilder.AppendLine(@"set HYBRIS_DATA_DIR=" + hybrisDataDirectory);
                hybrisStartCommandBuilder.AppendLine(@"set HYBRIS_TEMP_DIR=" + hybrisTempDirectory);
                hybrisStartCommandBuilder.AppendLine(@"set HYBRIS_WORK_DIR=" + hybrisWorkDirectory);
                hybrisStartCommandBuilder.AppendLine(@"set HYBRIS_LOG_DIR=" + hybrisLogsDirectory);
                hybrisStartCommandBuilder.AppendLine(@"set HYBRIS_LOGS_DIR=" + hybrisLogsDirectory);
                hybrisStartCommandBuilder.AppendLine();
                hybrisStartCommandBuilder.AppendLine(@"cd " + hybrisWorkingDirectory);
                hybrisStartCommandBuilder.AppendLine(@"call setantenv.bat");
                hybrisStartCommandBuilder.AppendLine(@"call hybrisserver.bat");
                File.WriteAllText(hybrisStartCommandFileName, hybrisStartCommandBuilder.ToString());
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error creating hybris start command: " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error creating hybris start command";
                return(false);
            }
            #endregion

            #region stop command
            // Build hybris stop command
            string hybrisStopCommandFileName = Path.Combine(hybrisWorkingDirectory, "hybris-stop.cmd");

            try
            {
                Trace.TraceInformation("HybrisPlugin: Generating hybris stop command");

                var hybrisStopCommandBuilder = new StringBuilder();
                hybrisStopCommandBuilder.AppendLine(@"@echo off");
                hybrisStopCommandBuilder.AppendLine(@"set path=" + Path.Combine(JavaHomeDirectory, @"bin") + ";" + searchPath);
                hybrisStopCommandBuilder.AppendLine(@"set java_home=" + JavaHomeDirectory);
                hybrisStopCommandBuilder.AppendLine(@"set temp=" + sharedTempDirectory);
                hybrisStopCommandBuilder.AppendLine(@"set tmp=" + sharedTempDirectory);
                hybrisStopCommandBuilder.AppendLine();
                hybrisStopCommandBuilder.AppendLine(@"set HYBRIS_DATA_DIR=" + hybrisDataDirectory);
                hybrisStopCommandBuilder.AppendLine(@"set HYBRIS_TEMP_DIR=" + hybrisTempDirectory);
                hybrisStopCommandBuilder.AppendLine(@"set HYBRIS_WORK_DIR=" + hybrisWorkDirectory);
                hybrisStopCommandBuilder.AppendLine(@"set HYBRIS_LOG_DIR=" + hybrisLogsDirectory);
                hybrisStopCommandBuilder.AppendLine(@"set HYBRIS_LOGS_DIR=" + hybrisLogsDirectory);
                hybrisStopCommandBuilder.AppendLine();
                hybrisStopCommandBuilder.AppendLine(@"cd " + hybrisWorkingDirectory);
                hybrisStopCommandBuilder.AppendLine(@"java -jar StopTanukiWrapper.jar");
                File.WriteAllText(hybrisStopCommandFileName, hybrisStopCommandBuilder.ToString());
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error creating hybris stop command: " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error creating hybris stop command";
                return(false);
            }
            #endregion

            // 4. TanukiWrapper
            #region Tanuki wrapper
            Trace.TraceInformation("HybrisPlugin: Installing StopTanukiWrapper.jar");
            try
            {
                // Save the required StopTanukiWrapper.jar file in the platform directory
                string stopTanukiWrapperFileName = Path.Combine(hybrisWorkingDirectory, "StopTanukiWrapper.jar");
                File.WriteAllBytes(stopTanukiWrapperFileName, hybrisOnAzure.Common.Properties.Resources.StopTanukiWrapper);
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error installing StopTanukiWrapper.jar: " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error installing StopTanukiWrapper.jar";
                return(false);
            }
            #endregion

            // 5. actually build the hybris platform
            #region Build hybris
            // Build hybris platform
            Trace.TraceInformation("HybrisPlugin: Building hybris platform.");
            try
            {
                var buildOutput = new StringBuilder();
                var buildError  = new StringBuilder();
                using (var buildProcess = new System.Diagnostics.Process
                {
                    StartInfo = new System.Diagnostics.ProcessStartInfo
                    {
                        WorkingDirectory = hybrisWorkingDirectory,
                        FileName = hybrisBuildCommandFileName,
                        Arguments = string.Empty,
                        UseShellExecute = false,
                        LoadUserProfile = false,
                        RedirectStandardOutput = true,
                        RedirectStandardError = true,
                        RedirectStandardInput = true,
                        CreateNoWindow = true,
                        WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
                    },
                    EnableRaisingEvents = true,
                })
                {
                    buildProcess.OutputDataReceived += (s, a) => Trace.TraceVerbose("HybrisPlugin: Building hybris ouput line" + a.Data);
                    buildProcess.ErrorDataReceived  += (s, a) => Trace.TraceAndLogError("HybrisPlugin", "Building hybris error line" + a.Data);

                    if (buildProcess.Start())
                    {
                        buildProcess.BeginOutputReadLine();
                        buildProcess.BeginErrorReadLine();
                        buildProcess.WaitForExit();
                    }

                    if (buildProcess.ExitCode == 0)
                    {
                        Trace.TraceAndLogInformation("HybrisPlugin", "Successfully built hybris platform.");
                    }
                    else
                    {
                        Trace.TraceAndLogError("HybrisPlugin", "Error executing build hybris platform command.");
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("Hybris", "Error building hybris platform. " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error building hybris platform.";
                return(false);
            }
            #endregion

            // 6. Get from additional settings if we may start the hybris process
            #region Additional configuration
            AdditionalConfigurationManager.Instance.AdditionalConfigurationChanged += Instance_AdditionalConfigurationChanged;
            try
            {
                Trace.TraceInformation("HybrisPlugin: Processing initial additional configuration.");
                AdditionalConfigurationManager.Instance.ProcessConfiguration();
                Trace.TraceInformation("HybrisPlugin: Successfully processed initial additional configuration.");
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error processing initial additional configuration: " + ex.ToString());
            }
            try
            {
                Trace.TraceInformation("HybrisPlugin", "Determining if Hybris was stopped before a reboot.");
                var stopHybris = AdditionalConfigurationManager.Instance.GetCurrentConfigurationValue("StopHybris");
                if (stopHybris == null)
                {
                    Trace.TraceAndLogWarning("HybrisPlugin", "Determining if Hybris was stopped before a reboot resulted in a NULL value. Hybris will be started.");
                }
                else
                {
                    Trace.TraceInformation("HybrisPlugin: Determining if Hybris was stopped before a reboot resulted in: " + stopHybris);
                    this.ConfigStopHybris = bool.Parse(stopHybris);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceAndLogError("HybrisPlugin", "Error getting from Additional configuration if processes are to be started: " + ex.ToString());
                this.Status        = AzurePluginStatus.ErrorInitializing;
                this.StatusMessage = "Error getting Additional configuration";
                return(false);
            }
            #endregion

            Trace.TraceInformation("HybrisPlugin: Initialization done.");
            this.Status        = AzurePluginStatus.NotStarted;
            this.StatusMessage = string.Empty;
            return(true);
        }
Exemple #6
0
        public override void Run()
        {
            var storageAccount = CloudStorageAccount.Parse
                                     (RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

            // Get table and queue objects for working with tables and queues.

            while (!IsStopped)
            {
                try
                {
                    // Receive the message
                    BrokeredMessage receivedMessage = null;
                    receivedMessage = Client.Receive();

                    if (receivedMessage != null)
                    {
                        // Process the message
                        Trace.WriteLine("Processing", receivedMessage.SequenceNumber.ToString());
                        NewCustomerCommand command = receivedMessage.GetBody <NewCustomerCommand>();
                        // Create the table client.
                        CloudTableClient tableClient = storageAccount.CreateCloudTableClient();

                        // Create the CloudTable object that represents the "Customer" table.
                        CloudTable table = tableClient.GetTableReference("Customer");

                        // Create a new customer entity.
                        Customer customer = new Customer {
                            Id           = Guid.NewGuid().ToString(),
                            PartitionKey = command.LastName,
                            RowKey       = command.FirstName,
                            FirstName    = command.FirstName,
                            LastName     = command.LastName,
                            Address      = command.Address,
                            Email        = command.Email,
                            Phone        = command.Phone
                        };

                        // Create the TableOperation that inserts the customer entity.
                        TableOperation insertOperation = TableOperation.Insert(customer);

                        // Execute the insert operation.
                        table.Execute(insertOperation);
                        receivedMessage.Complete();
                    }
                }
                catch (MessagingException e)
                {
                    if (!e.IsTransient)
                    {
                        Trace.WriteLine(e.Message);
                        throw;
                    }

                    Thread.Sleep(10000);
                }
                catch (OperationCanceledException e)
                {
                    if (!IsStopped)
                    {
                        Trace.WriteLine(e.Message);
                        throw;
                    }
                }
            }
        }
Exemple #7
0
        public override void Initialize(string name, NameValueCollection config)
        {
            // Verify that config isn't null
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            // Assign the provider a default name if it doesn't have one
            if (String.IsNullOrEmpty(name))
            {
                name = "TableServiceSessionStateProvider";
            }

            // Add a default "description" attribute to config if the
            // attribute doesn't exist or is empty
            if (string.IsNullOrEmpty(config["description"]))
            {
                config.Remove("description");
                config.Add("description", "Session state provider using table storage");
            }

            // Call the base class's Initialize method
            base.Initialize(name, config);

            bool allowInsecureRemoteEndpoints = Configuration.GetBooleanValue(config, "allowInsecureRemoteEndpoints", false);

            // structure storage-related properties
            _applicationName = Configuration.GetStringValueWithGlobalDefault(config, "applicationName",
                                                                             Configuration.DefaultProviderApplicationNameConfigurationString,
                                                                             Configuration.DefaultProviderApplicationName, false);

            _account =
                CloudStorageAccount.Parse(
                    RoleEnvironment.GetConfigurationSettingValue(Configuration.ConfigurationStorageConnectionStringName));

            _tableName = Configuration.GetStringValueWithGlobalDefault(config, "sessionTableName",
                                                                       Configuration.DefaultSessionTableNameConfigurationString,
                                                                       Configuration.DefaultSessionTableName, false);

            _containerName = Configuration.GetStringValueWithGlobalDefault(config, "containerName",
                                                                           Configuration.DefaultSessionContainerNameConfigurationString,
                                                                           Configuration.DefaultSessionContainerName, false);
            if (!SecUtility.IsValidContainerName(_containerName))
            {
                throw new ProviderException("The provider configuration for the TableStorageSessionStateProvider does not contain a valid container name. " +
                                            "Please refer to the documentation for the concrete rules for valid container names." +
                                            "The current container name is: " + _containerName);
            }

            config.Remove("allowInsecureRemoteEndpoints");
            config.Remove("containerName");
            config.Remove("applicationName");
            config.Remove("sessionTableName");

            // Throw an exception if unrecognized attributes remain
            if (config.Count > 0)
            {
                string attr = config.GetKey(0);
                if (!String.IsNullOrEmpty(attr))
                {
                    throw new ProviderException
                              ("Unrecognized attribute: " + attr);
                }
            }

            if (_account == null)
            {
                throw new ConfigurationErrorsException("Account information incomplete!");
            }

            _tableStorage             = _account.CreateCloudTableClient();
            _tableStorage.RetryPolicy = _tableRetry;
            var _blobStorage = _account.CreateCloudBlobClient();

            try
            {
                SecUtility.CheckAllowInsecureEndpoints(allowInsecureRemoteEndpoints, _tableStorage.BaseUri);
                SecUtility.CheckAllowInsecureEndpoints(allowInsecureRemoteEndpoints, _blobStorage.BaseUri);

                if (_tableStorage.CreateTableIfNotExist(_tableName))
                {
                    var ctx      = _tableStorage.GetDataServiceContext();
                    var dummyRow = new SessionRow("fake", "dummy");
                    ctx.AddObject(_tableName, dummyRow);
                    ctx.SaveChangesWithRetries();
                    ctx.DeleteObject(dummyRow);
                    ctx.SaveChangesWithRetries();
                }
                _blobProvider = new BlobProvider(_blobStorage, _containerName);
            }
            catch (SecurityException)
            {
                throw;
            }
            // catch InvalidOperationException as well as StorageException
            catch (Exception e)
            {
                string exceptionDescription = Configuration.GetInitExceptionDescription(_blobStorage, _tableStorage);
                string tableName            = _tableName ?? "no session table name specified";
                string containerName        = _containerName ?? "no container name specified";
                Log.Write(EventKind.Error, "Initialization of data service structures (tables and/or blobs) failed!" +
                          exceptionDescription + Environment.NewLine +
                          "Configured blob container: " + containerName + Environment.NewLine +
                          "Configured table name: " + tableName + Environment.NewLine +
                          e.Message + Environment.NewLine + e.StackTrace);
                throw new ProviderException("Initialization of data service structures (tables and/or blobs) failed!" +
                                            "The most probable reason for this is that " +
                                            "the storage endpoints are not configured correctly. Please look at the configuration settings " +
                                            "in your .cscfg and Web.config files. More information about this error " +
                                            "can be found in the logs when running inside the hosting environment or in the output " +
                                            "window of Visual Studio.", e);
            }
            Debug.Assert(_blobProvider != null);
        }
        public override bool OnStart()
        {
            ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount * 12;

            ConfigureDiagnostics();
            Trace.TraceInformation("Initializing storage account in WorkerA");
            var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            sendEmailQueue = queueClient.GetQueueReference("azuremailqueue");
            var tableClient = storageAccount.CreateCloudTableClient();

            mailingListTable    = tableClient.GetTableReference("mailinglist");
            messageTable        = tableClient.GetTableReference("message");
            messagearchiveTable = tableClient.GetTableReference("messagearchive");

            // Create if not exists for queue, blob container, SentEmail table.
            sendEmailQueue.CreateIfNotExists();
            messageTable.CreateIfNotExists();
            mailingListTable.CreateIfNotExists();
            messagearchiveTable.CreateIfNotExists();

            return(base.OnStart());
        }
Exemple #9
0
        public override bool OnStart()
        {
            // Set the maximum number of concurrent connections
            ServicePointManager.DefaultConnectionLimit = 12;

            XmlConfigurator.Configure();
            ILog log = LogManager.GetLogger(typeof(WorkerRole));

            string wadConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
            CloudStorageAccount            storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue(wadConnectionString));
            RoleInstanceDiagnosticManager  roleInstanceDiagnosticManager = storageAccount.CreateRoleInstanceDiagnosticManager(RoleEnvironment.DeploymentId, RoleEnvironment.CurrentRoleInstance.Role.Name, RoleEnvironment.CurrentRoleInstance.Id);
            DiagnosticMonitorConfiguration config = roleInstanceDiagnosticManager.GetCurrentConfiguration();

            config.Logs.ScheduledTransferPeriod         = TimeSpan.FromMinutes(1D);
            config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Undefined;
            config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Warning;
            config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod         = TimeSpan.FromMinutes(1D);
            config.Directories.ScheduledTransferPeriod = TimeSpan.FromMinutes(1D);

            roleInstanceDiagnosticManager.SetCurrentConfiguration(config);


            PhotoTaskManager.Instance.Start();
            RenderTaskManager.Instance.Start();
            ProfileTaskManager.Instance.Start();
            StatUpdate.Instance.Start();

            return(base.OnStart());
        }
Exemple #10
0
        public override bool OnStart()
        {
            TelemetryConfiguration.Active.InstrumentationKey = RoleEnvironment.GetConfigurationSettingValue("Telemetry.AI.InstrumentationKey");
            TelemetryConfiguration.Active.TelemetryInitializers.Add(new ItemCorrelationTelemetryInitializer());
            ServicePointManager.DefaultConnectionLimit = Environment.ProcessorCount * 12;

            Trace.TraceInformation("Initializing storage account in worker role B");
            var storageAccount = Microsoft.WindowsAzure.Storage.CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));

            // Initialize queue storage
            Trace.TraceInformation("Creating queue client.");
            CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient();

            sendEmailQueue = queueClient.GetQueueReference("azuremailqueue");
            subscribeQueue = queueClient.GetQueueReference("azuremailsubscribequeue");

            // Initialize blob storage
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

            blobContainer = blobClient.GetContainerReference("azuremailblobcontainer");

            // Initialize table storage
            var tableClient = storageAccount.CreateCloudTableClient();

            mailingListTable    = tableClient.GetTableReference("mailinglist");
            messageTable        = tableClient.GetTableReference("message");
            messagearchiveTable = tableClient.GetTableReference("messagearchive");

            Trace.TraceInformation("WorkerB: Creating blob container, queue, tables, if they don't exist.");
            blobContainer.CreateIfNotExists();
            sendEmailQueue.CreateIfNotExists();
            subscribeQueue.CreateIfNotExists();
            this.messageTable.CreateIfNotExists();
            this.mailingListTable.CreateIfNotExists();
            this.messagearchiveTable.CreateIfNotExists();

            return(base.OnStart());
        }
Exemple #11
0
 public static string GetApiAddressByKey(string apiKey)
 {
     return(RoleEnvironment.IsAvailable
                 ? RoleEnvironment.GetConfigurationSettingValue(apiKey)
                 : ConfigurationManager.AppSettings[apiKey]);
 }
Exemple #12
0
        private static void SendSubscribeEmail(string subscriberGUID, Subscriber subscriber, MailingList mailingList)
        {
            var email = SendGrid.GetInstance();

            email.From = new MailAddress(mailingList.FromEmailAddress);
            email.AddTo(subscriber.EmailAddress);
            string subscribeURL = RoleEnvironment.GetConfigurationSettingValue("AzureMailServiceURL") +
                                  "/subscribe?id=" + subscriberGUID + "&listName=" + subscriber.ListName;

            email.Html = String.Format("<p>Click the link below to subscribe to {0}. " +
                                       "If you don't confirm your subscription, you won't be subscribed to the list.</p>" +
                                       "<a href=\"{1}\">Confirm Subscription</a>", mailingList.Description, subscribeURL);
            email.Text = String.Format("Copy and paste the following URL into your browser in order to subscribe to {0}. " +
                                       "If you don't confirm your subscription, you won't be subscribed to the list.\n" +
                                       "{1}", mailingList.Description, subscribeURL);
            email.Subject = "Subscribe to " + mailingList.Description;
            var credentials   = new NetworkCredential(RoleEnvironment.GetConfigurationSettingValue("SendGridUserName"), RoleEnvironment.GetConfigurationSettingValue("SendGridPassword"));
            var transportREST = Web.GetInstance(credentials);

            transportREST.Deliver(email);
        }
Exemple #13
0
 public TableErrorLog(IDictionary config)
 {
     _connectionString = (string)config["connectionString"] ?? RoleEnvironment.GetConfigurationSettingValue((string)config["connectionStringName"]);
     _entityList       = new AzureEntityList <ErrorEntity>(_connectionString, TableName);
 }
Exemple #14
0
 public EventHubPersistence(string path)
 {
     eventHubClient = EventHubClient.CreateFromConnectionString(
         RoleEnvironment.GetConfigurationSettingValue("Microsoft.ServiceBus.ConnectionString"),
         path);
 }
Exemple #15
0
 public AzureShellSettingsManager(IShellSettingsManagerEventHandler events)
     : this(CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString")), events)
 {
 }
Exemple #16
0
 static AppSettings()
 {
     Account = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("DataConnectionString"));
     RefreshAvailableEndpoints();
 }