Skip to content

Commit d35f913

Browse files
authored
Merge pull request #1 from fossapps/initial_feature
Initial feature
2 parents 36e58c6 + 6e1ff07 commit d35f913

File tree

74 files changed

+1988
-396
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1988
-396
lines changed

.github/workflows/build.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: Build
33
on: [push]
44

55
env:
6-
SERVICE_NAME: micro.starter
7-
SERVICE_NAME_CAPITALIZED: Micro.Starter
6+
SERVICE_NAME: feature.manager
7+
SERVICE_NAME_CAPITALIZED: Feature.Manager
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
@@ -47,6 +47,9 @@ jobs:
4747
docker build . -t fossapps/$SERVICE_NAME --build-arg VERSION=$TAG
4848
docker tag fossapps/$SERVICE_NAME fossapps/$SERVICE_NAME:$TAG
4949
docker push fossapps/$SERVICE_NAME:$TAG
50+
51+
52+
5053
run-postman-tests:
5154
needs: build-docker-image
5255
runs-on: ubuntu-latest
@@ -88,3 +91,4 @@ jobs:
8891
@semantic-release/[email protected]
8992
@semantic-release/[email protected]
9093
@semantic-release/[email protected]
94+

.github/workflows/publish_sdk.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types: [published]
6+
env:
7+
SERVICE_NAME: feature.manager
8+
SERVICE_NAME_CAPITALIZED: Feature.Manager
9+
10+
jobs:
11+
publish:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v1
15+
- name: Setup .NET Core
16+
uses: actions/setup-dotnet@v1
17+
with:
18+
dotnet-version: 3.1.101
19+
- name: 'Load Docker Image'
20+
run: |
21+
TAG="${GITHUB_REF/refs\/tags\//}"
22+
docker pull fossapps/$SERVICE_NAME:$TAG
23+
- name: Spin-up Containers
24+
run: |
25+
TAG="${GITHUB_REF/refs\/tags\//}"
26+
TAG=$TAG docker-compose -f ./docker-compose.ci.yml up -d
27+
- name: Generate SDKs
28+
run: |
29+
cd ./Sdk
30+
sh ./generate_sdk.sh
31+
- name: pack
32+
run: |
33+
cd Sdk
34+
TAG="${GITHUB_REF/refs\/tags\//}"
35+
dotnet pack --include-symbols -p:PackageVersion=$TAG -c Release
36+
- name: release
37+
run: |
38+
dotnet nuget push ./bin/Release/Fossapps.Feature.Manager* -k ${{secrets.NUGET_TOKEN}} -s https://api.nuget.org/v3/index.json

Dockerfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
FROM mcr.microsoft.com/dotnet/core/sdk:3.0-alpine3.9 as build
1+
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine as build
22
WORKDIR /app
33
COPY . .
44
RUN dotnet restore
5-
RUN dotnet publish -c Release -o out --self-contained --runtime linux-x64 ./Micro.Starter.Api/Micro.Starter.Api.csproj
5+
RUN dotnet publish -c Release -o out --self-contained --runtime linux-x64 ./Feature.Manager.Api/Feature.Manager.Api.csproj
66

77
FROM debian:jessie-slim
88

99
ARG VERSION
1010
ENV APP_VERSION="${VERSION}"
1111
WORKDIR /app
1212
COPY --from=build /app/out/ ./
13-
RUN chmod +x ./Micro.Starter.Api && apt-get update && apt-get install -y --no-install-recommends libicu-dev openssl && rm -Rf /var/lib/apt/lists/* && apt-get clean
13+
RUN chmod +x ./Feature.Manager.Api && apt-get update && apt-get install -y --no-install-recommends libicu-dev openssl && rm -Rf /var/lib/apt/lists/* && apt-get clean
1414
ENV ASPNETCORE_URLS=http://+:5000
1515
EXPOSE 5000
1616
STOPSIGNAL SIGTERM
17-
CMD ["./Micro.Starter.Api"]
17+
CMD ["./Feature.Manager.Api"]

Micro.Starter.Api/Configs/DatabaseConfig.cs renamed to Feature.Manager.Api/Configs/DatabaseConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace Micro.Starter.Api.Configs
1+
namespace Feature.Manager.Api.Configs
22
{
33
public class DatabaseConfig
44
{

Micro.Starter.Api/Micro.Starter.Api.csproj renamed to Feature.Manager.Api/Feature.Manager.Api.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Feature.Manager.Api.FeatureRuns.Exceptions
4+
{
5+
public class FeatureAlreadyRunningException : Exception
6+
{
7+
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Feature.Manager.Api.FeatureRuns.Exceptions
4+
{
5+
public class FeatureRunNotFoundException : Exception
6+
{
7+
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Feature.Manager.Api.FeatureRuns.Exceptions
4+
{
5+
public class InvalidStopResultValueException : Exception
6+
{
7+
8+
}
9+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.ComponentModel.DataAnnotations;
3+
4+
namespace Feature.Manager.Api.FeatureRuns
5+
{
6+
public class FeatureRun
7+
{
8+
public string Id { set; get; }
9+
public int Allocation { set; get; }
10+
11+
[Required]
12+
public string FeatId { set; get; }
13+
public DateTime StartAt { set; get; }
14+
public DateTime? EndAt { set; get; }
15+
16+
[Required]
17+
public string RunToken { set; get; }
18+
19+
public StopResult? StopResult { set; get; }
20+
}
21+
22+
public enum StopResult
23+
{
24+
AllB,
25+
Removed,
26+
AllA,
27+
ChangeSettings
28+
}
29+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Feature.Manager.Api.FeatureRuns.ViewModels;
6+
using Feature.Manager.Api.Features.ViewModels;
7+
using Feature.Manager.Api.Models;
8+
using Feature.Manager.Api.Uuid;
9+
using Microsoft.EntityFrameworkCore;
10+
11+
namespace Feature.Manager.Api.FeatureRuns
12+
{
13+
public interface IFeatureRunRepository
14+
{
15+
Task<FeatureRun> CreateFeatureRun(CreateFeatureRunRequest request);
16+
Task<List<FeatureRun>> GetRunsForFeatureByFeatId(string featId);
17+
Task<FeatureRun> StopFeatureRun(StopFeatureRunRequest request);
18+
Task<FeatureRun> GetById(string featureRunId);
19+
Task<List<RunningFeature>> GetRunningFeatures();
20+
}
21+
public class FeatureRunRepository : IFeatureRunRepository
22+
{
23+
private readonly ApplicationContext _db;
24+
private readonly IUuidService _uuidService;
25+
26+
public FeatureRunRepository(ApplicationContext db, IUuidService uuidService)
27+
{
28+
_db = db;
29+
_uuidService = uuidService;
30+
}
31+
32+
public async Task<FeatureRun> CreateFeatureRun(CreateFeatureRunRequest request)
33+
{
34+
var run = new FeatureRun
35+
{
36+
Allocation = request.Allocation,
37+
StartAt = request.StartAt.ToUniversalTime(),
38+
FeatId = request.FeatId,
39+
Id = _uuidService.GenerateUuId(),
40+
RunToken = _uuidService.GenerateUuId(),
41+
};
42+
if (request.EndAt.HasValue)
43+
{
44+
run.EndAt = request.EndAt.Value.ToUniversalTime();
45+
}
46+
var response = await _db.FeatureRuns.AddAsync(run);
47+
await _db.SaveChangesAsync();
48+
return response.Entity;
49+
}
50+
51+
public Task<List<FeatureRun>> GetRunsForFeatureByFeatId(string featId)
52+
{
53+
return _db.FeatureRuns.AsNoTracking().Where(x => x.FeatId == featId).ToListAsync();
54+
}
55+
56+
public async Task<FeatureRun> StopFeatureRun(StopFeatureRunRequest request)
57+
{
58+
var featureRun = await GetById(request.RunId);
59+
_db.Attach(featureRun);
60+
Enum.TryParse(request.StopResult, out StopResult stopResult);
61+
featureRun.StopResult = stopResult;
62+
featureRun.EndAt = DateTime.Now.ToUniversalTime();
63+
await _db.SaveChangesAsync();
64+
return featureRun;
65+
}
66+
67+
public Task<FeatureRun> GetById(string featureRunId)
68+
{
69+
return _db.FeatureRuns.AsNoTracking().FirstOrDefaultAsync(x => x.Id == featureRunId);
70+
}
71+
72+
public async Task<List<RunningFeature>> GetRunningFeatures()
73+
{
74+
return await _db
75+
.FeatureRuns
76+
.AsNoTracking()
77+
.Where(x => x.StartAt < DateTime.Now)
78+
.Where(x => x.EndAt == null || x.StopResult == StopResult.AllB || x.EndAt > DateTime.Now)
79+
.Join(_db.Features, run => run.FeatId, feature => feature.FeatId, (run, feature) => new RunningFeature
80+
{
81+
Allocation = run.Allocation,
82+
FeatureToken = feature.FeatureToken,
83+
RunToken = run.RunToken,
84+
RunId = run.Id,
85+
RunStatus = run.StopResult,
86+
FeatureId = feature.FeatId
87+
})
88+
.ToListAsync();
89+
}
90+
}
91+
}

0 commit comments

Comments
 (0)