diff options
| author | Endi S. Dewata <edewata@redhat.com> | 2013-10-01 12:36:55 -0400 |
|---|---|---|
| committer | Endi S. Dewata <edewata@redhat.com> | 2013-10-08 10:02:59 -0400 |
| commit | 634d615d1832d7d86bc77af9d939a9d282c96350 (patch) | |
| tree | 6eaadc2678cf66b63ca90ed83fa8418604488584 /base/java-tools/src/com | |
| parent | 99def3060c7c59ea5727a5555adb7b4af3fc4887 (diff) | |
| download | pki-634d615d1832d7d86bc77af9d939a9d282c96350.tar.gz pki-634d615d1832d7d86bc77af9d939a9d282c96350.tar.xz pki-634d615d1832d7d86bc77af9d939a9d282c96350.zip | |
Added selftest resource.
New REST service and clients have been added for managing selftests
in all subsystems.
Ticket #652
Diffstat (limited to 'base/java-tools/src/com')
9 files changed, 320 insertions, 0 deletions
diff --git a/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java b/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java index ce253d884..fdef872fb 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/CACLI.java @@ -21,6 +21,7 @@ package com.netscape.cmstools.cli; import com.netscape.certsrv.ca.CAClient; import com.netscape.certsrv.client.Client; import com.netscape.cmstools.group.GroupCLI; +import com.netscape.cmstools.selftests.SelfTestCLI; import com.netscape.cmstools.user.UserCLI; /** @@ -34,6 +35,7 @@ public class CACLI extends SubsystemCLI { super("ca", "CA management commands", parent); addModule(new GroupCLI(this)); + addModule(new SelfTestCLI(this)); addModule(new UserCLI(this)); } diff --git a/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java b/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java index ecc72688a..3929b6f8d 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/KRACLI.java @@ -21,6 +21,7 @@ package com.netscape.cmstools.cli; import com.netscape.certsrv.client.Client; import com.netscape.certsrv.kra.KRAClient; import com.netscape.cmstools.group.GroupCLI; +import com.netscape.cmstools.selftests.SelfTestCLI; import com.netscape.cmstools.user.UserCLI; /** @@ -34,6 +35,7 @@ public class KRACLI extends SubsystemCLI { super("kra", "KRA management commands", parent); addModule(new GroupCLI(this)); + addModule(new SelfTestCLI(this)); addModule(new UserCLI(this)); } diff --git a/base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java index e28b97cdb..3768a48e7 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/OCSPCLI.java @@ -21,6 +21,7 @@ package com.netscape.cmstools.cli; import com.netscape.certsrv.client.Client; import com.netscape.certsrv.ocsp.OCSPClient; import com.netscape.cmstools.group.GroupCLI; +import com.netscape.cmstools.selftests.SelfTestCLI; import com.netscape.cmstools.user.UserCLI; /** @@ -34,6 +35,7 @@ public class OCSPCLI extends SubsystemCLI { super("ocsp", "OCSP management commands", parent); addModule(new GroupCLI(this)); + addModule(new SelfTestCLI(this)); addModule(new UserCLI(this)); } diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java index b8c90ed47..dd4f179c2 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/TKSCLI.java @@ -21,6 +21,7 @@ package com.netscape.cmstools.cli; import com.netscape.certsrv.client.Client; import com.netscape.certsrv.tks.TKSClient; import com.netscape.cmstools.group.GroupCLI; +import com.netscape.cmstools.selftests.SelfTestCLI; import com.netscape.cmstools.system.TPSConnectorCLI; import com.netscape.cmstools.user.UserCLI; @@ -35,6 +36,7 @@ public class TKSCLI extends SubsystemCLI { super("tks", "TKS management commands", parent); addModule(new GroupCLI(this)); + addModule(new SelfTestCLI(this)); addModule(new TPSConnectorCLI(this)); addModule(new UserCLI(this)); } diff --git a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java index 09596fae7..a3fe27eb8 100644 --- a/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java +++ b/base/java-tools/src/com/netscape/cmstools/cli/TPSCLI.java @@ -22,6 +22,7 @@ import com.netscape.certsrv.client.Client; import com.netscape.certsrv.tps.TPSClient; import com.netscape.cmstools.group.GroupCLI; import com.netscape.cmstools.logging.ActivityCLI; +import com.netscape.cmstools.selftests.SelfTestCLI; import com.netscape.cmstools.tps.authenticator.AuthenticatorCLI; import com.netscape.cmstools.tps.cert.TPSCertCLI; import com.netscape.cmstools.tps.config.ConfigCLI; @@ -47,6 +48,7 @@ public class TPSCLI extends SubsystemCLI { addModule(new ConnectionCLI(this)); addModule(new GroupCLI(this)); addModule(new ProfileCLI(this)); + addModule(new SelfTestCLI(this)); addModule(new TokenCLI(this)); addModule(new UserCLI(this)); } diff --git a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestCLI.java b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestCLI.java new file mode 100644 index 000000000..2e64e0576 --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestCLI.java @@ -0,0 +1,63 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.selftests; + +import java.io.IOException; + +import org.jboss.resteasy.plugins.providers.atom.Link; + +import com.netscape.certsrv.selftests.SelfTestClient; +import com.netscape.certsrv.selftests.SelfTestData; +import com.netscape.cmstools.cli.CLI; +/** + * @author Endi S. Dewata + */ +public class SelfTestCLI extends CLI { + + public SelfTestClient selfTestClient; + + public SelfTestCLI(CLI parent) { + super("selftest", "Selftest management commands", parent); + + addModule(new SelfTestFindCLI(this)); + addModule(new SelfTestRunCLI(this)); + addModule(new SelfTestShowCLI(this)); + } + + public void execute(String[] args) throws Exception { + + client = parent.getClient(); + selfTestClient = (SelfTestClient)parent.getClient("selftest"); + + super.execute(args); + } + + public static void printSelfTestData(SelfTestData selfTestData) throws IOException { + System.out.println(" SelfTest ID: " + selfTestData.getID()); + if (selfTestData.isEnabledAtStartup() != null) System.out.println(" Enabled at startup: " + selfTestData.isEnabledAtStartup()); + if (selfTestData.isCriticalAtStartup() != null) System.out.println(" Critical at startup: " + selfTestData.isCriticalAtStartup()); + if (selfTestData.isEnabledOnDemand() != null) System.out.println(" Enabled on demand: " + selfTestData.isEnabledOnDemand()); + if (selfTestData.isCriticalOnDemand() != null) System.out.println(" Critical on demand: " + selfTestData.isCriticalOnDemand()); + + Link link = selfTestData.getLink(); + if (verbose && link != null) { + System.out.println(" Link: " + link.getHref()); + } + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java new file mode 100644 index 000000000..245c9a61e --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestFindCLI.java @@ -0,0 +1,94 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.selftests; + +import java.util.Collection; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.selftests.SelfTestCollection; +import com.netscape.certsrv.selftests.SelfTestData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class SelfTestFindCLI extends CLI { + + public SelfTestCLI selfTestCLI; + + public SelfTestFindCLI(SelfTestCLI selfTestCLI) { + super("find", "Find selftests", selfTestCLI); + this.selfTestCLI = selfTestCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " [OPTIONS...]", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "start", true, "Page start"); + option.setArgName("start"); + options.addOption(option); + + option = new Option(null, "size", true, "Page size"); + option.setArgName("size"); + options.addOption(option); + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(1); + } + + String s = cmd.getOptionValue("start"); + Integer start = s == null ? null : Integer.valueOf(s); + + s = cmd.getOptionValue("size"); + Integer size = s == null ? null : Integer.valueOf(s); + + SelfTestCollection result = selfTestCLI.selfTestClient.findSelfTests(start, size); + Collection<SelfTestData> selfTests = result.getEntries(); + + MainCLI.printMessage(selfTests.size() + " connection(s) matched"); + + boolean first = true; + + for (SelfTestData selfTestInfo : selfTests) { + + if (first) { + first = false; + } else { + System.out.println(); + } + + SelfTestCLI.printSelfTestData(selfTestInfo); + } + + MainCLI.printMessage("Number of entries returned " + selfTests.size()); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java new file mode 100644 index 000000000..b4b51084a --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestRunCLI.java @@ -0,0 +1,66 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.selftests; + +import org.apache.commons.cli.CommandLine; + +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class SelfTestRunCLI extends CLI { + + public SelfTestCLI selfTestCLI; + + public SelfTestRunCLI(SelfTestCLI selfTestCLI) { + super("run", "Run selftests", selfTestCLI); + this.selfTestCLI = selfTestCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName(), options); + } + + public void execute(String[] args) throws Exception { + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(1); + } + + String[] cmdArgs = cmd.getArgs(); + + if (cmdArgs.length != 0) { + printHelp(); + System.exit(1); + } + + selfTestCLI.selfTestClient.executeSelfTests("run"); + + MainCLI.printMessage("Selftests completed"); + } +} diff --git a/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestShowCLI.java b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestShowCLI.java new file mode 100644 index 000000000..88527b32d --- /dev/null +++ b/base/java-tools/src/com/netscape/cmstools/selftests/SelfTestShowCLI.java @@ -0,0 +1,87 @@ +// --- BEGIN COPYRIGHT BLOCK --- +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; version 2 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this program; if not, write to the Free Software Foundation, Inc., +// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +// +// (C) 2013 Red Hat, Inc. +// All rights reserved. +// --- END COPYRIGHT BLOCK --- + +package com.netscape.cmstools.selftests; + +import java.io.FileWriter; +import java.io.PrintWriter; + +import org.apache.commons.cli.CommandLine; +import org.apache.commons.cli.Option; + +import com.netscape.certsrv.selftests.SelfTestData; +import com.netscape.cmstools.cli.CLI; +import com.netscape.cmstools.cli.MainCLI; + +/** + * @author Endi S. Dewata + */ +public class SelfTestShowCLI extends CLI { + + public SelfTestCLI selfTestCLI; + + public SelfTestShowCLI(SelfTestCLI selfTestCLI) { + super("show", "Show selftest", selfTestCLI); + this.selfTestCLI = selfTestCLI; + } + + public void printHelp() { + formatter.printHelp(getFullName() + " <SelfTest ID>", options); + } + + public void execute(String[] args) throws Exception { + + Option option = new Option(null, "output", true, "Output file to store selfTest properties."); + option.setArgName("file"); + options.addOption(option); + + CommandLine cmd = null; + + try { + cmd = parser.parse(options, args); + + } catch (Exception e) { + System.err.println("Error: " + e.getMessage()); + printHelp(); + System.exit(1); + } + + String[] cmdArgs = cmd.getArgs(); + + if (cmdArgs.length != 1) { + printHelp(); + System.exit(1); + } + + String selfTestID = args[0]; + String output = cmd.getOptionValue("output"); + + SelfTestData selfTestInfo = selfTestCLI.selfTestClient.getSelfTest(selfTestID); + + if (output == null) { + MainCLI.printMessage("SelfTest \"" + selfTestID + "\""); + SelfTestCLI.printSelfTestData(selfTestInfo); + + } else { + try (PrintWriter out = new PrintWriter(new FileWriter(output))) { + out.println(selfTestInfo); + } + MainCLI.printMessage("Stored selfTest \"" + selfTestID + "\" into " + output); + } + } +} |
