From 3ef8ab23beec1aa2946a245e20ff4f7265619546 Mon Sep 17 00:00:00 2001 From: mrizzi Date: Wed, 24 Jul 2019 15:06:20 +0200 Subject: [PATCH 1/5] MIGENG-103 Reporting API - Workload Inventory Report --- .../WorkloadInventoryReportRepository.java | 15 +++++++++++++ .../WorkloadInventoryReportService.java | 22 +++++++++++++++++++ src/main/resources/spring/camel-context.xml | 8 +++++++ 3 files changed, 45 insertions(+) create mode 100644 src/main/java/org/jboss/xavier/integrations/jpa/repository/WorkloadInventoryReportRepository.java create mode 100644 src/main/java/org/jboss/xavier/integrations/jpa/service/WorkloadInventoryReportService.java diff --git a/src/main/java/org/jboss/xavier/integrations/jpa/repository/WorkloadInventoryReportRepository.java b/src/main/java/org/jboss/xavier/integrations/jpa/repository/WorkloadInventoryReportRepository.java new file mode 100644 index 00000000..7df5d5ce --- /dev/null +++ b/src/main/java/org/jboss/xavier/integrations/jpa/repository/WorkloadInventoryReportRepository.java @@ -0,0 +1,15 @@ +package org.jboss.xavier.integrations.jpa.repository; + +import org.jboss.xavier.analytics.pojo.output.InitialSavingsEstimationReportModel; +import org.jboss.xavier.analytics.pojo.output.WorkloadInventoryReportModel; +import org.jboss.xavier.integrations.jpa.projection.InitialSavingsEstimationReportSummary; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface WorkloadInventoryReportRepository extends JpaRepository +{ + Page findByAnalysisId(Long analysisId, Pageable pageable); +} diff --git a/src/main/java/org/jboss/xavier/integrations/jpa/service/WorkloadInventoryReportService.java b/src/main/java/org/jboss/xavier/integrations/jpa/service/WorkloadInventoryReportService.java new file mode 100644 index 00000000..d640d511 --- /dev/null +++ b/src/main/java/org/jboss/xavier/integrations/jpa/service/WorkloadInventoryReportService.java @@ -0,0 +1,22 @@ +package org.jboss.xavier.integrations.jpa.service; + +import org.jboss.xavier.analytics.pojo.output.WorkloadInventoryReportModel; +import org.jboss.xavier.integrations.jpa.repository.WorkloadInventoryReportRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Component; + +@Component +public class WorkloadInventoryReportService +{ + @Autowired + WorkloadInventoryReportRepository reportRepository; + + public Page findByAnalysisId(Long analysisId, int page, int size) + { + Pageable pageable = new PageRequest(page, size); + return reportRepository.findByAnalysisId(analysisId, pageable); + } +} diff --git a/src/main/resources/spring/camel-context.xml b/src/main/resources/spring/camel-context.xml index c6e8c52b..8c193316 100644 --- a/src/main/resources/spring/camel-context.xml +++ b/src/main/resources/spring/camel-context.xml @@ -65,6 +65,14 @@ + + Get the Workload Inventory Reports + + + + + + From 2ce0a627fb9791281c5850d3c3230001acc74bec Mon Sep 17 00:00:00 2001 From: mrizzi Date: Thu, 25 Jul 2019 14:14:53 +0200 Subject: [PATCH 2/5] MIGENG-103 Added tests --- src/main/resources/spring/camel-context.xml | 6 +- .../route/XmlRoutes_RestReportTest.java | 94 ++++++++++++++++++- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/src/main/resources/spring/camel-context.xml b/src/main/resources/spring/camel-context.xml index 8c193316..5afe4011 100644 --- a/src/main/resources/spring/camel-context.xml +++ b/src/main/resources/spring/camel-context.xml @@ -56,13 +56,13 @@ Get the details of a report - + Get the Initial Cost Saving report - + @@ -70,7 +70,7 @@ - + diff --git a/src/test/java/org/jboss/xavier/integrations/route/XmlRoutes_RestReportTest.java b/src/test/java/org/jboss/xavier/integrations/route/XmlRoutes_RestReportTest.java index d5e3cce6..91e73b2d 100644 --- a/src/test/java/org/jboss/xavier/integrations/route/XmlRoutes_RestReportTest.java +++ b/src/test/java/org/jboss/xavier/integrations/route/XmlRoutes_RestReportTest.java @@ -6,6 +6,7 @@ import org.apache.camel.test.spring.UseAdviceWith; import org.jboss.xavier.Application; import org.jboss.xavier.integrations.jpa.service.InitialSavingsEstimationReportService; +import org.jboss.xavier.integrations.jpa.service.WorkloadInventoryReportService; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -38,7 +39,10 @@ public class XmlRoutes_RestReportTest { private TestRestTemplate restTemplate; @MockBean - private InitialSavingsEstimationReportService reportService; + private InitialSavingsEstimationReportService initialSavingsEstimationReportService; + + @MockBean + private WorkloadInventoryReportService workloadInventoryReportService; @Value("${camel.component.servlet.mapping.context-path}") String camel_context; @@ -49,7 +53,7 @@ public void setup() { } @Test - public void mainRouteBuilder_RestReport_SummaryParamGiven_ShouldCallFindReportSummary() throws Exception { + public void xmlRouteBuilder_RestReport_SummaryParamGiven_ShouldCallFindReportSummary() throws Exception { //Given camelContext.setTracing(true); camelContext.setAutoStartup(false); @@ -62,12 +66,12 @@ public void mainRouteBuilder_RestReport_SummaryParamGiven_ShouldCallFindReportSu restTemplate.getForEntity(camel_context + "report?summary={summary}", String.class, variables); //Then - verify(reportService).findReportSummary(anyInt(), anyInt()); + verify(initialSavingsEstimationReportService).findReportSummary(anyInt(), anyInt()); camelContext.stop(); } @Test - public void mainRouteBuilder_RestReport_NotSummaryParamGiven_ShouldCallFindReports() throws Exception { + public void xmlRouteBuilder_RestReport_NotSummaryParamGiven_ShouldCallFindReports() throws Exception { //Given camelContext.setTracing(true); camelContext.setAutoStartup(false); @@ -80,7 +84,87 @@ public void mainRouteBuilder_RestReport_NotSummaryParamGiven_ShouldCallFindRepor restTemplate.getForEntity(camel_context + "report?summary={summary}", String.class, variables); //Then - verify(reportService).findReports(); + verify(initialSavingsEstimationReportService).findReports(); + camelContext.stop(); + } + + @Test + public void xmlRouteBuilder_RestReportId_IdParamGiven_ShouldCallFindReportSummaryById() throws Exception { + //Given + camelContext.setTracing(true); + camelContext.setAutoStartup(false); + + //When + camelContext.start(); + camelContext.startRoute("report-get-details"); + Map variables = new HashMap<>(); + Long one = new Long(1); + variables.put("id", one); + restTemplate.getForEntity(camel_context + "report/{id}", String.class, variables); + + //Then + verify(initialSavingsEstimationReportService).findReportSummaryById(one); + camelContext.stop(); + } + + @Test + public void xmlRouteBuilder_RestReportIdInitialSavingsEstimation_IdParamGiven_ShouldCallFindByAnalysisId() throws Exception { + //Given + camelContext.setTracing(true); + camelContext.setAutoStartup(false); + + //When + camelContext.start(); + camelContext.startRoute("reports-get-details"); + Map variables = new HashMap<>(); + Long one = new Long(1); + variables.put("id", one); + restTemplate.getForEntity(camel_context + "report/{id}/initial-saving-estimation", String.class, variables); + + //Then + verify(initialSavingsEstimationReportService).findReportDetails(one); + camelContext.stop(); + } + + @Test + public void xmlRouteBuilder_RestReportIdWorkloadInventory_IdParamGiven_PageParamGiven_SizeParamGiven_ShouldCallFindByAnalysisId() throws Exception { + //Given + camelContext.setTracing(true); + camelContext.setAutoStartup(false); + + //When + camelContext.start(); + camelContext.startRoute("workload-inventory-report-get-details"); + Map variables = new HashMap<>(); + Long one = new Long(1); + variables.put("id", one); + int page = 2; + variables.put("page", page); + int size = 3; + variables.put("size", size); + restTemplate.getForEntity(camel_context + "report/{id}/workload-inventory?page={page}&size={size}", String.class, variables); + + //Then + verify(workloadInventoryReportService).findByAnalysisId(one, page, size); + camelContext.stop(); + } + + @Test + public void xmlRouteBuilder_RestReportIdWorkloadInventory_IdParamGiven_ShouldCallFindByAnalysisId() throws Exception { + //Given + camelContext.setTracing(true); + camelContext.setAutoStartup(false); + + //When + camelContext.start(); + camelContext.startRoute("workload-inventory-report-get-details"); + Map variables = new HashMap<>(); + Long one = new Long(1); + variables.put("id", one); + restTemplate.getForEntity(camel_context + "report/{id}/workload-inventory", String.class, variables); + + //Then + verify(workloadInventoryReportService).findByAnalysisId(one, 0, 10); camelContext.stop(); } From ab95f4553fa74b710d349c7f11b1b22561ef195d Mon Sep 17 00:00:00 2001 From: Carlos Esteban Feria Vila Date: Fri, 26 Jul 2019 18:16:38 +0200 Subject: [PATCH 3/5] add fabric8DeployConfig --- pom.xml | 3 + src/main/fabric8/deployment.yml | 107 +++++++++++++++++++++++++++----- src/main/fabric8/route.yml | 10 +++ src/main/fabric8/svc.yml | 14 +++++ 4 files changed, 117 insertions(+), 17 deletions(-) create mode 100644 src/main/fabric8/route.yml create mode 100644 src/main/fabric8/svc.yml diff --git a/pom.xml b/pom.xml index ef36cc4c..abcdb47c 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,9 @@ 3.6.0 2.19.1 + + analytics-integration + analytics-integration diff --git a/src/main/fabric8/deployment.yml b/src/main/fabric8/deployment.yml index 0a381294..d6d837ec 100644 --- a/src/main/fabric8/deployment.yml +++ b/src/main/fabric8/deployment.yml @@ -1,23 +1,96 @@ +kind: DeploymentConfig +apiVersion: apps.openshift.io/v1 +metadata: + name: analytics-integration spec: + triggers: + - type: ConfigChange + - type: ImageChange + imageChangeParams: + automatic: true + containerNames: + - analytics-integration + from: + kind: ImageStreamTag + name: analytics-integration:latest + replicas: 1 + selector: + deploymentconfig: analytics-integration template: + metadata: + labels: + deploymentconfig: analytics-integration spec: containers: - - + - name: analytics-integration + image: library/analytics-integration:latest + ports: + - name: jolokia + containerPort: 8778 + protocol: TCP + - name: rest + containerPort: 8080 + protocol: TCP + env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + apiVersion: v1 + fieldPath: metadata.namespace + - name: KIESERVER_SERVICE + value: analytics-kieserver + - name: KIESERVER_USERNAME + value: executionUser + - name: KIESERVER_PASSWORD + value: rksxsp2! + - name: KIESERVER_PATH + value: services/rest/server/containers/instances/${kieserver.container} + - name: KIESERVER_CONTAINER + value: sample-analytics_1.0.0-SNAPSHOT + - name: POSTGRESQL_USER + valueFrom: + secretKeyRef: + name: "postgresql" + key: database-user + - name: POSTGRESQL_PASSWORD + valueFrom: + secretKeyRef: + name: "postgresql" + key: database-password + - name: POSTGRESQL_DATABASE + valueFrom: + secretKeyRef: + name: "postgresql" + key: database-name + - name: AMQ_SERVER + value: broker-amq-tcp resources: - requests: - cpu: "0.2" - memory: 256Mi limits: - cpu: "1.0" - memory: 256Mi - env: - - name: SPRING_APPLICATION_JSON - value: '{"server":{"undertow":{"io-threads":1, "worker-threads":2 }}}' - - name: MYSQL_SERVICE_NAME - value: mysql - - name: MYSQL_SERVICE_DATABASE - value: sampledb - - name: MYSQL_SERVICE_USERNAME - value: ${mysql-service-username} - - name: MYSQL_SERVICE_PASSWORD - value: ${mysql-service-password} \ No newline at end of file + cpu: '1' + memory: 512Mi + requests: + cpu: 200m + memory: 512Mi + livenessProbe: + httpGet: + path: "/health" + port: 8081 + scheme: HTTP + initialDelaySeconds: 180 + timeoutSeconds: 1 + periodSeconds: 10 + successThreshold: 1 + failureThreshold: 3 + readinessProbe: + httpGet: + path: "/health" + port: 8081 + scheme: HTTP + initialDelaySeconds: 10 + timeoutSeconds: 1 + periodSeconds: 10 + successThreshold: 1 + failureThreshold: 3 + terminationMessagePath: "/dev/termination-log" + terminationMessagePolicy: File + imagePullPolicy: Always diff --git a/src/main/fabric8/route.yml b/src/main/fabric8/route.yml new file mode 100644 index 00000000..a7e64c14 --- /dev/null +++ b/src/main/fabric8/route.yml @@ -0,0 +1,10 @@ +apiVersion: route.openshift.io/v1 +kind: Route +metadata: + name: analytics-integration +spec: + port: + targetPort: http + to: + kind: Service + name: analytics-integration diff --git a/src/main/fabric8/svc.yml b/src/main/fabric8/svc.yml new file mode 100644 index 00000000..e22daa58 --- /dev/null +++ b/src/main/fabric8/svc.yml @@ -0,0 +1,14 @@ +kind: Service +apiVersion: v1 +metadata: + name: analytics-integration +spec: + ports: + - name: http + protocol: TCP + port: 8080 + targetPort: 8080 + selector: + deploymentconfig: analytics-integration + type: ClusterIP + sessionAffinity: None From d57ecd25cb400460fa75a870fdaa2bd53358790b Mon Sep 17 00:00:00 2001 From: Carlos Esteban Feria Vila Date: Tue, 6 Aug 2019 15:44:52 +0200 Subject: [PATCH 4/5] add custom fabric8 project name --- README.md | 12 ++++++++++++ pom.xml | 22 ++++++++++++++++++++-- src/main/fabric8/route.yml | 4 ++-- src/main/fabric8/svc.yml | 4 ++-- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0ce82d35..3065513a 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,18 @@ Instructions from https://access.redhat.com/documentation/en-us/red_hat_fuse/7.3 1. once the import has finished, click the `Build & Install` button from the upper right `Build` menu 1. once the build has been successfully done, click on the `Deploy` button +# Development + +## How to deploy local code to local OKD instance +build an image with your local code: + +`mvn -gs ./configuration/settings.xml clean package fabric8:deploy -DskipTests` + +once the it finishes, the deployment of a new integration pod to run the new image will start automatically in your OKD instance + +**NOTE: Do not use this method for deploying your code to production.** + + # Manage ## PostgreSQL diff --git a/pom.xml b/pom.xml index abcdb47c..4a6769e0 100644 --- a/pom.xml +++ b/pom.xml @@ -23,8 +23,9 @@ 3.6.0 2.19.1 - analytics-integration - analytics-integration + analytics-integration + ${project.fabric8.name} + ${project.fabric8.name} @@ -228,6 +229,23 @@ + + + src/main/fabric8 + true + + + src/main/resources + true + + + + + src/test/resources + true + + + org.apache.maven.plugins diff --git a/src/main/fabric8/route.yml b/src/main/fabric8/route.yml index a7e64c14..27090bb8 100644 --- a/src/main/fabric8/route.yml +++ b/src/main/fabric8/route.yml @@ -1,10 +1,10 @@ apiVersion: route.openshift.io/v1 kind: Route metadata: - name: analytics-integration + name: ${project.fabric8.name} spec: port: targetPort: http to: kind: Service - name: analytics-integration + name: ${project.fabric8.name} diff --git a/src/main/fabric8/svc.yml b/src/main/fabric8/svc.yml index e22daa58..c853c26f 100644 --- a/src/main/fabric8/svc.yml +++ b/src/main/fabric8/svc.yml @@ -1,7 +1,7 @@ kind: Service apiVersion: v1 metadata: - name: analytics-integration + name: ${project.fabric8.name} spec: ports: - name: http @@ -9,6 +9,6 @@ spec: port: 8080 targetPort: 8080 selector: - deploymentconfig: analytics-integration + deploymentconfig: ${project.fabric8.name} type: ClusterIP sessionAffinity: None From a1dbceb2b07b4c39eb23a0ff7948de2cf5df9305 Mon Sep 17 00:00:00 2001 From: Carlos Esteban Feria Vila Date: Tue, 6 Aug 2019 16:11:29 +0200 Subject: [PATCH 5/5] remove test resources filtering config --- pom.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 4a6769e0..45d54a8c 100644 --- a/pom.xml +++ b/pom.xml @@ -236,15 +236,9 @@ src/main/resources - true + false - - - src/test/resources - true - -