Ramesh N has uploaded a new change for review. Change subject: engine: BLL command to refresh volume details ......................................................................
engine: BLL command to refresh volume details Create a new BLL command to refresh volume details. It will make use of the GlusterSyncJob to refresh volume details. Change-Id: Ie06c6a45e00f35df45e130cdceb592e81b67998e Signed-off-by: Ramesh Nachimuthu <[email protected]> --- A backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/RefreshGlusterVolumeDetailsCommand.java A backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/RefreshGlusterVolumeDetailsCommandTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java M backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java M backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties M frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java M frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties A packaging/dbscripts/upgrade/03_04_0590_gluster_refresh_gluster_volume_details-event_map.sql 9 files changed, 230 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/47/24447/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/RefreshGlusterVolumeDetailsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/RefreshGlusterVolumeDetailsCommand.java new file mode 100644 index 0000000..dd3eb60 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/RefreshGlusterVolumeDetailsCommand.java @@ -0,0 +1,62 @@ +package org.ovirt.engine.core.bll.gluster; + +import org.ovirt.engine.core.bll.LockIdNameAttribute; +import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute; +import org.ovirt.engine.core.common.AuditLogType; +import org.ovirt.engine.core.common.action.gluster.GlusterVolumeParameters; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity; +import org.ovirt.engine.core.common.errors.VdcBllMessages; + + +/** + * BLL command to refresh gluster volume details + */ +@NonTransactiveCommandAttribute +@LockIdNameAttribute(isWait = true) +public class RefreshGlusterVolumeDetailsCommand extends GlusterVolumeCommandBase<GlusterVolumeParameters> { + + public RefreshGlusterVolumeDetailsCommand(GlusterVolumeParameters params) { + super(params); + } + + @Override + protected void setActionMessageParameters() { + addCanDoActionMessage(VdcBllMessages.VAR__ACTION__REFRESH); + addCanDoActionMessage(VdcBllMessages.VAR__TYPE__GLUSTER_VOLUME); + } + + @Override + protected boolean canDoAction() { + if(!super.canDoAction()) { + return false; + } + + GlusterVolumeEntity glusterVolume = getGlusterVolume(); + if (!glusterVolume.isOnline()) { + return failCanDoAction(VdcBllMessages.ACTION_TYPE_FAILED_GLUSTER_VOLUME_SHOULD_BE_STARTED); + } + + return true; + } + + protected GlusterSyncJob getSyncJobInstance() { + return GlusterSyncJob.getInstance(); + } + + @Override + protected void executeCommand() { + + getSyncJobInstance().refreshVolumeDetails(upServer, getGlusterVolume()); + setSucceeded(true); + + } + + @Override + public AuditLogType getAuditLogTypeValue() { + if (getSucceeded()) { + return AuditLogType.GLUSTER_VOLUME_DETAILS_REFRESH; + } else { + return errorType == null ? AuditLogType.GLUSTER_VOLUME_DETAILS_REFRESH_FAILED : errorType; + } + } +} diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/RefreshGlusterVolumeDetailsCommandTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/RefreshGlusterVolumeDetailsCommandTest.java new file mode 100644 index 0000000..81e52f4 --- /dev/null +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/RefreshGlusterVolumeDetailsCommandTest.java @@ -0,0 +1,150 @@ +package org.ovirt.engine.core.bll.gluster; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.ovirt.engine.core.common.AuditLogType; +import org.ovirt.engine.core.common.action.gluster.GlusterVolumeParameters; +import org.ovirt.engine.core.common.businessentities.VDS; +import org.ovirt.engine.core.common.businessentities.VDSStatus; +import org.ovirt.engine.core.common.businessentities.gluster.AccessProtocol; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity; +import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType; +import org.ovirt.engine.core.common.businessentities.gluster.TransportType; +import org.ovirt.engine.core.compat.Guid; +import org.ovirt.engine.core.dao.VdsGroupDAO; +import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao; + + +@RunWith(MockitoJUnitRunner.class) +public class RefreshGlusterVolumeDetailsCommandTest { + + private Guid volumeId1 = new Guid("8bc6f108-c0ef-43ab-ba20-ec41107220f5"); + private Guid volumeId2 = new Guid("b2cb2f73-fab3-4a42-93f0-d5e4c069a43e"); + private Guid CLUSTER_ID = new Guid("b399944a-81ab-4ec5-8266-e19ba7c3c9d1"); + + @Mock + GlusterVolumeDao volumeDao; + + /** + * The command under test. + */ + private RefreshGlusterVolumeDetailsCommand cmd; + + @Mock + private VdsGroupDAO vdsGroupDao; + + @Mock + private GlusterSyncJob syncJob; + + private void prepareMocks(RefreshGlusterVolumeDetailsCommand command) { + doReturn(volumeDao).when(command).getGlusterVolumeDao(); + doReturn(getVds(VDSStatus.Up)).when(command).getUpServer(); + doReturn(getDistributedVolume(volumeId1)).when(volumeDao).getById(volumeId1); + doReturn(getDistributedVolume(volumeId2)).when(volumeDao).getById(volumeId2); + doReturn(null).when(volumeDao).getById(null); + doNothing().when(syncJob).refreshVolumeDetails(any(VDS.class), any(GlusterVolumeEntity.class)); + when(cmd.getSyncJobInstance()).thenReturn(syncJob); + + } + + private VDS getVds(VDSStatus status) { + VDS vds = new VDS(); + vds.setId(Guid.newGuid()); + vds.setVdsName("gfs1"); + vds.setVdsGroupId(CLUSTER_ID); + vds.setStatus(status); + return vds; + } + + private GlusterVolumeEntity getDistributedVolume(Guid volumeId) { + GlusterVolumeEntity volume = getVolume(volumeId); + volume.setStatus((volumeId == volumeId1) ? GlusterStatus.UP : GlusterStatus.DOWN); + volume.setBricks(getBricks(volumeId, 2)); + volume.setVolumeType(GlusterVolumeType.DISTRIBUTE); + volume.setClusterId(CLUSTER_ID); + return volume; + } + + private GlusterVolumeEntity getVolume(Guid id) { + GlusterVolumeEntity volumeEntity = new GlusterVolumeEntity(); + volumeEntity.setId(id); + volumeEntity.setName("test-vol"); + volumeEntity.addAccessProtocol(AccessProtocol.GLUSTER); + volumeEntity.addTransportType(TransportType.TCP); + return volumeEntity; + } + + private List<GlusterBrickEntity> getBricks(Guid volumeId, int n) { + List<GlusterBrickEntity> bricks = new ArrayList<GlusterBrickEntity>(); + GlusterBrickEntity brick; + for (Integer i = 0; i < n; i++) { + brick = new GlusterBrickEntity(); + brick.setVolumeId(volumeId); + brick.setBrickDirectory("/tmp/test-vol" + i.toString()); + brick.setStatus(GlusterStatus.UP); + bricks.add(brick); + } + return bricks; + } + + protected VDS getServer() { + VDS server = new VDS(); + server.setId(Guid.newGuid()); + server.setVdsName("VDS1"); + server.setStatus(VDSStatus.Up); + server.setVdsGroupId(CLUSTER_ID); + return server; + } + + private RefreshGlusterVolumeDetailsCommand createTestCommand(Guid volumeId) { + return new RefreshGlusterVolumeDetailsCommand(new GlusterVolumeParameters(volumeId)); + } + + @Test + public void canDoActionFailesOnDownVolume() { + cmd = spy(createTestCommand(volumeId2)); + prepareMocks(cmd); + assertFalse(cmd.canDoAction()); + } + + @Test + public void canDoActionFailsOnNull() { + cmd = spy(createTestCommand(null)); + prepareMocks(cmd); + assertFalse(cmd.canDoAction()); + } + + @Test + public void canDoActionSucceedsOnUpVolume() { + cmd = spy(createTestCommand(volumeId1)); + prepareMocks(cmd); + assertTrue(cmd.canDoAction()); + } + + @Test + public void executeCommand() { + cmd = spy(createTestCommand(volumeId1)); + prepareMocks(cmd); + cmd.executeCommand(); + assertEquals(cmd.getAuditLogTypeValue(), AuditLogType.GLUSTER_VOLUME_DETAILS_REFRESH); + verify(syncJob, times(1)).refreshVolumeDetails(any(VDS.class), any(GlusterVolumeEntity.class)); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java index 50b942c..7487ceb 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java @@ -318,6 +318,8 @@ START_REMOVING_GLUSTER_VOLUME_BRICKS_DETECTED_FROM_CLI(4090), GLUSTER_VOLUME_REBALANCE_NOT_FOUND_FROM_CLI(4091), REMOVE_GLUSTER_VOLUME_BRICKS_NOT_FOUND_FROM_CLI(4092), + GLUSTER_VOLUME_DETAILS_REFRESH(4093), + GLUSTER_VOLUME_DETAILS_REFRESH_FAILED(4094), USER_FORCE_SELECTED_SPM(159), USER_VDS_RESTART(41), diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java index 7f68031..a635343 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java @@ -282,6 +282,8 @@ StartRemoveGlusterVolumeBricks(1422, ActionGroup.MANIPULATE_GLUSTER_VOLUME, QuotaDependency.NONE), StopRemoveGlusterVolumeBricks(1423, ActionGroup.MANIPULATE_GLUSTER_VOLUME, false, QuotaDependency.NONE), CommitRemoveGlusterVolumeBricks(1424, ActionGroup.MANIPULATE_GLUSTER_VOLUME, false, QuotaDependency.NONE), + RefreshGlusterVolumeDetails(1425, ActionGroup.MANIPULATE_GLUSTER_VOLUME, QuotaDependency.NONE), + // Cluster Policy AddClusterPolicy(1450, ActionGroup.EDIT_STORAGE_POOL_CONFIGURATION, false, QuotaDependency.NONE), EditClusterPolicy(1451, ActionGroup.EDIT_STORAGE_POOL_CONFIGURATION, false, QuotaDependency.NONE), diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java index ffeead5..47f8ea0 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AuditLogDirector.java @@ -156,6 +156,8 @@ severities.put(AuditLogType.GLUSTER_HOOK_REMOVE_FAILED, AuditLogSeverity.ERROR); severities.put(AuditLogType.GLUSTER_HOOK_REFRESH, AuditLogSeverity.NORMAL); severities.put(AuditLogType.GLUSTER_HOOK_REFRESH_FAILED, AuditLogSeverity.ERROR); + severities.put(AuditLogType.GLUSTER_VOLUME_DETAILS_REFRESH, AuditLogSeverity.NORMAL); + severities.put(AuditLogType.GLUSTER_VOLUME_DETAILS_REFRESH_FAILED, AuditLogSeverity.ERROR); severities.put(AuditLogType.GLUSTER_SERVICE_STARTED, AuditLogSeverity.NORMAL); severities.put(AuditLogType.GLUSTER_SERVICE_START_FAILED, AuditLogSeverity.ERROR); severities.put(AuditLogType.GLUSTER_SERVICE_STOPPED, AuditLogSeverity.NORMAL); diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties index ebb8653..3eebdc8 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties @@ -712,6 +712,8 @@ GLUSTER_HOOK_REMOVE_FAILED=Failed to remove Gluster Hook ${GlusterHookName} from cluster ${VdsGroupName}. ${FailureMessage} GLUSTER_HOOK_REFRESH=Refreshed gluster hooks in Cluster ${VdsGroupName}. GLUSTER_HOOK_REFRESH_FAILED=Failed to refresh gluster hooks in Cluster ${VdsGroupName}. +GLUSTER_VOLUME_DETAILS_REFRESH=Refreshed details of the volume ${glusterVolumeName}. +GLUSTER_VOLUME_DETAILS_REFRESH_FAILED=Failed to refresh the details of volume ${glusterVolumeName}. GLUSTER_SERVICE_STARTED=${servicetype} service started on host ${VdsName} on cluster ${VdsGroupName}. GLUSTER_SERVICE_START_FAILED=Could not start ${servicetype} service on host ${VdsName} on cluster ${VdsGroupName}. GLUSTER_SERVICE_STOPPED=${servicetype} services stopped on host ${VdsName} on cluster ${VdsGroupName}. diff --git a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java index 82f4509..c86927f 100644 --- a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java +++ b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java @@ -357,6 +357,10 @@ String AuditLogType___GLUSTER_HOOK_REFRESH_FAILED(); + String AuditLogType___GLUSTER_VOLUME_DETAILS_REFRESH(); + + String AuditLogType___GLUSTER_VOLUME_DETAILS_REFRESH_FAILED(); + String AuditLogType___GLUSTER_HOOK_CONFLICT_DETECTED(); String AuditLogType___GLUSTER_HOOK_DETECTED_NEW(); diff --git a/frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties b/frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties index 3d56d83..9b95fc9 100644 --- a/frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties +++ b/frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties @@ -175,6 +175,8 @@ AuditLogType___GLUSTER_HOOK_REMOVE_FAILED=Failed to remove Gluster Hook from cluster AuditLogType___GLUSTER_HOOK_REFRESH=Gluster Hooks refreshed AuditLogType___GLUSTER_HOOK_REFRESH_FAILED=Failed to refresh Gluster Hooks +AuditLogType___GLUSTER_VOLUME_DETAILS_REFRESH=Refreshed details of the volume +AuditLogType___GLUSTER_VOLUME_DETAILS_REFRESH_FAILED=Failed to refresh the details of volume AuditLogType___GLUSTER_HOOK_CONFLICT_DETECTED=Detected conflict in Gluster Hook AuditLogType___GLUSTER_HOOK_DETECTED_NEW=Detected new Gluster Hook AuditLogType___GLUSTER_HOOK_DETECTED_DELETE=Detected removal of Gluster Hook @@ -184,7 +186,7 @@ AuditLogType___GLUSTER_SERVICE_STOP_FAILED=Failed to stop Gluster service AuditLogType___GLUSTER_SERVICE_RESTARTED=Gluster Service re-started AuditLogType___GLUSTER_SERVICE_RESTART_FAILED=Failed to re-start Gluster Service -AuditLogType___GLUSTER_VOLUME_REMOVE_BRICKS_STOP=Stopped removing bricks from Gluster Volume +AuditLogType___GLUSTER_VOLUME_REMOVE_BRICKS_STOP=Stopped removing bricks from Gluster Volume AuditLogType___GLUSTER_VOLUME_REMOVE_BRICKS_STOP_FAILED=Failed to stop remove bricks from Gluster Volume AuditLogType___GLUSTER_BRICK_STATUS_CHANGED=Detected change in status of brick AuditLogType___GLUSTER_VOLUME_REBALANCE_NOT_FOUND_FROM_CLI=Could not find information for rebalance on volume from CLI. Marking it as unknown. diff --git a/packaging/dbscripts/upgrade/03_04_0590_gluster_refresh_gluster_volume_details-event_map.sql b/packaging/dbscripts/upgrade/03_04_0590_gluster_refresh_gluster_volume_details-event_map.sql new file mode 100644 index 0000000..4241b9f --- /dev/null +++ b/packaging/dbscripts/upgrade/03_04_0590_gluster_refresh_gluster_volume_details-event_map.sql @@ -0,0 +1,3 @@ +insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_DETAILS_REFRESH', 'UNASSIGNED'); +insert into event_map(event_up_name, event_down_name) values('GLUSTER_VOLUME_DETAILS_REFRESH_FAILED', 'UNASSIGNED'); + -- To view, visit http://gerrit.ovirt.org/24447 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie06c6a45e00f35df45e130cdceb592e81b67998e Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.4 Gerrit-Owner: Ramesh N <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
