Esempio n. 1
0
        public Task <string> OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
        {
            this.trace.Message("Service.OpenAsync: method invoked.");

            this.mdsAgentManager = new MdsAgentManager(this.initializationParameters, this.trace);
            this.mdsAgentManager.Start();
            return(Utility.CreateCompletedTask(string.Empty));
        }
Esempio n. 2
0
        /// <summary>
        /// Sets the partition info of the provided <paramref name="service"/>.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="partition">partition to set</param>
        /// <returns></returns>
        public static void SetPartition(this StatelessService service, IStatelessServicePartition partition)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            //protected IStatelessServicePartition Partition { get; private set; }
            var propertyInfo = typeof(StatelessService).GetProperty("Partition", BindingFlags.Instance | BindingFlags.NonPublic);

            propertyInfo?.SetValue(service, partition, BindingFlags.Instance | BindingFlags.NonPublic, null, null, CultureInfo.InvariantCulture);
        }
Esempio n. 3
0
        public Task <string> OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
        {
            Console.WriteLine("AspNetCoreService: OpenAsync");

            _webHost.Start();

            Console.WriteLine("AspNetCoreService: WebHost started");

            var    serverAddressesFeature = _webHost.ServerFeatures.Get <IServerAddressesFeature>();
            string addresses = string.Join(";", serverAddressesFeature.Addresses);

            Console.WriteLine("AspNetCoreService: Returning Addresses " + addresses);
            return(Task.FromResult(addresses));
        }
        public Task<string> OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
        {
            Console.WriteLine("AspNetCoreService: OpenAsync");

            _webHost.Start();

            Console.WriteLine("AspNetCoreService: WebHost started");

            var serverAddressesFeature = _webHost.ServerFeatures.Get<IServerAddressesFeature>();
            string addresses = string.Join(";", serverAddressesFeature.Addresses);

            Console.WriteLine("AspNetCoreService: Returning Addresses " + addresses);
            return Task.FromResult(addresses);
        }
Esempio n. 5
0
        public Task <string> OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
        {
            TokenValidationServiceFactory.TraceSource.WriteInfo(
                TokenValidationService.TraceType,
                "Opening TokenValidationService: partition={0} instance={1}",
                this.partitionId,
                this.instanceId);

            this.serviceAgent.RegisterTokenValidationService(this.partitionId, this.instanceId, this);

            var tcs = new TaskCompletionSource <string>();

            tcs.SetResult("Completed");
            return(tcs.Task);
        }
Esempio n. 6
0
            public Threading.Tasks.Task <string> OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
            {
                Debug.WriteLine("OnOpenAsync");
                Trace.WriteLine("HI");
                this.WriteEventToGlobalFile(SanityTest.OpenAsyncMarker);

                // return address as null or a string based upon the config entry.
                // null needs to be tested
                string address = null;

                if (this.initParams.CodePackageActivationContext.GetConfigurationPackageObject(SanityTest.ConfigurationPackageName).Settings.Sections[SanityTest.ConfigurationSectionName].Parameters.Contains(SanityTest.ConfigurationAddressParameterName))
                {
                    address = this.initParams.CodePackageActivationContext.GetConfigurationPackageObject(SanityTest.ConfigurationPackageName).Settings.Sections[SanityTest.ConfigurationSectionName].Parameters[SanityTest.ConfigurationAddressParameterName].Value;
                }

                return(Task.Factory.StartNew <string>(() => address));
            }
        internal StatelessServiceInstanceAdapter(
            StatelessServiceContext context,
            IStatelessUserServiceInstance userServiceInstance)
        {
            this.serviceContext = context;
            this.traceId        = ServiceTrace.GetTraceIdForReplica(context.PartitionId, context.InstanceId);
            this.serviceHelper  = new ServiceHelper(TraceType, this.traceId);

            this.servicePartition       = null;
            this.instanceListeners      = null;
            this.communicationListeners = null;
            this.endpointCollection     = new ServiceEndpointCollection();

            this.runAsynCancellationTokenSource = null;
            this.executeRunAsyncTask            = null;

            this.userServiceInstance           = userServiceInstance;
            this.userServiceInstance.Addresses = this.endpointCollection.ToReadOnlyDictionary();
        }
        public Task PublishAsync(HealthReport report, CancellationToken cancellationToken)
        {
            IServicePartition?partition = m_partitionAccessor.Value;

            if (partition == null)
            {
                m_logger.LogWarning(Tag.Create(), "Publisher run before partition provided.");

                return(Task.CompletedTask);
            }

            // Avoiding repeated pattern matching for each report entry.
            Action <SfHealthInformation> reportHealth = partition switch
            {
                IStatefulServicePartition statefulPartition => statefulPartition.ReportReplicaHealth,
                IStatelessServicePartition statelessPartition => statelessPartition.ReportInstanceHealth,
                                         _ => throw new ArgumentException($"Service partition type '{partition.GetType()}' is not supported."),
            };

            try
            {
                // We trust the framework to ensure that the report is not null and doesn't contain null entries.
                foreach (KeyValuePair <string, HealthReportEntry> entryPair in report.Entries)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    reportHealth(BuildSfHealthInformation(entryPair.Key, entryPair.Value));
                }

                cancellationToken.ThrowIfCancellationRequested();
                reportHealth(BuildSfHealthInformation(report));
            }
            catch (FabricObjectClosedException)
            {
                // Ignore, the service instance is closing.
            }

            return(Task.CompletedTask);
        }
        async Task <string> IStatelessServiceInstance.OpenAsync(
            IStatelessServicePartition partition,
            CancellationToken cancellationToken)
        {
            this.servicePartition = partition;

            // Set partition for user service instance before opening communication
            // listeners to enable users to report health using partition during
            // listener open process.
            this.userServiceInstance.Partition = partition;

            try
            {
                this.endpointCollection = await this.OpenCommunicationListenersAsync(cancellationToken);
            }
            catch (Exception exception)
            {
                ServiceTrace.Source.WriteWarningWithId(
                    TraceType,
                    this.traceId,
                    "Got exception when opening communication listeners - {0}",
                    exception);

                this.AbortCommunicationListeners();

                throw;
            }
            this.userServiceInstance.Addresses = this.endpointCollection.ToReadOnlyDictionary();

            this.runAsynCancellationTokenSource = new CancellationTokenSource();
            this.executeRunAsyncTask            = this.ScheduleRunAsync(this.runAsynCancellationTokenSource.Token);

            await this.userServiceInstance.OnOpenAsync(cancellationToken);

            return(this.endpointCollection.ToString());
        }
 protected override async Task OnOpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
 {
     if (StartProcessOnOpenAsync)
         await StartProcessAsync(cancellationToken);
     await base.OnOpenAsync(partition, cancellationToken);
 }
