Package org.rhq.modules.plugins.jbossas7.json

Examples of org.rhq.modules.plugins.jbossas7.json.Result


         */
        readResourceOperation.attributesOnly(true);
        readResourceOperation.includeDefaults(false);
        readResourceOperation.includeRuntime(false);

        Result res = getASConnection().execute(readResourceOperation, AVAIL_OP_TIMEOUT_SECONDS);
        if (res != null && res.isSuccess()) {
            return AvailabilityType.UP;
        }
        if (context.getResourceType().isSupportsMissingAvailabilityType()) {
            if (res != null && res.isRolledBack() && res.getFailureDescription().startsWith("JBAS014807")) {
                getLog().info("Reporting MISSING resource: " + getPath());
                return AvailabilityType.MISSING;
            }
        }
        if (res != null && res.isTimedout()) {
            return AvailabilityType.UNKNOWN;
        }
        return AvailabilityType.DOWN;
    }
View Full Code Here


                op = new ReadAttribute(address, complexRequest.getProp());
            } else {
                op = new ReadAttribute(address, reqName);
            }

            Result res = getASConnection().execute(op);
            if (!res.isSuccess()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Getting metric [" + req.getName() + "] at [ " + address + "] failed: "
                        + res.getFailureDescription());
                }
                return ReadMetricResult.RequestFailed;
            }

            Object val = res.getResult();
            if (val == null) // One of the AS7 ways of telling "This is not implemented" See also AS7-1454
                return ReadMetricResult.Null;

            if (req.getDataType() == DataType.MEASUREMENT) {
                if (val instanceof String && ((String) val).startsWith("JBAS018003")) // AS7 way of saying "no value available"
                    return ReadMetricResult.Null;
                try {
                    if (complexRequest != null) {
                        @SuppressWarnings("unchecked")
                        Map<String, Number> myValues = (Map<String, Number>) val;
                        for (String key : myValues.keySet()) {
                            String sub = complexRequest.getSub();
                            if (key.equals(sub)) {
                                addMetric2Report(report, req, myValues.get(key), resolveExpression);
                            }
                        }
                    } else {
                        addMetric2Report(report, req, val, resolveExpression);
                    }
                } catch (NumberFormatException e) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Non numeric input for [" + req.getName() + "] : [" + val + "]");
                    }
                    return ReadMetricResult.ResolveFailed;
                }
            } else if (req.getDataType() == DataType.TRAIT) {

                if (resolveExpression && val instanceof Map && ((Map) val).containsKey(EXPRESSION_VALUE_KEY)) {
                    String expression = (String) ((Map) val).get(EXPRESSION_VALUE_KEY);
                    ResolveExpression resolveExpressionOperation = new ResolveExpression(expression);
                    Result result = getASConnection().execute(resolveExpressionOperation);
                    if (!result.isSuccess()) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Skipping trait [" + req.getName()
                                            + "] in measurement report. Could not resolve expression [" + expression
                                            + "], failureDescription:" + result.getFailureDescription());
                            return ReadMetricResult.ResolveFailed;
                        }
                    }
                    val = result.getResult();
                }

                MeasurementDataTrait data = new MeasurementDataTrait(req, getStringValue(val));
                report.addData(data);
            }
View Full Code Here

    private void addMetric2Report(MeasurementReport report, MeasurementScheduleRequest req, Object val,
        boolean resolveExpression) {
        if (resolveExpression && val instanceof Map && ((Map) val).containsKey(EXPRESSION_VALUE_KEY)) {
            String expression = (String) ((Map) val).get(EXPRESSION_VALUE_KEY);
            ResolveExpression resolveExpressionOperation = new ResolveExpression(expression);
            Result result = getASConnection().execute(resolveExpressionOperation);
            if (!result.isSuccess()) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("Skipping metric [" + req.getName() + "] in measurement report. Could not resolve expression ["
                            + expression + "], failureDescription:" + result.getFailureDescription());
                    return;
                }
            }
            val = result.getResult();
        }
        Double d = Double.parseDouble(getStringValue(val));
        MeasurementDataNumeric data = new MeasurementDataNumeric(req, d);
        report.addData(data);
    }
View Full Code Here

            includeRuntime);
        Configuration configuration = delegate.loadResourceConfiguration();

        // Read server state
        Operation op = new Operation("whoami", getAddress());
        Result res = getASConnection().execute(op);

        //:whoami might fail host controller resources, in that case use :read-resource operation
        //which is slower due to larger content returned but more reliable since every resource has it.
        if (!res.isSuccess()) {
            op = new Operation("read-resource", getAddress());
            res = getASConnection().execute(op);
        }
        includeOOBMessages(res, configuration);
        return configuration;
View Full Code Here

        }

        if (context.getResourceType().getName().equals(MANAGED_SERVER)) {
            // We need to do two steps because of AS7-4032
            Operation stop = new Operation("stop", getAddress());
            Result res = getASConnection().execute(stop);
            if (!res.isSuccess()) {
                throw new IllegalStateException("Managed server [" + path
                    + "] is still running and can't be stopped, so it cannot be removed.");
            }
        }
        Operation op = new Remove(address);
        Result res = getASConnection().execute(op, 120);
        if (!res.isSuccess()) {
            throw new IllegalArgumentException("Delete for [" + path + "] failed: " + res.getFailureDescription());
        }
    }
View Full Code Here

                    report.setStatus(CreateResourceStatus.INVALID_CONFIGURATION);
                    return report;
                }

                ReadChildrenNames op = new ReadChildrenNames(address, pathProperty.getStringValue());
                Result res = connection.execute(op);
                if (res.isSuccess()) {
                    @SuppressWarnings("unchecked")
                    List<String> entries = (List<String>) res.getResult();
                    if (!entries.isEmpty()) {
                        report.setErrorMessage("Resource is a singleton, but there are already children " + entries
                            + " please remove them and retry");
                        report.setStatus(CreateResourceStatus.FAILURE);
                        return report;
View Full Code Here

        step1.addAdditionalProperty("name", deploymentName);
        step1.addAdditionalProperty("runtime-name", runtimeName);

        String resourceKey;
        Result result;

        CompositeOperation cop = new CompositeOperation();
        cop.addStep(step1);
        /*
         * We need to check here if this is an upload to /deployment only
         * or if this should be deployed to a server group too
         */

        if (!toServerGroup) {

            // if standalone, then :deploy the deployment anyway
            if (context.getResourceType().getName().contains("Standalone")) {
                Operation step2 = new Operation("deploy", step1.getAddress());
                cop.addStep(step2);
            }

            result = connection.execute(cop, 300);
            resourceKey = step1.getAddress().getPath();

        } else {

            Address serverGroupAddress = new Address(context.getResourceKey());
            serverGroupAddress.add("deployment", deploymentName);
            Operation step2 = new Operation("add", serverGroupAddress);

            cop.addStep(step2);

            Operation step3 = new Operation("deploy", serverGroupAddress);
            cop.addStep(step3);

            resourceKey = serverGroupAddress.getPath();

            if (verbose) {
                LOG.info("Deploy operation: " + cop);
            }

            result = connection.execute(cop, 300);
        }

        if ((!result.isSuccess())) {
            String failureDescription = result.getFailureDescription();
            report.setErrorMessage(failureDescription);
            report.setStatus(CreateResourceStatus.FAILURE);
            LOG.warn("Deploy of [" + runtimeName + "] failed: " + failureDescription);
        } else {
            report.setStatus(CreateResourceStatus.SUCCESS);
View Full Code Here

                }
            }
        }

        OperationResult operationResult = new OperationResult();
        Result result = getASConnection().execute(operation);

        if (result == null) {
            operationResult.setErrorMessage("Connection was null - is the server running?");
            return operationResult;
        }

        if (!result.isSuccess()) {
            operationResult.setErrorMessage(result.getFailureDescription());
        } else {
            String tmp;
            if (result.getResult() == null)
                tmp = "-none provided by the server-";
            else
                tmp = result.getResult().toString();
            operationResult.setSimpleResult(tmp);
        }
        return operationResult;
    }
View Full Code Here

        return readAttribute(address, name, resultType, 10);
    }

    protected <R> R readAttribute(Address address, String name, Class<R> resultType, int timeoutSec) throws Exception {
        Operation op = new ReadAttribute(address, name);
        Result res = getASConnection().execute(op, timeoutSec);

        if (!res.isSuccess()) {
            if (res.isTimedout()) {
                throw new TimeoutException("Read attribute operation timed out");
            }
            if (res.isRolledBack() && !res.getFailureDescription().startsWith("JBAS015135")) {
                // this means we've connected, authenticated, but still failed
                throw new ResultFailedException("Failed to read attribute [" + name + "] of address ["
                    + getAddress().getPath() + "] - response: " + res);
            }
            if (res.isRolledBack() && res.getFailureDescription().startsWith("JBAS015135")) {
                // this means we've connected, authenticated, but still failed
                throw new SecurityRealmNotReadyException("Failed to read attribute [" + name + "] of address ["
                    + getAddress().getPath() + "] - response: " + res);
            }
            throw new Exception("Failed to read attribute [" + name + "] of address [" + getAddress().getPath()
                + "] - response: " + res);
        }

        return resultType.cast(res.getResult());
    }
View Full Code Here

    }

    @Override
    public AvailabilityType getAvailability() {
        Operation op = new ReadResource(getAddress());
        Result res = getASConnection().execute(op, AVAIL_OP_TIMEOUT_SECONDS);

        if (!res.isSuccess()) {
            if (res.isTimedout()) {
                return AvailabilityType.UNKNOWN;
            }

            if (res.getFailureDescription() != null && res.getFailureDescription().toLowerCase().contains("not found")) {
                getLog().debug("Reporting MISSING resource: " + getPath());
                return AvailabilityType.MISSING;
            }

            return AvailabilityType.DOWN;
        }

        if (res.getResult() == null) {
            return AvailabilityType.DOWN;
        }

        @SuppressWarnings("unchecked")
        Map<String, Object> results = (Map<String, Object>) res.getResult();
        if (results.get("enabled") == null || !(Boolean) results.get("enabled")) {
            return AvailabilityType.DOWN;
        }

        return AvailabilityType.UP;
View Full Code Here

TOP

Related Classes of org.rhq.modules.plugins.jbossas7.json.Result

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.