@Override public void addTo(CommandContext ctx, ModelNode headers) throws CommandFormatException { if(name == null) { throw new CommandFormatException("Header name is null."); } if(value == null) { throw new CommandFormatException("Value for header '" + name + "' is null."); } headers.get(name).set(value); } }
@Override protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException { final String op = operation.getValue(ctx.getParsedCommandLine()); if (op == null) { throw new CommandFormatException("Invalid operation"); } ModelNode mn = ctx.buildRequest(op); return mn; }
protected String[] getLinks(ArgumentWithValue linksArg, final ParsedCommandLine args) throws CommandFormatException { final String deploymentsStr = linksArg.getValue(args); final String[] deployments; if(deploymentsStr == null) { deployments = null; } else { deployments = deploymentsStr.split(",+"); if(deployments.length == 0) { throw new CommandFormatException(linksArg.getFullName() + " is missing value."); } } return deployments; }
@Override public ModelNode buildRequest(CommandContext context) throws CommandFormatException { ModelNode composite = new ModelNode(); composite.get(Util.OPERATION).set(Util.COMPOSITE); composite.get(Util.ADDRESS).setEmptyList(); try { managementInterface = ManagementInterfaces.disableSSL(context, managementInterface, composite.get(Util.STEPS)); } catch (Exception ex) { throw new CommandFormatException(ex.getLocalizedMessage() == null ? ex.toString() : ex.getLocalizedMessage(), ex); } return composite; }
public static boolean isEnabledDeployment(String name, ModelControllerClient client, String serverGroup) throws OperationFormatException, IOException, CommandFormatException { DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(); if (serverGroup != null) { builder.addNode(Util.SERVER_GROUP, serverGroup); } builder.addNode(Util.DEPLOYMENT, name); builder.setOperationName(Util.READ_ATTRIBUTE); builder.addProperty(Util.NAME, Util.ENABLED); ModelNode request = builder.buildRequest(); ModelNode outcome = client.execute(request); if (isSuccess(outcome)) { if (!outcome.hasDefined(RESULT)) { throw new CommandFormatException("No result for " + name); } return outcome.get(RESULT).asBoolean(); } return false; }
@Override protected void doHandle(CommandContext ctx) throws CommandLineException { final List<String> names = ctx.getParsedCommandLine().getOtherProperties(); if(names.isEmpty()) { throw new CommandFormatException("Variable name is missing"); } for (String name : names) { if (name.charAt(0) == '$') { name = name.substring(1); if (name.isEmpty()) { throw new CommandFormatException("Variable name is missing after '$'"); } } ctx.setVariable(name, null); } }
@Override public ModelNode buildRequest(CommandContext context) throws CommandFormatException { ModelNode composite = new ModelNode(); composite.get(Util.OPERATION).set(Util.COMPOSITE); composite.get(Util.ADDRESS).setEmptyList(); try { serverName = HTTPServer.disableSSL(context, serverName, composite.get(Util.STEPS)); } catch (Exception ex) { throw new CommandFormatException(ex.getLocalizedMessage() == null ? ex.toString() : ex.getLocalizedMessage(), ex); } return composite; }
@Override public void addTo(CommandContext ctx, ModelNode headers) throws CommandFormatException { if(name == null) { throw new CommandFormatException("Header name is null."); } if(value == null) { throw new CommandFormatException("Value for header '" + name + "' is null."); } headers.get(name).set(value); } }
public static boolean isEnabledDeployment(String name, ModelControllerClient client, String serverGroup) throws OperationFormatException, IOException, CommandFormatException { DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(); if (serverGroup != null) { builder.addNode(Util.SERVER_GROUP, serverGroup); } builder.addNode(Util.DEPLOYMENT, name); builder.setOperationName(Util.READ_ATTRIBUTE); builder.addProperty(Util.NAME, Util.ENABLED); ModelNode request = builder.buildRequest(); ModelNode outcome = client.execute(request); if (isSuccess(outcome)) { if (!outcome.hasDefined(RESULT)) { throw new CommandFormatException("No result for " + name); } return outcome.get(RESULT).asBoolean(); } return false; }
@Override protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException { final String op = operation.getValue(ctx.getParsedCommandLine()); if (op == null) { throw new CommandFormatException("Invalid operation"); } ModelNode mn = ctx.buildRequest(op); return mn; }
@Override protected void doHandle(CommandContext ctx) throws CommandLineException { final List<String> names = ctx.getParsedCommandLine().getOtherProperties(); if(names.isEmpty()) { throw new CommandFormatException("Variable name is missing"); } for (String name : names) { if (name.charAt(0) == '$') { name = name.substring(1); if (name.isEmpty()) { throw new CommandFormatException("Variable name is missing after '$'"); } } ctx.setVariable(name, null); } }
protected String[] getLinks(ArgumentWithValue linksArg, final ParsedCommandLine args) throws CommandFormatException { final String deploymentsStr = linksArg.getValue(args); final String[] deployments; if(deploymentsStr == null) { deployments = null; } else { deployments = deploymentsStr.split(",+"); if(deployments.length == 0) { throw new CommandFormatException(linksArg.getFullName() + " is missing value."); } } return deployments; }
@Override public ModelNode buildRequest(CommandContext context) throws CommandFormatException { ModelNode composite = new ModelNode(); composite.get(Util.OPERATION).set(Util.COMPOSITE); composite.get(Util.ADDRESS).setEmptyList(); try { serverName = HTTPServer.disableSSL(context, serverName, composite.get(Util.STEPS)); } catch (Exception ex) { throw new CommandFormatException(ex.getLocalizedMessage() == null ? ex.toString() : ex.getLocalizedMessage(), ex); } return composite; }
protected static void setPropertyMapValue(ModelNode request, String name, String value) throws CommandFormatException { if(name == null || name.trim().isEmpty()) throw new IllegalArgumentException("The argument name is not specified: '" + name + "'"); if(value == null || value.trim().isEmpty()) throw new IllegalArgumentException("The argument value is not specified: '" + value + "'"); ModelNode nodeValue = new ModelNode(); String[] props = value.split(","); for(String prop : props) { int equals = prop.indexOf('='); if(equals == -1) { throw new CommandFormatException("Property '" + prop + "' in '" + value + "' is missing the equals sign."); } String propName = prop.substring(0, equals); if(propName.isEmpty()) { throw new CommandFormatException("Property name is missing for '" + prop + "' in '" + value + "'"); } nodeValue.add(propName, prop.substring(equals + 1)); } request.get(name).set(nodeValue); } }
@Override protected void doHandle(CommandContext ctx) throws CommandLineException { final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine(); final String actionValue = action.getValue(parsedCmd); if(actionValue == null) { throw new CommandFormatException("Action argument is missing: " + ACTION_ADD + " or " + ACTION_REMOVE); } if(ACTION_ADD.equals(actionValue)) { addModule(ctx, parsedCmd); } else if(ACTION_REMOVE.equals(actionValue)) { removeModule(parsedCmd, ctx); } else { throw new CommandFormatException("Unexpected action '" + actionValue + "', expected values: " + ACTION_ADD + ", " + ACTION_REMOVE); } }
@Override protected void recognizeArguments(CommandContext ctx) throws CommandFormatException { final Map<String, CommandArgument> allArgs = getAllArguments(ctx); if(!allArgs.keySet().containsAll(ctx.getParsedCommandLine().getPropertyNames())) { final Set<String> unrecognized = new HashSet<String>(ctx.getParsedCommandLine().getPropertyNames()); unrecognized.removeAll(allArgs.keySet()); throw new CommandFormatException("Unrecognized arguments: " + unrecognized); } }
protected void assertNotPresent(ArgumentWithoutValue arg, ParsedCommandLine args) throws CommandFormatException { if(arg.isPresent(args)) { throw new CommandFormatException(arg.getFullName() + " is not allowed with action '" + action.getValue(args) + "'"); } }
@Override public ModelNode buildRequest(CommandContext context) throws CommandFormatException { ModelNode composite = new ModelNode(); composite.get(Util.OPERATION).set(Util.COMPOSITE); composite.get(Util.ADDRESS).setEmptyList(); try { managementInterface = ManagementInterfaces.disableSSL(context, managementInterface, composite.get(Util.STEPS)); } catch (Exception ex) { throw new CommandFormatException(ex.getLocalizedMessage() == null ? ex.toString() : ex.getLocalizedMessage(), ex); } return composite; }
protected static void setPropertyMapValue(ModelNode request, String name, String value) throws CommandFormatException { if(name == null || name.trim().isEmpty()) throw new IllegalArgumentException("The argument name is not specified: '" + name + "'"); if(value == null || value.trim().isEmpty()) throw new IllegalArgumentException("The argument value is not specified: '" + value + "'"); ModelNode nodeValue = new ModelNode(); String[] props = value.split(","); for(String prop : props) { int equals = prop.indexOf('='); if(equals == -1) { throw new CommandFormatException("Property '" + prop + "' in '" + value + "' is missing the equals sign."); } String propName = prop.substring(0, equals); if(propName.isEmpty()) { throw new CommandFormatException("Property name is missing for '" + prop + "' in '" + value + "'"); } nodeValue.add(propName, prop.substring(equals + 1)); } request.get(name).set(nodeValue); } }
@Override protected void doHandle(CommandContext ctx) throws CommandLineException { final ParsedCommandLine parsedCmd = ctx.getParsedCommandLine(); final String actionValue = action.getValue(parsedCmd); if(actionValue == null) { throw new CommandFormatException("Action argument is missing: " + ACTION_ADD + " or " + ACTION_REMOVE); } if(ACTION_ADD.equals(actionValue)) { addModule(ctx, parsedCmd); } else if(ACTION_REMOVE.equals(actionValue)) { removeModule(parsedCmd, ctx); } else { throw new CommandFormatException("Unexpected action '" + actionValue + "', expected values: " + ACTION_ADD + ", " + ACTION_REMOVE); } }