private void UpdateJavaAndHybrisPackages(AdditionalConfiguration oldAddConfig, AdditionalConfiguration newAddConfig)
        {
            CloudStorageAccount storageAccount;
            if (!RoleEnvironment.IsAvailable)
                storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true;");
            else
                storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            var blobClient = storageAccount.CreateCloudBlobClient();

            var oldDefaultBackOfficeConfig = oldAddConfig.Roles.First(r => r.Name == "MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole").Instances.First(i => i.Id == "default");
            var currentJavaPackage = oldDefaultBackOfficeConfig.Configurations.Any(c => c.Name == "JavaPackage") ? oldDefaultBackOfficeConfig.Configurations.First(c => c.Name == "JavaPackage").Value : string.Empty;
            var currentHybrisPackage = oldDefaultBackOfficeConfig.Configurations.Any(c => c.Name == "HybrisPackage") ? oldDefaultBackOfficeConfig.Configurations.First(c => c.Name == "HybrisPackage").Value : string.Empty;

            var newJavaPackage = txtJavaPackage.Text;
            if (string.IsNullOrEmpty(newJavaPackage))
                throw new Exception("No Java Package defined.");
            if (!blobClient.BlobExists("deployment/JavaPackages/" + newJavaPackage))
                throw new Exception("Could not find java package at deployment/JavaPackages/" + newJavaPackage);

            var newHybrisPackage = txtHybrisPackage.Text;
            if (string.IsNullOrEmpty(newHybrisPackage))
                throw new Exception("No Hybris Package defined.");
            if (!blobClient.DirectoryExists("deployment/HybrisPackages/" + newHybrisPackage))
                throw new Exception("Could not find hybris package at deployment/HybrisPackages/" + newHybrisPackage);

            if (currentJavaPackage != newJavaPackage)
                blobClient.CopyBlob("deployment/JavaPackages/" + newJavaPackage, "deployment/java.zip");
            if (currentHybrisPackage != newHybrisPackage)
                blobClient.CopyDirectory("deployment/HybrisPackages/" + newHybrisPackage, "deployment");

            // store new package information
            foreach (var role in newAddConfig.Roles.Where(r => r.Name == "MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole" || r.Name == "MicrosoftDXGermany.hybrisOnAzure.FrontendWorkerRole"))
                foreach(var instance in role.Instances)
                {
                    // remove old package information
                    instance.Configurations.RemoveAll(c => c.Name == "JavaPackage");
                    instance.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "JavaPackage", Value = newJavaPackage });
                    instance.Configurations.RemoveAll(c => c.Name == "HybrisPackage");
                    instance.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "HybrisPackage", Value = newHybrisPackage });
                }
        }
        private void DisplayRoleStatus(string roleName, string componentName, Table targetTable, AdditionalConfiguration additionalConfig)
        {
            var role = RoleEnvironment.Roles[roleName];
            foreach(var currentInstance in role.Instances)
            {
                var additionalInstanceConfig = additionalConfig.GetConfigurationForInstance(currentInstance.Role.Name, currentInstance.Id);
                var row = new TableRow();
                targetTable.Rows.Add(row);
                var cll1 = new TableCell();
                row.Cells.Add(cll1);
                var div = new Panel();
                cll1.Controls.Add(div);

                // display IPAddress / Name of that instance
                div.Controls.Add(new Label() { Text = currentInstance.InstanceEndpoints.First().Value.IPEndpoint.Address.ToString() + "<br />" });

                // get status from that instance
                var statusClient = GetStatusServiceClientForInstance(currentInstance);
                if (statusClient == null)
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label() { Text = "No connection to status client." });
                    continue;
                }
                Dictionary<string, Dictionary<string, Tuple<string, string>>> clientResult = null;
                try
                {
                    clientResult = statusClient.GetPluginStatus();
                }
                catch (Exception ex)
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label() { Text = "Error retrieving client status. " + ex.Message });
                    continue;
                }

                var cll2 = new TableCell();
                row.Cells.Add(cll2);
                var div2 = new Panel() { CssClass = "pluginState" };
                cll2.Controls.Add(div2);

                // there is only one component running: FrontendWorkerServer or BackOfficeWorkerServer
                var component = clientResult[componentName];
                foreach(var pluginName in component.Keys)
                {
                    div2.Controls.Add(new Label() { Text = pluginName + " (" });
                    div2.Controls.Add(new Label() { Text = component[pluginName].Item1, CssClass = component[pluginName].Item1.ToLower() });
                    div2.Controls.Add(new Label() { Text = "): " + component[pluginName].Item2 + "<br />" });
                }

                // display role status
                if (component.Values.Any(pluginStatus => pluginStatus.Item1.ToLower() == "error"))
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label() { Text = "Error" });
                }
                else if (component.Values.Any(pluginStatus => pluginStatus.Item1.ToLower() == "warning"))
                {
                    div.CssClass = "warning";
                    div.Controls.Add(new Label() { Text = "Error" });
                }
                else
                {
                    div.CssClass = "healthy";
                    div.Controls.Add(new Label() { Text = "Healthy" });
                }

                // display controls for rebooting and stop hybris
                var table = new Table() { CssClass = "instanceOptions" };
                cll2.Controls.Add(table);
                var r1 = new TableRow();
                table.Rows.Add(r1);
                var c1 = new TableCell();
                r1.Cells.Add(c1);
                var chk1 = new CheckBox() { ID = "chkStopHybris_" + currentInstance.Id, Text = "Stop Hybris" };
                if (!Page.IsPostBack)
                    chk1.Checked = additionalInstanceConfig.Any(c => c.Name == "StopHybris") ? bool.Parse(additionalInstanceConfig.First(c => c.Name == "StopHybris").Value) : false;
                c1.Controls.Add(chk1);
                var r2 = new TableRow();
                table.Rows.Add(r2);
                var c2 = new TableCell();
                r2.Cells.Add(c2);
                var chk2 = new CheckBox() { ID = "chkReboot_" + currentInstance.Id, Text = "Reboot" };
                if (!Page.IsPostBack)
                    chk2.Checked = false; // TODO: Init
                c2.Controls.Add(chk2);
            }
        }
        private AdditionalConfiguration GetNewAdditionalConfiguration()
        {
            var newConfiguration = new AdditionalConfiguration();

            // Arr Configuration
            int desiredArrInstanceCount;
            if (!int.TryParse(txtArrInstanceCount.Text, out desiredArrInstanceCount))
                throw new Exception("Cannot parse ARR instance count");
            var arrRole = new tangible.Azure.AdditionalConfiguration.Role() { Name = "MicrosoftDXGermany.hybrisOnAzure.ArrRole", DesiredInstanceCount = desiredArrInstanceCount };
            newConfiguration.Roles.Add(arrRole);

            // default configuration
            var arrDefaultConfig = new tangible.Azure.AdditionalConfiguration.Instance() { Id = "default" };
            arrRole.Instances.Add(arrDefaultConfig);
            arrDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "IsInMaintenance", Value = "False" });

            // instance configuration
            if (RoleEnvironment.IsAvailable)
                foreach (var arrInstance in RoleEnvironment.Roles["MicrosoftDXGermany.hybrisOnAzure.ArrRole"].Instances)
                {
                    var arrInstanceConfig = new tangible.Azure.AdditionalConfiguration.Instance() { Id = arrInstance.Id };
                    arrRole.Instances.Add(arrInstanceConfig);
                    var setMaintenance = Page.FindControl("chkMaintenance_" + arrInstance.Id) as CheckBox;
                    if (setMaintenance != null)
                        arrInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "IsInMaintenance", Value = setMaintenance.Checked.ToString() });
                }

            // Frontend Worker Instances
            int desiredFrontendInstanceCount;
            if (!int.TryParse(txtArrInstanceCount.Text, out desiredFrontendInstanceCount))
                throw new Exception("Cannot parse FrontendWorker instance count");
            var frontendRole = new tangible.Azure.AdditionalConfiguration.Role() { Name = "MicrosoftDXGermany.hybrisOnAzure.FrontendWorkerRole", DesiredInstanceCount = desiredFrontendInstanceCount };
            newConfiguration.Roles.Add(frontendRole);

            // defaultConfiguration
            var frontendDefaultConfig = new tangible.Azure.AdditionalConfiguration.Instance() { Id = "default" };
            frontendRole.Instances.Add(frontendDefaultConfig);
            frontendDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "StopHybris", Value = "False" });
            frontendDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "Reboot", Value = String.Empty });

            // instance configuration
            if (RoleEnvironment.IsAvailable && RoleEnvironment.Roles.ContainsKey("MicrosoftDXGermany.hybrisOnAzure.FrontendWorkerRole"))
                foreach (var frontendInstance in RoleEnvironment.Roles["MicrosoftDXGermany.hybrisOnAzure.FrontendWorkerRole"].Instances)
                {
                    var frontendInstanceConfig = new tangible.Azure.AdditionalConfiguration.Instance() { Id = frontendInstance.Id };
                    frontendRole.Instances.Add(frontendInstanceConfig);
                    var stopHybris = Page.FindControl("chkStopHybris_" + frontendInstance.Id) as CheckBox;
                    if (stopHybris != null)
                        frontendInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "StopHybris", Value = stopHybris.Checked.ToString() });
                    var reboot = Page.FindControl("chkReboot_" + frontendInstance.Id) as CheckBox;
                    if (reboot != null)
                        frontendInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "Reboot", Value = (reboot.Checked) ? newConfiguration.Timestamp.ToString() : string.Empty });
                }

            // BackOffice Worker Instances
            var backOfficeRole = new tangible.Azure.AdditionalConfiguration.Role() { Name = "MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole" };
            newConfiguration.Roles.Add(backOfficeRole);

            // defaultConfiguration
            var backOfficeDefaultConfig = new tangible.Azure.AdditionalConfiguration.Instance() { Id = "default" };
            backOfficeRole.Instances.Add(frontendDefaultConfig);
            backOfficeDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "StopHybris", Value = "False" });
            backOfficeDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "Reboot", Value = String.Empty });

            // instance configuration
            if (RoleEnvironment.IsAvailable && RoleEnvironment.Roles.ContainsKey("MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole"))
                foreach (var backOfficeInstance in RoleEnvironment.Roles["MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole"].Instances)
                {
                    var backOfficeInstanceConfig = new tangible.Azure.AdditionalConfiguration.Instance() { Id = backOfficeInstance.Id };
                    backOfficeRole.Instances.Add(backOfficeInstanceConfig);
                    var stopHybris = Page.FindControl("chkStopHybris_" + backOfficeInstance.Id) as CheckBox;
                    if (stopHybris != null)
                        backOfficeInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "StopHybris", Value = stopHybris.Checked.ToString() });
                    var reboot = Page.FindControl("chkReboot_" + backOfficeInstance.Id) as CheckBox;
                    if (reboot != null)
                        backOfficeInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem() { Name = "Reboot", Value = (reboot.Checked) ? newConfiguration.Timestamp.ToString() : string.Empty });
                }

            return newConfiguration;
        }
        private void DisplayArrStatus(AdditionalConfiguration additionalConfig)
        {
            var role = RoleEnvironment.Roles["MicrosoftDXGermany.hybrisOnAzure.ArrRole"];

            TableRow currentRow = null;
            for(int i = 0; i < role.Instances.Count; i++)
            {
                var currentInstance = role.Instances[i];

                // only display 6 instances per row
                // > add current row and create a new one
                if (i % 6 == 0)
                {
                    currentRow = new TableRow();
                    tblArr.Rows.Add(currentRow);
                }

                var cll = new TableCell();
                currentRow.Cells.Add(cll);
                var div = new Panel() { CssClass = "default" };
                cll.Controls.Add(div);

                // display IPAddress / Name of that instance
                div.Controls.Add(new Label() { Text = currentInstance.InstanceEndpoints.First().Value.IPEndpoint.Address.ToString() + "<br />" });

                // get status from that instance
                var statusClient = GetStatusServiceClientForInstance(currentInstance);
                if (statusClient == null)
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label() { Text = "No connection to status client." });
                    continue;
                }
                Dictionary<string, Dictionary<string, Tuple<string, string>>> clientResult = null;
                try
                {
                    clientResult = statusClient.GetPluginStatus();
                }
                catch(Exception ex)
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label() { Text = "Error retrieving client status. " + ex.Message });
                    continue;
                }

                // there is only one component (ArrServer) running hosting one plugin (ArrPlugin)
                // > we get this specific status information
                Tuple<string, string> arrPluginStatus;
                try
                {
                    arrPluginStatus = clientResult["ArrServer"]["ArrPlugin"];
                    var status = arrPluginStatus.Item1.ToLower();
                    div.CssClass = (status == "healthy" || status == "warning" || status == "error") ? status : "default";
                    div.Controls.Add(new Label() { Text = arrPluginStatus.Item2 });
                }
                catch(Exception ex)
                {
                    div.CssClass = "warning";
                    div.Controls.Add(new Label() { Text = "Error getting plugin status: " + ex.Message });
                    continue;
                }

                // display checkBox for MaintenanceMode
                var chk = new CheckBox() { ID = "chkMaintenance_" + currentInstance.Id, Text = "Set maintenance" };
                if (!Page.IsPostBack)
                    chk.Checked = arrPluginStatus.Item2.ToLower().Contains("maintenance");
                cll.Controls.Add(chk);
            }

            // display current instance count
            if (!Page.IsPostBack)
            {
                txtArrInstanceCount.Text = role.Instances.Count.ToString();
            }
        }
