Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * JBoss, Home of Professional Open Source.
   * Copyright 2012, Red Hat, Inc., and individual contributors
   * as indicated by the @author tags. See the copyright.txt file in the
   * distribution for a full listing of individual contributors.
   *
   * This is free software; you can redistribute it and/or modify it
   * under the terms of the GNU Lesser General Public License as
   * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */
 
 package org.jboss.as.domain.controller.operations.coordination;
 
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.COMPOSITE;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.DOMAIN_RESULTS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXTENSION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.FAILURE_DESCRIPTION;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.IGNORED;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OPERATION_HEADERS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OUTCOME;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.RESULT;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.STEPS;
 import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUCCESS;
 import static org.jboss.as.domain.controller.DomainControllerLogger.HOST_CONTROLLER_LOGGER;
 
 
 
 import java.util.List;

Author(s):
Emanuel Muckenhuber
 
 
     private final String name;
     private final ModelNode operation;
     private final OperationContext context;
 
     public HostControllerUpdateTask(final String namefinal ModelNode operationfinal OperationContext context,
                                     final TransformingProxyController proxyController) {
         this. = name;
         this. = context;
         this. = operation;
         this. = proxyController;
     }
 
     public ExecutedHostRequest execute(final ProxyOperationListener listener) {
         boolean trace = .isTraceEnabled();
         if (trace) {
             .tracef("Sending %s to %s");
         }
         final TransactionalProtocolClient client = .getProtocolClient();
         final OperationMessageHandler messageHandler = new DelegatingMessageHandler();
         final OperationAttachments operationAttachments = new DelegatingOperationAttachments();
         final SubsystemInfoOperationListener subsystemListener = new SubsystemInfoOperationListener(listener.getTransformers());
         try {
 
             final OperationTransformer.TransformedOperation transformationResult = .transformOperation();
             final ModelNode transformedOperation = transformationResult.getTransformedOperation();
             final ProxyOperation proxyOperation = new ProxyOperation(transformedOperationmessageHandleroperationAttachments);
            try {
                // Make sure we preserve the operation headers like PrepareStepHandler.EXECUTE_FOR_COORDINATOR
                if(transformedOperation != null) {
                    transformedOperation.get().set(.get());
                    // If the operation was transformed
                    if (!.equals(transformedOperation)) {
                        // push all operations (incl. read-only) to the servers
                        transformedOperation.get(.).set(true);
                    }
                }
                final AsyncFuture<ModelNoderesult = client.execute(subsystemListenerproxyOperation);
                return new ExecutedHostRequest(resulttransformationResult);
            } catch (IOException e) {
                // Handle protocol failures
                final TransactionalProtocolClient.PreparedOperation<ProxyOperationresult = BlockingQueueOperationListener.FailedOperation.create(proxyOperatione);
                subsystemListener.operationPrepared(result);
                return new ExecutedHostRequest(result.getFinalResult(), transformationResult);
            }
        } catch (OperationFailedException e) {
            // Handle transformation failures
            final ProxyOperation proxyOperation = new ProxyOperation(messageHandleroperationAttachments);
            final TransactionalProtocolClient.PreparedOperation<ProxyOperationresult = BlockingQueueOperationListener.FailedOperation.create(proxyOperatione);
            subsystemListener.operationPrepared(result);
        }
    }
    static class ProxyOperation extends TransactionalOperationImpl {
        private final String name;
        protected ProxyOperation(final String namefinal ModelNode operationfinal OperationMessageHandler messageHandlerfinal OperationAttachments attachments) {
            super(operationmessageHandlerattachments);
            this. = name;
        }
        public String getName() {
            return ;
        }
    }
        private final AsyncFuture<ModelNodefutureResult;
        private final OperationResultTransformer resultTransformer;
        private final OperationRejectionPolicy rejectPolicy;
        ExecutedHostRequest(AsyncFuture<ModelNodefutureResultOperationResultTransformer resultTransformerOperationRejectionPolicy rejectPolicy) {
            this. = futureResult;
            this. = resultTransformer;
            this. = rejectPolicy;
        }
        ExecutedHostRequest(AsyncFuture<ModelNodefutureResultOperationTransformer.TransformedOperation transformedOperation) {
            this(futureResulttransformedOperationtransformedOperation);
        }
        public Future<ModelNodegetFinalResult() {
            return ;
        }
        @Override
        public boolean rejectOperation(ModelNode result) {
            // Check the host result for successful operations and see if we have to reject it
            if(result.get().has()) {
                final ModelNode domainResults = result.get();
                // Don't reject ignored operations
                if(domainResults.getType() == . && .equals(domainResults.asString())) {
                    return false;
                }
                // The format of the prepared operation of the domain coordination step1 is different from a normal operation
                // a user would need to handle, therefore try to fix it up as good as possible
                final ModelNode userOp = new ModelNode();
                userOp.get().set();
                userOp.get().set(domainResults);
                return .rejectOperation(userOp);
            } else {
                // This should only handle failed host operations
                return .rejectOperation(result);
            }
        }
        @Override
        public String getFailureDescription() {
            return .getFailureDescription();
        }
        @Override
        public ModelNode transformResult(ModelNode result) {
            final boolean reject = rejectOperation(result);
            if(reject) {
                result.get().set(getFailureDescription());
            }
            if(result.get().has()) {
                final ModelNode domainResults = result.get();
                if(domainResults.getType() == . && .equals(domainResults.asString())) {
                    // Untransformed
                    return result;
                }
                final ModelNode userResult = new ModelNode();
                userResult.get().set(result.get());
                userResult.get().set(domainResults);
                if(result.hasDefined()) {
                    userResult.get().set(result.get());
                }
                // Transform the result
                final ModelNode transformed = .transformResult(userResult);
                result.get().set(transformed.get());
                return result;
            } else {
                return .transformResult(result);
            }
        }
        public void asyncCancel() {
            .asyncCancel(false);
        }
    }

    
