コード例 #1
0
        /// <summary>
        /// Fork an orchestration.
        /// </summary>
        /// <param name="orchestration">The orchestration to perform.</param>
        /// <returns>a task that completes when the orchestration has been durably queued.</returns>
        public Task ForkOrchestration(IOrchestration orchestration)
        {
            var requestMessage = application.MakeRequest(orchestration);

            requestSender.Add(requestMessage);
            return(requestSender.NotifyAndWaitForWorkToBeServiced());
        }
コード例 #2
0
        public void ForkOrchestration <TReturn2>(IOrchestration <TReturn2> orchestration)
        {
            if (!RecordOrReplayCall(MessageType.ForkOperation, out var opid, out var clock, out var instanceId))
            {
                if (!process.Orchestrations.TryGetValue(orchestration.GetType(), out var orchestrationInfo))
                {
                    throw new BuilderException($"undefined orchestration type {orchestration.GetType().FullName}.");
                }
                orchestrationInfo.CanExecuteLocally(orchestration, out var destination);
                (ForkedDestinations ?? (ForkedDestinations = new SortedSet <uint>())).Add(destination);
                var message = orchestrationInfo.CreateForkMessage(orchestration);
                message.Opid           = opid;
                message.Clock          = clock;
                message.Parent         = this.Opid;
                message.LockedByCaller = false;

                process.Send(destination, message);

                process.Telemetry?.OnApplicationEvent(
                    processId: process.ProcessId,
                    id: opid.ToString(),
                    name: orchestration.ToString(),
                    parent: Opid.ToString(),
                    opSide: OperationSide.Fork,
                    opType: OperationType.Orchestration,
                    duration: 0
                    );
            }
        }
コード例 #3
0
 public RequestMessage CreateForkMessage(IOrchestration orchestration)
 {
     return(new ForkOperation <TRequest>()
     {
         Request = (TRequest)orchestration
     });
 }
コード例 #4
0
 public IMessage MakeRequest(IOrchestration orchestration)
 {
     return new ExternalRequest()
     {
         Orchestration = orchestration
     };
 }
コード例 #5
0
 public Task <TReturn2> PerformOrchestration <TReturn2>(IOrchestration <TReturn2> orchestration)
 {
     if (!RecordOrReplayCall(MessageType.RequestOperation, out var opid, out var clock, out var instanceId))
     {
         if (!process.Orchestrations.TryGetValue(orchestration.GetType(), out var orchestrationInfo))
         {
             throw new BuilderException($"undefined orchestration type {orchestration.GetType().FullName}.");
         }
         if (LockSet != null)
         {
             if (!orchestrationInfo.RequiresLocks(orchestration, out var locks))
             {
                 throw new SynchronizationDisciplineException("an orchestration called from a locked context must be locked also");
             }
             foreach (var l in locks)
             {
                 if (!LockSet.Contains(l))
                 {
                     throw new SynchronizationDisciplineException("to perform an orchestration in a locked context, the caller's affinities must contain the callee's affinities");
                 }
             }
         }
         orchestrationInfo.CanExecuteLocally(orchestration, out uint destination);
         var message = orchestrationInfo.CreateRequestMessage(orchestration);
         message.Opid           = opid;
         message.Clock          = clock;
         message.Parent         = this.Opid;
         message.LockedByCaller = (LockSet != null);
         process.Send(destination, message);
     }
     if (!ReplayReturn(MessageType.RespondToOperation, opid, out var result))
     {
         var continuationInfo = new ContinuationInfo <TReturn2>(orchestration.ToString(), OperationType.Orchestration);
         Continuations[opid] = continuationInfo;
         return(continuationInfo.Tcs.Task);
     }
     else
     {
         if (process.Serializer.DeserializeException(result, out var e))
         {
             return(Task.FromException <TReturn2>(e));
         }
         else
         {
             return(Task.FromResult((TReturn2)result));
         }
     }
 }
コード例 #6
0
        /// <summary>
        /// Perform an orchestration.
        /// </summary>
        /// <typeparam name="TReturn">The type of the result</typeparam>
        /// <param name="orchestration">The orchestration to perform</param>
        /// <returns>a task that completes after the orchestration has finished, with the result.</returns>
        public Task <TReturn> PerformOrchestration <TReturn>(IOrchestration <TReturn> orchestration)
        {
            var co = new ClientRequestOrchestration <TStaticApplicationInfo, TReturn>()
            {
                Orchestration     = orchestration,
                ClientRequestId   = Guid.NewGuid(),
                ResponsePartition = responsePartition
            };

            var continuation = new TaskCompletionSource <TReturn>();

            continuations.TryAdd(co.ClientRequestId, continuation);

            var requestMessage = application.MakeRequest(co);

            requestSender.Add(requestMessage);
            requestSender.Notify();

            return(continuation.Task);
        }