Ejemplo n.º 5
0
        private void DisplayArrStatus(AdditionalConfiguration additionalConfig)
        {
            var role = RoleEnvironment.Roles["MicrosoftDXGermany.hybrisOnAzure.ArrRole"];

            TableRow currentRow = null;

            for (int i = 0; i < role.Instances.Count; i++)
            {
                var currentInstance = role.Instances[i];

                // only display 6 instances per row
                // > add current row and create a new one
                if (i % 6 == 0)
                {
                    currentRow = new TableRow();
                    tblArr.Rows.Add(currentRow);
                }

                var cll = new TableCell();
                currentRow.Cells.Add(cll);
                var div = new Panel()
                {
                    CssClass = "default"
                };
                cll.Controls.Add(div);

                // display IPAddress / Name of that instance
                div.Controls.Add(new Label()
                {
                    Text = currentInstance.InstanceEndpoints.First().Value.IPEndpoint.Address.ToString() + "<br />"
                });

                // get status from that instance
                var statusClient = GetStatusServiceClientForInstance(currentInstance);
                if (statusClient == null)
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label()
                    {
                        Text = "No connection to status client."
                    });
                    continue;
                }
                Dictionary <string, Dictionary <string, Tuple <string, string> > > clientResult = null;
                try
                {
                    clientResult = statusClient.GetPluginStatus();
                }
                catch (Exception ex)
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label()
                    {
                        Text = "Error retrieving client status. " + ex.Message
                    });
                    continue;
                }

                // there is only one component (ArrServer) running hosting one plugin (ArrPlugin)
                // > we get this specific status information
                Tuple <string, string> arrPluginStatus;
                try
                {
                    arrPluginStatus = clientResult["ArrServer"]["ArrPlugin"];
                    var status = arrPluginStatus.Item1.ToLower();
                    div.CssClass = (status == "healthy" || status == "warning" || status == "error") ? status : "default";
                    div.Controls.Add(new Label()
                    {
                        Text = arrPluginStatus.Item2
                    });
                }
                catch (Exception ex)
                {
                    div.CssClass = "warning";
                    div.Controls.Add(new Label()
                    {
                        Text = "Error getting plugin status: " + ex.Message
                    });
                    continue;
                }

                // display checkBox for MaintenanceMode
                var chk = new CheckBox()
                {
                    ID = "chkMaintenance_" + currentInstance.Id, Text = "Set maintenance"
                };
                if (!Page.IsPostBack)
                {
                    chk.Checked = arrPluginStatus.Item2.ToLower().Contains("maintenance");
                }
                cll.Controls.Add(chk);
            }

            // display current instance count
            if (!Page.IsPostBack)
            {
                txtArrInstanceCount.Text = role.Instances.Count.ToString();
            }
        }
