public Task <string> OpenAsync(CancellationToken cancellationToken) { StatefulServiceInitializationParameters statefulInitParam = this.serviceParameters as StatefulServiceInitializationParameters; int port = this.serviceParameters.CodePackageActivationContext.GetEndpoint("ServiceEndPoint").Port; if (statefulInitParam != null) { this.listeningAddress = String.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}/{2}/{3}/", port, statefulInitParam.PartitionId, statefulInitParam.ReplicaId, Guid.NewGuid()); } else { this.listeningAddress = String.Format( CultureInfo.InvariantCulture, "http://+:{0}/", port); } this.publishingAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); this.webServer = WebApp.Start(this.listeningAddress, app => this.pipelineSpec.CreateOwinPipeline(app)); return(Task.FromResult(this.publishingAddress)); }
private ICommunicationListener CreateInternalListener(StatefulServiceInitializationParameters args) { // Partition replica's URL is the node's IP, port, PartitionId, ReplicaId, Guid EndpointResourceDescription internalEndpoint = args.CodePackageActivationContext.GetEndpoint("ProcessingServiceEndpoint"); // Multiple replicas of this service may be hosted on the same machine, // so this address needs to be unique to the replica which is why we have partition ID + replica ID in the URL. // HttpListener can listen on multiple addresses on the same port as long as the URL prefix is unique. // The extra GUID is there for an advanced case where secondary replicas also listen for read-only requests. // When that's the case, we want to make sure that a new unique address is used when transitioning from primary to secondary // to force clients to re-resolve the address. // '+' is used as the address here so that the replica listens on all available hosts (IP, FQDM, localhost, etc.) string uriPrefix = String.Format( "{0}://+:{1}/{2}/{3}-{4}/", internalEndpoint.Protocol, internalEndpoint.Port, this.ServiceInitializationParameters.PartitionId, this.ServiceInitializationParameters.ReplicaId, Guid.NewGuid()); string nodeIP = FabricRuntime.GetNodeContext().IPAddressOrFQDN; // The published URL is slightly different from the listening URL prefix. // The listening URL is given to HttpListener. // The published URL is the URL that is published to the Service Fabric Naming Service, // which is used for service discovery. Clients will ask for this address through that discovery service. // The address that clients get needs to have the actual IP or FQDN of the node in order to connect, // so we need to replace '+' with the node's IP or FQDN. string uriPublished = uriPrefix.Replace("+", nodeIP); return(new HttpCommunicationListener(uriPrefix, uriPublished, this.ProcessInternalRequest)); }
public void Initialize(StatefulServiceInitializationParameters initializationParameters) { this.currentRole = ReplicaRole.Unknown; this.initializationParameters = initializationParameters; this.TraceInfo("IStatefulServiceReplica::Initialize invoked for service {0}.", this.initializationParameters.ServiceName); }
void IStateProviderReplica.Initialize(StatefulServiceInitializationParameters initializationParameters) { this.initiParams = initializationParameters; this.traceId = ActorTrace.GetTraceIdForReplica(this.initiParams.PartitionId, this.initiParams.ReplicaId); var statefulServiceContext = new StatefulServiceContext( FabricRuntime.GetNodeContext(), this.initiParams.CodePackageActivationContext, this.initiParams.ServiceTypeName, this.initiParams.ServiceName, this.initiParams.InitializationData, this.initiParams.PartitionId, this.initiParams.ReplicaId); var stateManagerConfig = this.userDefinedStateManagerConfig; if (stateManagerConfig == null) { var actorImplType = this.actorTypeInformation.ImplementationType; stateManagerConfig = new ReliableStateManagerConfiguration( ActorNameFormat.GetConfigPackageName(actorImplType), ActorNameFormat.GetFabricServiceReplicatorSecurityConfigSectionName(actorImplType), ActorNameFormat.GetFabricServiceReplicatorConfigSectionName(actorImplType)); } this.stateManager = new ReliableStateManager(statefulServiceContext, stateManagerConfig); ReleaseAssert.AssertIfNull(this.onDataLossAsyncFunc, "onDataLossAsync event handler cannot be null."); this.stateManager.OnDataLossAsync = this.onDataLossAsyncFunc; this.stateManager.Initialize(this.initiParams); }
private ICommunicationListener CreateInternalListener(StatefulServiceInitializationParameters args) { // Partition replica's URL is the node's IP, port, PartitionId, ReplicaId, Guid EndpointResourceDescription internalEndpoint = args.CodePackageActivationContext.GetEndpoint("ProcessingServiceEndpoint"); // Multiple replicas of this service may be hosted on the same machine, // so this address needs to be unique to the replica which is why we have partition ID + replica ID in the URL. // HttpListener can listen on multiple addresses on the same port as long as the URL prefix is unique. // The extra GUID is there for an advanced case where secondary replicas also listen for read-only requests. // When that's the case, we want to make sure that a new unique address is used when transitioning from primary to secondary // to force clients to re-resolve the address. // '+' is used as the address here so that the replica listens on all available hosts (IP, FQDM, localhost, etc.) string uriPrefix = String.Format( "{0}://+:{1}/{2}/{3}-{4}/", internalEndpoint.Protocol, internalEndpoint.Port, this.ServiceInitializationParameters.PartitionId, this.ServiceInitializationParameters.ReplicaId, Guid.NewGuid()); string nodeIP = FabricRuntime.GetNodeContext().IPAddressOrFQDN; // The published URL is slightly different from the listening URL prefix. // The listening URL is given to HttpListener. // The published URL is the URL that is published to the Service Fabric Naming Service, // which is used for service discovery. Clients will ask for this address through that discovery service. // The address that clients get needs to have the actual IP or FQDN of the node in order to connect, // so we need to replace '+' with the node's IP or FQDN. string uriPublished = uriPrefix.Replace("+", nodeIP); return new HttpCommunicationListener(uriPrefix, uriPublished, this.ProcessInternalRequest); }
private void InitializeKvs(StatefulServiceInitializationParameters initParams) { this.configSectionName = Encoding.Unicode.GetString(initParams.InitializationData); string enableTStoreString = this.configStore.ReadUnencryptedString( this.configSectionName, Constants.ConfigurationSection.EnableTStore); bool enableTStore = (string.Compare(enableTStoreString, "true", StringComparison.CurrentCultureIgnoreCase) == 0); string globalEnableTStoreString = this.configStore.ReadUnencryptedString( Constants.ConfigurationSection.ReplicatedStore, Constants.ConfigurationSection.EnableTStore); bool globalEnableTStore = (string.Compare(globalEnableTStoreString, "true", StringComparison.CurrentCultureIgnoreCase) == 0); if (enableTStore || globalEnableTStore) { base.Initialize_OverrideNativeKeyValueStore(initParams); } else { base.Initialize(initParams); } }
void IStateProviderReplica.Initialize(StatefulServiceInitializationParameters initParams) { traceId = initParams.PartitionId.ToString("B") + ":" + initParams.ReplicaId.ToString(CultureInfo.InvariantCulture); this.initParams = initParams; storeReplica = CreateStoreReplica(); storeReplica.Initialize(this.initParams); }
/// <summary> /// Creates and returns a communication listener. /// </summary> /// <param name="initializationParameters"> /// The service initialization parameters. /// </param> /// <returns> /// A new <see cref="ICommunicationListener"/>. /// </returns> private ICommunicationListener CreateCommunicationListener(StatefulServiceInitializationParameters initializationParameters) { return(new WcfCommunicationListener(initializationParameters, typeof(ITableStoreService), this) { Binding = ServiceBindings.TcpBinding, EndpointResourceName = "ServiceEndpoint" }); }
void IStateProviderReplica.Initialize(StatefulServiceInitializationParameters initializationParameters) { if (this._backupRestoreManager != null) { this._backupRestoreManager.Initialize(initializationParameters); } ((IStateProviderReplica)this._replica).Initialize(initializationParameters); }
public void Initialize(StatefulServiceInitializationParameters context) { this.serviceParameters = context; var replicaId = context.ReplicaId.ToString("X"); var partitionKey = context.PartitionId.ToString("N"); var workDirectory = context.CodePackageActivationContext.WorkDirectory; this.logFilePath = Path.Combine(workDirectory, $"journal_{partitionKey}_{replicaId}"); }
public Task <string> OpenAsync(CancellationToken cancellationToken) { ServiceEventSource.Current.Message("Initialize"); EndpointResourceDescription serviceEndpoint = serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; if (serviceInitializationParameters is StatefulServiceInitializationParameters) { StatefulServiceInitializationParameters statefulInitParams = (StatefulServiceInitializationParameters)serviceInitializationParameters; this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}/{2}/{3}", port, statefulInitParams.PartitionId, statefulInitParams.ReplicaId, Guid.NewGuid()); } else if (serviceInitializationParameters is StatelessServiceInitializationParameters) { this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, string.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + '/'); } else { throw new InvalidOperationException(); } this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); ServiceEventSource.Current.Message("Opening on {0}", this.publishAddress); try { ServiceEventSource.Current.Message("Starting web server on {0}", this.listeningAddress); this.serverHandle = WebApp.Start(this.listeningAddress, appBuilder => this.startup.Configuration(appBuilder)); return(Task.FromResult(this.publishAddress)); } catch (Exception ex) { Trace.WriteLine(ex); this.StopWebServer(); throw; } }
/// <summary> /// Creates and returns a communication listener. /// </summary> /// <param name="initializationParameters"> /// The service initialization parameters. /// </param> /// <returns> /// A new <see cref="ICommunicationListener"/>. /// </returns> public ICommunicationListener CreateCommunicationListener(StatefulServiceInitializationParameters initializationParameters) { this.replicaId = initializationParameters.ReplicaId; this.partitionId = initializationParameters.PartitionId; return(new WcfCommunicationListener(initializationParameters, typeof(IKeyValueStore), this) { Binding = ServiceBindings.TcpBinding, EndpointResourceName = "ServiceEndpoint" }); }
public static UpgradeSystemService CreateAndInitialize(StatefulServiceInitializationParameters initParams) { var replica = new UpgradeSystemService( initParams.CodePackageActivationContext.WorkDirectory, initParams.PartitionId); replica.InitializeKvs(initParams); return(replica); }
/// <summary> /// This is the very first method called by the framework /// Provides all the initialization information /// No complex processing should be done here /// All heavy lifting should be done in Open /// </summary> /// <param name="initParameters">Initialization parameters.</param> void IStatefulServiceReplica.Initialize(StatefulServiceInitializationParameters initParameters) { this.tracer = new Tracer(initParameters.PartitionId, initParameters.ReplicaId); FabricEvents.Events.Lifecycle( this.tracer.Type, "Initialize" + " Name: " + initParameters.ServiceTypeName + " Uri: " + initParameters.ServiceName + " PartitionId: " + initParameters.PartitionId + " ReplicaId: " + initParameters.ReplicaId); this.initializationParameters = initParameters; }
protected override void OnInitialize(StatefulServiceInitializationParameters initializationParameters) { initializationParameters.ThrowIfNull("initializationParameters"); base.OnInitialize(initializationParameters); this.UpdateReplicatorSettings(this.GetReplicatorSettings()); this.serviceId = string.Format( CultureInfo.InvariantCulture, "[{0}+{1}+{2}]", initializationParameters.ServiceName, initializationParameters.PartitionId, initializationParameters.ReplicaId); }
public BackupStore( Uri endpoint, StorageCredentials credentials, IStatefulServicePartition servicePartition, StatefulServiceInitializationParameters statefulServiceInitializationParameters) { this.cloudBlobClient = new CloudBlobClient(endpoint, credentials); this.servicePartition = servicePartition; this.statefulServiceInitializationParameters = statefulServiceInitializationParameters; this.backupBlobContainer = this.GetBackupBlobContainer(); }
public BackupStore( Uri endpoint, StorageCredentials credentials, IStatefulServicePartition servicePartition, Guid testId, StatefulServiceInitializationParameters statefulServiceInitializationParameters) { this.cloudBlobClient = new CloudBlobClient(endpoint, credentials); this.servicePartition = servicePartition; this.testId = testId; this.statefulServiceInitializationParameters = statefulServiceInitializationParameters; this.backupBlobContainer = this.GetBackupBlobContainer(); }
public void Initialize(StatefulServiceInitializationParameters initializationParameters) { if (initializationParameters == null) { throw new ArgumentNullException("initializationParameters"); } this.initializationParameters = initializationParameters; this.serviceId = string.Format( CultureInfo.InvariantCulture, "[{0}+{1}]", initializationParameters.PartitionId, initializationParameters.ReplicaId); }
public void ServiceMessage(StatefulServiceInitializationParameters service, string message, params object[] args) { if (this.IsEnabled()) { string finalMessage = string.Format(message, args); this.ServiceMessage( service.ServiceName.ToString(), service.ServiceTypeName, service.ReplicaId, service.PartitionId, service.CodePackageActivationContext.ApplicationName, service.CodePackageActivationContext.ApplicationTypeName, FabricRuntime.GetNodeContext().NodeName, finalMessage); } }
public void Initialize(StatefulServiceInitializationParameters initializationParameters) { this.initParams = initializationParameters; this.partitionId = initializationParameters.PartitionId; this.replicaId = initializationParameters.ReplicaId; // write the information from the code package activation context var context = initializationParameters.CodePackageActivationContext; WriteEventToGlobalFile(string.Format(CultureInfo.InvariantCulture, "ApplicationName = {0}", context.ApplicationName)); WriteEventToGlobalFile(string.Format(CultureInfo.InvariantCulture, "ApplicationTypeName = {0}", context.ApplicationTypeName)); WriteEventToGlobalFile(string.Format(CultureInfo.InvariantCulture, "ServiceManifestName = {0}", context.GetServiceManifestName())); WriteEventToGlobalFile(string.Format(CultureInfo.InvariantCulture, "ServiceManifestVersion = {0}", context.GetServiceManifestVersion())); WriteEventToGlobalFile(string.Format(CultureInfo.InvariantCulture, "CodePackageName = {0}", context.CodePackageName)); WriteEventToGlobalFile(string.Format(CultureInfo.InvariantCulture, "CodePackageVersion = {0}", context.CodePackageVersion)); }
public void ServiceMessage(StatefulServiceInitializationParameters service, string message, params object[] args) { if (this.IsEnabled()) { string finalMessage = string.Format(message, args); ServiceMessage( service.ServiceName.ToString(), service.ServiceTypeName, service.ReplicaId, service.PartitionId, service.CodePackageActivationContext.ApplicationName, service.CodePackageActivationContext.ApplicationTypeName, FabricRuntime.GetNodeContext().NodeName, finalMessage); } }
IStatefulServiceReplica IStatefulServiceFactory.CreateReplica( string serviceTypeName, Uri serviceName, byte[] initializationData, Guid partitionId, long replicaId) { var initParams = new StatefulServiceInitializationParameters(FabricRuntime.GetActivationContext()) { ServiceTypeName = serviceTypeName, ServiceName = serviceName, InitializationData = initializationData, PartitionId = partitionId, ReplicaId = replicaId, }; return(UpgradeSystemService.CreateAndInitialize(initParams)); }
public void Initialize() { ServiceEventSource.Current.Message("Initialize"); EndpointResourceDescription serviceEndpoint = this.serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; if (this.serviceInitializationParameters is StatefulServiceInitializationParameters) { StatefulServiceInitializationParameters statefulInitParams = (StatefulServiceInitializationParameters)this.serviceInitializationParameters; this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}/{2}/{3}", port, statefulInitParams.PartitionId.ToString().Replace("-", ""), statefulInitParams.ReplicaId, this.appRoot); } else if (this.serviceInitializationParameters is StatelessServiceInitializationParameters) { this.listeningAddress = string.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, string.IsNullOrWhiteSpace(this.appRoot) ? string.Empty : this.appRoot.TrimEnd('/') + '/'); } else { throw new InvalidOperationException(); } //this.listeningAddress = String.Format( // CultureInfo.InvariantCulture, // "http://+:{0}/{1}", // port, // String.IsNullOrWhiteSpace(this.appRoot) // ? String.Empty // : this.appRoot.TrimEnd('/') + '/'); this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); }
public void Initialize(StatefulServiceInitializationParameters context) { serviceParameters = context; string replicaId = context.ReplicaId.ToString("X"); string partitionKey = context.PartitionId.ToString("N"); string workDirectory = context.CodePackageActivationContext.WorkDirectory; logFilePath = Path.Combine(workDirectory, $"journal_{partitionKey}_{replicaId}"); NodeContext nodeContext = FabricRuntime.GetNodeContext(); serviceContext = new StatefulServiceContext( nodeContext, context.CodePackageActivationContext, context.ServiceTypeName, context.ServiceName, context.InitializationData, context.PartitionId, context.ReplicaId); }
/// <summary> /// Initializes the replica object. /// </summary> /// <param name="initializationParameters">Service initialization parameters.</param> public virtual void Initialize(StatefulServiceInitializationParameters initializationParameters) { // // Check arguments. // if (null == initializationParameters) { AppTrace.TraceSource.WriteError("StatefulServiceReplica.Initialize", "{0}", this.GetHashCode()); throw new ArgumentNullException("initializationParameters"); } // // Perform local initialization. // this.initializationParameters = initializationParameters; AppTrace.TraceSource.WriteNoise("StatefulServiceReplica.Initialize", "{0}", this.ToString()); // // Perform custom initialization. // this.OnInitialize(initializationParameters); }
internal static void SetupLoggerPath( ref ReliableStateManagerReplicatorSettings replicatorSettings, ref StatefulServiceInitializationParameters initializationParameters) { string pathToSharedContainer; // Use this when running with the kernel mode logger as all replicas for all nodes should use the same log if (string.IsNullOrEmpty(replicatorSettings.SharedLogId) || string.IsNullOrEmpty(replicatorSettings.SharedLogPath)) { string fabricDataRoot; try { fabricDataRoot = System.Fabric.Common.FabricEnvironment.GetDataRoot(); } catch (Exception) { // // If the Fabric Data Root does not exist then we may be running in a container. And in // this case we count on the driver to do the mapping into the host path. So pick a random // path here knowing it will be mapped. // fabricDataRoot = "q:\\"; } // Use default log id and location {3CA2CCDA-DD0F-49c8-A741-62AAC0D4EB62} var staticLogContainerGuid = Constants.DefaultSharedLogContainerGuid; pathToSharedContainer = System.IO.Path.Combine( fabricDataRoot, Constants.DefaultSharedLogSubdirectory); pathToSharedContainer = System.IO.Path.Combine(pathToSharedContainer, Constants.DefaultSharedLogName); replicatorSettings.SharedLogId = staticLogContainerGuid; replicatorSettings.SharedLogPath = pathToSharedContainer; } }
public void Initialize(ServiceInitializationParameters serviceInitializationParameters) { Trace.WriteLine("Initialize"); EndpointResourceDescription serviceEndpoint = serviceInitializationParameters.CodePackageActivationContext.GetEndpoint("ServiceEndpoint"); int port = serviceEndpoint.Port; if (serviceInitializationParameters is StatefulServiceInitializationParameters) { StatefulServiceInitializationParameters statefulInitParams = (StatefulServiceInitializationParameters)serviceInitializationParameters; this.listeningAddress = String.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}/{2}/{3}", port, statefulInitParams.PartitionId, statefulInitParams.ReplicaId, Guid.NewGuid()); } else if (serviceInitializationParameters is StatelessServiceInitializationParameters) { this.listeningAddress = String.Format( CultureInfo.InvariantCulture, "http://+:{0}/{1}", port, String.IsNullOrWhiteSpace(this.appRoot) ? String.Empty : this.appRoot.TrimEnd('/') + '/'); } else { throw new InvalidOperationException(); } this.publishAddress = this.listeningAddress.Replace("+", FabricRuntime.GetNodeContext().IPAddressOrFQDN); }
void IStatefulServiceReplica.Initialize(StatefulServiceInitializationParameters initializationParameters) { // See comments regarding state provider replica in c'tor this.stateProviderReplica.Initialize(initializationParameters); }
public Logger(StatefulServiceInitializationParameters initializationParameters) { this.InitializationParameters = initializationParameters; }
public void Initialize(StatefulServiceInitializationParameters initializationParameters) { InitializationParameters = initializationParameters; }
public void Initialize(StatefulServiceInitializationParameters initializationParameters) { throw new NotImplementedException(); }
void IStateProviderReplica.Initialize(StatefulServiceInitializationParameters initializationParameters) { this.initParams = initializationParameters; this.traceId = ActorTrace.GetTraceIdForReplica(this.initParams.PartitionId, this.initParams.ReplicaId); }
/// <inheritdoc /> public void Initialize(StatefulServiceInitializationParameters initializationParameters) { this.initializationParameters = initializationParameters; this.currentRole = ReplicaRole.Unknown; }