예제 #1
0
        public static SCOFolder[] GetAllFolders()
        {
            OrchestratorContext context = GetOrchestratorContext();

            var folders = (from f in context.Folders
                           select f);

            //Folder[] allFolders = new Folder[folders.Count()];

            //int i = 0;
            //foreach (Folder f in folders)
            //{
            //    allFolders[i] = f;
            //    i++;
            //}

            //return allFolders;

            SCOFolder[] allFolders = new SCOFolder[folders.Count()];

            int i = 0;

            foreach (Folder f in folders)
            {
                allFolders[i] = new SCOFolder(f);
                i++;
            }

            return(allFolders);
        }
예제 #2
0
        public static SCORunbook[] GetAllRunningRunbooks()
        {
            OrchestratorContext context = GetOrchestratorContext();

            Dictionary <Guid, SCORunbook> runbookDict = new Dictionary <Guid, SCORunbook>();
            var jobs = (from jb in context.Jobs
                        where jb.Status == "Running" || jb.Status == "Pending"
                        select jb);

            foreach (Job j in jobs)
            {
                var runbook = (from rb in context.Runbooks
                               where rb.Id == j.RunbookId
                               select rb).FirstOrDefault();

                if (!runbookDict.ContainsKey(runbook.Id))
                {
                    runbookDict.Add(runbook.Id, new SCORunbook(runbook));
                }
            }

            SCORunbook[] allRunbooks = new SCORunbook[runbookDict.Count];
            runbookDict.Values.CopyTo(allRunbooks, 0);
            return(allRunbooks);
        }
예제 #3
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);
        }
예제 #4
0
 private static void pollForJobCompletion(OrchestratorContext sco, Guid jobID)
 {
     try
     {
         while (!SCOrch.getJobDetails(sco, jobID).job.Status.Equals("Completed"))
         {
             System.Threading.Thread.Sleep(new TimeSpan(0, 0, 3));
         }
         JobInstance j = SCOrch.getJobDetails(sco, jobID);
         Console.WriteLine("<OutputParameters>");
         foreach (string key in j.OutputParameters.Keys)
         {
             Console.WriteLine(string.Format("\t<{0}>{1}</{0}>", key, j.OutputParameters[key]));
         }
         Console.WriteLine("</OutputParameters>");
     }
     // Allow for 1 webservice Error
     catch
     {
         sco = setupOrchestratorConnection();
         while (!SCOrch.getJobDetails(sco, jobID).job.Status.Equals("Completed"))
         {
             System.Threading.Thread.Sleep(new TimeSpan(0, 0, 3));
         }
         JobInstance j = SCOrch.getJobDetails(sco, jobID);
         Console.WriteLine("<OutputParameters>");
         foreach (string key in j.OutputParameters.Keys)
         {
             Console.WriteLine(string.Format("\t<{0}>{1}</{0}>", key, j.OutputParameters[key]));
         }
         Console.WriteLine("</OutputParameters>");
     }
 }
예제 #5
0
 private void pollForJobCompletion(OrchestratorContext sco, Guid jobID)
 {
     while (!SCOrch.getJobDetails(sco, jobID).job.Status.Equals("Completed"))
     {
         System.Threading.Thread.Sleep(new TimeSpan(0, 0, 3));
     }
 }
예제 #6
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);
        }
예제 #7
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            OrchestratorContext sco = new OrchestratorContext(new Uri(Credentials.OrchestratorServiceURL));

            sco.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password, Credentials.Domain);
            sco.MergeOption = MergeOption.OverwriteChanges;

            Runbook[] runbookArray = SCOrch.getAllRunningRunbooks(sco);

            response.WithFiltering().PublishRange(parseResults(runbookArray));
        }
예제 #8
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            OrchestratorContext sco = new OrchestratorContext(new Uri(Credentials.OrchestratorServiceURL));

            sco.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password, Credentials.Domain);
            sco.MergeOption = MergeOption.OverwriteChanges;

            RunbookServerInst[] RunbookServerArray = SCOrch.getAllRunbookServer(sco, true);

            response.WithFiltering().PublishRange(parseResults(RunbookServerArray));
            response.Publish("Number Of Runbook Servers", numberOfRunbookServer);
        }
