public static Task DeleteTaskHubResources(string testName, bool enableExtendedSessions)
        {
            string hubName  = GetTaskHubNameFromTestName(testName, enableExtendedSessions);
            var    settings = new AzureStorageOrchestrationServiceSettings
            {
                TaskHubName             = hubName,
                StorageConnectionString = GetStorageConnectionString(),
            };

            var service = new AzureStorageOrchestrationService(settings);

            return(service.DeleteAsync());
        }
        /// <summary>
        /// Gets a <see cref="DurableOrchestrationClient"/> using configuration from a <see cref="OrchestrationClientAttribute"/> instance.
        /// </summary>
        /// <param name="attribute">The attribute containing the client configuration parameters.</param>
        /// <returns>Returns a <see cref="DurableOrchestrationClient"/> instance. The returned instance may be a cached instance.</returns>
        protected internal virtual DurableOrchestrationClient GetClient(OrchestrationClientAttribute attribute)
        {
            DurableOrchestrationClient client = this.cachedClients.GetOrAdd(
                attribute,
                attr =>
            {
                AzureStorageOrchestrationServiceSettings settings = this.GetOrchestrationServiceSettings(attr);
                var innerClient = new AzureStorageOrchestrationService(settings);
                return(new DurableOrchestrationClient(innerClient, this, attr, this.traceHelper));
            });

            return(client);
        }
Ejemplo n.º 3
0
        public PartitionManager(AzureStorageOrchestrationServiceSettings settings, string accountName, string workerName, ILeaseManager <T> leaseManager, PartitionManagerOptions options)
        {
            this.accountName  = accountName;
            this.taskHub      = settings.TaskHubName;
            this.workerName   = workerName;
            this.leaseManager = leaseManager;
            this.options      = options;
            this.settings     = settings;

            this.currentlyOwnedShards     = new ConcurrentDictionary <string, T>();
            this.keepRenewingDuringClose  = new ConcurrentDictionary <string, T>();
            this.partitionObserverManager = new PartitionObserverManager(this);
        }
Ejemplo n.º 4
0
        public SessionBase(AzureStorageOrchestrationServiceSettings settings, string storageAccountName, OrchestrationInstance orchestrationInstance, Guid traceActivityId)
        {
            this.settings           = settings ?? throw new ArgumentNullException(nameof(settings));
            this.storageAccountName = storageAccountName ?? throw new ArgumentNullException(nameof(storageAccountName));
            this.taskHubName        = settings.TaskHubName ?? throw new ArgumentNullException(nameof(settings.TaskHubName));
            this.Instance           = orchestrationInstance ?? throw new ArgumentNullException(nameof(orchestrationInstance));

            this.TraceActivityId         = traceActivityId;
            this.StorageOperationContext = new OperationContext
            {
                ClientRequestID = this.TraceActivityId.ToString(),
            };
        }
Ejemplo n.º 5
0
        public TestOrchestrationHost(AzureStorageOrchestrationServiceSettings settings)
        {
            var service = new AzureStorageOrchestrationService(settings);

            service.CreateAsync().GetAwaiter().GetResult();

            this.settings = settings;

            this.worker = new TaskHubWorker(service);
            this.client = new TaskHubClient(service);
            this.addedOrchestrationTypes = new HashSet <Type>();
            this.addedActivityTypes      = new HashSet <Type>();
        }
Ejemplo n.º 6
0
 public BlobLease(
     string partitionId,
     CloudBlobDirectory leaseDirectory,
     string accountName,
     AzureStorageOrchestrationServiceStats stats,
     AzureStorageOrchestrationServiceSettings settings)
 {
     this.PartitionId = partitionId;
     this.Blob        = leaseDirectory.GetBlockBlobReference(partitionId);
     this.accountName = accountName;
     this.stats       = stats;
     this.settings    = settings;
 }
Ejemplo n.º 7
0
        public AzureStorageClient(CloudStorageAccount account, AzureStorageOrchestrationServiceSettings settings)
        {
            this.account  = account;
            this.Settings = settings;

            this.StorageAccountName = account.Credentials.AccountName;
            this.Stats       = new AzureStorageOrchestrationServiceStats();
            this.queueClient = account.CreateCloudQueueClient();
            this.queueClient.BufferManager = SimpleBufferManager.Shared;
            this.blobClient = account.CreateCloudBlobClient();
            this.blobClient.BufferManager = SimpleBufferManager.Shared;

            this.blobClient.DefaultRequestOptions.MaximumExecutionTime = StorageMaximumExecutionTime;
        }
