/// <summary>
        /// Creates <see cref="JobBlockingPolicyManager"/>.
        /// Specify <see cref="oldVersionedPropertyStore"/> when IS is used in a multi-tenant cluster (E.g. RP cluster)
        /// where each IS service communicates with one FC. In that case, we want individual job blocking policies for each IS service.
        /// If this parameter is <c>null</c>, then the same job blocking policy is shared across all IS services in a multi-tenant cluster.
        /// </summary>
        public static async Task <IJobBlockingPolicyManager> CreateAsync(
            TraceType traceType,
            IVersionedPropertyStore versionedPropertyStore,
            IVersionedPropertyStore oldVersionedPropertyStore = null)
        {
            traceType.Validate("traceType");
            versionedPropertyStore.Validate("versionedPropertyStore");

            traceType.WriteInfo("Starting creation of {0}", typeof(JobBlockingPolicyManager).Name);

            var manager = new JobBlockingPolicyManager(versionedPropertyStore);

            var activityId = Guid.NewGuid();

            var versionedKeyValue = await ReadPropertyAsync(traceType, versionedPropertyStore, activityId).ConfigureAwait(false);

            if (versionedKeyValue == null)
            {
                string defaultPolicyValue = JobBlockingPolicy.BlockNone.ToString();

                if (oldVersionedPropertyStore != null)
                {
                    var oldVersionedKeyValue = await ReadPropertyAsync(traceType, oldVersionedPropertyStore, activityId).ConfigureAwait(false);

                    if (oldVersionedKeyValue != null)
                    {
                        defaultPolicyValue = oldVersionedKeyValue.Value;
                    }

                    traceType.WriteInfo(
                        "{0} properties '{1}={2}' and '{3}' {4} newer versioned property store.",
                        oldVersionedKeyValue != null ? "Migrating" : "Creating",
                        PolicyPropertyName, defaultPolicyValue, PolicyVersionName,
                        oldVersionedKeyValue != null ? "to" : "in");
                }

                try
                {
                    await versionedPropertyStore.UpdateValueAsync(
                        activityId,
                        PolicyPropertyName,
                        PolicyVersionName,
                        defaultPolicyValue).ConfigureAwait(false);
                }
                catch (FabricException ex)
                {
                    if (ex.ErrorCode != FabricErrorCode.WriteConflict)
                    {
                        traceType.WriteError("Properties '{0}' and '{1}' could not be updated. Exception: {2}",
                                             PolicyPropertyName, PolicyVersionName, ex);
                        throw;
                    }
                }
            }

            traceType.WriteInfo("Successfully created {0}", typeof(JobBlockingPolicyManager).Name);
            return(manager);
        }
        public static async Task <IVersionedPropertyStore> CreateAsync(
            Guid activityId,
            TraceType traceType,
            Uri storeName,
            IPropertyManagerWrapper propertyManager,
            IRetryPolicyFactory retryPolicyFactory)
        {
            traceType.Validate("traceType");
            storeName.Validate("storeName");
            propertyManager.Validate("propertyManager");
            retryPolicyFactory.Validate("retryPolicyFactory");

            var store = new VersionedPropertyStore(traceType, storeName, propertyManager, retryPolicyFactory);

            await store.InitializeStoreNameAsync(activityId).ConfigureAwait(false);

            return(store);
        }
Esempio n. 3
0
        /// <summary>
        /// Writes an aggregated event for consumption by listeners (e.g. TraceViewer).
        /// Here, the typeNameSuffix and key parameter combination has to be distinct for each event.
        /// If they are the same, then DCA will forward only the last event.
        /// So, don't use this for dumping snapshot views. (i.e. poll every x seconds and dump state)
        /// Instead use this for dumping state changes where you can tolerate loss of this message downstream.
        /// </summary>
        /// <remarks>
        /// Also, use this only for low volume data since DCA has to handle a distinct Id each time at the VM level.
        /// </remarks>
        /// <example>
        /// traceType.WriteAggregatedEvent(
        ///     "CompletedRepairTask"
        ///     "Azure/PlatformMaintenance/1e56e313-0e1e-47d0-85f2-9f75e4833a4f/4/5644"
        ///     "{0}",
        ///     repairTask.ToJson());
        /// </example>
        public static void WriteAggregatedEvent(
            this TraceType traceType,
            string typeNameSuffix,
            string key,
            string format,
            params object[] args)
        {
            traceType.Validate("traceType");
            typeNameSuffix.Validate("typeNameSuffix");
            key.Validate("key");

            // E.g. WARP-Prod-CDM-CDM05PrdApp01@CompletedRepairTask@Azure/PlatformMaintenance/1e56e313-0e1e-47d0-85f2-9f75e4833a4f/4/5644
            string id      = "{0}@{1}@{2}".ToString(traceType.Id, typeNameSuffix, key);
            string message = string.Format(CultureInfo.InvariantCulture, format, args);

            // this shows up in TraceViewer under the Type column as
            // InfrastructureServiceAggregatedEvent@WARP-Prod-CDM-CDM05PrdApp01@CompletedRepairTask@Azure/PlatformMaintenance/1e56e313-0e1e-47d0-85f2-9f75e4833a4f/4/5644
            FabricEvents.Events.InfrastructureServiceAggregatedEvent(id, message);
        }
Esempio n. 4
0
 public ConfigSection(TraceType traceType, IConfigStore configStore, string configSectionName)
 {
     this.traceType   = traceType.Validate("traceType");
     this.ConfigStore = configStore.Validate("configStore");
     this.Name        = configSectionName.Validate("configSectionName");
 }
Esempio n. 5
0
 public ServiceFabricQueryClient(TraceType traceType)
 {
     this.traceType = traceType.Validate("traceType");
 }
Esempio n. 6
0
        public CommandHandler(TraceType traceType)
        {
            this.traceType = traceType.Validate("traceType");

            Commands = new Dictionary <string, CommandHandlerEntry>(StringComparer.OrdinalIgnoreCase);
        }