Shireesh Anjal has uploaded a new change for review.

Change subject: gluster: Make set option a step of create volume
......................................................................

gluster: Make set option a step of create volume

Modified the CreateGlusterVolumeCommand to invoke
SetGlusterVolumeOptionCommand as a child step of itself.

Also enhanced the job message for CreateGlusterVolume
to display name of the volume being created.

Change-Id: Ie0f22e9862584f1a616fcc01e8a80b7d5a5ffc78
Signed-off-by: Shireesh Anjal <san...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/gluster/GlusterConstants.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/job/StepEnum.java
M 
backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
5 files changed, 76 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/05/10905/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeCommand.java
index 5b766c6..4f150a7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeCommand.java
@@ -1,10 +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 org.ovirt.engine.core.bll.LockIdNameAttribute;
 import org.ovirt.engine.core.bll.NonTransactiveCommandAttribute;
+import org.ovirt.engine.core.bll.context.CommandContext;
+import org.ovirt.engine.core.bll.job.ExecutionContext;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
@@ -17,6 +21,9 @@
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeType;
 import org.ovirt.engine.core.common.businessentities.gluster.TransportType;
+import org.ovirt.engine.core.common.constants.gluster.GlusterConstants;
+import org.ovirt.engine.core.common.job.Step;
+import org.ovirt.engine.core.common.job.StepEnum;
 import org.ovirt.engine.core.common.validation.group.CreateEntity;
 import 
org.ovirt.engine.core.common.validation.group.gluster.CreateReplicatedVolume;
 import 
org.ovirt.engine.core.common.validation.group.gluster.CreateStripedVolume;
@@ -40,6 +47,15 @@
         super(params);
         volume = getParameters().getVolume();
         setVdsGroupId(volume.getClusterId());
+    }
+
+    @Override
+    public Map<String, String> getJobMessageProperties() {
+        if (jobProperties == null) {
+            jobProperties = super.getJobMessageProperties();
+            jobProperties.put(GlusterConstants.VOLUME, 
getParameters().getVolume().getName());
+        }
+        return jobProperties;
     }
 
     @Override
