Michael Kublin has uploaded a new change for review. Change subject: core: Clean up of AddVdsCommand and UpdateVdsCommand ......................................................................
core: Clean up of AddVdsCommand and UpdateVdsCommand The following patch is simple clean up of two commands, it is obvious that clean up is not full. The following clean up is: 1. Removing unused CommandParametersInitializer class 2. Clean up of ArraysList 3. Some small code clean ups Change-Id: Ibf3a2c67ea5dbae8458844beaa98c175513b483c Signed-off-by: Michael Kublin <mkub...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java D backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/CommandParametersInitializer.java 3 files changed, 8 insertions(+), 88 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/23/8423/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java index 8251f2a..42fe613 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/AddVdsCommand.java @@ -45,21 +45,13 @@ import org.ovirt.engine.core.dal.VdcBllMessages; import org.ovirt.engine.core.dal.dbbroker.DbFacade; import org.ovirt.engine.core.dal.job.ExecutionMessageDirector; -import org.ovirt.engine.core.utils.CommandParametersInitializer; import org.ovirt.engine.core.utils.FileUtil; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; import org.ovirt.engine.core.utils.threadpool.ThreadPoolUtil; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; @NonTransactiveCommandAttribute(forceCompensation = true) public class AddVdsCommand<T extends AddVdsActionParameters> extends VdsCommand<T> { - - static { - CommandParametersInitializer initializer = new CommandParametersInitializer(); - initializer.AddParameter(VdsStatic.class, "mVds"); - } private VDS upServer; @@ -468,8 +460,6 @@ } return super.getValidationGroups(); } - - private static Log log = LogFactory.getLog(AddVdsCommand.class); @Override public Map<String, String> getJobMessageProperties() { diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java index b29d52c..b339119 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/UpdateVdsCommand.java @@ -1,6 +1,7 @@ package org.ovirt.engine.core.bll; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.apache.commons.lang.StringUtils; @@ -15,7 +16,6 @@ import org.ovirt.engine.core.common.businessentities.VDSStatus; import org.ovirt.engine.core.common.businessentities.VDSType; import org.ovirt.engine.core.common.businessentities.VdsSpmStatus; -import org.ovirt.engine.core.common.businessentities.VdsStatic; import org.ovirt.engine.core.common.businessentities.network_cluster; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; @@ -27,21 +27,13 @@ import org.ovirt.engine.core.compat.Guid; import org.ovirt.engine.core.dal.VdcBllMessages; import org.ovirt.engine.core.dal.dbbroker.DbFacade; -import org.ovirt.engine.core.utils.CommandParametersInitializer; -import org.ovirt.engine.core.utils.log.Log; -import org.ovirt.engine.core.utils.log.LogFactory; import org.ovirt.engine.core.utils.transaction.TransactionMethod; import org.ovirt.engine.core.utils.transaction.TransactionSupport; public class UpdateVdsCommand<T extends UpdateVdsActionParameters> extends VdsCommand<T> { - static { - CommandParametersInitializer initializer = new CommandParametersInitializer(); - initializer.AddParameter(VdsStatic.class, "mVds"); - } - - private static Log log = LogFactory.getLog(UpdateVdsCommand.class); private VDS _oldVds; + private static final List<String> UPDATE_FIELDS_VDS_BROKER = Arrays.asList("host_name", "ip", "vds_unique_id", "port", "vds_group_id"); public UpdateVdsCommand(T parameters) { super(parameters); @@ -109,8 +101,7 @@ returnValue = returnValue && IsPowerManagementLegal(getParameters().getVdsStaticData(), compatibilityVersion); } else { - getReturnValue().getCanDoActionMessages() - .add(VdcBllMessages.VDS_STATUS_NOT_VALID_FOR_UPDATE.toString()); + addCanDoActionMessage(VdcBllMessages.VDS_STATUS_NOT_VALID_FOR_UPDATE.toString()); } } else { addCanDoActionMessage(VdcBllMessages.VDS_INVALID_SERVER_ID); @@ -134,9 +125,7 @@ // if host_name changed and host is spm we need to update irsBroker cache with the new host_name if (!Guid.Empty.equals(_oldVds.getstorage_pool_id()) && _oldVds.getspm_status() != VdsSpmStatus.None && !StringUtils.equals(_oldVds.gethost_name(), getParameters().getVdsStaticData().gethost_name())) { - Backend.getInstance() - .getResourceManager() - .RunVdsCommand(VDSCommandType.UpdateSpmHostName, + runVdsCommand(VDSCommandType.UpdateSpmHostName, new UpdateSpmHostNameVDSCommandParameters(_oldVds.getstorage_pool_id(), _oldVds.gethost_name(), getParameters().getVdsStaticData().gethost_name())); @@ -149,8 +138,8 @@ tempVar.setRebootAfterInstallation(getParameters().isRebootAfterInstallation()); ArrayList<VdcReturnValueBase> resultList = Backend.getInstance().runInternalMultipleActions( VdcActionType.InstallVds, - new java.util.ArrayList<VdcActionParametersBase>(java.util.Arrays - .asList(new VdcActionParametersBase[] { tempVar }))); + new ArrayList<VdcActionParametersBase>(Arrays + .asList(tempVar))); // Since Host status is set to "Installing", failure of InstallVdsCommand will hang the Host to in that // status, therefore needed to fail the command to revert the status. @@ -209,16 +198,14 @@ }); if (getParameters().getInstallVds()) { - Backend.getInstance() - .getResourceManager() - .RunVdsCommand(VDSCommandType.SetVdsStatus, + runVdsCommand(VDSCommandType.SetVdsStatus, new SetVdsStatusVDSCommandParameters(getVdsId(), VDSStatus.Installing)); } } private boolean NeedToUpdateVdsBroker() { return VdsHandler.IsFieldsUpdated(getParameters().getVdsStaticData(), _oldVds.getStaticData(), - java.util.Arrays.asList(new String[] { "host_name", "ip", "vds_unique_id", "port", "vds_group_id" })); + UPDATE_FIELDS_VDS_BROKER); } @Override diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/CommandParametersInitializer.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/CommandParametersInitializer.java deleted file mode 100644 index 94c37a0..0000000 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/CommandParametersInitializer.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.ovirt.engine.core.utils; - -public class CommandParametersInitializer implements Cloneable { - public java.util.HashMap<java.lang.Class, java.util.LinkedList<String>> mParameters = - new java.util.HashMap<java.lang.Class, java.util.LinkedList<String>>(); - - public final void AddParameter(java.lang.Class type, String parameterName) { - java.util.LinkedList<String> values = null; - if (!((values = mParameters.get(type)) != null)) { - values = new java.util.LinkedList<String>(); - mParameters.put(type, values); - } - if (!values.contains(parameterName)) { - values.offer(parameterName); - } - } - - public final void AddParameters(java.lang.Class type, Iterable<String> parameterNames) { - java.util.LinkedList<String> values = null; - if (!((values = mParameters.get(type)) != null)) { - values = new java.util.LinkedList<String>(); - mParameters.put(type, values); - } - for (String param : parameterNames) { - values.offer(param); - } - } - - public final void InitializeParameter(Object obj, Object value) { - java.lang.Class type = obj.getClass(); - java.util.LinkedList<String> values = null; - if ((values = mParameters.get(value.getClass())) != null && values.size() != 0) { - try { - String paramName = values.poll(); - java.lang.reflect.Field field = type.getField(paramName); - if (field != null) { - try { - field.set(obj, value); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - } catch (Exception e) { - throw new VdcException(e); - } - } - } - - public final Object clone() { - CommandParametersInitializer newInstance = new CommandParametersInitializer(); - for (java.lang.Class type : mParameters.keySet()) { - java.util.LinkedList<String> values = mParameters.get(type); - newInstance.AddParameters(type, values); - } - return newInstance; - } -} -- To view, visit http://gerrit.ovirt.org/8423 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ibf3a2c67ea5dbae8458844beaa98c175513b483c Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Michael Kublin <mkub...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches