Exemplo n.º 1
0
        private static bool runRunbook()
        {
            bool status             = true;
            OrchestratorContext sco = setupOrchestratorConnection();
            string jobID;

            try
            {
                if (!String.IsNullOrEmpty(RUNBOOK_PATH))
                {
                    jobID = Convert.ToString(((Job)SCOrch.startRunbookJob(sco, RUNBOOK_PATH, INPUT_RUNBOOK_PARAMETERS)).Id);
                }
                else if (!String.IsNullOrEmpty(RUNBOOK_PATH))
                {
                    jobID = Convert.ToString(((Job)SCOrch.startRunbookJob(sco, new Guid(RUNBOOK_GUID), INPUT_RUNBOOK_PARAMETERS)).Id);
                }
                else
                {
                    Console.WriteLine("Must pass either -RunbookPath or -RunbookGUID"); return(false);
                }

                if (waitForExit)
                {
                    pollForJobCompletion(sco, new Guid(jobID));
                }
            }
            // If webservice isn't available attempt 1 try again
            catch
            {
                throw;
            }
            return(status);
        }
Exemplo n.º 2
0
        private static bool runRunbook()
        {
            bool status             = true;
            OrchestratorContext sco = setupOrchestratorConnection();

            OrchestratorInterop.SCOrchestrator.Job job;
            try
            {
                if (string.IsNullOrEmpty(TargetRunbookServer))
                {
                    if (!String.IsNullOrEmpty(RunbookPath))
                    {
                        job = SCOrch.startRunbookJob(sco, RunbookPath, _InputParameters);
                    }
                    else if (!String.IsNullOrEmpty(RunbookGUID))
                    {
                        job = SCOrch.startRunbookJob(sco, new Guid(RunbookGUID), _InputParameters);
                    }
                    else
                    {
                        throw new Exception("Must pass either -RunbookPath or -RunbookGUID");
                    }
                }
                else
                {
                    if (!String.IsNullOrEmpty(RunbookPath))
                    {
                        job = SCOrch.startRunbookJob(sco, RunbookPath, TargetRunbookServer, _InputParameters);
                    }
                    else if (!String.IsNullOrEmpty(RunbookGUID))
                    {
                        job = SCOrch.startRunbookJob(sco, new Guid(RunbookGUID), TargetRunbookServer, _InputParameters);
                    }
                    else
                    {
                        throw new Exception("Must pass either -RunbookPath or -RunbookGUID");
                    }
                }

                if (WaitForExit)
                {
                    pollForJobCompletion(sco, job.Id);
                }
                else
                {
                    JobInstance ji = new JobInstance();
                    ji.job = job;
                    // WriteObject(ji);
                }
            }
            catch
            {
                throw;
            }
            return(status);
        }
Exemplo n.º 3
0
        protected override void ProcessRecord()
        {
            String exceptionMessage = String.Empty;
            bool   finished         = false;

            int internalCounter = 0;

            while (internalCounter < RetryCount && !finished)
            {
                sco = setupOrchestratorConnection();
                OrchestratorInterop.SCOrchestrator.Job job;
                try
                {
                    switch (ParameterSetName)
                    {
                    case "Runbook":
                        if (RunbookServer.Equals(String.Empty))
                        {
                            job = SCOrch.startRunbookJob(sco, Runbook.Id, HashtableToDictionary(_InputParameters));
                        }
                        else
                        {
                            job = SCOrch.startRunbookJob(sco, Runbook.Id, RunbookServer, HashtableToDictionary(_InputParameters));
                        }
                        break;

                    case "RunbookGuid":
                        if (RunbookServer.Equals(String.Empty))
                        {
                            job = SCOrch.startRunbookJob(sco, RunbookGuid, HashtableToDictionary(_InputParameters));
                        }
                        else
                        {
                            job = SCOrch.startRunbookJob(sco, RunbookGuid, RunbookServer, HashtableToDictionary(_InputParameters));
                        }

                        break;

                    default:
                    case "RunbookPath":
                        if (RunbookServer.Equals(String.Empty))
                        {
                            job = SCOrch.startRunbookJob(sco, RunbookPath, HashtableToDictionary(_InputParameters));
                        }
                        else
                        {
                            job = SCOrch.startRunbookJob(sco, RunbookPath, RunbookServer, HashtableToDictionary(_InputParameters));
                        }
                        break;
                    }

                    if (WaitForExit.IsPresent)
                    {
                        pollForJobCompletion(sco, job.Id);
                        WriteObject(SCOrch.getJobDetails(sco, job.Id));
                    }
                    else
                    {
                        WriteObject(new JobInstance()
                        {
                            job = job
                        });
                    }

                    finished = true;
                }
                catch (Exception e)
                {
                    exceptionMessage = String.Format("Summary: {0}\nDetails: {1}", e.Message, e.InnerException);
                    if (exceptionMessage.Contains("Summary: No Input Parameter on Runbook Found for Key:"))
                    {
                        throw new Exception(exceptionMessage);
                    }
                    else if (exceptionMessage.Equals("Must pass either -RunbookPath or -RunbookGUID"))
                    {
                        throw new Exception(exceptionMessage);
                    }
                    else if (exceptionMessage.Contains("Runbook Not Found:  "))
                    {
                        throw new Exception(exceptionMessage);
                    }
                    else if (exceptionMessage.Contains("The requested operation requires Publish permissions on the Runbook"))
                    {
                        throw new Exception(exceptionMessage);
                    }

                    internalCounter++;
                    Thread.Sleep(new TimeSpan(0, 0, RetryDelay));
                }
            }

            if (internalCounter >= RetryCount)
            {
                throw new Exception(exceptionMessage);
            }
        }
