Skip to content

Commit

Permalink
Merge pull request #1 from dante-mat/fargate/lab1-before
Browse files Browse the repository at this point in the history
Fargate/lab1 before
  • Loading branch information
dante-mat authored Oct 24, 2024
2 parents 8807b88 + 34188ce commit 1c11723
Show file tree
Hide file tree
Showing 34 changed files with 494 additions and 57 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/datacenterMap.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ jobs:
"SERVICE_NAME": "backend",
"TASK_NAME": "backend"
}
}
}
5 changes: 1 addition & 4 deletions .github/workflows/provisionWithTerraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ on:
options:
- 'ecs'
- 'eks'


jobs:
properties:
uses: ./.github/workflows/datacenterMap.yml
Expand All @@ -36,7 +34,6 @@ jobs:
AWS_KEY: ${{ secrets[format('{0}_AWS_KEY', inputs.hubEnv)] }}
AWS_SECRET: ${{ secrets[format('{0}_AWS_SECRET', inputs.hubEnv)] }}
AWS_REGION: ${{ needs.properties.outputs.REGION }}

steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down Expand Up @@ -107,4 +104,4 @@ jobs:
docker build -t prometheus-custom .
docker tag prometheus-custom ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:prometheus
docker push ${{ env.AWS_ACCOUNT }}.dkr.ecr.eu-central-1.amazonaws.com/monitoring:prometheus
cd ..
cd ..
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,105 @@
}
]
}
},
"/notifyMe": {
"post": {
"tags": [
"notifyme"
],
"summary": "Send the message to SNS Topic",
"description": "Send the message to SNS Topic",
"operationId": "notifyMe",
"responses": {
"201": {
"description": "Message published to topic.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SentMessage"
}
}
}
},
"400": {
"description": "Bad request.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiBusinessErrorResponse"
}
}
}
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden."
},
"404": {
"description": "Resource not available."
},
"422": {
"description": "Request timed out. One of the backend services took too long to process request.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiBusinessErrorResponse"
}
}
}
},
"429": {
"description": "Too many requests for same device.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiBusinessErrorResponse"
}
}
}
},
"500": {
"description": "Internal server error.",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiServerErrorResponse"
}
}
}
},
"503": {
"description": "Service unavailable",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiServerErrorResponse"
}
}
}
}
},
"requestBody": {
"description": "NotifyMe text",
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/NotifyMe"
}
}
}
},
"security": [
{
"basicAuth":[]
}
]
}
}

},
"components": {
"schemas": {
Expand Down Expand Up @@ -388,6 +486,44 @@
"example": "cpu"
}
}
},
"NotifyMe": {
"type": "object",
"description": "Represents the message",
"required": [
"text"
],
"properties": {
"source_lc": {
"type": "string",
"example": "pl",
"description": "Contains the language code of source"
},
"target_lc": {
"type": "string",
"example": "en",
"description": "Contains the language code of target"
},
"text": {
"type": "string",
"description": "Text to send",
"example": "cpu"
}
}
},
"SentMessage": {
"type": "object",
"description": "Represents the message",
"required": [
"text"
],
"properties": {
"text": {
"type": "string",
"description": "Sent message",
"example": "Kra kre mija, tu lis ma nore, a ja nos tre."
}
}
}
},
"securitySchemes": {
Expand All @@ -397,4 +533,4 @@
}
}
}
}
}
12 changes: 12 additions & 0 deletions app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-sns</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-translate</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-comprehend</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/awstraining/backend/Application.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.awstraining.backend;

import static org.springframework.boot.Banner.Mode.OFF;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.scheduling.annotation.EnableScheduling;

import static org.springframework.boot.Banner.Mode.OFF;