예제 #9
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            String JobStatus = request.Inputs["Job Status"].AsString();

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

            sco.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password, Credentials.Domain);
            sco.MergeOption = MergeOption.OverwriteChanges;

            Runbook[] RunbookArray = SCOrch.getMonitorRunbook(sco, false);

            response.WithFiltering().PublishRange(parseResults(RunbookArray));
        }
예제 #10
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            String JobId = request.Inputs["Job Id"].AsString();

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

            sco.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password, Credentials.Domain);
            sco.MergeOption = MergeOption.OverwriteChanges;

            JobInstance jobInstance = SCOrch.getJobDetails(sco, new Guid(JobId));

            response.WithFiltering().PublishRange(parseResults(jobInstance));
        }
예제 #11
0
        public static Guid StartRunbookWithParameters(Guid runbookId, SCORunbookInstanceParameter[] inputParams)
        {
            //Guid runbookId = new Guid(runbookId);

            Hashtable parameterValues = new Hashtable();

            //parameterValues.Add("Param1", "This is the value for Param1.");
            //parameterValues.Add("Param2", "This is the value for Param2.");


            foreach (SCORunbookInstanceParameter inParam in inputParams)
            {
                parameterValues.Add(inParam.Name, inParam.Value);
            }

            OrchestratorContext context = GetOrchestratorContext();

            // Retrieve parameters for the runbook
            var runbookParams = context.RunbookParameters.Where(runbookParam => runbookParam.RunbookId == runbookId && runbookParam.Direction == "In");

            // Configure the XML for the parameters
            StringBuilder parametersXml = new StringBuilder();

            if (runbookParams != null && runbookParams.Count() > 0)
            {
                parametersXml.Append("<Data>");
                foreach (var param in runbookParams)
                {
                    parametersXml.AppendFormat("<Parameter><ID>{0}</ID><Value>{1}</Value></Parameter>", param.Id.ToString("B"), parameterValues[param.Name]);
                }
                parametersXml.Append("</Data>");
            }

            try
            {
                // Create new job and assign runbook Id and parameters.
                Job job = new Job();
                job.RunbookId  = runbookId;
                job.Parameters = parametersXml.ToString();

                // Add newly created job.
                context.AddToJobs(job);
                context.SaveChanges();

                return(job.Id);
            }
            catch (DataServiceQueryException ex)
            {
                throw new ApplicationException("Error starting runbook.", ex);
            }
        }
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            String RunbookIdentifier = request.Inputs["Runbook Identifier"].AsString();
            String IdentifierType    = request.Inputs["Identifier Type"].AsString();
            String jobStatus         = String.Empty;

            if (request.Inputs.Contains("Job Status"))
            {
                jobStatus = request.Inputs["Job Status"].AsString();
            }
            OrchestratorContext sco = new OrchestratorContext(new Uri(Credentials.OrchestratorServiceURL));

            sco.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password, Credentials.Domain);
            sco.MergeOption = MergeOption.OverwriteChanges;

            JobInstance[] jobInstance = new JobInstance[0];

            switch (IdentifierType)
            {
            case "Runbook Path":
                if (jobStatus.Equals(String.Empty))
                {
                    jobInstance = SCOrch.getRunbookJobInstances(sco, RunbookIdentifier);
                }
                else
                {
                    jobInstance = SCOrch.getRunbookJobInstances(sco, RunbookIdentifier, jobStatus);
                }
                break;

            case "Runbook GUID":
                Guid runbookGUID = new Guid(RunbookIdentifier);
                if (jobStatus.Equals(String.Empty))
                {
                    jobInstance = SCOrch.getRunbookJobInstances(sco, runbookGUID);
                }
                else
                {
                    jobInstance = SCOrch.getRunbookJobInstances(sco, runbookGUID, jobStatus);
                }
                break;

            default:
                response.LogErrorMessage("Must choose Runbook Path or Runbook GUID as an Identifier Type");
                break;
            }
            response.WithFiltering().PublishRange(parseResults(jobInstance));
            response.Publish("Number of Jobs", numberOfJobs);
        }
예제 #13
0
        private OrchestratorContext setupOrchestratorConnection()
        {
            OrchestratorContext sco = new OrchestratorContext(new Uri(webserverURL));

            if (alternateCredentials == null)
            {
                sco.Credentials = CredentialCache.DefaultCredentials;
            }
            else
            {
                sco.Credentials = alternateCredentials;
            }
            sco.MergeOption = MergeOption.OverwriteChanges;

            return(sco);
        }
예제 #14
0
        public static string[] GetRunbookInputParams(Guid runbookId)
        {
            OrchestratorContext context = GetOrchestratorContext();

            // Retrieve parameters
            //var runbookParams = context.RunbookParameters.Where(runbookParam => runbookParam.RunbookId == runbookId);
            var runbookParams = context.RunbookParameters.Where(runbookParam => runbookParam.RunbookId == runbookId && runbookParam.Direction == "In");

            List <string> paramNamesList = new List <string>();

            foreach (RunbookParameter param in runbookParams)
            {
                paramNamesList.Add(param.Name);
            }

            return(paramNamesList.ToArray());
        }
예제 #15
0
        /// <summary>
        /// Starts the runbook with parameters.
        /// </summary>
        /// <param name="runbookId">The runbook identifier.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>The identifier of the process.</returns>
        public Guid StartRunbookWithParameters(Guid runbookId, IDictionary <string, string> parameters)
        {
            // Create Orchestrator context
            var context = new OrchestratorContext(new Uri(_serviceRoot));

            context.Credentials = new NetworkCredential("administrator", "Password@1");

            // Retrieve parameters for the runbook
            var runbookParams = context.RunbookParameters.Where(runbookParam => runbookParam.RunbookId == runbookId && runbookParam.Direction == "In");

            // Configure the XML for the parameters
            var parametersXml = new StringBuilder();

            if (runbookParams != null && runbookParams.Count() > 0)
            {
                parametersXml.Append("<Data>");
                foreach (var param in runbookParams)
                {
                    parametersXml.AppendFormat("<Parameter><ID>{0}</ID><Value>{1}</Value></Parameter>", param.Id.ToString("B"), parameters[param.Name]);
                }
                parametersXml.Append("</Data>");
            }

            try
            {
                Job job = new Job
                {
                    RunbookId        = runbookId,
                    Parameters       = parametersXml.ToString(),
                    CreationTime     = DateTime.UtcNow,
                    LastModifiedTime = DateTime.UtcNow
                };

                context.AddToJobs(job);
                context.SaveChanges();

                return(job.Id);
            }
            catch (DataServiceQueryException ex)
            {
                throw new ApplicationException("Error starting runbook.", ex);
            }
        }
예제 #16
0
        private static OrchestratorContext setupOrchestratorConnection()
        {
            OrchestratorContext sco = new OrchestratorContext(new Uri(WEBSERVICE_URL));

            if (useAltCreds)
            {
                NetworkCredential credentials = new NetworkCredential();
                credentials.UserName = username;
                credentials.Domain   = domain;
                credentials.Password = password;
                sco.Credentials      = credentials;
            }
            else
            {
                sco.Credentials = CredentialCache.DefaultCredentials;
            }
            sco.MergeOption = MergeOption.OverwriteChanges;
            return(sco);
        }
예제 #17
0
        public OrchestratorProvider(NetworkCredential creds, string serviceUri)
        {
            Uri serviceRoot = new Uri(serviceUri);

            _context             = new OrchestratorContext(serviceRoot);
            _context.Credentials = creds;
            _creds = creds;
            //_runbooks = _context.Runbooks.ToList();
            _context.MergeOption = MergeOption.OverwriteChanges;
            int i   = 0;
            var rbs = _context.Runbooks.Skip(i * 50).Take(50);

            _runbooks = new List <Runbook>();
            while (rbs.Count() != 0)
            {
                _runbooks.AddRange(rbs.ToList());
                i++;
                rbs = _context.Runbooks.Skip(i * 50).Take(50);
            }
        }
예제 #18
0
        public static SCOJobInstance[] GetRunbookJobInstances(String runbookPath, String runbookName)
        {
            OrchestratorContext context = GetOrchestratorContext();

            ArrayList jInstanceArrayList = new ArrayList();

            SCOJobInstance[] jInstances;

            var runbook = (from rb in context.Runbooks
                           where rb.Path == runbookPath &&
                           rb.Name == runbookName
                           select rb).FirstOrDefault();

            if (runbook == null)
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "Runbook Not Found:  ", runbookPath);
                throw new Exception(msg);
            }

            var jobs = (from jb in context.Jobs
                        where jb.RunbookId == runbook.Id
                        select jb);

            if (jobs == null)
            {
                if (runbook == null)
                {
                    var msg = string.Format(CultureInfo.InvariantCulture, "Jobs not found for Runbook:  ", runbookPath);
                    throw new Exception(msg);
                }
            }
            foreach (Job j in jobs)
            {
                jInstanceArrayList.Add(GetJobDetails(j.Id));
            }

            jInstances = new SCOJobInstance[jInstanceArrayList.Count];
            jInstanceArrayList.CopyTo(jInstances);
            return(jInstances);
        }
예제 #19
0
        public void Design(IActivityDesigner designer)
        {
            OrchestratorContext sco = new OrchestratorContext(new Uri(Credentials.OrchestratorServiceURL));

            sco.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password, Credentials.Domain);
            sco.MergeOption = MergeOption.OverwriteChanges;

            string[] SummaryString = SCOrch.getOrchestartorEventSummaries(sco);

            if (SummaryString.Length > 0)
            {
                designer.AddFilter("Summary").WithRelations(Relation.Contains | Relation.EqualTo).WithListBrowser(SummaryString);
            }
            else
            {
                designer.AddFilter("Summary").WithRelations(Relation.Contains | Relation.EqualTo);
            }

            designer.AddFilter("CreationTime").WithRelations(Relation.After | Relation.Before);

            designer.AddCorellatedData(typeof(EventInst));
            designer.AddOutput("Number of Events");
        }
예제 #20
0
        public static SCORunbook[] GetAllRunbooks()
        {
            OrchestratorContext context = GetOrchestratorContext();

            var runbooks = from runbook in context.Runbooks
                           select runbook;

            //foreach (var item in runbooks)
            //{
            //    int index = Array.IndexOf(runbooks.ToArray(), item);
            //}

            List <SCORunbook> rbList = new List <SCORunbook>();

            foreach (Runbook rb in runbooks)
            {
                SCORunbook item = new SCORunbook();
                item.Name = rb.Name;
                item.Id   = rb.Id;
                rbList.Add(item);
            }

            return(rbList.ToArray());
        }
예제 #21
0
        public static SCORunbook[] GetAllRunbooksInFolder(String FolderPath)
        {
            OrchestratorContext context = GetOrchestratorContext();

            var folder = (from fol in context.Folders
                          where fol.Path == FolderPath
                          select fol).FirstOrDefault();

            if (folder == null)
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "Runbooks Not Found in Folder:  ", FolderPath);
                throw new Exception(msg);
            }

            Guid folderId = folder.Id;

            var runbooks = (from rb in context.Runbooks
                            where rb.FolderId == folderId
                            select rb);

            if (runbooks == null)
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "Runbooks Not Found in Folder:  ", FolderPath);
                throw new Exception(msg);
            }
            SCORunbook[] runbookArray = new SCORunbook[runbooks.Count()];
            int          i            = 0;

            foreach (Runbook r in runbooks)
            {
                runbookArray[i] = new SCORunbook(r);
                i++;
            }

            return(runbookArray);
        }
