Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
rik2803 committed Sep 9, 2020
2 parents 7babf67 + 2e8cfa1 commit e15e5b9
Show file tree
Hide file tree
Showing 15 changed files with 495 additions and 275 deletions.
42 changes: 27 additions & 15 deletions .github/workflows/ci-develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,26 @@ jobs:
image: "${{ steps.set-image-output.outputs.image }}"
env:
IMAGE: "${{ secrets.ECR_REPO_HOST }}/${{ secrets.ECR_REPO_NAME }}:${GITHUB_SHA}"
- name: Get service to update
id: set-service-output
run: |
echo "::set-output name=service::$(aws ecs list-services --cluster ${{ secrets.CLUSTER_NAME_DEV }} --output text | grep Statistics | awk -F'/' '{print $2}')"
- name: Deploy services with new task definition
- name: Deploy new task definition
id: deploy-task-definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.render-task-def.outputs.task-definition }}
service: ${{ steps.set-service-output.outputs.service }}
cluster: ${{ secrets.CLUSTER_NAME_DEV }}
wait-for-service-stability: false
- name: Determine scheduled task name
id: get-scheduled-task-name
run: |
SCHEDULEDTASKNAME=$(aws events list-rules --query "Rules[*]|[?contains(Name,'Statist')].Name" --output text)
echo "::set-output name=scheduledtaskname::${SCHEDULEDTASKNAME}"
- name: Create new target config for the statistics scheduled task
id: update-scheduled-task-statistics
run: |
aws events list-targets-by-rule --rule "${{ steps.get-scheduled-task-name.outputs.scheduledtaskname }}" > targetdef.orig.json
jq '.Targets[0].EcsParameters.TaskDefinitionArn = "${{ steps.deploy-task-definition.outputs.task-definition-arn }}"' targetdef.orig.json > targetdef.json
aws events put-targets --cli-input-json file://targetdef.json --rule "${{ steps.get-scheduled-task-name.outputs.scheduledtaskname }}"
deploy-tst-statistics:
name: "Deploy the external statistics service to the tst environment"
name: "Deploy the statistics service to the tst environment"
runs-on: ubuntu-latest
if: github.base_ref == 'development' && github.event.action == 'closed' && github.event.pull_request.merged
needs:
Expand Down Expand Up @@ -145,14 +151,20 @@ jobs:
image: "${{ steps.set-image-output.outputs.image }}"
env:
IMAGE: "${{ secrets.ECR_REPO_HOST }}/${{ secrets.ECR_REPO_NAME }}:${GITHUB_SHA}"
- name: Get service to update
id: set-service-output
run: |
echo "::set-output name=service::$(aws ecs list-services --cluster ${{ secrets.CLUSTER_NAME_TST }} --output text | grep Statistics | awk -F'/' '{print $2}')"
- name: Deploy services with new task definition
- name: Deploy new task definition
id: deploy-task-definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.render-task-def.outputs.task-definition }}
service: ${{ steps.set-service-output.outputs.service }}
cluster: ${{ secrets.CLUSTER_NAME_TST }}
wait-for-service-stability: false
- name: Determine scheduled task name
id: get-scheduled-task-name
run: |
SCHEDULEDTASKNAME=$(aws events list-rules --query "Rules[*]|[?contains(Name,'Statist')].Name" --output text)
echo "::set-output name=scheduledtaskname::${SCHEDULEDTASKNAME}"
- name: Create new target config for the statistics scheduled task
id: update-scheduled-task-statistics
run: |
aws events list-targets-by-rule --rule "${{ steps.get-scheduled-task-name.outputs.scheduledtaskname }}" > targetdef.orig.json
jq '.Targets[0].EcsParameters.TaskDefinitionArn = "${{ steps.deploy-task-definition.outputs.task-definition-arn }}"' targetdef.orig.json > targetdef.json
aws events put-targets --cli-input-json file://targetdef.json --rule "${{ steps.get-scheduled-task-name.outputs.scheduledtaskname }}"
21 changes: 14 additions & 7 deletions .github/workflows/ci-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,21 @@ jobs:
image: "${{ steps.set-image-output.outputs.image }}"
env:
IMAGE: "${{ secrets.ECR_REPO_HOST }}/${{ secrets.ECR_REPO_NAME }}:${GITHUB_SHA}"
- name: Get service to update
id: set-service-output
run: |
echo "::set-output name=service::$(aws ecs list-services --cluster ${{ secrets.CLUSTER_NAME_STG }} --output text | grep Statistics | awk -F'/' '{print $2}')"
- name: Deploy services with new task definition
- name: Deploy new task definition
id: deploy-task-definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.render-task-def.outputs.task-definition }}
service: ${{ steps.set-service-output.outputs.service }}
cluster: ${{ secrets.CLUSTER_NAME_STG }}
wait-for-service-stability: false
- name: Determine scheduled task name
id: get-scheduled-task-name
run: |
SCHEDULEDTASKNAME=$(aws events list-rules --query "Rules[*]|[?contains(Name,'Statist')].Name" --output text)
echo "::set-output name=scheduledtaskname::${SCHEDULEDTASKNAME}"
- name: Create new target config for the statistics scheduled task
id: update-scheduled-task-statistics
run: |
aws events list-targets-by-rule --rule "${{ steps.get-scheduled-task-name.outputs.scheduledtaskname }}" > targetdef.orig.json
jq '.Targets[0].EcsParameters.TaskDefinitionArn = "${{ steps.deploy-task-definition.outputs.task-definition-arn }}"' targetdef.orig.json > targetdef.json
aws events put-targets --cli-input-json file://targetdef.json --rule "${{ steps.get-scheduled-task-name.outputs.scheduledtaskname }}"
20 changes: 13 additions & 7 deletions .github/workflows/ci-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,20 @@ jobs:
image: "${{ steps.set-image-output.outputs.image }}"
env:
IMAGE: "${{ secrets.ECR_REPO_HOST }}/${{ secrets.ECR_REPO_NAME }}:${GITHUB_SHA}"
- name: Get service to update
id: set-service-output
run: |
echo "::set-output name=service::$(aws ecs list-services --cluster ${{ secrets.CLUSTER_NAME_PRD }} --output text | grep Statistics | awk -F'/' '{print $2}')"
- name: Deploy services with new task definition
- name: Deploy new task definition
id: deploy-task-definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.render-task-def.outputs.task-definition }}
service: ${{ steps.set-service-output.outputs.service }}
cluster: ${{ secrets.CLUSTER_NAME_PRD }}
wait-for-service-stability: false
- name: Determine scheduled task name
id: get-scheduled-task-name
run: |
SCHEDULEDTASKNAME=$(aws events list-rules --query "Rules[*]|[?contains(Name,'Statist')].Name" --output text)
echo "::set-output name=scheduledtaskname::${SCHEDULEDTASKNAME}"
- name: Create new target config for the statistics scheduled task
id: update-scheduled-task-statistics
run: |
aws events list-targets-by-rule --rule "${{ steps.get-scheduled-task-name.outputs.scheduledtaskname }}" > targetdef.orig.json
jq '.Targets[0].EcsParameters.TaskDefinitionArn = "${{ steps.deploy-task-definition.outputs.task-definition-arn }}"' targetdef.orig.json > targetdef.json
aws events put-targets --cli-input-json file://targetdef.json --rule "${{ steps.get-scheduled-task-name.outputs.scheduledtaskname }}"
94 changes: 13 additions & 81 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,48 +85,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-aws-parameter-store-config</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
Expand All @@ -138,16 +96,9 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.13.26</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
Expand All @@ -164,6 +115,16 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.11.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>2.11.2</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -203,18 +164,6 @@
</environmentVariables>
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
<execution>
<goals>
<goal>repackage</goal>
Expand All @@ -223,23 +172,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
<configuration>
<apiDocsUrl>http://localhost:8080/api/docs</apiDocsUrl>
<outputFileName>openapi.json</outputFileName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/be/coronalert/statistics/StatisticsReport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package be.coronalert.statistics;

import be.coronalert.statistics.data.Result;
import java.time.LocalDate;
import lombok.Data;

@Data
public class StatisticsReport {

private Integer averageInfected;
private Integer averageInfectedChangePercentage;
private Integer averageHospitalised;
private Integer averageHospitalisedChangePercentage;
private Integer averageDeceased;
private Integer averageDeceasedChangePercentage;
private LocalDate startDate;
private LocalDate endDate;


/**
* Creates the statisticsreport.
*/
public StatisticsReport(
LocalDate endDate,
Result cases,
Result hospitalisations,
Result mortalities

) {

this.endDate = endDate;
this.startDate = this.endDate.minusDays(6);

this.averageDeceased = mortalities.getCurrentValue().intValue();
this.averageDeceasedChangePercentage = mortalities.getDifference();

this.averageHospitalised = hospitalisations.getCurrentValue().intValue();
this.averageHospitalisedChangePercentage = hospitalisations.getDifference();

this.averageInfected = cases.getCurrentValue().intValue();
this.averageInfectedChangePercentage = cases.getDifference();

}

}
77 changes: 77 additions & 0 deletions src/main/java/be/coronalert/statistics/StatisticsRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package be.coronalert.statistics;

import be.coronalert.statistics.cases.CovidCasesPoller;
import be.coronalert.statistics.config.StatisticsServiceConfig;
import be.coronalert.statistics.hospitalisations.HospitalisationsPoller;
import be.coronalert.statistics.mortality.MortalityPoller;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.LocalDate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;

@Component
@Order(1)
public class StatisticsRunner implements ApplicationRunner {

private static final Logger logger = LoggerFactory.getLogger(StatisticsRunner.class);

private static final Region DEFAULT_REGION = Region.EU_CENTRAL_1;

@Autowired
private ConfigurableApplicationContext context;

@Autowired
private HospitalisationsPoller hospitalisationsPoller;

@Autowired
private CovidCasesPoller covidCasesPoller;

@Autowired
private MortalityPoller mortalityPoller;

@Autowired
private StatisticsServiceConfig statisticsServiceConfig;

@Autowired
private ObjectMapper objectMapper;

@Override
public void run(ApplicationArguments args) throws Exception {
StatisticsReport statisticsReport = new StatisticsReport(
LocalDate.now().minusDays(4),
covidCasesPoller.pollResults(),
hospitalisationsPoller.pollResults(),
mortalityPoller.pollResults()
);

logger.info("statisticsReport = " + statisticsReport);

PutObjectRequest putObjectRequest = PutObjectRequest
.builder()
.bucket(statisticsServiceConfig.getS3().getBucket())
.key(statisticsServiceConfig.getS3().getKey())
.contentType("application/json")
.build();

RequestBody requestBody = RequestBody.fromString(objectMapper.writeValueAsString(statisticsReport));

S3Client s3Client = S3Client
.builder()
.region(DEFAULT_REGION)
.build();

s3Client.putObject(putObjectRequest, requestBody);

context.close();
}
}
Loading

0 comments on commit e15e5b9

Please sign in to comment.