Ejemplo n.º 6
0
        private AdditionalConfiguration GetNewAdditionalConfiguration()
        {
            var newConfiguration = new AdditionalConfiguration();

            // Arr Configuration
            int desiredArrInstanceCount;

            if (!int.TryParse(txtArrInstanceCount.Text, out desiredArrInstanceCount))
            {
                throw new Exception("Cannot parse ARR instance count");
            }
            var arrRole = new tangible.Azure.AdditionalConfiguration.Role()
            {
                Name = "MicrosoftDXGermany.hybrisOnAzure.ArrRole", DesiredInstanceCount = desiredArrInstanceCount
            };

            newConfiguration.Roles.Add(arrRole);

            // default configuration
            var arrDefaultConfig = new tangible.Azure.AdditionalConfiguration.Instance()
            {
                Id = "default"
            };

            arrRole.Instances.Add(arrDefaultConfig);
            arrDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
            {
                Name = "IsInMaintenance", Value = "False"
            });

            // instance configuration
            if (RoleEnvironment.IsAvailable)
            {
                foreach (var arrInstance in RoleEnvironment.Roles["MicrosoftDXGermany.hybrisOnAzure.ArrRole"].Instances)
                {
                    var arrInstanceConfig = new tangible.Azure.AdditionalConfiguration.Instance()
                    {
                        Id = arrInstance.Id
                    };
                    arrRole.Instances.Add(arrInstanceConfig);
                    var setMaintenance = Page.FindControl("chkMaintenance_" + arrInstance.Id) as CheckBox;
                    if (setMaintenance != null)
                    {
                        arrInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
                        {
                            Name = "IsInMaintenance", Value = setMaintenance.Checked.ToString()
                        });
                    }
                }
            }

            // Frontend Worker Instances
            int desiredFrontendInstanceCount;

            if (!int.TryParse(txtArrInstanceCount.Text, out desiredFrontendInstanceCount))
            {
                throw new Exception("Cannot parse FrontendWorker instance count");
            }
            var frontendRole = new tangible.Azure.AdditionalConfiguration.Role()
            {
                Name = "MicrosoftDXGermany.hybrisOnAzure.FrontendWorkerRole", DesiredInstanceCount = desiredFrontendInstanceCount
            };

            newConfiguration.Roles.Add(frontendRole);

            // defaultConfiguration
            var frontendDefaultConfig = new tangible.Azure.AdditionalConfiguration.Instance()
            {
                Id = "default"
            };

            frontendRole.Instances.Add(frontendDefaultConfig);
            frontendDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
            {
                Name = "StopHybris", Value = "False"
            });
            frontendDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
            {
                Name = "Reboot", Value = String.Empty
            });

            // instance configuration
            if (RoleEnvironment.IsAvailable && RoleEnvironment.Roles.ContainsKey("MicrosoftDXGermany.hybrisOnAzure.FrontendWorkerRole"))
            {
                foreach (var frontendInstance in RoleEnvironment.Roles["MicrosoftDXGermany.hybrisOnAzure.FrontendWorkerRole"].Instances)
                {
                    var frontendInstanceConfig = new tangible.Azure.AdditionalConfiguration.Instance()
                    {
                        Id = frontendInstance.Id
                    };
                    frontendRole.Instances.Add(frontendInstanceConfig);
                    var stopHybris = Page.FindControl("chkStopHybris_" + frontendInstance.Id) as CheckBox;
                    if (stopHybris != null)
                    {
                        frontendInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
                        {
                            Name = "StopHybris", Value = stopHybris.Checked.ToString()
                        });
                    }
                    var reboot = Page.FindControl("chkReboot_" + frontendInstance.Id) as CheckBox;
                    if (reboot != null)
                    {
                        frontendInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
                        {
                            Name = "Reboot", Value = (reboot.Checked) ? newConfiguration.Timestamp.ToString() : string.Empty
                        });
                    }
                }
            }

            // BackOffice Worker Instances
            var backOfficeRole = new tangible.Azure.AdditionalConfiguration.Role()
            {
                Name = "MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole"
            };

            newConfiguration.Roles.Add(backOfficeRole);

            // defaultConfiguration
            var backOfficeDefaultConfig = new tangible.Azure.AdditionalConfiguration.Instance()
            {
                Id = "default"
            };

            backOfficeRole.Instances.Add(frontendDefaultConfig);
            backOfficeDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
            {
                Name = "StopHybris", Value = "False"
            });
            backOfficeDefaultConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
            {
                Name = "Reboot", Value = String.Empty
            });

            // instance configuration
            if (RoleEnvironment.IsAvailable && RoleEnvironment.Roles.ContainsKey("MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole"))
            {
                foreach (var backOfficeInstance in RoleEnvironment.Roles["MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole"].Instances)
                {
                    var backOfficeInstanceConfig = new tangible.Azure.AdditionalConfiguration.Instance()
                    {
                        Id = backOfficeInstance.Id
                    };
                    backOfficeRole.Instances.Add(backOfficeInstanceConfig);
                    var stopHybris = Page.FindControl("chkStopHybris_" + backOfficeInstance.Id) as CheckBox;
                    if (stopHybris != null)
                    {
                        backOfficeInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
                        {
                            Name = "StopHybris", Value = stopHybris.Checked.ToString()
                        });
                    }
                    var reboot = Page.FindControl("chkReboot_" + backOfficeInstance.Id) as CheckBox;
                    if (reboot != null)
                    {
                        backOfficeInstanceConfig.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
                        {
                            Name = "Reboot", Value = (reboot.Checked) ? newConfiguration.Timestamp.ToString() : string.Empty
                        });
                    }
                }
            }

            return(newConfiguration);
        }