Esempio n. 11
0
        /// <summary>
        /// The open async.
        /// </summary>
        /// <param name="partition">
        /// The partition.
        /// </param>
        /// <param name="cancellationToken">
        /// The cancellation token.
        /// </param>
        /// <returns>
        /// A <see cref="Task"/> representing the work performed.
        /// </returns>
        public async Task<string> OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
        {
            var serviceName = this.parameters.ServiceName;
            var instanceId = this.parameters.InstanceId;
            var activation = this.parameters.CodePackageActivationContext;
            var node = await FabricRuntime.GetNodeContextAsync(TimeSpan.FromMinutes(1), cancellationToken);
            var nodeAddress = await GetNodeAddress(node.IPAddressOrFQDN);
            
            var context = await FabricRuntime.GetActivationContextAsync(TimeSpan.FromMinutes(5), CancellationToken.None);
            var serviceConfig = context.GetConfigurationPackageObject("Config").Settings;
            
            var siloEndpoint = new IPEndPoint(nodeAddress, activation.GetEndpoint("OrleansSiloEndpoint").Port);
            var proxyEndpoint = new IPEndPoint(nodeAddress, activation.GetEndpoint("OrleansProxyEndpoint").Port);

            var config = GetConfiguration();

            /*
            if (string.Equals(config.Globals.DataConnectionString, AzureStorageEmulator.UseDevelopmentStorage, StringComparison.Ordinal))
            {
                AzureStorageEmulator.Start();
            }
            */

            // Here you can read configuration from Fabric and modify the SiloConfiguration before starting the silo.
            /* 
            var storageConfig = new StorageConfiguration(serviceConfig);
            config.Globals.RegisterBootstrapProvider<SiloBootstrap>(SiloBootstrap.ProviderName);

            // Configure actor state storage.
            config.Globals.RegisterStorageProvider<AzureTableStorage>(
                "Default", 
                new Dictionary<string, string>
                {
                    { "DataConnectionString", storageConfig.ActorStateStoreConnectionString }, 
                    { "UseJsonFormat", true.ToString(CultureInfo.InvariantCulture) }
                });

            // Configure clustering.
            config.Globals.LivenessType = GlobalConfiguration.LivenessProviderType.AzureTable;
            config.Globals.DataConnectionString = storageConfig.ActorSystemStoreConnectionString;
            
            // Configure the event journal.
            // Note: Grain type and provider name are currently ignored.
            JournalProviderManager.Manager.GetProviderDelegate =
                (type, providerName) =>
                new AzureTableJournalProvider(storageConfig.JournalConnectionString, SerializationSettings.JsonConfig);
            */

            Trace.TraceInformation("Silo Configuration:\n{0}", config);
            var connectionString = config.Globals.DataConnectionString;
            try
            {
                this.fabricSilo = new OrleansFabricSilo(serviceName, instanceId, siloEndpoint, proxyEndpoint, connectionString);

                if (this.fabricSilo.Start(config))
                {
                    this.MonitorSilo(partition);
                    return this.fabricSilo.SiloEndpoint.ToString();
                }
            }
            catch (Exception exception)
            {
                this.stopped.TrySetException(exception);
                this.fabricSilo.Abort();
                throw;
            }

            partition.ReportFault(FaultType.Transient);
            var failure = new InvalidOperationException("Failed to start silo.");
            this.stopped.TrySetException(failure);
            throw failure;
        }
Esempio n. 12
0
 public Threading.Tasks.Task <string> OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
 {
     ServiceImplementationHelper.HandleOpen(this.initParams.InitializationData, this.instanceId);
     return(Task.Factory.StartNew <string>(() => "http://localhost:80"));
 }
Esempio n. 13
0
 public async Task <string> OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
 {
     return(@"{""Endpoints"":{""Listener1"":""Endpoint1"",""Listener2"":""Endpoint2"" }}");
 }
Esempio n. 14
0
 public StatelessServiceLoadReporter(IStatelessServicePartition partition)
 {
     _partition = partition;
 }
Esempio n. 15
0
 public Threading.Tasks.Task <string> OpenAsync(IStatelessServicePartition partition, CancellationToken cancellationToken)
 {
     throw new NotImplementedException();
 }