Skip to content

Commit

Permalink
feat: Create API ML sample extension (#1947)
Browse files Browse the repository at this point in the history
* Create and package sample extension

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

* ADD the path to the jar

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

* Fix gradle creation of jar

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

* Add doc

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

* Remove jib

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

* Clean up dependencies

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

* skip sonar scan

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

* package controller and dependencies

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

* Create and package sample extension

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

* ADD the path to the jar

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

* Fix gradle creation of jar

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

* Add doc

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

* Remove jib

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

* Clean up dependencies

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

* skip sonar scan

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

* package controller and dependencies

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

* Address requests

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

* Update doc

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

* Replace back icon to use material

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

* Revert change

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

* Fix action

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

* attempt

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

* Attempt 2

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

* Attempt 3

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

* Fix PR name

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

* Fix extension path

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

* Fix extension path

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

* Fix extension path

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

* Change extension package to be included in the component scan

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

* debug loader path

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

* remove debug logs

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

Co-authored-by: achmelo <[email protected]>
  • Loading branch information
taban03 and achmelo authored Jan 5, 2022
1 parent dc26114 commit a085cf3
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 10 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/pull-request-snapshot-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
name: Release new version for specific pull request (snapshot)

on:
workflow_dispatch:
inputs:
pull_request:
description: 'The pull request snapshot that is going to be released (i.e PR-XXXX)'
required: true
pull_request:
branches: [ master, v2.x.x ]

env:
PR_NUMBER: ${{ github.event.number }}

jobs:
build:
Expand Down Expand Up @@ -48,7 +48,7 @@ jobs:

- name: Release with Gradle
run: |
BRANCH_NAME=${{ github.event.inputs.pull_request }}
BRANCH_NAME=PR-${{ env.PR_NUMBER }}
sed -i '/version=/ s/-SNAPSHOT/-'"$BRANCH_NAME"'-SNAPSHOT/' ./gradle.properties
./gradlew build publishAllVersions -Pzowe.deploy.username=$ARTIFACTORY_USERNAME -Pzowe.deploy.password=$ARTIFACTORY_PASSWORD -Partifactory_user=$ARTIFACTORY_USERNAME -Partifactory_password=$ARTIFACTORY_USERNAME -PpullRequest=$BRANCH_NAME
env:
Expand Down
56 changes: 56 additions & 0 deletions apiml-sample-extension-package/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.
*/

ext {
artifactName = 'apiml-sample-extension-package'
pullNo = project.hasProperty("pullRequest") && project.getProperty("pullRequest") != null ? "-" + project.getProperty("pullRequest") : ""
}

configurations {
sampleExtensionJar
zip
}

dependencies {
sampleExtensionJar(project(path: ":apiml-sample-extension"))
}

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

into('/') {
from "$resourceDir/manifest.yaml"
}

into('bin/') {
from configurations.sampleExtensionJar
}
}

jar.dependsOn(packageSampleExtension)
build.dependsOn(packageSampleExtension)

artifacts {
zip packageSampleExtension
}

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

jar {
enabled false
}
23 changes: 23 additions & 0 deletions apiml-sample-extension-package/src/main/resources/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
name: apiml-sample-extension
# Component identifier. This identifier matches artifact path in Zowe Artifactory https://zowe.jfrog.io/.
id: org.zowe.apiml.sdk.apiml-sample-extension-package
# Component version is defined in gradle.properties for Gradle project
# Human readable component name
title: A sample extension for API ML
# Human readable component description
description: JAR that contains a simple controller.
license: EPL-2.0
repository:
type: git
url: https://github.com/zowe/api-layer.git
build:
branch: "{{build.branch}}"
number: "{{build.number}}"
commitHash: "{{build.commitHash}}"
timestamp: "{{build.timestamp}}"
# The following block contains all the extensions directory path
# (or file path) that will be included in the API ML
gatewaySharedLibs:
- bin/apiml-sample-extension.jar

15 changes: 15 additions & 0 deletions apiml-sample-extension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# API ML sample extension

This is an API ML sample extension. It only contains a simple controller for testing.
The extension is added to the API Gateway class path. Therefore, as a result, the controller is added in the context
of the API Gateway without starting a new service.

## Usage

If the extension is correctly added to the API Gateway classpath, it will be possible to
call the REST endpoint defined in the controller via Gateway.
The extension is scanned and added to the classpath during the Zowe instance preparation, therefore
once the Gateway is started, you can:

1. Call the `https://<hostname>:<gatewayPort>/api/v1/greeting` endpoint though Gateway
2. Verify that you get the message `Hello, I'm a sample extension!` as response
44 changes: 44 additions & 0 deletions apiml-sample-extension/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
buildscript {
repositories mavenRepositories
dependencies {
classpath("gradle.plugin.com.gorylenko.gradle-git-properties:gradle-git-properties:${gradleGitPropertiesVersion}")
classpath ("org.eclipse.jgit:org.eclipse.jgit:5.13.0.202109080827-r") {
force = true
}
}
}

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

apply plugin: 'com.gorylenko.gradle-git-properties'

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

dependencies {

implementation libraries.springFox
implementation libraries.spring_webmvc

}

jar {
enabled true
baseName = "apiml-sample-extension"
archiveName = "${baseName}.jar"
}

publishing {
publications {
mavenJavaLib(MavenPublication) {
artifact jar
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.gateway.api;

import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.*;

/**
* Controller that returns greetings.
*/
@RestController
@Api(tags = {"Other Operations"})
@RequestMapping("/api/v1")
public class GreetingController {
private static final String GREETING = "Hello, I'm a sample extension!";

/**
* Gets a greeting for anyone.
*/
@GetMapping(value = "/greeting")
public String greeting() {
return GREETING;
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,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']) {
':discoverable-client:build', ':zaas-client:build', ':apiml-sample-extension:build']) {
description "Build core components"
group "build"
}
Expand Down
3 changes: 2 additions & 1 deletion gradle/license.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ ext.projectsNeedLicense = [
'onboarding-enabler-nodejs',
'zaas-client',
'mock-services',
'apiml-tomcat-common'
'apiml-tomcat-common',
'apiml-sample-extension'
]

configure(subprojects.findAll { it.name in projectsNeedLicense }) {
Expand Down
5 changes: 3 additions & 2 deletions gradle/publish.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ ext.javaLibraries = [
'zaas-client',
'discoverable-client',
'certificate-analyser',
'apiml-tomcat-common'
'apiml-tomcat-common',
'apiml-sample-extension'
]

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

ext.enablers = [ext.javaEnabler, ext.springBootEnabler, ext.micronautEnabler]
ext.projectsToPublish = ext.serviceJars + ext.javaLibraries + ext.enablers
Expand Down
14 changes: 14 additions & 0 deletions gradle/sonar.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,20 @@ project(":apiml-common-lib-package") {
}
}

// Packaging project; sonar does not apply
project(":apiml-sample-extension-package") {
sonarqube {
skipProject = true
}
}

// Packaging project; sonar does not apply
project(":apiml-sample-extension") {
sonarqube {
skipProject = true
}
}

// Packaging project; sonar does not apply
project(":mock-services") {
sonarqube {
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,6 @@ include 'metrics-service-ui'
include 'metrics-service-package'
include 'apiml-tomcat-common'
include 'onboarding-enabler-java-sample-app-plain-java'
include 'apiml-sample-extension'
include 'apiml-sample-extension-package'

0 comments on commit a085cf3

Please sign in to comment.