Skip to content

Commit

Permalink
SOLR-17062: Create JS client for Admin UI use (#2050)
Browse files Browse the repository at this point in the history
This commit adds build code to generate a JS client (using the
OpenAPI Generator's 'javascript' template) and adds the necessary
plumbing to bundle the client into our Admin UI.  See 'CollectionsV2' in
services.js as an example.

Note that nothing in this commit adds this JS client as a release
artifact, publishes it to npm, etc.

---------

Co-authored-by: Houston Putman <[email protected]>
  • Loading branch information
gerlowskija and HoustonPutman committed Dec 5, 2023
1 parent 571bf71 commit 66333ae
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gradle/node.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

configure([project(":solr:packaging"), project(":solr:solr-ref-guide")]) {
configure([project(":solr:packaging"), project(":solr:solr-ref-guide"), project(":solr:webapp")]) {
apply plugin: "com.github.node-gradle.node"

ext {
Expand Down
27 changes: 27 additions & 0 deletions solr/api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

plugins {
id 'io.swagger.core.v3.swagger-gradle-plugin' version '2.2.2'
id "org.openapi.generator" version "6.0.1"
}

apply plugin: 'java-library'

description = 'API - Interfaces and classes used to represent Solrs APIs'

ext {
jsClientDir = "${buildDir}/generated/js"
openApiSpecDir = "${buildDir}/generated/openapi"
openApiSpecFile = "${project.openApiSpecDir}/openapi.json"
}
Expand All @@ -33,6 +35,10 @@ configurations {
canBeConsumed = true
canBeResolved = false
}
jsClient {
canBeConsumed = true
canBeResolved = false
}
}

resolve {
Expand All @@ -55,8 +61,29 @@ dependencies {
testImplementation 'org.apache.lucene:lucene-test-framework'
}

// Non-Java client generation tasks below:

task buildJSClient(type: org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
generatorName.set("javascript")
inputSpec.set("$openApiSpecFile")
outputDir.set("$jsClientDir")
packageName.set("solr")
generateApiTests.set(false)
generateModelTests.set(false)
}

tasks.withType(org.openapitools.generator.gradle.plugin.tasks.GenerateTask) {
dependsOn(resolve)
}

artifacts {
// Ensure the OAS is available to other modules who want to generate code (i.e. solrj)
openapiSpec resolve.outputDir, {
builtBy resolve
}

// Makes our Javascript client available to the Admin UI build
jsClient file(project.jsClientDir), {
builtBy buildJSClient
}
}
83 changes: 83 additions & 0 deletions solr/webapp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ configurations {
war {}
serverLib
solrCore
generatedJSClient
generatedJSClientBundle
}

ext {
jsClientWorkspace = layout.buildDirectory.dir("jsClientWorkspace").get()
jsClientBundleDir = layout.buildDirectory.dir("jsClientBundle").get()
browserifyVersion = "17.0.0"
}

dependencies {
Expand All @@ -34,6 +42,77 @@ dependencies {
serverLib project(path: ":solr:server", configuration: "serverLib")
solrCore project(":solr:core")
implementation(configurations.solrCore - configurations.serverLib)

generatedJSClient project(path: ":solr:api", configuration: "jsClient")
generatedJSClientBundle files(jsClientBundleDir) {
builtBy "generateJsClientBundle"
}
}

task syncJSClientSourceCode(type: Sync) {
group = 'Solr JS Client'
from configurations.generatedJSClient

into project.jsClientWorkspace
}

task jsClientDownloadDeps(type: NpmTask) {
group = 'Solr JS Client'
dependsOn tasks.syncJSClientSourceCode

args = ["install"]
workingDir = file(project.jsClientWorkspace)

inputs.dir("${jsClientWorkspace}/src")
inputs.file("${jsClientWorkspace}/package.json")
outputs.dir("${jsClientWorkspace}/node_modules")
}

task jsClientBuild(type: NpmTask) {
group = 'Solr JS Client'
dependsOn tasks.jsClientDownloadDeps

args = ["run", "build"]
workingDir = file(project.jsClientWorkspace)

inputs.dir("${jsClientWorkspace}/src")
inputs.file("${jsClientWorkspace}/package.json")
inputs.dir("${jsClientWorkspace}/node_modules")
outputs.dir("${jsClientWorkspace}/dist")
}

task downloadBrowserify(type: NpmTask) {
group = 'Build Dependency Download'
args = ["install", "browserify@${project.browserifyVersion}"]

inputs.property("browserify version", project.browserifyVersion)
outputs.dir("${project.nodeProjectDir}/node_modules/browserify")
}

task setupJsBundleDir(type: Sync) {
group = 'Solr JS Client'
dependsOn tasks.syncJSClientSourceCode

from configurations.generatedJSClient

include "README.md"
include "docs/**"

into project.jsClientBundleDir
}

task generateJsClientBundle(type: NpxTask) {
group = 'Solr JS Client'
dependsOn tasks.downloadBrowserify
dependsOn tasks.jsClientBuild
dependsOn tasks.setupJsBundleDir

command = 'browserify'
args = ['dist/index.js', '-s', 'solrApi', '-o', "${jsClientBundleDir}/index.js"]
workingDir = file(project.jsClientWorkspace)


outputs.dir("${jsClientBundleDir}")
}

war {
Expand All @@ -44,6 +123,10 @@ war {
exclude "libs/angular-utf8-base.js"
exclude "libs/angular.js"
exclude "libs/chosen.jquery.js"

from (configurations.generatedJSClientBundle, {
into "libs/solr"
})
}

// Expose 'war' archive as an artifact so that it can be packaged in the distribution.
Expand Down
1 change: 1 addition & 0 deletions solr/webapp/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<script src="libs/highlight.js?_=${version}"></script>
<script src="libs/d3.js?_=${version}"></script>
<script src="libs/ui-grid.min.js?_=${version}"></script>
<script src="libs/solr/index.js"></script>
<script src="libs/jquery-ui.min.js?_=${version}"></script>
<script src="libs/angular-utf8-base64.min.js?_=${version}"></script>
<script src="libs/jssha-3.3.1-sha256.min.js?_=${version}"></script>
Expand Down
22 changes: 11 additions & 11 deletions solr/webapp/web/js/angular/controllers/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

solrAdminApp.controller('CollectionsController',
function($scope, $routeParams, $location, $timeout, Collections, Zookeeper, Constants, ConfigSets){
function($scope, $routeParams, $location, $timeout, Collections, CollectionsV2, Zookeeper, Constants, ConfigSets){
$scope.resetMenu("collections", Constants.IS_ROOT_PAGE);

$scope.refresh = function() {
Expand Down Expand Up @@ -215,16 +215,16 @@ solrAdminApp.controller('CollectionsController',
alert("No collection selected.");
return;
}
Collections.reload({name: $scope.collection.name},
function(successData) {
$scope.reloadSuccess = true;
$timeout(function() {$scope.reloadSuccess=false}, 1000);
},
function(failureData) {
$scope.reloadFailure = true;
$timeout(function() {$scope.reloadFailure=false}, 1000);
$location.path("/~collections");
});
CollectionsV2.reloadCollection($scope.collection.name, function(error, data,response) {
if (error) {
$scope.reloadFailure = true;
$timeout(function() {$scope.reloadFailure=false}, 1000);
$location.path("/~collections");
} else {
$scope.reloadSuccess = true;
$timeout(function() {$scope.reloadSuccess=false}, 1000);
}
});
};

$scope.toggleAddReplica = function(shard) {
Expand Down
6 changes: 6 additions & 0 deletions solr/webapp/web/js/angular/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ solrAdminServices.factory('System',
['$resource', function($resource) {
return $resource('admin/metrics', {"wt":"json", "nodes": "@nodes", "prefix":"@prefix", "_":Date.now()});
}])
.factory('CollectionsV2',
function() {
solrApi.ApiClient.instance.basePath = '/api';
delete solrApi.ApiClient.instance.defaultHeaders["User-Agent"];
return new solrApi.CollectionsApi();
})
.factory('Collections',
['$resource', function($resource) {
return $resource('admin/collections',
Expand Down

0 comments on commit 66333ae

Please sign in to comment.