Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id A9561200CF8 for ; Wed, 30 Aug 2017 18:39:37 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id A7EA516981F; Wed, 30 Aug 2017 16:39:37 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 7C103169800 for ; Wed, 30 Aug 2017 18:39:33 +0200 (CEST) Received: (qmail 6030 invoked by uid 500); 30 Aug 2017 16:39:32 -0000 Mailing-List: contact commits-help@oodt.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@oodt.apache.org Delivered-To: mailing list commits@oodt.apache.org Received: (qmail 4048 invoked by uid 99); 30 Aug 2017 16:39:31 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Aug 2017 16:39:31 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 62668F5581; Wed, 30 Aug 2017 16:39:31 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mattmann@apache.org To: commits@oodt.apache.org Date: Wed, 30 Aug 2017 16:40:07 -0000 Message-Id: <7f9efd3b2a684438b990e08554f1a086@git.apache.org> In-Reply-To: <602f1c7b278843318b280f88fc5fbb83@git.apache.org> References: <602f1c7b278843318b280f88fc5fbb83@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [38/52] [abbrv] oodt git commit: Altered config publisher CLI to use cas-cli archived-at: Wed, 30 Aug 2017 16:39:37 -0000 Altered config publisher CLI to use cas-cli Project: http://git-wip-us.apache.org/repos/asf/oodt/repo Commit: http://git-wip-us.apache.org/repos/asf/oodt/commit/01331125 Tree: http://git-wip-us.apache.org/repos/asf/oodt/tree/01331125 Diff: http://git-wip-us.apache.org/repos/asf/oodt/diff/01331125 Branch: refs/heads/master Commit: 01331125b24dafa374af6f5a6789c060651474fd Parents: 39b6c88 Author: Imesha Sudasingha Authored: Wed Jul 26 23:50:52 2017 +0530 Committer: Imesha Sudasingha Committed: Fri Jul 28 21:20:43 2017 +0530 ---------------------------------------------------------------------- config/pom.xml | 4 +- config/src/main/assembly/assembly.xml | 18 ++- .../oodt/config/distributed/cli/CLIAction.java | 116 +++++++++++++++++++ .../config/distributed/cli/CmdLineOptions.java | 58 ---------- .../config/distributed/cli/ConfigPublisher.java | 84 ++------------ config/src/main/resources/cmd-line-actions.xml | 38 ++++++ config/src/main/resources/cmd-line-options.xml | 50 ++++++++ config/src/main/resources/config-publisher.xml | 42 +++++++ .../src/main/resources/etc/config-publisher.xml | 42 ------- config/src/main/resources/etc/log4j.xml | 54 --------- config/src/main/resources/log4j.xml | 54 +++++++++ config/src/main/scripts/conf-publisher | 4 + .../AbstractDistributedConfigurationTest.java | 2 + .../DistributedConfigurationManagerTest.java | 4 +- .../DistributedConfigurationPublisherTest.java | 5 +- core/pom.xml | 5 - 16 files changed, 337 insertions(+), 243 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/pom.xml ---------------------------------------------------------------------- diff --git a/config/pom.xml b/config/pom.xml index 6719c48..438efc4 100644 --- a/config/pom.xml +++ b/config/pom.xml @@ -17,8 +17,8 @@ - args4j - args4j + org.apache.oodt + cas-cli commons-io http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/assembly/assembly.xml ---------------------------------------------------------------------- diff --git a/config/src/main/assembly/assembly.xml b/config/src/main/assembly/assembly.xml index bb6f31e..a6db0fc 100644 --- a/config/src/main/assembly/assembly.xml +++ b/config/src/main/assembly/assembly.xml @@ -40,7 +40,23 @@ ${basedir}/src/main/resources - . + etc + + config-publisher.xml + log4j.xml + + + + ${basedir}/src/main/resources + policy + + cmd-line-actions.xml + cmd-line-options.xml + + + + ${basedir}/src/main/resources/examples + examples http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/java/org/apache/oodt/config/distributed/cli/CLIAction.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/oodt/config/distributed/cli/CLIAction.java b/config/src/main/java/org/apache/oodt/config/distributed/cli/CLIAction.java new file mode 100644 index 0000000..32fd640 --- /dev/null +++ b/config/src/main/java/org/apache/oodt/config/distributed/cli/CLIAction.java @@ -0,0 +1,116 @@ +/* + * 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.oodt.config.distributed.cli; + +import org.apache.oodt.cas.cli.action.CmdLineAction; +import org.apache.oodt.cas.cli.exception.CmdLineActionException; +import org.apache.oodt.config.Constants; +import org.apache.oodt.config.distributed.DistributedConfigurationPublisher; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.util.Map; + +import static org.apache.oodt.config.Constants.Properties.ZK_CONNECT_STRING; + +/** + * {@link CmdLineAction} specifying the verify, publish and clear tasks of distributed configuration management. + * + * @author Imesha Sudasingha + */ +public class CLIAction extends CmdLineAction { + + public enum Action { + PUBLISH, VERIFY, CLEAR + } + + private String connectString; + private Action action; + + public CLIAction(Action action) { + this.action = action; + } + + @Override + public void execute(ActionMessagePrinter printer) throws CmdLineActionException { + try { + ApplicationContext applicationContext = new ClassPathXmlApplicationContext(Constants.CONFIG_PUBLISHER_XML); + Map distributedConfigurationPublisher = applicationContext.getBeansOfType(DistributedConfigurationPublisher.class); + + for (Object bean : distributedConfigurationPublisher.values()) { + DistributedConfigurationPublisher publisher = (DistributedConfigurationPublisher) bean; + switch (action) { + case PUBLISH: + publish(publisher); + break; + case VERIFY: + verify(publisher); + break; + case CLEAR: + clear(publisher); + break; + } + publisher.destroy(); + } + } catch (BeansException e) { + System.out.println(String.format("Error occurred when obtaining configuration publisher beans: '%s'", e.getMessage())); + } catch (Exception e) { + System.out.println(String.format("Error occurred when publishing configuration to zookeeper: '%s'", e.getMessage())); + } + + System.out.println("Exiting CLI ..."); + } + + private void publish(DistributedConfigurationPublisher publisher) throws Exception { + System.out.println(); + System.out.println(String.format("Publishing configuration for : %s", publisher.getComponent())); + publisher.publishConfiguration(); + System.out.println(String.format("Published configuration for : %s", publisher.getComponent())); + System.out.println(); + } + + private void verify(DistributedConfigurationPublisher publisher) throws Exception { + System.out.println(); + System.out.println(String.format("Verifying configuration for : %s", publisher.getComponent())); + if (publisher.verifyPublishedConfiguration()) { + System.out.println("OK... Configuration verified"); + System.out.println(String.format("Verified configuration for : %s", publisher.getComponent())); + } else { + System.err.println("ERROR... Published configuration doesn't match the local files. Please check above logs"); + } + System.out.println(); + } + + private void clear(DistributedConfigurationPublisher publisher) throws Exception { + System.out.println(); + System.out.println(String.format("Clearing configuration for : %s", publisher.getComponent())); + publisher.clearConfiguration(); + System.out.println(String.format("Cleared configuration for : %s", publisher.getComponent())); + System.out.println(); + } + + public String getConnectString() { + return connectString; + } + + public void setConnectString(String connectString) { + System.setProperty(ZK_CONNECT_STRING, connectString); + this.connectString = connectString; + } +} http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/java/org/apache/oodt/config/distributed/cli/CmdLineOptions.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/oodt/config/distributed/cli/CmdLineOptions.java b/config/src/main/java/org/apache/oodt/config/distributed/cli/CmdLineOptions.java deleted file mode 100644 index a262387..0000000 --- a/config/src/main/java/org/apache/oodt/config/distributed/cli/CmdLineOptions.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.oodt.config.distributed.cli; - -import org.kohsuke.args4j.Option; - -/** - * Bean class used to map CLI options and arguments provided by the user when publishing configuration to zookeeper - * - * @author Imesha Sudaingha - */ -public class CmdLineOptions { - - @Option(name = "-connectString", usage = "Zookeeper connect string", required = true) - private String connectString; - - @Option(name = "-publish", usage = "Publishes configuration specified in the spring config file to zookeeper. " + - "Any current similar config in zookeeper will be overwritten. If not specified, " + - "command will be assumed as a publish") - private boolean publish = false; - - @Option(name = "-verify", usage = "Verifies the content in the local files and the published ones. Results will be printed.") - private boolean verify = false; - - @Option(name = "-clear", usage = "Unpublish any configuration which has been published earlier using the same spring config file") - private boolean clear = false; - - public String getConnectString() { - return connectString; - } - - public boolean isPublish() { - return publish; - } - - public boolean isVerify() { - return verify; - } - - public boolean isClear() { - return clear; - } -} http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/java/org/apache/oodt/config/distributed/cli/ConfigPublisher.java ---------------------------------------------------------------------- diff --git a/config/src/main/java/org/apache/oodt/config/distributed/cli/ConfigPublisher.java b/config/src/main/java/org/apache/oodt/config/distributed/cli/ConfigPublisher.java index 7a78a8c..f4c45a7 100644 --- a/config/src/main/java/org/apache/oodt/config/distributed/cli/ConfigPublisher.java +++ b/config/src/main/java/org/apache/oodt/config/distributed/cli/ConfigPublisher.java @@ -17,89 +17,21 @@ package org.apache.oodt.config.distributed.cli; -import org.apache.oodt.config.Constants; -import org.apache.oodt.config.distributed.DistributedConfigurationPublisher; -import org.kohsuke.args4j.CmdLineException; -import org.kohsuke.args4j.CmdLineParser; +import org.apache.oodt.cas.cli.CmdLineUtility; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.context.ApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; - -import java.util.Map; - -import static org.apache.oodt.config.Constants.Properties.ZK_CONNECT_STRING; +/** + * Class with main method which gets invoked by the CLI. + * + * @author Imesha Sudasingha + */ public class ConfigPublisher { private static final Logger logger = LoggerFactory.getLogger(ConfigPublisher.class); public static void main(String[] args) throws Exception { - CmdLineOptions cmdLineOptions = new CmdLineOptions(); - CmdLineParser parser = new CmdLineParser(cmdLineOptions); - - try { - parser.parseArgument(args); - } catch (CmdLineException e) { - System.err.println("There's an error in your command"); - parser.printUsage(System.err); - return; - } - - if (cmdLineOptions.getConnectString() == null && System.getProperty(ZK_CONNECT_STRING) == null) { - System.err.println("Zookeeper connect string is not found"); - parser.printUsage(System.err); - return; - } else { - System.setProperty(ZK_CONNECT_STRING, cmdLineOptions.getConnectString()); - } - - System.out.println("Starting configuration publishing"); - - try { - ApplicationContext applicationContext = new ClassPathXmlApplicationContext(Constants.CONFIG_PUBLISHER_XML); - Map distributedConfigurationPublisher = applicationContext.getBeansOfType(DistributedConfigurationPublisher.class); - - for (Object bean : distributedConfigurationPublisher.values()) { - DistributedConfigurationPublisher publisher = (DistributedConfigurationPublisher) bean; - System.out.println(String.format("\nProcessing commands for component : %s", publisher.getComponent())); - - if (cmdLineOptions.isPublish()) { - System.out.println(String.format("Publishing configuration for : %s", publisher.getComponent())); - publisher.publishConfiguration(); - System.out.println(String.format("Published configuration for : %s", publisher.getComponent())); - System.out.println(); - } - - if (cmdLineOptions.isVerify()) { - System.out.println(String.format("Verifying configuration for : %s", publisher.getComponent())); - if (publisher.verifyPublishedConfiguration()) { - System.out.println("OK... Configuration verified"); - System.out.println(String.format("Verified configuration for : %s", publisher.getComponent())); - } else { - System.err.println("ERROR... Published configuration doesn't match the local files. Please check above logs"); - } - System.out.println(); - } - - if (cmdLineOptions.isClear()) { - System.out.println(String.format("Clearing configuration for : %s", publisher.getComponent())); - publisher.clearConfiguration(); - System.out.println(String.format("Cleared configuration for : %s", publisher.getComponent())); - System.out.println(); - } - - publisher.destroy(); - } - } catch (BeansException e) { - logger.error("Error occurred when obtaining configuration publisher beans", e); - throw e; - } catch (Exception e) { - logger.error("Error occurred when publishing configuration to zookeeper", e); - throw e; - } - - logger.info("Exiting CLI ..."); + CmdLineUtility cmdLineUtility = new CmdLineUtility(); + cmdLineUtility.run(args); } } http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/resources/cmd-line-actions.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/cmd-line-actions.xml b/config/src/main/resources/cmd-line-actions.xml new file mode 100644 index 0000000..08f5415 --- /dev/null +++ b/config/src/main/resources/cmd-line-actions.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/resources/cmd-line-options.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/cmd-line-options.xml b/config/src/main/resources/cmd-line-options.xml new file mode 100644 index 0000000..9aff21e --- /dev/null +++ b/config/src/main/resources/cmd-line-options.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/resources/config-publisher.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/config-publisher.xml b/config/src/main/resources/config-publisher.xml new file mode 100644 index 0000000..88ba33b --- /dev/null +++ b/config/src/main/resources/config-publisher.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/resources/etc/config-publisher.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/etc/config-publisher.xml b/config/src/main/resources/etc/config-publisher.xml deleted file mode 100644 index 88ba33b..0000000 --- a/config/src/main/resources/etc/config-publisher.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/resources/etc/log4j.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/etc/log4j.xml b/config/src/main/resources/etc/log4j.xml deleted file mode 100644 index 8cc1919..0000000 --- a/config/src/main/resources/etc/log4j.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/resources/log4j.xml ---------------------------------------------------------------------- diff --git a/config/src/main/resources/log4j.xml b/config/src/main/resources/log4j.xml new file mode 100644 index 0000000..8cc1919 --- /dev/null +++ b/config/src/main/resources/log4j.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/main/scripts/conf-publisher ---------------------------------------------------------------------- diff --git a/config/src/main/scripts/conf-publisher b/config/src/main/scripts/conf-publisher index 618af4b..47c32f2 100644 --- a/config/src/main/scripts/conf-publisher +++ b/config/src/main/scripts/conf-publisher @@ -30,6 +30,10 @@ echo -n "Starting Configuration Publisher" $JAVA_HOME/bin/java \ -cp ${LIB_DEPS} \ -Dlog4j.configuration=etc/log4j.xml \ + -Djava.ext.dirs=. \ + -Djava.util.logging.config.file=${CONF_HOME}/etc/logging.properties \ + -Dorg.apache.oodt.cas.cli.action.spring.config=${CONF_HOME}/policy/cmd-line-actions.xml \ + -Dorg.apache.oodt.cas.cli.option.spring.config=${CONF_HOME}/policy/cmd-line-options.xml \ org.apache.oodt.config.distributed.cli.ConfigPublisher "$@" echo "OK" sleep 1 http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/test/java/org/apache/oodt/config/distributed/AbstractDistributedConfigurationTest.java ---------------------------------------------------------------------- diff --git a/config/src/test/java/org/apache/oodt/config/distributed/AbstractDistributedConfigurationTest.java b/config/src/test/java/org/apache/oodt/config/distributed/AbstractDistributedConfigurationTest.java index e14d43a..4694dfa 100644 --- a/config/src/test/java/org/apache/oodt/config/distributed/AbstractDistributedConfigurationTest.java +++ b/config/src/test/java/org/apache/oodt/config/distributed/AbstractDistributedConfigurationTest.java @@ -36,6 +36,8 @@ public abstract class AbstractDistributedConfigurationTest { zookeeper.start(); System.setProperty(ZK_CONNECT_STRING, zookeeper.getConnectString()); + System.setProperty("org.apache.oodt.cas.cli.action.spring.config", "src/main/resources/cmd-line-actions.xml"); + System.setProperty("org.apache.oodt.cas.cli.option.spring.config", "src/main/resources/cmd-line-options.xml"); client = CuratorUtils.newCuratorFrameworkClient(zookeeper.getConnectString()); client.start(); http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java ---------------------------------------------------------------------- diff --git a/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java b/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java index 9052ac3..71ce713 100644 --- a/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java +++ b/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationManagerTest.java @@ -58,7 +58,7 @@ public class DistributedConfigurationManagerTest extends AbstractDistributedConf ConfigPublisher.main(new String[]{ "-connectString", zookeeper.getConnectString(), - "-publish" + "-a", "publish" }); ApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG_PUBLISHER_XML); @@ -140,7 +140,7 @@ public class DistributedConfigurationManagerTest extends AbstractDistributedConf ConfigPublisher.main(new String[]{ "-connectString", zookeeper.getConnectString(), - "-clear" + "-a", "clear" }); AbstractDistributedConfigurationTest.tearDown(); http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java ---------------------------------------------------------------------- diff --git a/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java b/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java index 2c130db..5a529ed 100644 --- a/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java +++ b/config/src/test/java/org/apache/oodt/config/distributed/DistributedConfigurationPublisherTest.java @@ -43,8 +43,7 @@ public class DistributedConfigurationPublisherTest extends AbstractDistributedCo // Publishing configuration through CLI and verifying whether they were stored correctly ConfigPublisher.main(new String[]{ "-connectString", zookeeper.getConnectString(), - "-publish", - "-verify" + "-a", "publish" }); ApplicationContext applicationContext = new ClassPathXmlApplicationContext(CONFIG_PUBLISHER_XML); @@ -84,7 +83,7 @@ public class DistributedConfigurationPublisherTest extends AbstractDistributedCo // Clearing configuration through CLI and checking whether the configuration has actually been gone ConfigPublisher.main(new String[]{ "-connectString", zookeeper.getConnectString(), - "-clear" + "-a", "clear" }); for (DistributedConfigurationPublisher publisher : publishers) { http://git-wip-us.apache.org/repos/asf/oodt/blob/01331125/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index f6382f4..118d171 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -254,11 +254,6 @@ the License. test - args4j - args4j - 2.33 - - org.apache.cxf cxf-rt-frontend-jaxrs 2.6.0