Package org.jboss.as.domain.client.impl

Examples of org.jboss.as.domain.client.impl.DomainUpdateApplierResponse


                log.infof("Received domain model update %s", update);
        }

        @Override
        protected void sendResponse(final OutputStream output) throws IOException {
            DomainUpdateApplierResponse response = processUpdate();
            final Marshaller marshaller = getMarshaller();
            marshaller.start(createByteOutput(output));
            marshaller.writeByte(DomainClientProtocol.RETURN_APPLY_UPDATE);
            marshaller.writeObject(response);
            marshaller.finish();
View Full Code Here


        List<DomainUpdateResult<?>> result;

        List<DomainUpdateApplierResponse> domainResults = applyUpdatesToModel(updates);

        // Check the last update to verify overall success
        DomainUpdateApplierResponse last = domainResults.get(domainResults.size() - 1);
        if (last.isCancelled() || last.isRolledBack() || last.getDomainFailure() != null || last.getHostFailures().size() > 0) {
            // Something failed; don't push to servers
            result = new ArrayList<DomainUpdateResult<?>>();
            for (DomainUpdateApplierResponse duar : domainResults) {
                if (duar.isCancelled()) {
                    result.add(new DomainUpdateResult<Object>(true));
View Full Code Here

                    // the failed update -- which should not have changed anything
                    rollbacks.add(0, rollback);
                    // Stick in a placeholder result that will survive if
                    // a domain update faiure triggers a rollback or will get replaced with
                    // the final result if we apply to servers
                    result.add(new DomainUpdateApplierResponse(false));
                }
                catch (UpdateFailedException e) {
                    log.debugf(e, "Failed applying %s", update);
                    ok = false;
                    result.add(new DomainUpdateApplierResponse(e));
                }
            } else {
                // Add a cancellation response
                result.add(new DomainUpdateApplierResponse(true));
            }
        }

        if (!ok) {
            // Apply compensating updates to fix our local model
View Full Code Here

                    hostFailures.put(entry.getKey(), new UpdateFailedException(e));
                }
            }
            if (hostFailures.size() == 0) {
                log.debugf("%s servers affected by update %s", servers.size(), i);
                result.add(new DomainUpdateApplierResponse(servers));
            }
            else {
                log.debugf("%s server managers failed on update %s", hostFailures.size(), i);
                result.add(new DomainUpdateApplierResponse(hostFailures));
                ok = false;
                // No point processing other updates, as we are going to roll them back.
                // Act as if we did the whole thing one update at a time and this
                // failure stopped us doing the rest
                break;
            }
        }

        if (!ok) {

            // Some server manager failed, so we gotta roll 'em all back

            log.warn("One or more updates failed on some server managers; rolling back");

            // Apply compensating updates to fix our local model
            for (int i = 0; i < rollbacks.size(); i++) {
                AbstractDomainModelUpdate<?> rollback = rollbacks.get(i);
                try {
                    domainModel.update(rollback);
                }
                catch (UpdateFailedException e) {
                    // TODO uh oh. Reload from the file?
                }
            }

            // List of servers we fail to successfully roll back
            Set<String> outOfSync = new HashSet<String>();

            Map<String, Future<Boolean>> rollbackFutures = new HashMap<String, Future<Boolean>>(futures.size());
            for (Map.Entry<String, Future<List<ModelUpdateResponse<List<ServerIdentity>>>>> entry : futures.entrySet()) {
                try {
                    // For this host figure out how many updates need to be rolled back
                    List<ModelUpdateResponse<List<ServerIdentity>>> rspList = entry.getValue().get();
                    int idx = rspList.size() - 1;
                    if (idx >= 0 && !rspList.get(idx).isSuccess()) {
                        idx--; // !isSuccess one shouldn't have affected model state so no rollback of it
                    }
                    if (idx < 0) {
                        // This host didn't apply anything
                        continue;
                    }

                    // Set up the rollback list
                    final List<AbstractDomainModelUpdate<?>> serverManagerRollbacks =
                        (idx == rollbacks.size() -1) ? rollbacks : new ArrayList<AbstractDomainModelUpdate<?>>(idx + 1);
                    if (serverManagerRollbacks != rollbacks) {
                        // Rollbacks are in reverse order from updates. We take
                        // the last X=idx items from the rollback list since
                        // those correspond to the updates that didn't fail and need rollback
                        for (int j = rollbacks.size() - 1 - idx; j < rollbacks.size(); j++) {
                            serverManagerRollbacks.add(rollbacks.get(j));
                        }
                    }
                    // Tell the host to roll back
                    final ServerManagerClient client = clients.get(entry.getKey());
                    Callable<Boolean> callable = new Callable<Boolean>() {
                        @Override
                        public Boolean call() throws Exception {
                            List<ModelUpdateResponse<List<ServerIdentity>>> rsp = client.updateDomainModel(serverManagerRollbacks);
                            return Boolean.valueOf(rsp.size() == serverManagerRollbacks.size() && rsp.get(rsp.size() - 1).isSuccess());
                        }
                    };
                    rollbackFutures.put(entry.getKey(), scheduledExecutorService.getValue().submit(callable));

                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    outOfSync.add(entry.getKey());
                } catch (ExecutionException e) {
                    outOfSync.add(entry.getKey());
                }
            }

            // Wait until rollbacks complete
            for (Map.Entry<String, Future<Boolean>> entry : rollbackFutures.entrySet()) {
                try {
                    if (!entry.getValue().get()) {
                        outOfSync.add(entry.getKey());
                    }
                }  catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                    outOfSync.add(entry.getKey());
                } catch (ExecutionException e) {
                    outOfSync.add(entry.getKey());
                }
            }

            for (String host : outOfSync) {
                // Rollback failed; need to push the whole model
                ServerManagerClient client = clients.get(host);
                client.updateDomainModel(domainModel);
            }

            // Update the result list to record the rollbacks
            for (int i = 0; i < result.size(); i++) {
                DomainUpdateApplierResponse rsp = result.get(i);
                if (rsp.getHostFailures().size() < 0) {
                    result.set(i, new DomainUpdateApplierResponse(false));
                }
            }
        }

        return result;
