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

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


        }
    }

    private OperationResult invokeSimpleOperation(String action) {
        Operation op = new Operation(action, getAddress());
        Result res = getASConnection().execute(op);
        OperationResult result = new OperationResult();
        if (res.isSuccess()) {
            result.setSimpleResult("Success");
            if ("enable".equals(action)) {
                context.getAvailabilityContext().enable();
            }
            if ("disable".equals(action)) {
                context.getAvailabilityContext().disable();
            }
        } else {
            result.setErrorMessage(res.getFailureDescription());
        }

        return result;
    }
View Full Code Here


        JsonNode resultNode = uploadResult.get("result");
        String hash = resultNode.get("BYTES_VALUE").getTextValue();

        try {
            Redeployer redeployer = new Redeployer(detail.getKey().getName(), hash, getASConnection());
            Result result = redeployer.redeployOnServer();
            if (result.isRolledBack()) {
                response.setOverallRequestResult(ContentResponseResult.FAILURE);
                response.setOverallRequestErrorMessage("Rolled Back: " + result.getFailureDescription());
            } else {
                response.setOverallRequestResult(ContentResponseResult.SUCCESS);
                //we just deployed a different file on the AS7 server, so let's refresh ourselves
                deploymentFile = determineDeploymentFile();
                DeployIndividualPackageResponse packageResponse = new DeployIndividualPackageResponse(detail.getKey(),
                    ContentResponseResult.SUCCESS);
                response.addPackageResponse(packageResponse);
            }

        } catch (Exception e) {
            response.setOverallRequestResult(ContentResponseResult.FAILURE);
            response.setOverallRequestErrorMessage(e.getMessage());
        }

        ContentResponseResult result = response.getOverallRequestResult();
        getLog().info(
            "Result of deployment of "
                + resourceType.getName()
                + " Resource with key ["
                + detail.getKey()
                + "]: "
                + ((ContentResponseResult.SUCCESS == result) ? result.name() : (result.name() + ": " + response
                    .getOverallRequestErrorMessage())));

        return response;
    }