@@ -169,10 +185,12 @@
         for (GlusterVolumeOptionEntity option : volume.getOptions()) {
             // make sure that volume id is set
             option.setVolumeId(volume.getId());
+
             VdcReturnValueBase setOptionReturnValue =
                     runBllAction(
                             VdcActionType.SetGlusterVolumeOption,
-                            new GlusterVolumeOptionParameters(option));
+                            new GlusterVolumeOptionParameters(option),
+                            createCommandContext(volume, option));
             if (!getSucceeded()) {
                 errors.addAll(setOptionReturnValue.getCanDoActionMessages());
                 errors.addAll(setOptionReturnValue.getExecuteFailedMessages());
@@ -185,6 +203,35 @@
     }
 
     /**
+     * Creates command context for setting a given option on the given volume
+     *
+     * @param volume
+     * @param option
+     * @return
+     */
+    private CommandContext createCommandContext(GlusterVolumeEntity volume, 
GlusterVolumeOptionEntity option) {
+        // Add sub-step for setting given option
+        Step setOptionStep = addSubStep(StepEnum.EXECUTING,
+                StepEnum.SETTING_GLUSTER_OPTION, getOptionValues(volume, 
option));
+
+        // Create execution context for setting option
+        ExecutionContext setOptionCtx = new ExecutionContext();
+        setOptionCtx.setMonitored(true);
+        setOptionCtx.setStep(setOptionStep);
+
+        return new CommandContext(setOptionCtx, getCompensationContext());
+    }
+
+    private Map<String, String> getOptionValues(GlusterVolumeEntity volume, 
GlusterVolumeOptionEntity option) {
+        Map<String, String> values = new HashMap<String, String>();
+        values.put(GlusterConstants.CLUSTER, getVdsGroupName());
+        values.put(GlusterConstants.VOLUME, volume.getName());
+        values.put(GlusterConstants.OPTION_KEY, option.getKey());
+        values.put(GlusterConstants.OPTION_VALUE, option.getValue());
+        return values;
+    }
+
+    /**
      * Validates the the number of bricks against the replica count or stripe 
count based on volume type
      *
      * @param volume
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
index ca705dc..098d57f 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterCommandBase.java
@@ -8,6 +8,7 @@
 import org.apache.commons.lang.SystemUtils;
 import org.ovirt.engine.core.bll.Backend;
 import org.ovirt.engine.core.bll.CommandBase;
+import org.ovirt.engine.core.bll.context.CommandContext;
 import org.ovirt.engine.core.bll.utils.ClusterUtils;
 import org.ovirt.engine.core.bll.utils.PermissionSubject;
 import org.ovirt.engine.core.common.AuditLogType;
@@ -97,6 +98,20 @@
         return returnValue;
     }
 
+    /**
+     * Executes given BLL action, updates the success flag based on the 
result, and returns the result
+     *
+     * @param actionType
+     * @param params
+     * @param context
+     * @return
+     */
+    protected VdcReturnValueBase runBllAction(VdcActionType actionType, 
VdcActionParametersBase params, CommandContext context) {
+        VdcReturnValueBase returnValue = 
Backend.getInstance().runInternalAction(actionType, params, context);
+        setSucceeded(returnValue.getSucceeded());
+        return returnValue;
+    }
+
     protected void handleVdsErrors(AuditLogType errType, List<String> errors) {
         errorType = errType;
         getReturnValue().getExecuteFailedMessages().addAll(errors);
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/gluster/GlusterConstants.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/gluster/GlusterConstants.java
index ed417ac..f946cb4 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/gluster/GlusterConstants.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/constants/gluster/GlusterConstants.java
@@ -10,4 +10,11 @@
 
     public static final int DEFAULT_REPLICA_COUNT = 2;
     public static final int DEFAULT_STRIPE_COUNT = 4;
+
+    // Variables used in audit messages.
+    // Keep the values lowercase to avoid call to String#toLowerCase()
+    public static final String CLUSTER = "cluster";
+    public static final String VOLUME = "glustervolume";
+    public static final String OPTION_KEY = "key";
+    public static final String OPTION_VALUE = "value";
 }
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/job/StepEnum.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/job/StepEnum.java
index 5518536..17a4b18 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/job/StepEnum.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/job/StepEnum.java
@@ -20,6 +20,9 @@
     RUN_STATELESS_VM,
     TAKING_VM_FROM_POOL,
 
+    // Gluster
+    SETTING_GLUSTER_OPTION,
+
     /**
      * Maps VDSM tasks type to {@code StepEnum} so it can be resolvable as 
readable description
      */
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
 
b/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
index 165f4ec..cce6bcb 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/ExecutionMessages.properties
@@ -72,7 +72,7 @@
 job.RemoveSnapshot=Removing Snapshot ${Snapshot} of VM ${VM}
 job.StartGlusterVolumeProfile=Start Profiling on Gluster Volume 
${GlusterVolume}
 job.StopGlusterVolumeProfile=Stop Profiling on Gluster Volume ${GlusterVolume}
-job.CreateGlusterVolume=Creating Gluster Volume on Cluster ${VdsGroups}
+job.CreateGlusterVolume=Creating Gluster Volume ${GlusterVolume} on Cluster 
${VdsGroups}
 job.SetGlusterVolumeOption= Setting Option on Gluster Volume ${GlusterVolume}
 job.StartGlusterVolume=Starting Gluster Volume ${GlusterVolume}
 job.StopGlusterVolume=Stopping Gluster Volume ${GlusterVolume}
@@ -103,6 +103,8 @@
 step.TAKING_VM_FROM_POOL=Taking VM ${VM} from VM pool in order to run it
 step.CLONE_IMAGE_STRUCTURE=Cloning image's structure
 step.SYNC_IMAGE_DATA=Synchronizing image data
+# Gluster step types
+step.SETTING_GLUSTER_OPTION=Setting option ${Key}=${Value} on volume 
${GlusterVolume} of cluster ${Cluster}
 
 # Non-monitored job:
 job.AddVmInterface=Adding Network Interface ${InterfaceName} to VM ${VM}


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

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

Reply via email to