Ravi Nori has uploaded a new change for review. Change subject: engine : Persist CommandEntity ......................................................................
engine : Persist CommandEntity Persist command entity using CommandEntityDao if the cooridnationType is CoordinationType.BY_COMMAND_ID or 'root of flow' (need help figuring that out pls see patch Yair). No command has been changed to try this out and rebuilding on restart will be in next patch. Change-Id: I37c56116752307676d5a82d74c8253c1883d0b32 Signed-off-by: Ravi Nori <[email protected]> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.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/dao/CommandEntityDaoDbFacadeImpl.java M backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/CommandEntityDaoTest.java 4 files changed, 88 insertions(+), 2 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/60/14660/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java index 0a49721..173875c 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandBase.java @@ -53,6 +53,7 @@ import org.ovirt.engine.core.common.businessentities.BusinessEntitySnapshot; import org.ovirt.engine.core.common.businessentities.BusinessEntitySnapshot.EntityStatusSnapshot; import org.ovirt.engine.core.common.businessentities.BusinessEntitySnapshot.SnapshotType; +import org.ovirt.engine.core.common.businessentities.CommandEntity; import org.ovirt.engine.core.common.businessentities.QuotaEnforcementTypeEnum; import org.ovirt.engine.core.common.businessentities.StoragePool; import org.ovirt.engine.core.common.businessentities.tags; @@ -1367,6 +1368,10 @@ task.setEntityType(entityType); task.setAssociatedEntities(entityIds); AsyncTaskUtils.addOrUpdateTaskInDB(task); + AsyncTasks asyncTask = task.getParameters().getDbAsyncTask(); + if (shouldPersistCommandEntity(asyncTask)) { + persistCommandEntity(asyncTask); + } getAsyncTaskManager().lockAndAddTaskToManager(task); retValue = task.getVdsmTaskId(); ExecutionHandler.updateStepExternalId(taskStep, retValue, ExternalSystemType.VDSM); @@ -1379,6 +1384,34 @@ return retValue; } + private boolean shouldPersistCommandEntity(AsyncTasks task) { + return this.actionType.isEndOfCommandCoordination() || + isRootOfFlow(task); + } + + protected boolean isRootOfFlow(AsyncTasks task) { + VdcActionType commandType = task.getActionParameters().getCommandType(); + // how do I determine the 'root of flow' from commandType + return true; + } + + private void persistCommandEntity(AsyncTasks task) { + CommandEntity entity = new CommandEntity(); + entity.setCommandType(task.getActionParameters().getCommandType()); + entity.setCreatedAt(task.getStartTime()); + entity.setId(task.getCommandId()); + entity.setParentCommandId(getParentCommandId()); + DbFacade.getInstance().getCommandEntityDao().save(entity); + } + + private Guid getParentCommandId() { + Guid parentCommandId = Guid.Empty; + if (getParameters().getParentParameters() != null) { + parentCommandId = getParameters().getParentParameters().getCommandId(); + } + return parentCommandId; + } + /** * Create the {@link SPMAsyncTask} object to be run * @param asyncTaskCreationInfo Info on how to create the task 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 7fa88f5..fddc8ac 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 @@ -245,6 +245,7 @@ private boolean isActionMonitored = true; private static java.util.HashMap<Integer, VdcActionType> mappings = new HashMap<Integer, VdcActionType>(); private QuotaDependency quotaDependency; + private CoordinationType coordinationType = CoordinationType.BY_ENTITY_ID; static { for (VdcActionType action : values()) { @@ -265,13 +266,16 @@ } private VdcActionType(int value, ActionGroup actionGroupValue, boolean isActionMonitored, QuotaDependency quotaDependency) { + this(value, actionGroupValue, isActionMonitored, quotaDependency, CoordinationType.BY_ENTITY_ID); + } + + private VdcActionType(int value, ActionGroup actionGroupValue, boolean isActionMonitored, QuotaDependency quotaDependency, CoordinationType coordinationType) { this.intValue = value; this.actionGroup = actionGroupValue; this.isActionMonitored = isActionMonitored; this.quotaDependency = quotaDependency; + this.coordinationType = coordinationType; } - - public int getValue() { return intValue; @@ -283,6 +287,10 @@ public boolean isActionMonitored() { return isActionMonitored; + } + + public boolean isEndOfCommandCoordination() { + return coordinationType.equals(CoordinationType.BY_COMMAND_ID); } public static VdcActionType forValue(int value) { @@ -306,4 +314,9 @@ public enum QuotaDependency { NONE, STORAGE, VDS_GROUP, BOTH } + + public enum CoordinationType { + BY_COMMAND_ID, + BY_ENTITY_ID + } } diff --git a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDaoDbFacadeImpl.java b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDaoDbFacadeImpl.java index 1e4a2a7..e2ee2d9 100644 --- a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDaoDbFacadeImpl.java +++ b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/CommandEntityDaoDbFacadeImpl.java @@ -66,6 +66,18 @@ } @Override + public void save(CommandEntity entity) { + getCallsHandler().executeModification("InsertCommandEntity", + createFullParametersMapper(entity)); + } + + @Override + public void update(CommandEntity entity) { + getCallsHandler().executeModification("UpdateCommandEntity", + createFullParametersMapper(entity)); + } + + @Override public List<CommandEntity> getByParentId(Guid parentId) { MapSqlParameterSource parameterSource = getCustomMapSqlParameterSource().addValue("command_id", parentId); return getCallsHandler().executeReadList("GetCommandEntitiesByParentId", diff --git a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/CommandEntityDaoTest.java b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/CommandEntityDaoTest.java index b5832f2..6994652 100644 --- a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/CommandEntityDaoTest.java +++ b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/CommandEntityDaoTest.java @@ -56,6 +56,20 @@ return 3; } + /** + * Ensures that saving a user works as expected. + */ + @Test + @Override + public void testSave() { + CommandEntity entity = this.generateNewEntity(); + dao.save(entity); + + CommandEntity result = dao.get(entity.getId()); + + assertEquals(entity, result); + } + @Test public void testRemoveByParent() { List<CommandEntity> childCommands = dbFacade.getCommandEntityDao().getByParentId(getExistingEntityId()); @@ -78,4 +92,18 @@ } } + /** + * Ensures that updating a user works as expected. + */ + @Test + public void testUpdate() { + CommandEntity entity = this.generateNewEntity(); + entity.setCommandType(VdcActionType.StopVm); + + dao.update(entity); + + CommandEntity result = dao.get(entity.getId()); + + assertEquals(entity, result); + } } -- To view, visit http://gerrit.ovirt.org/14660 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I37c56116752307676d5a82d74c8253c1883d0b32 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Ravi Nori <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