@SpringBootApplication
@EnableScheduling
public class Application {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.awstraining.backend.business.measurements;

import java.util.List;

import com.awstraining.backend.business.measurements.exceptions.CouldNotSaveMeasurementException;
import com.awstraining.backend.business.measurements.repository.MeasurementDBEntity;
import com.awstraining.backend.business.measurements.repository.MeasurementRepositoryDynamoDB;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MeasurementService {
@Value("${backend.measurements.ttlInSeconds:2592000}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.awstraining.backend.business.measurements.controller;

import static java.lang.System.currentTimeMillis;

import java.util.List;

import com.awstraining.backend.api.rest.v1.DeviceIdApi;
import com.awstraining.backend.api.rest.v1.model.Measurement;
import com.awstraining.backend.api.rest.v1.model.Measurements;
Expand All @@ -16,6 +12,10 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static java.lang.System.currentTimeMillis;

@RestController
@RequestMapping("device/v1")
class DeviceController implements DeviceIdApi {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.awstraining.backend.business.measurements.exceptions;

import static java.lang.System.currentTimeMillis;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.ResponseEntity.status;
import com.awstraining.backend.api.rest.v1.model.ApiBusinessErrorResponse;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletRequest;

import com.awstraining.backend.api.rest.v1.model.ApiBusinessErrorResponse;
import org.springframework.http.ResponseEntity;
import static java.lang.System.currentTimeMillis;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.ResponseEntity.status;

public class CouldNotSaveMeasurementException extends RuntimeException {
public ResponseEntity<ApiBusinessErrorResponse> toResponse(final HttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package com.awstraining.backend.business.measurements.exceptions;

import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;

import javax.servlet.http.HttpServletRequest;

import com.awstraining.backend.api.rest.v1.model.ApiBusinessErrorResponse;
import org.springframework.core.annotation.Order;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

import static org.springframework.core.Ordered.HIGHEST_PRECEDENCE;

@Order(HIGHEST_PRECEDENCE)
@ControllerAdvice
public class MeasurementsExceptionHandler {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.awstraining.backend.business.measurements.exceptions;

import static java.lang.System.currentTimeMillis;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
import static org.springframework.http.ResponseEntity.status;
import com.awstraining.backend.api.rest.v1.model.ApiBusinessErrorResponse;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletRequest;

import com.awstraining.backend.api.rest.v1.model.ApiBusinessErrorResponse;
import org.springframework.http.ResponseEntity;
import static java.lang.System.currentTimeMillis;
import static org.springframework.http.HttpStatus.UNPROCESSABLE_ENTITY;
import static org.springframework.http.ResponseEntity.status;

public class UnknownDeviceException extends RuntimeException {
public ResponseEntity<ApiBusinessErrorResponse> toResponse(final HttpServletRequest request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.awstraining.backend.business.measurements.repository;

import java.util.List;

import com.awstraining.backend.business.measurements.exceptions.CouldNotSaveMeasurementException;

import java.util.List;

public interface MeasurementRepository {
void save(final MeasurementDBEntity measurementDbEntity) throws CouldNotSaveMeasurementException;
List<MeasurementDBEntity> getAll();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.awstraining.backend.business.measurements.repository;

import java.util.List;

import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression;
import com.awstraining.backend.business.measurements.exceptions.CouldNotSaveMeasurementException;
Expand All @@ -10,6 +8,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class MeasurementRepositoryDynamoDB implements MeasurementRepository {
private static final Logger LOGGER = LogManager.getLogger(MeasurementRepositoryDynamoDB.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.awstraining.backend.business.notifyme;

public interface MessageSender {

void send(String text);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.awstraining.backend.business.notifyme;

public record NotifyMeDO(String text, String sourceLc, String targetLc) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.awstraining.backend.business.notifyme;

import org.springframework.stereotype.Service;

@Service
public class NotifyMeService {

// TODO: lab1
// 1. Inject MessageSender.
// TODO lab2
// 1. Inject Translator
// TODO lab3
// 1. Inject sentiment detector
// @Autowired
public NotifyMeService() {

}

public String notifyMe(NotifyMeDO notifyMe) {

// TODO: lab1
// 1. Send text using sender.
// 2. Return sent message.
// TODO: lab2
// 1. Translate text from using translator.
// 2. Change sending of text to "translated text" and return it.
// TODO: lab3
// 1. Detect sentiment of translated message.
// 2. Change sending of text to "setiment: translated text" and return it.
return "This service is not available.";
}

}
Loading

0 comments on commit 1c11723

Please sign in to comment.