From 8113ebb08fad47db7886c6726682bfaeccb81ace Mon Sep 17 00:00:00 2001 From: Alex Huang Date: Mon, 26 Aug 2013 20:02:43 -0700 Subject: [PATCH] Moved the csvtotags into StringUtils. It was there to begin with. No idea who copied it to ConfigurationManager --- .../cloud/template/TemplateApiService.java | 3 -- .../api/command/user/vm/DeployVMCmd.java | 2 +- .../cloud/vm/VirtualMachineManagerImpl.java | 5 +- .../configuration/ConfigurationManager.java | 24 --------- .../ConfigurationManagerImpl.java | 50 ++----------------- .../network/as/AutoScaleManagerImpl.java | 2 +- .../com/cloud/storage/StorageManagerImpl.java | 3 +- .../cloud/template/TemplateManagerImpl.java | 14 +----- .../vpc/MockConfigurationManagerImpl.java | 27 ---------- utils/src/com/cloud/utils/StringUtils.java | 15 +++++- 10 files changed, 26 insertions(+), 119 deletions(-) diff --git a/api/src/com/cloud/template/TemplateApiService.java b/api/src/com/cloud/template/TemplateApiService.java index 26f381914c9..7387661a301 100755 --- a/api/src/com/cloud/template/TemplateApiService.java +++ b/api/src/com/cloud/template/TemplateApiService.java @@ -36,7 +36,6 @@ import com.cloud.exception.InternalErrorException; import com.cloud.exception.ResourceAllocationException; import com.cloud.exception.StorageUnavailableException; import com.cloud.user.Account; -import com.cloud.utils.Pair; import com.cloud.utils.exception.CloudRuntimeException; public interface TemplateApiService { @@ -88,8 +87,6 @@ public interface TemplateApiService { */ String extract(ExtractTemplateCmd cmd) throws InternalErrorException; - VirtualMachineTemplate getTemplate(long templateId); - List listTemplatePermissions(BaseListTemplateOrIsoPermissionsCmd cmd); boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissionsCmd cmd); diff --git a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java index 3866eba0511..c7bc587c35d 100755 --- a/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java @@ -465,7 +465,7 @@ public class DeployVMCmd extends BaseAsyncCreateCmd { throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId); } - VirtualMachineTemplate template = _templateService.getTemplate(templateId); + VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId); // Make sure a valid template ID was specified if (template == null) { throw new InvalidParameterValueException("Unable to use template " + templateId); diff --git a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java index 8e0a71cdaeb..7c37be8fcad 100755 --- a/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java +++ b/engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java @@ -160,6 +160,7 @@ import com.cloud.user.dao.AccountDao; import com.cloud.utils.Journal; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; +import com.cloud.utils.StringUtils; import com.cloud.utils.Ternary; import com.cloud.utils.component.ManagerBase; import com.cloud.utils.concurrency.NamedThreadFactory; @@ -2740,8 +2741,8 @@ public class VirtualMachineManagerImpl extends ManagerBase implements VirtualMac } // Check that the service offering being upgraded to has all the tags of the current service offering - List currentTags = _configMgr.csvTagsToList(currentServiceOffering.getTags()); - List newTags = _configMgr.csvTagsToList(newServiceOffering.getTags()); + List currentTags = StringUtils.csvTagsToList(currentServiceOffering.getTags()); + List newTags = StringUtils.csvTagsToList(newServiceOffering.getTags()); if (!newTags.containsAll(currentTags)) { throw new InvalidParameterValueException("Unable to upgrade virtual machine; the new service offering " + "does not have all the tags of the " diff --git a/server/src/com/cloud/configuration/ConfigurationManager.java b/server/src/com/cloud/configuration/ConfigurationManager.java index 792ff94db69..6e76b6ffb91 100755 --- a/server/src/com/cloud/configuration/ConfigurationManager.java +++ b/server/src/com/cloud/configuration/ConfigurationManager.java @@ -16,7 +16,6 @@ // under the License. package com.cloud.configuration; -import java.util.List; import java.util.Map; import java.util.Set; @@ -176,22 +175,6 @@ public interface ConfigurationManager { */ boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller); - /** - * Converts a comma separated list of tags to a List - * - * @param tags - * @return List of tags - */ - List csvTagsToList(String tags); - - /** - * Converts a List of tags to a comma separated list - * - * @param tags - * @return String containing a comma separated list of tags - */ - String listToCsvTags(List tags); - void checkZoneAccess(Account caller, DataCenter zone); void checkDiskOfferingAccess(Account caller, DiskOffering dof); @@ -256,11 +239,4 @@ public interface ConfigurationManager { AllocationState findPodAllocationState(HostPodVO pod); AllocationState findClusterAllocationState(ClusterVO cluster); - - /** - * @param tags - * @return - */ - String cleanupTags(String tags); - } diff --git a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java index 3f603d37a7e..120e7bb13c6 100755 --- a/server/src/com/cloud/configuration/ConfigurationManagerImpl.java +++ b/server/src/com/cloud/configuration/ConfigurationManagerImpl.java @@ -2189,7 +2189,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired, boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag, Integer networkRate, String deploymentPlanner, Map details, Long bytesReadRate, Long bytesWriteRate, Long iopsReadRate, Long iopsWriteRate) { - tags = cleanupTags(tags); + tags = StringUtils.cleanupTags(tags); ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, null, offerHA, limitResourceUse, volatileVm, displayText, localStorageRequired, false, tags, isSystem, vm_type, domainId, hostTag, deploymentPlanner); @@ -2341,7 +2341,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati maxIops = null; } - tags = cleanupTags(tags); + tags = StringUtils.cleanupTags(tags); DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize, tags, isCustomized, isCustomizedIops, minIops, maxIops); newDiskOffering.setUseLocalStorage(localStorageRequired); @@ -3428,50 +3428,6 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati } } - @Override - public List csvTagsToList(String tags) { - List tagsList = new ArrayList(); - - if (tags != null) { - String[] tokens = tags.split(","); - for (int i = 0; i < tokens.length; i++) { - tagsList.add(tokens[i].trim()); - } - } - - return tagsList; - } - - @Override - public String listToCsvTags(List tagsList) { - String tags = ""; - if (tagsList.size() > 0) { - for (int i = 0; i < tagsList.size(); i++) { - tags += tagsList.get(i); - if (i != tagsList.size() - 1) { - tags += ","; - } - } - } - - return tags; - } - - @Override - public String cleanupTags(String tags) { - if (tags != null) { - String[] tokens = tags.split(","); - StringBuilder t = new StringBuilder(); - for (int i = 0; i < tokens.length; i++) { - t.append(tokens[i].trim()).append(","); - } - t.delete(t.length() - 1, t.length()); - tags = t.toString(); - } - - return tags; - } - @DB protected boolean savePublicIPRange(String startIP, String endIP, long zoneId, long vlanDbId, long sourceNetworkid, long physicalNetworkId) { @@ -4120,7 +4076,7 @@ public class ConfigurationManagerImpl extends ManagerBase implements Configurati String multicastRateStr = _configDao.getValue("multicast.throttling.rate"); int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr)); - tags = cleanupTags(tags); + tags = StringUtils.cleanupTags(tags); // specifyVlan should always be true for Shared network offerings if (!specifyVlan && type == GuestType.Shared) { diff --git a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java index d0f4922d8db..859211bd572 100644 --- a/server/src/com/cloud/network/as/AutoScaleManagerImpl.java +++ b/server/src/com/cloud/network/as/AutoScaleManagerImpl.java @@ -266,7 +266,7 @@ public class AutoScaleManagerImpl extends ManagerBase implements AutoScale long autoscaleUserId = vmProfile.getAutoScaleUserId(); int destroyVmGraceperiod = vmProfile.getDestroyVmGraceperiod(); - VirtualMachineTemplate template = _templateMgr.getTemplate(templateId); + VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId); // Make sure a valid template ID was specified if (template == null) { throw new InvalidParameterValueException("Unable to use the given template."); diff --git a/server/src/com/cloud/storage/StorageManagerImpl.java b/server/src/com/cloud/storage/StorageManagerImpl.java index b5d6ff953ef..c13837335ac 100755 --- a/server/src/com/cloud/storage/StorageManagerImpl.java +++ b/server/src/com/cloud/storage/StorageManagerImpl.java @@ -150,6 +150,7 @@ import com.cloud.user.User; import com.cloud.user.dao.UserDao; import com.cloud.utils.NumbersUtil; import com.cloud.utils.Pair; +import com.cloud.utils.StringUtils; import com.cloud.utils.UriUtils; import com.cloud.utils.component.ComponentContext; import com.cloud.utils.component.ManagerBase; @@ -525,7 +526,7 @@ public class StorageManagerImpl extends ManagerBase implements StorageManager, C @Override public String getStoragePoolTags(long poolId) { - return _configMgr.listToCsvTags(_storagePoolDao.searchForStoragePoolDetails(poolId, "true")); + return StringUtils.listToCsvTags(_storagePoolDao.searchForStoragePoolDetails(poolId, "true")); } @Override diff --git a/server/src/com/cloud/template/TemplateManagerImpl.java b/server/src/com/cloud/template/TemplateManagerImpl.java index e3fa957d791..f6ae0cbf994 100755 --- a/server/src/com/cloud/template/TemplateManagerImpl.java +++ b/server/src/com/cloud/template/TemplateManagerImpl.java @@ -392,7 +392,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, String mode = cmd.getMode(); Long eventId = cmd.getStartEventId(); - VirtualMachineTemplate template = getTemplate(templateId); + VirtualMachineTemplate template = _tmpltDao.findById(templateId); if (template == null) { throw new InvalidParameterValueException("unable to find template with id " + templateId); } @@ -1100,16 +1100,6 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, } } - @Override - public VirtualMachineTemplate getTemplate(long templateId) { - VMTemplateVO template = _tmpltDao.findById(templateId); - if (template != null && template.getRemoved() == null) { - return template; - } - - return null; - } - @Override public List listTemplatePermissions(BaseListTemplateOrIsoPermissionsCmd cmd) { Account caller = CallContext.current().getCallingAccount(); @@ -1119,7 +1109,7 @@ public class TemplateManagerImpl extends ManagerBase implements TemplateManager, throw new PermissionDeniedException("unable to list permissions for " + cmd.getMediaType() + " with id " + id); } - VirtualMachineTemplate template = getTemplate(id); + VirtualMachineTemplate template = _tmpltDao.findById(id); if (template == null) { throw new InvalidParameterValueException("unable to find " + cmd.getMediaType() + " with id " + id); } diff --git a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java index 79fbfbbbe69..74211d4b48a 100755 --- a/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java +++ b/server/test/com/cloud/vpc/MockConfigurationManagerImpl.java @@ -448,24 +448,6 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu return false; } - /* (non-Javadoc) - * @see com.cloud.configuration.ConfigurationManager#csvTagsToList(java.lang.String) - */ - @Override - public List csvTagsToList(String tags) { - // TODO Auto-generated method stub - return null; - } - - /* (non-Javadoc) - * @see com.cloud.configuration.ConfigurationManager#listToCsvTags(java.util.List) - */ - @Override - public String listToCsvTags(List tags) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.configuration.ConfigurationManager#checkZoneAccess(com.cloud.user.Account, com.cloud.dc.DataCenter) */ @@ -559,15 +541,6 @@ public class MockConfigurationManagerImpl extends ManagerBase implements Configu return null; } - /* (non-Javadoc) - * @see com.cloud.configuration.ConfigurationManager#cleanupTags(java.lang.String) - */ - @Override - public String cleanupTags(String tags) { - // TODO Auto-generated method stub - return null; - } - /* (non-Javadoc) * @see com.cloud.configuration.ConfigurationManager#createDiskOffering(java.lang.Long, java.lang.String, java.lang.String, java.lang.Long, java.lang.String, boolean, boolean, boolean) */ diff --git a/utils/src/com/cloud/utils/StringUtils.java b/utils/src/com/cloud/utils/StringUtils.java index c02082cca42..948c0ac4c37 100644 --- a/utils/src/com/cloud/utils/StringUtils.java +++ b/utils/src/com/cloud/utils/StringUtils.java @@ -57,11 +57,24 @@ public class StringUtils { return false; } + public static String cleanupTags(String tags) { + if (tags != null) { + String[] tokens = tags.split(","); + StringBuilder t = new StringBuilder(); + for (int i = 0; i < tokens.length; i++) { + t.append(tokens[i].trim()).append(","); + } + t.delete(t.length() - 1, t.length()); + tags = t.toString(); + } + + return tags; + } + /** * @param tags * @return List of tags */ - public static List csvTagsToList(String tags) { List tagsList = new ArrayList();