@Override protected OnlineManagementClient create(OnlineOptions options) throws IOException { return new OnlineManagementClientImpl(options); }
@Override public void apply(OnlineCommand... commands) throws CommandFailedException { apply(Arrays.asList(commands)); }
OnlineManagementClientImpl(OnlineOptions options) throws IOException { this.options = options; this.adjustOperationForDomain = new AdjustOperationForDomain(options); connect(); }
@Override public void apply(Iterable<OnlineCommand> commands) throws CommandFailedException { checkClosed(); try { OnlineManagementClient client = AutomaticErrorHandlingForCommands.wrap(this); OnlineCommandContext ctx = new OnlineCommandContext(client, version); for (OnlineCommand command : commands) { log.infof("Applying command %s", command); command.apply(ctx); } } catch (RuntimeCommandFailedException e) { throw e.original; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new CommandFailedException(e); } catch (Exception e) { throw new CommandFailedException(e); } }
fakeJbossCliConfigToAvoidWarning(); checkStandaloneVsDomain(); } catch (Exception e) { try {
private void checkStandaloneVsDomain() throws IOException { ModelNode op = new ModelNode(); op.get(Constants.OP).set(Constants.READ_CHILDREN_TYPES); op.get(Constants.OP_ADDR).setEmptyList(); ModelNodeResult result = this.execute(op); List<String> rootChildrenTypes = result.stringListValue(); if (options.isStandalone && !rootChildrenTypes.contains(Constants.SUBSYSTEM)) { throw new IllegalStateException("According to the options, this client should be connected" + " to a standalone server, but the server appears to be something else"); } else if (options.isDomain && !rootChildrenTypes.contains(Constants.PROFILE)) { throw new IllegalStateException("According to the options, this client should be connected" + " to a domain controller, but the server appears to be something else"); } }
@Override public void executeCli(String cliOperation) throws CliException, IOException { if (cliOperation.trim().startsWith("connect")) { throw new CliException("The 'connect' operation is not supported"); } checkClosed(); cliOperation = adjustOperationForDomain.adjust(cliOperation); log.debugf("Executing CLI operation %s", cliOperation); try { if ("reload".equals(cliOperation.trim())) { // CLI requires a special implementation of ModelControllerClient for "reload" and "shutdown", // but we only have the standard one, so these operations won't work // // however, "reload" with no options is particularly common in CLI scripts, so this special case // helps in those situations new Administration(this).reload(); } else { cliContext.handle(cliOperation); } } catch (Exception e) { if (e.getCause() instanceof IOException) { throw (IOException) e.getCause(); } throw new CliException(e); } if (cliContext.getExitCode() != 0 || cliContext.isTerminated()) { throw new CliException("CLI operation failed: " + cliOperation); } }
@Override public ModelNodeResult execute(String operation) throws CliException, IOException { checkClosed(); operation = adjustOperationForDomain.adjust(operation); log.debugf("Executing operation %s", operation); ModelNode parsedOperation; try { parsedOperation = cliContext.buildRequest(operation); } catch (CommandFormatException e) { throw new CliException(e); } ModelNode result = client.execute(parsedOperation); return new ModelNodeResult(result); }
@Override public void reconnect(int timeoutInSeconds) throws TimeoutException, InterruptedException { if (options.isWrappedClient) { throw new UnsupportedOperationException("Can't reconnect a wrapped client"); } log.info("Reconnecting the client"); try { client.close(); cliContext.disconnectController(); } catch (Throwable ignored) { } long endTime = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(timeoutInSeconds); while (System.currentTimeMillis() < endTime) { try { connect(); return; } catch (Throwable e) { log.info(e.getMessage()); // server is probably down, will retry } Thread.sleep(500); } throw new TimeoutException("Timeout reconnecting to server"); }
@Override public ModelNodeResult execute(ModelNode operation) throws IOException { checkClosed(); operation = adjustOperationForDomain.adjust(operation); log.debugf("Executing operation %s", ModelNodeOperationToCliString.convert(operation)); log.tracef("JSON format:%n%s", operation.toJSONString(false)); ModelNode result = client.execute(operation); return new ModelNodeResult(result); }
@Override public ModelNodeResult execute(Operation operation) throws IOException { checkClosed(); operation = adjustOperationForDomain.adjust(operation); log.debugf("Executing operation %s", ModelNodeOperationToCliString.convert(operation.getOperation())); log.tracef("JSON format:%n%s", operation.getOperation().toJSONString(false)); ModelNode result = client.execute(operation); return new ModelNodeResult(result); }