Sahina Bose has uploaded a new change for review.

Change subject: engine: Log when gluster task started from CLI
......................................................................

engine: Log when gluster task started from CLI

Add event log messages when a gluster task - rebalance
or remove brick - is started from CLI

Change-Id: I381ecc028ff5dd36202916953f5c3c623b43e526
Bug-Url: https://bugzilla.redhat.com/1015444
Signed-off-by: Sahina Bose <sab...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterTasksSyncJob.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/VdcEventNotificationUtils.java
M 
backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
A 
packaging/dbscripts/upgrade/03_04_0170_gluster_async_tasks_fromcli_event_map.sql
5 files changed, 57 insertions(+), 20 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/78/22078/1

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 a7a48e0..5df229b 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
@@ -8,6 +8,7 @@
 import java.util.Map.Entry;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
 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;
@@ -15,6 +16,7 @@
 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.AuditLogType;
 import org.ovirt.engine.core.common.action.AddInternalJobParameters;
 import org.ovirt.engine.core.common.action.AddStepParameters;
 import org.ovirt.engine.core.common.action.VdcActionType;
@@ -26,6 +28,7 @@
 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.constants.gluster.GlusterConstants;
 import org.ovirt.engine.core.common.errors.VdcBLLException;
 import org.ovirt.engine.core.common.errors.VdcBllErrors;
 import org.ovirt.engine.core.common.job.ExternalSystemType;
@@ -33,6 +36,7 @@
 import org.ovirt.engine.core.common.job.Step;
 import org.ovirt.engine.core.common.job.StepEnum;
 import org.ovirt.engine.core.compat.Guid;
+import 
org.ovirt.engine.core.dal.dbbroker.auditloghandling.gluster.GlusterAuditLogUtil;
 import org.ovirt.engine.core.dal.job.ExecutionMessageDirector;
 import org.ovirt.engine.core.dao.gluster.GlusterDBUtils;
 import org.ovirt.engine.core.utils.log.Log;
@@ -153,7 +157,6 @@
                 task.getTaskId(),
                 ExternalSystemType.GLUSTER);
         updateVolumeBricksAndLock(cluster, task);
