Arik Hadas has uploaded a new change for review. Change subject: core: patterned pool names support ......................................................................
core: patterned pool names support This patch contains the backend part of patterned pool names support. the user can specify inside a pool name a mask for the indexes that are included in the generated names of the VMs in the pool. that way, the user can determine a fixed-length to the generated VM names. The mask is a sequence of question-marks. the mask will be replaced with a zero-padded number in the length of the mask corredponding to the index of the VM in the pool, in the generate VM names. for example, for the patterned pool name 'my???pool', the generated names of the VMs will be: my01pool, my02pool, ... , my999pool (it's the user's responsibility not to set too many VMs in pool). Change-Id: I81a1ffb6324fb728b2584677dd654ac79b679cd8 Bug-Url: https://bugzilla.redhat.com/892260 Signed-off-by: Arik Hadas <aha...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java 3 files changed, 21 insertions(+), 4 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/86/11986/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java index a5345d3..4047d91 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommonVmPoolWithVmsCommand.java @@ -4,6 +4,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import org.ovirt.engine.core.bll.context.CommandContext; import org.ovirt.engine.core.bll.job.ExecutionContext; @@ -23,9 +25,9 @@ import org.ovirt.engine.core.common.businessentities.StoragePoolStatus; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.VmOsType; +import org.ovirt.engine.core.common.businessentities.VmPool; import org.ovirt.engine.core.common.businessentities.VmStatic; import org.ovirt.engine.core.common.businessentities.storage_domains; -import org.ovirt.engine.core.common.businessentities.VmPool; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.job.Step; @@ -98,7 +100,7 @@ VmTemplateHandler.lockVmTemplateInTransaction(getParameters().getVmStaticData().getVmtGuid(), getCompensationContext()); - String vmName = getParameters().getVmStaticData().getVmName(); + String poolName = getParameters().getVmStaticData().getVmName(); int subsequentFailedAttempts = 0; int vmPoolMaxSubsequentFailures = Config.<Integer> GetValue(ConfigValues.VmPoolMaxSubsequentFailures); for (int i = 1, number = 1; i <= getParameters().getVmsCount(); i++, number++) { @@ -106,7 +108,7 @@ number--; do { number++; - currentVmName = String.format("%1$s-%2$s", vmName, number); + currentVmName = createName(poolName, number); } while ((Boolean) Backend .getInstance() .runInternalQuery(VdcQueryType.IsVmWithSameNameExist, @@ -149,6 +151,19 @@ getCompensationContext().resetCompensation(); } + private static final Pattern PATTERNED_POOL_NAME_PATTERN = Pattern.compile("^.*?([" + VmPool.MASK_CHARACTER + "]+).*?$"); + + private String createName(String poolName, int number) { + Matcher matcher = PATTERNED_POOL_NAME_PATTERN.matcher(poolName); + if (matcher.find()) { + String numberPart = matcher.group(1); + return String.format(poolName.replace(numberPart, "%0" + numberPart.length() + "d"), number); + } + else { + return String.format("%1$s-%2$s", poolName, number); + } + } + private CommandContext createAddVmStepContext(String currentVmName) { CommandContext commandCtx = null; diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java index 5165e6d..f7fe4b6 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/VmPool.java @@ -21,7 +21,7 @@ @NotNull(message = "VALIDATION.VM_POOLS.NAME.NOT_NULL", groups = { CreateEntity.class, UpdateEntity.class }) @Size(min = 1, max = BusinessEntitiesDefinitions.VM_POOL_NAME_SIZE) - @Pattern(regexp = ValidationUtils.NO_SPECIAL_CHARACTERS_WITH_DOT, message = "ACTION_TYPE_FAILED_NAME_MAY_NOT_CONTAIN_SPECIAL_CHARS", groups = { CreateEntity.class, + @Pattern(regexp = ValidationUtils.POOL_NAME_PATTERN, message = "ACTION_TYPE_FAILED_NAME_MAY_NOT_CONTAIN_SPECIAL_CHARS", groups = { CreateEntity.class, UpdateEntity.class }) private String name; diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java index 3b51c3a..897b36b 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/utils/ValidationUtils.java @@ -13,6 +13,7 @@ import javax.validation.Validator; import org.ovirt.engine.core.common.action.VdcActionParametersBase; +import org.ovirt.engine.core.common.businessentities.VmPool; public class ValidationUtils { @@ -34,6 +35,7 @@ public static final String NULLABLE_MAC_ADDRESS = "^((\\d|([a-f]|[A-F])){2}:){5}(\\d|([a-f]|[A-F])){2}$|^$"; // Invalid mac address (for now just checking 00:00:00:00:00:00 public static final String INVALID_NULLABLE_MAC_ADDRESS = "^(00:){5}00$"; + public static final String POOL_NAME_PATTERN = "^[\\p{L}0-9._-]+[" + VmPool.MASK_CHARACTER + "]*[\\p{L}0-9._-]*|[\\p{L}0-9._-]*[" + VmPool.MASK_CHARACTER + "]*[\\p{L}0-9._-]+$"; private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator(); -- To view, visit http://gerrit.ovirt.org/11986 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I81a1ffb6324fb728b2584677dd654ac79b679cd8 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Arik Hadas <aha...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches