private String getFormat(CommandContext ctx) throws CommandFormatException { String reportFormat = formatArg.getValue(ctx.getParsedCommandLine(), false); if (reportFormat == null) { reportFormat = "xml"; } return reportFormat; }
@Override public boolean canAppearNext(CommandContext ctx) throws CommandFormatException { return !helpArg.isPresent(ctx.getParsedCommandLine()); } };
@Override protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException { final ModelNode req = new ModelNode(); final ModelNode address = req.get(Util.ADDRESS); if(ctx.isDomainMode()) { address.add(Util.HOST, host.getValue(ctx.getParsedCommandLine(), true)); address.add(Util.SERVER, server.getValue(ctx.getParsedCommandLine(), true)); } address.add(Util.SUBSYSTEM, Util.DATASOURCES); req.get(Util.OPERATION).set(Util.INSTALLED_DRIVERS_LIST); return req; }
@Override public HandledRequest buildHandledRequest(CommandContext ctx, Attachments attachments) throws CommandFormatException { String targetPath = targetFile.getValue(ctx.getParsedCommandLine()); String act = action.getValue(ctx.getParsedCommandLine()); if (act == null || act.isEmpty()) { throw new CommandFormatException("Action is missing"); } AttachmentResponseHandler handler = new AttachmentResponseHandler(ctx, targetPath, act.equals(SAVE), overwrite.isPresent(ctx.getParsedCommandLine()), createDirs.isPresent(ctx.getParsedCommandLine())); return new HandledRequest(buildRequest(ctx, attachments), handler); } }
@Override protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException { format = getFormat(ctx); targetPath = new File(targetFileArg.getValue(ctx.getParsedCommandLine(), true)).toPath(); if (Files.notExists(targetPath.getParent()) || !Files.isDirectory(targetPath.getParent())) { throw new OperationFormatException("Incorrect destination directory " + targetPath.getParent()); } DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(); builder.setOperationName("product-info"); builder.getModelNode().get(FILE).set(true); builder.getModelNode().get("format").set(format); ModelNode request = builder.buildRequest(); return request; }
protected void addHeaders(CommandContext ctx, ModelNode request) throws CommandFormatException { if(!headers.isPresent(ctx.getParsedCommandLine())) { return; } final ModelNode headersNode = headers.toModelNode(ctx); if (headersNode != null && headersNode.getType() != ModelType.OBJECT) { throw new CommandFormatException("--headers option has wrong value '"+headersNode+"'"); } final ModelNode opHeaders = request.get(Util.OPERATION_HEADERS); opHeaders.set(headersNode); }
protected ModelNode redeployAffected(CommandContext ctx) throws CommandLineException { final ParsedCommandLine args = ctx.getParsedCommandLine(); assertNotPresent(serverGroups, args); assertNotPresent(allServerGroups, args); assertNotPresent(allRelevantServerGroups, args); assertNotPresent(content, args); assertNotPresent(deployments, args); assertNotPresent(redeployAffected, args); final String overlay = getName(ctx, false); final ModelNode redeployOp = new ModelNode(); redeployOp.get(Util.OPERATION).set(Util.COMPOSITE); redeployOp.get(Util.ADDRESS).setEmptyList(); final ModelNode steps = redeployOp.get(Util.STEPS); // In domain and standalone, this operation redeploy them all. addRedeployStep(overlay, steps); if(!steps.isDefined() || steps.asList().isEmpty()) { throw new CommandFormatException("None of the deployments affected."); } return redeployOp; }
protected void addAddRedeployLinksSteps(CommandContext ctx, ModelNode steps, String overlay, String serverGroup, String[] links, boolean regexp) throws CommandLineException { boolean warn = false; for(String link : links) { final ModelNode op = new ModelNode(); final ModelNode address = op.get(Util.ADDRESS); if(serverGroup != null) { address.add(Util.SERVER_GROUP, serverGroup); } address.add(Util.DEPLOYMENT_OVERLAY, overlay); address.add(Util.DEPLOYMENT, link); op.get(Util.OPERATION).set(Util.ADD); steps.add(op); if (redeployAffected.isPresent(ctx.getParsedCommandLine())) { addRedeployStep(overlay, link, serverGroup, steps); } else { warn = true; } } if (warn) { String warningMsg = serverGroup == null ? WARN_MSG + Arrays.toString(links) : WARN_MSG + Arrays.toString(links) + " in server group " + serverGroup; ctx.printLine(warningMsg); } }
@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 public boolean canAppearNext(CommandContext ctx) throws CommandFormatException { if(!ctx.isDomainMode()) { return false; } final String actionStr = action.getValue(ctx.getParsedCommandLine()); if(actionStr == null) { return false; } if(ADD.equals(actionStr) || LINK.equals(actionStr)) { return super.canAppearNext(ctx); } return false; } };
@Override protected void recognizeArguments(CommandContext ctx) throws CommandFormatException { String act = getAction(ctx); if (DISPLAY.equals(act)) { if (targetFile.isPresent(ctx.getParsedCommandLine())) { throw new CommandFormatException(targetFile.getFullName() + " can't be used with display action"); } if (overwrite.isPresent(ctx.getParsedCommandLine())) { throw new CommandFormatException(overwrite.getFullName() + " can't be used with display action"); } if (createDirs.isPresent(ctx.getParsedCommandLine())) { throw new CommandFormatException(createDirs.getFullName() + " can't be used with display action"); } } super.recognizeArguments(ctx); }
@Override public boolean canAppearNext(CommandContext ctx) throws CommandFormatException { if(ctx.isDomainMode()) { return host.isPresent(ctx.getParsedCommandLine()) && server.isPresent(ctx.getParsedCommandLine()) && super.canAppearNext(ctx); } return super.canAppearNext(ctx); } };
@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); } }
@Override protected void handleResponse(CommandContext ctx, OperationResponse response, boolean composite) throws CommandLineException { ModelNode result = response.getResponseNode(); String targetPath = targetFile.getValue(ctx.getParsedCommandLine()); String act = action.getValue(ctx.getParsedCommandLine()); if (act == null || act.isEmpty()) { throw new CommandFormatException("Action is missing"); } AttachmentResponseHandler handler = new AttachmentResponseHandler(ctx, targetPath, act.equals(SAVE), overwrite.isPresent(ctx.getParsedCommandLine()), createDirs.isPresent(ctx.getParsedCommandLine())); handler.handleResponse(result, response); }
@Override protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException { final ModelNode req = new ModelNode(); final ModelNode address = req.get(Util.ADDRESS); if(ctx.isDomainMode()) { address.add(Util.HOST, host.getValue(ctx.getParsedCommandLine(), true)); address.add(Util.SERVER, server.getValue(ctx.getParsedCommandLine(), true)); } address.add(Util.SUBSYSTEM, Util.DATASOURCES); req.get(Util.OPERATION).set(Util.INSTALLED_DRIVERS_LIST); return req; }
@Override protected ModelNode buildRequestWithoutHeaders(CommandContext ctx) throws CommandFormatException { format = getFormat(ctx); targetPath = new File(targetFileArg.getValue(ctx.getParsedCommandLine(), true)).toPath(); if (Files.notExists(targetPath.getParent()) || !Files.isDirectory(targetPath.getParent())) { throw new OperationFormatException("Incorrect destination directory " + targetPath.getParent()); } DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder(); builder.setOperationName("product-info"); builder.getModelNode().get(FILE).set(true); builder.getModelNode().get("format").set(format); ModelNode request = builder.buildRequest(); return request; }
protected void addHeaders(CommandContext ctx, ModelNode request) throws CommandFormatException { if(!headers.isPresent(ctx.getParsedCommandLine())) { return; } final ModelNode headersNode = headers.toModelNode(ctx); if (headersNode != null && headersNode.getType() != ModelType.OBJECT) { throw new CommandFormatException("--headers option has wrong value '"+headersNode+"'"); } final ModelNode opHeaders = request.get(Util.OPERATION_HEADERS); opHeaders.set(headersNode); }
protected ModelNode redeployAffected(CommandContext ctx) throws CommandLineException { final ParsedCommandLine args = ctx.getParsedCommandLine(); assertNotPresent(serverGroups, args); assertNotPresent(allServerGroups, args); assertNotPresent(allRelevantServerGroups, args); assertNotPresent(content, args); assertNotPresent(deployments, args); assertNotPresent(redeployAffected, args); final String overlay = getName(ctx, false); final ModelNode redeployOp = new ModelNode(); redeployOp.get(Util.OPERATION).set(Util.COMPOSITE); redeployOp.get(Util.ADDRESS).setEmptyList(); final ModelNode steps = redeployOp.get(Util.STEPS); // In domain and standalone, this operation redeploy them all. addRedeployStep(overlay, steps); if(!steps.isDefined() || steps.asList().isEmpty()) { throw new CommandFormatException("None of the deployments affected."); } return redeployOp; }
protected void addAddRedeployLinksSteps(CommandContext ctx, ModelNode steps, String overlay, String serverGroup, String[] links, boolean regexp) throws CommandLineException { boolean warn = false; for(String link : links) { final ModelNode op = new ModelNode(); final ModelNode address = op.get(Util.ADDRESS); if(serverGroup != null) { address.add(Util.SERVER_GROUP, serverGroup); } address.add(Util.DEPLOYMENT_OVERLAY, overlay); address.add(Util.DEPLOYMENT, link); op.get(Util.OPERATION).set(Util.ADD); steps.add(op); if (redeployAffected.isPresent(ctx.getParsedCommandLine())) { addRedeployStep(overlay, link, serverGroup, steps); } else { warn = true; } } if (warn) { String warningMsg = serverGroup == null ? WARN_MSG + Arrays.toString(links) : WARN_MSG + Arrays.toString(links) + " in server group " + serverGroup; ctx.printLine(warningMsg); } }
@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; }