internal async Task<List<IGossipChannel>> GetGossipChannels(Silo silo) { List<IGossipChannel> gossipChannels = new List<IGossipChannel>(); var channelConfigurations = silo.GlobalConfig.GossipChannels; if (channelConfigurations != null) { foreach (var channelConfiguration in channelConfigurations) { switch (channelConfiguration.ChannelType) { case GlobalConfiguration.GossipChannelType.AzureTable: var tableChannel = AssemblyLoader.LoadAndCreateInstance<IGossipChannel>(Constants.ORLEANS_AZURE_UTILS_DLL, logger); await tableChannel.Initialize(silo.GlobalConfig.ServiceId, channelConfiguration.ConnectionString); gossipChannels.Add(tableChannel); break; default: break; } logger.Info("Configured Gossip Channel: Type={0} ConnectionString={1}", channelConfiguration.ChannelType, channelConfiguration.ConnectionString); } } return gossipChannels; }
public static void Initialize(Silo silo, IGrainFactory grainFactory, string reminderTableAssembly = null) { var config = silo.GlobalConfig; var serviceType = config.ReminderServiceType; var logger = TraceLogger.GetLogger("ReminderTable"); switch (serviceType) { default: throw new NotSupportedException( String.Format( "The reminder table does not currently support service provider {0}.", serviceType)); case GlobalConfiguration.ReminderServiceProviderType.SqlServer: Singleton = AssemblyLoader.LoadAndCreateInstance<IReminderTable>(Constants.ORLEANS_SQL_UTILS_DLL, logger); return; case GlobalConfiguration.ReminderServiceProviderType.AzureTable: Singleton = AssemblyLoader.LoadAndCreateInstance<IReminderTable>(Constants.ORLEANS_AZURE_UTILS_DLL, logger); return; case GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain: Singleton = grainFactory.GetGrain<IReminderTableGrain>(Constants.ReminderTableGrainId); return; case GlobalConfiguration.ReminderServiceProviderType.MockTable: Singleton = new MockReminderTable(config.MockReminderTableTimeout); return; case GlobalConfiguration.ReminderServiceProviderType.Custom: Singleton = AssemblyLoader.LoadAndCreateInstance<IReminderTable>(reminderTableAssembly, logger); return; } }
internal Task CreateMembershipTableProvider(Catalog catalog, Silo silo) { var livenessType = silo.GlobalConfig.LivenessType; logger.Info(ErrorCode.MembershipFactory1, "Creating membership table provider for type={0}", Enum.GetName(typeof(GlobalConfiguration.LivenessProviderType), livenessType)); if (livenessType.Equals(GlobalConfiguration.LivenessProviderType.MembershipTableGrain)) { return catalog.CreateSystemGrain( Constants.SystemMembershipTableId, typeof(GrainBasedMembershipTable).FullName); } return TaskDone.Done; }
public static MvcHtmlString StationChannelLinks(this HtmlHelper helper, Silo.Domain.Entities.Station station) { if (station.Channels != null && station.Channels.Any()) { string text = String.Join(", ", station.Channels.OrderBy(x => x.TxAntAzimuth).Select(x => (int)x.TxAntAzimuth).ToArray()); return helper.ActionLink(text, "Channels", null, new { station.Id }, new { style = "text-decoration: underline" }); } else { return helper.ActionLink("New Channel", "Create", "Channel", new { stationId = station.Id }, new { @class = "btn btn-success" }); } }
internal async Task<IMultiClusterOracle> CreateGossipOracle(Silo silo) { if (! silo.GlobalConfig.HasMultiClusterNetwork) { logger.Info("Skip multicluster oracle creation (no multicluster network configured)"); return null; } logger.Info("Creating multicluster oracle..."); var channels = await GetGossipChannels(silo); if (channels.Count == 0) logger.Warn(ErrorCode.MultiClusterNetwork_NoChannelsConfigured, "No gossip channels are configured."); var gossipOracle = new MultiClusterOracle(silo.SiloAddress, channels, silo.GlobalConfig); logger.Info("Created multicluster oracle."); return gossipOracle; }
private int HandleCropsReadyForHarvest(int cropCount) { Silo siloToFill = null; if (previouslyFilledSilo && previouslyFilledSilo.GetPercentFilled() < 1.0f) siloToFill = previouslyFilledSilo; else siloToFill = previouslyFilledSilo = GetGreatestNonFullSilo(); int leftOverCrops = cropCount; if (!siloToFill) { print("No silos available to fill"); return 0; } while (leftOverCrops > 0) { leftOverCrops = siloToFill.AddCrops(leftOverCrops); if (siloToFill.GetPercentFilled() >= 1.0f) siloToFill = GetGreatestNonFullSilo(); if (!siloToFill) break; } return cropCount - leftOverCrops; //Return the number of crops successfully deposited }
internal string SiloName { get; private set; } // name of this silo. internal MembershipOracleData(Silo silo, TraceLogger log) { logger = log; localTable = new Dictionary<SiloAddress, MembershipEntry>(); localTableCopy = new Dictionary<SiloAddress, SiloStatus>(); localTableCopyOnlyActive = new Dictionary<SiloAddress, SiloStatus>(); localNamesTableCopy = new Dictionary<SiloAddress, string>(); statusListeners = new List<ISiloStatusListener>(); SiloStartTime = DateTime.UtcNow; MyAddress = silo.SiloAddress; MyHostname = silo.LocalConfig.DNSHostName; SiloName = silo.LocalConfig.SiloName; CurrentStatus = SiloStatus.Created; clusterSizeStatistic = IntValueStatistic.FindOrCreate(StatisticNames.MEMBERSHIP_ACTIVE_CLUSTER_SIZE, () => localTableCopyOnlyActive.Count); clusterStatistic = StringValueStatistic.FindOrCreate(StatisticNames.MEMBERSHIP_ACTIVE_CLUSTER, () => { List<string> list = localTableCopyOnlyActive.Keys.Select(addr => addr.ToLongString()).ToList(); list.Sort(); return Utils.EnumerableToString(list); }); }
internal async Task SetSiloMetricsTableDataManager(Silo silo, NodeConfiguration nodeConfig) { bool useAzureTable; bool useExternalMetricsProvider = ShouldUseExternalMetricsProvider(silo, nodeConfig, out useAzureTable); if (useExternalMetricsProvider) { var extType = nodeConfig.StatisticsProviderName; var metricsProvider = silo.StatisticsProviderManager.GetProvider(extType); var metricsDataPublisher = metricsProvider as ISiloMetricsDataPublisher; if (metricsDataPublisher == null) { var msg = String.Format("Trying to create {0} as a silo metrics publisher, but the provider is not available." + " Expected type = {1} Actual type = {2}", extType, typeof(IStatisticsPublisher), metricsProvider.GetType()); throw new InvalidOperationException(msg); } var configurableMetricsDataPublisher = metricsDataPublisher as IConfigurableSiloMetricsDataPublisher; if (configurableMetricsDataPublisher != null) { var gateway = nodeConfig.IsGatewayNode ? nodeConfig.ProxyGatewayEndpoint : null; configurableMetricsDataPublisher.AddConfiguration( silo.GlobalConfig.DeploymentId, true, silo.Name, silo.SiloAddress, gateway, nodeConfig.DNSHostName); } MetricsTable.MetricsDataPublisher = metricsDataPublisher; } else if (useAzureTable) { // Hook up to publish silo metrics to Azure storage table var gateway = nodeConfig.IsGatewayNode ? nodeConfig.ProxyGatewayEndpoint : null; var metricsDataPublisher = AssemblyLoader.LoadAndCreateInstance<ISiloMetricsDataPublisher>(Constants.ORLEANS_AZURE_UTILS_DLL, logger); await metricsDataPublisher.Init(silo.GlobalConfig.DeploymentId, silo.GlobalConfig.DataConnectionString, silo.SiloAddress, silo.Name, gateway, nodeConfig.DNSHostName); MetricsTable.MetricsDataPublisher = metricsDataPublisher; } // else no metrics }
/// <summary> /// Initialize this silo. /// </summary> public void InitializeOrleansSilo() { #if DEBUG AssemblyLoaderUtils.EnableAssemblyLoadTracing(); #endif try { if (!ConfigLoaded) LoadOrleansConfig(); orleans = new Silo(Name, Type, Config); } catch (Exception exc) { ReportStartupError(exc); orleans = null; } }
public LocalGrainDirectory(Silo silo) { log = TraceLogger.GetLogger("Orleans.GrainDirectory.LocalGrainDirectory"); MyAddress = silo.LocalMessageCenter.MyAddress; Scheduler = silo.LocalScheduler; membershipRingList = new List<SiloAddress>(); membershipCache = new HashSet<SiloAddress>(); silo.OrleansConfig.OnConfigChange("Globals/Caching", () => { lock (membershipCache) { DirectoryCache = GrainDirectoryCacheFactory<List<Tuple<SiloAddress, ActivationId>>>.CreateGrainDirectoryCache(silo.GlobalConfig); } }); maintainer = GrainDirectoryCacheFactory<List<Tuple<SiloAddress, ActivationId>>>.CreateGrainDirectoryCacheMaintainer(this, DirectoryCache); if (silo.GlobalConfig.SeedNodes.Count > 0) { seed = silo.GlobalConfig.SeedNodes.Contains(MyAddress.Endpoint) ? MyAddress : SiloAddress.New(silo.GlobalConfig.SeedNodes[0], 0); } stopPreparationResolver = new TaskCompletionSource<bool>(); DirectoryPartition = new GrainDirectoryPartition(); HandoffManager = new GrainDirectoryHandoffManager(this, silo.GlobalConfig); RemGrainDirectory = new RemoteGrainDirectory(this, Constants.DirectoryServiceId); CacheValidator = new RemoteGrainDirectory(this, Constants.DirectoryCacheValidatorId); // add myself to the list of members AddServer(MyAddress); Func<SiloAddress, string> siloAddressPrint = (SiloAddress addr) => String.Format("{0}/{1:X}", addr.ToLongString(), addr.GetConsistentHashCode()); localLookups = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_LOCAL_ISSUED); localSuccesses = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_LOCAL_SUCCESSES); fullLookups = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_FULL_ISSUED); RemoteLookupsSent = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_REMOTE_SENT); RemoteLookupsReceived = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_REMOTE_RECEIVED); LocalDirectoryLookups = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_LOCALDIRECTORY_ISSUED); LocalDirectorySuccesses = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_LOCALDIRECTORY_SUCCESSES); cacheLookups = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_CACHE_ISSUED); cacheSuccesses = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_CACHE_SUCCESSES); StringValueStatistic.FindOrCreate(StatisticNames.DIRECTORY_LOOKUPS_CACHE_HITRATIO, () => { long delta1, delta2; long curr1 = cacheSuccesses.GetCurrentValueAndDelta(out delta1); long curr2 = cacheLookups.GetCurrentValueAndDelta(out delta2); return String.Format("{0}, Delta={1}", (curr2 != 0 ? (float)curr1 / (float)curr2 : 0) ,(delta2 !=0 ? (float)delta1 / (float)delta2 : 0)); }); CacheValidationsSent = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_VALIDATIONS_CACHE_SENT); CacheValidationsReceived = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_VALIDATIONS_CACHE_RECEIVED); registrationsIssued = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_REGISTRATIONS_ISSUED); RegistrationsLocal = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_REGISTRATIONS_LOCAL); RegistrationsRemoteSent = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_REGISTRATIONS_REMOTE_SENT); RegistrationsRemoteReceived = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_REGISTRATIONS_REMOTE_RECEIVED); registrationsSingleActIssued = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_REGISTRATIONS_SINGLE_ACT_ISSUED); RegistrationsSingleActLocal = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_REGISTRATIONS_SINGLE_ACT_LOCAL); RegistrationsSingleActRemoteSent = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_REGISTRATIONS_SINGLE_ACT_REMOTE_SENT); RegistrationsSingleActRemoteReceived = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_REGISTRATIONS_SINGLE_ACT_REMOTE_RECEIVED); unregistrationsIssued = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_UNREGISTRATIONS_ISSUED); UnregistrationsLocal = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_UNREGISTRATIONS_LOCAL); UnregistrationsRemoteSent = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_UNREGISTRATIONS_REMOTE_SENT); UnregistrationsRemoteReceived = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_UNREGISTRATIONS_REMOTE_RECEIVED); unregistrationsManyIssued = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_UNREGISTRATIONS_MANY_ISSUED); UnregistrationsManyRemoteSent = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_UNREGISTRATIONS_MANY_REMOTE_SENT); UnregistrationsManyRemoteReceived = CounterStatistic.FindOrCreate(StatisticNames.DIRECTORY_UNREGISTRATIONS_MANY_REMOTE_RECEIVED); directoryPartitionCount = IntValueStatistic.FindOrCreate(StatisticNames.DIRECTORY_PARTITION_SIZE, () => DirectoryPartition.Count); IntValueStatistic.FindOrCreate(StatisticNames.DIRECTORY_RING_MYPORTION_RINGDISTANCE, () => RingDistanceToSuccessor()); FloatValueStatistic.FindOrCreate(StatisticNames.DIRECTORY_RING_MYPORTION_RINGPERCENTAGE, () => (((float)RingDistanceToSuccessor()) / ((float)(int.MaxValue * 2L))) * 100); FloatValueStatistic.FindOrCreate(StatisticNames.DIRECTORY_RING_MYPORTION_AVERAGERINGPERCENTAGE, () => membershipRingList.Count == 0 ? 0 : ((float)100 / (float)membershipRingList.Count)); IntValueStatistic.FindOrCreate(StatisticNames.DIRECTORY_RING_RINGSIZE, () => membershipRingList.Count); StringValueStatistic.FindOrCreate(StatisticNames.DIRECTORY_RING, () => { lock (membershipCache) { return Utils.EnumerableToString(membershipRingList, siloAddressPrint); } }); StringValueStatistic.FindOrCreate(StatisticNames.DIRECTORY_RING_PREDECESSORS, () => Utils.EnumerableToString(FindPredecessors(MyAddress, 1), siloAddressPrint)); StringValueStatistic.FindOrCreate(StatisticNames.DIRECTORY_RING_SUCCESSORS, () => Utils.EnumerableToString(FindSuccessors(MyAddress, 1), siloAddressPrint)); }
internal TestHooksSystemTarget(Silo silo) : base(Constants.TestHooksSystemTargetId, silo.SiloAddress) { this.silo = silo; consistentRingProvider = silo.RingProvider; }
internal InsideRcManagerSystem(InsideRcManager insideRcManager, Silo silo) : base(Constants.ReactiveCacheManagerId, silo.SiloAddress) { InsideRcManager = insideRcManager; }
/// <summary> /// Start this silo. /// </summary> /// <returns></returns> public bool StartOrleansSilo() { try { if (string.IsNullOrEmpty(Thread.CurrentThread.Name)) Thread.CurrentThread.Name = this.GetType().Name; if (orleans != null) { orleans.Start(); var startupEventName = Name; logger.Info(ErrorCode.SiloStartupEventName, "Silo startup event name: {0}", startupEventName); bool createdNew; startupEvent = new EventWaitHandle(true, EventResetMode.ManualReset, startupEventName, out createdNew); if (!createdNew) { logger.Info(ErrorCode.SiloStartupEventOpened, "Opened existing startup event. Setting the event {0}", startupEventName); startupEvent.Set(); } else { logger.Info(ErrorCode.SiloStartupEventCreated, "Created and set startup event {0}", startupEventName); } logger.Info(ErrorCode.SiloStarted, "Silo {0} started successfully", Name); IsStarted = true; } else { throw new InvalidOperationException("Cannot start silo " + this.Name + " due to prior initialization error"); } } catch (Exception exc) { ReportStartupError(exc); orleans = null; IsStarted = false; return false; } return true; }
/// <summary> /// Initialize this silo. /// </summary> public void InitializeOrleansSilo() { #if DEBUG AssemblyLoaderUtils.EnableAssemblyLoadTracing(); #endif try { if (!ConfigLoaded) LoadOrleansConfig(); logger.Info( ErrorCode.SiloInitializing, "Initializing Silo {0} on host={1} CPU count={2} running .NET version='{3}' Is .NET 4.5={4} OS version='{5}'", Name, Environment.MachineName, Environment.ProcessorCount, Environment.Version, ConfigUtilities.IsNet45OrNewer(), Environment.OSVersion); logger.Info(ErrorCode.SiloGcSetting, "Silo running with GC settings: ServerGC={0} GCLatencyMode={1}", GCSettings.IsServerGC, Enum.GetName(typeof(GCLatencyMode), GCSettings.LatencyMode)); if (!GCSettings.IsServerGC) logger.Warn(ErrorCode.SiloGcWarning, "Note: Silo not running with ServerGC turned on - recommend checking app config : <configuration>-<runtime>-<gcServer enabled=\"true\"> and <configuration>-<runtime>-<gcConcurrent enabled=\"false\"/>"); orleans = new Silo(Name, Type, Config); } catch (Exception exc) { ReportStartupError(exc); orleans = null; } }
/// <summary> /// Initialize this silo. /// </summary> public void InitializeOrleansSilo() { #if DEBUG AssemblyLoaderUtils.EnableAssemblyLoadTracing(); #endif try { if (!ConfigLoaded) LoadOrleansConfig(); orleans = new Silo(Name, Type, Config); logger.Info(ErrorCode.Runtime_Error_100288, "Successfully initialized Orleans silo '{0}' as a {1} node.", orleans.Name, orleans.Type); } catch (Exception exc) { ReportStartupError(exc); orleans = null; } }
/// <summary> /// Start this silo. /// </summary> /// <returns></returns> public bool StartOrleansSilo() { try { if (string.IsNullOrEmpty(Thread.CurrentThread.Name)) Thread.CurrentThread.Name = this.GetType().Name; if (orleans != null) { var shutdownEventName = Config.Defaults.SiloShutdownEventName ?? Name + "-Shutdown"; logger.Info(ErrorCode.SiloShutdownEventName, "Silo shutdown event name: {0}", shutdownEventName); bool createdNew; shutdownEvent = new EventWaitHandle(false, EventResetMode.ManualReset, shutdownEventName, out createdNew); if (!createdNew) { logger.Info(ErrorCode.SiloShutdownEventOpened, "Opened existing shutdown event. Setting the event {0}", shutdownEventName); } else { logger.Info(ErrorCode.SiloShutdownEventCreated, "Created and set shutdown event {0}", shutdownEventName); } // Start silo orleans.Start(); // Wait for the shutdown event, and trigger a graceful shutdown if we receive it. var shutdownThread = new Thread( o => { shutdownEvent.WaitOne(); logger.Info(ErrorCode.SiloShutdownEventReceived, "Received a shutdown event. Starting graceful shutdown."); orleans.Shutdown(); }); shutdownThread.IsBackground = true; shutdownThread.Start(); var startupEventName = Name; logger.Info(ErrorCode.SiloStartupEventName, "Silo startup event name: {0}", startupEventName); startupEvent = new EventWaitHandle(true, EventResetMode.ManualReset, startupEventName, out createdNew); if (!createdNew) { logger.Info(ErrorCode.SiloStartupEventOpened, "Opened existing startup event. Setting the event {0}", startupEventName); startupEvent.Set(); } else { logger.Info(ErrorCode.SiloStartupEventCreated, "Created and set startup event {0}", startupEventName); } logger.Info(ErrorCode.SiloStarted, "Silo {0} started successfully", Name); IsStarted = true; } else { throw new InvalidOperationException("Cannot start silo " + this.Name + " due to prior initialization error"); } } catch (Exception exc) { ReportStartupError(exc); orleans = null; IsStarted = false; return false; } return true; }
/// <summary> /// Set the type of this silo. Default is Secondary. /// </summary> /// <param name="siloType">Type of this silo.</param> public void SetSiloType(Silo.SiloType siloType) { logger.Info(ErrorCode.SiloSetSiloType, "Setting silo type {0}", siloType); Type = siloType; }
private static bool ShouldUseExternalMetricsProvider( Silo silo, IStatisticsConfiguration nodeConfig, out bool useAzureTable) { useAzureTable = silo.GlobalConfig.LivenessType == GlobalConfiguration.LivenessProviderType.AzureTable && !string.IsNullOrEmpty(silo.GlobalConfig.DeploymentId) && !string.IsNullOrEmpty(silo.GlobalConfig.DataConnectionString); return !string.IsNullOrEmpty(nodeConfig.StatisticsProviderName); }
internal IMembershipOracle CreateMembershipOracle(Silo silo, IMembershipTable membershipTable) { var livenessType = silo.GlobalConfig.LivenessType; logger.Info("Creating membership oracle for type={0}", Enum.GetName(typeof(GlobalConfiguration.LivenessProviderType), livenessType)); return new MembershipOracle(silo, membershipTable); }
public MyPerSiloGrain(IGrainIdentity id, Silo silo, ILoggerFactory loggerFactory, IGrainFactory grainFactory) : base(id, silo, loggerFactory, grainFactory) { }