From 082aed3d33109903208014432eebbe3e69737d4e Mon Sep 17 00:00:00 2001 From: Nitin Mehta Date: Fri, 19 Sep 2014 13:40:17 -0700 Subject: [PATCH] CLOUDSTACK-7588: [Vmware] Creating templates (with same names) from volumes get deleted from CS. Fix it by changing the unique name generation to the standard one used by registertemplate. Also cleaned up vmtemplatevo which had too many constructors. --- .../src/com/cloud/storage/VMTemplateVO.java | 38 ++----------------- .../cloud/template/TemplateManagerImpl.java | 9 ++--- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/engine/schema/src/com/cloud/storage/VMTemplateVO.java b/engine/schema/src/com/cloud/storage/VMTemplateVO.java index 9a77cbf873a..d44de221a87 100755 --- a/engine/schema/src/com/cloud/storage/VMTemplateVO.java +++ b/engine/schema/src/com/cloud/storage/VMTemplateVO.java @@ -159,10 +159,8 @@ public class VMTemplateVO implements VirtualMachineTemplate { uuid = UUID.randomUUID().toString(); } - /** - * Proper constructor for a new vm template. - */ - public VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url, + //FIXME - Remove unwanted constructors. + private VMTemplateVO(long id, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType, Map details) { this(id, @@ -250,8 +248,8 @@ public class VMTemplateVO implements VirtualMachineTemplate { state = State.Active; } - // Has an extra attribute - isExtractable - public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, + //FIXME - Remove unwanted constructors. Made them private for now + private VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, boolean bootable, HypervisorType hyperType, Map details) { this(id, @@ -278,34 +276,6 @@ public class VMTemplateVO implements VirtualMachineTemplate { state = State.Active; } - public VMTemplateVO(Long id, String uniqueName, String name, ImageFormat format, boolean isPublic, boolean featured, boolean isExtractable, TemplateType type, - String url, Date created, boolean requiresHvm, int bits, long accountId, String cksum, String displayText, boolean enablePassword, long guestOSId, - boolean bootable, HypervisorType hyperType, String templateTag, Map details) { - this(id, - uniqueName, - name, - format, - isPublic, - featured, - isExtractable, - type, - url, - created, - requiresHvm, - bits, - accountId, - cksum, - displayText, - enablePassword, - guestOSId, - bootable, - hyperType, - details); - this.templateTag = templateTag; - uuid = UUID.randomUUID().toString(); - state = State.Active; - } - @Override public boolean getEnablePassword() { return enablePassword; diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index 06ca5e0209e..247ed003711 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -22,7 +22,6 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.UUID; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -1605,7 +1604,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, throw new InvalidParameterValueException("GuestOS with ID: " + guestOSId + " does not exist."); } - String uniqueName = Long.valueOf((userId == null) ? 1 : userId).toString() + UUID.nameUUIDFromBytes(name.getBytes()).toString(); Long nextTemplateId = _tmpltDao.getNextInSequence(Long.class, "id"); String description = cmd.getDisplayText(); boolean isExtractable = false; @@ -1630,10 +1628,9 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, s_logger.debug("Adding template tag: " + templateTag); } } - privateTemplate = - new VMTemplateVO(nextTemplateId, uniqueName, name, ImageFormat.RAW, isPublic, featured, isExtractable, TemplateType.USER, null, null, requiresHvmValue, - bitsValue, templateOwner.getId(), null, description, passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails()); - privateTemplate.setDynamicallyScalable(isDynamicScalingEnabled); + privateTemplate = new VMTemplateVO(nextTemplateId, name, ImageFormat.RAW, isPublic, featured, isExtractable, + TemplateType.USER, null, requiresHvmValue, bitsValue, templateOwner.getId(), null, description, + passwordEnabledValue, guestOS.getId(), true, hyperType, templateTag, cmd.getDetails(), false, isDynamicScalingEnabled); if (sourceTemplateId != null) { if (s_logger.isDebugEnabled()) {