Ejemplo n.º 7
0
        private void UpdateJavaAndHybrisPackages(AdditionalConfiguration oldAddConfig, AdditionalConfiguration newAddConfig)
        {
            CloudStorageAccount storageAccount;

            if (!RoleEnvironment.IsAvailable)
            {
                storageAccount = CloudStorageAccount.Parse("UseDevelopmentStorage=true;");
            }
            else
            {
                storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            }
            var blobClient = storageAccount.CreateCloudBlobClient();

            var oldDefaultBackOfficeConfig = oldAddConfig.Roles.First(r => r.Name == "MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole").Instances.First(i => i.Id == "default");
            var currentJavaPackage         = oldDefaultBackOfficeConfig.Configurations.Any(c => c.Name == "JavaPackage") ? oldDefaultBackOfficeConfig.Configurations.First(c => c.Name == "JavaPackage").Value : string.Empty;
            var currentHybrisPackage       = oldDefaultBackOfficeConfig.Configurations.Any(c => c.Name == "HybrisPackage") ? oldDefaultBackOfficeConfig.Configurations.First(c => c.Name == "HybrisPackage").Value : string.Empty;

            var newJavaPackage = txtJavaPackage.Text;

            if (string.IsNullOrEmpty(newJavaPackage))
            {
                throw new Exception("No Java Package defined.");
            }
            if (!blobClient.BlobExists("deployment/JavaPackages/" + newJavaPackage))
            {
                throw new Exception("Could not find java package at deployment/JavaPackages/" + newJavaPackage);
            }

            var newHybrisPackage = txtHybrisPackage.Text;

            if (string.IsNullOrEmpty(newHybrisPackage))
            {
                throw new Exception("No Hybris Package defined.");
            }
            if (!blobClient.DirectoryExists("deployment/HybrisPackages/" + newHybrisPackage))
            {
                throw new Exception("Could not find hybris package at deployment/HybrisPackages/" + newHybrisPackage);
            }

            if (currentJavaPackage != newJavaPackage)
            {
                blobClient.CopyBlob("deployment/JavaPackages/" + newJavaPackage, "deployment/java.zip");
            }
            if (currentHybrisPackage != newHybrisPackage)
            {
                blobClient.CopyDirectory("deployment/HybrisPackages/" + newHybrisPackage, "deployment");
            }

            // store new package information
            foreach (var role in newAddConfig.Roles.Where(r => r.Name == "MicrosoftDXGermany.hybrisOnAzure.BackOfficeWorkerRole" || r.Name == "MicrosoftDXGermany.hybrisOnAzure.FrontendWorkerRole"))
            {
                foreach (var instance in role.Instances)
                {
                    // remove old package information
                    instance.Configurations.RemoveAll(c => c.Name == "JavaPackage");
                    instance.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
                    {
                        Name = "JavaPackage", Value = newJavaPackage
                    });
                    instance.Configurations.RemoveAll(c => c.Name == "HybrisPackage");
                    instance.Configurations.Add(new tangible.Azure.AdditionalConfiguration.ConfigurationItem()
                    {
                        Name = "HybrisPackage", Value = newHybrisPackage
                    });
                }
            }
        }
