Package org.jboss.as.controller

Examples of org.jboss.as.controller.ControllerTransaction


        }

    }

    private DomainLevelResult executeOnDomainControllers(Operation operation, ResultHandler handler, OperationRouting routing) throws OperationFailedException {
        ControllerTransaction  transaction = new ControllerTransaction();
        try {
            ModelNode operationNode = operation.getOperation();
            // Get a copy of the rollout plan so it doesn't get disrupted by any handlers
            ModelNode rolloutPlan = operationNode.hasDefined(OPERATION_HEADERS) && operationNode.get(OPERATION_HEADERS).has(ROLLOUT_PLAN)
                ? operationNode.get(OPERATION_HEADERS).remove(ROLLOUT_PLAN) : null;

            // System.out.println("---- Push to hosts");
            // Push to hosts, formulate plan, push to servers
            Map<String, ModelNode> hostResults = null;
            try {
                hostResults = pushToHosts(operation, routing, transaction);
            }
            catch (Exception e) {
                ModelNode failureMsg = new ModelNode();
                failureMsg.get(DOMAIN_FAILURE_DESCRIPTION).set(e.toString());
                throw new OperationFailedException(failureMsg);
            }

            // System.out.println("---- Pushed to hosts");
            ModelNode masterFailureResult = null;
            ModelNode hostFailureResults = null;
            ModelNode masterResult = hostResults.get(localHostName);
            // System.out.println("-----Checking host results");
            if (masterResult != null && masterResult.hasDefined(OUTCOME) && FAILED.equals(masterResult.get(OUTCOME).asString())) {
                transaction.setRollbackOnly();
                masterFailureResult = masterResult.hasDefined(FAILURE_DESCRIPTION) ? masterResult.get(FAILURE_DESCRIPTION) : new ModelNode().set("Unexplained failure");
            }
            else {
                for (Map.Entry<String, ModelNode> entry : hostResults.entrySet()) {
                    ModelNode hostResult = entry.getValue();
                    if (hostResult.hasDefined(OUTCOME) && FAILED.equals(hostResult.get(OUTCOME).asString())) {
                        if (hostFailureResults == null) {
                            transaction.setRollbackOnly();
                            hostFailureResults = new ModelNode();
                        }
                        ModelNode desc = hostResult.hasDefined(FAILURE_DESCRIPTION) ? hostResult.get(FAILURE_DESCRIPTION) : new ModelNode().set("Unexplained failure");
                        hostFailureResults.add(entry.getKey(), desc);
                    }
                }
            }

            // for (Map.Entry<String, ModelNode> entry : hostResults.entrySet()) {
            //    System.out.println("======================================================");
            //    System.out.println(entry.getKey());
            //    System.out.println("======================================================");
            //    System.out.println(entry.getValue());
            // }

            if (transaction.isRollbackOnly()) {
                ModelNode failureMsg = new ModelNode();
                if (masterFailureResult != null) {
                    failureMsg.get(DOMAIN_FAILURE_DESCRIPTION).set(masterFailureResult);
                }
                else if (hostFailureResults != null) {
                    failureMsg.get(HOST_FAILURE_DESCRIPTIONS).set(hostFailureResults);
                }
                throw new OperationFailedException(failureMsg);
            }

            // TODO formulate the domain-level result
            //....

            // Formulate plan
            Map<String, Map<ServerIdentity, ModelNode>> opsByGroup = getOpsByGroup(hostResults);
            ModelNode compensatingOperation = getCompensatingOperation(operationNode, hostResults);
            // System.out.println(compensatingOperation);

            DomainLevelResult result;
            if (opsByGroup.size() == 0) {
                ModelNode singleHostResult = getSingleHostResult(hostResults);
                result = new DomainLevelResult(singleHostResult, compensatingOperation);
            }
            else {
                try {
                    rolloutPlan = getRolloutPlan(rolloutPlan, opsByGroup);
                    // System.out.println(rolloutPlan);
                }
                catch (OperationFailedException ofe) {
                    // treat as a master DC failure
                    ModelNode failureMsg = new ModelNode();
                    failureMsg.get(DOMAIN_FAILURE_DESCRIPTION).set(ofe.getFailureDescription());
                    throw new OperationFailedException(failureMsg);
                }
                result = new DomainLevelResult(opsByGroup, compensatingOperation, rolloutPlan);
            }

            return result;

        } catch (OperationFailedException ofe) {
            transaction.setRollbackOnly();
            throw ofe;
        } finally {
            transaction.commit();
        }

    }
