This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
523 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 15 additions & 22 deletions
37
src/main/java/uk/gov/justice/CatchUpAndShutteringManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,38 @@ | ||
package uk.gov.justice; | ||
|
||
import static org.slf4j.LoggerFactory.getLogger; | ||
import static uk.gov.justice.Operations.CATCHUP; | ||
import static uk.gov.justice.Operations.SHUTTER; | ||
import static uk.gov.justice.Operations.UNSHUTTER; | ||
|
||
import uk.gov.justice.jmx.tools.CatchUpInvoker; | ||
import uk.gov.justice.jmx.tools.ShutteringInvoker; | ||
import uk.gov.justice.framework.command.tools.CommandLineArgumentParser; | ||
import uk.gov.justice.framework.command.tools.SystemCommandInvoker; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
|
||
import org.slf4j.Logger; | ||
|
||
@ApplicationScoped | ||
public class CatchUpAndShutteringManager { | ||
|
||
private static final Logger logger = getLogger(CatchUpAndShutteringManager.class.getName()); | ||
|
||
/** | ||
* | ||
* @param args operation, host, port | ||
* @throws Exception | ||
*/ | ||
public static void main(String... args) throws Exception { | ||
public static void main(String... args) { | ||
boolean argumentParsed = new CommandLineArgumentParser(args).parse(); | ||
|
||
final String operation = args[0]; | ||
final String host = args[1]; | ||
final String port = args[2]; | ||
if(argumentParsed){ | ||
final String command = args[0]; | ||
final String host = args[1]; | ||
final String port = args[2]; | ||
|
||
logger.info("Operation: {}", operation); | ||
logger.info("Host: {}", host); | ||
logger.info("Port: {}", port); | ||
SystemCommandInvoker systemCommandInvoker = new SystemCommandInvoker(); | ||
|
||
if(operation.equalsIgnoreCase(SHUTTER.name())){ | ||
new ShutteringInvoker().runShuttering(true, host, port); | ||
} | ||
if(operation.equalsIgnoreCase(UNSHUTTER.name())){ | ||
new ShutteringInvoker().runShuttering(false, host, port); | ||
systemCommandInvoker.runSystemCommand(command, host, port); | ||
|
||
logger.info("CatchUpAndShutteringManager invoked successfully"); | ||
} | ||
if(operation.equalsIgnoreCase(CATCHUP.name())){ | ||
new CatchUpInvoker().runCatchup(host, port); | ||
else{ | ||
logger.error("CatchUpAndShutteringManager not invoked successfully!!! Please check command line arguments & usage"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package uk.gov.justice; | ||
|
||
public enum Operation {SHUTTER, UNSHUTTER, CATCHUP, REBUILD, UNKNOWN} |
This file was deleted.
Oops, something went wrong.
78 changes: 78 additions & 0 deletions
78
src/main/java/uk/gov/justice/framework/command/tools/CommandLineArgumentParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package uk.gov.justice.framework.command.tools; | ||
|
||
import static org.apache.commons.lang3.StringUtils.isNotBlank; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
import org.apache.commons.cli.BasicParser; | ||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.HelpFormatter; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
import org.slf4j.Logger; | ||
|
||
|
||
public class CommandLineArgumentParser { | ||
|
||
private static final Logger logger = getLogger(CommandLineArgumentParser.class.getName()); | ||
|
||
private String[] args; | ||
private Options options = new Options(); | ||
|
||
|
||
public CommandLineArgumentParser(String[] args) { | ||
|
||
this.args = args; | ||
|
||
options.addOption("h", "help", false, "show help."); | ||
options.addOption("c", "command", true, "Framework command to execute, for example CATCHUP,SHUTTER, UNSHUTTER & REBUILD."); | ||
options.addOption("ho", "host", true, "Host Remote or Localhost"); | ||
options.addOption("p", "port", true, "Wildfly management port"); | ||
} | ||
|
||
public boolean parse() { | ||
CommandLineParser parser = new BasicParser(); | ||
|
||
try { | ||
CommandLine cmd = parser.parse(options, args); | ||
|
||
if (cmd.hasOption("h")){ | ||
help(); | ||
} | ||
|
||
if (isCommandNullOrEmpty(cmd) && isHostNullOrEmpty(cmd) && isPortNullOrEmpty(cmd)) { | ||
return true; | ||
} else { | ||
help(); | ||
return false; | ||
} | ||
|
||
} catch (ParseException e) { | ||
logger.info("Failed to parse command line properties", e); | ||
help(); | ||
return false; | ||
} | ||
} | ||
|
||
private void help() { | ||
// This prints out some help | ||
HelpFormatter formatter = new HelpFormatter(); | ||
|
||
formatter.printHelp("CatchUpAndShutteringManager", options); | ||
} | ||
|
||
private boolean isCommandNullOrEmpty(CommandLine cmd){ | ||
return cmd.hasOption("c") && | ||
(isNotBlank(cmd.getOptionValue("c"))); | ||
} | ||
|
||
private boolean isHostNullOrEmpty(CommandLine cmd){ | ||
return cmd.hasOption("ho") && | ||
isNotBlank(cmd.getOptionValue("ho")); | ||
} | ||
|
||
private boolean isPortNullOrEmpty(CommandLine cmd){ | ||
return cmd.hasOption("p") && | ||
isNotBlank(cmd.getOptionValue("p")); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/uk/gov/justice/framework/command/tools/EnumValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package uk.gov.justice.framework.command.tools; | ||
|
||
import uk.gov.justice.Operation; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
@ApplicationScoped | ||
public class EnumValidator { | ||
|
||
|
||
public boolean checkCommandIsValid(final String command) { | ||
return contains(Operation.class, command); | ||
} | ||
|
||
private static boolean contains(Class<? extends Enum> clazz, String val) { | ||
Enum[] arr = clazz.getEnumConstants(); | ||
for (Enum operation : arr) { | ||
if (operation.name().equals(val)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
Oops, something went wrong.