Shubhendu Tripathi has uploaded a new change for review. Change subject: gluster: Refactored GlusterTaskSyncJob ......................................................................
gluster: Refactored GlusterTaskSyncJob Rafactored the class GlusterTaskSyncJob and moved the reusable methods to GlusterTaskUtils class. The changes include - 1. Modified the class GlusterTaskUtils as a singleton class 2. Moved reusable code from GlusterTaskSyncJob to GlusterTaskUtils class 3. Modified the dependencies accordingly Change-Id: I1abecae9389530324154cdc059ee717db0a61715 Signed-off-by: Shubhendu Tripathi <shtri...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRebalanceGlusterVolumeCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/tasks/GlusterTaskUtils.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJobTest.java 7 files changed, 245 insertions(+), 143 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/63/21063/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java index 21a3392..9371a97 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CommitRemoveGlusterVolumeBricksCommand.java @@ -48,8 +48,8 @@ return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_BRICKS_REQUIRED); } - if (!(GlusterTaskUtils.isTaskOfType(volume, GlusterTaskType.REMOVE_BRICK)) - || !(GlusterTaskUtils.isTaskStatus(volume, JobExecutionStatus.FINISHED))) { + if (!(getGlusterTaskUtils().isTaskOfType(volume, GlusterTaskType.REMOVE_BRICK)) + || !(getGlusterTaskUtils().isTaskStatus(volume, JobExecutionStatus.FINISHED))) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_VOLUME_REMOVE_BRICKS_NOT_FINISHED); } @@ -113,4 +113,8 @@ public GlusterDBUtils getDbUtils() { return GlusterDBUtils.getInstance(); } + + public GlusterTaskUtils getGlusterTaskUtils() { + return GlusterTaskUtils.getInstance(); + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java index bc0d382..a52664c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.java @@ -1,15 +1,14 @@ package org.ovirt.engine.core.bll.gluster; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.ovirt.engine.core.bll.Backend; +import org.ovirt.engine.core.bll.gluster.tasks.GlusterTaskUtils; import org.ovirt.engine.core.bll.gluster.tasks.GlusterTasksService; import org.ovirt.engine.core.bll.interfaces.BackendInternal; -import org.ovirt.engine.core.bll.job.ExecutionContext; import org.ovirt.engine.core.bll.job.ExecutionHandler; import org.ovirt.engine.core.bll.job.JobRepository; import org.ovirt.engine.core.bll.job.JobRepositoryFactory; @@ -23,9 +22,7 @@ import org.ovirt.engine.core.common.businessentities.VdsStatic; import org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity; import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity; -import org.ovirt.engine.core.common.constants.gluster.GlusterConstants; import org.ovirt.engine.core.common.errors.VdcBLLException; -import org.ovirt.engine.core.common.gluster.GlusterFeatureSupported; import org.ovirt.engine.core.common.job.ExternalSystemType; import org.ovirt.engine.core.common.job.JobExecutionStatus; import org.ovirt.engine.core.common.job.Step; @@ -40,11 +37,6 @@ import org.ovirt.engine.core.utils.transaction.TransactionSupport; public class GlusterTasksSyncJob extends GlusterJob { - private static final String REBALANCE_IN_PROGRESS = "IN PROGRESS"; - private static final String REMOVE_BRICK_FAILED = "MIGRATION FAILED"; - private static final String REMOVE_BRICK_IN_PROGRESS = "MIGRATION IN PROGRESS"; - private static final String REMOVE_BRICK_FINISHED = "MIGRATION COMPLETE"; - private static final Log log = LogFactory.getLog(GlusterTasksSyncJob.class); private static GlusterTasksSyncJob instance = new GlusterTasksSyncJob(); @@ -61,10 +53,6 @@ public GlusterTasksService getProvider() { return provider; - } - - public JobRepository getJobRepository() { - return JobRepositoryFactory.getJobRepository(); } public BackendInternal getBackend() { @@ -84,7 +72,7 @@ } private Map<Guid, GlusterAsyncTask> updateTasksInCluster(final VDSGroup cluster) { - if (!supportsGlusterAsyncTasksFeature(cluster)) + if (!getGlusterTaskUtils().supportsGlusterAsyncTasksFeature(cluster)) { return null; } @@ -116,24 +104,7 @@ } }); } - //update status in step table - for (Step step: steps) { - if (step.getEndTime() != null) { - //we have already processed the task - continue; - } - step.setDescription(getTaskMessage(cluster, step.getStepType(), task)); - step.setStatus(task.getStatus()); - if (hasTaskCompleted(task)) { - step.markStepEnded(task.getStatus()); - endStepJob(step); - releaseVolumeLock(task.getTaskId()); - } else { - getJobRepository().updateStep(step); - } - } - - + getGlusterTaskUtils().updateSteps(cluster, task, steps); } return runningTasks; @@ -173,7 +144,7 @@ private Guid addAsyncTaskStep(VDSGroup cluster, GlusterAsyncTask task, StepEnum step, Guid execStepId) { VdcReturnValueBase result; result = getBackend().runInternalAction(VdcActionType.AddInternalStep, - new AddStepParameters(execStepId, getTaskMessage(cluster, step, task), step)); + new AddStepParameters(execStepId, getGlusterTaskUtils().getTaskMessage(cluster, step, task), step)); if (!result.getSucceeded()) { //log and return @@ -199,7 +170,7 @@ private Guid addJob(VDSGroup cluster, GlusterAsyncTask task, VdcActionType actionType) { VdcReturnValueBase result = getBackend().runInternalAction(VdcActionType.AddInternalJob, - new AddInternalJobParameters(ExecutionMessageDirector.resolveJobMessage(actionType, getMessageMap(cluster, task)), + new AddInternalJobParameters(ExecutionMessageDirector.resolveJobMessage(actionType, getGlusterTaskUtils().getMessageMap(cluster, task)), actionType, true) ); if (!result.getSucceeded()) { //log and return @@ -207,19 +178,6 @@ } Guid jobId = (Guid)result.getActionReturnValue(); return jobId; - } - - private void releaseVolumeLock(Guid taskId) { - //get volume associated with task - GlusterVolumeEntity vol= getVolumeDao().getVolumeByGlusterTask(taskId); - - if (vol != null) { - //release lock on volume - releaseLock(vol.getId()); - - } else { - log.debugFormat("Did not find a volume associated with task {0}", taskId); - } } private void updateVolumeBricksAndLock(VDSGroup cluster, GlusterAsyncTask task) { @@ -266,83 +224,11 @@ } } - protected void endStepJob(Step step) { - getJobRepository().updateStep(step); - ExecutionContext finalContext = ExecutionHandler.createFinalizingContext(step.getId()); - ExecutionHandler.endTaskJob(finalContext, isTaskSuccess(step)); + public GlusterTaskUtils getGlusterTaskUtils() { + return GlusterTaskUtils.getInstance(); } - private static boolean isTaskSuccess(Step step) { - switch (step.getStatus()) { - case ABORTED: - case FAILED: - return false; - case FINISHED: - return true; - default: - return false; - } - } - - private static boolean hasTaskCompleted(GlusterAsyncTask task) { - //Remove brick task is marked completed only if committed or aborted. - if (JobExecutionStatus.ABORTED == task.getStatus() || - (JobExecutionStatus.FINISHED == task.getStatus() && task.getType() != GlusterTaskType.REMOVE_BRICK) - || JobExecutionStatus.FAILED == task.getStatus()) { - return true; - } - return false; - } - - private static String getTaskMessage(VDSGroup cluster, StepEnum stepType, GlusterAsyncTask task) { - if (task==null) { - return null; - } - Map<String, String> values = getMessageMap(cluster, task); - - return ExecutionMessageDirector.resolveStepMessage(stepType, values); - } - - private static Map<String, String> getMessageMap(VDSGroup cluster, GlusterAsyncTask task) { - Map<String, String> values = new HashMap<String, String>(); - values.put(GlusterConstants.CLUSTER, cluster.getName()); - values.put(GlusterConstants.VOLUME, task.getTaskParameters().getVolumeName()); - String jobStatus = getJobStatusInfo(task); - values.put(GlusterConstants.JOB_STATUS, jobStatus); - values.put(GlusterConstants.JOB_INFO, task.getMessage()); - return values; - } - - private static String getJobStatusInfo(GlusterAsyncTask task) { - String jobStatus = task.getStatus().toString(); - if (task.getType() == GlusterTaskType.REMOVE_BRICK) { - switch (task.getStatus()) { - case FINISHED: - jobStatus = REMOVE_BRICK_FINISHED; - break; - case STARTED: - jobStatus = REMOVE_BRICK_IN_PROGRESS; - break; - case FAILED: - jobStatus = REMOVE_BRICK_FAILED; - break; - default: - break; - } - } - if (task.getType() == GlusterTaskType.REBALANCE) { - switch (task.getStatus()) { - case STARTED: - jobStatus = REBALANCE_IN_PROGRESS; - break; - default: - break; - } - } - return jobStatus; - } - - private boolean supportsGlusterAsyncTasksFeature(VDSGroup cluster) { - return cluster.supportsGlusterService() && GlusterFeatureSupported.glusterAsyncTasks(cluster.getcompatibility_version()); + public JobRepository getJobRepository() { + return JobRepositoryFactory.getJobRepository(); } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java index 774f8f3..748e475 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopGlusterVolumeCommand.java @@ -47,8 +47,8 @@ return false; } - if (GlusterTaskUtils.isTaskOfType(volume, GlusterTaskType.REBALANCE) - && GlusterTaskUtils.isTaskStatus(volume, JobExecutionStatus.STARTED)) { + if (getGlusterTaskUtils().isTaskOfType(volume, GlusterTaskType.REBALANCE) + && getGlusterTaskUtils().isTaskStatus(volume, JobExecutionStatus.STARTED)) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_VOLUME_CANNOT_STOP_REBALANCE_IN_PROGRESS); } @@ -79,4 +79,8 @@ return errorType == null ? AuditLogType.GLUSTER_VOLUME_STOP_FAILED : errorType; } } + + public GlusterTaskUtils getGlusterTaskUtils() { + return GlusterTaskUtils.getInstance(); + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRebalanceGlusterVolumeCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRebalanceGlusterVolumeCommand.java index bcb559c..1f45e6b 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRebalanceGlusterVolumeCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRebalanceGlusterVolumeCommand.java @@ -38,8 +38,8 @@ return false; } - if (!(GlusterTaskUtils.isTaskOfType(glusterVolume, GlusterTaskType.REBALANCE)) - || !(GlusterTaskUtils.isTaskStatus(glusterVolume, JobExecutionStatus.STARTED))) { + if (!(getGlusterTaskUtils().isTaskOfType(glusterVolume, GlusterTaskType.REBALANCE)) + || !(getGlusterTaskUtils().isTaskStatus(glusterVolume, JobExecutionStatus.STARTED))) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_VOLUME_REBALANCE_NOT_STARTED); } return true; @@ -86,4 +86,7 @@ } } + public GlusterTaskUtils getGlusterTaskUtils() { + return GlusterTaskUtils.getInstance(); + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java index 67b6830..6981bd3 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/StopRemoveGlusterVolumeBricksCommand.java @@ -43,8 +43,8 @@ return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_BRICKS_REQUIRED); } - if (!(GlusterTaskUtils.isTaskOfType(volume, GlusterTaskType.REMOVE_BRICK)) - || !(GlusterTaskUtils.isTaskStatus(volume, JobExecutionStatus.STARTED) || GlusterTaskUtils.isTaskStatus(volume, + if (!(getGlusterTaskUtils().isTaskOfType(volume, GlusterTaskType.REMOVE_BRICK)) + || !(getGlusterTaskUtils().isTaskStatus(volume, JobExecutionStatus.STARTED) || getGlusterTaskUtils().isTaskStatus(volume, JobExecutionStatus.FINISHED))) { return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_VOLUME_REMOVE_BRICKS_NOT_STARTED); } @@ -89,4 +89,8 @@ public BackendInternal getBackend() { return super.getBackend(); } + + public GlusterTaskUtils getGlusterTaskUtils() { + return GlusterTaskUtils.getInstance(); + } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/tasks/GlusterTaskUtils.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/tasks/GlusterTaskUtils.java index 87b47cb..2c7e2b0 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/tasks/GlusterTaskUtils.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/tasks/GlusterTaskUtils.java @@ -1,12 +1,60 @@ package org.ovirt.engine.core.bll.gluster.tasks; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.ovirt.engine.core.bll.LockMessagesMatchUtil; +import org.ovirt.engine.core.bll.gluster.GlusterTasksSyncJob; +import org.ovirt.engine.core.bll.job.ExecutionContext; +import org.ovirt.engine.core.bll.job.ExecutionHandler; +import org.ovirt.engine.core.bll.job.JobRepository; +import org.ovirt.engine.core.bll.job.JobRepositoryFactory; +import org.ovirt.engine.core.common.asynctasks.gluster.GlusterAsyncTask; import org.ovirt.engine.core.common.asynctasks.gluster.GlusterTaskType; +import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.gluster.GlusterTaskSupport; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity; +import org.ovirt.engine.core.common.constants.gluster.GlusterConstants; +import org.ovirt.engine.core.common.errors.VdcBllMessages; +import org.ovirt.engine.core.common.gluster.GlusterFeatureSupported; import org.ovirt.engine.core.common.job.JobExecutionStatus; +import org.ovirt.engine.core.common.job.Step; +import org.ovirt.engine.core.common.job.StepEnum; +import org.ovirt.engine.core.common.locks.LockingGroup; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dal.dbbroker.DbFacade; +import org.ovirt.engine.core.dal.job.ExecutionMessageDirector; +import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao; +import org.ovirt.engine.core.utils.lock.EngineLock; +import org.ovirt.engine.core.utils.lock.LockManager; +import org.ovirt.engine.core.utils.lock.LockManagerFactory; +import org.ovirt.engine.core.utils.log.Log; +import org.ovirt.engine.core.utils.log.LogFactory; public class GlusterTaskUtils { + private static GlusterTaskUtils instance; - public static boolean isTaskOfType(GlusterTaskSupport supportObj, GlusterTaskType type) { + private static final String REBALANCE_IN_PROGRESS = "IN PROGRESS"; + private static final String REMOVE_BRICK_FAILED = "MIGRATION FAILED"; + private static final String REMOVE_BRICK_IN_PROGRESS = "MIGRATION IN PROGRESS"; + private static final String REMOVE_BRICK_FINISHED = "MIGRATION COMPLETE"; + + private static final Log log = LogFactory.getLog(GlusterTasksSyncJob.class); + + protected GlusterTaskUtils() { + } + + public static GlusterTaskUtils getInstance() { + if (instance == null) { + instance = new GlusterTaskUtils(); + } + + return instance; + } + + public boolean isTaskOfType(GlusterTaskSupport supportObj, GlusterTaskType type) { if (supportObj.getAsyncTask() != null && supportObj.getAsyncTask().getType() == type) { return true; } @@ -14,11 +62,159 @@ return false; } - public static boolean isTaskStatus(GlusterTaskSupport supportObj, JobExecutionStatus status) { + public boolean isTaskStatus(GlusterTaskSupport supportObj, JobExecutionStatus status) { if (supportObj.getAsyncTask() != null && supportObj.getAsyncTask().getStatus() == status) { return true; } return false; } + + /** + * Releases the lock held on the cluster having given id and locking group {@link LockingGroup#GLUSTER} + * + * @param clusterId + * ID of the cluster on which the lock is to be released + */ + public void releaseLock(Guid clusterId) { + getLockManager().releaseLock(getEngineLock(clusterId)); + } + + /** + * Returns an {@link EngineLock} instance that represents a lock on a cluster with given id and the locking group + * {@link LockingGroup#GLUSTER} + * + * @param clusterId + * @return + */ + private EngineLock getEngineLock(Guid clusterId) { + return new EngineLock(Collections.singletonMap(clusterId.toString(), + LockMessagesMatchUtil.makeLockingPair(LockingGroup.GLUSTER, + VdcBllMessages.ACTION_TYPE_FAILED_OBJECT_LOCKED)), null); + } + + public void releaseVolumeLock(Guid taskId) { + // get volume associated with task + GlusterVolumeEntity vol = getVolumeDao().getVolumeByGlusterTask(taskId); + + if (vol != null) { + // release lock on volume + releaseLock(vol.getId()); + + } else { + log.debugFormat("Did not find a volume associated with task {0}", taskId); + } + } + + public void endStepJob(Step step) { + getJobRepository().updateStep(step); + ExecutionContext finalContext = ExecutionHandler.createFinalizingContext(step.getId()); + ExecutionHandler.endTaskJob(finalContext, isTaskSuccess(step)); + } + + public boolean isTaskSuccess(Step step) { + switch (step.getStatus()) { + case ABORTED: + case FAILED: + return false; + case FINISHED: + return true; + default: + return false; + } + } + + public boolean hasTaskCompleted(GlusterAsyncTask task) { + // Remove brick task is marked completed only if committed or aborted. + if (JobExecutionStatus.ABORTED == task.getStatus() || + (JobExecutionStatus.FINISHED == task.getStatus() && task.getType() != GlusterTaskType.REMOVE_BRICK) + || JobExecutionStatus.FAILED == task.getStatus()) { + return true; + } + return false; + } + + public String getTaskMessage(VDSGroup cluster, StepEnum stepType, GlusterAsyncTask task) { + if (task == null) { + return null; + } + Map<String, String> values = getMessageMap(cluster, task); + + return ExecutionMessageDirector.resolveStepMessage(stepType, values); + } + + public Map<String, String> getMessageMap(VDSGroup cluster, GlusterAsyncTask task) { + Map<String, String> values = new HashMap<String, String>(); + values.put(GlusterConstants.CLUSTER, cluster.getName()); + values.put(GlusterConstants.VOLUME, task.getTaskParameters().getVolumeName()); + String jobStatus = getJobStatusInfo(task); + values.put(GlusterConstants.JOB_STATUS, jobStatus); + values.put(GlusterConstants.JOB_INFO, task.getMessage()); + return values; + } + + private String getJobStatusInfo(GlusterAsyncTask task) { + String jobStatus = task.getStatus().toString(); + if (task.getType() == GlusterTaskType.REMOVE_BRICK) { + switch (task.getStatus()) { + case FINISHED: + jobStatus = REMOVE_BRICK_FINISHED; + break; + case STARTED: + jobStatus = REMOVE_BRICK_IN_PROGRESS; + break; + case FAILED: + jobStatus = REMOVE_BRICK_FAILED; + break; + default: + break; + } + } + if (task.getType() == GlusterTaskType.REBALANCE) { + switch (task.getStatus()) { + case STARTED: + jobStatus = REBALANCE_IN_PROGRESS; + break; + default: + break; + } + } + return jobStatus; + } + + public void updateSteps(VDSGroup cluster, GlusterAsyncTask task, List<Step> steps) { + // update status in step table + for (Step step : steps) { + if (step.getEndTime() != null) { + // we have already processed the task + continue; + } + step.setDescription(getTaskMessage(cluster, step.getStepType(), task)); + step.setStatus(task.getStatus()); + if (hasTaskCompleted(task)) { + step.markStepEnded(task.getStatus()); + endStepJob(step); + releaseVolumeLock(task.getTaskId()); + } else { + getJobRepository().updateStep(step); + } + } + } + + public boolean supportsGlusterAsyncTasksFeature(VDSGroup cluster) { + return cluster.supportsGlusterService() + && GlusterFeatureSupported.glusterAsyncTasks(cluster.getcompatibility_version()); + } + + public GlusterVolumeDao getVolumeDao() { + return DbFacade.getInstance().getGlusterVolumeDao(); + } + + public JobRepository getJobRepository() { + return JobRepositoryFactory.getJobRepository(); + } + + public LockManager getLockManager() { + return LockManagerFactory.getLockManager(); + } } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJobTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJobTest.java index f56b97f..63ba3cc 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJobTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJobTest.java @@ -19,6 +19,7 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; +import org.ovirt.engine.core.bll.gluster.tasks.GlusterTaskUtils; import org.ovirt.engine.core.bll.gluster.tasks.GlusterTasksService; import org.ovirt.engine.core.bll.interfaces.BackendInternal; import org.ovirt.engine.core.bll.job.JobRepository; @@ -80,6 +81,8 @@ @Mock private BackendInternal backend; + private GlusterTaskUtils taskUtils; + private GlusterAuditLogUtil logUtil; private GlusterTasksSyncJob tasksSyncJob; @@ -94,6 +97,7 @@ MockitoAnnotations.initMocks(this); tasksSyncJob = Mockito.spy(GlusterTasksSyncJob.getInstance()); logUtil = Mockito.spy(GlusterAuditLogUtil.getInstance()); + taskUtils = Mockito.spy(GlusterTaskUtils.getInstance()); doNothing().when(logUtil).logClusterMessage(any(Guid.class), any(AuditLogType.class)); doReturn(clusterDao).when(tasksSyncJob).getClusterDao(); @@ -101,11 +105,14 @@ doReturn(provider).when(tasksSyncJob).getProvider(); doReturn(stepDao).when(tasksSyncJob).getStepDao(); doReturn(volumeDao).when(tasksSyncJob).getVolumeDao(); + doReturn(volumeDao).when(taskUtils).getVolumeDao(); doReturn(jobRepository).when(tasksSyncJob).getJobRepository(); + doReturn(jobRepository).when(taskUtils).getJobRepository(); doReturn(backend).when(tasksSyncJob).getBackend(); + doReturn(taskUtils).when(tasksSyncJob).getGlusterTaskUtils(); doNothing().when(tasksSyncJob).releaseLock(any(Guid.class)); - doNothing().when(tasksSyncJob).endStepJob(any(Step.class)); - + doNothing().when(taskUtils).endStepJob(any(Step.class)); + doNothing().when(taskUtils).releaseLock(any(Guid.class)); } @Test @@ -115,7 +122,7 @@ tasksSyncJob.updateGlusterAsyncTasks(); Mockito.verify(jobRepository, times(1)).updateStep(any(Step.class)); - Mockito.verify(tasksSyncJob, times(1)).endStepJob(any(Step.class)); + Mockito.verify(taskUtils, times(1)).endStepJob(any(Step.class)); } @Test @@ -125,7 +132,7 @@ Mockito.verify(volumeDao, times(0)).updateVolumeTask(VOL_GUIDS[0], null); Mockito.verify(volumeDao, times(0)).updateVolumeTask(VOL_GUIDS[1], null); Mockito.verify(jobRepository, times(0)).updateStep(any(Step.class)); - Mockito.verify(tasksSyncJob, times(0)).endStepJob(any(Step.class)); + Mockito.verify(taskUtils, times(0)).endStepJob(any(Step.class)); } @Test @@ -137,7 +144,7 @@ tasksSyncJob.updateGlusterAsyncTasks(); Mockito.verify(jobRepository, times(0)).updateStep(any(Step.class)); - Mockito.verify(tasksSyncJob, times(0)).endStepJob(any(Step.class)); + Mockito.verify(taskUtils, times(0)).endStepJob(any(Step.class)); Mockito.verify(backend, times(6)).runInternalAction(any(VdcActionType.class), any(VdcActionParametersBase.class)); } @@ -150,7 +157,7 @@ tasksSyncJob.updateGlusterAsyncTasks(); Mockito.verify(jobRepository, times(0)).updateStep(any(Step.class)); - Mockito.verify(tasksSyncJob, times(0)).endStepJob(any(Step.class)); + Mockito.verify(taskUtils, times(0)).endStepJob(any(Step.class)); Mockito.verify(backend, times(2)).runInternalAction(any(VdcActionType.class), any(VdcActionParametersBase.class)); } @@ -161,7 +168,7 @@ prepareMocks(); tasksSyncJob.updateGlusterAsyncTasks(); Mockito.verify(jobRepository, times(2)).updateStep(any(Step.class)); - Mockito.verify(tasksSyncJob, times(0)).endStepJob(any(Step.class)); + Mockito.verify(taskUtils, times(0)).endStepJob(any(Step.class)); } @Test @@ -170,7 +177,7 @@ prepareMocks(); tasksSyncJob.updateGlusterAsyncTasks(); Mockito.verify(jobRepository, times(0)).updateStep(any(Step.class)); - Mockito.verify(tasksSyncJob, times(2)).endStepJob(any(Step.class)); + Mockito.verify(taskUtils, times(2)).endStepJob(any(Step.class)); } private void prepareMocks() { @@ -192,7 +199,6 @@ steps.add(createStep()); return steps; } - private Step createStep() { Step step = new Step(); @@ -254,5 +260,4 @@ cluster.setcompatibility_version(v); return cluster; } - } -- To view, visit http://gerrit.ovirt.org/21063 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I1abecae9389530324154cdc059ee717db0a61715 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Shubhendu Tripathi <shtri...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches