public Task Run() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string sqlQuery = $@" USE {scaleUnit.AxDbName}; EXEC sys.sp_set_session_context @key = N'ActiveScaleUnitId', @value = ''; DELETE FROM SysFeatureStateV0; DELETE FROM FeatureManagementState; DELETE FROM FeatureManagementMetadata; DELETE FROM SysFlighting; TRUNCATE TABLE NumberSequenceScope; EXEC sys.sp_set_session_context @key = N'ActiveScaleUnitId', @value = '@A'; "; string cmd = "Invoke-Sqlcmd -Query " + CommandExecutor.Quotes + sqlQuery + CommandExecutor.Quotes + " -QueryTimeout 65535"; CommandExecutor ce = new CommandExecutor(); ce.RunCommand(cmd); return(Task.CompletedTask); }
public Task Run() { CheckForAdminAccess.ValidateCurrentUserIsProcessAdmin(); ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string cmd = $@" if (Get-Service '{scaleUnit.BatchServiceName()}' -ErrorAction SilentlyContinue) {{ Stop-Service -Name {scaleUnit.BatchServiceName()}; }} .$env:systemroot\System32\inetsrv\appcmd.exe stop apppool /apppool.name:{scaleUnit.AppPoolName()}; .$env:systemroot\System32\inetsrv\appcmd.exe stop site /site.name:{scaleUnit.SiteName()}; "; var ce = new CommandExecutor(); try { ce.RunCommand(cmd); } catch (Exception) { if (!Config.UseSingleOneBox()) { throw; } } return(Task.CompletedTask); }
public Task Run() { const string ScaleUnitManagementUserName = "******"; ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string sqlQuery = $@" USE {scaleUnit.AxDbName}; IF NOT EXISTS (SELECT TOP 1 1 FROM SysAADClientTable WHERE AADClientId = '{scaleUnit.AuthConfiguration.AppId}') BEGIN IF EXISTS (SELECT TOP 1 1 FROM USERINFO WHERE ID = '{ScaleUnitManagementUserName}') INSERT INTO SysAADClientTable (AADClientId, UserId, Name) VALUES ('{scaleUnit.AuthConfiguration.AppId}', '{ScaleUnitManagementUserName}', 'Scale Unit Management Tool'); ELSE INSERT INTO SysAADClientTable (AADClientId, UserId, Name) VALUES ('{scaleUnit.AuthConfiguration.AppId}', 'Admin', 'Scale Unit Management Tool'); END "; string cmd = "Invoke-SqlCmd -Query " + CommandExecutor.Quotes + sqlQuery + CommandExecutor.Quotes + " -QueryTimeout 65535"; CommandExecutor ce = new CommandExecutor(); ce.RunCommand(cmd); return(Task.CompletedTask); }
public void Run() { CheckForAdminAccess.ValidateCurrentUserIsProcessAdmin(); ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string cmd = $@" Stop-Service -Name {scaleUnit.BatchServiceName()}; .$env:systemroot\System32\inetsrv\appcmd.exe stop apppool /apppool.name:{scaleUnit.AppPoolName()}; .$env:systemroot\System32\inetsrv\appcmd.exe stop site /site.name:{scaleUnit.SiteName()}; "; CommandExecutor ce = new CommandExecutor(); try { ce.RunCommand(cmd); } catch (Exception) { if (!Config.UseSingleOneBox()) { throw; } } }
public Task Run() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); using (var webConfig = new WebConfig()) { SharedWebConfig.Configure(webConfig); if (scaleUnit.EnvironmentType == EnvironmentType.VHD || Config.UseSingleOneBox()) { webConfig.UpdateXElement("Infrastructure.StartStorageEmulator", "false"); webConfig.AddValidAudiences(scaleUnit); } } if (Config.UseSingleOneBox()) { // Update hosts file using (var hosts = new Hosts()) { hosts.AddMapping(scaleUnit.IpAddress, scaleUnit.DomainSafe()); } // Update IIS binding IISAdministrationHelper.CreateSite( siteName: scaleUnit.SiteName(), siteRoot: scaleUnit.SiteRoot(), bindingInformation: scaleUnit.IpAddress + ":443:" + scaleUnit.DomainSafe(), certSubject: scaleUnit.DomainSafe(), appPoolName: scaleUnit.AppPoolName()); } return(Task.CompletedTask); }
public void Run() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); if (scaleUnit.EnvironmentType == EnvironmentType.VHD || Config.UseSingleOneBox()) { // Update hosts file using (var hosts = new Hosts()) { hosts.AddMapping(scaleUnit.IpAddress, scaleUnit.DomainSafe()); hosts.AddMapping(Config.HubScaleUnit().IpAddress, Config.HubScaleUnit().DomainSafe()); } IISAdministrationHelper.CreateSite( siteName: scaleUnit.SiteName(), siteRoot: scaleUnit.SiteRoot(), bindingInformation: scaleUnit.IpAddress + ":443:" + scaleUnit.DomainSafe(), certSubject: scaleUnit.DomainSafe(), appPoolName: scaleUnit.AppPoolName()); } using (var webConfig = new WebConfig()) { if (scaleUnit.EnvironmentType == EnvironmentType.VHD || Config.UseSingleOneBox()) { if (!String.IsNullOrEmpty(Config.AADTenantId())) { webConfig.UpdateXElement("Aad.AADTenantId", Config.AADTenantId()); } if (!String.IsNullOrEmpty(scaleUnit.AzureStorageConnectionString)) { webConfig.UpdateXElement("AzureStorage.StorageConnectionString", scaleUnit.AzureStorageConnectionString); } webConfig.UpdateXElement("Infrastructure.FullyQualifiedDomainName", scaleUnit.DomainSafe()); webConfig.UpdateXElement("Infrastructure.HostName", scaleUnit.DomainSafe()); webConfig.UpdateXElement("Infrastructure.HostedServiceName", scaleUnit.ScaleUnitUrlName()); string scaleUnitUrl = scaleUnit.Endpoint() + "/"; webConfig.UpdateXElement("Infrastructure.HostUrl", scaleUnitUrl); webConfig.UpdateXElement("Infrastructure.SoapServicesUrl", scaleUnitUrl); webConfig.UpdateXElement("DataAccess.Database", scaleUnit.AxDbName); } webConfig.AddKey("ScaleUnit.InstanceID", scaleUnit.ScaleUnitId); webConfig.AddKey("ScaleUnit.Enabled", "true"); webConfig.AddKey("DbSync.TriggersEnabled", "true"); } WifServiceConfig.Update(); if (Config.UseSingleOneBox()) { CreateScaleUnitBatchService(scaleUnit); } }
public void Run() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string sqlQuery = $"USE master; IF NOT EXISTS (SELECT * FROM sys.change_tracking_databases WHERE database_id=DB_ID('{scaleUnit.AxDbName}')) ALTER DATABASE {scaleUnit.AxDbName} SET CHANGE_TRACKING = ON(CHANGE_RETENTION = 2 DAYS, AUTO_CLEANUP = ON)"; string cmd = "Invoke-Sqlcmd -Query " + CommandExecutor.Quotes + sqlQuery + CommandExecutor.Quotes + " -QueryTimeout 65535"; CommandExecutor ce = new CommandExecutor(); ce.RunCommand(cmd); }
public WebConfig() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); webConfigPath = scaleUnit.WebConfigPath(); configEncryptorExePath = scaleUnit.ConfigEncryptorExePath(); doc = XDocument.Load(webConfigPath); appSettingsElement = doc.Descendants() .Where(x => (string)x.Name.LocalName == "appSettings") .FirstOrDefault(); }
public HubConfigurationManager() { scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); hubConfig = new ScaleUnitEnvironmentConfiguration() { AppId = Config.InterAOSAppId(), AppTenant = Config.InterAOSAuthority(), HubResourceId = Config.InterAOSAppResourceId(scaleUnit), HubUrl = scaleUnit.Endpoint(), HubS2SEncryptedSecret = Config.InterAOSAppSecret(), ScaleUnitType = "0", }; }
public Task Run() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); if (scaleUnit.EnvironmentType == EnvironmentType.VHD || Config.UseSingleOneBox()) { // Update hosts file using (var hosts = new Hosts()) { hosts.AddMapping(scaleUnit.IpAddress, scaleUnit.DomainSafe()); hosts.AddMapping(Config.HubScaleUnit().IpAddress, Config.HubScaleUnit().DomainSafe()); } IISAdministrationHelper.CreateSite( siteName: scaleUnit.SiteName(), siteRoot: scaleUnit.SiteRoot(), bindingInformation: scaleUnit.IpAddress + ":443:" + scaleUnit.DomainSafe(), certSubject: scaleUnit.DomainSafe(), appPoolName: scaleUnit.AppPoolName()); } using (var webConfig = new WebConfig()) { SharedWebConfig.Configure(webConfig); if (scaleUnit.EnvironmentType == EnvironmentType.VHD || Config.UseSingleOneBox()) { webConfig.UpdateXElement("Infrastructure.FullyQualifiedDomainName", scaleUnit.DomainSafe()); webConfig.UpdateXElement("Infrastructure.HostName", scaleUnit.DomainSafe()); webConfig.UpdateXElement("Infrastructure.HostedServiceName", scaleUnit.ScaleUnitUrlName()); string scaleUnitUrl = scaleUnit.Endpoint() + "/"; webConfig.UpdateXElement("Infrastructure.HostUrl", scaleUnitUrl); webConfig.UpdateXElement("Infrastructure.SoapServicesUrl", scaleUnitUrl); webConfig.UpdateXElement("DataAccess.Database", scaleUnit.AxDbName); webConfig.AddValidAudiences(scaleUnit); } } WifServiceConfig.Update(); if (Config.UseSingleOneBox()) { CreateScaleUnitBatchService(scaleUnit); } return(Task.CompletedTask); }
public static void Configure(WebConfig webConfig) { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); if (scaleUnit.EnvironmentType == EnvironmentType.VHD || Config.UseSingleOneBox()) { if (!String.IsNullOrEmpty(scaleUnit.AzureStorageConnectionString)) { webConfig.UpdateXElement("AzureStorage.StorageConnectionString", scaleUnit.AzureStorageConnectionString); } } webConfig.AddKey("ScaleUnit.InstanceID", scaleUnit.ScaleUnitId); webConfig.AddKey("ScaleUnit.Enabled", "true"); webConfig.AddKey("DbSync.TriggersEnabled", "true"); }
public void Run() { CheckForAdminAccess.ValidateCurrentUserIsProcessAdmin(); ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string cmd = $@" Start-Service -Name {scaleUnit.BatchServiceName()}; .$env:systemroot\System32\inetsrv\appcmd.exe start apppool /apppool.name:{scaleUnit.AppPoolName()}; .$env:systemroot\System32\inetsrv\appcmd.exe start site /site.name:{scaleUnit.SiteName()}; "; CommandExecutor ce = new CommandExecutor(); ce.RunCommand(cmd); }
public void Run() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string sqlQuery = $@" USE {scaleUnit.AxDbName}; IF NOT EXISTS (SELECT TOP 1 1 FROM SysAADClientTable WHERE AADClientId = '{Config.AppId()}') INSERT INTO SysAADClientTable (AADClientId, UserId, Name) VALUES ('{Config.AppId()}', 'Admin', 'Scale Unit Management Tool'); "; string cmd = "Invoke-SqlCmd -Query " + CommandExecutor.Quotes + sqlQuery + CommandExecutor.Quotes + " -QueryTimeout 65535"; CommandExecutor ce = new CommandExecutor(); ce.RunCommand(cmd); }
public static void Update() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); XmlDocument wifDoc = new XmlDocument(); wifDoc.Load(scaleUnit.WifServicesConfigPath()); // Update urls in wif.services.config var cookieHandlerNode = wifDoc.SelectSingleNode("/system.identityModel.services/federationConfiguration/cookieHandler"); XmlAttributeCollection attrColl = cookieHandlerNode.Attributes; XmlAttribute attr = (XmlAttribute)attrColl.GetNamedItem("domain"); attr.Value = scaleUnit.DomainSafe(); wifDoc.Save(scaleUnit.WifServicesConfigPath()); }
private static async Task InstallWorkloadsForScaleUnit(int input, string selectionHistory) { List <ScaleUnitInstance> scaleUnitInstances = Config.ScaleUnitInstances(); scaleUnitInstances.Sort(); using (var context = ScaleUnitContext.CreateContext(scaleUnitInstances[input - 1].ScaleUnitId)) { if (ScaleUnitContext.GetScaleUnitId() == "@@") { await new HubWorkloadInstaller().Install(); } else { await new ScaleUnitWorkloadInstaller().Install(); } } }
private static async Task PrintAvailableStepsForScaleUnit(int input, string selectionHistory) { List <ScaleUnitInstance> scaleUnitInstances = Config.ScaleUnitInstances(); scaleUnitInstances.Sort(); using (var context = ScaleUnitContext.CreateContext(scaleUnitInstances[input - 1].ScaleUnitId)) { if (scaleUnitInstances[input - 1].ScaleUnitId == "@@") { await new EnableScaleUnitFeatureOnHub().PrintAvailableSteps(input, selectionHistory); } else { await new EnableScaleUnitFeatureOnScaleUnit().PrintAvailableSteps(input, selectionHistory); } } }
public Task Run() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string sqlQuery = $@" USE {scaleUnit.AxDbName}; IF NOT EXISTS (SELECT TOP 1 1 FROM SysFlighting WHERE FlightName = '{MESFlightName}') INSERT INTO SysFlighting (FlightName, Enabled, FlightServiceId) VALUES ('{MESFlightName}', 1, 12719367); "; string cmd = "Invoke-SqlCmd -Query " + CommandExecutor.Quotes + sqlQuery + CommandExecutor.Quotes + " -QueryTimeout 65535"; CommandExecutor ce = new CommandExecutor(); ce.RunCommand(cmd); return(Task.CompletedTask); }
private static async Task ConfigureScaleUnit(int input, string selectionHistory) { List <ScaleUnitInstance> scaleUnitInstances = Config.ScaleUnitInstances(); scaleUnitInstances.Sort(); using (var context = ScaleUnitContext.CreateContext(scaleUnitInstances[input - 1].ScaleUnitId)) { if (ScaleUnitContext.GetScaleUnitId() == "@@") { await new HubConfigurationManager().Configure(); } else { await new ScaleUnitConfigurationManager().Configure(); } } }
protected async Task PrintAvailableSteps(int input, string selectionHistory) { var options = new List <CLIOption>(); AvailableSteps = GetAvailableSteps(); AvailableSteps.Sort((x, y) => x.Priority().CompareTo(y.Priority())); foreach (IStep s in AvailableSteps) { options.Add(new CLIOption() { Name = s.Label(), Command = RunStepsFromTask }); } ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); CLIScreen screen = new CLIScreen(options, selectionHistory, $"Task sequence to run for {scaleUnit.PrintableName()}\n", "\nSelect task to start from: "); await CLIMenu.ShowScreen(screen); }
public void Run() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); using (var webConfig = new WebConfig()) { if (scaleUnit.EnvironmentType == EnvironmentType.VHD) { if (!String.IsNullOrEmpty(Config.AADTenantId())) { webConfig.UpdateXElement("Aad.AADTenantId", Config.AADTenantId()); } if (!String.IsNullOrEmpty(scaleUnit.AzureStorageConnectionString)) { webConfig.UpdateXElement("AzureStorage.StorageConnectionString", scaleUnit.AzureStorageConnectionString); } webConfig.UpdateXElement("Infrastructure.StartStorageEmulator", "false"); } webConfig.AddKey("ScaleUnit.InstanceID", scaleUnit.ScaleUnitId); webConfig.AddKey("ScaleUnit.Enabled", "true"); webConfig.AddKey("DbSync.TriggersEnabled", "true"); } if (Config.UseSingleOneBox()) { // Update hosts file using (var hosts = new Hosts()) { hosts.AddMapping(scaleUnit.IpAddress, scaleUnit.DomainSafe()); } // Update IIS binding IISAdministrationHelper.CreateSite( siteName: scaleUnit.SiteName(), siteRoot: scaleUnit.SiteRoot(), bindingInformation: scaleUnit.IpAddress + ":443:" + scaleUnit.DomainSafe(), certSubject: scaleUnit.DomainSafe(), appPoolName: scaleUnit.AppPoolName()); } }
public void Run() { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string sqlQuery = $@" USE {scaleUnit.AxDbName}; -- insert row under Hub scale unit id to avoid merge conflicts later, as the table is synced Hub->Scale Unit EXEC sys.sp_set_session_context @key = N'ActiveScaleUnitId', @value = '@@'; IF NOT EXISTS (SELECT TOP 1 1 FROM SysFlighting WHERE FlightName = '{MESFlightName}') INSERT INTO SysFlighting (FlightName, Enabled, FlightServiceId) VALUES ('{MESFlightName}', 1, 12719367); "; string cmd = "Invoke-SqlCmd -Query " + CommandExecutor.Quotes + sqlQuery + CommandExecutor.Quotes + " -QueryTimeout 65535"; CommandExecutor ce = new CommandExecutor(); ce.RunCommand(cmd); }
internal static void CreateSite(string siteName, string siteRoot, string bindingInformation, string certSubject, string appPoolName) { if (String.IsNullOrEmpty(siteName) || String.IsNullOrEmpty(siteRoot) || String.IsNullOrEmpty(bindingInformation) || String.IsNullOrEmpty(certSubject) || String.IsNullOrEmpty(appPoolName)) { throw new ArgumentNullException(); } ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); if (!scaleUnit.IsHub() && Config.UseSingleOneBox()) { CreateAppPoolForScaleUnit(scaleUnit, appPoolName); } using (ServerManager manager = new ServerManager()) { Site site = manager.Sites.FirstOrDefault((s) => s.Name.Equals(siteName)); if (site != null) { manager.Sites.Remove(site); } site = manager.Sites.Add(siteName, siteRoot, 443); site.Applications[0].ApplicationPoolName = appPoolName; site.Bindings.Clear(); site.Bindings.Add(bindingInformation, CertificateStoreHelper.GetCertificateHashFromLocalMachineStore(certSubject), CertificateStoreHelper.PersonalCertificateStoreName); manager.CommitChanges(); } }
public void Run() { Console.WriteLine("2. Executing DbSync"); try { ScaleUnitInstance scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); string dbSyncTool = Path.Combine(scaleUnit.ServiceVolume, @"AOSService\PackagesLocalDirectory\bin\syncengine.exe"); string metaBinariesPath = Path.Combine(scaleUnit.ServiceVolume, @"AOSService\PackagesLocalDirectory"); string cmd = dbSyncTool + " -syncmode=" + CommandExecutor.Quotes + "fullall" + CommandExecutor.Quotes + " -metadatabinaries=" + CommandExecutor.Quotes + metaBinariesPath + CommandExecutor.Quotes + " -connect=" + CommandExecutor.Quotes + $"Data Source=localhost;Initial Catalog={scaleUnit.AxDbName};Integrated Security=True;Enlist=True;Application Name=AXVSSDK" + CommandExecutor.Quotes + " -verbosity=" + CommandExecutor.Quotes + "Diagnostic" + CommandExecutor.Quotes + " -scaleUnitOptionsAsJson=" + CommandExecutor.Quotes + "{" + CommandExecutor.Quotes + "IsScaleUnitFeatureEnabled" + CommandExecutor.Quotes + ": true, " + CommandExecutor.Quotes + "scaleUnitMnemonics" + CommandExecutor.Quotes + ":" + $"'{scaleUnit.ScaleUnitId}'" + " }" + CommandExecutor.Quotes + " -triggerOptionsAsJson=" + CommandExecutor.Quotes + "{" + CommandExecutor.Quotes + "IsEnabled" + CommandExecutor.Quotes + ": true}" + CommandExecutor.Quotes + $" > {scaleUnit.AxDbName}_DbSync.log"; Console.WriteLine(cmd); Console.WriteLine("\nDBSync started at: " + DateTime.UtcNow + ", this will take approximately 30 minutes.\n"); CommandExecutor ce = new CommandExecutor(); ce.RunCommand(cmd); Console.WriteLine("\nDBSync finished \n"); } catch (Exception) { Console.WriteLine("\nDBSync failed \n"); throw; } }
public ScaleUnitWorkloadInstaller() { scaleUnit = Config.FindScaleUnitWithId(ScaleUnitContext.GetScaleUnitId()); }