Source:
<code>protected void executeCommand() { VDSGroup sourceCluster = getVdsGroup(); final Guid targetClusterId = getParameters().getClusterId(); if (sourceCluster.getId().equals(targetClusterId)) { setSucceeded(true); return; } TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { @Override public Void runInTransaction() { VdsStatic staticData = getVds().getStaticData(); getCompensationContext().snapshotEntity(staticData); staticData.setvds_group_id(targetClusterId); DbFacade.getInstance().getVdsStaticDAO().update(staticData); getCompensationContext().stateChanged(); return null; } }); if (sourceCluster.supportsGlusterService()) { glusterHostRemove(sourceCluster.getId()); if (!getSucceeded()) { return; } } <START> if (getVdsGroup(getParameters().getClusterId()).supportsGlusterService()) { <END> glusterHostAdd(getParameters().getClusterId()); if (!getSucceeded()) { return; } } getParameters().setCompensationEnabled(true); getParameters().setTransactionScopeOption(TransactionScopeOption.RequiresNew); if (sourceCluster.getstorage_pool_id() != null) { VdcReturnValueBase removeVdsSpmIdReturn = Backend.getInstance().runInternalAction(VdcActionType.RemoveVdsSpmId, getParameters(), new CommandContext(getCompensationContext())); if (!removeVdsSpmIdReturn.getSucceeded()) { setSucceeded(false); getReturnValue().setFault(removeVdsSpmIdReturn.getFault()); return; } } if (targetStoragePool != null) { VdcReturnValueBase addVdsSpmIdReturn = Backend.getInstance().runInternalAction(VdcActionType.AddVdsSpmId, getParameters(), new CommandContext(getCompensationContext())); if (!addVdsSpmIdReturn.getSucceeded()) { setSucceeded(false); getReturnValue().setFault(addVdsSpmIdReturn.getFault()); return; } } setSucceeded(true); }</code><technical_language>Introducing methods getSourceClusterId(), getSourceCluster(), getTargetClusterId() getTargetCluster() code more readable, instead of repeating code getVdsGroup(getParameters().getClusterId()) in multiple places</technical_language>

Target:
protected void executeCommand() { VDSGroup sourceCluster = getVdsGroup(); final Guid targetClusterId = getParameters().getClusterId(); if (sourceCluster.getId().equals(targetClusterId)) { setSucceeded(true); return; } TransactionSupport.executeInNewTransaction(new TransactionMethod<Void>() { @Override public Void runInTransaction() { VdsStatic staticData = getVds().getStaticData(); getCompensationContext().snapshotEntity(staticData); staticData.setvds_group_id(targetClusterId); DbFacade.getInstance().getVdsStaticDAO().update(staticData); getCompensationContext().stateChanged(); return null; } }); if (sourceCluster.supportsGlusterService() && getClusterUtils().hasServers(getSourceClusterId())) { glusterHostRemove(getSourceClusterId()); if (!getSucceeded()) { return; } } if (getVdsGroup(getTargetClusterId()).supportsGlusterService() && getClusterUtils().hasMultipleServers(getTargetClusterId())) { glusterHostAdd(getTargetClusterId()); if (!getSucceeded()) { return; } } getParameters().setCompensationEnabled(true); getParameters().setTransactionScopeOption(TransactionScopeOption.RequiresNew); if (sourceCluster.getstorage_pool_id() != null) { VdcReturnValueBase removeVdsSpmIdReturn = Backend.getInstance().runInternalAction(VdcActionType.RemoveVdsSpmId, getParameters(), new CommandContext(getCompensationContext())); if (!removeVdsSpmIdReturn.getSucceeded()) { setSucceeded(false); getReturnValue().setFault(removeVdsSpmIdReturn.getFault()); return; } } if (targetStoragePool != null) { VdcReturnValueBase addVdsSpmIdReturn = Backend.getInstance().runInternalAction(VdcActionType.AddVdsSpmId, getParameters(), new CommandContext(getCompensationContext())); if (!addVdsSpmIdReturn.getSucceeded()) { setSucceeded(false); getReturnValue().setFault(addVdsSpmIdReturn.getFault()); return; } } setSucceeded(true); }