diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 5f18d712..00000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,42 +0,0 @@ -# This workflow will build a Java project with Maven -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v2 - with: - java-version: '11' - distribution: 'adopt' - - name: Build with Maven - run: mvn -B package --file pom.xml - - name: Install Octopus CLI 🐙 - uses: OctopusDeploy/install-octopus-cli-action@v1.1.6 - with: - version: latest - - name: Push a package to Octopus Deploy 🐙 - uses: OctopusDeploy/push-package-action@v1.0.1 - with: - api_key: ${{ secrets.OCTOPUS_APIKEY }} - server: ${{ secrets.OCTOPUS_SERVER }} - packages: "build/DevOpsUsach2020-0.0.1.jar" - - name: Create a release in Octopus Deploy 🐙 - uses: OctopusDeploy/create-release-action@v1.0.2 - with: - api_key: ${{ secrets.OCTOPUS_APIKEY }} - server: ${{ secrets.OCTOPUS_SERVER }} - project: "test-bci" - deploy_to: "QA" diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..60d744ef --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,75 @@ +pipeline { + agent any + stages { + stage('Build'){ + steps{ + echo 'Building...' + slackSend color: "warning", message: "Building... branch: ${GIT_BRANCH}" + sh './mvnw clean compile -e' + + } + post { + success { + echo 'Build Success' + slackSend color: "good", message: "Build Success" + } + failure { + echo 'Build Failed' + slackSend color: "danger", message: "Build Failed" + } + } + } + stage('Test'){ + steps{ + echo 'Testing...' + slackSend color: "warning", message: "Testing..." + sh './mvnw test -e' + } + post { + success { + echo 'Test Success' + slackSend color: "good", message: "Test Success" + } + failure { + echo 'Test Failed' + slackSend color: "danger", message: "Test Failed" + } + } + } + stage('Package'){ + steps{ + echo 'Packaging...' + slackSend color: "warning", message: "Packaging..." + sh './mvnw package -e' + } + post { + success { + echo 'Package Success' + slackSend color: "good", message: "Package Success" + } + failure { + echo 'Package Failed' + slackSend color: "danger", message: "Package Failed" + } + } + } + stage('Run'){ + steps{ + echo 'Running...' + slackSend color: "warning", message: "Running..." + sh '#./mvnw spring-boot:run -e' + } + post { + success { + echo 'Run Success' + slackSend color: "good", message: "Run Success" + cleanWs() + } + failure { + echo 'Run Failed' + slackSend color: "danger", message: "Run Failed" + } + } + } + } +} diff --git a/README.md b/README.md index 9b67037b..3e52a329 100644 --- a/README.md +++ b/README.md @@ -43,4 +43,4 @@ # Uso - Agregar archivo **_Jenkinsfile_** en la raíz de la rama del proyecto a procesar (sólo como pivote al código del pipeline). - Registrar Pipeline en **_Jenkins -> Administrar Jenkins -> Configuración Global -> Global Pipeline Libraries_** bajo el nombre **_pipeline_** -- Configurar _Multibranch Pipeline Job_ o _Pipeline Job_ en Jenkins con el repositorio del proyecto a procesar. +- Configurar _Multibranch Pipeline Job_ o _Pipeline Job_ en Jenkins con el repositorio del proyecto a procesar... diff --git a/src/main/java/com/devopsusach2020/rest/RestData.java b/src/main/java/com/devopsusach2020/rest/RestData.java index e06ca00f..b7e1e238 100644 --- a/src/main/java/com/devopsusach2020/rest/RestData.java +++ b/src/main/java/com/devopsusach2020/rest/RestData.java @@ -23,13 +23,49 @@ public class RestData { private final static Logger LOGGER = Logger.getLogger("devops.subnivel.Control"); - @GetMapping(path = "/test", produces = MediaType.APPLICATION_JSON_VALUE) - public @ResponseBody Pais getData(@RequestParam(name = "msg") String message){ - - LOGGER.log(Level.INFO, "Proceso exitoso de prueba"); - - Pais response = new Pais(); - response.setMensaje("Mensaje Recibido: " + message); - return response; - } +@GetMapping (path = "/estadoPais", produces = MediaType. APPLICATION_JSON_VALUE) +public @ResponseBody Pais getTotalPais (@RequestParam(name = "pais") String message) { +RestTemplate restTemplate = new RestTemplate(); +ResponseEntity call= restTemplate.getForEntity("https://api.covid19api.com/live/country/" + message, String.class); + + LOGGER.log(Level.INFO, "Consulta por pais"); + Pais response = new Pais(); + int confirmed = 0; + int death = 0; + int recovered = 0; + Gson gson = new Gson(); + Pais[] estados = gson. fromJson(call.getBody().toLowerCase(), Pais[].class); + +for(Pais estado : estados) { + response.setDate(estado.getDate()); + response.setActive(estado.getActive()); + confirmed += estado.getConfirmed(); + death += estado.getDeaths(); + recovered += estado.getRecovered(); +} + + response. setConfirmed (confirmed); + response.setDeaths (death); + response. setRecovered (recovered); + response.setCountry(message); + response.setMensaje("ok"); +return response; +} + +@GetMapping (path = "/estadoMundial", produces = MediaType. APPLICATION_JSON_VALUE) + public @ResponseBody Mundial getTotalMundial(){ + + LOGGER.log(Level.INFO, "Consulta mundial"); + + RestTemplate restTemplate = new RestTemplate(); + ResponseEntity call= restTemplate.getForEntity("https://api.covid19api.com/world/total", String.class); + Mundial response = new Mundial(); + Gson gson = new Gson(); + Mundial estado = gson.fromJson(call.getBody().toLowerCase(), Mundial.class); + response.setTotalConfirmed(estado.getTotalConfirmed()); + response.setTotalDeaths(estado.getTotalDeaths()); + response.setTotalRecovered(estado.getTotalRecovered()); + return response; +} + }