Moved the csvtotags into StringUtils. It was there to begin with. No idea who copied it to ConfigurationManager

This commit is contained in:
Alex Huang 2013-08-26 20:02:43 -07:00
parent 64f9f0cee6
commit 8113ebb08f
10 changed files with 26 additions and 119 deletions

View File

@ -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<String> listTemplatePermissions(BaseListTemplateOrIsoPermissionsCmd cmd);
boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissionsCmd cmd);

View File

@ -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);

View File

@ -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<String> currentTags = _configMgr.csvTagsToList(currentServiceOffering.getTags());
List<String> newTags = _configMgr.csvTagsToList(newServiceOffering.getTags());
List<String> currentTags = StringUtils.csvTagsToList(currentServiceOffering.getTags());
List<String> 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 "

View File

@ -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<String> 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<String> 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);
}

View File

@ -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<String, String> 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<String> csvTagsToList(String tags) {
List<String> tagsList = new ArrayList<String>();
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<String> 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) {

View File

@ -266,7 +266,7 @@ public class AutoScaleManagerImpl<Type> 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.");

View File

@ -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

View File

@ -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<String> 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);
}

View File

@ -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<String> 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<String> 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)
*/

View File

@ -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<String> csvTagsToList(String tags) {
List<String> tagsList = new ArrayList<String>();