The transactional operation listener.
        final boolean trace = .isTraceEnabled();
        @Override
        public void operationPrepared(final TransactionalProtocolClient.PreparedOperation<ProxyOperationprepared) {
            try {
                super.operationPrepared(prepared);
            } finally {
                if () {
                    final ModelNode result = prepared.getPreparedResult();
                    final String hostName = prepared.getOperation().getName();
                    .tracef("Received prepared result %s from %s"resulthostName);
                }
            }
        }
        @Override
        public void operationComplete(final ProxyOperation operationfinal ModelNode result) {
            try {
                super.operationComplete(operationresult);
            } finally {
                if () {
                    final String hostName = operation.getName();
                    .tracef("Received final result %s from %s"resulthostName);
                }
            }
        }
    }

    
Checks responses from slaves for subsystem version information. TODO this is pretty hacky
        private final ProxyOperationListener delegate;
        private final Transformers transformers;
        private SubsystemInfoOperationListener(ProxyOperationListener delegateTransformers transformers) {
            this. = delegate;
            this. = transformers;
        }
        @Override
            .operationPrepared(prepared);
        }
        @Override
        public void operationFailed(ProxyOperation operationModelNode result) {
            .operationFailed(operationresult);
        }
        @Override
        public void operationComplete(ProxyOperation operationModelNode result) {
            try {
                storeSubsystemVersions(operation.getOperation(), result);
            } finally {
                .operationComplete(operationresult);
            }
        }
        private void storeSubsystemVersions(ModelNode operationModelNode response) {
            PathAddress address = operation.hasDefined() ? PathAddress.pathAddress(operation.get()) : .;
            if (address.size() == 0 && .equals(operation.get().asString()) && response.hasDefined()) {
                // recurse
                List<ModelNodesteps = operation.hasDefined() ? operation.get().asList() : Collections.<ModelNode>emptyList();
                ModelNode result = response.get();
                for (int i = 0; i < steps.size(); i++) {
                    ModelNode stepOp = steps.get(i);
                    String resultID = "step-" + (i+1);
                    if (result.hasDefined(resultID)) {
                        storeSubsystemVersions(stepOpresult.get(resultID));
                    }
                }
            } else if (address.size() == 1 && .equals(operation.get().asString())
                        && .equals(address.getElement(0).getKey())
                        && response.hasDefined() && response.get().hasDefined()) {
                // Extract the subsystem info and store it
                TransformationTarget target = .getTarget();
                for (Property p : response.get().asPropertyList()) {
                    String[] version = p.getValue().asString().split("\\.");
                    int major = Integer.parseInt(version[0]);
                    int minor = Integer.parseInt(version[1]);
                    target.addSubsystemVersion(p.getName(), majorminor);
                    .debugf("Registering subsystem %s for host %s with major version [%d] and minor version [%d]",
                            p.getName(), addressmajorminor);
                }
                // purge the subsystem version data from the response
                response.get().set(new ModelNode());
            }
        }
    }
    private static class DelegatingMessageHandler implements OperationMessageHandler {
        private final OperationContext context;
        DelegatingMessageHandler(final OperationContext context) {
            this. = context;
        }
        @Override
        public void handleReport(MessageSeverity severityString message) {
            .report(severitymessage);
        }
    }
    private static class DelegatingOperationAttachments implements OperationAttachments {
        private final OperationContext context;
        private DelegatingOperationAttachments(final OperationContext context) {
            this. = context;
        }
        @Override
        public boolean isAutoCloseStreams() {
            return false;
        }
        @Override
        public List<InputStreamgetInputStreams() {
            int count = .getAttachmentStreamCount();
            List<InputStreamresult = new ArrayList<InputStream>(count);
            for (int i = 0; i < counti++) {
                result.add(.getAttachmentStream(i));
            }
            return result;
        }
        @Override
        public void close() throws IOException {
            //
        }
    }
New to GrepCode? Check out our FAQ X