Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Updating templates for Voting Application #45

Open
wants to merge 30 commits into
base: 2018-09-01-preview
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c1c473f
change the API version to 2018-09-01-preview
vipul-modi Sep 19, 2018
9f9ff83
Use secret resource for the ACR password. The ACR server name should …
vipul-modi Sep 20, 2018
5237849
add description and windows file for private registry
vipul-modi Sep 20, 2018
b36acb5
counter with service fabric volume driver
vipul-modi Sep 21, 2018
03ed157
Add SF Volume Disk Counter Sample and template
Sep 21, 2018
9758a5c
Add linux sfmesh counter sf block store app
ashishnegi Sep 22, 2018
4b118da
Merge pull request #27 from ashishnegi/prv-preview/sfblkstore/linux
Oct 8, 2018
8981db5
Merge pull request #26 from wangcai0124/SFVolDiskCounterSample-2018-0…
Oct 8, 2018
62bc69a
Updating for new gateway, network and secret resources
vipul-modi Oct 25, 2018
ab8af8d
fix the network specification
vipul-modi Oct 26, 2018
1622b8f
Output the public IP address
vipul-modi Oct 29, 2018
60abaea
updated linux templates
jeffj6123 Oct 30, 2018
fe34acb
initial readme for helloworld
Oct 31, 2018
70a2544
Merge branch '2018-09-01-preview' of https://github.com/Azure-Samples…
Oct 31, 2018
2777b71
Merge pull request #34 from jeffj6123/2018-09-01-preview
Nov 1, 2018
5d9a15f
rename the templates
vipul-modi Nov 1, 2018
b1f7ab0
private registry scenario documentation and template files
vipul-modi Nov 1, 2018
2583f61
updating the instructions.
vipul-modi Nov 2, 2018
91502f9
minor edits
vipul-modi Nov 5, 2018
325cf37
Jejarry/windowsvisualobject (#37)
jeffj6123 Nov 6, 2018
92a7474
Mesh ingress gateway sample template (#36)
kavyako Nov 7, 2018
00ea6ff
2018 09 01 preview (#40)
mattrowmsft Nov 7, 2018
0f416fb
added the stateful one (#41)
jeffj6123 Nov 7, 2018
fe059f8
Service Fabric Reliable volume templates for counter application
Nov 7, 2018
f4081f2
Service Fabric Reliable Volume the counter templates are checked in i…
Nov 7, 2018
53780f5
Fixed linux visualObjects network address Prefixes (#42)
jeffj6123 Nov 9, 2018
5ff6994
Fix os type mismatch in counter windows sample (#43)
wangcai0124 Nov 9, 2018
3a9a627
merging with upstream
Nov 9, 2018
f0a7c5a
Updating voting application templates
Nov 9, 2018
aa2bd88
Addressing review comments
Nov 12, 2018
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
3 changes: 3 additions & 0 deletions src/counterSFVolumeDisk/build.linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
echo docker build src -f src/counterService/linux.Dockerfile -t azure-mesh-counter:dev-alpine
docker build src -f src/counterService/linux.Dockerfile -t azure-mesh-counter:dev-alpine
3 changes: 3 additions & 0 deletions src/counterSFVolumeDisk/build.windows.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
echo docker build src -f src\counterService\Dockerfile -t azure-mesh-counter:dev-nanoserver-1709
docker build src -f src\counterService\Dockerfile -t azure-mesh-counter:dev-nanoserver-1709
8 changes: 8 additions & 0 deletions src/counterSFVolumeDisk/src/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.dockerignore
.env
.git
.gitignore
.vs
.vscode
*/bin
*/obj
31 changes: 31 additions & 0 deletions src/counterSFVolumeDisk/src/counter.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2043
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9B56FCB0-63B4-404F-8A09-42EF52B53347}") = "counter", "counter\counter.sfaproj", "{7D82C8E1-BB96-4224-9313-66E4708F84EC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "counterService", "counterService\counterService.csproj", "{76F462BC-5933-4211-BE85-660B974C5764}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7D82C8E1-BB96-4224-9313-66E4708F84EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7D82C8E1-BB96-4224-9313-66E4708F84EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7D82C8E1-BB96-4224-9313-66E4708F84EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7D82C8E1-BB96-4224-9313-66E4708F84EC}.Release|Any CPU.Build.0 = Release|Any CPU
{76F462BC-5933-4211-BE85-660B974C5764}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{76F462BC-5933-4211-BE85-660B974C5764}.Debug|Any CPU.Build.0 = Debug|Any CPU
{76F462BC-5933-4211-BE85-660B974C5764}.Release|Any CPU.ActiveCfg = Release|Any CPU
{76F462BC-5933-4211-BE85-660B974C5764}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {99AE5AC4-7192-4E37-91B5-9280EBBC58A6}
EndGlobalSection
EndGlobal
5 changes: 5 additions & 0 deletions src/counterSFVolumeDisk/src/counter/App Resources/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
application:
schemaVersion: 1.0.0-preview2
name: counterAppSFVD
properties:
description: Azure Service Fabric Mesh Counter Application.
14 changes: 14 additions & 0 deletions src/counterSFVolumeDisk/src/counter/App Resources/network.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Network definition ##
network:
schemaVersion: 1.0.0-preview2
name: counterAppNetworkSFVD
properties:
description: Azure Service Fabric Mesh Counter Application network.
addressPrefix: 10.0.0.4/22
ingressConfig:
layer4:
- name: counterServiceIngress
publicPort: 8080
applicationName: counterAppSFVD
serviceName: counterServiceSFVD
endpointName: counterServiceSFVDListener
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Visual Studio SFApp Publish Profile ##
vsSFAppPublishProfile:
schemaVersion: 1.0.0-preview2
13 changes: 13 additions & 0 deletions src/counterSFVolumeDisk/src/counter/counter.sfaproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.SFApp.Sdk">
<PropertyGroup Label="Globals">
<ProjectGuid>7d82c8e1-bb96-4224-9313-66e4708f84ec</ProjectGuid>
<SFApplicationProjectVersion>1.0</SFApplicationProjectVersion>
<SFApplicationTargetsVersion>1.0.0-preview.5.0</SFApplicationTargetsVersion>
<SFApplicationToolingVersion>0.8.0.0</SFApplicationToolingVersion>
</PropertyGroup>
<ItemGroup>
<None Include="App Resources\app.yaml" />
<None Include="App Resources\network.yaml" />
<None Include="Publish Profiles\cloud.yaml" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

namespace Microsoft.ServiceFabricMesh.Samples.Counter.Service.Controllers
{
using Microsoft.AspNetCore.Mvc;

[Route("api/[controller]")]
public class ValuesController : Controller
{
private Counter counter;

public ValuesController(Counter counter)
{
this.counter = counter;
}

// GET api/values
[HttpGet]
public string Get()
{
return counter.GetValueJson();
}
}
}
141 changes: 141 additions & 0 deletions src/counterSFVolumeDisk/src/counterService/Counter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

namespace Microsoft.ServiceFabricMesh.Samples.Counter.Service
{
using System;
using System.Globalization;
using System.IO;
using System.Threading;
using System.Threading.Tasks;

public class Counter : IDisposable
{
private const string CounterUpdateInternalEnvVar = "COUNTER_UPDATE_INTERVAL_SECONDS";

private readonly string stateFilePath;
private readonly string stateFolderPath;

private bool disposed = false;
private long value;


public Counter()
: this(GetCounterUpdateInterval())
{
}

public Counter(TimeSpan updateInterval)
{
this.UpdateInterval = updateInterval;
this.stateFolderPath = FileStoreUtility.GetStateFolderPath("counter");

if (!Directory.Exists(this.stateFolderPath))
{
Directory.CreateDirectory(this.stateFolderPath);
}

this.stateFilePath = Path.Combine(this.stateFolderPath, "counter.txt");
if (!File.Exists(this.stateFilePath))
{
this.value = 0;
WriteCounterValue(this.stateFilePath, this.value);
}
else
{
this.value = ReadCounterValue(this.stateFilePath);
}

#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
this.StartUpdateAsync();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
}

public TimeSpan UpdateInterval { get; }

public string GetValueJson()
{
return string.Format(CultureInfo.InvariantCulture, "{{\"value\" : {0} }}", GetValue());
}

public long GetValue()
{
return Interlocked.Read(ref this.value);
}

private async Task StartUpdateAsync()
{
while (!this.disposed)
{
var currentValue = ReadCounterValue(this.stateFilePath);
if (currentValue != -1)
{
currentValue++;
WriteCounterValue(this.stateFilePath, currentValue);
Interlocked.Exchange(ref this.value, currentValue);
}

await Task.Delay(this.UpdateInterval);
}
}

private static long ReadCounterValue(string stateFilePath)
{
try
{
if (!long.TryParse(File.ReadAllText(stateFilePath), out long value))
{
value = -1;
}

return value;
}
catch(Exception e)
{
Console.WriteLine("Error {0} in reading counter value from file {1}.", e.Message, stateFilePath);
return -1;
}
}

private static void WriteCounterValue(string stateFilePath, long value)
{
try
{
File.WriteAllText(stateFilePath, value.ToString());
}
catch(Exception e)
{
Console.WriteLine("Error {0} in writer counter value to file {1}.", e.Message, stateFilePath);
}
}

private static TimeSpan GetCounterUpdateInterval()
{
if (!int.TryParse(Environment.GetEnvironmentVariable(CounterUpdateInternalEnvVar), out int counterUpdateInternalSeconds))
{
counterUpdateInternalSeconds = 1;
}

return TimeSpan.FromSeconds(counterUpdateInternalSeconds);
}

protected virtual void Dispose(bool disposing)
{
if (!disposed)
{
if (disposing)
{
}

disposed = true;
}
}

public void Dispose()
{
Dispose(true);
}
}
}
19 changes: 19 additions & 0 deletions src/counterSFVolumeDisk/src/counterService/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM microsoft/aspnetcore:2.0-nanoserver-1709 AS base
WORKDIR /app
EXPOSE 80

FROM microsoft/aspnetcore-build:2.0 AS build
WORKDIR /src
COPY counterService/counterService.csproj counterService/
RUN dotnet restore counterService/counterService.csproj
COPY . .
WORKDIR /src/counterService
RUN dotnet build counterService.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish counterService.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "counterService.dll"]
56 changes: 56 additions & 0 deletions src/counterSFVolumeDisk/src/counterService/FileStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

namespace Microsoft.ServiceFabricMesh.Samples.Counter.Service
{
using System;
using System.IO;
using System.Reflection;
using System.Threading;

public static class FileStoreUtility
{
private const string StoreRootFolderEnvVar = "STORE_ROOT";
private const string StateFolderNameEnvVar = "STATE_FOLDER_NAME";
private const string FabricIdEnvVar = "Fabric_Id";
private const string StoreRootFolderName = "data";

public static string GetStateFolderPath(string appName = null)
{
var storeRootPath = GetStoreRootPath(appName);

var subFolderName = Environment.GetEnvironmentVariable(StateFolderNameEnvVar);
if (string.IsNullOrEmpty(subFolderName))
{
subFolderName = Environment.GetEnvironmentVariable(FabricIdEnvVar);
}

if (string.IsNullOrEmpty(subFolderName))
{
subFolderName = Guid.NewGuid().ToString();
}

var stateFolderPath = Path.Combine(storeRootPath, subFolderName);
return stateFolderPath;
}

private static string GetStoreRootPath(string appName)
{
var storeRootPath = Environment.GetEnvironmentVariable(StoreRootFolderEnvVar);
if (string.IsNullOrEmpty(storeRootPath))
{
var codeFolderFullPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
storeRootPath = Path.Combine(codeFolderFullPath, StoreRootFolderName);
}

if (!string.IsNullOrEmpty(appName))
{
storeRootPath = Path.Combine(storeRootPath, appName);
}

return storeRootPath;
}
}
}
24 changes: 24 additions & 0 deletions src/counterSFVolumeDisk/src/counterService/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information.
// ------------------------------------------------------------

namespace Microsoft.ServiceFabricMesh.Samples.Counter.Service.Controllers
{
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
}
}
Loading