Esempio n. 1
0
        public static int CreateRepairTask(string[] args)
        {
            const string DefaultRepairTaskIdFormat = "InfrastructureService/{0}";

            string repairTaskId = string.Format(CultureInfo.InvariantCulture, DefaultRepairTaskIdFormat, Guid.NewGuid());

            var nodeNames = args[1].Split(new[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
            var action    = args[2];

            var repairTask = new ClusterRepairTask(repairTaskId, action) // TODO
            {
                Description = "Manual repair task for testing",
                Target      = new NodeRepairTargetDescription(nodeNames)
            };

            var activityLogger = new ActivityLoggerFactory().Create(Constants.TraceType);
            var rm             = new ServiceFabricRepairManagerFactory(
                new CoordinatorEnvironment(
                    "fabric:/System/InfrastructureService",
                    new ConfigSection(Constants.TraceType, new MockConfigStore(), "ConfigSection"),
                    Constants.TraceTypeName,
                    new MockInfrastructureAgentWrapper()),
                activityLogger,
                new [] { "paralleljobs1-bn-cs.cloudapp.net:19000" }).Create();

            long status = rm.CreateRepairTaskAsync(Guid.NewGuid(), new ServiceFabricRepairTask(repairTask)).GetAwaiter().GetResult();

            return((int)status);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates Repair task for a node with executor set as Patch Orchestration Service
        /// </summary>
        /// <param name="fc">Fabric client object used for carrying out service fabric client requests</param>
        /// <param name="nodeName">Node name for which repair task needs to be created</param>
        /// <param name="taskDescription">Description of repair task which needs to be created</param>
        /// <param name="resultDetails">Result details for the completed operation to make the repair task verbose</param>
        /// <param name="executorData">Executor data associated with the repair task</param>
        /// <param name="timeout">Timeout for the async operation</param>
        /// <param name="cancellationToken">The cancellation token to cancel the async operation</param>
        /// <returns>A Task representing the asnyc operation, result of task would be <see cref="NodeAgentSfUtilityExitCodes"/></returns>
        internal static async Task <NodeAgentSfUtilityExitCodes> CreateRepairTaskForNode(FabricClient fc, string nodeName,
                                                                                         string taskDescription, string resultDetails, ExecutorDataForRmTask executorData, TimeSpan timeout,
                                                                                         CancellationToken cancellationToken)
        {
            string            taskIdPrefix = string.Format("{0}_{1}", TaskIdPrefix, nodeName);
            string            taskId       = string.Format("{0}_{1}", taskIdPrefix, Guid.NewGuid());
            ClusterRepairTask repairTask   = new ClusterRepairTask(taskId, RepairAction);

            repairTask.Description   = taskDescription;
            repairTask.State         = RepairTaskState.Claimed;
            repairTask.Executor      = ExecutorName;
            repairTask.ExecutorData  = SerializationUtility.Serialize(executorData);
            repairTask.Target        = new NodeRepairTargetDescription(nodeName);
            repairTask.ResultDetails = resultDetails;

            try
            {
                await fc.RepairManager.CreateRepairTaskAsync(repairTask, timeout, cancellationToken);

                return(NodeAgentSfUtilityExitCodes.Success);
            }
            catch (Exception e)
            {
                ServiceEventSource.Current.ErrorMessage(
                    String.Format("RepairManagerHelper.CreateRepairTaskForNode failed. Exception details {0}", e));
                if (e is FabricTransientException)
                {
                    return(NodeAgentSfUtilityExitCodes.RetryableException);
                }
                else
                {
                    return(NodeAgentSfUtilityExitCodes.Failure);
                }
            }
        }
        public void GetJobIdTest()
        {
            var  id = Guid.NewGuid().ToString();
            uint ud = 2;

            var repairTask = new ClusterRepairTask
            {
                ExecutorData = new RepairTaskExecutorData {
                    JobId = id, UD = ud
                }.ToJson(),
            };

            var wrapperRepairTask = new ServiceFabricRepairTask(repairTask);

            var parsedId = wrapperRepairTask.GetJobId();

            Assert.AreEqual(id, parsedId, "Verifying if job Id could be parsed from repair task");
        }
Esempio n. 4
0
        public static RepairTask Convert(WinFabricRepairTask winFabricRepairTask)
        {
            ThrowIf.Null(winFabricRepairTask, "winFabricRepairTask");

            var repairTask = new ClusterRepairTask(winFabricRepairTask.TaskId, winFabricRepairTask.Action)
            {
                Version       = winFabricRepairTask.Version,
                Description   = winFabricRepairTask.Description,
                State         = Convert(winFabricRepairTask.State),
                Target        = Convert(winFabricRepairTask.Target),
                Executor      = winFabricRepairTask.Executor,
                ExecutorData  = winFabricRepairTask.ExecutorData,
                Impact        = Convert(winFabricRepairTask.Impact),
                ResultStatus  = Convert(winFabricRepairTask.ResultStatus),
                ResultCode    = winFabricRepairTask.ResultCode,
                ResultDetails = winFabricRepairTask.ResultDetails
            };

            return(repairTask);
        }
Esempio n. 5
0
        private RepairTask CreateRepairTask()
        {
            string taskId = string.Format(
                CultureInfo.InvariantCulture,
                DefaultTaskIdFormat,
                Guid.NewGuid());

            if (!string.IsNullOrEmpty(this.TaskId))
            {
                taskId = this.TaskId;
            }

            switch (this.ParameterSetName)
            {
            case ParamSetNodeBuiltInAuto:
            {
                var repairTask = new ClusterRepairTask(
                    taskId,
                    SystemRepairActionHelper.GetActionString(this.NodeAction));

                repairTask.Description = this.Description;
                repairTask.Target      = new NodeRepairTargetDescription(this.NodeName);

                return(repairTask);
            }

            case ParamSetNodeCustomAuto:
            {
                var repairTask = new ClusterRepairTask(taskId, this.CustomAction);

                repairTask.Description = this.Description;
                repairTask.Target      = new NodeRepairTargetDescription(this.NodeNames);

                return(repairTask);
            }

            case ParamSetNodeManual:
            {
                var repairTask = new ClusterRepairTask(
                    taskId,
                    SystemRepairActionHelper.ManualRepairAction);

                repairTask.Description = this.Description;
                repairTask.State       = RepairTaskState.Preparing;
                repairTask.Executor    = "Manual";

                // Informational only
                repairTask.Target = new NodeRepairTargetDescription(this.NodeNames);

                var impact = new NodeRepairImpactDescription();
                foreach (var nodeName in this.NodeNames)
                {
                    impact.ImpactedNodes.Add(new NodeImpact(nodeName, this.NodeImpact));
                }

                repairTask.Impact = impact;

                return(repairTask);
            }

            default:
                // Unsupported parameter set
                throw new NotSupportedException();
            }
        }