private ServerIdentity readServerIdentity() throws IOException { expectHeader(DomainClientProtocol.RETURN_HOST_NAME); // Note: all StreamedResponse object values are marshalled as object, not UTF String hostName = unmarshal(unmarshaller, String.class); expectHeader(DomainClientProtocol.RETURN_SERVER_GROUP_NAME); String groupName = unmarshal(unmarshaller, String.class); expectHeader(DomainClientProtocol.RETURN_SERVER_NAME); String serverName = unmarshal(unmarshaller, String.class); return new ServerIdentity(hostName, groupName, serverName); }
private byte readDeploymentSetRollback(Map<UUID, DeploymentSetPlanResult> setResults) throws IOException { UUID setId = unmarshal(unmarshaller, UUID.class); DeploymentSetPlanResult setResult = setResults.get(setId); if (setResult == null) { throw new IOException("Unknown deployment set plan " + setId); } // A valid deployment set plan will have at least one action byte nextHeader = unmarshaller.readByte(); expectHeader(nextHeader, DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_ID); do { nextHeader = readDeploymentActionRollback(setResult); } while (nextHeader != DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_ID); // If the set plan generated server updates, those will come next if (nextHeader == DomainClientProtocol.RETURN_SERVER_DEPLOYMENT_ROLLBACK) { do { nextHeader = readServerDeploymentRollback(setResult); } while(nextHeader == DomainClientProtocol.RETURN_SERVER_DEPLOYMENT_ROLLBACK); } return nextHeader; }
/** {@inheritDoc} */ @Override protected List<StandaloneUpdateResult<?>> receiveResponse(InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, StandaloneClientProtocol.PARAM_APPLY_UPDATES_RESULT_COUNT); final int updateCount = unmarshaller.readInt(); List<StandaloneUpdateResult<?>> results = new ArrayList<StandaloneUpdateResult<?>>(); for (int i = 0; i < updateCount; i++) { expectHeader(unmarshaller, StandaloneClientProtocol.PARAM_APPLY_UPDATE_RESULT); byte resultCode = unmarshaller.readByte(); if (resultCode == (byte) StandaloneClientProtocol.PARAM_APPLY_UPDATE_RESULT_EXCEPTION) { final UpdateFailedException failure = unmarshal(unmarshaller, UpdateFailedException.class); results.add(new StandaloneUpdateResult<Object>(null, failure)); } else { final Object result = unmarshal(unmarshaller, Object.class); results.add(new StandaloneUpdateResult<Object>(result, null)); } } return results; } }
@Override protected final DomainUpdateApplierResponse receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_APPLY_UPDATE); DomainUpdateApplierResponse rsp = unmarshal(unmarshaller, DomainUpdateApplierResponse.class); unmarshaller.finish(); return rsp; } }
@Override protected final List<HostUpdateResult<?>> receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_APPLY_UPDATES_RESULT_COUNT); final int updateCount = unmarshaller.readInt(); final List<HostUpdateResult<?>> results = new ArrayList<HostUpdateResult<?>>(updateCount); for (int i = 0; i < updateCount; i++) { expectHeader(unmarshaller, DomainClientProtocol.RETURN_APPLY_HOST_UPDATE); HostUpdateResult<?> updateResult = unmarshal(unmarshaller, HostUpdateResult.class); results.add(updateResult); } unmarshaller.finish(); return results; } }
@Override protected final DomainModel receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_DOMAIN_MODEL); final DomainModel domainModel = unmarshal(unmarshaller, DomainModel.class); unmarshaller.finish(); return domainModel; } }
@Override protected final ServerModel receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_SERVER_MODEL); final ServerModel serverModel = unmarshal(unmarshaller, ServerModel.class); unmarshaller.finish(); return serverModel; } }
/** {@inheritDoc} */ @Override protected ServerModel receiveResponse(InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, StandaloneClientProtocol.PARAM_SERVER_MODEL); final ServerModel serverModel = unmarshal(unmarshaller, ServerModel.class); unmarshaller.finish(); return serverModel; } }
@Override protected final HostModel receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_HOST_MODEL); final HostModel hostModel = unmarshal(unmarshaller, HostModel.class); unmarshaller.finish(); return hostModel; } }
@Override protected final ServerStatus receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_SERVER_STATUS); final ServerStatus serverStatus = unmarshal(unmarshaller, ServerStatus.class); unmarshaller.finish(); return serverStatus; } }
/** {@inheritDoc} */ @Override protected final ServerDeploymentPlanResult receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, StandaloneClientProtocol.PARAM_DEPLOYMENT_PLAN_RESULT); final ServerDeploymentPlanResult result = unmarshal(unmarshaller, ServerDeploymentPlanResult.class); unmarshaller.finish(); return result; } }
@Override protected final List<DomainUpdateResult<?>> receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_APPLY_UPDATES_RESULT_COUNT); final int updateCount = unmarshaller.readInt(); final List<DomainUpdateResult<?>> results = new ArrayList<DomainUpdateResult<?>>(updateCount); for (int i = 0; i < updateCount; i++) { expectHeader(unmarshaller, DomainClientProtocol.RETURN_APPLY_UPDATE); DomainUpdateResult<?> updateResult = unmarshal(unmarshaller, DomainUpdateResult.class); results.add(updateResult); } unmarshaller.finish(); return results; } }
private byte readDeploymentSetResult(final Map<UUID, DeploymentSetPlanResult>setResults) throws IOException { UUID setId = unmarshal(unmarshaller, UUID.class); DeploymentSetPlan setPlan = findDeploymentSet(setId); // will throw ISE if not found // A valid deployment set plan will have at least one action byte nextHeader = unmarshaller.readByte(); expectHeader(nextHeader, DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_ID); // Next the server will send all the results of applying set plan updates to DC and SM domain model Map<UUID, DeploymentActionResult> actionResults = new HashMap<UUID, DeploymentActionResult>(); do { nextHeader = readDeploymentActionResult(setPlan, actionResults); } while (nextHeader == DomainClientProtocol.RETURN_DEPLOYMENT_ACTION_ID); // If the set plan generated server updates, those will come next if (nextHeader == DomainClientProtocol.RETURN_SERVER_DEPLOYMENT) { do { nextHeader = readServerDeploymentResult(actionResults); } while (nextHeader == DomainClientProtocol.RETURN_SERVER_DEPLOYMENT); } DeploymentSetPlanResult setResult = new DeploymentSetPlanResultImpl(setPlan, actionResults); setResults.put(setId, setResult); return nextHeader; }
public DeploymentPlanResult readResult() throws IOException { UUID planId = unmarshal(unmarshaller, UUID.class); if (!deploymentPlan.getId().equals(planId)) throw new IllegalStateException("Incorrect id " + planId + " for result; expected " + deploymentPlan.getId()); byte header = unmarshaller.readByte(); if (header == DomainClientProtocol.RETURN_DEPLOYMENT_PLAN_INVALID) { InvalidDeploymentPlanException e = unmarshal(unmarshaller, InvalidDeploymentPlanException.class); return new DeploymentPlanResultImpl(deploymentPlan, e);
private byte readDeploymentActionResult(final DeploymentSetPlan setPlan, final Map<UUID, DeploymentActionResult> actionResults) throws IOException { 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(); }
@Override protected final Map<ServerIdentity, ServerStatus> receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_SERVER_STATUS_COUNT); final int count = unmarshaller.readInt(); final Map<ServerIdentity, ServerStatus> results = new HashMap<ServerIdentity, ServerStatus>(count); for (int i = 0; i < count; i++) { expectHeader(unmarshaller, DomainClientProtocol.RETURN_HOST_NAME); final String hostName = unmarshaller.readUTF(); expectHeader(unmarshaller, DomainClientProtocol.RETURN_SERVER_GROUP_NAME); final String groupName = unmarshaller.readUTF(); expectHeader(unmarshaller, DomainClientProtocol.RETURN_SERVER_NAME); final String serverName = unmarshaller.readUTF(); expectHeader(unmarshaller, DomainClientProtocol.RETURN_SERVER_STATUS); final ServerStatus serverStatus = unmarshal(unmarshaller, ServerStatus.class); results.put(new ServerIdentity(hostName, groupName, serverName), serverStatus); } unmarshaller.finish(); return results; } }
private byte readServerDeploymentRollback(DeploymentSetPlanResult setResult) throws IOException { UUID actionId = unmarshal(unmarshaller, UUID.class); DeploymentActionResultImpl actionResult = (DeploymentActionResultImpl) setResult.getDeploymentActionResults().get(actionId); ServerIdentity serverId = readServerIdentity(); expectHeader(DomainClientProtocol.RETURN_SERVER_DEPLOYMENT_RESULT); @SuppressWarnings("unchecked") UpdateResultHandlerResponse<Void> urhr = unmarshal(unmarshaller, UpdateResultHandlerResponse.class);
private byte readServerDeploymentResult(Map<UUID, DeploymentActionResult> actionResults) throws IOException { UUID actionId = unmarshal(unmarshaller, UUID.class); DeploymentActionResultImpl actionResult = (DeploymentActionResultImpl) actionResults.get(actionId); ServerIdentity serverId = readServerIdentity(); expectHeader(DomainClientProtocol.RETURN_SERVER_DEPLOYMENT_RESULT); @SuppressWarnings("unchecked") UpdateResultHandlerResponse<Void> urhr = unmarshal(unmarshaller, UpdateResultHandlerResponse.class); ServerUpdateResult<Void> sur = new ServerUpdateResultImpl<Void>(actionId, serverId, urhr); actionResult.storeServerUpdateResult(serverId, sur); // Notifiy and listeners DeploymentActionImpl action = (DeploymentActionImpl) actionResult.getDeploymentAction(); for (DomainUpdateListener<?> listener : action.getListeners()) { if (urhr.isCancelled()) { listener.handleCancellation(serverId); } else if (urhr.isRolledBack()) { listener.handleRollbackSuccess(serverId); } else if (urhr.isTimedOut()) { listener.handleTimeout(serverId); } else if (urhr.getFailureResult() != null) { listener.handleFailure(urhr.getFailureResult(), serverId); } else { listener.handleSuccess(null, serverId); } } return unmarshaller.readByte(); }
private byte readDeploymentActionRollback(DeploymentSetPlanResult setResult) throws IOException { 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) {
@Override protected final Void receiveResponse(final InputStream input) throws IOException { final Unmarshaller unmarshaller = getUnmarshaller(); unmarshaller.start(createByteInput(input)); expectHeader(unmarshaller, DomainClientProtocol.RETURN_APPLY_SERVER_MODEL_UPDATE); @SuppressWarnings("unchecked") final UpdateResultHandlerResponse<R> result = unmarshal(unmarshaller, UpdateResultHandlerResponse.class); unmarshaller.finish(); if (resultHandler != null) { if (result.isCancelled()) { resultHandler.handleCancellation(param); } else if (result.isRolledBack()) { resultHandler.handleRollbackSuccess(param); } else if (result.isTimedOut()) { resultHandler.handleTimeout(param); } else if (result.getFailureResult() != null) { resultHandler.handleFailure(result.getFailureResult(), param); } else { resultHandler.handleSuccess(result.getSuccessResult(), param); } } unmarshaller.finish(); return null; } }