View Full Code Here

            final Map<AbstractDomainModelUpdate<?>, AbstractServerModelUpdate<?>> serverByDomain) {

        Map<ServerIdentity, List<AbstractServerModelUpdate<?>>> result = new HashMap<ServerIdentity, List<AbstractServerModelUpdate<?>>>();

        for (int i = 0; i < domainResults.size(); i++) {
            DomainUpdateApplierResponse domainResult = domainResults.get(i);
            AbstractDomainModelUpdate<?> domainUpdate = domainUpdates.get(i);
            AbstractServerModelUpdate<?> serverUpdate = serverByDomain.get(domainUpdate);
            for (ServerIdentity server : domainResult.getServers()) {
                List<AbstractServerModelUpdate<?>> serverList = result.get(server);
                if (serverList == null) {
                    serverList = new ArrayList<AbstractServerModelUpdate<?>>();
                    result.put(server, serverList);
                }
View Full Code Here

        // Inform client of results
        pushSingleResponse(responseQueue, new StreamedResponse((byte) DomainClientProtocol.RETURN_DEPLOYMENT_SET_ID, updateSet.setPlan.getId()));
        DeploymentAction lastResponseAction = null;
        for (int i = 0; i < rsps.size(); i++) {
            DomainUpdateApplierResponse duar = rsps.get(i);
            // There can be multiple domain updates for a given action, but we
            // only send one response. Use this update result for the response if
            // 1) it failed or 2) it's the last update associated with the action
            if (duar.getDomainFailure() != null || duar.getHostFailures().size() > 0 || updateSet.isLastDomainUpdateForAction(i)) {
                DeploymentAction action = updateSet.getDeploymentActionForDomainUpdate(i);
                if (action != lastResponseAction) {
                    List<StreamedResponse> rspList = new ArrayList<StreamedResponse>(2);
                    rspList.add(new StreamedResponse((byte) DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_ID, action.getId()));
                    rspList.add(new StreamedResponse((byte) DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_MODEL_RESULT, duar));
                    responseQueue.put(rspList);
                    lastResponseAction = action;
                }
            }
        }

        // See if the above was successful before moving on to servers
        DomainUpdateApplierResponse last = rsps.get(rsps.size() - 1);
        if (last.getDomainFailure() != null || last.getHostFailures().size() > 0) {
            // DomainModel update failed; don't apply to servers. The DomainController will
            // have already rolled back the domain model update
            return false;
        }
View Full Code Here

        byte type = forRollback ? (byte) DomainClientProtocol.RETURN_DEPLOYMENT_SET_ROLLBACK
                                : (byte) DomainClientProtocol.RETURN_DEPLOYMENT_SET_ID;
        pushSingleResponse(responseQueue, new StreamedResponse(type, updateSet.setPlan.getId()));

        List<StreamedResponse> rspList = new ArrayList<StreamedResponse>();
        DomainUpdateApplierResponse duar = new DomainUpdateApplierResponse(true);
        for (ActionUpdates au : updateSet.actionUpdates) {
            rspList.add(new StreamedResponse((byte) DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_ID, au.action.getId()));
            rspList.add(new StreamedResponse((byte) DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_MODEL_RESULT, duar));
        }
View Full Code Here

        // Inform client of results
        pushSingleResponse(responseQueue, new StreamedResponse((byte) DomainClientProtocol.RETURN_DEPLOYMENT_SET_ROLLBACK, updateSet.setPlan.getId()));
        DeploymentAction lastResponseAction = null;
        for (int i = 0; i < rsps.size(); i++) {
            DomainUpdateApplierResponse duar = rsps.get(i);
            // There can be multiple domain updates for a given action, but we
            // only send one response. Use this update result for the response if
            // 1) it failed or 2) it's the last update associated with the action
            if (duar.getDomainFailure() != null || duar.getHostFailures().size() > 0 || updateSet.isLastDomainRollbackForAction(i)) {
                DeploymentAction action = updateSet.getDeploymentActionForDomainUpdate(i);
                if (action != lastResponseAction) {
                    List<StreamedResponse> rspList = new ArrayList<StreamedResponse>(2);
                    rspList.add(new StreamedResponse((byte) DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_ID, action.getId()));
                    rspList.add(new StreamedResponse((byte) DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_MODEL_RESULT, duar));
                    responseQueue.put(rspList);
                    lastResponseAction = action;
                }
            }
        }

        DomainUpdateApplierResponse last = rsps.get(rsps.size() - 1);
        if (last.getDomainFailure() != null || last.getHostFailures().size() > 0) {
            throw new RollbackFailedException();
        }

        // Apply to servers
        Runnable r = getServerUpdateTask(updateSet, rsps, true, responseQueue);
View Full Code Here

        UUID actionId = unmarshal(unmarshaller, UUID.class);
        DeploymentActionImpl action = findDeploymentAction(actionId, setPlan);
        Set<DomainUpdateListener<?>> listeners = action.getListeners();
        expectHeader(DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_MODEL_RESULT);
        DomainUpdateApplierResponse duar = unmarshal(unmarshaller, DomainUpdateApplierResponse.class);
        DeploymentActionResultImpl actionResult = new DeploymentActionResultImpl(action, duar);
        actionResults.put(actionId, actionResult);

        // Notify any listeners
        for (DomainUpdateListener<?> listener : listeners) {
            if (duar.isCancelled()) {
                listener.handleCancelledByDomain();
            }
            else if (duar.isRolledBack()) {
                listener.handleDomainRollback();
            }
            else if (duar.getDomainFailure() != null) {
                listener.handleDomainFailed(duar.getDomainFailure());
            }
            else if (duar.getHostFailures().size() > 0) {
                listener.handleHostFailed(duar.getHostFailures());
            }
            else {
                listener.handleServersIdentified(duar.getServers());
            }
        }

        return unmarshaller.readByte();
    }
View Full Code Here

        UUID actionId = unmarshal(unmarshaller, UUID.class);
        DeploymentActionImpl action = findDeploymentAction(actionId, setResult.getDeploymentSetPlan());
        Set<DomainUpdateListener<?>> listeners = action.getListeners();
        expectHeader(DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_MODEL_RESULT);
        DomainUpdateApplierResponse duar = unmarshal(unmarshaller, DomainUpdateApplierResponse.class);
        DeploymentActionResultImpl actionResult = (DeploymentActionResultImpl) setResult.getDeploymentActionResults().get(actionId);
        if (actionResult != null) {
            actionResult.markRolledBack(duar);

            // Notify any listeners
            for (DomainUpdateListener<?> listener : listeners) {
                if (duar.isCancelled()) {
                    listener.handleDomainRollbackFailed(new RollbackCancelledException("Rollback of deployment action " + actionId + "was cancelled"));
                }
                else if (duar.isRolledBack()) {
                    listener.handleDomainRollbackFailed(new RollbackCancelledException("Rollback of deployment action " + actionId + "was itself rolled back"));
                }
                else if (duar.getDomainFailure() != null) {
                    listener.handleDomainRollbackFailed(duar.getDomainFailure());
                }
                else if (duar.getHostFailures().size() > 0) {
                    listener.handleHostRollbackFailed(duar.getHostFailures());
                }
                else {
                    listener.handleDomainRollback();
                }
            }
View Full Code Here

TOP

Related Classes of org.jboss.as.domain.client.impl.DomainUpdateApplierResponse

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.