예제 #22
0
        private async Task <ICommandResult <TResult> > Handle <TPayload, TResult>(IDurableClient durableClient, OrchestratorContext orchestratorContext, ICommand <TPayload, TResult> command, string orchestrationName)
            where TPayload : new()
            where TResult : new()
        {
            var instanceId = await durableClient
                             .StartNewAsync <object>(orchestrationName, command.CommandId.ToString(), (orchestratorContext, command))
                             .ConfigureAwait(false);

            var status = await durableClient
                         .GetStatusAsync(instanceId)
                         .ConfigureAwait(false);

            return(status?.GetResult <TResult>());
        }
예제 #23
0
        public static SCOJobInstance StopRunbookJob(Guid JobId)
        {
            OrchestratorContext context = GetOrchestratorContext();

            var jobId = JobId;

            var job = (from j in context.Jobs
                       where j.Id == jobId
                       select j).FirstOrDefault();

            if (job == null)
            {
                var msg = string.Format(CultureInfo.InvariantCulture, "Job Not Found: ", jobId);
                throw new Exception(msg);
            }

            List <SCORunbookInstanceParameter> jobOutput = new List <SCORunbookInstanceParameter>();
            List <SCORunbookInstanceParameter> jobInput  = new List <SCORunbookInstanceParameter>();

            if (job.Status.Equals("Completed", StringComparison.OrdinalIgnoreCase))
            {
                // Get the return data
                var instances = context.RunbookInstances.Where(ri => ri.JobId == jobId);

                // For the non-monitor runbook job, there should be only one instance.
                foreach (var instance in instances)
                {
                    if (!instance.Status.Equals("Success", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    var outParameters = context.RunbookInstanceParameters.Where(
                        rip => rip.RunbookInstanceId == instance.Id && rip.Direction.Equals("Out", StringComparison.OrdinalIgnoreCase));

                    foreach (var parameter in outParameters)
                    {
                        SCORunbookInstanceParameter newParam = new SCORunbookInstanceParameter();
                        newParam.Name  = parameter.Name;
                        newParam.Value = parameter.Value;

                        jobOutput.Add(newParam);
                    }

                    var inParameters = context.RunbookInstanceParameters.Where(
                        rip => rip.RunbookInstanceId == instance.Id && rip.Direction.Equals("In", StringComparison.OrdinalIgnoreCase));

                    foreach (var parameter in inParameters)
                    {
                        SCORunbookInstanceParameter newParam = new SCORunbookInstanceParameter();
                        newParam.Name  = parameter.Name;
                        newParam.Value = parameter.Value;

                        jobInput.Add(newParam);
                    }
                }
            }
            else
            {
                // Get the return data
                var instances = context.RunbookInstances.Where(ri => ri.JobId == jobId);

                foreach (var instance in instances)
                {
                    var inParameters = context.RunbookInstanceParameters.Where(
                        rip => rip.RunbookInstanceId == instance.Id && rip.Direction.Equals("In", StringComparison.OrdinalIgnoreCase));

                    foreach (var parameter in inParameters)
                    {
                        SCORunbookInstanceParameter newParam = new SCORunbookInstanceParameter();
                        newParam.Name  = parameter.Name;
                        newParam.Value = parameter.Value;

                        jobInput.Add(newParam);
                    }
                }

                // Set <Status> to "Canceled" (this is what stops the Job)
                job.Status = "Canceled";
                context.UpdateObject(job);
                context.SaveChanges();
            }

            SCOJobInstance jInstance = new SCOJobInstance()
            {
                Job = new SCOJob(job), InputParameters = jobInput.ToArray(), OutputParameters = jobOutput.ToArray()
            };

            return(jInstance);
        }
예제 #24
0
        public void Design(IActivityDesigner designer)
        {
            string[] RunbookServerNames = new string[0];

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

                sco.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password, Credentials.Domain);
                sco.MergeOption = MergeOption.OverwriteChanges;

                RunbookServerInst[] allRunbookServers = SCOrch.getAllRunbookServer(sco, false);

                RunbookServerNames = new string[allRunbookServers.Count()];

                int b = 0;
                foreach (RunbookServerInst r in allRunbookServers)
                {
                    try
                    {
                        RunbookServerNames[b] = r.server.Name;
                        b++;
                    }
                    catch { }
                }
            }
            catch { }

            designer.AddInput("Runbook Identifier").WithDefaultValue(@"\ParentFolder\ContainingFolder\Runbook Name");
            designer.AddInput("Identifier Type").WithDefaultValue(@"Runbook Path").WithListBrowser(new string[] { "Runbook Path", "Runbook GUID" });
            designer.AddInput("Wait for Exit").WithDefaultValue("True").WithListBrowser(new string[] { "True", "False" });
            if (RunbookServerNames.Length > 0)
            {
                designer.AddInput("Runbook Server Name").WithDefaultValue(RunbookServerNames[0]).WithListBrowser(RunbookServerNames).NotRequired();
            }
            else
            {
                designer.AddInput("Runbook Server Name").NotRequired();
            }
            designer.AddInput("Alternate User Name").NotRequired();
            designer.AddInput("Alternate User Domain").NotRequired();

            designer.AddInput("Password").NotRequired();


            for (int i = 0; i < Credentials.MaxInputParameters; i++)
            {
                if (i < 10)
                {
                    designer.AddInput("0" + i.ToString() + "_ParameterName").NotRequired();
                    designer.AddInput("0" + i.ToString() + "_ParameterValue").NotRequired();
                }
                else
                {
                    designer.AddInput(i.ToString() + "_ParameterName").NotRequired();
                    designer.AddInput(i.ToString() + "_ParameterValue").NotRequired();
                }
            }

            designer.AddCorellatedData(typeof(JobDetails));
        }