View Full Code Here


            txId.readExternal(inputStream);
        }

        @Override
        protected void sendResponse(final OutputStream outputStream) throws IOException {
            ControllerTransaction tx = transactions.remove(txId);
            if (tx != null) {
                tx.setRollbackOnly();
                tx.commit();
            }
        }
View Full Code Here

                cmd = inputStream.read();
            }
        }

        protected ControllerTransaction getTransaction() {
            ControllerTransaction result = new ControllerTransaction(txId);
            ControllerTransaction existing = transactions.putIfAbsent(txId, result);
            if (existing != null) {
                result = existing;
            }
            return result;
        }
View Full Code Here

            txId.readExternal(inputStream);
        }

        @Override
        protected void sendResponse(final OutputStream outputStream) throws IOException {
            ControllerTransaction tx = transactions.remove(txId);
            if (tx != null) {
                tx.commit();
            }
        }
View Full Code Here

        // Get a copy of the rollout plan so it doesn't get disrupted by any handlers
        ModelNode rolloutPlan = operationNode.has(ROLLOUT_PLAN) ? operationNode.remove(ROLLOUT_PLAN) : null;

        // Push to hosts, formulate plan, push to servers
        ControllerTransaction  transaction = new ControllerTransaction();
        Map<String, ModelNode> hostResults = null;
        try {
            hostResults = pushToHosts(operation, routing, transaction);
        }
        catch (Exception e) {
            transaction.setRollbackOnly();
            transaction.commit();
            handler.handleResultFragment(new String[]{DOMAIN_FAILURE_DESCRIPTION}, new ModelNode().set(e.toString()));
            handler.handleFailed(null);
            return new BasicOperationResult();
        }

        // System.out.println("---- Pushed to hosts");
        ModelNode masterFailureResult = null;
        ModelNode hostFailureResults = null;
        ModelNode masterResult = hostResults.get(localHostName);
        // System.out.println("-----Checking host results");
        if (masterResult != null && masterResult.hasDefined(OUTCOME) && FAILED.equals(masterResult.get(OUTCOME).asString())) {
            transaction.setRollbackOnly();
            masterFailureResult = masterResult.hasDefined(FAILURE_DESCRIPTION) ? masterResult.get(FAILURE_DESCRIPTION) : new ModelNode().set("Unexplained failure");
        }
        else {
            for (Map.Entry<String, ModelNode> entry : hostResults.entrySet()) {
                ModelNode hostResult = entry.getValue();
                if (hostResult.hasDefined(OUTCOME) && FAILED.equals(hostResult.get(OUTCOME).asString())) {
                    if (hostFailureResults == null) {
                        transaction.setRollbackOnly();
                        hostFailureResults = new ModelNode();
                    }
                    ModelNode desc = hostResult.hasDefined(FAILURE_DESCRIPTION) ? hostResult.get(FAILURE_DESCRIPTION) : new ModelNode().set("Unexplained failure");
                    hostFailureResults.add(entry.getKey(), desc);
                }
            }
        }

        // for (Map.Entry<String, ModelNode> entry : hostResults.entrySet()) {
        //    System.out.println("======================================================");
        //    System.out.println(entry.getKey());
        //    System.out.println("======================================================");
        //    System.out.println(entry.getValue());
        // }

        if (transaction.isRollbackOnly()) {
            transaction.commit();
            if (masterFailureResult != null) {
                handler.handleResultFragment(new String[]{DOMAIN_FAILURE_DESCRIPTION}, masterFailureResult);
            }
            else if (hostFailureResults != null) {
                handler.handleResultFragment(new String[]{HOST_FAILURE_DESCRIPTIONS}, hostFailureResults);
            }
            handler.handleFailed(null);
            return new BasicOperationResult();
        } else {
            // TODO formulate the domain-level result
            //....

            // Formulate plan
            Map<String, Map<ServerIdentity, ModelNode>> opsByGroup = getOpsByGroup(hostResults);
            try {
                rolloutPlan = getRolloutPlan(rolloutPlan, opsByGroup);
            }
            catch (OperationFailedException ofe) {
                transaction.setRollbackOnly();
                // treat as a master DC failure
                handler.handleResultFragment(new String[]{DOMAIN_FAILURE_DESCRIPTION}, ofe.getFailureDescription());
                handler.handleFailed(null);
                return new BasicOperationResult();
            }
            finally {
                transaction.commit();
            }

            // System.out.println(rolloutPlan);
            ModelNode compensatingOperation = getCompensatingOperation(operationNode, hostResults);
            // System.out.println(compensatingOperation);
View Full Code Here

        // Get a copy of the rollout plan so it doesn't get disrupted by any handlers
        ModelNode rolloutPlan = operation.has(ROLLOUT_PLAN) ? operation.remove(ROLLOUT_PLAN) : null;

        // Push to hosts, formulate plan, push to servers
        ControllerTransaction  transaction = new ControllerTransaction();
        Map<String, ModelNode> hostResults = null;
        try {
            hostResults = pushToHosts(operationContext, routing, transaction);
        }
        catch (Exception e) {
            transaction.setRollbackOnly();
            transaction.commit();
            handler.handleResultFragment(new String[]{DOMAIN_FAILURE_DESCRIPTION}, new ModelNode().set(e.toString()));
            handler.handleFailed(null);
            return new BasicOperationResult();
        }

//        System.out.println("---- Pushed to hosts");
        ModelNode masterFailureResult = null;
        ModelNode hostFailureResults = null;
        ModelNode masterResult = hostResults.get(localHostName);
//        System.out.println("-----Checking host results");
        if (masterResult != null && masterResult.hasDefined(OUTCOME) && FAILED.equals(masterResult.get(OUTCOME).asString())) {
            transaction.setRollbackOnly();
            masterFailureResult = masterResult.hasDefined(FAILURE_DESCRIPTION) ? masterResult.get(FAILURE_DESCRIPTION) : new ModelNode().set("Unexplained failure");
        }
        else {
            for (Map.Entry<String, ModelNode> entry : hostResults.entrySet()) {
                ModelNode hostResult = entry.getValue();
                if (hostResult.hasDefined(OUTCOME) && FAILED.equals(hostResult.get(OUTCOME).asString())) {
                    if (hostFailureResults == null) {
                        transaction.setRollbackOnly();
                        hostFailureResults = new ModelNode();
                    }
                    ModelNode desc = hostResult.hasDefined(FAILURE_DESCRIPTION) ? hostResult.get(FAILURE_DESCRIPTION) : new ModelNode().set("Unexplained failure");
                    hostFailureResults.add(entry.getKey(), desc);
                }
            }
        }

//        for (Map.Entry<String, ModelNode> entry : hostResults.entrySet()) {
//            System.out.println("======================================================");
//            System.out.println(entry.getKey());
//            System.out.println("======================================================");
//            System.out.println(entry.getValue());
//        }

        if (transaction.isRollbackOnly()) {
            transaction.commit();
            if (masterFailureResult != null) {
                handler.handleResultFragment(new String[]{DOMAIN_FAILURE_DESCRIPTION}, masterFailureResult);
            }
            else if (hostFailureResults != null) {
                handler.handleResultFragment(new String[]{HOST_FAILURE_DESCRIPTIONS}, hostFailureResults);
            }
            handler.handleFailed(null);
            return new BasicOperationResult();
        } else {
            // TODO formulate the domain-level result
            //....

            // Formulate plan
            Map<String, Map<ServerIdentity, ModelNode>> opsByGroup = getOpsByGroup(hostResults);
            try {
                rolloutPlan = getRolloutPlan(rolloutPlan, opsByGroup);
            }
            catch (OperationFailedException ofe) {
                transaction.setRollbackOnly();
                // treat as a master DC failure
                handler.handleResultFragment(new String[]{DOMAIN_FAILURE_DESCRIPTION}, ofe.getFailureDescription());
                handler.handleFailed(null);
                return new BasicOperationResult();
            }
            finally {
                transaction.commit();
            }

//            System.out.println(rolloutPlan);

            ModelNode compensatingOperation = getCompensatingOperation(operation, hostResults);
View Full Code Here

TOP

Related Classes of org.jboss.as.controller.ControllerTransaction

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.