Skip to content

Commit 8113ebb

Browse files
author
Alex Huang
committed
Moved the csvtotags into StringUtils. It was there to begin with. No idea who copied it to ConfigurationManager
1 parent 64f9f0c commit 8113ebb

10 files changed

Lines changed: 26 additions & 119 deletions

File tree

api/src/com/cloud/template/TemplateApiService.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.cloud.exception.ResourceAllocationException;
3737
import com.cloud.exception.StorageUnavailableException;
3838
import com.cloud.user.Account;
39-
import com.cloud.utils.Pair;
4039
import com.cloud.utils.exception.CloudRuntimeException;
4140

4241
public interface TemplateApiService {
@@ -88,8 +87,6 @@ public interface TemplateApiService {
8887
*/
8988
String extract(ExtractTemplateCmd cmd) throws InternalErrorException;
9089

91-
VirtualMachineTemplate getTemplate(long templateId);
92-
9390
List<String> listTemplatePermissions(BaseListTemplateOrIsoPermissionsCmd cmd);
9491

9592
boolean updateTemplateOrIsoPermissions(BaseUpdateTemplateOrIsoPermissionsCmd cmd);

api/src/org/apache/cloudstack/api/command/user/vm/DeployVMCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ public void create() throws ResourceAllocationException{
465465
throw new InvalidParameterValueException("Unable to find service offering: " + serviceOfferingId);
466466
}
467467

468-
VirtualMachineTemplate template = _templateService.getTemplate(templateId);
468+
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
469469
// Make sure a valid template ID was specified
470470
if (template == null) {
471471
throw new InvalidParameterValueException("Unable to use template " + templateId);

engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@
160160
import com.cloud.utils.Journal;
161161
import com.cloud.utils.NumbersUtil;
162162
import com.cloud.utils.Pair;
163+
import com.cloud.utils.StringUtils;
163164
import com.cloud.utils.Ternary;
164165
import com.cloud.utils.component.ManagerBase;
165166
import com.cloud.utils.concurrency.NamedThreadFactory;
@@ -2740,8 +2741,8 @@ public void checkIfCanUpgrade(VirtualMachine vmInstance, long newServiceOffering
27402741
}
27412742

27422743
// Check that the service offering being upgraded to has all the tags of the current service offering
2743-
List<String> currentTags = _configMgr.csvTagsToList(currentServiceOffering.getTags());
2744-
List<String> newTags = _configMgr.csvTagsToList(newServiceOffering.getTags());
2744+
List<String> currentTags = StringUtils.csvTagsToList(currentServiceOffering.getTags());
2745+
List<String> newTags = StringUtils.csvTagsToList(newServiceOffering.getTags());
27452746
if (!newTags.containsAll(currentTags)) {
27462747
throw new InvalidParameterValueException("Unable to upgrade virtual machine; the new service offering " +
27472748
"does not have all the tags of the "

server/src/com/cloud/configuration/ConfigurationManager.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package com.cloud.configuration;
1818

19-
import java.util.List;
2019
import java.util.Map;
2120
import java.util.Set;
2221

@@ -176,22 +175,6 @@ DataCenterVO createZone(long userId, String zoneName, String dns1, String dns2,
176175
*/
177176
boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account caller);
178177

179-
/**
180-
* Converts a comma separated list of tags to a List
181-
*
182-
* @param tags
183-
* @return List of tags
184-
*/
185-
List<String> csvTagsToList(String tags);
186-
187-
/**
188-
* Converts a List of tags to a comma separated list
189-
*
190-
* @param tags
191-
* @return String containing a comma separated list of tags
192-
*/
193-
String listToCsvTags(List<String> tags);
194-
195178
void checkZoneAccess(Account caller, DataCenter zone);
196179

197180
void checkDiskOfferingAccess(Account caller, DiskOffering dof);
@@ -256,11 +239,4 @@ NetworkOfferingVO createNetworkOffering(String name, String displayText, Traffic
256239
AllocationState findPodAllocationState(HostPodVO pod);
257240

258241
AllocationState findClusterAllocationState(ClusterVO cluster);
259-
260-
/**
261-
* @param tags
262-
* @return
263-
*/
264-
String cleanupTags(String tags);
265-
266242
}

server/src/com/cloud/configuration/ConfigurationManagerImpl.java

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ public ServiceOfferingVO createServiceOffering(long userId, boolean isSystem, Vi
21892189
String name, int cpu, int ramSize, int speed, String displayText, boolean localStorageRequired,
21902190
boolean offerHA, boolean limitResourceUse, boolean volatileVm, String tags, Long domainId, String hostTag,
21912191
Integer networkRate, String deploymentPlanner, Map<String, String> details, Long bytesReadRate, Long bytesWriteRate, Long iopsReadRate, Long iopsWriteRate) {
2192-
tags = cleanupTags(tags);
2192+
tags = StringUtils.cleanupTags(tags);
21932193
ServiceOfferingVO offering = new ServiceOfferingVO(name, cpu, ramSize, speed, networkRate, null, offerHA,
21942194
limitResourceUse, volatileVm, displayText, localStorageRequired, false, tags, isSystem, vm_type,
21952195
domainId, hostTag, deploymentPlanner);
@@ -2341,7 +2341,7 @@ public DiskOfferingVO createDiskOffering(Long domainId, String name, String desc
23412341
maxIops = null;
23422342
}
23432343

2344-
tags = cleanupTags(tags);
2344+
tags = StringUtils.cleanupTags(tags);
23452345
DiskOfferingVO newDiskOffering = new DiskOfferingVO(domainId, name, description, diskSize, tags, isCustomized,
23462346
isCustomizedIops, minIops, maxIops);
23472347
newDiskOffering.setUseLocalStorage(localStorageRequired);
@@ -3428,50 +3428,6 @@ public boolean releasePublicIpRange(long vlanDbId, long userId, Account caller)
34283428
}
34293429
}
34303430

3431-
@Override
3432-
public List<String> csvTagsToList(String tags) {
3433-
List<String> tagsList = new ArrayList<String>();
3434-
3435-
if (tags != null) {
3436-
String[] tokens = tags.split(",");
3437-
for (int i = 0; i < tokens.length; i++) {
3438-
tagsList.add(tokens[i].trim());
3439-
}
3440-
}
3441-
3442-
return tagsList;
3443-
}
3444-
3445-
@Override
3446-
public String listToCsvTags(List<String> tagsList) {
3447-
String tags = "";
3448-
if (tagsList.size() > 0) {
3449-
for (int i = 0; i < tagsList.size(); i++) {
3450-
tags += tagsList.get(i);
3451-
if (i != tagsList.size() - 1) {
3452-
tags += ",";
3453-
}
3454-
}
3455-
}
3456-
3457-
return tags;
3458-
}
3459-
3460-
@Override
3461-
public String cleanupTags(String tags) {
3462-
if (tags != null) {
3463-
String[] tokens = tags.split(",");
3464-
StringBuilder t = new StringBuilder();
3465-
for (int i = 0; i < tokens.length; i++) {
3466-
t.append(tokens[i].trim()).append(",");
3467-
}
3468-
t.delete(t.length() - 1, t.length());
3469-
tags = t.toString();
3470-
}
3471-
3472-
return tags;
3473-
}
3474-
34753431
@DB
34763432
protected boolean savePublicIPRange(String startIP, String endIP, long zoneId, long vlanDbId, long sourceNetworkid,
34773433
long physicalNetworkId) {
@@ -4120,7 +4076,7 @@ public NetworkOfferingVO createNetworkOffering(String name, String displayText,
41204076

41214077
String multicastRateStr = _configDao.getValue("multicast.throttling.rate");
41224078
int multicastRate = ((multicastRateStr == null) ? 10 : Integer.parseInt(multicastRateStr));
4123-
tags = cleanupTags(tags);
4079+
tags = StringUtils.cleanupTags(tags);
41244080

41254081
// specifyVlan should always be true for Shared network offerings
41264082
if (!specifyVlan && type == GuestType.Shared) {

server/src/com/cloud/network/as/AutoScaleManagerImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ protected AutoScaleVmProfileVO checkValidityAndPersist(AutoScaleVmProfileVO vmPr
266266
long autoscaleUserId = vmProfile.getAutoScaleUserId();
267267
int destroyVmGraceperiod = vmProfile.getDestroyVmGraceperiod();
268268

269-
VirtualMachineTemplate template = _templateMgr.getTemplate(templateId);
269+
VirtualMachineTemplate template = _entityMgr.findById(VirtualMachineTemplate.class, templateId);
270270
// Make sure a valid template ID was specified
271271
if (template == null) {
272272
throw new InvalidParameterValueException("Unable to use the given template.");

server/src/com/cloud/storage/StorageManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
import com.cloud.user.dao.UserDao;
151151
import com.cloud.utils.NumbersUtil;
152152
import com.cloud.utils.Pair;
153+
import com.cloud.utils.StringUtils;
153154
import com.cloud.utils.UriUtils;
154155
import com.cloud.utils.component.ComponentContext;
155156
import com.cloud.utils.component.ManagerBase;
@@ -525,7 +526,7 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
525526

526527
@Override
527528
public String getStoragePoolTags(long poolId) {
528-
return _configMgr.listToCsvTags(_storagePoolDao.searchForStoragePoolDetails(poolId, "true"));
529+
return StringUtils.listToCsvTags(_storagePoolDao.searchForStoragePoolDetails(poolId, "true"));
529530
}
530531

531532
@Override

server/src/com/cloud/template/TemplateManagerImpl.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ public String extract(ExtractTemplateCmd cmd) {
392392
String mode = cmd.getMode();
393393
Long eventId = cmd.getStartEventId();
394394

395-
VirtualMachineTemplate template = getTemplate(templateId);
395+
VirtualMachineTemplate template = _tmpltDao.findById(templateId);
396396
if (template == null) {
397397
throw new InvalidParameterValueException("unable to find template with id " + templateId);
398398
}
@@ -1100,16 +1100,6 @@ public boolean deleteIso(DeleteIsoCmd cmd) {
11001100
}
11011101
}
11021102

1103-
@Override
1104-
public VirtualMachineTemplate getTemplate(long templateId) {
1105-
VMTemplateVO template = _tmpltDao.findById(templateId);
1106-
if (template != null && template.getRemoved() == null) {
1107-
return template;
1108-
}
1109-
1110-
return null;
1111-
}
1112-
11131103
@Override
11141104
public List<String> listTemplatePermissions(BaseListTemplateOrIsoPermissionsCmd cmd) {
11151105
Account caller = CallContext.current().getCallingAccount();
@@ -1119,7 +1109,7 @@ public List<String> listTemplatePermissions(BaseListTemplateOrIsoPermissionsCmd
11191109
throw new PermissionDeniedException("unable to list permissions for " + cmd.getMediaType() + " with id " + id);
11201110
}
11211111

1122-
VirtualMachineTemplate template = getTemplate(id);
1112+
VirtualMachineTemplate template = _tmpltDao.findById(id);
11231113
if (template == null) {
11241114
throw new InvalidParameterValueException("unable to find " + cmd.getMediaType() + " with id " + id);
11251115
}

server/test/com/cloud/vpc/MockConfigurationManagerImpl.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -448,24 +448,6 @@ public boolean deleteVlanAndPublicIpRange(long userId, long vlanDbId, Account ca
448448
return false;
449449
}
450450

451-
/* (non-Javadoc)
452-
* @see com.cloud.configuration.ConfigurationManager#csvTagsToList(java.lang.String)
453-
*/
454-
@Override
455-
public List<String> csvTagsToList(String tags) {
456-
// TODO Auto-generated method stub
457-
return null;
458-
}
459-
460-
/* (non-Javadoc)
461-
* @see com.cloud.configuration.ConfigurationManager#listToCsvTags(java.util.List)
462-
*/
463-
@Override
464-
public String listToCsvTags(List<String> tags) {
465-
// TODO Auto-generated method stub
466-
return null;
467-
}
468-
469451
/* (non-Javadoc)
470452
* @see com.cloud.configuration.ConfigurationManager#checkZoneAccess(com.cloud.user.Account, com.cloud.dc.DataCenter)
471453
*/
@@ -559,15 +541,6 @@ public AllocationState findClusterAllocationState(ClusterVO cluster) {
559541
return null;
560542
}
561543

562-
/* (non-Javadoc)
563-
* @see com.cloud.configuration.ConfigurationManager#cleanupTags(java.lang.String)
564-
*/
565-
@Override
566-
public String cleanupTags(String tags) {
567-
// TODO Auto-generated method stub
568-
return null;
569-
}
570-
571544
/* (non-Javadoc)
572545
* @see com.cloud.configuration.ConfigurationManager#createDiskOffering(java.lang.Long, java.lang.String, java.lang.String, java.lang.Long, java.lang.String, boolean, boolean, boolean)
573546
*/

utils/src/com/cloud/utils/StringUtils.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,24 @@ public static boolean isNotBlank(String str) {
5757
return false;
5858
}
5959

60+
public static String cleanupTags(String tags) {
61+
if (tags != null) {
62+
String[] tokens = tags.split(",");
63+
StringBuilder t = new StringBuilder();
64+
for (int i = 0; i < tokens.length; i++) {
65+
t.append(tokens[i].trim()).append(",");
66+
}
67+
t.delete(t.length() - 1, t.length());
68+
tags = t.toString();
69+
}
70+
71+
return tags;
72+
}
73+
6074
/**
6175
* @param tags
6276
* @return List of tags
6377
*/
64-
6578
public static List<String> csvTagsToList(String tags) {
6679
List<String> tagsList = new ArrayList<String>();
6780

0 commit comments

Comments
 (0)