Ejemplo n.º 8
0
        public SafePartitionManager(
            AzureStorageOrchestrationService service,
            AzureStorageClient azureStorageClient,
            OrchestrationSessionManager sessionManager)
        {
            this.service            = service;
            this.azureStorageClient = azureStorageClient;
            this.settings           = this.azureStorageClient.Settings;
            this.sessionManager     = sessionManager;

            this.intentLeaseManager = AzureStorageOrchestrationService.GetBlobLeaseManager(
                this.azureStorageClient,
                "intent");

            this.intentLeaseCollectionManager = new LeaseCollectionBalancer <BlobLease>(
                "intent",
                settings,
                this.azureStorageClient.BlobAccountName,
                this.intentLeaseManager,
                new LeaseCollectionBalancerOptions
            {
                AcquireInterval = settings.LeaseAcquireInterval,
                RenewInterval   = settings.LeaseRenewInterval,
                LeaseInterval   = settings.LeaseInterval,
            });

            var currentlyOwnedIntentLeases = this.intentLeaseCollectionManager.GetCurrentlyOwnedLeases();

            this.ownershipLeaseManager = AzureStorageOrchestrationService.GetBlobLeaseManager(
                this.azureStorageClient,
                "ownership");

            this.ownershipLeaseCollectionManager = new LeaseCollectionBalancer <BlobLease>(
                "ownership",
                this.settings,
                this.azureStorageClient.BlobAccountName,
                this.ownershipLeaseManager,
                new LeaseCollectionBalancerOptions
            {
                AcquireInterval   = TimeSpan.FromSeconds(5),
                RenewInterval     = TimeSpan.FromSeconds(10),
                LeaseInterval     = TimeSpan.FromSeconds(15),
                ShouldStealLeases = false
            },
                shouldAquireLeaseDelegate: leaseKey => currentlyOwnedIntentLeases.ContainsKey(leaseKey),
                shouldRenewLeaseDelegate: leaseKey => currentlyOwnedIntentLeases.ContainsKey(leaseKey) ||
                this.sessionManager.IsControlQueueReceivingMessages(leaseKey) ||
                this.sessionManager.IsControlQueueProcessingMessages(leaseKey));
        }
Ejemplo n.º 9
0
        static AzureStorageOrchestrationServiceSettings GetSettings(
            string taskHub,
            int?maxPollingIntervalMilliseconds = null)
        {
            var settings = new AzureStorageOrchestrationServiceSettings {
                TaskHubName = taskHub
            };

            if (maxPollingIntervalMilliseconds != null)
            {
                settings.MaxQueuePollingInterval = TimeSpan.FromMilliseconds(maxPollingIntervalMilliseconds.Value);
            }

            return(settings);
        }
Ejemplo n.º 10
0
        public BlobLeaseManager(
            AzureStorageClient azureStorageClient,
            string leaseContainerName,
            string leaseType)
        {
            this.azureStorageClient = azureStorageClient;
            this.settings           = this.azureStorageClient.Settings;
            this.storageAccountName = this.azureStorageClient.StorageAccountName;
            this.taskHubName        = this.settings.TaskHubName;
            this.workerName         = this.settings.WorkerId;
            this.leaseContainerName = leaseContainerName;
            this.blobDirectoryName  = leaseType;
            this.leaseInterval      = this.settings.LeaseInterval;

            this.Initialize();
        }
Ejemplo n.º 11
0
        internal static TestOrchestrationHost GetTestOrchestrationHost(
            bool enableExtendedSessions,
            int extendedSessionTimeoutInSeconds = 30)
        {
            string storageConnectionString = GetTestStorageAccountConnectionString();

            var settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString    = storageConnectionString,
                TaskHubName                = ConfigurationManager.AppSettings.Get("TaskHubName"),
                ExtendedSessionsEnabled    = enableExtendedSessions,
                ExtendedSessionIdleTimeout = TimeSpan.FromSeconds(extendedSessionTimeoutInSeconds),
            };

            return(new TestOrchestrationHost(settings));
        }
