internal static AgentJobStep ConvertToAgentJobStep(JobStep step, LogSourceJobHistory.LogEntryJobHistory logEntry, string jobId) { AgentJobStepInfo stepInfo = new AgentJobStepInfo(); stepInfo.JobId = jobId; stepInfo.JobName = logEntry.JobName; stepInfo.StepName = step.Name; stepInfo.SubSystem = step.SubSystem; stepInfo.Id = step.ID; stepInfo.FailureAction = step.OnFailAction; stepInfo.SuccessAction = step.OnSuccessAction; stepInfo.FailStepId = step.OnFailStep; stepInfo.SuccessStepId = step.OnSuccessStep; stepInfo.Command = step.Command; stepInfo.CommandExecutionSuccessCode = step.CommandExecutionSuccessCode; stepInfo.DatabaseName = step.DatabaseName; stepInfo.DatabaseUserName = step.DatabaseUserName; stepInfo.Server = step.Server; stepInfo.OutputFileName = step.OutputFileName; stepInfo.RetryAttempts = step.RetryAttempts; stepInfo.RetryInterval = step.RetryInterval; stepInfo.ProxyName = step.ProxyName; AgentJobStep jobStep = new AgentJobStep(); jobStep.stepId = logEntry.StepID; jobStep.stepName = logEntry.StepName; jobStep.stepDetails = stepInfo; jobStep.message = logEntry.Message; jobStep.runDate = step.LastRunDate.ToString(); jobStep.runStatus = (Contracts.CompletionResult)step.LastRunOutcome; return(jobStep); }
public JobStepsActions( CDataContainer dataContainer, JobData jobData, AgentJobStepInfo stepInfo, ConfigAction configAction) { this.configAction = configAction; this.DataContainer = dataContainer; this.jobData = jobData; if (configAction == ConfigAction.Create) { this.data = new JobStepData(jobData.JobSteps); } else { JobStep jobStep = GetJobStep(this.jobData, stepInfo.StepName); this.data = new JobStepData(jobStep, jobData.JobSteps); } // load properties from AgentJobStepInfo this.data.ID = stepInfo.Id; this.data.Name = stepInfo.StepName; this.data.Command = stepInfo.Command; this.data.Subsystem = AgentUtilities.ConvertToAgentSubSytem(stepInfo.SubSystem); }
internal async Task <Tuple <bool, string> > ConfigureAgentJobStep( string ownerUri, AgentJobStepInfo stepInfo, ConfigAction configAction, RunType runType) { return(await Task <Tuple <bool, string> > .Run(() => { try { if (string.IsNullOrWhiteSpace(stepInfo.JobName)) { return new Tuple <bool, string>(false, "JobId cannot be null"); } JobData jobData; CDataContainer dataContainer; CreateJobData(ownerUri, stepInfo.JobName, out dataContainer, out jobData); using (var jobStep = new JobStepsActions(dataContainer, jobData, stepInfo, configAction)) { var executionHandler = new ExecutonHandler(jobStep); executionHandler.RunNow(runType, this); } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { // log exception here return new Tuple <bool, string>(false, ex.ToString()); } })); }
public static AgentJobStepInfo[] CreateNotebookPowerShellStep( string notebookName, string storageDatabase) { AgentJobStepInfo[] result; var assembly = Assembly.GetAssembly(typeof(AgentService)); string execNotebookScript; string notebookScriptResourcePath = "Microsoft.SqlTools.ServiceLayer.Agent.NotebookResources.NotebookJobScript.ps1"; using (Stream scriptStream = assembly.GetManifestResourceStream(notebookScriptResourcePath)) { using (StreamReader reader = new StreamReader(scriptStream)) { execNotebookScript = "$TargetDatabase = \"" + storageDatabase + "\"" + Environment.NewLine + reader.ReadToEnd(); } } result = new AgentJobStepInfo[1]; result[0] = new AgentJobStepInfo() { AppendLogToTable = false, AppendToLogFile = false, AppendToStepHist = false, Command = execNotebookScript, CommandExecutionSuccessCode = 0, DatabaseName = "", DatabaseUserName = null, FailStepId = 0, FailureAction = StepCompletionAction.QuitWithFailure, Id = 1, JobId = null, JobName = notebookName, OutputFileName = null, ProxyName = null, RetryAttempts = 0, RetryInterval = 0, Script = execNotebookScript, ScriptName = null, Server = "", StepName = "Exec-Notebook", SubSystem = AgentSubSystem.PowerShell, SuccessAction = StepCompletionAction.QuitWithSuccess, SuccessStepId = 0, WriteLogToTable = false, }; return(result); }
internal static async Task DeleteAgentJobStep( AgentService service, TestConnectionResult connectionResult, AgentJobStepInfo stepInfo) { var context = new Mock <RequestContext <ResultStatus> >(); await service.HandleDeleteAgentJobStepRequest(new DeleteAgentJobStepParams { OwnerUri = connectionResult.ConnectionInfo.OwnerUri, Step = stepInfo }, context.Object); context.VerifyAll(); }
internal static AgentJobStepInfo ConvertToAgentJobStepInfo(JobStep step, string jobId, string jobName) { AgentJobStepInfo stepInfo = new AgentJobStepInfo(); stepInfo.JobId = jobId; stepInfo.JobName = jobName; stepInfo.StepName = step.Name; stepInfo.SubSystem = step.SubSystem; stepInfo.Id = step.ID; stepInfo.FailureAction = step.OnFailAction; stepInfo.SuccessAction = step.OnSuccessAction; stepInfo.FailStepId = step.OnFailStep; stepInfo.SuccessStepId = step.OnSuccessStep; stepInfo.Command = step.Command; stepInfo.CommandExecutionSuccessCode = step.CommandExecutionSuccessCode; stepInfo.DatabaseName = step.DatabaseName; stepInfo.DatabaseUserName = step.DatabaseUserName; stepInfo.Server = step.Server; stepInfo.OutputFileName = step.OutputFileName; stepInfo.RetryAttempts = step.RetryAttempts; stepInfo.RetryInterval = step.RetryInterval; stepInfo.ProxyName = step.ProxyName; return(stepInfo); }