Skip to content

Commit

Permalink
feat: new cloud gateway service (#2576)
Browse files Browse the repository at this point in the history
* init gateway

Signed-off-by: achmelo <[email protected]>

* use routes from registration metadata

Signed-off-by: achmelo <[email protected]>

* include scg in project build

Signed-off-by: achmelo <[email protected]>

* fix build

Signed-off-by: achmelo <[email protected]>

* Add publishing of cloud-gateway-package

Signed-off-by: at670475 <[email protected]>

* CG port and schema

Signed-off-by: achmelo <[email protected]>

* remove unused config parameters

Signed-off-by: achmelo <[email protected]>

* build and publish CGW fat jar, include CGW in start up test

Signed-off-by: achmelo <[email protected]>

* Add test folders to make sonarqube pass

Signed-off-by: at670475 <[email protected]>

* update junit to compatible version, route locator test

Signed-off-by: achmelo <[email protected]>

* license

Signed-off-by: achmelo <[email protected]>

* Add unit test

Signed-off-by: at670475 <[email protected]>

* remove assertion

Signed-off-by: at670475 <[email protected]>

* put assertion back

Signed-off-by: at670475 <[email protected]>

Signed-off-by: achmelo <[email protected]>
Signed-off-by: at670475 <[email protected]>
Co-authored-by: Andrea Tabone <[email protected]>
  • Loading branch information
achmelo and taban03 authored Sep 14, 2022
1 parent 8f71bb5 commit 7c618c0
Show file tree
Hide file tree
Showing 27 changed files with 1,270 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ eggs
parts
bin
!gateway-package/src/main/resources/bin
!cloud-gateway-package/src/main/resources/bin
!api-catalog-package/src/main/resources/bin
!discovery-package/src/main/resources/bin
!caching-service-package/src/main/resources/bin
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ subprojects {
}

task buildCore(dependsOn: [':gateway-service:build', ':discovery-service:build', ':api-catalog-services:build', ':api-catalog-ui:build',
':discoverable-client:build', ':zaas-client:build', ':apiml-sample-extension:build']) {
':discoverable-client:build', ':zaas-client:build', ':apiml-sample-extension:build', ':cloud-gateway-service:build']) {
description "Build core components"
group "build"
}
Expand Down
49 changes: 49 additions & 0 deletions cloud-gateway-package/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
ext {
artifactName = 'cloud-gateway-package'
pullNo = project.hasProperty("pullRequest") && project.getProperty("pullRequest") != null ? "-" + project.getProperty("pullRequest") : ""
}

configurations {
cloudGatewayServiceJar
zip
}

dependencies {
cloudGatewayServiceJar(project(path: ":cloud-gateway-service", configuration: "bootArchives"))
}

task packageCloudGateway(type: Zip) {
archiveFileName = artifactName + pullNo + ".zip"
includeEmptyDirs = true
def resourceDir = 'src/main/resources/'

into('/') {
from "$resourceDir/manifest.yaml"
from "../schemas/cloud-gateway-schema.json"
}

into('bin/') {
from configurations.cloudGatewayServiceJar
from "$resourceDir/bin/start.sh"
from "$resourceDir/bin/validate.sh"
}
}

jar.dependsOn(packageCloudGateway)
build.dependsOn(packageCloudGateway)

artifacts {
zip packageCloudGateway
}

publishing {
publications {
mavenJava(MavenPublication) {
artifact("$buildDir/distributions/$artifactName" + pullNo + ".zip")
}
}
}

jar {
enabled false
}
109 changes: 109 additions & 0 deletions cloud-gateway-package/src/main/resources/bin/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/sh

################################################################################
# This program and the accompanying materials are made available under the terms of the
# Eclipse Public License v2.0 which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-v20.html
#
# SPDX-License-Identifier: EPL-2.0
#
# Copyright IBM Corporation 2021
################################################################################

# Variables required on shell:
# - JAVA_HOME
# - ZWE_STATIC_DEFINITIONS_DIR
# - ZWE_zowe_certificate_keystore_alias - The default alias of the key within the keystore
# - ZWE_zowe_certificate_keystore_file - The default keystore to use for SSL certificates
# - ZWE_zowe_certificate_keystore_password - The default password to access the keystore supplied by KEYSTORE
# - ZWE_zowe_certificate_truststore_file
# - ZWE_zowe_job_prefix
# - ZWE_zowe_logDirectory
# - ZWE_zowe_runtimeDirectory
# - ZWE_zowe_workspaceDirectory

