Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions changelog/unreleased/SOLR-17697-picocli-experimental-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ authors:
- name: Jan Høydahl
url: https://home.apache.org/phonebook.html?uid=janhoy
- name: Serhiy Bzhezytskyy
- name: Jalaz Kumar
nick: jaykay12
links:
- name: SOLR-17697
url: https://issues.apache.org/jira/browse/SOLR-17697
Expand All @@ -31,3 +33,5 @@ links:
url: https://issues.apache.org/jira/browse/SOLR-18518
- name: SOLR-18517
url: https://issues.apache.org/jira/browse/SOLR-18517
- name: SOLR-18515
url: https://issues.apache.org/jira/browse/SOLR-18515
81 changes: 81 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/ConnectionOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
package org.apache.solr.cli;

import java.io.IOException;
import java.util.Map;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.common.util.EnvUtils;
import picocli.CommandLine;

/**
Expand Down Expand Up @@ -73,4 +76,82 @@ String effectiveSolrUrl() throws IOException {
}
return solrUrl;
}

static String resolveSolrUrl(ConnectionOptions connectionOptions, String credentials)
throws Exception {
if (connectionOptions != null) {
String solrUrl = connectionOptions.effectiveSolrUrl();
if (solrUrl != null) {
return CLIUtils.normalizeSolrUrl(solrUrl);
}
String zkHost = connectionOptions.effectiveZkHost();
if (zkHost != null) {
return CLIUtils.solrUrlFromConnection(
CloudSolrClient.CloudSolrClientConnection.parse(zkHost), credentials);
}
}

String solrConnectionProp = EnvUtils.getProperty("solr.connection");
if (solrConnectionProp != null && !solrConnectionProp.isBlank()) {
var connection = CloudSolrClient.CloudSolrClientConnection.parse(solrConnectionProp);
if (connection.isZookeeper()) {
return CLIUtils.solrUrlFromConnection(connection, credentials);
}
return CLIUtils.normalizeSolrUrl(connection.quorumItems().get(0));
}

String zkHostProp = EnvUtils.getProperty("zkHost");
if (zkHostProp != null && !zkHostProp.isBlank()) {
return CLIUtils.solrUrlFromConnection(
CloudSolrClient.CloudSolrClientConnection.parse(zkHostProp), credentials);
}

String defaultUrl = CLIUtils.getDefaultSolrUrl();
CLIO.err(
"Neither --solr-connection, --zk-host or --solr-url parameters, nor SOLR_CONNECTION, ZK_HOST env var provided, so assuming solr url is "
+ defaultUrl
+ ".");
return defaultUrl;
}

static String resolveZkHost(
ConnectionOptions connectionOptions, String solrUrl, String credentials) throws Exception {
boolean resolveFromSolrUrl = false;
if (connectionOptions != null) {
String zkHost = connectionOptions.effectiveZkHost();
if (zkHost != null) {
return zkHost;
}
resolveFromSolrUrl = connectionOptions.effectiveSolrUrl() != null;
}

if (!resolveFromSolrUrl) {
String solrConnectionProp = EnvUtils.getProperty("solr.connection");
if (solrConnectionProp != null && !solrConnectionProp.isBlank()) {
var connection = CloudSolrClient.CloudSolrClientConnection.parse(solrConnectionProp);
if (connection.isZookeeper()) {
return solrConnectionProp;
}
}

String zkHostProp = EnvUtils.getProperty("zkHost");
if (zkHostProp != null && !zkHostProp.isBlank()) {
return zkHostProp;
}
}

try (SolrClient solrClient = CLIUtils.getSolrClient(solrUrl, credentials)) {
Map<String, Object> status = StatusTool.reportStatus(solrClient);
@SuppressWarnings("unchecked")
Map<String, Object> cloud = (Map<String, Object>) status.get("cloud");
if (cloud != null) {
String zookeeper = cloud.get("ZooKeeper").toString();
if (zookeeper != null && zookeeper.endsWith("(embedded)")) {
zookeeper = zookeeper.substring(0, zookeeper.length() - "(embedded)".length());
}
return zookeeper;
}
}
return null;
}
}
56 changes: 56 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/PackageAddKey.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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.
*/

package org.apache.solr.cli;

import java.nio.file.Path;

/** Supports package add-key command in the bin/solr script. */
@SuppressWarnings("UnnecessarilyFullyQualified")
@picocli.CommandLine.Command(
name = "add-key",
description = "Add a trusted key to Solr.",
exitCodeListHeading = "%nExit Codes:%n",
exitCodeList = {
"0: Operation completed successfully.",
"1: Operation failed; check output for details."
},
footerHeading = "%nExamples:%n",
footer = {
" # Add a trusted public key",
" bin/solr package add-key /path/to/public.key.der",
})
public class PackageAddKey extends PackageSubCommand {

@picocli.CommandLine.Parameters(
index = "0",
arity = "1",
paramLabel = "KEY-FILE",
description = "Path to a file containing the trusted key.")
private Path keyFile;

@Override
public int callTool() throws Exception {
return runWithManagers(
((packageManager, repositoryManager) -> packageTool.addKey(repositoryManager, keyFile)));
}

@Override
public String getName() {
return "add-key";
}
}
62 changes: 62 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/PackageAddRepo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.
*/