예제 #25
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));
        }
예제 #26
0
        public void Execute(IActivityRequest request, IActivityResponse response)
        {
            String   Summary         = String.Empty;
            String   SummaryCriteria = String.Empty;
            DateTime MinCreationDate = DateTime.MinValue;
            DateTime MaxCreationDate = DateTime.MaxValue;

            foreach (IFilterCriteria filter in request.Filters)
            {
                switch (filter.Name)
                {
                case "CreationTime":
                    switch (filter.Relation)
                    {
                    case Relation.After:
                        MinCreationDate = Convert.ToDateTime(filter.Value.AsString());
                        break;

                    case Relation.Before:
                        MaxCreationDate = Convert.ToDateTime(filter.Value.AsString());
                        break;
                    }
                    break;

                case "Summary":
                    Summary = filter.Value.AsString();
                    switch (filter.Relation)
                    {
                    case Relation.Contains:
                        SummaryCriteria = "Contains";
                        break;

                    case Relation.EqualTo:
                        SummaryCriteria = "Equals";
                        break;
                    }
                    break;

                default:
                    break;
                }
            }



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

            sco.Credentials = new NetworkCredential(Credentials.UserName, Credentials.Password, Credentials.Domain);
            sco.MergeOption = MergeOption.OverwriteChanges;

            Event[] eventArray = null;

            if (Summary.Equals(String.Empty))
            {
                eventArray = SCOrch.getOrchestartorEvents(sco, MinCreationDate, MaxCreationDate);
            }
            else
            {
                eventArray = SCOrch.getOrchestartorEvents(sco, MinCreationDate, MaxCreationDate, Summary, SummaryCriteria);
            }


            response.WithFiltering().PublishRange(parseResults(eventArray));
            response.Publish("Number of Events", numberOfEvents);
        }
예제 #27
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);
            }
        }
예제 #28
0
 protected override void BeginProcessing()
 {
     sco = setupOrchestratorConnection();
 }