コード例 #7
0
        void IContextWithForks.ForkOrchestration <TReturn>(IOrchestration <TReturn> orchestration)
        {
            if (!process.Orchestrations.TryGetValue(orchestration.GetType(), out var orchestrationInfo))
            {
                throw new BuilderException($"undefined orchestration type {orchestration.GetType().FullName}.");
            }
            orchestrationInfo.CanExecuteLocally(orchestration, out uint destination);
            var opid    = process.NextOpid;
            var message = orchestrationInfo.CreateForkMessage(orchestration);

            message.Opid   = opid;
            message.Parent = CurrentOpid;
            process.Send(destination, message);

            process.Telemetry?.OnApplicationEvent(
                processId: process.ProcessId,
                id: opid.ToString(),
                name: orchestration.ToString(),
                parent: CurrentOpid.ToString(),
                opSide: OperationSide.Fork,
                opType: OperationType.Orchestration,
                duration: 0
                );
        }
コード例 #8
0
 IServiceBuilder IServiceBuilder.OnFirstStart(IOrchestration orchestration)
 {
     process.StartupOrchestrations.Add(orchestration);
     return(this);
 }
コード例 #9
0
 public static void ScheduleOrchestration <TReturn>(this IContextWithForks context, TimeSpan delay, IOrchestration <TReturn> orchestration)
 {
     CheckTimeArgument(delay);
     context.ForkOrchestration(new Extensions.ForkedOrchestration <TReturn>()
     {
         Delay         = delay,
         Orchestration = orchestration
     });
 }
コード例 #10
0
        public static List <QueueMetadata> RunTask(QueueMetadata metadata, JObject taskProperties, string identifier, IOrchestration orchestration)
        {
            List <QueueMetadata> result = null;

            try
            {
                if (taskProperties == null)
                {
                    throw new Exception("TaskProperties for Transformer cannot be NULL");
                }

                TransformerConfiguration taskConfig = taskProperties.ToObject <TransformerConfiguration>();
                JObject transformerJson             = orchestration.GetTransformer(taskConfig.TransformerID);


                QueueMetadata transformedMetadata = new QueueMetadata()
                {
                    CustomPropertiesJson = metadata.CustomPropertiesJson,
                    ID = Guid.NewGuid(),
                    MessageBodyJson = metadata.MessageBodyJson,
                    Retries         = metadata.Retries,
                    SplitID         = metadata.SplitID,
                    StepIdentifier  = identifier,
                    Success         = true,
                    Timestamp       = DateTime.UtcNow
                };

                transformedMetadata.MessageBodyJson = JUST.JsonTransformer.Transform(transformerJson, metadata.MessageBodyJson);
                result = new List <QueueMetadata>();
                result.Add(transformedMetadata);
            }
            catch (Exception ex)
            {
                result = new List <QueueMetadata>();
                QueueMetadata errorMetaData = new QueueMetadata()
                {
                    CustomPropertiesJson = metadata.CustomPropertiesJson,
                    ID = Guid.NewGuid(),
                    MessageBodyJson = metadata.MessageBodyJson,
                    Retries         = metadata.Retries,
                    SplitID         = metadata.SplitID,
                    StepIdentifier  = identifier,
                    Success         = false,
                    Timestamp       = DateTime.UtcNow
                };

                Dictionary <string, string> customPropertiesSerialized = errorMetaData.CustomPropertiesJson.ToObject <Dictionary <string, string> >();
                if (customPropertiesSerialized.ContainsKey("Error"))
                {
                    customPropertiesSerialized.Remove("Error");
                }

                customPropertiesSerialized.Add("Error", ex.Message);

                errorMetaData.CustomPropertiesJson = JObject.FromObject(customPropertiesSerialized);

                result.Add(errorMetaData);
            }


            return(result);
        }
コード例 #11
0
 public OrchestrationController(IOptions <MySqlConfiguration> mySqlModel)
 {
     _connectionString = mySqlModel.Value.ConnectionString;
     _orchestration    = new MySqlOrchestration(_connectionString);
 }
コード例 #12
0
        public static async Task ForkOrchestration(IOrchestration orchestration, IStaticApplicationInfo applicationInfo, ILogger logger)
        {
            var client = ClientConnection.Get(applicationInfo, logger);

            await client.Fork(orchestration);
        }
コード例 #13
0
 public OrchestrationController(IOptions <DynamoDBConfiguration> model)
 {
     _model         = model.Value;
     _orchestration = new DynamoDBOchestration(_model);
 }
コード例 #14
0
 public OrchestrationEngine(IOrchestration orchestration)
 {
     _orchestration = orchestration;
 }