public void AddAction(SMVAction action, SMVActionCompleteCallBack callback, object context)
        {
            Log.LogDebug("Reached Add Action of Local " + action.GetFullName());
            var entry = new ActionsQueueEntry(action, callback, context);

            actionsQueue.Enqueue(entry);
        }
Beispiel #2
0
 public ActionsQueueEntry(SMVAction action, SMVActionCompleteCallBack callback, object context)
 {
     this.Action   = action;
     this.Callback = callback;
     this.Context  = context;
     this.Results  = new List <SMVActionResult>();
 }
Beispiel #3
0
        /// <summary>
        /// Helper function that calls adds an array of actions to Utitlity.scheduler, waits until they all complete
        /// and returns the results. Call Utility.scheduler.AddAction() directory for finer-grained control.
        /// </summary>
        /// <param name="actions">The list of actions to be executed.</param>
        /// <returns>The list of results of the actions that were executed.</returns>
        public static List <SMVActionResult> ExecuteActions(SMVAction[] actions, SMVActionCompleteCallBack callback = null)
        {
            var waitHandle = new CountdownEvent(actions.Length);

            actionResults = new List <SMVActionResult>();
            if (callback == null)
            {
                callback = new SMVActionCompleteCallBack(DoneExecuteAction);
            }

            foreach (SMVAction action in actions)
            {
                if (action.variables == null)
                {
                    action.variables = new Dictionary <string, string>(Utility.smvVars);
                }
                if (!string.IsNullOrEmpty(action.analysisProperty))
                {
                    action.variables["analysisProperty"] = action.analysisProperty;
                }
                Utility.scheduler.AddAction(action, callback, waitHandle);
            }

            waitHandle.Wait();
            return(actionResults);
        }
Beispiel #4
0
        public void AddAction(SMVAction action, SMVActionCompleteCallBack callback, object context)
        {
            try
            {
                Log.LogDebug("Reached AddAction of cloud" + action.GetFullName());
                Log.LogDebug("Adding action " + action.GetFullName());
                string actionGuid = Guid.NewGuid().ToString();
                // Upload action directory to blob storage.

                string actionPath = Utility.GetActionDirectory(action);
                string zipPath    = Path.Combine(Path.GetTempPath(), actionGuid);
                if (File.Exists(zipPath))
                {
                    File.Delete(zipPath);
                }
                ZipFile.CreateFromDirectory(actionPath, zipPath);
                Log.LogDebug("Created zip for " + actionPath);

                CloudBlockBlob blob = inputContainer.GetBlockBlobReference(actionGuid + ".zip");
                blob.UploadFromFile(zipPath);
                File.Delete(zipPath);
                Log.LogDebug("Uploaded blob " + blob.Name);

                // Add entry to table storage.

                // TODO: Due to constraints on sizes of properties in Azure table entities, serializedAction cannot be larger
                // than 64kB. Fix this if this becomes an issue.
                byte[]            serializedAction = Utility.ObjectToByteArray(action);
                string            moduleHash       = string.Empty;
                ActionsTableEntry entry            = new ActionsTableEntry(action.name, actionGuid, schedulerInstanceGuid, serializedAction,
                                                                           Utility.version, null, moduleHash);
                tableDataSource.AddEntry(entry);

                Log.LogDebug("Added to table " + entry.PartitionKey + "," + entry.RowKey);
                CloudMessage cloudMessage = new CloudMessage();
                cloudMessage.schedulerInstanceGuid = schedulerInstanceGuid;
                cloudMessage.actionGuid            = actionGuid;
                cloudMessage.maxDequeueCount       = maxDequeueCount;
                cloudMessage.useDb  = Utility.useDb;
                cloudMessage.taskId = Utility.taskId;

                string messageString = JsonConvert.SerializeObject(cloudMessage);
                // Add message to queue.
                //Log.LogInfo("Executing: " + action.GetFullName() + " [cloud id:" + actionGuid + "]");
                //string messageString = schedulerInstanceGuid + "," + actionGuid + "," + maxDequeueCount;
                var message = new CloudQueueMessage(messageString);
                actionsQueue.AddMessage(message);

                Log.LogDebug("Adding to queue " + message.Id);

                contextDictionary[actionGuid] = new CloudActionCompleteContext(action, callback, context);

                Log.LogDebug("Done adding.");
            } catch (Exception e)
            {
                Utility.scheduler.Dispose();
                Log.LogFatalError(e.ToString());
            }
        }
        public void AddAction(SMVAction action, SMVActionCompleteCallBack callback, object context)
        {
            if (!action.executeOn.Equals(Utility.schedulerType))
            {
                action.executeOn = "local";
            }
            Log.LogDebug("Queuing action: " + action.GetFullName() + " on " + action.executeOn);
            var entry = new ActionsQueueEntry(action, callback, context);

            actionsQueue.Enqueue(entry);
            counters.AddOrUpdate("queued", 1, (k, v) => v + 1);
        }
Beispiel #6
0
        public void AddAction(SMVAction action, SMVActionCompleteCallBack callback, object context)
        {
            var entry = new ActionsQueueEntry(action, callback, context);

            actionsQueue.Enqueue(entry);
        }
Beispiel #7
0
 public CloudActionCompleteContext(SMVAction _action, SMVActionCompleteCallBack _callback, object _context)
 {
     action   = _action;
     callback = _callback;
     context  = _context;
 }
        /// <summary>
        /// This callback function is called once an action and all its children have executed.
        /// </summary>
        /// <param name="results">A list of results, one for each action (the action added to the queue and its children).</param>
        /// <param name="context">A context object.</param>
        private void ActionComplete(SMVAction a, IEnumerable <SMVActionResult> results, object context)
        {
            var       entry  = context as ActionsQueueEntry;
            SMVAction action = entry.Action;
            SMVActionCompleteCallBack callback = entry.Callback;

            try
            {
                if (action.result == null)
                {
                    action.result = new SMVActionResult(action.name, "NO OUTPUT?", false, false, 0);
                }

                entry.Results.AddRange(results);
                counters.AddOrUpdate("completed", 1, (k, v) => v + 1);
                times.Add(action.result.time);

                File.WriteAllText(Path.Combine(Utility.GetActionDirectory(action), "smvstats.txt"),
                                  string.Format("Time: {0}", action.result.time));

                // Add result to our global result set.
                string result = "Failed";
                if (action.result != null && action.result.isSuccessful)
                {
                    result = "Success";
                }
                // Otherwise, add the next action to the queue, if any.
                else
                {
                    errorsEncountered = true;
                }
                lock (Utility.lockObject)
                {
                    Utility.result[action.GetFullName()] = result;
                }

                // If there was an error, simply call the callback function with whatever results we have, the callback is
                // expected to handle the errors by looking at the list of results.
                if (action.result == null || action.result.breakExecution || !action.result.isSuccessful)
                {
                    entry.Callback(action, entry.Results, entry.Context);
                }
                // Otherwise, add the next action to the queue, if any.
                else
                {
                    SMVAction nextAction = Utility.GetNextAction(action);
                    if (nextAction != null)
                    {
                        nextAction.analysisProperty = action.analysisProperty;

                        DebugUtility.DumpVariables(entry.Action.variables, "entry.action");
                        DebugUtility.DumpVariables(Utility.smvVars, "smvvars");

                        nextAction.variables = Utility.smvVars.Union(entry.Action.variables).ToDictionary(g => g.Key, g => g.Value);
                        this.AddAction(nextAction, entry.Callback, entry.Context);
                    }
                    else
                    {
                        entry.Callback(action, entry.Results, entry.Context);
                    }
                }
            }
            catch (Exception e)
            {
                Log.LogError("Error processing finalization for action " + action.GetFullName());

                action.result.output = e.ToString();
                entry.Callback(action, entry.Results, entry.Context);
            }

            // upate status line
            if (updateStatusMode)
            {
                string resultString = string.Format("\r[INFO] {0} of {1} jobs remaining. Avg(s): {2}. Std.Dev(s): {3}",
                                                    counters["queued"] - counters["completed"], counters["queued"],
                                                    times.Average().ToString("F2"),
                                                    Math.Sqrt(times.Average(v => Math.Pow(v - times.Average(), 2))).ToString("F2"));
                Console.Write(resultString);
                if (counters["queued"] == counters["completed"])
                {
                    Console.WriteLine();
                }
            }
        }