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

feat: anti-fraud validation in a transaction #17

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
21 changes: 21 additions & 0 deletions business-transaction-anti-fraud-v1/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Use an official OpenJDK runtime as a parent image
FROM openjdk:17-jdk-slim

# Set the working directory in the container
WORKDIR /app

# Copy the Maven project file and the source code
# COPY pom.xml /app
# COPY src /app/src

# Package the application
# RUN ./mvnw clean install -DskipTests

# Copy the packaged JAR file to the working directory
COPY target/*.jar app.jar

# Exponer el puerto en el que la aplicación se ejecutará (cambiar si es necesario)
EXPOSE 8080

# Run the application
ENTRYPOINT ["java", "-jar", "app.jar"]
42 changes: 42 additions & 0 deletions business-transaction-anti-fraud-v1/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# API business-transaction-anti-fraud

## Input Payload

```json
{
"id": "1",
"amount": "100",
"currency": "USD"
}
```

## Output Payload

```json
{
"transactionId": "1",
"isFraudulent": false,
"reason": ""
}
```


# ingress-nginx

**ingress-nginx** es un controlador de Ingress para Kubernetes basado en NGINX. Se utiliza para gestionar el acceso externo a los servicios en un clúster de Kubernetes, proporcionando balanceo de carga, terminación SSL y enrutamiento basado en host y ruta.

## Características principales

- **Balanceo de carga**: Distribuye el tráfico entrante entre múltiples réplicas de un servicio.
- **Terminación SSL**: Maneja la terminación SSL/TLS para asegurar las conexiones.
- **Enrutamiento basado en host y ruta**: Permite definir reglas para enrutar el tráfico a diferentes servicios basados en el host y la ruta de la solicitud.

## Instalación

Para instalar **ingress-nginx** en un clúster de Kubernetes, puedes usar Helm:

```bash
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install ingress-nginx ingress-nginx/ingress-nginx --namespace ingress-nginx --create-namespace

199 changes: 199 additions & 0 deletions business-transaction-anti-fraud-v1/checkstyle-checks.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">

<!--

Checkstyle configuration that checks the sun coding conventions from:

- the Java Language Specification at
https://docs.oracle.com/javase/specs/jls/se11/html/index.html

- the Sun Code Conventions at https://www.oracle.com/java/technologies/javase/codeconventions-contents.html

- the Javadoc guidelines at
https://www.oracle.com/technical-resources/articles/java/javadoc-tool.html

- the JDK Api documentation https://docs.oracle.com/en/java/javase/11/

- some best practices

Checkstyle is very configurable. Be sure to read the documentation at
https://checkstyle.org (or in your downloaded distribution).

Most Checks are configurable, be sure to consult the documentation.

To completely disable a check, just comment it out or delete it from the file.
To suppress certain violations please review suppression filters.

Finally, it is worth reading the documentation.

-->

<module name="Checker">
<!--
If you set the basedir property below, then all reported file
names will be relative to the specified directory. See
https://checkstyle.org/config.html#Checker

<property name="basedir" value="${basedir}"/>
-->
<property name="severity" value="error"/>

<property name="fileExtensions" value="java, properties, xml"/>

<!-- Excludes all 'module-info.java' files -->
<!-- See https://checkstyle.org/config_filefilters.html -->
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value="module\-info\.java$"/>
</module>

<!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
<module name="SuppressionFilter">
<property name="file" value="${org.checkstyle.sun.suppressionfilter.config}"
default="checkstyle-suppressions.xml" />
<property name="optional" value="true"/>
</module>

<!-- Checks that a package-info.java file exists for each package. -->
<!-- See https://checkstyle.org/config_javadoc.html#JavadocPackage -->
<module name="JavadocPackage"/>

<!-- Checks whether files end with a new line. -->
<!-- See https://checkstyle.org/config_misc.html#NewlineAtEndOfFile -->
<module name="NewlineAtEndOfFile"/>

<!-- Checks that property files contain the same keys. -->
<!-- See https://checkstyle.org/config_misc.html#Translation -->
<module name="Translation"/>

<!-- Checks for Size Violations. -->
<!-- See https://checkstyle.org/config_sizes.html -->
<module name="FileLength"/>
<module name="LineLength">
<property name="max" value="140" />
<property name="fileExtensions" value="java"/>
</module>

<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/config_whitespace.html -->
<module name="FileTabCharacter"/>

<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/config_misc.html -->
<module name="RegexpSingleline">
<property name="format" value="\s+$"/>
<property name="minimum" value="0"/>
<property name="maximum" value="0"/>
<property name="message" value="Line has trailing spaces."/>
</module>

<!-- Checks for Headers -->
<!-- See https://checkstyle.org/config_header.html -->
<module name="Header">
<property name="headerFile" value="${checkstyle.header.file}"/>
<property name="fileExtensions" value="java"/>
</module>

<module name="TreeWalker">

<!-- Checks for Javadoc comments. -->
<!-- See https://checkstyle.org/config_javadoc.html -->
<module name="InvalidJavadocPosition"/>
<module name="JavadocMethod"/>
<module name="JavadocType"/>
<module name="JavadocVariable"/>
<module name="JavadocStyle"/>
<module name="MissingJavadocMethod"/>

<!-- Checks for Naming Conventions. -->
<!-- See https://checkstyle.org/config_naming.html -->
<module name="ConstantName"/>
<module name="LocalFinalVariableName"/>
<module name="LocalVariableName"/>
<module name="MemberName"/>
<module name="MethodName"/>
<module name="PackageName"/>
<module name="ParameterName"/>
<module name="StaticVariableName"/>
<module name="TypeName"/>

<!-- Checks for imports -->
<!-- See https://checkstyle.org/config_imports.html -->
<module name="AvoidStarImport"/>
<module name="IllegalImport"/> <!-- defaults to sun.* packages -->
<module name="RedundantImport"/>
<module name="UnusedImports">
<property name="processJavadoc" value="false"/>
</module>

<!-- Checks for Size Violations. -->
<!-- See https://checkstyle.org/config_sizes.html -->
<module name="MethodLength"/>
<module name="ParameterNumber"/>

<!-- Checks for whitespace -->
<!-- See https://checkstyle.org/config_whitespace.html -->
<module name="EmptyForIteratorPad"/>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoWhitespaceAfter"/>
<module name="NoWhitespaceBefore"/>
<module name="OperatorWrap"/>
<module name="ParenPad"/>
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter"/>
<module name="WhitespaceAround"/>

<!-- Modifier Checks -->
<!-- See https://checkstyle.org/config_modifier.html -->
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>

<!-- Checks for blocks. You know, those {}'s -->
<!-- See https://checkstyle.org/config_blocks.html -->
<module name="AvoidNestedBlocks"/>
<module name="EmptyBlock"/>
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>

<!-- Checks for common coding problems -->
<!-- See https://checkstyle.org/config_coding.html -->
<module name="EmptyStatement"/>
<module name="EqualsHashCode"/>
<module name="HiddenField"/>
<module name="IllegalInstantiation"/>
<module name="InnerAssignment"/>
<module name="MagicNumber"/>
<module name="MissingSwitchDefault"/>
<module name="MultipleVariableDeclarations"/>
<module name="SimplifyBooleanExpression"/>
<module name="SimplifyBooleanReturn"/>

<!-- Checks for class design -->
<!-- See https://checkstyle.org/config_design.html -->
<module name="DesignForExtension"/>
<module name="FinalClass"/>
<module name="HideUtilityClassConstructor"/>
<module name="InterfaceIsType"/>
<module name="VisibilityModifier"/>

<!-- Miscellaneous other checks. -->
<!-- See https://checkstyle.org/config_misc.html -->
<module name="ArrayTypeStyle"/>
<module name="FinalParameters"/>
<module name="TodoComment"/>
<module name="UpperEll"/>

<!-- https://checkstyle.org/config_filters.html#SuppressionXpathFilter -->
<module name="SuppressionXpathFilter">
<property name="file" value="${org.checkstyle.sun.suppressionxpathfilter.config}"
default="checkstyle-xpath-suppressions.xml" />
<property name="optional" value="true"/>
</module>

</module>

</module>
23 changes: 23 additions & 0 deletions business-transaction-anti-fraud-v1/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>

<suppress checks="." files="[\\/]test[\\/]"/>
<suppress files="[/\\]target[/\\]" checks=".*"/>

<suppress checks="HideUtilityClassConstructor" files="StartApplication\.java"/>

<!-- suppress certain checks on all files in a package -->
<suppress files="com[\\/]bcp[\\/]services[\\/]trxantifraud"
checks="InvalidJavadocPosition|JavadocMethod|JavadocMethod|JavadocType|JavadocVariable|JavadocStyle|MissingJavadocMethod"/>
<suppress files="com[\\/]bcp[\\/]services[\\/]trxantifraud" checks="DesignForExtension"/>

<suppress files="com[\\/]bcp[\\/]services[\\/]trxantifraud"
checks="Header|JavadocPackage|NewlineAtEndOfFile"/>

<suppress checks="NewlineAtEndOfFile" files="[/\\]resources[/\\]"/>
</suppressions>
Empty file.
35 changes: 35 additions & 0 deletions business-transaction-anti-fraud-v1/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: '3'
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.0.1
container_name: zookeeper
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
ports:
- "2181:2181"

kafka:
image: confluentinc/cp-kafka:7.0.1
container_name: kafka
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
volumes:
- ./kafka-data:/var/lib/kafka/data

kafka-manager:
image: hlebalbau/kafka-manager:latest
container_name: kafka-manager
depends_on:
- kafka
ports:
- "9000:9000"
environment:
ZK_HOSTS: zookeeper:2181
27 changes: 27 additions & 0 deletions business-transaction-anti-fraud-v1/kubectl/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: business-transaction-anti-fraud-v1
spec:
replicas: 1 # Número inicial de réplicas
selector:
matchLabels:
app: business-transaction-anti-fraud-v1
template:
metadata:
labels:
app: business-transaction-anti-fraud-v1
spec:
containers:
- name: business-transaction-anti-fraud-v1-container
image: vllave/business-transaction-anti-fraud-v1:latest
resources:
limits:
cpu: "2" # cpu_limits
memory: "1512Mi" # memory_limits
requests:
cpu: "40m" # cpu_requests
memory: "256Mi" # memory_requests
env:
- name: JAVA_OPTS
value: "-Xms32m -Xmx1024m" # jvm_xms y jvm_xmx
24 changes: 24 additions & 0 deletions business-transaction-anti-fraud-v1/kubectl/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: business-transaction-anti-fraud-v1-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: business-transaction-anti-fraud-v1
minReplicas: 1
maxReplicas: 4
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 900 # target_average_cpu (representa el % de uso de CPU por pod)
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 350 # target_average_memory (representa el % de uso de memoria por pod)
Loading