package org.apache.solr.cli;

/** Supports package add-repo command in the bin/solr script. */
@SuppressWarnings("UnnecessarilyFullyQualified")
@picocli.CommandLine.Command(
name = "add-repo",
description = "Add a package repository to Solr.",
exitCodeListHeading = "%nExit Codes:%n",
exitCodeList = {
"0: Operation completed successfully.",
"1: Operation failed; check output for details."
},
footerHeading = "%nExamples:%n",
footer = {
" # Add a package repository",
" bin/solr package add-repo myrepo https://my.repo.example/repo",
})
public class PackageAddRepo extends PackageSubCommand {

@picocli.CommandLine.Parameters(
index = "0",
arity = "1",
paramLabel = "REPOSITORY-NAME",
description = "Name of the package repository.")
private String repoName;

@picocli.CommandLine.Parameters(
index = "1",
arity = "1",
paramLabel = "REPOSITORY-URL",
description = "URL of the package repository.")
private String repoUrl;

@Override
public int callTool() throws Exception {
return runWithManagers(
((packageManager, repositoryManager) ->
packageTool.addRepo(repositoryManager, repoName, repoUrl)));
}

@Override
public String getName() {
return "add-repo";
}
}
100 changes: 100 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/PackageDeploy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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.
*/

package org.apache.solr.cli;

import static org.apache.solr.cli.SolrCLI.printRed;

/** Supports package deploy command in the bin/solr script. */
@SuppressWarnings("UnnecessarilyFullyQualified")
@picocli.CommandLine.Command(
name = "deploy",
description = "Deploy an installed package to collections or at cluster level.",
exitCodeListHeading = "%nExit Codes:%n",
exitCodeList = {
"0: Operation completed successfully.",
"1: Operation failed; check output for details."
},
footerHeading = "%nExamples:%n",
footer = {
" # Deploy a package to a collection",
" bin/solr package deploy mypkg:1.0.0 --collections myCollection -y",
"",
" # Update an existing deployment",
" bin/solr package deploy mypkg --update --collections myCollection -y"
})
public class PackageDeploy extends PackageSubCommand {

@picocli.CommandLine.Parameters(
index = "0",
arity = "1",
paramLabel = "PACKAGE[:VERSION]",
description = "Package name, optionally with :version.")
private String packageNameAndVersion;

@picocli.CommandLine.Option(
names = {"--cluster"},
description = "Specifies that this action should affect cluster-level plugins only.")
private boolean cluster;

@picocli.CommandLine.Option(
names = {"--collections"},
paramLabel = "COLLECTIONS",
description =
"Specifies that this action should affect plugins for the given collections only, excluding cluster level plugins.")
private String collections;

@picocli.CommandLine.Option(
names = {"-p", "--param"},
paramLabel = "PARAMS",
description = "List of parameters to be used with deploy command.")
private String[] params;

@picocli.CommandLine.Option(
names = {"--update"},
description = "If a deployment is an update over a previous deployment.")
private boolean update;

@picocli.CommandLine.Option(
names = {"-y", "--no-prompt"},
description = "Don't prompt for input; accept all default choices, defaults to false.")
private boolean noPrompt;

@Override
public int callTool() throws Exception {
if (!cluster && collections == null) {
printRed(
"Either specify --cluster to deploy cluster level plugins or --collections <list-of-collections> to deploy collection level plugins");
return 1;
}
return runWithManagers(
(packageManager, repositoryManager) ->
packageTool.deploy(
packageManager,
packageNameAndVersion,
cluster,
collections,
params,
update,
noPrompt));
}

@Override
public String getName() {
return "deploy";
}
}
60 changes: 60 additions & 0 deletions solr/core/src/java/org/apache/solr/cli/PackageInstall.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.
*/

package org.apache.solr.cli;

/** Supports package install command in the bin/solr script. */
@SuppressWarnings("UnnecessarilyFullyQualified")
@picocli.CommandLine.Command(
name = "install",
description = "Install a package into Solr.",
exitCodeListHeading = "%nExit Codes:%n",
exitCodeList = {
"0: Operation completed successfully.",
"1: Operation failed; check output for details."
},
footerHeading = "%nExamples:%n",
footer = {
" # Install a specific package version",
" bin/solr package install mypkg:1.0.0",
"",
" # Install the latest available version",
" bin/solr package install mypkg"
})
public class PackageInstall extends PackageSubCommand {

@picocli.CommandLine.Parameters(
index = "0",
arity = "1",
paramLabel = "PACKAGE[:VERSION]",
description = "Package name, optionally with :version.")
private String packageNameAndVersion;

@Override
public int callTool() throws Exception {
final boolean[] status = {true};
runWithManagers(
(packageManager, repositoryManager) ->
status[0] = packageTool.install(repositoryManager, packageNameAndVersion));
return status[0] ? 0 : 1;
}

@Override
public String getName() {
return "install";
}
}
Loading
Loading