http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClient.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClient.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClient.java deleted file mode 100644 index f54401d..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClient.java +++ /dev/null @@ -1,334 +0,0 @@ -/* - * 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.logsearch.solr; - -import org.apache.ambari.logsearch.solr.commands.CheckConfigZkCommand; -import org.apache.ambari.logsearch.solr.commands.CreateCollectionCommand; -import org.apache.ambari.logsearch.solr.commands.CreateShardCommand; -import org.apache.ambari.logsearch.solr.commands.CreateSolrZnodeZkCommand; -import org.apache.ambari.logsearch.solr.commands.DownloadConfigZkCommand; -import org.apache.ambari.logsearch.solr.commands.EnableKerberosPluginSolrZkCommand; -import org.apache.ambari.logsearch.solr.commands.GetShardsCommand; -import org.apache.ambari.logsearch.solr.commands.GetSolrHostsCommand; -import org.apache.ambari.logsearch.solr.commands.ListCollectionCommand; -import org.apache.ambari.logsearch.solr.commands.SecureSolrZNodeZkCommand; -import org.apache.ambari.logsearch.solr.commands.SecureZNodeZkCommand; -import org.apache.ambari.logsearch.solr.commands.SetClusterPropertyZkCommand; -import org.apache.ambari.logsearch.solr.commands.UploadConfigZkCommand; -import org.apache.ambari.logsearch.solr.commands.CheckZnodeZkCommand; -import org.apache.ambari.logsearch.solr.util.ShardUtils; -import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.common.cloud.Slice; -import org.apache.solr.common.cloud.SolrZkClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Collection; -import java.util.List; - -/** - * Client for communicate with Solr (and Zookeeper) - */ -public class AmbariSolrCloudClient { - - private static final Logger LOG = LoggerFactory.getLogger(AmbariSolrCloudClient.class); - - private final String zkConnectString; - private final String collection; - private final String configSet; - private final String configDir; - private final int shards; - private final int replication; - private final int retryTimes; - private final int interval; - private final CloudSolrClient solrCloudClient; - private final SolrZkClient solrZkClient; - private final int maxShardsPerNode; - private final String routerName; - private final String routerField; - private final boolean splitting; - private final String jaasFile; - private final String znode; - private final String saslUsers; - private final String propName; - private final String propValue; - private final String securityJsonLocation; - private final boolean secure; - - public AmbariSolrCloudClient(AmbariSolrCloudClientBuilder builder) { - this.zkConnectString = builder.zkConnectString; - this.collection = builder.collection; - this.configSet = builder.configSet; - this.configDir = builder.configDir; - this.shards = builder.shards; - this.replication = builder.replication; - this.retryTimes = builder.retryTimes; - this.interval = builder.interval; - this.jaasFile = builder.jaasFile; - this.solrCloudClient = builder.solrCloudClient; - this.solrZkClient = builder.solrZkClient; - this.maxShardsPerNode = builder.maxShardsPerNode; - this.routerName = builder.routerName; - this.routerField = builder.routerField; - this.splitting = builder.splitting; - this.znode = builder.znode; - this.saslUsers = builder.saslUsers; - this.propName = builder.propName; - this.propValue = builder.propValue; - this.securityJsonLocation = builder.securityJsonLocation; - this.secure = builder.secure; - } - - /** - * Get Solr collections - */ - public List<String> listCollections() throws Exception { - return new ListCollectionCommand(getRetryTimes(), getInterval()).run(this); - } - - /** - * Create Solr collection if exists - */ - public String createCollection() throws Exception { - List<String> collections = listCollections(); - if (!collections.contains(getCollection())) { - String collection = new CreateCollectionCommand(getRetryTimes(), getInterval()).run(this); - LOG.info("Collection '{}' created.", collection); - } else { - LOG.info("Collection '{}' already exits.", getCollection()); - if (this.isSplitting()) { - createShard(null); - } - } - return getCollection(); - } - - /** - * Set cluster property in clusterprops.json. - */ - public void setClusterProp() throws Exception { - LOG.info("Set cluster prop: '{}'", this.getPropName()); - String newPropValue = new SetClusterPropertyZkCommand(getRetryTimes(), getInterval()).run(this); - LOG.info("Set cluster prop '{}' successfully to '{}'", this.getPropName(), newPropValue); - } - - /** - * Create a znode only if it does not exist. Return 0 code if it exists. - */ - public void createZnode() throws Exception { - boolean znodeExists = isZnodeExists(this.znode); - if (znodeExists) { - LOG.info("Znode '{}' already exists.", this.znode); - } else { - LOG.info("Znode '{}' does not exist. Creating...", this.znode); - String newZnode = new CreateSolrZnodeZkCommand(getRetryTimes(), getInterval()).run(this); - LOG.info("Znode '{}' is created successfully.", newZnode); - } - } - - /** - * Check znode exists or not based on the zookeeper connect string. - * E.g.: localhost:2181 and znode: /ambari-solr, checks existance of localhost:2181/ambari-solr - */ - public boolean isZnodeExists(String znode) throws Exception { - LOG.info("Check '{}' znode exists or not", znode); - boolean result = new CheckZnodeZkCommand(getRetryTimes(), getInterval(), znode).run(this); - if (result) { - LOG.info("'{}' znode exists", znode); - } else { - LOG.info("'{}' znode does not exist", znode); - } - return result; - } - - public void setupKerberosPlugin() throws Exception { - LOG.info("Setup kerberos plugin in security.json"); - new EnableKerberosPluginSolrZkCommand(getRetryTimes(), getInterval()).run(this); - LOG.info("KerberosPlugin is set in security.json"); - } - - /** - * Secure solr znode - */ - public void secureSolrZnode() throws Exception { - new SecureSolrZNodeZkCommand(getRetryTimes(), getInterval()).run(this); - } - - /** - * Secure znode - */ - public void secureZnode() throws Exception { - new SecureZNodeZkCommand(getRetryTimes(), getInterval()).run(this); - } - - /** - * Upload config set to zookeeper - */ - public String uploadConfiguration() throws Exception { - String configSet = new UploadConfigZkCommand(getRetryTimes(), getInterval()).run(this); - LOG.info("'{}' is uploaded to zookeeper.", configSet); - return configSet; - } - - /** - * Download config set from zookeeper - */ - public String downloadConfiguration() throws Exception { - String configDir = new DownloadConfigZkCommand(getRetryTimes(), getInterval()).run(this); - LOG.info("Config set is download from zookeeper. ({})", configDir); - return configDir; - } - - /** - * Get configuration if exists in zookeeper - */ - public boolean configurationExists() throws Exception { - boolean configExits = new CheckConfigZkCommand(getRetryTimes(), getInterval()).run(this); - if (configExits) { - LOG.info("Config {} exits", configSet); - } else { - LOG.info("Configuration '{}' does not exist", configSet); - } - return configExits; - } - - /** - * Create shard in collection - create a new one if shard name specified, if - * not create based on the number of shards logic (with shard_# suffix) - * - * @param shard - * name of the created shard - */ - public Collection<String> createShard(String shard) throws Exception { - Collection<String> existingShards = getShardNames(); - if (shard != null) { - new CreateShardCommand(shard, getRetryTimes(), getInterval()).run(this); - existingShards.add(shard); - } else { - List<String> shardList = ShardUtils.generateShardList(getMaxShardsPerNode()); - for (String shardName : shardList) { - if (!existingShards.contains(shardName)) { - new CreateShardCommand(shardName, getRetryTimes(), getInterval()).run(this); - LOG.info("New shard added to collection '{}': {}", getCollection(), shardName); - existingShards.add(shardName); - } - } - } - return existingShards; - } - - /** - * Get shard names - */ - public Collection<String> getShardNames() throws Exception { - Collection<Slice> slices = new GetShardsCommand(getRetryTimes(), getInterval()).run(this); - return ShardUtils.getShardNamesFromSlices(slices, this.getCollection()); - } - - /** - * Get Solr Hosts - */ - public Collection<String> getSolrHosts() throws Exception { - return new GetSolrHostsCommand(getRetryTimes(), getInterval()).run(this); - } - - public String getZkConnectString() { - return zkConnectString; - } - - public String getCollection() { - return collection; - } - - public String getConfigSet() { - return configSet; - } - - public String getConfigDir() { - return configDir; - } - - public int getShards() { - return shards; - } - - public int getReplication() { - return replication; - } - - public int getRetryTimes() { - return retryTimes; - } - - public int getInterval() { - return interval; - } - - public CloudSolrClient getSolrCloudClient() { - return solrCloudClient; - } - - public SolrZkClient getSolrZkClient() { - return solrZkClient; - } - - public int getMaxShardsPerNode() { - return maxShardsPerNode; - } - - public String getRouterName() { - return routerName; - } - - public String getRouterField() { - return routerField; - } - - public boolean isSplitting() { - return splitting; - } - - public String getJaasFile() { - return jaasFile; - } - - public String getSaslUsers() { - return saslUsers; - } - - public String getZnode() { - return znode; - } - - public String getPropName() { - return propName; - } - - public String getPropValue() { - return propValue; - } - - public boolean isSecure() { - return secure; - } - - public String getSecurityJsonLocation() { - return securityJsonLocation; - } -}
http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClientBuilder.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClientBuilder.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClientBuilder.java deleted file mode 100644 index 7593da6..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClientBuilder.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * 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.logsearch.solr; - -import org.apache.solr.client.solrj.impl.CloudSolrClient; -import org.apache.solr.client.solrj.impl.HttpClientUtil; -import org.apache.solr.client.solrj.impl.Krb5HttpClientConfigurer; -import org.apache.solr.common.cloud.SolrZkClient; - -public class AmbariSolrCloudClientBuilder { - private static final String KEYSTORE_LOCATION_ARG = "javax.net.ssl.keyStore"; - private static final String KEYSTORE_PASSWORD_ARG = "javax.net.ssl.keyStorePassword"; - private static final String KEYSTORE_TYPE_ARG = "javax.net.ssl.keyStoreType"; - private static final String TRUSTSTORE_LOCATION_ARG = "javax.net.ssl.trustStore"; - private static final String TRUSTSTORE_PASSWORD_ARG = "javax.net.ssl.trustStorePassword"; - private static final String TRUSTSTORE_TYPE_ARG = "javax.net.ssl.trustStoreType"; - - String zkConnectString; - String collection; - String configSet; - String configDir; - int shards = 1; - int replication = 1; - int retryTimes = 10; - int interval = 5; - int maxShardsPerNode = replication * shards; - String routerName = "implicit"; - String routerField = "_router_field_"; - CloudSolrClient solrCloudClient; - SolrZkClient solrZkClient; - boolean splitting; - String jaasFile; - String znode; - String saslUsers; - String propName; - String propValue; - String securityJsonLocation; - boolean secure; - - public AmbariSolrCloudClient build() { - return new AmbariSolrCloudClient(this); - } - - public AmbariSolrCloudClientBuilder withZkConnectString(String zkConnectString) { - this.zkConnectString = zkConnectString; - return this; - } - - public AmbariSolrCloudClientBuilder withCollection(String collection) { - this.collection = collection; - return this; - } - - public AmbariSolrCloudClientBuilder withConfigSet(String configSet) { - this.configSet = configSet; - return this; - } - - public AmbariSolrCloudClientBuilder withConfigDir(String configDir) { - this.configDir = configDir; - return this; - } - - public AmbariSolrCloudClientBuilder withShards(int shards) { - this.shards = shards; - return this; - } - - public AmbariSolrCloudClientBuilder withReplication(int replication) { - this.replication = replication; - return this; - } - - public AmbariSolrCloudClientBuilder withRetry(int retryTimes) { - this.retryTimes = retryTimes; - return this; - } - - public AmbariSolrCloudClientBuilder withInterval(int interval) { - this.interval = interval; - return this; - } - - public AmbariSolrCloudClientBuilder withMaxShardsPerNode(int maxShardsPerNode) { - this.maxShardsPerNode = maxShardsPerNode; - return this; - } - - public AmbariSolrCloudClientBuilder withRouterName(String routerName) { - this.routerName = routerName; - return this; - } - - public AmbariSolrCloudClientBuilder withRouterField(String routerField) { - this.routerField = routerField; - return this; - } - - public AmbariSolrCloudClientBuilder withSplitting(boolean splitting) { - this.splitting = splitting; - return this; - } - - public AmbariSolrCloudClientBuilder withJaasFile(String jaasFile) { - this.jaasFile = jaasFile; - setupSecurity(jaasFile); - return this; - } - - public AmbariSolrCloudClientBuilder withSolrCloudClient() { - this.solrCloudClient = new CloudSolrClient(this.zkConnectString); - return this; - } - - public AmbariSolrCloudClientBuilder withSolrZkClient(int zkClientTimeout, int zkClientConnectTimeout) { - this.solrZkClient = new SolrZkClient(this.zkConnectString, zkClientTimeout, zkClientConnectTimeout); - return this; - } - - public AmbariSolrCloudClientBuilder withKeyStoreLocation(String keyStoreLocation) { - if (keyStoreLocation != null) { - System.setProperty(KEYSTORE_LOCATION_ARG, keyStoreLocation); - } - return this; - } - - public AmbariSolrCloudClientBuilder withKeyStorePassword(String keyStorePassword) { - if (keyStorePassword != null) { - System.setProperty(KEYSTORE_PASSWORD_ARG, keyStorePassword); - } - return this; - } - - public AmbariSolrCloudClientBuilder withKeyStoreType(String keyStoreType) { - if (keyStoreType != null) { - System.setProperty(KEYSTORE_TYPE_ARG, keyStoreType); - } - return this; - } - - public AmbariSolrCloudClientBuilder withTrustStoreLocation(String trustStoreLocation) { - if (trustStoreLocation != null) { - System.setProperty(TRUSTSTORE_LOCATION_ARG, trustStoreLocation); - } - return this; - } - - public AmbariSolrCloudClientBuilder withTrustStorePassword(String trustStorePassword) { - if (trustStorePassword != null) { - System.setProperty(TRUSTSTORE_PASSWORD_ARG, trustStorePassword); - } - return this; - } - - public AmbariSolrCloudClientBuilder withTrustStoreType(String trustStoreType) { - if (trustStoreType != null) { - System.setProperty(TRUSTSTORE_TYPE_ARG, trustStoreType); - } - return this; - } - - public AmbariSolrCloudClientBuilder withSaslUsers(String saslUsers) { - this.saslUsers = saslUsers; - return this; - } - - public AmbariSolrCloudClientBuilder withZnode(String znode) { - this.znode = znode; - return this; - } - - public AmbariSolrCloudClientBuilder withClusterPropName(String clusterPropName) { - this.propName = clusterPropName; - return this; - } - - public AmbariSolrCloudClientBuilder withClusterPropValue(String clusterPropValue) { - this.propValue = clusterPropValue; - return this; - } - - public AmbariSolrCloudClientBuilder withSecurityJsonLocation(String securityJson) { - this.securityJsonLocation = securityJson; - return this; - } - - public AmbariSolrCloudClientBuilder withSecure(boolean isSecure) { - this.secure = isSecure; - return this; - } - - private void setupSecurity(String jaasFile) { - if (jaasFile != null) { - System.setProperty("java.security.auth.login.config", jaasFile); - HttpClientUtil.setConfigurer(new Krb5HttpClientConfigurer()); - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClientException.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClientException.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClientException.java deleted file mode 100644 index d03b779..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/AmbariSolrCloudClientException.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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.logsearch.solr; - -public class AmbariSolrCloudClientException extends Exception{ - public AmbariSolrCloudClientException(String message) { - super(message); - } - public AmbariSolrCloudClientException(String message, Throwable throwable) { - super(message, throwable); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractRetryCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractRetryCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractRetryCommand.java deleted file mode 100644 index cfe1e18..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractRetryCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClientException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class AbstractRetryCommand<RESPONSE> { - private static final Logger LOG = LoggerFactory.getLogger(AbstractRetryCommand.class); - - private final int interval; - private final int maxRetries; - - public AbstractRetryCommand(int maxRetries, int interval) { - this.maxRetries = maxRetries; - this.interval = interval; - } - - public abstract RESPONSE createAndProcessRequest(AmbariSolrCloudClient solrCloudClient) throws Exception; - - public RESPONSE run(AmbariSolrCloudClient solrCloudClient) throws Exception { - return retry(0, solrCloudClient); - } - - private RESPONSE retry(int tries, AmbariSolrCloudClient solrCloudClient) throws Exception { - try { - return createAndProcessRequest(solrCloudClient); - } catch (Exception ex) { - LOG.error(ex.getMessage(), ex); - tries++; - LOG.info("Command failed, tries again (tries: {})", tries); - if (maxRetries == tries) { - throw new AmbariSolrCloudClientException(String.format("Maximum retries exceeded: %d", tries), ex); - } else { - Thread.sleep(interval * 1000); - return retry(tries, solrCloudClient); - } - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractSolrRetryCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractSolrRetryCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractSolrRetryCommand.java deleted file mode 100644 index e3d0696..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractSolrRetryCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClientException; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; -import org.apache.solr.client.solrj.response.SolrResponseBase; - -public abstract class AbstractSolrRetryCommand<REQUEST extends CollectionAdminRequest, RESPONSE> - extends AbstractRetryCommand<RESPONSE> { - - public AbstractSolrRetryCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - public abstract RESPONSE handleResponse(CollectionAdminResponse response, AmbariSolrCloudClient client) throws Exception; - - public abstract REQUEST createRequest(AmbariSolrCloudClient client); - - public abstract String errorMessage(AmbariSolrCloudClient client); - - @Override - public RESPONSE createAndProcessRequest(AmbariSolrCloudClient client) throws Exception { - REQUEST request = createRequest(client); - CollectionAdminResponse response = (CollectionAdminResponse) request.process(client.getSolrCloudClient()); - handleErrorIfExists(response, errorMessage(client)); - return handleResponse(response, client); - } - - private void handleErrorIfExists(SolrResponseBase response, String message) throws AmbariSolrCloudClientException { - if (response.getStatus() != 0) { - throw new AmbariSolrCloudClientException(message); - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractStateFileZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractStateFileZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractStateFileZkCommand.java deleted file mode 100644 index d351589..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractStateFileZkCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.domain.AmbariSolrState; -import org.codehaus.jackson.JsonNode; -import org.codehaus.jackson.map.ObjectMapper; - -public abstract class AbstractStateFileZkCommand extends AbstractZookeeperRetryCommand<AmbariSolrState>{ - - public static final String STATE_FILE = "ambari-solr-state.json"; - public static final String STATE_FIELD = "ambari_solr_security_state"; - - public AbstractStateFileZkCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - public AmbariSolrState getStateFromJson(AmbariSolrCloudClient client, String fileName) throws Exception { - byte[] data = client.getSolrZkClient().getData(fileName, null, null, true); - String input = new String(data); - ObjectMapper mapper = new ObjectMapper(); - JsonNode rootNode = mapper.readValue(input.getBytes(), JsonNode.class); - return AmbariSolrState.valueOf(rootNode.get(STATE_FIELD).asText()); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractZookeeperConfigCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractZookeeperConfigCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractZookeeperConfigCommand.java deleted file mode 100644 index 031f5f7..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractZookeeperConfigCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; -import org.apache.solr.common.cloud.ZkConfigManager; - -public abstract class AbstractZookeeperConfigCommand<RESPONSE> extends AbstractZookeeperRetryCommand<RESPONSE> { - - public AbstractZookeeperConfigCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - protected abstract RESPONSE executeZkConfigCommand(ZkConfigManager zkConfigManager, AmbariSolrCloudClient client) - throws Exception; - - @Override - protected RESPONSE executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception { - ZkConfigManager zkConfigManager = createZkConfigManager(zkClient); - return executeZkConfigCommand(zkConfigManager, client); - } - - protected ZkConfigManager createZkConfigManager(SolrZkClient zkClient) { - return new ZkConfigManager(zkClient); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractZookeeperRetryCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractZookeeperRetryCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractZookeeperRetryCommand.java deleted file mode 100644 index 9995ea6..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/AbstractZookeeperRetryCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; - -public abstract class AbstractZookeeperRetryCommand<RESPONSE> extends AbstractRetryCommand<RESPONSE> { - - public AbstractZookeeperRetryCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - protected abstract RESPONSE executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) - throws Exception; - - @Override - public RESPONSE createAndProcessRequest(AmbariSolrCloudClient client) throws Exception { - SolrZkClient zkClient = client.getSolrZkClient(); - SolrZooKeeper solrZooKeeper = zkClient.getSolrZooKeeper(); - return executeZkCommand(client, zkClient, solrZooKeeper); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CheckConfigZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CheckConfigZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CheckConfigZkCommand.java deleted file mode 100644 index 182f049..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CheckConfigZkCommand.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.solr.common.cloud.ZkConfigManager; - -public class CheckConfigZkCommand extends AbstractZookeeperConfigCommand<Boolean> { - - public CheckConfigZkCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - protected Boolean executeZkConfigCommand(ZkConfigManager zkConfigManager, AmbariSolrCloudClient client) throws Exception { - return zkConfigManager.configExists(client.getConfigSet()); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CheckZnodeZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CheckZnodeZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CheckZnodeZkCommand.java deleted file mode 100644 index 6e82cc3..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CheckZnodeZkCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClientException; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; -import org.apache.zookeeper.KeeperException; - -public class CheckZnodeZkCommand extends AbstractZookeeperRetryCommand<Boolean> { - - private String znode; - - public CheckZnodeZkCommand(int maxRetries, int interval, String znode) { - super(maxRetries, interval); - this.znode = znode; - } - - @Override - protected Boolean executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception { - try { - return zkClient.exists(this.znode, false); - } catch (KeeperException e) { - throw new AmbariSolrCloudClientException("Exception during checking znode, " + - "Check zookeeper servers are running (n+1/2) or zookeeper quorum has established or not.", e); - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateCollectionCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateCollectionCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateCollectionCommand.java deleted file mode 100644 index f981cbb..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateCollectionCommand.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.util.ShardUtils; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; - -import java.util.ArrayList; -import java.util.List; - -public class CreateCollectionCommand extends AbstractSolrRetryCommand<CollectionAdminRequest.Create ,String> { - - public CreateCollectionCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - public String handleResponse(CollectionAdminResponse response, AmbariSolrCloudClient client) throws Exception { - return client.getCollection(); - } - - @Override - public CollectionAdminRequest.Create createRequest(AmbariSolrCloudClient client) { - CollectionAdminRequest.Create request = new CollectionAdminRequest.Create(); - request.setConfigName(client.getConfigSet()); - request.setCollectionName(client.getCollection()); - request.setNumShards(client.getShards()); - request.setReplicationFactor(client.getReplication()); - request.setMaxShardsPerNode(client.getMaxShardsPerNode()); - if (client.getRouterField() != null && client.getRouterName()!= null) { - request.setRouterName(client.getRouterName()); - request.setRouterField(client.getRouterField()); - } - if (client.isSplitting()) { - request.setShards(ShardUtils.generateShardListStr(client.getMaxShardsPerNode())); - } - return request; - } - - @Override - public String errorMessage(AmbariSolrCloudClient client) { - return String.format("Cannot create collection: '%s'", client.getCollection()); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateShardCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateShardCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateShardCommand.java deleted file mode 100644 index 343a498..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateShardCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; - -public class CreateShardCommand extends AbstractSolrRetryCommand<CollectionAdminRequest.CreateShard, String> { - - private final String shardName; - - public CreateShardCommand(String shardName, int maxRetries, int interval) { - super(maxRetries, interval); - this.shardName = shardName; - } - - @Override - public String handleResponse(CollectionAdminResponse response, AmbariSolrCloudClient client) throws Exception { - return shardName; - } - - @Override - public CollectionAdminRequest.CreateShard createRequest(AmbariSolrCloudClient client) { - CollectionAdminRequest.CreateShard createShardRequest = new CollectionAdminRequest.CreateShard(); - createShardRequest.setCollectionName(client.getCollection()); - createShardRequest.setShardName(shardName); - return createShardRequest; - } - - @Override - public String errorMessage(AmbariSolrCloudClient client) { - return String.format("Cannot add shard to collection '%s'", client.getCollection()); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateSolrZnodeZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateSolrZnodeZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateSolrZnodeZkCommand.java deleted file mode 100644 index cd95e38..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/CreateSolrZnodeZkCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClientException; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; -import org.apache.zookeeper.KeeperException; - -public class CreateSolrZnodeZkCommand extends AbstractZookeeperRetryCommand<String> { - - public CreateSolrZnodeZkCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - protected String executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception { - try { - zkClient.makePath(client.getZnode(), true); - return client.getZnode(); - } catch (KeeperException e) { - throw new AmbariSolrCloudClientException("Cannot create ZNode, check zookeeper servers are running (n+1/2), or zookeeper quorum has established or not.",e); - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/DownloadConfigZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/DownloadConfigZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/DownloadConfigZkCommand.java deleted file mode 100644 index 9da4e53..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/DownloadConfigZkCommand.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClientException; -import org.apache.solr.common.cloud.ZkConfigManager; - -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class DownloadConfigZkCommand extends AbstractZookeeperConfigCommand<String> { - - public DownloadConfigZkCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - protected String executeZkConfigCommand(ZkConfigManager zkConfigManager, AmbariSolrCloudClient client) throws Exception { - Path configDir = Paths.get(client.getConfigDir()); - String configSet = client.getConfigSet(); - try { - zkConfigManager.downloadConfigDir(configSet, configDir); - return configDir.toString(); - } catch (IOException e){ - throw new AmbariSolrCloudClientException("Error downloading configuration set, check Solr Znode has started or not " + - "(starting Solr (for Log Search) is responsible to create the Znode)" ,e); - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/EnableKerberosPluginSolrZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/EnableKerberosPluginSolrZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/EnableKerberosPluginSolrZkCommand.java deleted file mode 100644 index 3807887..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/EnableKerberosPluginSolrZkCommand.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; -import org.apache.zookeeper.CreateMode; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; - -public class EnableKerberosPluginSolrZkCommand extends AbstractZookeeperRetryCommand<String> { - - private static final String SECURITY_JSON = "/security.json"; - private static final String UNSECURE_CONTENT = "{}"; - - public EnableKerberosPluginSolrZkCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - protected String executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception { - String result = ""; - String filePath = client.getZnode() + SECURITY_JSON; - String fileContent = getFileContentFromZnode(zkClient, filePath); - String securityContent = getFileContent(client.getSecurityJsonLocation()); - if (client.isSecure()) { - if (!fileContent.equals(securityContent)) { - putFileContent(zkClient, filePath, securityContent); - } - result = securityContent; - } else { - if (!fileContent.equals(UNSECURE_CONTENT)) { - putFileContent(zkClient, filePath, UNSECURE_CONTENT); - } - result = UNSECURE_CONTENT; - } - return result; - } - - private void putFileContent(SolrZkClient zkClient, String fileName, String content) throws Exception { - if (zkClient.exists(fileName, true)) { - zkClient.setData(fileName, content.getBytes(StandardCharsets.UTF_8), true); - } else { - zkClient.create(fileName, content.getBytes(StandardCharsets.UTF_8), CreateMode.PERSISTENT, true); - } - } - - private String getFileContentFromZnode(SolrZkClient zkClient, String fileName) throws Exception { - String result; - if (zkClient.exists(fileName, true)) { - byte[] data = zkClient.getData(fileName, null, null, true); - result = new String(data, StandardCharsets.UTF_8); - } else { - result = UNSECURE_CONTENT; - } - return result; - } - - private String getFileContent(String fileLocation) throws IOException { - File securityJson = new File(fileLocation); - if (StringUtils.isNotEmpty(fileLocation) && securityJson.exists()) { - return FileUtils.readFileToString(securityJson); - } else { - return UNSECURE_CONTENT; - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetShardsCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetShardsCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetShardsCommand.java deleted file mode 100644 index 422878c..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetShardsCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.solr.common.cloud.Slice; -import org.apache.solr.common.cloud.ZkStateReader; - -import java.util.Collection; - -public class GetShardsCommand extends AbstractRetryCommand<Collection<Slice>> { - - public GetShardsCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - public Collection<Slice> createAndProcessRequest(AmbariSolrCloudClient solrCloudClient) throws Exception { - ZkStateReader zkReader = new ZkStateReader(solrCloudClient.getSolrZkClient()); - zkReader.createClusterStateWatchersAndUpdate(); - return zkReader.getClusterState().getSlices(solrCloudClient.getCollection()); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetSolrHostsCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetSolrHostsCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetSolrHostsCommand.java deleted file mode 100644 index 1aa8157..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetSolrHostsCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.zookeeper.ZooKeeper; - -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -public class GetSolrHostsCommand extends AbstractRetryCommand<Collection<String>> { - - public GetSolrHostsCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - public Collection<String> createAndProcessRequest(AmbariSolrCloudClient solrCloudClient) throws Exception { - List<String> solrHosts = new ArrayList<>(); - - ZooKeeper zk = new ZooKeeper(solrCloudClient.getZkConnectString(), 10000, null); - List<String> ids = zk.getChildren("/live_nodes", false); - for (String id : ids) { - if (id.endsWith("_solr")) { - String hostAndPort = id.substring(0, id.length() - 5); - String[] tokens = hostAndPort.split(":"); - String host = InetAddress.getByName(tokens[0]).getHostName(); - - solrHosts.add(host); - } - } - - return solrHosts; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetStateFileZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetStateFileZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetStateFileZkCommand.java deleted file mode 100644 index d04c89d..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/GetStateFileZkCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.domain.AmbariSolrState; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; - -public class GetStateFileZkCommand extends AbstractStateFileZkCommand { - private String unsecureZnode; - - public GetStateFileZkCommand(int maxRetries, int interval, String unsecureZnode) { - super(maxRetries, interval); - this.unsecureZnode = unsecureZnode; - } - - @Override - protected AmbariSolrState executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception { - AmbariSolrState result = AmbariSolrState.UNSECURE; - String stateFile = String.format("%s/%s", unsecureZnode, AbstractStateFileZkCommand.STATE_FILE); - if (zkClient.exists(stateFile, true)) { - result = getStateFromJson(client, stateFile); - } - return result; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/ListCollectionCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/ListCollectionCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/ListCollectionCommand.java deleted file mode 100644 index 0052615..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/ListCollectionCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.solr.client.solrj.request.CollectionAdminRequest; -import org.apache.solr.client.solrj.response.CollectionAdminResponse; - -import java.util.List; - -public class ListCollectionCommand extends AbstractSolrRetryCommand<CollectionAdminRequest.List, List<String>> { - - public ListCollectionCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - public List<String> handleResponse(CollectionAdminResponse response, AmbariSolrCloudClient client) throws Exception { - List<String> allCollectionList = (List<String>) response - .getResponse().get("collections"); - return allCollectionList; - } - - @Override - public CollectionAdminRequest.List createRequest(AmbariSolrCloudClient client) { - return new CollectionAdminRequest.List(); - } - - @Override - public String errorMessage(AmbariSolrCloudClient client) { - return "Cannot get collections."; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SecureSolrZNodeZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SecureSolrZNodeZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SecureSolrZNodeZkCommand.java deleted file mode 100644 index 31ad5d3..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SecureSolrZNodeZkCommand.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.util.AclUtils; -import org.apache.commons.lang.StringUtils; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; -import org.apache.solr.common.cloud.ZkConfigManager; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.ZooDefs; -import org.apache.zookeeper.data.ACL; -import org.apache.zookeeper.data.Id; -import org.apache.zookeeper.data.Stat; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class SecureSolrZNodeZkCommand extends AbstractZookeeperRetryCommand<Boolean> { - - private static final Logger LOG = LoggerFactory.getLogger(SecureSolrZNodeZkCommand.class); - - public SecureSolrZNodeZkCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - protected Boolean executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception { - String zNode = client.getZnode(); - List<ACL> newAclList = new ArrayList<>(); - List<ACL> saslUserList = AclUtils.createAclListFromSaslUsers(client.getSaslUsers().split(",")); - newAclList.addAll(saslUserList); - newAclList.add(new ACL(ZooDefs.Perms.READ, new Id("world", "anyone"))); - - String configsPath = String.format("%s/%s", zNode, "configs"); - String collectionsPath = String.format("%s/%s", zNode, "collections"); - String aliasesPath = String.format("%s/%s", zNode, "aliases.json"); // TODO: protect this later somehow - List<String> excludePaths = Arrays.asList(configsPath, collectionsPath, aliasesPath); - - createZnodeIfNeeded(configsPath, client.getSolrZkClient()); - createZnodeIfNeeded(collectionsPath, client.getSolrZkClient()); - - AclUtils.setRecursivelyOn(client.getSolrZkClient().getSolrZooKeeper(), zNode, newAclList, excludePaths); - - List<ACL> commonConfigAcls = new ArrayList<>(); - commonConfigAcls.addAll(saslUserList); - commonConfigAcls.add(new ACL(ZooDefs.Perms.READ | ZooDefs.Perms.CREATE, new Id("world", "anyone"))); - - LOG.info("Set sasl users for znode '{}' : {}", client.getZnode(), StringUtils.join(saslUserList, ",")); - LOG.info("Skip {}/configs and {}/collections", client.getZnode(), client.getZnode()); - solrZooKeeper.setACL(configsPath, AclUtils.mergeAcls(solrZooKeeper.getACL(configsPath, new Stat()), commonConfigAcls), -1); - solrZooKeeper.setACL(collectionsPath, AclUtils.mergeAcls(solrZooKeeper.getACL(collectionsPath, new Stat()), commonConfigAcls), -1); - - LOG.info("Set world:anyone to 'cr' on {}/configs and {}/collections", client.getZnode(), client.getZnode()); - AclUtils.setRecursivelyOn(solrZooKeeper, configsPath, saslUserList); - AclUtils.setRecursivelyOn(solrZooKeeper, collectionsPath, saslUserList); - - return true; - } - - private void createZnodeIfNeeded(String configsPath, SolrZkClient zkClient) throws KeeperException, InterruptedException { - if (!zkClient.exists(configsPath, true)) { - LOG.info("'{}' does not exist. Creating it ...", configsPath); - zkClient.makePath(configsPath, true); - } - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SecureZNodeZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SecureZNodeZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SecureZNodeZkCommand.java deleted file mode 100644 index f62b399..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SecureZNodeZkCommand.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.util.AclUtils; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; -import org.apache.zookeeper.ZooDefs; -import org.apache.zookeeper.data.ACL; -import org.apache.zookeeper.data.Id; - -import java.util.ArrayList; -import java.util.List; - -public class SecureZNodeZkCommand extends AbstractZookeeperRetryCommand<Boolean> { - - public SecureZNodeZkCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - protected Boolean executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception { - String zNode = client.getZnode(); - List<ACL> newAclList = new ArrayList<>(); - List<ACL> saslUserList = AclUtils.createAclListFromSaslUsers(client.getSaslUsers().split(",")); - newAclList.addAll(saslUserList); - newAclList.add(new ACL(ZooDefs.Perms.READ, new Id("world", "anyone"))); - AclUtils.setRecursivelyOn(client.getSolrZkClient().getSolrZooKeeper(), zNode, newAclList); - return true; - } - -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SetClusterPropertyZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SetClusterPropertyZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SetClusterPropertyZkCommand.java deleted file mode 100644 index 575d807..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/SetClusterPropertyZkCommand.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; -import org.apache.solr.common.cloud.ZkStateReader; - -public class SetClusterPropertyZkCommand extends AbstractZookeeperRetryCommand<String>{ - - public SetClusterPropertyZkCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - protected String executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception { - String propertyName = client.getPropName(); - String propertyValue = client.getPropValue(); - ZkStateReader reader = new ZkStateReader(zkClient); - reader.setClusterProperty(propertyName, propertyValue); - return propertyValue; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/UpdateStateFileZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/UpdateStateFileZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/UpdateStateFileZkCommand.java deleted file mode 100644 index dbb6d79..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/UpdateStateFileZkCommand.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.domain.AmbariSolrState; -import org.apache.solr.common.cloud.SolrZkClient; -import org.apache.solr.common.cloud.SolrZooKeeper; -import org.apache.zookeeper.CreateMode; -import org.codehaus.jackson.map.ObjectMapper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.nio.charset.StandardCharsets; -import java.util.HashMap; -import java.util.Map; - -public class UpdateStateFileZkCommand extends AbstractStateFileZkCommand { - - private static final Logger LOG = LoggerFactory.getLogger(UpdateStateFileZkCommand.class); - - private String unsecureZnode; - - public UpdateStateFileZkCommand(int maxRetries, int interval, String unsecureZnode) { - super(maxRetries, interval); - this.unsecureZnode = unsecureZnode; - } - - @Override - protected AmbariSolrState executeZkCommand(AmbariSolrCloudClient client, SolrZkClient zkClient, SolrZooKeeper solrZooKeeper) throws Exception { - boolean secure = client.isSecure(); - String stateFile = String.format("%s/%s", unsecureZnode, AbstractStateFileZkCommand.STATE_FILE); - AmbariSolrState result = null; - if (secure) { - LOG.info("Update state file in secure mode."); - updateStateFile(client, zkClient, AmbariSolrState.SECURE, stateFile); - result = AmbariSolrState.SECURE; - } else { - LOG.info("Update state file in unsecure mode."); - updateStateFile(client, zkClient, AmbariSolrState.UNSECURE, stateFile); - result = AmbariSolrState.UNSECURE; - } - return result; - } - - private void updateStateFile(AmbariSolrCloudClient client, SolrZkClient zkClient, AmbariSolrState stateToUpdate, - String stateFile) throws Exception { - if (!zkClient.exists(stateFile, true)) { - LOG.info("State file does not exits. Initializing it as '{}'", stateToUpdate); - zkClient.create(stateFile, createStateJson(stateToUpdate).getBytes(StandardCharsets.UTF_8), - CreateMode.PERSISTENT, true); - } else { - AmbariSolrState stateOnSecure = getStateFromJson(client, stateFile); - if (stateToUpdate.equals(stateOnSecure)) { - LOG.info("State file is in '{}' mode. No update.", stateOnSecure); - } else { - LOG.info("State file is in '{}' mode. Updating it to '{}'", stateOnSecure, stateToUpdate); - zkClient.setData(stateFile, createStateJson(stateToUpdate).getBytes(StandardCharsets.UTF_8), true); - } - } - } - - private String createStateJson(AmbariSolrState state) throws Exception { - Map<String, String> secStateMap = new HashMap<>(); - secStateMap.put(AbstractStateFileZkCommand.STATE_FIELD, state.toString()); - return new ObjectMapper().writeValueAsString(secStateMap); - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/UploadConfigZkCommand.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/UploadConfigZkCommand.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/UploadConfigZkCommand.java deleted file mode 100644 index 14f4654..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/commands/UploadConfigZkCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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.logsearch.solr.commands; - -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClient; -import org.apache.ambari.logsearch.solr.AmbariSolrCloudClientException; -import org.apache.solr.common.cloud.ZkConfigManager; - -import java.io.IOException; -import java.nio.file.Path; -import java.nio.file.Paths; - -public class UploadConfigZkCommand extends AbstractZookeeperConfigCommand<String> { - - public UploadConfigZkCommand(int maxRetries, int interval) { - super(maxRetries, interval); - } - - @Override - protected String executeZkConfigCommand(ZkConfigManager zkConfigManager, AmbariSolrCloudClient client) throws Exception { - Path configDir = Paths.get(client.getConfigDir()); - String configSet = client.getConfigSet(); - zkConfigManager.uploadConfigDir(configDir, configSet); - return configSet; - } -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/domain/AmbariSolrState.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/domain/AmbariSolrState.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/domain/AmbariSolrState.java deleted file mode 100644 index 577fefb..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/domain/AmbariSolrState.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.logsearch.solr.domain; - -/** - * Enum state values for storing security status in unsecure znode - */ -public enum AmbariSolrState { - SECURE, UNSECURE -} http://git-wip-us.apache.org/repos/asf/ambari/blob/c5ccb1ab/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/util/AclUtils.java ---------------------------------------------------------------------- diff --git a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/util/AclUtils.java b/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/util/AclUtils.java deleted file mode 100644 index fc25c49..0000000 --- a/ambari-logsearch/ambari-logsearch-solr-client/src/main/java/org/apache/ambari/logsearch/solr/util/AclUtils.java +++ /dev/null @@ -1,87 +0,0 @@ -/* - * 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.logsearch.solr.util; - -import org.apache.solr.common.cloud.SolrZooKeeper; -import org.apache.zookeeper.KeeperException; -import org.apache.zookeeper.ZooDefs; -import org.apache.zookeeper.data.ACL; -import org.apache.zookeeper.data.Id; -import org.apache.zookeeper.data.Stat; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class AclUtils { - - public static List<ACL> mergeAcls(List<ACL> originalAcls, List<ACL> updateAcls) { - Map<String, ACL> aclMap = new HashMap<>(); - List<ACL> acls = new ArrayList<>(); - if (originalAcls != null) { - for (ACL acl : originalAcls) { - aclMap.put(acl.getId().getId(), acl); - } - } - - if (updateAcls != null) { - for (ACL acl : updateAcls) { - aclMap.put(acl.getId().getId(), acl); - } - } - - for (Map.Entry<String, ACL> aclEntry : aclMap.entrySet()) { - acls.add(aclEntry.getValue()); - } - return acls; - } - - public static List<ACL> createAclListFromSaslUsers(String[] saslUsers) { - List<ACL> saslUserList = new ArrayList<>(); - for (String saslUser : saslUsers) { - ACL acl = new ACL(); - acl.setId(new Id("sasl", saslUser)); - acl.setPerms(ZooDefs.Perms.ALL); - saslUserList.add(acl); - } - return saslUserList; - } - - public static void setRecursivelyOn(SolrZooKeeper solrZooKeeper, String node, List<ACL> acls) throws KeeperException, InterruptedException { - setRecursivelyOn(solrZooKeeper, node, acls, new ArrayList<String>()); - } - - public static void setRecursivelyOn(SolrZooKeeper solrZooKeeper, String node, List<ACL> acls, List<String> excludePaths) - throws KeeperException, InterruptedException { - if (!excludePaths.contains(node)) { - List<ACL> newAcls = AclUtils.mergeAcls(solrZooKeeper.getACL(node, new Stat()), acls); - solrZooKeeper.setACL(node, newAcls, -1); - for (String child : solrZooKeeper.getChildren(node, null)) { - setRecursivelyOn(solrZooKeeper, path(node, child), acls, excludePaths); - } - } - } - - private static String path(String node, String child) { - return node.endsWith("/") ? node + child : node + "/" + child; - } -}