Ejemplo n.º 8
0
        private void DisplayRoleStatus(string roleName, string componentName, Table targetTable, AdditionalConfiguration additionalConfig)
        {
            var role = RoleEnvironment.Roles[roleName];

            foreach (var currentInstance in role.Instances)
            {
                var additionalInstanceConfig = additionalConfig.GetConfigurationForInstance(currentInstance.Role.Name, currentInstance.Id);
                var row = new TableRow();
                targetTable.Rows.Add(row);
                var cll1 = new TableCell();
                row.Cells.Add(cll1);
                var div = new Panel();
                cll1.Controls.Add(div);

                // display IPAddress / Name of that instance
                div.Controls.Add(new Label()
                {
                    Text = currentInstance.InstanceEndpoints.First().Value.IPEndpoint.Address.ToString() + "<br />"
                });

                // get status from that instance
                var statusClient = GetStatusServiceClientForInstance(currentInstance);
                if (statusClient == null)
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label()
                    {
                        Text = "No connection to status client."
                    });
                    continue;
                }
                Dictionary <string, Dictionary <string, Tuple <string, string> > > clientResult = null;
                try
                {
                    clientResult = statusClient.GetPluginStatus();
                }
                catch (Exception ex)
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label()
                    {
                        Text = "Error retrieving client status. " + ex.Message
                    });
                    continue;
                }

                var cll2 = new TableCell();
                row.Cells.Add(cll2);
                var div2 = new Panel()
                {
                    CssClass = "pluginState"
                };
                cll2.Controls.Add(div2);

                // there is only one component running: FrontendWorkerServer or BackOfficeWorkerServer
                var component = clientResult[componentName];
                foreach (var pluginName in component.Keys)
                {
                    div2.Controls.Add(new Label()
                    {
                        Text = pluginName + " ("
                    });
                    div2.Controls.Add(new Label()
                    {
                        Text = component[pluginName].Item1, CssClass = component[pluginName].Item1.ToLower()
                    });
                    div2.Controls.Add(new Label()
                    {
                        Text = "): " + component[pluginName].Item2 + "<br />"
                    });
                }

                // display role status
                if (component.Values.Any(pluginStatus => pluginStatus.Item1.ToLower() == "error"))
                {
                    div.CssClass = "error";
                    div.Controls.Add(new Label()
                    {
                        Text = "Error"
                    });
                }
                else if (component.Values.Any(pluginStatus => pluginStatus.Item1.ToLower() == "warning"))
                {
                    div.CssClass = "warning";
                    div.Controls.Add(new Label()
                    {
                        Text = "Error"
                    });
                }
                else
                {
                    div.CssClass = "healthy";
                    div.Controls.Add(new Label()
                    {
                        Text = "Healthy"
                    });
                }

                // display controls for rebooting and stop hybris
                var table = new Table()
                {
                    CssClass = "instanceOptions"
                };
                cll2.Controls.Add(table);
                var r1 = new TableRow();
                table.Rows.Add(r1);
                var c1 = new TableCell();
                r1.Cells.Add(c1);
                var chk1 = new CheckBox()
                {
                    ID = "chkStopHybris_" + currentInstance.Id, Text = "Stop Hybris"
                };
                if (!Page.IsPostBack)
                {
                    chk1.Checked = additionalInstanceConfig.Any(c => c.Name == "StopHybris") ? bool.Parse(additionalInstanceConfig.First(c => c.Name == "StopHybris").Value) : false;
                }
                c1.Controls.Add(chk1);
                var r2 = new TableRow();
                table.Rows.Add(r2);
                var c2 = new TableCell();
                r2.Cells.Add(c2);
                var chk2 = new CheckBox()
                {
                    ID = "chkReboot_" + currentInstance.Id, Text = "Reboot"
                };
                if (!Page.IsPostBack)
                {
                    chk2.Checked = false; // TODO: Init
                }
                c2.Controls.Add(chk2);
            }
        }