Skip to content

Commit a085cf3

Browse files
taban03achmelo
andauthored
feat: Create API ML sample extension (#1947)
* Create and package sample extension Signed-off-by: at670475 <andrea.tabone@broadcom.com> * ADD the path to the jar Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Fix gradle creation of jar Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Add doc Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Remove jib Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Clean up dependencies Signed-off-by: at670475 <andrea.tabone@broadcom.com> * skip sonar scan Signed-off-by: at670475 <andrea.tabone@broadcom.com> * package controller and dependencies Signed-off-by: achmelo <a.chmelo@gmail.com> * Create and package sample extension Signed-off-by: at670475 <andrea.tabone@broadcom.com> * ADD the path to the jar Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Fix gradle creation of jar Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Add doc Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Remove jib Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Clean up dependencies Signed-off-by: at670475 <andrea.tabone@broadcom.com> * skip sonar scan Signed-off-by: at670475 <andrea.tabone@broadcom.com> * package controller and dependencies Signed-off-by: achmelo <a.chmelo@gmail.com> * Address requests Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Update doc Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Replace back icon to use material Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Revert change Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Fix action Signed-off-by: at670475 <andrea.tabone@broadcom.com> * attempt Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Attempt 2 Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Attempt 3 Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Fix PR name Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Fix extension path Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Fix extension path Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Fix extension path Signed-off-by: at670475 <andrea.tabone@broadcom.com> * Change extension package to be included in the component scan Signed-off-by: at670475 <andrea.tabone@broadcom.com> * debug loader path Signed-off-by: achmelo <a.chmelo@gmail.com> * remove debug logs Signed-off-by: achmelo <a.chmelo@gmail.com> Co-authored-by: achmelo <a.chmelo@gmail.com>
1 parent dc26114 commit a085cf3

File tree

11 files changed

+197
-10
lines changed

11 files changed

+197
-10
lines changed

.github/workflows/pull-request-snapshot-release.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
name: Release new version for specific pull request (snapshot)
44

55
on:
6-
workflow_dispatch:
7-
inputs:
8-
pull_request:
9-
description: 'The pull request snapshot that is going to be released (i.e PR-XXXX)'
10-
required: true
6+
pull_request:
7+
branches: [ master, v2.x.x ]
8+
9+
env:
10+
PR_NUMBER: ${{ github.event.number }}
1111

1212
jobs:
1313
build:
@@ -48,7 +48,7 @@ jobs:
4848

4949
- name: Release with Gradle
5050
run: |
51-
BRANCH_NAME=${{ github.event.inputs.pull_request }}
51+
BRANCH_NAME=PR-${{ env.PR_NUMBER }}
5252
sed -i '/version=/ s/-SNAPSHOT/-'"$BRANCH_NAME"'-SNAPSHOT/' ./gradle.properties
5353
./gradlew build publishAllVersions -Pzowe.deploy.username=$ARTIFACTORY_USERNAME -Pzowe.deploy.password=$ARTIFACTORY_PASSWORD -Partifactory_user=$ARTIFACTORY_USERNAME -Partifactory_password=$ARTIFACTORY_USERNAME -PpullRequest=$BRANCH_NAME
5454
env:
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*/
10+
11+
ext {
12+
artifactName = 'apiml-sample-extension-package'
13+
pullNo = project.hasProperty("pullRequest") && project.getProperty("pullRequest") != null ? "-" + project.getProperty("pullRequest") : ""
14+
}
15+
16+
configurations {
17+
sampleExtensionJar
18+
zip
19+
}
20+
21+
dependencies {
22+
sampleExtensionJar(project(path: ":apiml-sample-extension"))
23+
}
24+
25+
task packageSampleExtension(type: Zip) {
26+
archiveName = artifactName + pullNo + ".zip"
27+
includeEmptyDirs = true
28+
def resourceDir = 'src/main/resources/'
29+
30+
into('/') {
31+
from "$resourceDir/manifest.yaml"
32+
}
33+
34+
into('bin/') {
35+
from configurations.sampleExtensionJar
36+
}
37+
}
38+
39+
jar.dependsOn(packageSampleExtension)
40+
build.dependsOn(packageSampleExtension)
41+
42+
artifacts {
43+
zip packageSampleExtension
44+
}
45+
46+
publishing {
47+
publications {
48+
mavenJava(MavenPublication) {
49+
artifact("$buildDir/distributions/$artifactName" + pullNo + ".zip")
50+
}
51+
}
52+
}
53+
54+
jar {
55+
enabled false
56+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: apiml-sample-extension
3+
# Component identifier. This identifier matches artifact path in Zowe Artifactory https://zowe.jfrog.io/.
4+
id: org.zowe.apiml.sdk.apiml-sample-extension-package
5+
# Component version is defined in gradle.properties for Gradle project
6+
# Human readable component name
7+
title: A sample extension for API ML
8+
# Human readable component description
9+
description: JAR that contains a simple controller.
10+
license: EPL-2.0
11+
repository:
12+
type: git
13+
url: https://github.com/zowe/api-layer.git
14+
build:
15+
branch: "{{build.branch}}"
16+
number: "{{build.number}}"
17+
commitHash: "{{build.commitHash}}"
18+
timestamp: "{{build.timestamp}}"
19+
# The following block contains all the extensions directory path
20+
# (or file path) that will be included in the API ML
21+
gatewaySharedLibs:
22+
- bin/apiml-sample-extension.jar
23+

apiml-sample-extension/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# API ML sample extension
2+
3+
This is an API ML sample extension. It only contains a simple controller for testing.
4+
The extension is added to the API Gateway class path. Therefore, as a result, the controller is added in the context
5+
of the API Gateway without starting a new service.
6+
7+
## Usage
8+
9+
If the extension is correctly added to the API Gateway classpath, it will be possible to
10+
call the REST endpoint defined in the controller via Gateway.
11+
The extension is scanned and added to the classpath during the Zowe instance preparation, therefore
12+
once the Gateway is started, you can:
13+
14+
1. Call the `https://<hostname>:<gatewayPort>/api/v1/greeting` endpoint though Gateway
15+
2. Verify that you get the message `Hello, I'm a sample extension!` as response

apiml-sample-extension/build.gradle

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
buildscript {
2+
repositories mavenRepositories
3+
dependencies {
4+
classpath("gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:${gradleGitPropertiesVersion}")
5+
classpath ("org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r") {
6+
force = true
7+
}
8+
}
9+
}
10+
11+
normalization {
12+
runtimeClasspath {
13+
ignore("**/*git.properties*")
14+
ignore("**/*build-info.properties*")
15+
}
16+
}
17+
18+
apply plugin: 'com.gorylenko.gradle-git-properties'
19+
20+
gitProperties {
21+
gitPropertiesDir = new File("${project.rootDir}/${name}/build/resources/main/META-INF")
22+
}
23+
24+
dependencies {
25+
26+
implementation libraries.springFox
27+
implementation libraries.spring_webmvc
28+
29+
}
30+
31+
jar {
32+
enabled true
33+
baseName = "apiml-sample-extension"
34+
archiveName = "${baseName}.jar"
35+
}
36+
37+
publishing {
38+
publications {
39+
mavenJavaLib(MavenPublication) {
40+
artifact jar
41+
}
42+
}
43+
}
44+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* This program and the accompanying materials are made available under the terms of the
3+
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
4+
* https://www.eclipse.org/legal/epl-v20.html
5+
*
6+
* SPDX-License-Identifier: EPL-2.0
7+
*
8+
* Copyright Contributors to the Zowe Project.
9+
*/
10+
package org.zowe.apiml.gateway.api;
11+
12+
import io.swagger.annotations.Api;
13+
import org.springframework.web.bind.annotation.*;
14+
15+
/**
16+
* Controller that returns greetings.
17+
*/
18+
@RestController
19+
@Api(tags = {"Other Operations"})
20+
@RequestMapping("/api/v1")
21+
public class GreetingController {
22+
private static final String GREETING = "Hello, I'm a sample extension!";
23+
24+
/**
25+
* Gets a greeting for anyone.
26+
*/
27+
@GetMapping(value = "/greeting")
28+
public String greeting() {
29+
return GREETING;
30+
}
31+
}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ subprojects {
106106
}
107107

108108
task buildCore(dependsOn: [':gateway-service:build', ':discovery-service:build', ':api-catalog-services:build', ':api-catalog-ui:build',
109-
':discoverable-client:build', ':zaas-client:build']) {
109+
':discoverable-client:build', ':zaas-client:build', ':apiml-sample-extension:build']) {
110110
description "Build core components"
111111
group "build"
112112
}

gradle/license.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ ext.projectsNeedLicense = [
2929
'onboarding-enabler-nodejs',
3030
'zaas-client',
3131
'mock-services',
32-
'apiml-tomcat-common'
32+
'apiml-tomcat-common',
33+
'apiml-sample-extension'
3334
]
3435

3536
configure(subprojects.findAll { it.name in projectsNeedLicense }) {

gradle/publish.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ ext.javaLibraries = [
1616
'zaas-client',
1717
'discoverable-client',
1818
'certificate-analyser',
19-
'apiml-tomcat-common'
19+
'apiml-tomcat-common',
20+
'apiml-sample-extension'
2021
]
2122

22-
ext.serviceJars = ['api-catalog-package', 'discovery-package', 'gateway-package', 'caching-service-package', 'metrics-service-package', 'apiml-common-lib-package']
23+
ext.serviceJars = ['api-catalog-package', 'discovery-package', 'gateway-package', 'caching-service-package', 'metrics-service-package', 'apiml-common-lib-package', 'apiml-sample-extension-package']
2324

2425
ext.enablers = [ext.javaEnabler, ext.springBootEnabler, ext.micronautEnabler]
2526
ext.projectsToPublish = ext.serviceJars + ext.javaLibraries + ext.enablers

gradle/sonar.gradle

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,20 @@ project(":apiml-common-lib-package") {
126126
}
127127
}
128128

129+
// Packaging project; sonar does not apply
130+
project(":apiml-sample-extension-package") {
131+
sonarqube {
132+
skipProject = true
133+
}
134+
}
135+
136+
// Packaging project; sonar does not apply
137+
project(":apiml-sample-extension") {
138+
sonarqube {
139+
skipProject = true
140+
}
141+
}
142+
129143
// Packaging project; sonar does not apply
130144
project(":mock-services") {
131145
sonarqube {

0 commit comments

Comments
 (0)