internal async Task HandleAgentProxiesRequest(AgentProxiesParams parameters, RequestContext <AgentProxiesResult> requestContext) { await Task.Run(async() => { var result = new AgentProxiesResult(); try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); int proxyCount = dataContainer.Server.JobServer.ProxyAccounts.Count; var proxies = new AgentProxyInfo[proxyCount]; for (int i = 0; i < proxyCount; ++i) { var proxy = dataContainer.Server.JobServer.ProxyAccounts[i]; proxies[i] = new AgentProxyInfo { AccountName = proxy.Name, Description = proxy.Description, CredentialName = proxy.CredentialName }; } result.Proxies = proxies; result.Success = true; } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.ToString(); } await requestContext.SendResult(result); }); }
internal async Task <Tuple <bool, string> > ConfigureAgentProxy( string ownerUri, string accountName, AgentProxyInfo proxy, ConfigAction configAction, RunType runType) { return(await Task <bool> .Run(() => { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); STParameters param = new STParameters(dataContainer.Document); param.SetParam("proxyaccount", accountName); using (AgentProxyAccountActions agentProxy = new AgentProxyAccountActions(dataContainer, proxy, configAction)) { var executionHandler = new ExecutonHandler(agentProxy); executionHandler.RunNow(runType, this); } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { return new Tuple <bool, string>(false, ex.ToString()); } })); }
/// <summary> /// Main constructor. Creates all pages and adds them /// to the tree control. /// </summary> public AgentProxyAccountActions(CDataContainer dataContainer, AgentProxyInfo proxyInfo, ConfigAction configAction) { this.DataContainer = dataContainer; this.proxyInfo = proxyInfo; this.configAction = configAction; if (configAction != ConfigAction.Drop) { // Create data structures int length = Enum.GetValues(typeof(ProxyPrincipalType)).Length; this.principals = new ArrayList[length]; for (int i = 0; i < length; ++i) { this.principals[i] = new ArrayList(); } if (configAction == ConfigAction.Update) { RefreshData(); } } // Find out if we are creating a new proxy account or // modifying an existing one. GetProxyAccountName(dataContainer, ref this.proxyAccountName, ref this.duplicate); }
/// <summary> /// Main constructor. Creates all pages and adds them /// to the tree control. /// </summary> public AgentProxyAccount(CDataContainer dataContainer, AgentProxyInfo proxyInfo) { this.DataContainer = dataContainer; this.proxyInfo = proxyInfo; // Find out if we are creating a new proxy account or // modifying an existing one. GetProxyAccountName(dataContainer, ref this.proxyAccountName, ref this.duplicate); }
public async Task TestHandleUpdateAgentProxyRequest() { using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile()) { var createContext = new Mock <RequestContext <CreateAgentProxyResult> >(); var updateContext = new Mock <RequestContext <UpdateAgentProxyResult> >(); var deleteContext = new Mock <RequestContext <DeleteAgentProxyResult> >(); var service = new AgentService(); var proxy = new AgentProxyInfo() { Id = 10, AccountName = "Test Proxy 2", CredentialName = "User", Description = "", IsEnabled = true }; var connectionResult = await LiveConnectionHelper.InitLiveConnectionInfoAsync("master", queryTempFile.FilePath); await service.HandleDeleteAgentProxyRequest(new DeleteAgentProxyParams() { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, Proxy = proxy }, deleteContext.Object); deleteContext.VerifyAll(); await service.HandleCreateAgentProxyRequest(new CreateAgentProxyParams { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, Proxy = proxy }, createContext.Object); createContext.VerifyAll(); string originalProxyName = proxy.AccountName; proxy.AccountName = proxy.AccountName + " Updated"; await service.HandleUpdateAgentProxyRequest(new UpdateAgentProxyParams() { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, OriginalProxyName = originalProxyName, Proxy = proxy }, updateContext.Object); updateContext.VerifyAll(); await service.HandleDeleteAgentProxyRequest(new DeleteAgentProxyParams() { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, Proxy = proxy }, deleteContext.Object); deleteContext.VerifyAll(); } }
internal static async Task DeleteAgentProxy( AgentService service, TestConnectionResult connectionResult, AgentProxyInfo proxy) { var context = new Mock <RequestContext <ResultStatus> >(); await service.HandleDeleteAgentProxyRequest(new DeleteAgentProxyParams() { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, Proxy = proxy }, context.Object); context.VerifyAll(); }
internal static async Task UpdateAgentProxy( AgentService service, TestConnectionResult connectionResult, string originalProxyName, AgentProxyInfo proxy) { var context = new Mock <RequestContext <AgentProxyResult> >(); await service.HandleUpdateAgentProxyRequest(new UpdateAgentProxyParams() { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, OriginalProxyName = originalProxyName, Proxy = proxy }, context.Object); context.VerifyAll(); }
internal async Task <bool> ConfigureAgentProxy( string ownerUri, string accountName, AgentProxyInfo proxy, AgentConfigAction configAction) { return(await Task <bool> .Run(() => { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection( ownerUri, out connInfo); CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true); STParameters param = new STParameters(dataContainer.Document); param.SetParam("proxyaccount", accountName); using (AgentProxyAccount agentProxy = new AgentProxyAccount(dataContainer, proxy)) { if (configAction == AgentConfigAction.Create) { return agentProxy.Create(); } else if (configAction == AgentConfigAction.Update) { return agentProxy.Update(); } else if (configAction == AgentConfigAction.Drop) { return agentProxy.Drop(); } else { return false; } } } catch (Exception) { // log exception here return false; } })); }
/// <summary> /// It creates a new ProxyAccount or gets an existing /// one from JobServer and updates all properties. /// </summary> private bool CreateOrUpdateProxyAccount(AgentProxyInfo proxyInfo) { ProxyAccount proxyAccount = null; if (this.configAction == ConfigAction.Create) { proxyAccount = new ProxyAccount(this.DataContainer.Server.JobServer, proxyInfo.AccountName, proxyInfo.CredentialName, proxyInfo.IsEnabled, proxyInfo.Description); UpdateProxyAccount(proxyAccount); proxyAccount.Create(); } else if (this.DataContainer.Server.JobServer.ProxyAccounts.Contains(this.proxyAccountName)) { // Try refresh and check again this.DataContainer.Server.JobServer.ProxyAccounts.Refresh(); if (this.DataContainer.Server.JobServer.ProxyAccounts.Contains(this.proxyAccountName)) { proxyAccount = AgentProxyAccountActions.GetProxyAccount(this.proxyAccountName, this.DataContainer.Server.JobServer); // Set the other properties proxyAccount.CredentialName = proxyInfo.CredentialName; proxyAccount.Description = proxyInfo.Description; UpdateProxyAccount(proxyAccount); proxyAccount.Alter(); // Rename the proxy if needed // This has to be done after Alter, in order to // work correcly when scripting this action. if (this.proxyAccountName != proxyInfo.AccountName) { proxyAccount.Rename(proxyInfo.AccountName); } } } else { return(false); } return(true); #if false // @TODO - reenable subsystem code below // Update the subsystems foreach (AgentSubSystem subsystem in this.addSubSystems) { proxyAccount.AddSubSystem(subsystem); } foreach (AgentSubSystem subsystem in this.removeSubSystems) { proxyAccount.RemoveSubSystem(subsystem); // Update jobsteps that use this proxy accunt // when some subsystems are removed from it string reassignToProxyName = this.reassignToProxyNames[(int)subsystem]; if (reassignToProxyName != null) { // if version is sql 11 and above call SMO API to reassign proxy account if (Utils.IsSql11OrLater(this.DataContainer.Server.ServerVersion)) { proxyAccount.Reassign(reassignToProxyName); } else { // legacy code // Get a list of all job step objects that use this proxy and this subsystem Request req = new Request(); req.Urn = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Server/JobServer/Job/Step[@ProxyName=\'{0}\' and @SubSystem={1}]", Urn.EscapeString(proxyAccount.Name), (int)subsystem); req.Fields = new string[] { "Name" }; req.ParentPropertiesRequests = new PropertiesRequest[1] { new PropertiesRequest() }; req.ParentPropertiesRequests[0].Fields = new string[] { "Name" }; Enumerator en = new Enumerator(); DataTable table = en.Process(this.DataContainer.ServerConnection, req); foreach (DataRow row in table.Rows) { // Get the actual job step object using urn string urnString = string.Format(System.Globalization.CultureInfo.InvariantCulture, "Server/JobServer/Job[@Name=\"{0}\"/Step[@Name=\"{1}\"", row["Job_Name"], row["Name"]); Urn urn = new Urn(urnString); JobStep jobStep = (JobStep)this.DataContainer.Server.GetSmoObject(urn); jobStep.ProxyName = reassignToProxyName; jobStep.Alter(); } } } } #endif }