# Optional variables:
# - CMMN_LB
# - LIBPATH
# - LIBRARY_PATH
# - ZWE_components_discovery_port - the port the discovery service will use
# - ZWE_configs_certificate_keystore_alias - The alias of the key within the keystore
# - ZWE_configs_certificate_keystore_file - The keystore to use for SSL certificates
# - ZWE_configs_certificate_keystore_password - The password to access the keystore supplied by KEYSTORE
# - ZWE_configs_certificate_keystore_type - The keystore type to use for SSL certificates
# - ZWE_configs_certificate_truststore_file
# - ZWE_configs_certificate_truststore_type
# - ZWE_configs_debug
# - ZWE_configs_port - the port the api gateway service will use
# - ZWE_configs_server_maxConnectionsPerRoute
# - ZWE_configs_server_maxTotalConnections
# - ZWE_configs_server_ssl_enabled
# - ZWE_configs_spring_profiles_active
# - ZWE_DISCOVERY_SERVICES_LIST

if [ -n "${LAUNCH_COMPONENT}" ]
then
JAR_FILE="${LAUNCH_COMPONENT}/cloud-gateway-service.jar"
else
JAR_FILE="$(pwd)/bin/cloud-gateway-service.jar"
fi
echo "jar file: "${JAR_FILE}
# script assumes it's in the gateway component directory and common_lib needs to be relative path

if [ -z "${LIBRARY_PATH}" ]
then
LIBRARY_PATH="../common-java-lib/bin/"
fi

# API Mediation Layer Debug Mode
export LOG_LEVEL=

if [ "${ZWE_configs_debug}" = "true" ]
then
export LOG_LEVEL="debug"
fi

LIBPATH="$LIBPATH":"/lib"
LIBPATH="$LIBPATH":"/usr/lib"
LIBPATH="$LIBPATH":"${JAVA_HOME}"/bin
LIBPATH="$LIBPATH":"${JAVA_HOME}"/bin/classic
LIBPATH="$LIBPATH":"${JAVA_HOME}"/bin/j9vm
LIBPATH="$LIBPATH":"${JAVA_HOME}"/lib/s390/classic
LIBPATH="$LIBPATH":"${JAVA_HOME}"/lib/s390/default
LIBPATH="$LIBPATH":"${JAVA_HOME}"/lib/s390/j9vm
LIBPATH="$LIBPATH":"${LIBRARY_PATH}"

CLOUD_GATEWAY_CODE=CG
_BPX_JOBNAME=${ZWE_zowe_job_prefix}${CLOUD_GATEWAY_CODE} java \
-Xms32m -Xmx256m \
${QUICK_START} \
-Dibm.serversocket.recover=true \
-Dfile.encoding=UTF-8 \
-Djava.io.tmpdir=/tmp \
-Dspring.profiles.active=${ZWE_configs_spring_profiles_active:-} \
-Dspring.profiles.include=$LOG_LEVEL \
-Dapiml.service.hostname=${ZWE_haInstance_hostname:-localhost} \
-Dapiml.service.port=${ZWE_configs_port:-10023} \
-Dapiml.logs.location=${ZWE_zowe_logDirectory} \
-Dapiml.zoweManifest=${ZWE_zowe_runtimeDirectory}/manifest.json \
-Dserver.address=0.0.0.0 \
-Deureka.client.serviceUrl.defaultZone=${ZWE_DISCOVERY_SERVICES_LIST:-"https://${ZWE_haInstance_hostname:-localhost}:${ZWE_components_discovery_port:-7553}/eureka/"} \
-Dserver.ssl.enabled=${ZWE_configs_server_ssl_enabled:-true} \
-Dserver.maxConnectionsPerRoute=${ZWE_configs_server_maxConnectionsPerRoute:-100} \
-Dserver.maxTotalConnections=${ZWE_configs_server_maxTotalConnections:-1000} \
-Dserver.ssl.keyStore="${ZWE_configs_certificate_keystore_file:-${ZWE_zowe_certificate_keystore_file}}" \
-Dserver.ssl.keyStoreType="${ZWE_configs_certificate_keystore_type:-${ZWE_zowe_certificate_keystore_type:-PKCS12}}" \
-Dserver.ssl.keyStorePassword="${ZWE_configs_certificate_keystore_password:-${ZWE_zowe_certificate_keystore_password}}" \
-Dserver.ssl.keyAlias="${ZWE_configs_certificate_keystore_alias:-${ZWE_zowe_certificate_keystore_alias}}" \
-Dserver.ssl.keyPassword="${ZWE_configs_certificate_keystore_password:-${ZWE_zowe_certificate_keystore_password}}" \
-Dserver.ssl.trustStore="${ZWE_configs_certificate_truststore_file:-${ZWE_zowe_certificate_truststore_file}}" \
-Dserver.ssl.trustStoreType="${ZWE_configs_certificate_truststore_type:-${ZWE_zowe_certificate_truststore_type:-PKCS12}}" \
-Dserver.ssl.trustStorePassword="${ZWE_configs_certificate_truststore_password:-${ZWE_zowe_certificate_truststore_password}}" \
-Djava.protocol.handler.pkgs=com.ibm.crypto.provider \
-Djava.library.path=${LIBPATH} \
-jar ${JAR_FILE} &

