IInfrastructureCoordinator CreateCoordinatorAzureParallelDisabled(CoordinatorFactoryArgs args)
 {
     return(CreateCoordinatorByReflection(
                ParallelAssemblyName,
                "System.Fabric.InfrastructureService.Parallel.AzureParallelDisabledCoordinatorFactory",
                args.ServiceName, this.configStore, args.ConfigSectionName, args.PartitionId, args.ReplicaId, args.Agent));
 }
 IInfrastructureCoordinator CreateCoordinatorServerRestart(CoordinatorFactoryArgs args)
 {
     return(CreateCoordinatorByReflection(
                SerialAssemblyName,
                ServerRestartCoordinatorFactoryTypeName,
                this.configStore, args.ConfigSectionName, args.PartitionId, args.ReplicaId));
 }
 IInfrastructureCoordinator InternalCreateCoordinatorAzureSerial(CoordinatorFactoryArgs args, IAzureModeDetector modeDetector)
 {
     return(CreateCoordinatorByReflection(
                SerialAssemblyName,
                SerialCoordinatorFactoryTypeName,
                this.configStore, args.ConfigSectionName, args.PartitionId, args.ReplicaId, args.Agent, modeDetector));
 }
Exemple #4
0
 public DelayLoadCoordinator(
     Func <CoordinatorFactoryArgs, IInfrastructureCoordinator> factory,
     CoordinatorFactoryArgs factoryArgs,
     IHealthClient healthClient,
     IConfigSection configSection)
 {
     this.factory       = factory.Validate("factory");
     this.factoryArgs   = factoryArgs.Validate("factoryArgs");
     this.healthClient  = healthClient.Validate("healthClient");
     this.configSection = configSection.Validate("configSection");
 }
        IInfrastructureCoordinator CreateCoordinatorDynamic(CoordinatorFactoryArgs args)
        {
            string coordinatorAssemblyName = this.ReadFactoryConfig(
                args.ConfigSection,
                "CoordinatorAssemblyName",
                string.Empty);

            string coordinatorFactoryType = this.ReadFactoryConfig(
                args.ConfigSection,
                "CoordinatorFactoryType",
                string.Empty);

            return(CreateCoordinatorByReflection(
                       coordinatorAssemblyName,
                       coordinatorFactoryType,
                       args.ServiceName,
                       this.configStore,
                       args.ConfigSectionName,
                       args.PartitionId,
                       args.ReplicaId));
        }
        /// <summary>
        /// Detects the mode by checking if the parallel endpoint is publishing
        /// job information. If so, creates the parallel coordinator. If not, creates
        /// the serial coordinator but passes it a reference to the autodetector, so
        /// that the serial coordinator can exit when it detects that parallel mode has
        /// been enabled via a tenant update. That update would be invisible over the
        /// serial channel, so this is the only way the serial coordinator can detect a change.
        /// </summary>
        IInfrastructureCoordinator CreateCoordinatorAzureAutodetect(CoordinatorFactoryArgs args)
        {
            var azureParallelFactory = InternalCreateCoordinatorFactoryAzureParallel(args);

            IAzureModeDetector modeDetector = ((IAzureModeDetectorFactory)azureParallelFactory).CreateAzureModeDetector();

            AzureMode mode = modeDetector.DetectModeAsync().GetAwaiter().GetResult();

            TraceType.WriteInfo("Auto-detected Azure mode: {0}", mode);

            switch (mode)
            {
            case AzureMode.Serial:
                return(InternalCreateCoordinatorAzureSerial(args, modeDetector));

            case AzureMode.Parallel:
                return(azureParallelFactory.Create());

            default:
                throw new InvalidOperationException("Failed to auto-detect Azure coordinator mode");
            }
        }
        private IInfrastructureCoordinator CreateCoordinator(CoordinatorFactoryArgs args)
        {
            IInfrastructureCoordinator coordinator;

            var configSection = args.ConfigSection;

            if (configSection.SectionExists)
            {
                string coordinatorType = this.ReadFactoryConfig(configSection, CoordinatorTypeKeyName, string.Empty);
                TraceType.WriteInfo("Coordinator type: {0}", coordinatorType ?? "<not specified>");

                Func <CoordinatorFactoryArgs, IInfrastructureCoordinator> factory;
                if (!this.coordinatorFactoryMap.TryGetValue(coordinatorType, out factory))
                {
                    // Current behavior is that coordinator defaults to AzureAutodetect when not specified in config
                    TraceType.WriteInfo("Using default coordinator type: AzureAutodetect");
                    factory = this.CreateCoordinatorAzureAutodetect;
                }

                if (this.ReadFactoryConfig(configSection, "DelayLoadCoordinator", false))
                {
                    TraceType.WriteInfo("Coordinator will be delay-loaded");
                    coordinator = new DelayLoadCoordinator(factory, args, new ServiceFabricHealthClient(), configSection);
                }
                else
                {
                    coordinator = factory(args);
                }
            }
            else
            {
                Trace.WriteWarning(TraceType, "No configuration found; infrastructure coordinator is not active");
                coordinator = this.CreateCoordinatorNull(args);
            }

            return(coordinator);
        }
        IInfrastructureCoordinator CreateCoordinatorAzureParallel(CoordinatorFactoryArgs args)
        {
            var factory = InternalCreateCoordinatorFactoryAzureParallel(args);

            return(factory.Create());
        }
 IInfrastructureCoordinatorFactory InternalCreateCoordinatorFactoryAzureParallel(CoordinatorFactoryArgs args)
 {
     return(CreateCoordinatorFactoryByReflection(
                ParallelAssemblyName,
                ParallelCoordinatorFactoryTypeName,
                args.ServiceName, this.configStore, args.ConfigSectionName, args.PartitionId, args.ReplicaId, args.Agent));
 }
 IInfrastructureCoordinator CreateCoordinatorAzureSerial(CoordinatorFactoryArgs args)
 {
     return(InternalCreateCoordinatorAzureSerial(args, null));
 }
 IInfrastructureCoordinator CreateCoordinatorTest(CoordinatorFactoryArgs args)
 {
     return(new TestInfrastructureCoordinator(args.Agent, args.PartitionId));
 }
 IInfrastructureCoordinator CreateCoordinatorNull(CoordinatorFactoryArgs args)
 {
     return(new NullCoordinator());
 }
        public IStatefulServiceReplica CreateReplica(
            string serviceTypeName,
            Uri serviceName,
            byte[] initializationData,
            Guid partitionId,
            long replicaId)
        {
            string replicaConfigSectionName = this.configSectionName;

            if (replicaConfigSectionName == null)
            {
                // When run as a system service, the configuration section name is encoded
                // in the service initialization data, because there can be multiple
                // InfrastructureService instances, each with its own config section.
                // When run as an application, a fixed configuration section name is used,
                // and passed into the factory constructor.
                replicaConfigSectionName = Encoding.Unicode.GetString(initializationData);
            }

            Trace.WriteInfo(
                TraceType,
                "CreateReplica: serviceName = {0}, partitionId = {1}, configSectionName = {2}",
                serviceName,
                partitionId,
                replicaConfigSectionName);

            try
            {
                var args = new CoordinatorFactoryArgs()
                {
                    Agent         = this.infrastructureServiceAgent,
                    ConfigSection = GetConfigSection(replicaConfigSectionName),
                    PartitionId   = partitionId,
                    ReplicaId     = replicaId,
                    ServiceName   = serviceName,
                };

                IInfrastructureCoordinator coordinator = CreateCoordinator(args);

                var replica = new ServiceReplica(
                    this.infrastructureServiceAgent,
                    coordinator,
                    GetReplicatorAddress(coordinator, args.ConfigSection),
                    UseClusterSecuritySettingsForReplicator(args.ConfigSection),
                    args.ConfigSection);

                return(replica);
            }
            catch (TargetInvocationException ex)
            {
                TraceType.WriteError("Error creating infrastructure coordinator. Cannot continue further. Exception: {0}", ex);

                if (ex.InnerException != null)
                {
                    // Rethrow, preserving the original stack trace from exceptions that
                    // come from dynamic invoke (e.g. factory creation) via reflection.
                    ExceptionDispatchInfo.Capture(ex.InnerException).Throw();
                }

                throw;
            }
            catch (Exception ex)
            {
                TraceType.WriteError("Error creating infrastructure coordinator. Cannot continue further. Exception: {0}", ex);
                throw;
            }
        }