Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch HueBotSample from SFStateful to SFStateless. #248

Merged
merged 1 commit into from
May 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class Bot
/// <param name="options">The bot options.</param>
/// <param name="graphLogger">The graph logger.</param>
/// <param name="serviceContext">Service context.</param>
public Bot(BotOptions options, IGraphLogger graphLogger, StatefulServiceContext serviceContext)
public Bot(BotOptions options, IGraphLogger graphLogger, StatelessServiceContext serviceContext)
{
this.Options = options;
this.logger = graphLogger;
Expand Down Expand Up @@ -320,7 +320,7 @@ private CallHandler GetHandlerOrThrow(string callId)
/// <param name="options">The bot options.</param>
/// <param name="serviceContext">Service context.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
private MediaPlatformSettings MediaInit(BotOptions options, StatefulServiceContext serviceContext)
private MediaPlatformSettings MediaInit(BotOptions options, StatelessServiceContext serviceContext)
{
var instanceNumber = serviceContext.NodeInstance();
var publicMediaUrl = options.BotMediaProcessorUrl ?? options.BotBaseUrl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ namespace Sample.HueBot.Controllers
public class JoinCallController : Controller
{
private Bot bot;
private StatefulServiceContext statefulServiceContext;
private StatelessServiceContext statelessServiceContext;
private BotOptions botOptions;

/// <summary>
/// Initializes a new instance of the <see cref="JoinCallController"/> class.
/// </summary>
/// <param name="bot">Bot instance.</param>
/// <param name="statefulServiceContext">The service context.</param>
/// <param name="statelessServiceContext">The service context.</param>
/// <param name="botOptions">The bot options.</param>
public JoinCallController(Bot bot, StatefulServiceContext statefulServiceContext, BotOptions botOptions)
public JoinCallController(Bot bot, StatelessServiceContext statelessServiceContext, BotOptions botOptions)
{
this.bot = bot;
this.statefulServiceContext = statefulServiceContext;
this.statelessServiceContext = statelessServiceContext;
this.botOptions = botOptions;
}

Expand All @@ -48,7 +48,7 @@ public async Task<IActionResult> JoinCallAsync([FromBody] JoinCallBody joinCallB
var call = await this.bot.JoinCallAsync(joinCallBody).ConfigureAwait(false);

var serviceURL = new UriBuilder($"{this.Request.Scheme}://{this.Request.Host}");
serviceURL.Port = this.botOptions.BotBaseUrl.Port + this.statefulServiceContext.NodeInstance();
serviceURL.Port = this.botOptions.BotBaseUrl.Port + this.statelessServiceContext.NodeInstance();

return this.Ok(new JoinCallResponseBody
{
Expand Down
15 changes: 7 additions & 8 deletions Samples/V1.0Samples/LocalMediaSamples/HueBot/HueBot/HueBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace HueBot
/// <summary>
/// The FabricRuntime creates an instance of this class for each service type instance.
/// </summary>
internal sealed class HueBot : StatefulService
internal sealed class HueBot : StatelessService
{
private IGraphLogger logger;
private SampleObserver observer;
Expand All @@ -35,10 +35,10 @@ internal sealed class HueBot : StatefulService
/// <summary>
/// Initializes a new instance of the <see cref="HueBot" /> class.
/// </summary>
/// <param name="context">Stateful service context from service fabric.</param>
/// <param name="context">Stateless service context from service fabric.</param>
/// <param name="logger">Global logger instance.</param>
/// <param name="observer">Global observer instance.</param>
public HueBot(StatefulServiceContext context, IGraphLogger logger, SampleObserver observer)
public HueBot(StatelessServiceContext context, IGraphLogger logger, SampleObserver observer)
: base(context)
{
this.logger = logger;
Expand All @@ -54,7 +54,7 @@ public HueBot(StatefulServiceContext context, IGraphLogger logger, SampleObserve
/// Optional override to create listeners (like tcp, http) for this service instance.
/// </summary>
/// <returns>The collection of listeners.</returns>
protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListeners()
protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
{
this.configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
Expand All @@ -65,10 +65,10 @@ protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListe

this.bot = new Bot(this.botOptions, this.logger, this.Context);

var serviceReplicaListeners = new List<ServiceReplicaListener>();
var serviceInstanceListeners = new List<ServiceInstanceListener>();
foreach (string endpointName in new[] { "ServiceEndpoint", "SignalingPort", "LocalEndpoint" })
{
serviceReplicaListeners.Add(new ServiceReplicaListener(
serviceInstanceListeners.Add(new ServiceInstanceListener(
serviceContext =>
new HttpSysCommunicationListener(serviceContext, endpointName, (url, listener) =>
{
Expand All @@ -78,7 +78,7 @@ protected override IEnumerable<ServiceReplicaListener> CreateServiceReplicaListe
endpointName));
}

return serviceReplicaListeners.ToArray();
return serviceInstanceListeners.ToArray();
}

/// <summary>
Expand All @@ -102,7 +102,6 @@ private IWebHost CreateHueBotWebHost(string url)
services => services
.AddSingleton(this.logger)
.AddSingleton(this.observer)
.AddSingleton(this.StateManager)
.AddSingleton(this.Context)
.AddSingleton(this.botOptions)
.AddSingleton(this.bot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ServiceTypes>
<!-- This is the name of your ServiceType.
This name must match the string used in RegisterServiceType call in Program.cs. -->
<StatefulServiceType ServiceTypeName="HueBotType" HasPersistedState="true" />
<StatelessServiceType ServiceTypeName="HueBotType" />
</ServiceTypes>

<!-- Code package is your service executable. -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<ApplicationManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationTypeName="HueBotSFType" ApplicationTypeVersion="2.0.0" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="HueBot_MinReplicaSetSize" DefaultValue="1" />
<Parameter Name="HueBot_PartitionCount" DefaultValue="1" />
<Parameter Name="HueBot_TargetReplicaSetSize" DefaultValue="1" />
<Parameter Name="HueBot_InstanceCount" DefaultValue="-1" />
</Parameters>
<!-- Import the ServiceManifest from the ServicePackage. The ServiceManifestName and ServiceManifestVersion
should match the Name and Version attributes of the ServiceManifest element defined in the
Expand All @@ -24,9 +22,9 @@
ServiceFabric PowerShell module.
The attribute ServiceTypeName below must match the name defined in the imported ServiceManifest.xml file. -->
<Service Name="HueBot" ServicePackageActivationMode="ExclusiveProcess">
<StatefulService ServiceTypeName="HueBotType" TargetReplicaSetSize="[HueBot_TargetReplicaSetSize]" MinReplicaSetSize="[HueBot_MinReplicaSetSize]">
<UniformInt64Partition PartitionCount="[HueBot_PartitionCount]" LowKey="1" HighKey="[HueBot_PartitionCount]" />
</StatefulService>
<StatelessService ServiceTypeName="HueBotType" InstanceCount="[HueBot_InstanceCount]">
<SingletonPartition />
</StatelessService>
</Service>
</DefaultServices>
<Principals>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/HueBotSF" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="HueBot_PartitionCount" Value="5" />
<Parameter Name="HueBot_MinReplicaSetSize" Value="1" />
<Parameter Name="HueBot_TargetReplicaSetSize" Value="1" />
<Parameter Name="HueBot_InstanceCount" Value="-1" />
</Parameters>
</Application>
</Application>
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/HueBotSF" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="HueBot_PartitionCount" Value="1" />
<Parameter Name="HueBot_MinReplicaSetSize" Value="1" />
<Parameter Name="HueBot_TargetReplicaSetSize" Value="1" />
<Parameter Name="HueBot_InstanceCount" Value="-1" />
</Parameters>
</Application>
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="fabric:/HueBotSF" xmlns="http://schemas.microsoft.com/2011/01/fabric">
<Parameters>
<Parameter Name="HueBot_PartitionCount" Value="3" />
<Parameter Name="HueBot_MinReplicaSetSize" Value="3" />
<Parameter Name="HueBot_TargetReplicaSetSize" Value="3" />
<Parameter Name="HueBot_InstanceCount" Value="-1" />
</Parameters>
</Application>