From 61231460d445036732be85bd155f9523dcb4490c Mon Sep 17 00:00:00 2001 From: Red Hat Developers Launcher <45641108+redhat-developers-launcher@users.noreply.github.com> Date: Fri, 3 Jan 2020 14:39:22 +0000 Subject: [PATCH] Initial commit --- .github/CODE_OF_CONDUCT.md | 46 ++ .github/ISSUE_TEMPLATE.md | 16 + .github/PULL_REQUEST_TEMPLATE.md | 35 ++ .gitignore | 30 ++ .mvn/wrapper/MavenWrapperDownloader.java | 110 ++++ .mvn/wrapper/maven-wrapper.properties | 1 + .openshiftio/application.yaml | 483 ++++++++++++++++++ Jenkinsfile | 16 + LICENSE | 201 ++++++++ README.adoc | 104 ++++ mocks/arrivals/GET.mock | 16 + mocks/departures/GET.mock | 16 + mvnw | 286 +++++++++++ mvnw.cmd | 161 ++++++ pom.xml | 237 +++++++++ src/main/fabric8/deployment.yml | 15 + .../fuse/boosters/rest/http/Application.java | 16 + .../fuse/boosters/rest/http/Arrival.java | 15 + .../fuse/boosters/rest/http/ArrivalsList.java | 6 + .../boosters/rest/http/ArrivalsService.java | 16 + .../rest/http/ArrivalsServiceImpl.java | 22 + .../fuse/boosters/rest/http/CamelRouter.java | 88 ++++ .../fuse/boosters/rest/http/Departure.java | 15 + .../boosters/rest/http/DeparturesList.java | 6 + .../boosters/rest/http/DeparturesService.java | 16 + .../rest/http/DeparturesServiceImpl.java | 20 + .../fuse/boosters/rest/http/Flight.java | 25 + .../rest/http/FlightAggregationStrategy.java | 34 ++ .../fuse/boosters/rest/http/FlightsList.java | 6 + .../boosters/rest/http/IndexRootMapper.java | 17 + .../resources/META-INF/resources/favicon.ico | Bin 0 -> 82874 bytes .../META-INF/resources/rest-http-index.html | 32 ++ src/main/resources/application.properties | 9 + src/main/resources/log4j2.properties | 8 + .../boosters/rest/http/HttpRequestKT.java | 54 ++ .../boosters/rest/http/HttpRequestTest.java | 31 ++ 36 files changed, 2209 insertions(+) create mode 100644 .github/CODE_OF_CONDUCT.md create mode 100644 .github/ISSUE_TEMPLATE.md create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .gitignore create mode 100755 .mvn/wrapper/MavenWrapperDownloader.java create mode 100755 .mvn/wrapper/maven-wrapper.properties create mode 100644 .openshiftio/application.yaml create mode 100644 Jenkinsfile create mode 100644 LICENSE create mode 100644 README.adoc create mode 100644 mocks/arrivals/GET.mock create mode 100644 mocks/departures/GET.mock create mode 100755 mvnw create mode 100755 mvnw.cmd create mode 100644 pom.xml create mode 100644 src/main/fabric8/deployment.yml create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/Application.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/Arrival.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsList.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsService.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsServiceImpl.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/CamelRouter.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/Departure.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesList.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesService.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesServiceImpl.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/Flight.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/FlightAggregationStrategy.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/FlightsList.java create mode 100644 src/main/java/com/redhat/fuse/boosters/rest/http/IndexRootMapper.java create mode 100644 src/main/resources/META-INF/resources/favicon.ico create mode 100644 src/main/resources/META-INF/resources/rest-http-index.html create mode 100644 src/main/resources/application.properties create mode 100644 src/main/resources/log4j2.properties create mode 100644 src/test/java/com/redhat/fuse/boosters/rest/http/HttpRequestKT.java create mode 100644 src/test/java/com/redhat/fuse/boosters/rest/http/HttpRequestTest.java diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..7e77a3a --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,46 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md new file mode 100644 index 0000000..84266d8 --- /dev/null +++ b/.github/ISSUE_TEMPLATE.md @@ -0,0 +1,16 @@ +## Description + + +## Expected Behavior + + +## Actual Behavior + + +## Environment + +* Java: +* Maven: + +## Steps to reproduce + diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..b68bcfd --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,35 @@ +## Motivation + + +## What + + +## Why + + +## How + + +## Verification Steps + + +## Checklist: + +- [ ] Code has been tested locally by PR requester +- [ ] Changes have been successfully verified by another team member + +## Progress + +- [x] Finished task +- [ ] TODO + +## Additional Notes + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..248dbbf --- /dev/null +++ b/.gitignore @@ -0,0 +1,30 @@ +# Compiled class file +*.class + +# Log file +*.log + +# BlueJ files +*.ctxt + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear +*.zip +*.tar.gz +*.rar + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + +target/ +.idea/ +*.iml +.vscode/ +.classpath +.project +.settings/ diff --git a/.mvn/wrapper/MavenWrapperDownloader.java b/.mvn/wrapper/MavenWrapperDownloader.java new file mode 100755 index 0000000..fa4f7b4 --- /dev/null +++ b/.mvn/wrapper/MavenWrapperDownloader.java @@ -0,0 +1,110 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +*/ + +import java.net.*; +import java.io.*; +import java.nio.channels.*; +import java.util.Properties; + +public class MavenWrapperDownloader { + + /** + * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. + */ + private static final String DEFAULT_DOWNLOAD_URL = + "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar"; + + /** + * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to + * use instead of the default one. + */ + private static final String MAVEN_WRAPPER_PROPERTIES_PATH = + ".mvn/wrapper/maven-wrapper.properties"; + + /** + * Path where the maven-wrapper.jar will be saved to. + */ + private static final String MAVEN_WRAPPER_JAR_PATH = + ".mvn/wrapper/maven-wrapper.jar"; + + /** + * Name of the property which should be used to override the default download url for the wrapper. + */ + private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; + + public static void main(String args[]) { + System.out.println("- Downloader started"); + File baseDirectory = new File(args[0]); + System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); + + // If the maven-wrapper.properties exists, read it and check if it contains a custom + // wrapperUrl parameter. + File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); + String url = DEFAULT_DOWNLOAD_URL; + if(mavenWrapperPropertyFile.exists()) { + FileInputStream mavenWrapperPropertyFileInputStream = null; + try { + mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); + Properties mavenWrapperProperties = new Properties(); + mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); + url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); + } catch (IOException e) { + System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); + } finally { + try { + if(mavenWrapperPropertyFileInputStream != null) { + mavenWrapperPropertyFileInputStream.close(); + } + } catch (IOException e) { + // Ignore ... + } + } + } + System.out.println("- Downloading from: : " + url); + + File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); + if(!outputFile.getParentFile().exists()) { + if(!outputFile.getParentFile().mkdirs()) { + System.out.println( + "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); + } + } + System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); + try { + downloadFileFromURL(url, outputFile); + System.out.println("Done"); + System.exit(0); + } catch (Throwable e) { + System.out.println("- Error downloading"); + e.printStackTrace(); + System.exit(1); + } + } + + private static void downloadFileFromURL(String urlString, File destination) throws Exception { + URL website = new URL(urlString); + ReadableByteChannel rbc; + rbc = Channels.newChannel(website.openStream()); + FileOutputStream fos = new FileOutputStream(destination); + fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); + fos.close(); + rbc.close(); + } + +} diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100755 index 0000000..00d32aa --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip \ No newline at end of file diff --git a/.openshiftio/application.yaml b/.openshiftio/application.yaml new file mode 100644 index 0000000..dc3dabe --- /dev/null +++ b/.openshiftio/application.yaml @@ -0,0 +1,483 @@ +apiVersion: v1 +kind: Template +metadata: + name: launchpad-builder-fuse-flights-aggregator + annotations: + description: This template creates a Build Configuration using an S2I builder. + tags: instant-app +parameters: +- name: SOURCE_REPOSITORY_URL + description: The source URL for the application + displayName: Source URL + required: true +- name: SOURCE_REPOSITORY_REF + description: The branch name for the application + displayName: Source Branch + value: master + required: true +- name: SOURCE_REPOSITORY_DIR + description: The location within the source repo of the application + displayName: Source Directory + value: . + required: true +- name: ARTIFACT_COPY_ARGS + description: Syntax to be used to copy uberjar files to the target directory + displayName: Copy Args + value: '*-exec.jar' + required: true +- name: GITHUB_WEBHOOK_SECRET + description: A secret string used to configure the GitHub webhook. + displayName: GitHub Webhook Secret + required: true + from: '[a-zA-Z0-9]{40}' + generate: expression +- name: MAVEN_MIRROR_URL + description: Maven Nexus Repository to be used during build phase + displayName: + value: '' + required: false +- name: BUILDER_IMAGE_NAME + description: Name of the image to use as a builder image + displayName: Builder Image Name + value: 'fabric8/s2i-java:latest' + required: true +objects: +- apiVersion: v1 + kind: ImageStream + metadata: + name: fuse-java-openshift + spec: + tags: + - name: "latest" + annotations: + description: Fabric8 Java S2I images. + iconClass: icon-jboss + tags: 'builder,jboss-fuse,java,xpaas,hidden' + version: '1.0' + from: + kind: DockerImage + name: ${BUILDER_IMAGE_NAME} +- apiVersion: v1 + kind: ImageStream + metadata: + name: fuse-flights-aggregator + spec: {} +- apiVersion: v1 + kind: BuildConfig + metadata: + name: fuse-flights-aggregator + labels: + app: fuse-flights-aggregator + group: com.redhat.fuse.boosters + provider: fabric8 + spec: + output: + to: + kind: ImageStreamTag + name: fuse-flights-aggregator:latest + postCommit: {} + resources: {} + runPolicy: Serial + source: + git: + uri: ${SOURCE_REPOSITORY_URL} + ref: ${SOURCE_REPOSITORY_REF} + #contextDir: ${SOURCE_REPOSITORY_DIR} + type: Git + strategy: + sourceStrategy: + env: + - name: BUILD_LOGLEVEL + value: '5' + - name: MAVEN_ARGS_APPEND + value: "-pl ${SOURCE_REPOSITORY_DIR}" + - name: ARTIFACT_DIR + value: "${SOURCE_REPOSITORY_DIR}/target" + - name: MAVEN_MIRROR_URL + value: "${MAVEN_MIRROR_URL}" + - name: ARTIFACT_COPY_ARGS + value: "${ARTIFACT_COPY_ARGS}" + forcePull: true + from: + kind: ImageStreamTag + name: fuse-java-openshift:latest + incremental: true + type: Source + triggers: + - github: + secret: ${GITHUB_WEBHOOK_SECRET} + type: GitHub + - type: ConfigChange + - imageChange: {} + type: ImageChange + status: + lastVersion: 0 +- apiVersion: v1 + kind: Service + metadata: + annotations: + prometheus.io/port: "9779" + prometheus.io/scrape: "true" + labels: + expose: "true" + app: fuse-flights-aggregator + provider: fabric8 + group: com.redhat.fuse.boosters + name: fuse-flights-aggregator + spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: fuse-flights-aggregator + provider: fabric8 + group: com.redhat.fuse.boosters +- apiVersion: v1 + kind: Service + metadata: + labels: + app: fuse-flights-aggregator + group: com.redhat.fuse.boosters + name: arrivals + spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: fuse-flights-aggregator + group: com.redhat.fuse.boosters + service: arrivals +- apiVersion: v1 + kind: Service + metadata: + labels: + app: fuse-flights-aggregator + group: com.redhat.fuse.boosters + name: departures + spec: + ports: + - name: http + port: 8080 + protocol: TCP + targetPort: 8080 + selector: + app: fuse-flights-aggregator + group: com.redhat.fuse.boosters + service: departures +- apiVersion: v1 + kind: DeploymentConfig + metadata: + labels: + app: fuse-flights-aggregator + provider: fabric8 + group: com.redhat.fuse.boosters + name: fuse-flights-aggregator + spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + app: fuse-flights-aggregator + provider: fabric8 + group: com.redhat.fuse.boosters + strategy: + rollingParams: + timeoutSeconds: 3600 + type: Rolling + template: + metadata: + labels: + app: fuse-flights-aggregator + provider: fabric8 + group: com.redhat.fuse.boosters + spec: + containers: + - env: + - name: KUBERNETES_NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: ARRIVALS_HOST + value: arrivals:8080 + - name: DEPARTURES_HOST + value: departures:8080 + image: fuse-flights-aggregator:latest + imagePullPolicy: IfNotPresent + livenessProbe: + httpGet: + path: /health + port: 8080 + scheme: HTTP + initialDelaySeconds: 180 + name: fuse-flights-aggregator + ports: + - containerPort: 8080 + name: http + protocol: TCP + - containerPort: 9779 + name: prometheus + protocol: TCP + - containerPort: 8778 + name: jolokia + protocol: TCP + readinessProbe: + httpGet: + path: /health + port: 8080 + scheme: HTTP + initialDelaySeconds: 10 + resources: + limits: + cpu: 500m + memory: 350Mi + requests: + cpu: 500m + memory: 256Mi + securityContext: + privileged: false + triggers: + - type: ConfigChange + - imageChangeParams: + automatic: true + containerNames: + - fuse-flights-aggregator + from: + kind: ImageStreamTag + name: fuse-flights-aggregator:latest + type: ImageChange +- apiVersion: v1 + kind: DeploymentConfig + metadata: + labels: + app: fuse-flights-aggregator + group: com.redhat.fuse.boosters + service: arrivals + name: arrivals + spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + app: fuse-flights-aggregator + service: arrivals + group: com.redhat.fuse.boosters + strategy: + rollingParams: + timeoutSeconds: 3600 + type: Rolling + template: + metadata: + labels: + app: fuse-flights-aggregator + service: arrivals + group: com.redhat.fuse.boosters + spec: + containers: + - image: quay.io/dmartin/mockserver:latest + imagePullPolicy: IfNotPresent + name: arrivals + ports: + - containerPort: 8080 + name: http + protocol: TCP + resources: {} + securityContext: + privileged: false + volumeMounts: + - mountPath: /tmp/mocks/arrivals + name: arrivals + volumes: + - configMap: + defaultMode: 420 + name: arrivals + name: arrivals + triggers: + - type: ConfigChange +- apiVersion: v1 + kind: DeploymentConfig + metadata: + labels: + app: fuse-flights-aggregator + group: com.redhat.fuse.boosters + service: departures + name: departures + spec: + replicas: 1 + revisionHistoryLimit: 2 + selector: + app: fuse-flights-aggregator + service: departures + group: com.redhat.fuse.boosters + strategy: + rollingParams: + timeoutSeconds: 3600 + type: Rolling + template: + metadata: + labels: + app: fuse-flights-aggregator + service: departures + group: com.redhat.fuse.boosters + spec: + containers: + - image: quay.io/dmartin/mockserver:latest + imagePullPolicy: IfNotPresent + name: departures + ports: + - containerPort: 8080 + name: http + protocol: TCP + resources: {} + securityContext: + privileged: false + volumeMounts: + - mountPath: /tmp/mocks/departures + name: departures + volumes: + - configMap: + defaultMode: 420 + name: departures + name: departures + triggers: + - type: ConfigChange +- apiVersion: v1 + kind: ConfigMap + data: + GET.mock: |- + HTTP/1.1 200 OK + Content-Type: application/json; charset=utf-8 + + [{ + "code": "LAX", + "time": 1538050030000 + }, { + "code": "ORD", + "time": 1538051000000 + }, { + "code": "DFW", + "time": 1538052030000 + }, { + "code": "DEN", + "time": 1538053030000 + }, { + "code": "SFO", + "time": 1538050030000 + }, { + "code": "LAS", + "time": 1538051000000 + }, { + "code": "SEA", + "time": 1538052030000 + }, { + "code": "CLT", + "time": 1538053030000 + }, { + "code": "DUB", + "time": 1538050030000 + }, { + "code": "JFK", + "time": 1538051000000 + }, { + "code": "RDU", + "time": 1538052030000 + }, { + "code": "ATL", + "time": 1538053030000 + }, { + "code": "MCO", + "time": 1538052030000 + }, { + "code": "PHX", + "time": 1538053030000 + }] + metadata: + labels: + app: fuse-flights-aggregator + group: com.redhat.fuse.boosters + name: arrivals +- apiVersion: v1 + kind: ConfigMap + data: + GET.mock: |- + HTTP/1.1 200 OK + Content-Type: application/json; charset=utf-8 + + [{ + "code": "CDG", + "time": 1538054430000 + }, { + "code": "JFK", + "time": 1538055500000 + }, { + "code": "EWR", + "time": 1538056630000 + }, { + "code": "MIA", + "time": 1538057730000 + }, { + "code": "LAX", + "time": 1538060030000 + }, { + "code": "ORD", + "time": 1538052000000 + }, { + "code": "DFW", + "time": 1538051030000 + }, { + "code": "DEN", + "time": 1538053230000 + }, { + "code": "SFO", + "time": 1538060030000 + }, { + "code": "LAS", + "time": 1538052000000 + }, { + "code": "SEA", + "time": 1538051030000 + }, { + "code": "CLT", + "time": 1538053230000 + }, { + "code": "DUB", + "time": 1538060030000 + }, { + "code": "JFK", + "time": 1538052000000 + }, { + "code": "RDU", + "time": 1538051030000 + }, { + "code": "ATL", + "time": 1538053230000 + }, { + "code": "MCO", + "time": 1538051030000 + }, { + "code": "PHX", + "time": 1538053230000 + }] + metadata: + labels: + app: fuse-flights-aggregator + group: com.redhat.fuse.boosters + name: departures +- apiVersion: v1 + kind: Route + metadata: + labels: + app: fuse-flights-aggregator + provider: fabric8 + group: com.redhat.fuse.boosters + name: fuse-flights-aggregator + spec: + tls: + insecureEdgeTerminationPolicy: Allow + termination: edge + port: + targetPort: 8080 + to: + kind: Service + name: fuse-flights-aggregator diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 0000000..8fc2481 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2018 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +boosterBuild() diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..c9cd878 --- /dev/null +++ b/README.adoc @@ -0,0 +1,104 @@ +:launchURL: https://developers.redhat.com/launch + += Fuse Aggregation + +The booster demonstrates how to aggregate JSON data from 2 services using Camel. + +Use this booster to: + +* Execute an HTTP GET request on the `camel/flights` endpoint to retrieve a list of flights (arrivals and departures). Arrivals and Departures are aggregated from 2 separate services. See `CamelRouter.java` for how these 2 services are aggregated. +These services are configured to be local service beans by default. However, you can change the camel routing to fetch data from 2 mock servers (included in this booster). + +* Browse the API's Swagger page. + +== Deployment options + +You can run this booster in the following modes: + +* Single-node OpenShift cluster +* OpenShift Online at link:{launchURL}[] +* Standalone on your machine + +The most effective way to use this booster is to deploy and run the project on OpenShift. + +For more details about running this booster on a single-node OpenShift cluster, CI/CD deployments, as well as the rest of the runtime, see the link:http://appdev.openshift.io/docs/spring-boot-runtime.html[Spring Boot Runtime Guide]. + +IMPORTANT: This booster requires Java 8 JDK or later and Maven 3.3.x or later. + + +== Running the booster on a single-node OpenShift cluster + +A single-node OpenShift cluster provides you with access to a cloud environment that is similar to a production environment. + +If you have a single-node OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, link:http://appdev.openshift.io/docs/minishift-installation.html[installed and running], you can deploy your booster there. + +To deploy this booster to a running single-node OpenShift cluster: + +. Download the project and extract the archive on your local filesystem. + +. Log in to your OpenShift cluster: ++ +[source,bash,options="nowrap",subs="attributes+"] +---- +$ oc login -u developer -p developer +---- + +. Create a new OpenShift project for the booster: ++ +[source,bash,options="nowrap",subs="attributes+"] +---- +$ oc new-project MY_PROJECT_NAME +---- + +. Change the directory to the folder that contains the extracted booster application (for example, `my_openshift/fuse-rest-http-booster`) : ++ +[source,bash,options="nowrap",subs="attributes+"] +---- +$ cd my_openshift/fuse-rest-http-booster +---- + +. Build and deploy the project to the OpenShift cluster: ++ +[source,bash,options="nowrap",subs="attributes+"] +---- +$ mvn clean -DskipTests fabric8:deploy -Popenshift +---- + +. In your browser, navigate to the `MY_PROJECT_NAME` project in the OpenShift console. +Wait until you can see that the pod for the `fuse-rest-http-booster` application has started up. + +. On the project's `Overview` page, locate the URL for the `fuse-flights-aggregator` application. The URL uses this form: +`http://fuse-flights-aggregator-MY_PROJECT_NAME.OPENSHIFT_IP_ADDR.nip.io`. + +. Click the URL to access the Flights Service and then follow the instructions on that page. + +== Running the booster on OpenShift Online + +To deploy this booster directly to OpenShift Online when you create the project at link:{launchURL}[]. + +. Go to link:{launchURL}[]. +. At the *Deployment step*, select *Use OpenShift Online*. +. Follow the on-screen instructions to create a new *REST API Level 0* project by using the *Fuse* runtime. + +NOTE: As part of the process of creating this booster, link:{launchURL}[] sets up a project with a CI/CD deployment of this booster. You can see the status of this deployment in your single-node OpenShift cluster or OpenShift Online web console. + +== Running the booster standalone on your machine + +To run this booster as a standalone project on your local machine: + +. Download the project and extract the archive on your local filesystem. + +. Build the project: ++ +[source,bash,options="nowrap",subs="attributes+"] +---- +$ cd PROJECT_DIR +$ mvn clean package +---- +. Run the services: ++ +[source,bash,options="nowrap",subs="attributes+"] +---- +$ mvn spring-boot:run +---- +. Go to link:http://localhost:8080[] and then follow the instructions on that page. diff --git a/mocks/arrivals/GET.mock b/mocks/arrivals/GET.mock new file mode 100644 index 0000000..fe63256 --- /dev/null +++ b/mocks/arrivals/GET.mock @@ -0,0 +1,16 @@ +HTTP/1.1 200 OK +Content-Type: application/json; charset=utf-8 + +[{ + "code": "DUB", + "time": 1538050030000 +}, { + "code": "JFK", + "time": 1538051000000 +}, { + "code": "RDU", + "time": 1538052030000 +}, { + "code": "ATL", + "time": 1538053030000 +}] diff --git a/mocks/departures/GET.mock b/mocks/departures/GET.mock new file mode 100644 index 0000000..6062455 --- /dev/null +++ b/mocks/departures/GET.mock @@ -0,0 +1,16 @@ +HTTP/1.1 200 OK +Content-Type: application/json; charset=utf-8 + +[{ + "code": "CDG", + "time": 1538054430000 +}, { + "code": "JFK", + "time": 1538055500000 +}, { + "code": "EWR", + "time": 1538056630000 +}, { + "code": "MIA", + "time": 1538057730000 +}] diff --git a/mvnw b/mvnw new file mode 100755 index 0000000..5551fde --- /dev/null +++ b/mvnw @@ -0,0 +1,286 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven2 Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" + # TODO classpath? +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`which java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + wget "$jarUrl" -O "$wrapperJarPath" + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + curl -o "$wrapperJarPath" "$jarUrl" + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100755 index 0000000..48363fa --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,161 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM http://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven2 Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" +if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar" +FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + echo Found %WRAPPER_JAR% +) else ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" + echo Finished downloading %WRAPPER_JAR% +) +@REM End of extension + +%MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" +if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%" == "on" pause + +if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% + +exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..39e5968 --- /dev/null +++ b/pom.xml @@ -0,0 +1,237 @@ + + + 4.0.0 + com.yourcompany.newapp + newapp-fuse + 1.0.0-SNAPSHOT + Fuse :: Boosters :: Rest HTTP + + UTF-8 + UTF-8 + 1.5.13.RELEASE + 2.21.2 + + 3.5.40 + + 1.17.1 + 1.4.0.Final + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + org.apache.camel + camel-spring-boot-dependencies + ${camel.version} + pom + import + + + org.arquillian.cube + arquillian-cube-bom + ${arquillian.cube.version} + import + pom + + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + org.springframework.boot + spring-boot-starter-undertow + + + org.springframework.boot + spring-boot-starter-actuator + + + org.webjars + swagger-ui + 3.13.0 + + + org.webjars + webjars-locator + 0.33 + + + + org.apache.camel + camel-spring-boot-starter + + + org.apache.camel + camel-http-starter + + + org.apache.camel + camel-servlet-starter + + + org.apache.camel + camel-jackson-starter + + + org.apache.camel + camel-swagger-java-starter + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.apache.camel + camel-test + test + + + org.arquillian.cube + arquillian-cube-requirement + test + + + org.arquillian.cube + arquillian-cube-openshift + + + org.apache.httpcomponents + httpclient-osgi + + + test + + + org.jboss.arquillian.junit + arquillian-junit-standalone + ${arquillian.version} + test + + + + + + + io.fabric8 + fabric8-maven-plugin + ${fmp.version} + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + true + + + **/*KT.java + + + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot.version} + + exec + + + + + repackage + + + + + + + + + redhat-ga-repository + https://maven.repository.redhat.com/ga + + + false + + + + redhat-ea-repository + https://maven.repository.redhat.com/earlyaccess/all + + + false + + + + + + redhat-ga-repository + https://maven.repository.redhat.com/ga + + + false + + + + redhat-ea-repository + https://maven.repository.redhat.com/earlyaccess/all + + + false + + + + + + openshift + + + + io.fabric8 + fabric8-maven-plugin + + + + resource + build + + + + + + + + + + + diff --git a/src/main/fabric8/deployment.yml b/src/main/fabric8/deployment.yml new file mode 100644 index 0000000..d31cae1 --- /dev/null +++ b/src/main/fabric8/deployment.yml @@ -0,0 +1,15 @@ +spec: + template: + spec: + containers: + - + 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 }}}' diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/Application.java b/src/main/java/com/redhat/fuse/boosters/rest/http/Application.java new file mode 100644 index 0000000..e85fb7b --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/Application.java @@ -0,0 +1,16 @@ +package com.redhat.fuse.boosters.rest.http; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + /** + * Main method to start the application. + */ + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} \ No newline at end of file diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/Arrival.java b/src/main/java/com/redhat/fuse/boosters/rest/http/Arrival.java new file mode 100644 index 0000000..aad11c7 --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/Arrival.java @@ -0,0 +1,15 @@ +package com.redhat.fuse.boosters.rest.http; + +public class Arrival extends Flight { + + public Arrival(){} + + public Arrival(String code, Long time) { + this.setCode(code); + this.setTime(time); + } + + @Override public String getFlightType() { + return "arrival"; + } +} diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsList.java b/src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsList.java new file mode 100644 index 0000000..76e66eb --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsList.java @@ -0,0 +1,6 @@ +package com.redhat.fuse.boosters.rest.http; + +import java.util.LinkedList; + +public class ArrivalsList extends LinkedList { +} diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsService.java b/src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsService.java new file mode 100644 index 0000000..b1e0aeb --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsService.java @@ -0,0 +1,16 @@ +package com.redhat.fuse.boosters.rest.http; + +import java.util.List; + +/** + * Service interface for name service. + * + */ +public interface ArrivalsService { + + /** + * @return a list of arrivals + */ + List getArrivals(); + +} \ No newline at end of file diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsServiceImpl.java b/src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsServiceImpl.java new file mode 100644 index 0000000..3f2fd3d --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/ArrivalsServiceImpl.java @@ -0,0 +1,22 @@ +package com.redhat.fuse.boosters.rest.http; + +import com.google.common.collect.Lists; +import org.apache.camel.Header; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service("arrivalsService") +public class ArrivalsServiceImpl implements ArrivalsService { + + @Override + public List getArrivals() { + return Lists.newArrayList( + new Arrival("DUB", 1538050030000l), + new Arrival("JFK", 1538051000000l), + new Arrival("RDU", 1538052030000l), + new Arrival("ATL", 1538053030000l) + ); + } + +} \ No newline at end of file diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/CamelRouter.java b/src/main/java/com/redhat/fuse/boosters/rest/http/CamelRouter.java new file mode 100644 index 0000000..c5d489f --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/CamelRouter.java @@ -0,0 +1,88 @@ +package com.redhat.fuse.boosters.rest.http; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.model.dataformat.JsonLibrary; +import org.apache.camel.model.rest.RestBindingMode; +import org.apache.camel.model.rest.RestParamType; +import org.springframework.stereotype.Component; + +import java.util.List; + +/** + * A simple Camel REST DSL route that implements the arrivals service. + * + */ +@Component +public class CamelRouter extends RouteBuilder { + + + @Override + public void configure() throws Exception { + String arrivalsHost = System.getenv("ARRIVALS_HOST"); + String departuresHost = System.getenv("DEPARTURES_HOST"); + + if (arrivalsHost == null || arrivalsHost.isEmpty()) { + throw new Exception("ARRIVALS_HOST env var not set"); + } else if(departuresHost == null || departuresHost.isEmpty()) { + throw new Exception("DEPARTURES_HOST env var not set"); + } + + // @formatter:off + restConfiguration() + .enableCORS(true) + .apiContextPath("/api-doc") + .apiProperty("api.title", "Airport Flights REST API") + .apiProperty("api.version", "1.0") + .apiProperty("cors", "true") + .apiProperty("base.path", "camel/") + .apiProperty("api.path", "/") + .apiProperty("host", "") + .apiProperty("schemes", "https") + .apiContextRouteId("doc-api") + .component("servlet") + .bindingMode(RestBindingMode.json); + + rest("/flights") + .description("List all flights (arrivals & departures)") + .get() + .param().name("user_key") + .type(RestParamType.query) + .required(false) + .description("User Key, if calling the API in front of 3Scale.") + .endParam() + .outType(FlightsList.class) + .route().routeId("flights-api") + .multicast(new FlightAggregationStrategy()) + .parallelProcessing() + + // + // COMMENT OUT THIS + .to("direct:arrivalsImplLocal", "direct:departuresImplLocal"); + + // + // UNCOMMENT THIS + //.to("direct:arrivalsImplRemote", "direct:departuresImplRemote"); + + from("direct:arrivalsImplRemote").description("Arrivals REST service implementation route") + .streamCaching() + .to(String.format("http://%s/arrivals?bridgeEndpoint=true", arrivalsHost)) + .convertBodyTo(String.class) + .unmarshal().json(JsonLibrary.Jackson, ArrivalsList.class); + + from("direct:departuresImplRemote").description("Departures REST service implementation route") + .streamCaching() + .to(String.format("http://%s/departures?bridgeEndpoint=true", departuresHost)) + .convertBodyTo(String.class) + .unmarshal().json(JsonLibrary.Jackson, DeparturesList.class); + + from("direct:arrivalsImplLocal").description("Arrivals REST service implementation route") + .streamCaching() + .to("bean:arrivalsService?method=getArrivals"); + + from("direct:departuresImplLocal").description("Departures REST service implementation route") + .streamCaching() + .to("bean:departuresService?method=getDepartures"); + // @formatter:on + } + +} \ No newline at end of file diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/Departure.java b/src/main/java/com/redhat/fuse/boosters/rest/http/Departure.java new file mode 100644 index 0000000..5e41f14 --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/Departure.java @@ -0,0 +1,15 @@ +package com.redhat.fuse.boosters.rest.http; + +public class Departure extends Flight { + + public Departure() {} + + public Departure(String code, Long time) { + this.setCode(code); + this.setTime(time); + } + + @Override public String getFlightType() { + return "departure"; + } +} diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesList.java b/src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesList.java new file mode 100644 index 0000000..ed0f8ea --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesList.java @@ -0,0 +1,6 @@ +package com.redhat.fuse.boosters.rest.http; + +import java.util.LinkedList; + +public class DeparturesList extends LinkedList { +} diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesService.java b/src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesService.java new file mode 100644 index 0000000..edf89d3 --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesService.java @@ -0,0 +1,16 @@ +package com.redhat.fuse.boosters.rest.http; + +import java.util.List; + +/** + * Service interface for name service. + * + */ +public interface DeparturesService { + + /** + * @return a list of departures + */ + List getDepartures(); + +} \ No newline at end of file diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesServiceImpl.java b/src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesServiceImpl.java new file mode 100644 index 0000000..0a424bc --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/DeparturesServiceImpl.java @@ -0,0 +1,20 @@ +package com.redhat.fuse.boosters.rest.http; + +import com.google.common.collect.Lists; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service("departuresService") +public class DeparturesServiceImpl implements DeparturesService { + + @Override + public List getDepartures() { + return Lists.newArrayList( + new Departure("CDG", 1538054430000l), + new Departure("JFK", 1538055500000l), + new Departure("EWR", 1538056630000l), + new Departure("MIA", 1538057730000l) + ); + } +} \ No newline at end of file diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/Flight.java b/src/main/java/com/redhat/fuse/boosters/rest/http/Flight.java new file mode 100644 index 0000000..d81f6ef --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/Flight.java @@ -0,0 +1,25 @@ +package com.redhat.fuse.boosters.rest.http; + +public abstract class Flight { + + private String code; + private Long time; + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public Long getTime() { + return time; + } + + public void setTime(Long time) { + this.time = time; + } + + public abstract String getFlightType(); +} diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/FlightAggregationStrategy.java b/src/main/java/com/redhat/fuse/boosters/rest/http/FlightAggregationStrategy.java new file mode 100644 index 0000000..0048bc5 --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/FlightAggregationStrategy.java @@ -0,0 +1,34 @@ +package com.redhat.fuse.boosters.rest.http; + +import org.apache.camel.Exchange; +import org.apache.camel.processor.aggregate.AggregationStrategy; + +import java.util.ArrayList; +import java.util.List; + +public class FlightAggregationStrategy implements AggregationStrategy { + + @Override public Exchange aggregate(Exchange ex1, Exchange ex2) { + if (ex1 == null) { + return ex2; + } else { + List arrivals = ex1.getIn().getBody(ArrivalsList.class); + List departures = ex2.getIn().getBody(DeparturesList.class); + + List flights = new ArrayList<>(); + + for (Arrival arrival: arrivals) { + flights.add(arrival); + } + for (Departure departure: departures) { + flights.add(departure); + } + + ex1.getIn().setBody(flights); + return ex1; + } + } +} + + + diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/FlightsList.java b/src/main/java/com/redhat/fuse/boosters/rest/http/FlightsList.java new file mode 100644 index 0000000..ce653bc --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/FlightsList.java @@ -0,0 +1,6 @@ +package com.redhat.fuse.boosters.rest.http; + +import java.util.List; + +public interface FlightsList extends List { +} diff --git a/src/main/java/com/redhat/fuse/boosters/rest/http/IndexRootMapper.java b/src/main/java/com/redhat/fuse/boosters/rest/http/IndexRootMapper.java new file mode 100644 index 0000000..e985310 --- /dev/null +++ b/src/main/java/com/redhat/fuse/boosters/rest/http/IndexRootMapper.java @@ -0,0 +1,17 @@ +package com.redhat.fuse.boosters.rest.http; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; + +@Configuration +@ComponentScan +public class IndexRootMapper extends WebMvcConfigurerAdapter { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("forward:/rest-http-index.html"); + } + +} \ No newline at end of file diff --git a/src/main/resources/META-INF/resources/favicon.ico b/src/main/resources/META-INF/resources/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..145e43a597d5ad7b786ec72597390bef28f38f87 GIT binary patch literal 82874 zcmeI4dyHIF9mnr>ki|#3qT)L&RD?$H#UBc_b}oZ4)>tG+ zRTLGY1VM~M@kPW}WNAY%s8zv75V2cPN(AXZQHHYJ>-W2zLM>l51W!kUTRYyh$_jeP?pJ2L zk=3y3dV)Z=d~g(w{vpWCC(g%Pq0c}UKo>(lfF6Nd4$tYYfU@GRkW?O0eJEQuwle9;o*Za5R?64}Q z-mm@|3i8GyANbVzYrAS6@H4ENbG&C$CVq)z?n^&Bwakt=xx5~7V|q^{S3Zb<>67BB zeeg~*=PoMAkoR@md_B74zFFyYRJwNG8%dN8B4GNYxN0AqS76S?(4JxTJuQ}0vYgjx zn@zi~iR>>QM8Nb(an(NHy-RoQJ*FhXcbR>&?(Gz9me1xcHEnLkI-fa*LOuvl>7TNy zeeijpb3Ry665|`qzT+kL_0xHu_BPWV$He!lSjY!4GW}6rwGX}kY|aNqmPB~G*>_#Z zeVNYtuO~o1hTOd;Hx@o;%X% {^AvhxGyH&QwH~7i6?2e86XM=R$vj+`Mw_&A-e)7?{m>$@P(I-O&xav9N4d^t5GO-}P?;#|gO`_SRJlDv z!1~~Z3P!yUK6oF-X|Mku#r74@5gm-*`XK9bL#9ltA2xN~o(`!E9=XK|Uw^YbnKBy384>r|nKDfsC z;P480%Lf(0?7^mb%?I{-5@o)(QRex9J}39!MDB3Nz2<{A;dtG3(T}j6H)oe3=NnKR z$_l+7WYJmtb=C*G_rhmWMaAd1esuf3=|1T2cF1|*`&eJ@4+7h~uk=CaUWmE8&-!*K z7S;!RW=t+c^`uy%D(@Kr)(38G6dH}NH+=A^1Xd}eGk+BQ1^$%g2 z&)#BTePH)1vVMB3QI+=$fnM|h;T{TYg7W6+PUL(QIuObV`5=qV;;-Xx-9J1}@q5yK z9E*aFv_y}UiDgK3`^J7R96u;xG5CIVo z0TB=Z5fA|p5CIVo0TEan1op>a@N=crJG?{VZ&`log+g&03T-ae*9H>b zj56CN*Y#OE0II^GXQ3_s-s8Dm`xggtuJm$V9mw(9^|yK7)5fQ;;pc?5A4A@ikoBQ$ zr^q^guV&l+V`QftULNmB*`R-HJ6z{Ivrt@%LO(b3UBNR0d8 zALrpRZv+eJ12>i}7{hbCaTMLG$_KAUhi*J>$!Cdv@cZEpLN15Pe?y_)&B+GF>B4D~$9P$DGCLOPPJ^}f!<0m6y3HgA}Xv;*%2ZwnLgytMSKbMUveehy* z?sLl9{wwy0eHUClDEn%5o*(i->^0{%k+=YC4&KKYR zY=8deWY^8_ygahHyCuIbwpWK@As@uZbg#UO5BU1=v)wU);e>oJg}lc-ofz2H6%~0u zVD5Iv&P|?M%SLE!+BReBF(2?6(C)+UdAsj6o$u8#?@%Zf@_xb?SY97<6i{0VKi_PC@s%SP2c;C(Cl-i~XuHK+-%Jn#KWK4^hkz(vRhzd-*N zwRAa_{=DOB&2k$H>4SfwV>{n?zou+d?F07z6UdH>&kOi{-lkXn0c>Z5e2_(_J9Qx+ z_|MS>(e>XU`x@Ww4JYJ-ZOFOP6Yu@RqR9Kfe%RSR@A_kjwQtLPAMpC^-hg<0V~;y_ zUBtFe@^b%$?GwDR$FTi$C@bWHEIQq(E8+w8?4RrI_l6Vl0p~@TDB^=rG-&4~*RL+q zNh{a)!F-=5+pc-;-vQb2-RN!e`y6>8ALJ3LzP^YL4o0{BXH(t_vC&N*)X)*fa607A zGtRlyP}%5)4>*ReL)HhpZ)CUmJj4d?oj%3Whp=t;;rbiA9D2?M@1q?8#qP!0T&>R~ z5c0u2NOR9ZdCl=CXG@Y)FZ zAgc}fBkS{q*L>S%w|u}k$j|Meaet|81iLpn^#RZSqtIID66hdkC8Q`vpsWu#_s$A* zvCux?XWHWe<0x9xEg!Id&c~1s$jFaQeZcnkUT^`l0a^vU3R09KP{aofG`Sff=jD;+ zyX^yB2mA%P4jP4cP2EX!(+4lZzj6iakq!uX7pg+0nL- zHES&Pn6mQbTW8xZy6*SI&mH_tl|lqWKmYKmYKmYKmYKmYKmYKmYKmYKmX_^$ktuy zrbyjbBb|3$tUtC{i}yDjIff?oYXs}+L#&$^nyi_FZ}Hq+2iCE==_C!+txwVB)Lp8 z7MQgT>&7QWlQjeB^w7G2#>$~qyRA0ICnoW?HpfsmKDVyUx)Ih*&e?C=)zy;={Wb?! zH;nxz=G4_|lVgn|v+I)DWHRNoSs$3JHC7J8*po-ksZ0J}_u6<}W5BP&vDY}3q!y@~ zbmMH)0{e|MW{$5}t0(vD2HN6TPu#Jy?&d%pc{T^@$#{F+46`xRO`*=)4?NZ+X{&Bi s+kR= + + + + Red Hat Fuse Aggregation + + + +
+
+