예제 #29
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "command")] HttpRequest httpRequest,
            [DurableClient] IDurableClient durableClient,
            ILogger logger)
        {
            if (httpRequest is null)
            {
                throw new ArgumentNullException(nameof(httpRequest));
            }

            if (durableClient is null)
            {
                throw new ArgumentNullException(nameof(durableClient));
            }

            var requestBody = await new StreamReader(httpRequest.Body)
                              .ReadToEndAsync()
                              .ConfigureAwait(false);

            var command = JsonConvert.DeserializeObject <ICommand>(requestBody);

            var teamCloud = await teamCloudRepository
                            .GetAsync()
                            .ConfigureAwait(false);

            var orchestratorContext = new OrchestratorContext(teamCloud);

            if (command.ProjectId.HasValue)
            {
                var project = await projectsRepository
                              .GetAsync(command.ProjectId.Value)
                              .ConfigureAwait(false);

                orchestratorContext.Project = project;
            }

            switch (command)
            {
            case ProjectCreateCommand projectCreateCommand:
                var projectCreateCommandResult = await Handle(durableClient, orchestratorContext, projectCreateCommand, nameof(ProjectCreateOrchestration))
                                                 .ConfigureAwait(false);

                return(new OkObjectResult(projectCreateCommandResult));

            case ProjectUpdateCommand projectUpdateCommand:
                var projectUpdateCommandResult = await Handle(durableClient, orchestratorContext, projectUpdateCommand, nameof(ProjectCreateOrchestration))
                                                 .ConfigureAwait(false);

                return(new OkObjectResult(projectUpdateCommandResult));

            case ProjectDeleteCommand projectDeleteCommand:
                var projectDeleteCommandResult = await Handle(durableClient, orchestratorContext, projectDeleteCommand, nameof(ProjectDeleteOrchestration))
                                                 .ConfigureAwait(false);

                return(new ObjectResult(projectDeleteCommandResult));

            case ProjectUserCreateCommand projectUserCreateCommand:
                var projectUserCreateCommandResult = await Handle(durableClient, orchestratorContext, projectUserCreateCommand, nameof(ProjectUserCreateOrchestration))
                                                     .ConfigureAwait(false);

                return(new OkObjectResult(projectUserCreateCommandResult));

            case ProjectUserUpdateCommand projectUserUpdateCommand:
                var projectUserUpdateCommandResult = await Handle(durableClient, orchestratorContext, projectUserUpdateCommand, nameof(ProjectUserCreateOrchestration))
                                                     .ConfigureAwait(false);

                return(new OkObjectResult(projectUserUpdateCommandResult));

            case ProjectUserDeleteCommand projectUserDeleteCommand:
                var projectUserDeleteCommandResult = await Handle(durableClient, orchestratorContext, projectUserDeleteCommand, nameof(ProjectUserDeleteOrchestration))
                                                     .ConfigureAwait(false);

                return(new OkObjectResult(projectUserDeleteCommandResult));

            case TeamCloudCreateCommand teamCloudCreateCommand:
                var teamCloudCreateCommandResult = await Handle(durableClient, orchestratorContext, teamCloudCreateCommand, nameof(TeamCloudCreateOrchestration))
                                                   .ConfigureAwait(false);

                return(new OkObjectResult(teamCloudCreateCommandResult));

            case TeamCloudUserCreateCommand teamCloudUserCreateCommand:
                var teamCloudUserCreateCommandResult = await Handle(durableClient, orchestratorContext, teamCloudUserCreateCommand, nameof(TeamCloudUserCreateOrchestration))
                                                       .ConfigureAwait(false);

                return(new OkObjectResult(teamCloudUserCreateCommandResult));

            case TeamCloudUserUpdateCommand teamCloudUserUpdateCommand:
                var teamCloudUserUpdateCommandResult = await Handle(durableClient, orchestratorContext, teamCloudUserUpdateCommand, nameof(TeamCloudUserCreateOrchestration))
                                                       .ConfigureAwait(false);

                return(new OkObjectResult(teamCloudUserUpdateCommandResult));

            case TeamCloudUserDeletCommand teamCloudUserDeletCommand:
                var teamCloudUserDeletCommandResult = await Handle(durableClient, orchestratorContext, teamCloudUserDeletCommand, nameof(TeamCloudUserDeleteOrchestration))
                                                      .ConfigureAwait(false);

                return(new OkObjectResult(teamCloudUserDeletCommandResult));
            }

            return(new NotFoundResult());
        }