Ejemplo n.º 12
0
        public TaskHubClient GetTaskHubClient(string taskHubName, string storageConnectionString)
        {
            if (this.taskHubClient == null)
            {
                var azureStorageOrchestrationSetting = new AzureStorageOrchestrationServiceSettings()
                {
                    TaskHubName             = taskHubName,
                    StorageConnectionString = storageConnectionString
                };

                IOrchestrationServiceClient orchestrationServiceClient = new AzureStorageOrchestrationService(azureStorageOrchestrationSetting);

                this.taskHubClient = new TaskHubClient(orchestrationServiceClient);
            }
            return(this.taskHubClient);
        }
Ejemplo n.º 13
0
        static async Task Main(string[] args)
        {
            //Use Azurite emulator
            string storageConnectionString = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;" +
                                             "BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;QueueEndpoint=http://127.0.0.1:10001/devstoreaccount1;TableEndpoint=http://127.0.0.1:10002/devstoreaccount1";
            string taskHubName = "RetryTest";

            var settings = new AzureStorageOrchestrationServiceSettings();

            settings.StorageConnectionString      = storageConnectionString;
            settings.TaskHubName                  = taskHubName;
            settings.UseDataContractSerialization = true;

            var orchestrationServiceAndClient = new AzureStorageOrchestrationService(settings);
            await orchestrationServiceAndClient.CreateIfNotExistsAsync();

            var taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
            var taskHub       = new TaskHubWorker(orchestrationServiceAndClient);

            // add instance
            _ = Task.Run(async() =>
            {
                OrchestrationInstance ins = await taskHubClient.CreateOrchestrationInstanceAsync(typeof(HelloOrchestration), "b", "");
            });

            // add worker
            try
            {
                taskHub.AddTaskOrchestrations(
                    typeof(HelloOrchestration)
                    );

                taskHub.AddTaskActivitiesFromInterface <IFailedTask>(new FailedTask());


                await taskHub.StartAsync();

                //Console.WriteLine("Press any key to quit.");
                Console.ReadLine();
                taskHub.StopAsync(true).Wait();
            }
            catch (Exception e)
            {
                // silently eat any unhandled exceptions.
                Console.WriteLine($"worker exception: {e}");
            }
        }
        /// <summary>
        /// Internal initialization call from the WebJobs host.
        /// </summary>
        /// <param name="context">Extension context provided by WebJobs.</param>
        void IExtensionConfigProvider.Initialize(ExtensionConfigContext context)
        {
            ConfigureLoaderHooks();

            context.ApplyConfig(this, "DurableTask");

            // Register the trigger bindings
            JobHostConfiguration hostConfig = context.Config;
            ILogger logger = context.Config.LoggerFactory.CreateLogger(LoggerCategoryName);

            this.traceHelper    = new EndToEndTraceHelper(hostConfig, logger, this.LogReplayEvents);
            this.httpApiHandler = new HttpApiHandler(this, logger);

            this.lifeCycleNotificationHelper = new LifeCycleNotificationHelper(this, context);

            // Register the non-trigger bindings, which have a different model.
            var bindings = new BindingHelper(this, this.traceHelper);

            // For 202 support
            if (this.NotificationUrl == null)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                this.NotificationUrl = context.GetWebhookHandler();
#pragma warning restore CS0618 // Type or member is obsolete
            }

            // Note that the order of the rules is important
            var rule = context.AddBindingRule <OrchestrationClientAttribute>()
                       .AddConverter <string, StartOrchestrationArgs>(bindings.StringToStartOrchestrationArgs)
                       .AddConverter <JObject, StartOrchestrationArgs>(bindings.JObjectToStartOrchestrationArgs);

            rule.BindToCollector <StartOrchestrationArgs>(bindings.CreateAsyncCollector);
            rule.BindToInput <DurableOrchestrationClient>(this.GetClient);

            context.AddBindingRule <OrchestrationTriggerAttribute>()
            .BindToTrigger(new OrchestrationTriggerAttributeBindingProvider(this, context, this.traceHelper));

            context.AddBindingRule <ActivityTriggerAttribute>()
            .BindToTrigger(new ActivityTriggerAttributeBindingProvider(this, context, this.traceHelper));

            AzureStorageOrchestrationServiceSettings settings = this.GetOrchestrationServiceSettings();
            this.orchestrationService = new AzureStorageOrchestrationService(settings);
            this.taskHubWorker        = new TaskHubWorker(this.orchestrationService, this, this);
            this.taskHubWorker.AddOrchestrationDispatcherMiddleware(this.OrchestrationMiddleware);

            context.Config.AddService <IOrchestrationService>(this.orchestrationService);
        }
        private static async Task Main(string[] args)
        {
            foreach (DictionaryEntry env in Environment.GetEnvironmentVariables())
            {
                var name  = (string)env.Key;
                var value = (string)env.Value;
                Console.WriteLine("{0}={1}", name, value);
            }

            var storageConnectionString = Environment.GetEnvironmentVariable("StorageConnectionString");
            var taskHubName             = Environment.GetEnvironmentVariable("TaskHubName");
            var durationInSeconds       = Environment.GetEnvironmentVariable("DurationInSeconds");
            var mre = new ManualResetEvent(false);

            var settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString = storageConnectionString,
                TaskHubName             = taskHubName
            };
            var orchestrationServiceAndClient = new AzureStorageOrchestrationService(settings);

            var taskHubClient = new TaskHubClient(orchestrationServiceAndClient);
            var taskHub       = new TaskHubWorker(orchestrationServiceAndClient);

            orchestrationServiceAndClient.CreateIfNotExistsAsync().Wait();
            try
            {
                await taskHub
                .AddTaskOrchestrations(typeof(CronOrchestration))
                .AddTaskActivities(new CronTask())
                .StartAsync();

                var orchestrationInstance = await taskHubClient.CreateOrchestrationInstanceAsync(
                    typeof(CronOrchestration),
                    TimeSpan.FromSeconds(double.Parse(durationInSeconds ?? "5")));

                Console.WriteLine($"ExecutionId: {orchestrationInstance.ExecutionId}. Blocking main thread.");
                mre.WaitOne();
                await taskHub.StopAsync(true);

                Console.WriteLine("Done!!");
            }
            catch (Exception e)
            {
                Console.WriteLine($"worker exception: {e}");
            }
        }