Red Hat Fuse Aggregation

+

+ The booster demonstrates how to aggregate JSON data from 2 services using Camel. +

+

+ To demonstrate the behavior of this booster: + +

    +
  • Click camel/flights to retrieve a list of flights (arrivals and departures). +

    A new browser window opens and shows a response in JSON format with a payload of flights.

  • +
  • Arrivals and Departures are aggregated from 2 separate services. See `CamelRouter.java` for how these 2 services are aggregated
  • +
  • These services are configured to be local service beans by default. However, you can change the camel routing to fetch data from 2 mock servers (included in this booster).
  • +
+

+

Click API Swagger page to open the REST API's Swagger page.

+
+
+ + diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties new file mode 100644 index 0000000..57ab22d --- /dev/null +++ b/src/main/resources/application.properties @@ -0,0 +1,9 @@ +server.port=8080 + +# disable all management enpoints except health +endpoints.enabled = false +endpoints.health.enabled = true +management.health.defaults.enabled=false + +camel.health.enabled=false +camel.health.indicator.enabled=true diff --git a/src/main/resources/log4j2.properties b/src/main/resources/log4j2.properties new file mode 100644 index 0000000..ca73e8a --- /dev/null +++ b/src/main/resources/log4j2.properties @@ -0,0 +1,8 @@ +appender.stdout.type = Console +appender.stdout.name = stdout +appender.stdout.layout.type = PatternLayout +appender.stdout.layout.pattern = %d [%-15.15t] %-5p %-30.30c{1} - %m%n +logger.zipkin.name = org.apache.camel.zipkin +logger.zipkin.level = DEBUG +rootLogger.level = DEBUG +rootLogger.appenderRef.stdout.ref = stdout diff --git a/src/test/java/com/redhat/fuse/boosters/rest/http/HttpRequestKT.java b/src/test/java/com/redhat/fuse/boosters/rest/http/HttpRequestKT.java new file mode 100644 index 0000000..0bcf11c --- /dev/null +++ b/src/test/java/com/redhat/fuse/boosters/rest/http/HttpRequestKT.java @@ -0,0 +1,54 @@ +/* + * Copyright 2005-2016 Red Hat, Inc. + * + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package com.redhat.fuse.boosters.rest.http; + +import io.fabric8.kubernetes.api.model.v4_0.HasMetadata; +import io.fabric8.openshift.clnt.v4_0.OpenShiftClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.HashMap; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(Arquillian.class) +public class HttpRequestKT { + + @ArquillianResource + OpenShiftClient client; + + @Test + public void templateTest() throws Exception { + File template = new File(".openshiftio/application.yaml"); + assertTrue(template.exists()); + HashMap templateParameters = new HashMap(){ + {put("SOURCE_REPOSITORY_URL","https://github.com/jboss-fuse/fuse-rest-http-booster");} + }; + List resources = client.templates().load(template).process(templateParameters).getItems(); + + for(HasMetadata res : resources){ + client.resource(res).createOrReplace(); + } + + assertEquals("fuse-rest-http-booster", client.buildConfigs().list().getItems().get(0).getMetadata().getName()); + } +} diff --git a/src/test/java/com/redhat/fuse/boosters/rest/http/HttpRequestTest.java b/src/test/java/com/redhat/fuse/boosters/rest/http/HttpRequestTest.java new file mode 100644 index 0000000..2bc7eed --- /dev/null +++ b/src/test/java/com/redhat/fuse/boosters/rest/http/HttpRequestTest.java @@ -0,0 +1,31 @@ +package com.redhat.fuse.boosters.rest.http; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class HttpRequestTest { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void greetingsShouldReturnFallbackMessage() throws Exception { + Assert.assertEquals( 8, this.restTemplate.getForObject("http://localhost:" + port + "/camel/flights", FlightsList.class).size()); + } + + @Test + public void healthShouldReturnOkMessage() throws Exception { + Assert.assertEquals( "{\"status\":\"UP\"}", this.restTemplate.getForObject("http://localhost:" + port + "/health", String.class)); + } +} \ No newline at end of file