Exemplo n.º 4
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            String RunbookIdentifier = request.Inputs["Runbook Identifier"].AsString();
            String IdentifierType    = request.Inputs["Identifier Type"].AsString();
            String WaitForExit       = request.Inputs["Wait For Exit"].AsString();

            String RunbookServerName = String.Empty;

            String altUserName   = String.Empty;
            String altUserDomain = String.Empty;
            String altPassword   = String.Empty;

            if (request.Inputs.Contains("Alternate User Name") && request.Inputs.Contains("Alternate User Domain") && request.Inputs.Contains("Password"))
            {
                altPassword   = request.Inputs["Password"].AsString();
                altUserDomain = request.Inputs["Alternate User Domain"].AsString();
                altUserName   = request.Inputs["Alternate User Name"].AsString();
            }

            if (request.Inputs.Contains("Runbook Server Name"))
            {
                RunbookServerName = request.Inputs["Runbook Server Name"].AsString();
            }

            Dictionary <string, string> ParameterList = new Dictionary <string, string>();

            for (int i = 0; i < Credentials.MaxInputParameters; i++)
            {
                if (i < 10)
                {
                    if (request.Inputs.Contains("0" + i.ToString() + "_ParameterName") && request.Inputs.Contains("0" + i.ToString() + "_ParameterValue"))
                    {
                        string paramName  = request.Inputs["0" + i.ToString() + "_ParameterName"].AsString();
                        string paramValue = request.Inputs["0" + i.ToString() + "_ParameterValue"].AsString();

                        ParameterList.Add(paramName, paramValue);
                    }
                }
                else
                {
                    if (request.Inputs.Contains(i.ToString() + "_ParameterName") && request.Inputs.Contains(i.ToString() + "_ParameterValue"))
                    {
                        string paramName  = request.Inputs["0" + i.ToString() + "_ParameterName"].AsString();
                        string paramValue = request.Inputs["0" + i.ToString() + "_ParameterValue"].AsString();

                        ParameterList.Add(paramName, paramValue);
                    }
                }
            }

            OrchestratorContext sco = new OrchestratorContext(new Uri(Credentials.OrchestratorServiceURL));

            if (altUserName.Equals(String.Empty))
            {
                sco.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password, Credentials.Domain);
            }
            else
            {
                sco.Credentials = new NetworkCredential(altUserName, altPassword, altUserDomain);
            }
            sco.MergeOption = MergeOption.OverwriteChanges;

            Guid jobInstanceGUID = Guid.NewGuid();

            if (RunbookServerName.Equals(String.Empty))
            {
                switch (IdentifierType.ToUpper())
                {
                case "RUNBOOK PATH":
                    jobInstanceGUID = ((Job)SCOrch.startRunbookJob(sco, RunbookIdentifier, ParameterList)).Id;
                    break;

                case "RUNBOOK GUID":
                    Guid runbookGUID = new Guid(RunbookIdentifier);
                    jobInstanceGUID = ((Job)SCOrch.startRunbookJob(sco, runbookGUID, ParameterList)).Id;
                    break;

                default:
                    jobInstanceGUID = ((Job)SCOrch.startRunbookJob(sco, RunbookIdentifier, ParameterList)).Id;
                    break;
                }
            }
            else
            {
                switch (IdentifierType.ToUpper())
                {
                case "RUNBOOK PATH":
                    jobInstanceGUID = ((Job)SCOrch.startRunbookJob(sco, RunbookIdentifier, RunbookServerName, ParameterList)).Id;
                    break;

                case "RUNBOOK GUID":
                    Guid runbookGUID = new Guid(RunbookIdentifier);
                    jobInstanceGUID = ((Job)SCOrch.startRunbookJob(sco, runbookGUID, RunbookServerName, ParameterList)).Id;
                    break;

                default:
                    jobInstanceGUID = ((Job)SCOrch.startRunbookJob(sco, RunbookIdentifier, RunbookServerName, ParameterList)).Id;
                    break;
                }
            }

            if (WaitForExit.Equals("True"))
            {
                JobInstance ji = SCOrch.getJobDetails(sco, jobInstanceGUID);
                while (!(ji.job.Status.Equals("Completed") || ji.job.Status.Equals("Canceled") || ji.job.Status.Equals("Failed")))
                {
                    System.Threading.Thread.Sleep(new TimeSpan(0, 0, 3));
                    ji = SCOrch.getJobDetails(sco, jobInstanceGUID);
                }
            }

            JobInstance jobInstance = SCOrch.getJobDetails(sco, jobInstanceGUID);

            response.WithFiltering().PublishRange(parseResults(jobInstance));
        }