Ejemplo n.º 16
0
        public AzureTableTrackingStore(
            AzureStorageOrchestrationServiceSettings settings,
            MessageManager messageManager,
            AzureStorageOrchestrationServiceStats stats)
        {
            this.settings             = settings;
            this.messageManager       = messageManager;
            this.stats                = stats;
            this.tableEntityConverter = new TableEntityConverter();
            this.taskHubName          = settings.TaskHubName;

            CloudStorageAccount account = CloudStorageAccount.Parse(settings.StorageConnectionString);

            this.storageAccountName = account.Credentials.AccountName;

            CloudTableClient tableClient = account.CreateCloudTableClient();

            tableClient.BufferManager = SimpleBufferManager.Shared;

            string historyTableName = $"{taskHubName}History";

            NameValidator.ValidateTableName(historyTableName);

            string instancesTableName = $"{taskHubName}Instances";

            NameValidator.ValidateTableName(instancesTableName);

            this.historyTable   = tableClient.GetTableReference(historyTableName);
            this.instancesTable = tableClient.GetTableReference(instancesTableName);

            this.StorageTableRequestOptions = settings.HistoryTableRequestOptions;

            this.eTagValues = new ConcurrentDictionary <string, string>();

            // Use reflection to learn all the different event types supported by DTFx.
            // This could have been hardcoded, but I generally try to avoid hardcoding of point-in-time DTFx knowledge.
            Type historyEventType = typeof(HistoryEvent);

            IEnumerable <Type> historyEventTypes = historyEventType.Assembly.GetTypes().Where(
                t => !t.IsAbstract && t.IsSubclassOf(historyEventType));

            PropertyInfo eventTypeProperty = historyEventType.GetProperty(nameof(HistoryEvent.EventType));

            this.eventTypeMap = historyEventTypes.ToDictionary(
                type => ((HistoryEvent)FormatterServices.GetUninitializedObject(type)).EventType);
        }