View Full Code Here

     * @return A file object pointing to the deployed file or null if there is no content
     */
    @SuppressWarnings("unchecked")
    private File determineDeploymentFile() {
        Operation op = new ReadAttribute(getAddress(), "content");
        Result result = getASConnection().execute(op);

        List<Map<String, Object>> content = (List<Map<String, Object>>) result.getResult();
        if (content == null || content.isEmpty()) {
            // No content -> check for server group
            if (path.startsWith(("server-group="))) {
                // Server group has no content of its own - use the domain deployment
                String name = path.substring(path.lastIndexOf("=") + 1);
                op = new ReadResource(new Address("deployment", name));
                result = getASConnection().execute(op);
                if (result.isSuccess()) {
                    Map<String, Object> contentMap = (Map<String, Object>) result.getResult();
                    content = (List<Map<String, Object>>) contentMap.get("content");
                    if (content.get(0).containsKey("path")) {
                        String path = (String) content.get(0).get("path");
                        String relativeTo = (String) content.get(0).get("relative-to");
                        deploymentFile = getDeploymentFileFromPath(relativeTo, path);
                    } else if (content.get(0).containsKey("hash")) {
                        String base64Hash = ((Map<String, String>) content.get(0).get("hash")).get("BYTES_VALUE");
                        byte[] hash = Base64.decode(base64Hash);
                        ServerGroupComponent sgc = (ServerGroupComponent) context.getParentResourceComponent();
                        String baseDir = ((HostControllerComponent) sgc.context.getParentResourceComponent()).pluginConfiguration
                            .getSimpleValue("baseDir");
                        String contentPath = new File(baseDir, "/data/content").getAbsolutePath();
                        deploymentFile = getDeploymentFileFromHash(hash, contentPath);
                    }
                    return deploymentFile;
                }
            } else {
                getLog().warn(
                    "Could not determine the location of the deployment - the content descriptor wasn't found for deployment"
                        + getAddress() + ".");
                return null;
            }
        }

        Boolean archive = (Boolean) content.get(0).get("archive");
        if (archive != null && !archive) {
            getLog().debug("Exploded deployments not supported for retrieving the content.");
            return null;
        }

        File deploymentFile = null;
        if (content.get(0).containsKey("path")) {
            String path = (String) content.get(0).get("path");
            String relativeTo = (String) content.get(0).get("relative-to");
            deploymentFile = getDeploymentFileFromPath(relativeTo, path);
        } else if (content.get(0).containsKey("hash")) {
            String base64Hash = ((Map<String, String>) content.get(0).get("hash")).get("BYTES_VALUE");
            byte[] hash = Base64.decode(base64Hash);
            Address contentPathAddress;
            if (context.getParentResourceComponent() instanceof ManagedASComponent) {
                // -> managed server we need to check for host=x/server=y, but the path brings host=x,server-config=y
                String p = ((ManagedASComponent) context.getParentResourceComponent()).getPath();
                p = p.replaceAll("server-config=", "server=");
                contentPathAddress = new Address(p);
                contentPathAddress.add("core-service", "server-environment");
            } else {
                // standalone
                contentPathAddress = new Address("core-service", "server-environment");
            }
            op = new ReadAttribute(contentPathAddress, "content-dir");
            result = getASConnection().execute(op);

            String contentPath;
            if (result.isSuccess()) {
                contentPath = (String) result.getResult();
            } else {
                // No success above -> check if this is a domain deployment
                if (this instanceof DomainDeploymentComponent) {
                    String baseDir = ((HostControllerComponent) context.getParentResourceComponent()).pluginConfiguration
                        .getSimpleValue("baseDir");
View Full Code Here

                relativeTo = relativeTo.substring("jboss.server.".length());
                relativeTo = relativeTo.replace('.', '-');

                //now look for the transformed relativeTo in the server environment
                Operation op = new ReadAttribute(new Address("core-service", "server-environment"), relativeTo);
                Result res = getASConnection().execute(op);

                relativeTo = (String) res.getResult();

                return new File(relativeTo, path);
            } else {
                getLog().warn("Unsupported property used as a base for deployment path specification: " + relativeTo);
                return null;
View Full Code Here

        return contentFileInfo.getVersion(null);
    }

    private String getDeploymentName() {
        Operation op = new ReadAttribute(getAddress(), "name");
        Result res = getASConnection().execute(op);

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

    @Override
    public OperationResult invokeOperation(String name, Configuration parameters) throws Exception {
        Operation op = new Operation(name, getAddress());
        OperationResult operationResult = new OperationResult();
        Result result = null;

        String modClusterKeyMesg = "Modcluster resource keys are not in correct format.";
        modClusterKeyMesg += " Should be {modcluster address}:{jvmRoute}:{virtual-host}:{context} but instead ";
        modClusterKeyMesg += " was '" + key + "'";

        if ("list-proxies".equals(name)) {
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                ArrayList container = (ArrayList) result.getResult();
                if ((container != null) && !container.isEmpty()) {
                    Object type = container.get(0);
                    String values = "";
                    if (type instanceof String) {
                        for (int i = 0; i < container.size(); i++) {
                            values += container.get(i) + ",";
                        }
                        values = values.substring(0, values.length() - 1);
                    } else {
                        values = container.toString();
                    }
                    operationResult.getComplexResults().put(new PropertySimple("proxy-list", values));

                } else {//return empty value.
                    operationResult.getComplexResults().put(new PropertySimple("proxy-list", ""));
                }
            }
        } else if ("add-proxy".equals(name)) {
            addAdditionalToOp(op, parameters, "host", false);
            addAdditionalToOp(op, parameters, "port", false);
            result = getASConnection().execute(op);
            if (result != null && result.isSuccess()) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("remove-proxy".equals(name)) {
            addAdditionalToOp(op, parameters, "host", false);
            addAdditionalToOp(op, parameters, "port", false);
            result = getASConnection().execute(op);
            if (result != null && result.isSuccess()) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("disable-context".equals(name)) {//disable handled by base case
            //update the operation components with details from the resource being operated on.
            //Ex. {modcluster address}:{jvmRoute}:{virtual-host}:{context}
            String[] keyComponents = key.split(":");
            if (keyComponents.length == 4) {
                op.addAdditionalProperty("virtualhost", keyComponents[2]);
                op.addAdditionalProperty("context", keyComponents[3]);
                result = getASConnection().execute(op);
                if ((result != null) && (result.isSuccess())) {
                    operationResult.setSimpleResult("Success");
                }
            } else {
                operationResult.setErrorMessage(modClusterKeyMesg);
                return operationResult;
            }
        } else if ("enable-context".equals(name)) {//enable handled by base case
            String currentAddress = getAddress().getPath();
            //update the operation components with details from the resource being operated on.
            //Ex. {modcluster address}:{jvmRoute}:{virtual-host}:{context}
            String[] keyComponents = key.split(":");
            if (keyComponents.length == 4) {
                op.addAdditionalProperty("virtualhost", keyComponents[2]);
                op.addAdditionalProperty("context", keyComponents[3]);
                result = getASConnection().execute(op);
                if ((result != null) && (result.isSuccess())) {
                    operationResult.setSimpleResult("Success");
                }
            } else {
                operationResult.setErrorMessage(modClusterKeyMesg);
                return operationResult;
            }
        } else if ("stop-context".equals(name)) {
            String currentAddress = getAddress().getPath();
            //Ex. {modcluster address}:{jvmRoute}:{virtual-host}:{context}
            String[] keyComponents = key.split(":");
            if (keyComponents.length == 4) {
                op.addAdditionalProperty("virtualhost", keyComponents[2]);
                op.addAdditionalProperty("context", keyComponents[3]);
                addAdditionalToOp(op, parameters, "waittime", true);
                result = getASConnection().execute(op);
                if ((result != null) && (result.isSuccess())) {
                    operationResult.setSimpleResult("Success");
                }
            } else {
                operationResult.setErrorMessage(modClusterKeyMesg);
                return operationResult;
            }
        } else if ("add-custom-metric".equals(name)) {
            //update the address and operation name. Use class name as identifier.
            String newOperationDestination = getAddress().getPath() + DYNAMIC_PROVIDER
                + ",custom-load-metric,custom-load-metric=" + retrieveNewIdentifier(parameters, "class");
            op = new Operation("add", new Address(newOperationDestination));
            addAdditionalToOp(op, parameters, "class", false);
            addAdditionalToOp(op, parameters, "weight", false);
            addAdditionalToOp(op, parameters, "capacity", true);
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("remove-custom-metric".equals(name)) {
            //update the address and operation name. Use class name as identifier.
            String newOperationDestination = getAddress().getPath() + DYNAMIC_PROVIDER
                + ",custom-load-metric,custom-load-metric=" + retrieveNewIdentifier(parameters, "class");
            op = new Operation("remove", new Address(newOperationDestination));
            addAdditionalToOp(op, parameters, "class", false);
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("add-metric".equals(name)) {
            //update the address and operation name. Use class name as identifier.
            String newOperationDestination = getAddress().getPath() + DYNAMIC_PROVIDER
                + ",custom-load-metric,load-metric=" + retrieveNewIdentifier(parameters, "type");
            op = new Operation("add", new Address(newOperationDestination));
            addAdditionalToOp(op, parameters, "weight", false);
            addAdditionalToOp(op, parameters, "capacity", true);
            addAdditionalToOp(op, parameters, "type", false);
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("remove-metric".equals(name)) {
            //update the address and operation name. Use class name as identifier.
            String newOperationDestination = getAddress().getPath() + DYNAMIC_PROVIDER
                + ",custom-load-metric,load-metric=" + retrieveNewIdentifier(parameters, "type");
            op = new Operation("remove", new Address(newOperationDestination));
            addAdditionalToOp(op, parameters, "type", false);
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                operationResult.setSimpleResult("Success");
            }
        } else if ("read-proxies-configuration".equals(name)) {
            //spinder 3/25/12: Can we do better than displaying all content as massive string?
            //                 Content is unstructured/variable from httpd server.
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                ArrayList container = (ArrayList) result.getResult();
                if ((container != null) && !container.isEmpty()) {
                    Object type = container.get(0);
                    String values = "";
                    if (type instanceof String) {
                        for (int i = 0; i < container.size(); i++) {
                            values += container.get(i) + ",";
                        }
                        values = values.substring(0, values.length() - 1);
                    } else {
                        values = container.toString();
                    }
                    operationResult.getComplexResults().put(new PropertySimple("current-proxy-config", values));

                } else {//return empty value.
                    operationResult.getComplexResults().put(new PropertySimple("current-proxy-config", ""));
                }
            }
        } else if ("read-proxies-info".equals(name)) {
            //spinder 3/25/12: Can we do better than displaying all content as massive string?
            //                 Content is unstructured/variable from httpd server.
            result = getASConnection().execute(op);
            if ((result != null) && (result.isSuccess())) {
                ArrayList container = (ArrayList) result.getResult();
                if ((container != null) && !container.isEmpty()) {
                    Object type = container.get(0);
                    String values = "";
                    if (type instanceof String) {
                        for (int i = 0; i < container.size(); i++) {
                            values += container.get(i) + ",";
                        }
                        values = values.substring(0, values.length() - 1);
                    } else {
                        values = container.toString();
                    }
                    operationResult.getComplexResults().put(new PropertySimple("current-proxy-info", values));

                } else {//return empty value.
                    operationResult.getComplexResults().put(new PropertySimple("current-proxy-info", ""));
                }
            }
        } else {
            /*
             * This is a catch all for operations that are not explicitly treated above.
             */
            result = getASConnection().execute(op);
            if (result.isSuccess()) {
                operationResult.setSimpleResult("Success");
            }
        }

        if (!result.isSuccess()) {
            operationResult.setErrorMessage(result.getFailureDescription());
        }

        return operationResult;
    }
View Full Code Here

        }
    }

    private JsonNode resultAsJsonNode(String outcome, String failureDescription, Throwable rhqThrowable,
                                      Boolean rolledBack) {
        Result result = new Result();
        result.setOutcome(outcome);
        if (failureDescription != null) {
            result.setFailureDescription(failureDescription);
        }
        if (rhqThrowable != null) {
            result.setRhqThrowable(rhqThrowable);
        }
        if (rolledBack == TRUE) {
            result.setRolledBack(true);
        }
        return mapper.valueToTree(result);
    }
View Full Code Here

    public Result execute(Operation op, boolean isComplex, int timeoutSec) {
        JsonNode node = executeRaw(op, timeoutSec);

        if (node == null) {
            LOG.warn("Operation [" + op + "] returned null.");
            Result failure = new Result();
            failure.setFailureDescription("Operation [" + op + "] returned null.");
            return failure;
        }
        Result res;
        try {
            //check for failure-description indicator, otherwise ObjectMapper will try to deserialize as json. Ex.
            // {"outcome":"failed","failure-description":"JBAS014792: Unknown attribute number-of-timed-out-transactions","rolled-back":true}
            String as7ResultSerialization = node.toString();

            if (as7ResultSerialization.indexOf(JSON_NODE_FAILURE_DESCRIPTION) > -1) {
                if (verbose) {
                    LOG.warn("------ Detected 'failure-description' when communicating with server."
                        + as7ResultSerialization);
                }
            }

            if (isComplex) {
                res = mapper.readValue(node, ComplexResult.class);
            } else {
                res = mapper.readValue(node, Result.class);
            }
            return res;
        } catch (IOException e) {
            LOG.error(e.getMessage());
            if (verbose) {
                LOG.error("----------- Operation execution unparsable. Request " + ":[" + op + "] Response:<" + node
                    + ">");
            }
            Result failure = new Result();
            failure.setFailureDescription("Operation <" + op + "> returned unparsable JSON, <" + node + ">.");
            return failure;
            //don't return null.
        }
    }
View Full Code Here

                propertyAddress.add(connPropAttributeNameOnServer, connectionProperty.getKey());
                Operation op = new Operation("add", propertyAddress);
                op.addAdditionalProperty("value", connectionProperty.getValue());
                cop.addStep(op);
            }
            Result res = getASConnection().execute(cop);
            if (!res.isSuccess()) {
                report.setErrorMessage("Datasource was added, but setting " + connPropAttributeNameOnServer
                    + " failed: " + res.getFailureDescription());
                report.setStatus(INVALID_ARTIFACT);
                return report;
            }
        }

        // Now enable/disable datasource as required

        ReadAttribute readEnabledAttribute = new ReadAttribute(datasourceAddress, ENABLED_ATTRIBUTE);
        Result readEnabledAttributeResult = getASConnection().execute(readEnabledAttribute);
        if (!readEnabledAttributeResult.isSuccess()) {
            report.setStatus(INVALID_ARTIFACT);
            report.setErrorMessage("Datasource was added but the agent could not read its configuration: "
                + readEnabledAttributeResult.getFailureDescription());
            return report;
        }
        Boolean enabledPropertyCurrentValue = (Boolean) readEnabledAttributeResult.getResult();
        if (enabledPropertyCurrentValue != enableDatasource) {
            if (enableDatasource == TRUE) {
                Operation operation = new Operation(ENABLE_OPERATION, datasourceAddress);
                Result result = getASConnection().execute(operation);
                if (!result.isSuccess()) {
                    report.setStatus(INVALID_ARTIFACT);
                    report.setErrorMessage("Datasource was added but not enabled: " + result.getFailureDescription());
                }
            } else {
                Operation operation = new Operation(DISABLE_OPERATION, datasourceAddress);
                Result result = getASConnection().execute(operation);
                if (!result.isSuccess()) {
                    report.setStatus(INVALID_ARTIFACT);
                    report.setErrorMessage("Datasource was added but not disabled: " + result.getFailureDescription());
                }
            }
        }

        return report;
View Full Code Here

        Operation operation;
        if (name.equals("jndi-view")) {
            Address address = new Address(path);
            operation = new Operation("jndi-view",address);
            Result res = getASConnection().execute(operation);

            if (!res.isSuccess()) {
                result.setErrorMessage(res.getFailureDescription());
                return result;
            }

            Configuration config = result.getComplexResults();

            Map<String,Map> contexts = (Map<String, Map>) res.getResult();

            String entryName = "java: contexts";
            Map<String,Map> javaContexts = contexts.get(entryName);
            PropertyList javaContextsMap = fillMap(javaContexts, "java-contexts", false);
            config.put(javaContextsMap);
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.