pid=$!
echo "pid=${pid}"

wait %1
14 changes: 14 additions & 0 deletions cloud-gateway-package/src/main/resources/bin/validate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

################################################################################
# This program and the accompanying materials are made available under the terms of the
# Eclipse Public License v2.0 which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-v20.html
#
# SPDX-License-Identifier: EPL-2.0
#
# Copyright IBM Corporation 2021
################################################################################

print_formatted_debug "ZWELS" "cloud-gateway-service,bin/validate.sh:${LINENO}" "- Checking Cloud Gateway Service port ${ZWE_configs_port}"
validate_this "is_port_available \"${ZWE_configs_port}\" 2>&1" "cloud-gateway-service,bin/validate.sh:${LINENO}"
28 changes: 28 additions & 0 deletions cloud-gateway-package/src/main/resources/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
name: cloud-gateway
# Component identifier. This identifier matches artifact path in Zowe Artifactory https://zowe.jfrog.io/.
id: org.zowe.apiml.cloud-gateway-package
# Component version is defined in gradle.properties for Gradle project
# Human readable component name
title: Cloud Gateway
# Human readable component description
description: API Gateway service to route requests to services registered in the API Mediation Layer and provides an API for mainframe security.
license: EPL-2.0
schemas:
configs: cloud-gateway-schema.json
repository:
type: git
url: https://github.com/zowe/api-layer.git
commands:
start: bin/start.sh
validate: bin/validate.sh
# if we need to automatically tag file encoding on z/OS during installation
autoEncoding:
# tag all files
- "."
apimlServices:
dynamic:
- serviceId: cloud-gateway
configs:
port: 7563
debug: false
1 change: 1 addition & 0 deletions cloud-gateway-package/src/test/java/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Required by sonarqube
37 changes: 37 additions & 0 deletions cloud-gateway-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
104 changes: 104 additions & 0 deletions cloud-gateway-service/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
buildscript {
repositories mavenRepositories
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:2.7.3")
classpath("gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:${gradleGitPropertiesVersion}")
classpath("org.eclipse.jgit:org.eclipse.jgit") {
version {
strictly '5.13.0.202109080827-r'
}
}
}
}

normalization {
runtimeClasspath {
ignore("**/*git.properties*")
ignore("**/*build-info.properties*")
}
}

apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.gorylenko.gradle-git-properties'
apply plugin: 'com.google.cloud.tools.jib'
apply from: "../gradle/jib.gradle"

def javaAgentPort = 6310
def debugPort = 5130
def componentName = "cloud-gateway-service"

setJib(componentName, javaAgentPort, debugPort)
jib.container.mainClass = 'org.zowe.apiml.cloudgatewayservice.CloudGatewayServiceApplication'

springBoot {
// This statement tells the Gradle Spring Boot plugin to generate a file
// build/resources/main/META-INF/build-info.properties that is picked up by Spring Boot to display
// via /info endpoint
buildInfo {
properties {
// Generate extra build info:
additional = [
by : System.properties['user.name'],
operatingSystem: "${System.properties['os.name']} (${System.properties['os.version']})",
number : System.getenv('BUILD_NUMBER') ? System.getenv('BUILD_NUMBER') : "n/a",
machine : InetAddress.localHost.hostName
]
}
}
}

gitProperties {
gitPropertiesDir = new File("${project.rootDir}/${name}/build/resources/main/META-INF")
}

dependencies {

implementation project(':common-service-core')
implementation 'org.springframework.cloud:spring-cloud-starter-gateway:3.1.3'
implementation 'org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:3.1.3'
implementation 'org.springframework.boot:spring-boot-starter-actuator:2.7.3'

compileOnly libraries.lombok
annotationProcessor libraries.lombok
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor:2.7.3'



testImplementation 'org.springframework.boot:spring-boot-starter-test:2.7.3'
}

bootJar {
archiveFileName = "cloud-gateway-service.jar"
manifest {
attributes 'Main-Class': 'org.springframework.boot.loader.PropertiesLauncher'
}
archiveClassifier = "application"
}

jar {
enabled true
archiveClassifier = ""
}

bootRun {
if (project.hasProperty('args')) {
args project.args.split(',')
}
systemProperties = System.properties
}

publishing {
publications {
mavenJavaFat(MavenPublication) {
groupId = 'org.zowe.apiml'
artifactId = 'cloud-gateway-fat-jar'

artifact bootJar
}
}
}

task wrapper(type: Wrapper){
gradleVersion = '7.2'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*/

package org.zowe.apiml.cloudgatewayservice;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CloudGatewayServiceApplication {

public static void main(String[] args) {
SpringApplication.run(CloudGatewayServiceApplication.class, args);
}

}
Loading

0 comments on commit 7c618c0

Please sign in to comment.