Ejemplo n.º 17
0
        // This method should not be called before the app settings are resolved into the options.
        // Because of this, we wait to validate the options until right before building a durability provider, rather
        // than in the Factory constructor.
        private void EnsureDefaultClientSettingsInitialized()
        {
            if (!this.hasValidatedOptions)
            {
                if (!this.options.IsDefaultHubName())
                {
                    this.azureStorageOptions.ValidateHubName(this.options.HubName);
                }
                else if (!this.azureStorageOptions.IsSanitizedHubName(this.options.HubName, out string sanitizedHubName))
                {
                    this.options.SetDefaultHubName(sanitizedHubName);
                }

                this.defaultSettings     = this.GetAzureStorageOrchestrationServiceSettings();
                this.hasValidatedOptions = true;
            }
        }
Ejemplo n.º 18
0
        public TaskHubQueue(
            CloudQueue storageQueue,
            AzureStorageOrchestrationServiceSettings settings,
            AzureStorageOrchestrationServiceStats stats,
            MessageManager messageManager)
        {
            this.storageQueue       = storageQueue;
            this.storageAccountName = storageQueue.ServiceClient.Credentials.AccountName;
            this.settings           = settings;
            this.stats          = stats;
            this.messageManager = messageManager;

            TimeSpan minPollingDelay = TimeSpan.FromMilliseconds(50);
            TimeSpan maxPollingDelay = AzureStorageOrchestrationService.MaxQueuePollingDelay;

            this.backoffHelper = new BackoffPollingHelper(minPollingDelay, maxPollingDelay);
        }
        /// <summary>
        /// Internal initialization call from the WebJobs host.
        /// </summary>
        /// <param name="context">Extension context provided by WebJobs.</param>
        void IExtensionConfigProvider.Initialize(ExtensionConfigContext context)
        {
            ConfigureLoaderHooks();

            // Functions V1 has it's configuration initialized at startup time (now).
            // For Functions V2 (and for some unit tests) configuration happens earlier in the pipeline.
            if (!this.isOptionsConfigured)
            {
                this.InitializeForFunctionsV1(context);
            }

            // Throw if any of the configured options are invalid
            this.Options.Validate();

            // For 202 support
            if (this.Options.NotificationUrl == null)
            {
#pragma warning disable CS0618 // Type or member is obsolete
                this.Options.NotificationUrl = context.GetWebhookHandler();
#pragma warning restore CS0618 // Type or member is obsolete
            }

            this.TraceConfigurationSettings();

            var bindings = new BindingHelper(this, this.TraceHelper);

            // Note that the order of the rules is important
            var rule = context.AddBindingRule <OrchestrationClientAttribute>()
                       .AddConverter <string, StartOrchestrationArgs>(bindings.StringToStartOrchestrationArgs)
                       .AddConverter <JObject, StartOrchestrationArgs>(bindings.JObjectToStartOrchestrationArgs);

            rule.BindToCollector <StartOrchestrationArgs>(bindings.CreateAsyncCollector);
            rule.BindToInput <DurableOrchestrationClient>(this.GetClient);

            context.AddBindingRule <OrchestrationTriggerAttribute>()
            .BindToTrigger(new OrchestrationTriggerAttributeBindingProvider(this, context, this.TraceHelper));

            context.AddBindingRule <ActivityTriggerAttribute>()
            .BindToTrigger(new ActivityTriggerAttributeBindingProvider(this, context, this.TraceHelper));

            AzureStorageOrchestrationServiceSettings settings = this.GetOrchestrationServiceSettings();
            this.orchestrationService = new AzureStorageOrchestrationService(settings);
            this.taskHubWorker        = new TaskHubWorker(this.orchestrationService, this, this);
            this.taskHubWorker.AddOrchestrationDispatcherMiddleware(this.OrchestrationMiddleware);
        }
