Skip to content
Permalink
Browse files
AMBARI-23945. Add new --delete-znode command for solrCloudClient.sh
  • Loading branch information
oleewere committed May 27, 2018
1 parent 882927f commit de5b0ad2d155be675ab0c8dd2dbd63efcd5911e1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
@@ -54,6 +54,7 @@ public class AmbariSolrCloudCLI {
private static final String SECURITY_JSON_LOCATION = "security-json-location";
private static final String REMOVE_ADMIN_HANDLERS = "remove-admin-handlers";
private static final String TRANSFER_ZNODE_COMMAND = "transfer-znode";
private static final String DELETE_ZNODE_COMMAND = "delete-znode";
private static final String CMD_LINE_SYNTAX =
"\n./solrCloudCli.sh --create-collection -z host1:2181,host2:2181/ambari-solr -c collection -cs conf_set"
+ "\n./solrCloudCli.sh --upload-config -z host1:2181,host2:2181/ambari-solr -d /tmp/myconfig_dir -cs config_set"
@@ -63,6 +64,7 @@ public class AmbariSolrCloudCLI {
+ "\n./solrCloudCli.sh --remove-admin-handlers -z host1:2181,host2:2181/ambari-solr -c collection"
+ "\n./solrCloudCli.sh --create-znode -z host1:2181,host2:2181 -zn /ambari-solr"
+ "\n./solrCloudCli.sh --check-znode -z host1:2181,host2:2181 -zn /ambari-solr"
+ "\n./solrCloudCli.sh --delete-znode -z host1:2181,host2:2181 -zn /ambari-solr"
+ "\n./solrCloudCli.sh --transfer-znode -z host1:2181,host2:2181 -cps /ambari-solr -cpd /ambari-solr-backup"
+ "\n./solrCloudCli.sh --cluster-prop -z host1:2181,host2:2181/ambari-solr -cpn urlScheme -cpn http"
+ "\n./solrCloudCli.sh --secure-znode -z host1:2181,host2:2181 -zn /ambari-solr -su logsearch,atlas,ranger --jaas-file /etc/myconf/jaas_file"
@@ -151,6 +153,11 @@ public static void main(String[] args) {
.desc("Transfer znode (copy from/to local or to another znode)")
.build();

final Option deleteZnodeOption = Option.builder("dz")
.longOpt(DELETE_ZNODE_COMMAND)
.desc("Delete znode")
.build();

final Option shardNameOption = Option.builder("sn")
.longOpt("shard-name")
.desc("Name of the shard for create-shard command")
@@ -396,6 +403,7 @@ public static void main(String[] args) {
options.addOption(copyDestOption);
options.addOption(saslUsersOption);
options.addOption(checkZnodeOption);
options.addOption(deleteZnodeOption);
options.addOption(setupKerberosPluginOption);
options.addOption(securityJsonLocationOption);

@@ -452,10 +460,13 @@ public static void main(String[] args) {
} else if (cli.hasOption("tz")) {
command = TRANSFER_ZNODE_COMMAND;
validateRequiredOptions(cli, command, zkConnectStringOption, copyScrOption, copyDestOption);
}else {
} else if (cli.hasOption("dz")) {
command = DELETE_ZNODE_COMMAND;
validateRequiredOptions(cli, command, zkConnectStringOption, znodeOption);
} else {
List<String> commands = Arrays.asList(CREATE_COLLECTION_COMMAND, CREATE_SHARD_COMMAND, UPLOAD_CONFIG_COMMAND,
DOWNLOAD_CONFIG_COMMAND, CONFIG_CHECK_COMMAND, SET_CLUSTER_PROP, CREATE_ZNODE, SECURE_ZNODE_COMMAND, UNSECURE_ZNODE_COMMAND,
SECURE_SOLR_ZNODE_COMMAND, CHECK_ZNODE, SETUP_KERBEROS_PLUGIN, REMOVE_ADMIN_HANDLERS, TRANSFER_ZNODE_COMMAND);
SECURE_SOLR_ZNODE_COMMAND, CHECK_ZNODE, SETUP_KERBEROS_PLUGIN, REMOVE_ADMIN_HANDLERS, TRANSFER_ZNODE_COMMAND, DELETE_ZNODE_COMMAND);
helpFormatter.printHelp(CMD_LINE_SYNTAX, options);
exit(1, String.format("One of the supported commands is required (%s)", StringUtils.join(commands, "|")));
}
@@ -591,6 +602,10 @@ public static void main(String[] args) {
solrCloudClient = clientBuilder.build();
solrCloudClient.transferZnode();
break;
case DELETE_ZNODE_COMMAND:
solrCloudClient = clientBuilder.build();
solrCloudClient.deleteZnode();
break;
default:
throw new AmbariSolrCloudClientException(String.format("Not found command: '%s'", command));
}
@@ -22,6 +22,7 @@
import org.apache.ambari.infra.solr.commands.CreateCollectionCommand;
import org.apache.ambari.infra.solr.commands.CreateShardCommand;
import org.apache.ambari.infra.solr.commands.CreateSolrZnodeZkCommand;
import org.apache.ambari.infra.solr.commands.DeleteZnodeZkCommand;
import org.apache.ambari.infra.solr.commands.DownloadConfigZkCommand;
import org.apache.ambari.infra.solr.commands.EnableKerberosPluginSolrZkCommand;
import org.apache.ambari.infra.solr.commands.GetShardsCommand;
@@ -279,6 +280,13 @@ public boolean transferZnode() throws Exception {
return new TransferZnodeZkCommand(getRetryTimes(), getInterval()).run(this);
}

/**
* Delete znode path (and all sub nodes)
*/
public boolean deleteZnode() throws Exception {
return new DeleteZnodeZkCommand(getRetryTimes(), getInterval()).run(this);
}

public String getZkConnectString() {
return zkConnectString;
}
@@ -0,0 +1,37 @@
/*
* 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.ambari.infra.solr.commands;

import org.apache.ambari.infra.solr.AmbariSolrCloudClient;
import org.apache.solr.common.cloud.SolrZkClient;
import org.apache.solr.common.cloud.SolrZooKeeper;

public class DeleteZnodeZkCommand extends AbstractZookeeperRetryCommand<Boolean> {

public DeleteZnodeZkCommand(int maxRetries, int interval) {
super(maxRetries, interval);
}

@Override
protected Boolean executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception {
zkClient.clean(client.getZnode());
return true;
}

}

0 comments on commit de5b0ad

Please sign in to comment.