/// <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);
        }
Beispiel #2
0
        private async void RunCoordinatorWrapperAsyncThreadProc(object state)
        {
            var tcs = (TaskCompletionSource <object>)state;
            CancellationToken token = this.coordinatorCancelTokenSource.Token;

            TraceType.WriteInfo("Invoking coordinator RunAsync");
            try
            {
                await this.coordinator.RunAsync(this.primaryEpoch, token);
            }
            catch (Exception e)
            {
                if (!(token.IsCancellationRequested && (e is OperationCanceledException)))
                {
                    TraceType.WriteError("Unhandled exception from coordinator RunAsync: {0}", e);

                    if (this.configSection.ReadConfigValue("CrashOnRunAsyncUnhandledException", true))
                    {
                        // Allow the process to crash. If config is false, then this will fall through
                        // to the "unexpected completion" cases below, and can call ReportFault instead.
                        throw;
                    }
                }
            }

            if (!token.IsCancellationRequested)
            {
                if (this.configSection.ReadConfigValue("CrashOnRunAsyncUnexpectedCompletion", true))
                {
                    TraceType.WriteError("Coordinator RunAsync completed unexpectedly; exiting process");
                    Environment.FailFast("Coordinator RunAsync completed unexpectedly");
                }

                if (this.configSection.ReadConfigValue("ReportFaultOnRunAsyncUnexpectedCompletion", true))
                {
                    TraceType.WriteError("Coordinator RunAsync completed unexpectedly; reporting transient fault");
                    this.partition.ReportFault(FaultType.Transient);
                }
            }

            TraceType.WriteInfo("Coordinator RunAsync completed");
            tcs.SetResult(null);
        }
Beispiel #3
0
        public static ServiceFactory CreateAndRegister()
        {
            try
            {
                IInfrastructureAgentWrapper agent = new InfrastructureAgentWrapper();

                var configUpdateHandler       = new FactoryConfigUpdateHandler();
                NativeConfigStore configStore = NativeConfigStore.FabricGetConfigStore(configUpdateHandler);

                ServiceFactory factory = new ServiceFactory(agent, configStore, null, configUpdateHandler);

                agent.RegisterInfrastructureServiceFactory(factory);

                return(factory);
            }
            catch (Exception ex)
            {
                TraceType.WriteError("Error registering infrastructure service factory. Cannot continue further. Exception: {0}", ex);
                throw;
            }
        }
Beispiel #4
0
        public static RoleInstanceState ToRoleInstanceState(this ManagementRoleInstanceStatus managementRoleInstanceStatus)
        {
            RoleInstanceState state;

            bool success = Enum.TryParse(managementRoleInstanceStatus.ToString(), out state);

            if (!success)
            {
                string message = "Unable to convert {0}.{1} to {2}".ToString(
                    typeof(ManagementRoleInstanceStatus).Name,
                    managementRoleInstanceStatus,
                    typeof(RoleInstanceState));

                TraceType.WriteError(message);
                throw new ArgumentException(message);
            }

            return(state);
        }