Package org.jboss.as.controller.client

Examples of org.jboss.as.controller.client.ModelControllerClient


        public ValueCompleter(final String attrName) {
            super(new CandidatesProvider() {
                @Override
                public List<String> getAllCandidates(CommandContext ctx) {
                    ModelControllerClient client = ctx.getModelControllerClient();
                    if(client == null) {
                        return Collections.emptyList();
                    }

                    DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();
                    if (ctx.isDomainMode()) {
                        final String profileName = profile.getValue(ctx.getParsedCommandLine());
                        if (profileName == null) {
                            return Collections.emptyList();
                        }
                        builder.addNode("profile", profileName);
                    }
                    builder.addNode("subsystem", "datasources");

                    final String dsName = jndiName.getValue(ctx.getParsedCommandLine());
                    if(dsName == null) {
                        return Collections.emptyList();
                    }
                    builder.addNode(dsType, dsName);

                    builder.setOperationName("read-attribute");
                    builder.addProperty("name", attrName);

                    try {
                        ModelNode result = client.execute(builder.buildRequest());
                        if(!result.hasDefined("result"))
                            return Collections.emptyList();
                        return Collections.singletonList(result.get("result").asString());
                    } catch (Exception e) {
                        return Collections.emptyList();
View Full Code Here


    ManagementResourceRegistration getRootRegistration() {
        return rootRegistration;
    }

    public ModelControllerClient createClient(final Executor executor) {
        return new ModelControllerClient() {

            @Override
            public void close() throws IOException {
                // whatever
            }
View Full Code Here

        };

        name = new ArgumentWithValue(this, new DefaultCompleter(new DefaultCompleter.CandidatesProvider() {
            @Override
            public List<String> getAllCandidates(CommandContext ctx) {
                ModelControllerClient client = ctx.getModelControllerClient();
                if (client == null) {
                    return Collections.emptyList();
                    }

                final String profileArg;
View Full Code Here

        operation.addCantAppearAfter(helpArg);

        name = new ArgumentWithValue(this, new DefaultCompleter(new DefaultCompleter.CandidatesProvider() {
            @Override
            public List<String> getAllCandidates(CommandContext ctx) {
                ModelControllerClient client = ctx.getModelControllerClient();
                if (client == null) {
                    return Collections.emptyList();
                }
                DefaultOperationRequestAddress address = new DefaultOperationRequestAddress();
                if(dependsOnProfile && ctx.isDomainMode()) {
View Full Code Here

    }

    @Override
    protected void doHandle(CommandContext ctx) throws CommandFormatException {

        ModelControllerClient client = ctx.getModelControllerClient();

        ParsedCommandLine args = ctx.getParsedCommandLine();
        boolean l = this.l.isPresent(args);
        if (!args.hasProperties() || l) {
            printList(ctx, Util.getDeployments(client), l);
            return;
        }

        final String path = this.path.getValue(args);
        final File f;
        if(path != null) {
            f = new File(path);
            if(!f.exists()) {
                ctx.printLine("Path " + f.getAbsolutePath() + " doesn't exist.");
                return;
            }
            if(f.isDirectory()) {
                ctx.printLine(f.getAbsolutePath() + " is a directory.");
                return;
            }
        } else {
            f = null;
        }

        String name = this.name.getValue(args);
        if(name == null) {
            if(f == null) {
                ctx.printLine("Either path or --name is requied.");
                return;
            }
            name = f.getName();
        }

        final String runtimeName = rtName.getValue(args);

        if(Util.isDeploymentInRepository(name, client) && f != null) {
            if(force.isPresent(args)) {
                DefaultOperationRequestBuilder builder = new DefaultOperationRequestBuilder();

                ModelNode result;

                // replace
                builder = new DefaultOperationRequestBuilder();
                builder.setOperationName(Util.FULL_REPLACE_DEPLOYMENT);
                builder.addProperty("name", name);
                if(runtimeName != null) {
                    builder.addProperty(Util.RUNTIME_NAME, runtimeName);
                }

                FileInputStream is = null;
                try {
                    is = new FileInputStream(f);
                    ModelNode request = builder.buildRequest();
                    OperationBuilder op = new OperationBuilder(request);
                    op.addInputStream(is);
                    request.get(Util.CONTENT).get(0).get(Util.INPUT_STREAM_INDEX).set(0);
                    result = client.execute(op.build());
                } catch(Exception e) {
                    ctx.printLine("Failed to replace the deployment: " + e.getLocalizedMessage());
                    return;
                } finally {
                    StreamUtils.safeClose(is);
                }
                if(!Util.isSuccess(result)) {
                    ctx.printLine(Util.getFailureDescription(result));
                    return;
                }

                ctx.printLine("'" + name + "' re-deployed successfully.");
            } else {
                ctx.printLine("'" + name + "' is already deployed (use " + force.getFullName() + " to force re-deploy).");
            }

            return;
        } else {

            // deploy
            // Actually, the add is performed first.
            // But the deploy request is build before to make sure all the required parameters have been provided
            ModelNode deployRequest = null;
            if (!disabled.isPresent(args)) {
                if (ctx.isDomainMode()) {
                    final List<String> serverGroups;
                    if (ctx.isDomainMode()) {
                        if(allServerGroups.isPresent(args)) {
                            serverGroups = Util.getServerGroups(client);
                        } else {
                            String serverGroupsStr = this.serverGroups.getValue(args);
                            if(serverGroupsStr == null) {
                                final StringBuilder buf = new StringBuilder();
                                buf.append("One of ");
                                if(f != null) {
                                    buf.append(disabled.getFullName()).append(", ");
                                }
                                buf.append("--all-server-groups or --server-groups is missing.");
                                ctx.printLine(buf.toString());
                                return;
                            }
                            serverGroups = Arrays.asList(serverGroupsStr.split(","));
                        }

                        if(serverGroups.isEmpty()) {
                            ctx.printLine("No server group is available.");
                            return;
                        }
                    } else {
                        serverGroups = null;
                    }

                    deployRequest = new ModelNode();
                    deployRequest.get(Util.OPERATION).set(Util.COMPOSITE);
                    deployRequest.get(Util.ADDRESS).setEmptyList();
                    ModelNode steps = deployRequest.get(Util.STEPS);

                    for (String serverGroup : serverGroups) {
                        steps.add(Util.configureDeploymentOperation(Util.ADD, name, serverGroup));
                    }

                    for (String serverGroup : serverGroups) {
                        steps.add(Util.configureDeploymentOperation(Util.DEPLOY, name, serverGroup));
                    }
                } else {
                    deployRequest = new ModelNode();
                    deployRequest.get(Util.OPERATION).set(Util.DEPLOY);
                    deployRequest.get(Util.ADDRESS, Util.DEPLOYMENT).set(name);
                }
            }


            // add
            if (f != null) {
                ModelNode request = new ModelNode();
                request.get(Util.OPERATION).set(Util.ADD);
                request.get(Util.ADDRESS, Util.DEPLOYMENT).set(name);
                if (runtimeName != null) {
                    request.get(Util.RUNTIME_NAME).set(runtimeName);
                }

                ModelNode result;
                FileInputStream is = null;
                try {
                    is = new FileInputStream(f);
                    OperationBuilder op = new OperationBuilder(request);
                    op.addInputStream(is);
                    request.get(Util.CONTENT).get(0).get(Util.INPUT_STREAM_INDEX).set(0);
                    result = client.execute(op.build());
                } catch (Exception e) {
                    ctx.printLine("Failed to add the deployment content to the repository: " + e.getLocalizedMessage());
                    return;
                } finally {
                    StreamUtils.safeClose(is);
                }
                if (!Util.isSuccess(result)) {
                    ctx.printLine(Util.getFailureDescription(result));
                    return;
                }
            }


            if(deployRequest != null) {
                ModelNode result;
                try {
                    result = client.execute(deployRequest);
                } catch (Exception e) {
                    ctx.printLine("Failed to deploy: " + e.getLocalizedMessage());
                    return;
                }
View Full Code Here

     * @see org.jboss.as.cli.CommandHandler#handle(org.jboss.as.cli.CommandContext)
     */
    @Override
    public void handle(CommandContext ctx) {

        ModelControllerClient client = ctx.getModelControllerClient();
        if(client == null) {
            ctx.printLine("You are disconnected at the moment." +
                    " Type 'connect' to connect to the server" +
                    " or 'help' for the list of supported commands.");
            return;
        }

        ModelNode request = (ModelNode) ctx.get("OP_REQ");
        if(request == null) {
            ctx.printLine("Parsed request isn't available.");
            return;
        }

        try {
            validateRequest(ctx, request);
        } catch(CommandFormatException e) {
            ctx.printLine(e.getLocalizedMessage());
            return;
        }

        try {
            ModelNode result = client.execute(request);
            ctx.printLine(result.toString());
        } catch(NoSuchElementException e) {
            ctx.printLine("ModelNode request is incomplete: " + e.getMessage());
        } catch (CancellationException e) {
            ctx.printLine("The result couldn't be retrieved (perhaps the task was cancelled: " + e.getLocalizedMessage());
View Full Code Here

        return Collections.emptyList();
    }

    private void validateRequest(CommandContext ctx, ModelNode request) throws CommandFormatException {

        final ModelControllerClient client = ctx.getModelControllerClient();
        if(client == null) {
            throw new CommandFormatException("No connection to the controller.");
        }

        final Set<String> keys = request.keys();

        if(!keys.contains(Util.OPERATION)) {
            throw new CommandFormatException("Request is missing the operation name.");
        }
        final String operationName = request.get(Util.OPERATION).asString();

        if(!keys.contains(Util.ADDRESS)) {
            throw new CommandFormatException("Request is missing the address part.");
        }
        final ModelNode address = request.get(Util.ADDRESS);

        if(keys.size() == 2) { // no props
            return;
        }

        final ModelNode opDescrReq = new ModelNode();
        opDescrReq.get(Util.ADDRESS).set(address);
        opDescrReq.get(Util.OPERATION).set(Util.READ_OPERATION_DESCRIPTION);
        opDescrReq.get(Util.NAME).set(operationName);

        final ModelNode outcome;
        try {
            outcome = client.execute(opDescrReq);
        } catch(Exception e) {
            throw new CommandFormatException("Failed to perform " + Util.READ_OPERATION_DESCRIPTION + " to validate the request: " + e.getLocalizedMessage());
        }
        if (!Util.isSuccess(outcome)) {
            throw new CommandFormatException("Failed to get the list of the operation properties: \"" + Util.getFailureDescription(outcome) + '\"');
View Full Code Here

        if(jndiName == null) {
            throw new OperationFormatException("name is missing.");
        }

        ModelControllerClient client = ctx.getModelControllerClient();
        final String resource;
        if(Util.isTopic(client, jndiName)) {
            resource = "jms-topic";
        } else if(Util.isQueue(client, jndiName)) {
            resource = "jms-queue";
View Full Code Here

        };

        name = new ArgumentWithValue(this, new DefaultCompleter(new DefaultCompleter.CandidatesProvider() {
            @Override
            public List<String> getAllCandidates(CommandContext ctx) {
                ModelControllerClient client = ctx.getModelControllerClient();
                if (client == null) {
                    return Collections.emptyList();
                    }

                final String profileArg;
View Full Code Here

    }

    @Override
    protected void doHandle(CommandContext ctx) throws CommandFormatException {

        ModelControllerClient client = ctx.getModelControllerClient();
        ParsedCommandLine args = ctx.getParsedCommandLine();
        boolean l = this.l.isPresent(args);
        if(!args.hasProperties() || l) {
            printList(ctx, Util.getDeployments(client), l);
            return;
        }

        final String name = this.name.getValue(ctx.getParsedCommandLine());
        if (name == null) {
            printList(ctx, Util.getDeployments(client), l);
            return;
        }

        ModelNode request;
        try {
            request = buildRequest(ctx);
        } catch (OperationFormatException e) {
            ctx.printLine(e.getLocalizedMessage());
            return;
        }

        ModelNode result;
        try {
            result = client.execute(request);
        } catch (Exception e) {
            ctx.printLine("Undeploy failed: " + e.getLocalizedMessage());
            return;
        }
        if (!Util.isSuccess(result)) {
View Full Code Here

TOP

Related Classes of org.jboss.as.controller.client.ModelControllerClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.