Ejemplo n.º 20
0
        public static TestOrchestrationHost GetTestOrchestrationHost(
            bool enableExtendedSessions,
            int extendedSessionTimeoutInSeconds = 30,
            bool fetchLargeMessages             = true)
        {
            string storageConnectionString = GetTestStorageAccountConnectionString();

            var settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString      = storageConnectionString,
                TaskHubName                  = GetTestTaskHubName(),
                ExtendedSessionsEnabled      = enableExtendedSessions,
                ExtendedSessionIdleTimeout   = TimeSpan.FromSeconds(extendedSessionTimeoutInSeconds),
                FetchLargeMessageDataEnabled = fetchLargeMessages,
            };

            return(new TestOrchestrationHost(settings));
        }
Ejemplo n.º 21
0
        public AzureStorageClient(AzureStorageOrchestrationServiceSettings settings)
        {
            this.Settings = settings;

            this.account = settings.StorageAccountDetails == null
                ? CloudStorageAccount.Parse(settings.StorageConnectionString)
                : settings.StorageAccountDetails.ToCloudStorageAccount();

            this.StorageAccountName = account.Credentials.AccountName;

            this.Stats       = new AzureStorageOrchestrationServiceStats();
            this.queueClient = account.CreateCloudQueueClient();
            this.queueClient.BufferManager = SimpleBufferManager.Shared;
            this.blobClient = account.CreateCloudBlobClient();
            this.blobClient.BufferManager = SimpleBufferManager.Shared;

            this.blobClient.DefaultRequestOptions.MaximumExecutionTime = StorageMaximumExecutionTime;
        }
        public static TestOrchestrationHost GetTestOrchestrationHost(
            bool enableExtendedSessions,
            int extendedSessionTimeoutInSeconds = 30,
            bool fetchLargeMessages             = true)
        {
            string storageConnectionString = GetTestStorageAccountConnectionString();

            var settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString      = storageConnectionString,
                TaskHubName                  = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None).AppSettings.Settings["TaskHubName"].Value,
                ExtendedSessionsEnabled      = enableExtendedSessions,
                ExtendedSessionIdleTimeout   = TimeSpan.FromSeconds(extendedSessionTimeoutInSeconds),
                FetchLargeMessageDataEnabled = fetchLargeMessages,
            };

            return(new TestOrchestrationHost(settings));
        }
        internal AzureStorageOrchestrationServiceSettings GetAzureStorageOrchestrationServiceSettings(
            string connectionName      = null,
            string taskHubNameOverride = null)
        {
            connectionName = connectionName ?? this.defaultConnectionName;

            string resolvedStorageConnectionString = this.connectionStringResolver.Resolve(connectionName);

            if (string.IsNullOrEmpty(resolvedStorageConnectionString))
            {
                throw new InvalidOperationException("Unable to find an Azure Storage connection string to use for this binding.");
            }

            TimeSpan extendedSessionTimeout = TimeSpan.FromSeconds(
                Math.Max(this.options.ExtendedSessionIdleTimeoutInSeconds, 0));

            var settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString                 = resolvedStorageConnectionString,
                TaskHubName                             = taskHubNameOverride ?? this.options.HubName,
                PartitionCount                          = this.azureStorageOptions.PartitionCount,
                ControlQueueBatchSize                   = this.azureStorageOptions.ControlQueueBatchSize,
                ControlQueueBufferThreshold             = this.azureStorageOptions.ControlQueueBufferThreshold,
                ControlQueueVisibilityTimeout           = this.azureStorageOptions.ControlQueueVisibilityTimeout,
                WorkItemQueueVisibilityTimeout          = this.azureStorageOptions.WorkItemQueueVisibilityTimeout,
                MaxConcurrentTaskOrchestrationWorkItems = this.options.MaxConcurrentOrchestratorFunctions,
                MaxConcurrentTaskActivityWorkItems      = this.options.MaxConcurrentActivityFunctions,
                ExtendedSessionsEnabled                 = this.options.ExtendedSessionsEnabled,
                ExtendedSessionIdleTimeout              = extendedSessionTimeout,
                MaxQueuePollingInterval                 = this.azureStorageOptions.MaxQueuePollingInterval,
                TrackingStoreStorageAccountDetails      = GetStorageAccountDetailsOrNull(
                    this.connectionStringResolver,
                    this.azureStorageOptions.TrackingStoreConnectionStringName),
                FetchLargeMessageDataEnabled        = this.azureStorageOptions.FetchLargeMessagesAutomatically,
                ThrowExceptionOnInvalidDedupeStatus = true,
            };

            if (!string.IsNullOrEmpty(this.azureStorageOptions.TrackingStoreNamePrefix))
            {
                settings.TrackingStoreNamePrefix = this.azureStorageOptions.TrackingStoreNamePrefix;
            }

            return(settings);
        }
        public TestOrchestrationHost(AzureStorageOrchestrationServiceSettings settings)
        {
            try
            {
                var service = new AzureStorageOrchestrationService(settings);
                service.CreateAsync().GetAwaiter().GetResult(); // I change Create to CreateIfNotExistsAsync for enabling execute without fail once per twice.

                this.settings = settings;

                this.worker = new TaskHubWorker(service);
                this.client = new TaskHubClient(service);
                this.addedOrchestrationTypes = new HashSet <Type>();
                this.addedActivityTypes      = new HashSet <Type>();
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Ejemplo n.º 25
0
        private static async Task StartWorker()
        {
            var workerId = Guid.NewGuid().ToString();

            Console.WriteLine("*****************************************************");
            Console.WriteLine("**** Starting Worker Service: " + workerId);
            Console.WriteLine("*****************************************************");

            var storageConnectionString = ConfigurationManager.AppSettings["StorageConnectionString"];
            var taskHubName             = ConfigurationManager.AppSettings["TaskHubName"];

            var azureStorageOrchestrationSetting = new AzureStorageOrchestrationServiceSettings()
            {
                TaskHubName             = taskHubName,
                StorageConnectionString = storageConnectionString,
                WorkerId = workerId
            };

            IOrchestrationService       orchestrationService       = new AzureStorageOrchestrationService(azureStorageOrchestrationSetting);
            IOrchestrationServiceClient orchestrationServiceClient = new AzureStorageOrchestrationService(azureStorageOrchestrationSetting);

            var taskHubWorker = new TaskHubWorker(orchestrationService);
            var taskHubClient = new TaskHubClient(orchestrationServiceClient);

            _ = taskHubWorker.AddTaskOrchestrations(typeof(ModelValidationOrchestration));
            _ = taskHubWorker.AddTaskActivities(typeof(ExtractInterfacesActivity));
            _ = taskHubWorker.AddTaskActivities(typeof(ValidateInterfaceActivity));

            await orchestrationService.CreateIfNotExistsAsync().ConfigureAwait(true);

            Task.Run(async() =>
            {
                await Start(taskHubWorker).ConfigureAwait(true);
            }).Wait();

            while (true)
            {
                Thread.Sleep(1000);
                Console.ForegroundColor = ConsoleColor.DarkGreen;
                Console.WriteLine("Working: " + DateTime.Now.ToString());
            }
        }
        void IExtensionConfigProvider.Initialize(ExtensionConfigContext context)
        {
            ConfigureLoaderHooks();

            context.ApplyConfig(this, "DurableTask");

            // Register the trigger bindings
            JobHostConfiguration hostConfig = context.Config;

            this.traceHelper    = new EndToEndTraceHelper(hostConfig, context.Trace);
            this.httpApiHandler = new HttpApiHandler(this, context.Trace);

            // Register the non-trigger bindings, which have a different model.
            var bindings = new BindingHelper(this, this.traceHelper);

            // For 202 support
            if (this.NotificationUrl == null)
            {
                this.NotificationUrl = context.GetWebhookHandler();
            }

            // Note that the order of the rules is important
            var rule = context.AddBindingRule <OrchestrationClientAttribute>()
                       .AddConverter <JObject, StartOrchestrationArgs>(bindings.JObjectToStartOrchestrationArgs);

            rule.BindToCollector <StartOrchestrationArgs>(bindings.CreateAsyncCollector);
            rule.BindToInput <DurableOrchestrationClient>(GetClient);

            context.AddBindingRule <OrchestrationTriggerAttribute>()
            .BindToTrigger(new OrchestrationTriggerAttributeBindingProvider(this, context, this.traceHelper));

            context.AddBindingRule <ActivityTriggerAttribute>()
            .BindToTrigger(new ActivityTriggerAttributeBindingProvider(this, context, this.traceHelper));

            AzureStorageOrchestrationServiceSettings settings = this.GetOrchestrationServiceSettings();

            this.orchestrationService = new AzureStorageOrchestrationService(settings);
            this.taskHubWorker        = new TaskHubWorker(this.orchestrationService, this, this);
            this.taskHubWorker.AddOrchestrationDispatcherMiddleware(this.OrchestrationMiddleware);
        }
Ejemplo n.º 27
0
        public static TestOrchestrationHost GetTestOrchestrationHost(
            bool enableExtendedSessions,
            int extendedSessionTimeoutInSeconds = 30,
            bool fetchLargeMessages             = true)
        {
            string storageConnectionString = GetTestStorageAccountConnectionString();

            var settings = new AzureStorageOrchestrationServiceSettings
            {
                StorageConnectionString      = storageConnectionString,
                TaskHubName                  = GetTestTaskHubName(),
                ExtendedSessionsEnabled      = enableExtendedSessions,
                ExtendedSessionIdleTimeout   = TimeSpan.FromSeconds(extendedSessionTimeoutInSeconds),
                FetchLargeMessageDataEnabled = fetchLargeMessages,

                // Setting up a logger factory to enable the new DurableTask.Core logs
                // TODO: Add a logger provider so we can collect these logs in memory.
                LoggerFactory = new LoggerFactory(),
            };

            return(new TestOrchestrationHost(settings));
        }
        private async Task DeleteTaskHub(string taskHub, string connectionString)
        {
            var settings = new AzureStorageOrchestrationServiceSettings()
            {
                TaskHubName             = taskHub,
                StorageConnectionString = connectionString,
            };

            var service = new AzureStorageOrchestrationService(settings);
            await service.StartAsync();

            this.output.WriteLine($"Deleting task hub : {taskHub}");
            try
            {
                await service.DeleteAsync();
            }
            catch (Exception ex)
            {
                // Log error, but don't fail the test, as it can be cleaned up later.
                this.output.WriteLine($"Encountered exception deleting task hub: : {ex.ToString()}");
            }
        }
        public AzureStorageDurabilityProviderFactory(
            IOptions <DurableTaskOptions> options,
            IConnectionStringResolver connectionStringResolver)
        {
            this.options             = options.Value;
            this.azureStorageOptions = new AzureStorageOptions();
            JsonConvert.PopulateObject(JsonConvert.SerializeObject(this.options.StorageProvider), this.azureStorageOptions);

            this.azureStorageOptions.Validate();
            if (!this.options.IsDefaultHubName())
            {
                this.azureStorageOptions.ValidateHubName(this.options.HubName);
            }
            else if (!this.azureStorageOptions.IsSanitizedHubName(this.options.HubName, out string sanitizedHubName))
            {
                this.options.SetDefaultHubName(sanitizedHubName);
            }

            this.connectionStringResolver = connectionStringResolver;
            this.defaultConnectionName    = this.azureStorageOptions.ConnectionStringName ?? ConnectionStringNames.Storage;
            this.defaultSettings          = this.GetAzureStorageOrchestrationServiceSettings();
        }
        private AzureStorageDurabilityProvider GetAzureStorageStorageProvider(DurableClientAttribute attribute)
        {
            string connectionName = attribute.ConnectionName ?? this.defaultConnectionName;
            AzureStorageOrchestrationServiceSettings settings = this.GetAzureStorageOrchestrationServiceSettings(connectionName, attribute.TaskHub);

            AzureStorageDurabilityProvider innerClient;

            if (string.Equals(this.defaultSettings.TaskHubName, settings.TaskHubName, StringComparison.OrdinalIgnoreCase) &&
                string.Equals(this.defaultSettings.StorageConnectionString, settings.StorageConnectionString, StringComparison.OrdinalIgnoreCase))
            {
                // It's important that clients use the same AzureStorageOrchestrationService instance
                // as the host when possible to ensure we any send operations can be picked up
                // immediately instead of waiting for the next queue polling interval.
                innerClient = this.defaultStorageProvider;
            }
            else
            {
                innerClient = new AzureStorageDurabilityProvider(new AzureStorageOrchestrationService(settings), connectionName);
            }

            return(innerClient);
        }