-
     }
 
     private Guid addAsyncTaskStep(VDSGroup cluster, GlusterAsyncTask task, 
StepEnum step, Guid execStepId) {
@@ -211,29 +214,30 @@
                 if (GlusterTaskType.REMOVE_BRICK == task.getType()) {
                     //update bricks associated with task id
                     String[] bricks = task.getTaskParameters().getBricks();
-                    if (bricks == null)
+
+                    if (bricks != null)
                     {
-                        return;
-                    }
-                    List<GlusterBrickEntity> brickEntities = new ArrayList<>();
-                    for (String brick: bricks) {
-                        String[] brickParts = brick.split(":", -1);
-                        String hostnameOrIp = brickParts[0];
-                        String brickDir = brickParts[1];
-                        GlusterBrickEntity brickEntity = new 
GlusterBrickEntity();
-                        VdsStatic server = 
GlusterDBUtils.getInstance().getServer(cluster.getId(), hostnameOrIp);
-                        if (server == null) {
-                            log.warnFormat("Could not find server {0} in 
cluster {1}", hostnameOrIp, cluster.getId());
-                        } else {
-                            brickEntity.setServerId(server.getId());
-                            brickEntity.setBrickDirectory(brickDir);
-                            brickEntity.setAsyncTask(new GlusterAsyncTask());
-                            
brickEntity.getAsyncTask().setTaskId(task.getTaskId());
-                            brickEntities.add(brickEntity);
+                        List<GlusterBrickEntity> brickEntities = new 
ArrayList<>();
+                        for (String brick: bricks) {
+                            String[] brickParts = brick.split(":", -1);
+                            String hostnameOrIp = brickParts[0];
+                            String brickDir = brickParts[1];
+                            GlusterBrickEntity brickEntity = new 
GlusterBrickEntity();
+                            VdsStatic server = 
GlusterDBUtils.getInstance().getServer(cluster.getId(), hostnameOrIp);
+                            if (server == null) {
+                                log.warnFormat("Could not find server {0} in 
cluster {1}", hostnameOrIp, cluster.getId());
+                            } else {
+                                brickEntity.setServerId(server.getId());
+                                brickEntity.setBrickDirectory(brickDir);
+                                brickEntity.setAsyncTask(new 
GlusterAsyncTask());
+                                
brickEntity.getAsyncTask().setTaskId(task.getTaskId());
+                                brickEntities.add(brickEntity);
+                            }
                         }
+                        
getBrickDao().updateAllBrickTasksByHostIdBrickDirInBatch(brickEntities);
                     }
-                    
getBrickDao().updateAllBrickTasksByHostIdBrickDirInBatch(brickEntities);
                 }
+                logTaskStartedFromCLI(cluster, task, vol);
             } catch (Exception e) {
                 log.error(e);
                 throw new VdcBLLException(VdcBllErrors.GeneralException, 
e.getMessage());
@@ -247,6 +251,29 @@
         }
     }
 
+    private void logTaskStartedFromCLI(VDSGroup cluster, GlusterAsyncTask 
task, GlusterVolumeEntity vol) {
+        Map<String, String> values = new HashMap<String, String>();
+
+        AuditLogType logType;
+        switch (task.getType()) {
+        case REBALANCE:
+            logType = 
AuditLogType.GLUSTER_VOLUME_REBALANCE_START_DETECTED_FROM_CLI;
+            break;
+        case REMOVE_BRICK:
+            logType = 
AuditLogType.START_REMOVING_GLUSTER_VOLUME_BRICKS_DETECTED_FROM_CLI;
+            values.put(GlusterConstants.BRICK, 
StringUtils.join(task.getTaskParameters().getBricks(), ','));
+            break;
+         default:
+            logType = AuditLogType.UNASSIGNED;
+            break;
+        }
+        getGlusterLogUtil().logAuditMessage(cluster.getId(), vol, null, 
logType, values);
+    }
+
+    protected GlusterAuditLogUtil getGlusterLogUtil() {
+        return GlusterAuditLogUtil.getInstance();
+    }
+
     public GlusterTaskUtils getGlusterTaskUtils() {
         return GlusterTaskUtils.getInstance();
     }
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 18b5dfe..af38202 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
@@ -307,6 +307,9 @@
     GLUSTER_BRICK_STATUS_CHANGED(4086),
     GLUSTER_VOLUME_REBALANCE_FINISHED(4087),
     GLUSTER_VOLUME_MIGRATE_BRICK_DATA_FINISHED(4088),
+    GLUSTER_VOLUME_REBALANCE_START_DETECTED_FROM_CLI(4089),
+    START_REMOVING_GLUSTER_VOLUME_BRICKS_DETECTED_FROM_CLI(4090),
+
 
     USER_FORCE_SELECTED_SPM(159),
     USER_VDS_RESTART(41),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/VdcEventNotificationUtils.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/VdcEventNotificationUtils.java
index 8780986..cc1164e 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/VdcEventNotificationUtils.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/VdcEventNotificationUtils.java
@@ -77,6 +77,8 @@
         AddEventNotificationEntry(EventNotificationEntity.GlusterVolume, 
AuditLogType.GLUSTER_VOLUME_REPLACE_BRICK_FAILED);
         AddEventNotificationEntry(EventNotificationEntity.GlusterVolume, 
AuditLogType.GLUSTER_VOLUME_REPLACE_BRICK_START);
         AddEventNotificationEntry(EventNotificationEntity.GlusterVolume, 
AuditLogType.GLUSTER_VOLUME_REPLACE_BRICK_START_FAILED);
+        AddEventNotificationEntry(EventNotificationEntity.GlusterVolume, 
AuditLogType.GLUSTER_VOLUME_REBALANCE_START_DETECTED_FROM_CLI);
+        AddEventNotificationEntry(EventNotificationEntity.GlusterVolume, 
AuditLogType.START_REMOVING_GLUSTER_VOLUME_BRICKS_DETECTED_FROM_CLI);
         AddEventNotificationEntry(EventNotificationEntity.Host, 
AuditLogType.GLUSTER_SERVER_ADD_FAILED);
         AddEventNotificationEntry(EventNotificationEntity.Host, 
AuditLogType.GLUSTER_SERVER_REMOVE);
         AddEventNotificationEntry(EventNotificationEntity.Host, 
AuditLogType.GLUSTER_SERVER_REMOVE_FAILED);
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 5176e29..4d57117 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -626,6 +626,8 @@
 GLUSTER_VOLUME_REBALANCE_FINISHED=${action} ${status} on volume 
${glusterVolumeName}.
 GLUSTER_VOLUME_MIGRATE_BRICK_DATA_FINISHED=${action} ${status} for brick(s) on 
volume ${glusterVolumeName}. Please review to abort or commit.
 GLUSTER_SERVER_ADD_FAILED=Failed to add gluster server ${VdsName} into Cluster 
${VdsGroupName}.
+GLUSTER_VOLUME_REBALANCE_START_DETECTED_FROM_CLI=Detected start of rebalance 
on volume ${glusterVolumeName} of Cluster ${VdsGroupName} from CLI.
+START_REMOVING_GLUSTER_VOLUME_BRICKS_DETECTED_FROM_CLI=Detected start of brick 
removal for bricks ${brick} on volume ${glusterVolumeName} of Cluster 
${VdsGroupName} from CLI.
 GLUSTER_SERVER_REMOVE=Gluster server ${VdsName} removed from Cluster 
${VdsGroupName}.
 GLUSTER_SERVER_REMOVE_FAILED=Failed to remove gluster server ${VdsName} from 
Cluster ${VdsGroupName}.
 GLUSTER_SERVERS_LIST_FAILED=Failed to fetch gluster peer list from server 
${VdsName} on Cluster ${VdsGroupName}.
diff --git 
a/packaging/dbscripts/upgrade/03_04_0170_gluster_async_tasks_fromcli_event_map.sql
 
b/packaging/dbscripts/upgrade/03_04_0170_gluster_async_tasks_fromcli_event_map.sql
new file mode 100644
index 0000000..3ffbc9d
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_04_0170_gluster_async_tasks_fromcli_event_map.sql
@@ -0,0 +1,3 @@
+insert into event_map(event_up_name, event_down_name) 
values('GLUSTER_VOLUME_REBALANCE_START_DETECTED_FROM_CLI', 'UNASSIGNED');
+insert into event_map(event_up_name, event_down_name) 
values('START_REMOVING_GLUSTER_VOLUME_BRICKS_DETECTED_FROM_CLI', 'UNASSIGNED');
+


-- 
To view, visit http://gerrit.ovirt.org/22078
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I381ecc028ff5dd36202916953f5c3c623b43e526
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Sahina Bose <sab...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to