Beispiel #1
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)
        {
            Log.LogDebug("Reached Add Action of Local " + action.GetFullName());
            var entry = new ActionsQueueEntry(action, callback, context);

            actionsQueue.Enqueue(entry);
        }
        /// <summary>
        /// This function runs in its own thread, dequeueing actions from the actions queue and sending them to the
        /// appropriate scheduler.
        /// </summary>
        private void Execute()
        {
            while (!done)
            {
                ActionsQueueEntry entry;
                while (!done && actionsQueue.TryDequeue(out entry))
                {
                    SMVAction action        = entry.Action;
                    string    schedulerType = action.executeOn;

                    if (!schedulers.ContainsKey(schedulerType))
                    {
                        Log.LogFatalError("Could not find scheduler of type: " + schedulerType +
                                          " while executing action " + action.name);
                    }
                    else
                    {
                        Log.LogDebug("scheduler found for " + schedulerType);
                        ISMVActionScheduler scheduler = schedulers[schedulerType];
                        lock (Utility.lockObject)
                        {
                            Utility.result.Add(action.GetFullName(), "Skipped");
                        }
                        scheduler.AddAction(action, new SMVActionCompleteCallBack(ActionComplete), entry);
                    }
                }
                System.Threading.Thread.Sleep(2000);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Call back used by ExecuteActions().
        /// </summary>
        /// <param name="results"></param>
        /// <param name="context"></param>
        static void DoneExecuteAction(SMVAction action, IEnumerable <SMVActionResult> results, object context)
        {
            Log.LogDebug("Reached DoneExecuteAction for " + action.GetFullName());
            actionResults.AddRange(results);

            var countDownEvent = context as CountdownEvent;

            countDownEvent.Signal();
        }
        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);
        }
        /// <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();
                }
            }
        }