Skip to content

Commit fd3945b

Browse files
author
GabrielBrascher
committed
Address reviewers from abandoned PR #1597.
1 parent 4809fe7 commit fd3945b

File tree

3 files changed

+74
-59
lines changed

3 files changed

+74
-59
lines changed

server/src/main/java/com/cloud/deploy/FirstFitPlanner.java

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ public class FirstFitPlanner extends AdapterBase implements DeploymentClusterPla
122122
protected String globalDeploymentPlanner = "FirstFitPlanner";
123123
protected String[] implicitHostTags;
124124

125+
private final static String DEPLOY_VM = "deployvm";
126+
125127
@Override
126128
public List<Long> orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
127129
VirtualMachine vm = vmProfile.getVirtualMachine();
@@ -197,25 +199,24 @@ public List<Long> orderClusters(VirtualMachineProfile vmProfile, DeploymentPlan
197199
return clusterList;
198200
}
199201

200-
private void reorderClustersBasedOnImplicitTags(List<Long> clusterList, int requiredCpu, long requiredRam) {
201-
final HashMap<Long, Long> UniqueTagsInClusterMap = new HashMap<Long, Long>();
202-
Long uniqueTags;
203-
for (Long clusterId : clusterList) {
204-
uniqueTags = (long) 0;
202+
public void reorderClustersBasedOnImplicitTags(List<Long> clusterList, int requiredCpu, long requiredRam) {
203+
Map<Long, Long> UniqueTagsInClusterMap = new HashMap<>();
204+
for (Long clusterId : clusterList) {
205+
long uniqueTags = 0l;
205206
List<Long> hostList = capacityDao.listHostsWithEnoughCapacity(requiredCpu, requiredRam, clusterId, Host.Type.Routing.toString());
206207
if (!hostList.isEmpty() && implicitHostTags.length > 0) {
207-
uniqueTags = new Long(hostTagsDao.getDistinctImplicitHostTags(hostList, implicitHostTags).size());
208-
}
209-
UniqueTagsInClusterMap.put(clusterId, uniqueTags);
208+
uniqueTags = hostTagsDao.getDistinctImplicitHostTags(hostList, implicitHostTags).size();
210209
}
211-
Collections.sort(clusterList, new Comparator<Long>() {
212-
@Override
213-
public int compare(Long o1, Long o2) {
214-
Long t1 = UniqueTagsInClusterMap.get(o1);
215-
Long t2 = UniqueTagsInClusterMap.get(o2);
216-
return t1.compareTo(t2);
217-
}
218-
});
210+
UniqueTagsInClusterMap.put(clusterId, uniqueTags);
211+
}
212+
Collections.sort(clusterList, new Comparator<Long>() {
213+
@Override
214+
public int compare(Long o1, Long o2) {
215+
Long t1 = UniqueTagsInClusterMap.get(o1);
216+
Long t2 = UniqueTagsInClusterMap.get(o2);
217+
return t1.compareTo(t2);
218+
}
219+
});
219220
}
220221

221222
private List<Long> scanPodsForDestination(VirtualMachineProfile vmProfile, DeploymentPlan plan, ExcludeList avoid) {
@@ -304,10 +305,6 @@ private List<Short> getCapacitiesForCheckingThreshold() {
304305

305306
/**
306307
* This method should remove the clusters crossing capacity threshold to avoid further vm allocation on it.
307-
* @param clusterListForVmAllocation
308-
* @param avoid
309-
* @param vmProfile
310-
* @param plan
311308
*/
312309
protected void removeClustersCrossingThreshold(List<Long> clusterListForVmAllocation, ExcludeList avoid,
313310
VirtualMachineProfile vmProfile, DeploymentPlan plan) {
@@ -318,7 +315,7 @@ protected void removeClustersCrossingThreshold(List<Long> clusterListForVmAlloca
318315
VirtualMachine vm = vmProfile.getVirtualMachine();
319316
Map<String, String> details = vmDetailsDao.listDetailsKeyPairs(vm.getId());
320317
Boolean isThresholdEnabled = ClusterThresholdEnabled.value();
321-
if (!(isThresholdEnabled || (details != null && details.containsKey("deployvm")))) {
318+
if (!isThresholdEnabled && !details.containsKey(DEPLOY_VM)) {
322319
return;
323320
}
324321

@@ -362,7 +359,6 @@ private List<Long> scanClustersForDestinationInZoneOrPod(long id, boolean isZone
362359

363360
VirtualMachine vm = vmProfile.getVirtualMachine();
364361
ServiceOffering offering = vmProfile.getServiceOffering();
365-
DataCenter dc = dcDao.findById(vm.getDataCenterId());
366362
int requiredCpu = offering.getCpu() * offering.getSpeed();
367363
long requiredRam = offering.getRamSize() * 1024L * 1024L;
368364

@@ -579,7 +575,6 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
579575

580576
@Override
581577
public DeployDestination plan(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid) throws InsufficientServerCapacityException {
582-
// TODO Auto-generated method stub
583578
return null;
584579
}
585580

@@ -597,4 +592,8 @@ public String getConfigComponentName() {
597592
public ConfigKey<?>[] getConfigKeys() {
598593
return new ConfigKey<?>[] {ClusterCPUCapacityDisableThreshold, ClusterMemoryCapacityDisableThreshold, ClusterThresholdEnabled};
599594
}
595+
596+
public void setImplicitHostTags(String[] implicitHostTags) {
597+
this.implicitHostTags = implicitHostTags;
598+
}
600599
}

server/src/test/java/com/cloud/vm/FirstFitPlannerTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,6 @@ public void checkClusterListBasedOnHostTag() throws InsufficientServerCapacityEx
210210
}
211211

212212
private List<Long> initializeForClusterListBasedOnHostTag(ServiceOffering offering) {
213-
214-
215213
when(offering.getHostTag()).thenReturn("hosttag1");
216214
initializeForClusterThresholdDisabled();
217215
List<Long> matchingClusters = new ArrayList<>();

services/console-proxy/server/src/main/java/com/cloud/consoleproxy/ConsoleProxyHttpHandlerHelper.java

Lines changed: 52 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,34 @@
2323

2424
public class ConsoleProxyHttpHandlerHelper {
2525
private static final Logger s_logger = Logger.getLogger(ConsoleProxyHttpHandlerHelper.class);
26+
private static final String AND = "&";
27+
private static final String EQUALS = "=";
28+
private static final String HOST = "host";
29+
private static final String PORT = "port";
30+
private static final String SID = "sid";
31+
private static final String TAG = "tag";
32+
private static final String CONSOLE_URL = "consoleurl";
33+
private static final String SESSION_REF = "sessionref";
34+
private static final String TICKET = "ticket";
35+
private static final String LOCALE = "locale";
36+
private static final String HYPERV_HOST = "hypervHost";
37+
private static final String USERNAME = "username";
38+
private static final String PASSWORD = "password";
39+
private static final String TOKEN = "token";
2640

2741
public static Map<String, String> getQueryMap(String query) {
28-
String[] params = query.split("&");
42+
String[] params = query.split(AND);
2943
Map<String, String> map = new HashMap<String, String>();
3044
for (String param : params) {
31-
String[] paramTokens = param.split("=");
45+
String[] paramTokens = param.split(EQUALS);
3246
if (paramTokens != null && paramTokens.length == 2) {
33-
String name = param.split("=")[0];
34-
String value = param.split("=")[1];
47+
String name = paramTokens[0];
48+
String value = paramTokens[1];
3549
map.put(name, value);
3650
} else if (paramTokens.length == 3) {
3751
// very ugly, added for Xen tunneling url
3852
String name = paramTokens[0];
39-
String value = paramTokens[1] + "=" + paramTokens[2];
53+
String value = paramTokens[1] + EQUALS + paramTokens[2];
4054
map.put(name, value);
4155
} else {
4256
if (s_logger.isDebugEnabled())
@@ -46,53 +60,53 @@ public static Map<String, String> getQueryMap(String query) {
4660

4761
// This is a ugly solution for now. We will do encryption/decryption translation
4862
// here to make it transparent to rest of the code.
49-
if (map.get("token") != null) {
63+
if (map.get(TOKEN) != null) {
5064
ConsoleProxyPasswordBasedEncryptor encryptor = new ConsoleProxyPasswordBasedEncryptor(ConsoleProxy.getEncryptorPassword());
5165

52-
ConsoleProxyClientParam param = encryptor.decryptObject(ConsoleProxyClientParam.class, map.get("token"));
66+
ConsoleProxyClientParam param = encryptor.decryptObject(ConsoleProxyClientParam.class, map.get(TOKEN));
5367

5468
// make sure we get information from token only
5569
guardUserInput(map);
5670
if (param != null) {
5771
if (param.getClientHostAddress() != null) {
5872
s_logger.debug("decode token. host: " + param.getClientHostAddress());
59-
map.put("host", param.getClientHostAddress());
73+
map.put(HOST, param.getClientHostAddress());
6074
} else {
61-
s_logger.error("decode token. host info is not found!");
75+
logMessageIfCannotFindClientParam(HOST);
6276
}
6377
if (param.getClientHostPort() != 0) {
6478
s_logger.debug("decode token. port: " + param.getClientHostPort());
65-
map.put("port", String.valueOf(param.getClientHostPort()));
79+
map.put(PORT, String.valueOf(param.getClientHostPort()));
6680
} else {
67-
s_logger.error("decode token. port info is not found!");
81+
logMessageIfCannotFindClientParam(PORT);
6882
}
6983
if (param.getClientTag() != null) {
7084
s_logger.debug("decode token. tag: " + param.getClientTag());
71-
map.put("tag", param.getClientTag());
85+
map.put(TAG, param.getClientTag());
7286
} else {
73-
s_logger.error("decode token. tag info is not found!");
87+
logMessageIfCannotFindClientParam(TAG);
7488
}
7589
if (param.getClientHostPassword() != null) {
76-
map.put("sid", param.getClientHostPassword());
90+
map.put(SID, param.getClientHostPassword());
7791
} else {
78-
s_logger.error("decode token. sid info is not found!");
92+
logMessageIfCannotFindClientParam(SID);
7993
}
8094
if (param.getClientTunnelUrl() != null)
81-
map.put("consoleurl", param.getClientTunnelUrl());
95+
map.put(CONSOLE_URL, param.getClientTunnelUrl());
8296
if (param.getClientTunnelSession() != null)
83-
map.put("sessionref", param.getClientTunnelSession());
97+
map.put(SESSION_REF, param.getClientTunnelSession());
8498
if (param.getTicket() != null)
85-
map.put("ticket", param.getTicket());
99+
map.put(TICKET, param.getTicket());
86100
if (param.getLocale() != null)
87-
map.put("locale", param.getLocale());
101+
map.put(LOCALE, param.getLocale());
88102
if (param.getHypervHost() != null)
89-
map.put("hypervHost", param.getHypervHost());
103+
map.put(HYPERV_HOST, param.getHypervHost());
90104
if (param.getUsername() != null)
91-
map.put("username", param.getUsername());
105+
map.put(USERNAME, param.getUsername());
92106
if (param.getPassword() != null)
93-
map.put("password", param.getPassword());
107+
map.put(PASSWORD, param.getPassword());
94108
} else {
95-
s_logger.error("Unable to decode token");
109+
s_logger.error("Unable to decode token due to null console proxy client param");
96110
}
97111
} else {
98112
// we no longer accept information from parameter other than token
@@ -102,17 +116,21 @@ public static Map<String, String> getQueryMap(String query) {
102116
return map;
103117
}
104118

119+
private static void logMessageIfCannotFindClientParam(String param) {
120+
s_logger.error("decode token. " + param + " info is not found!");
121+
}
122+
105123
private static void guardUserInput(Map<String, String> map) {
106-
map.remove("host");
107-
map.remove("port");
108-
map.remove("tag");
109-
map.remove("sid");
110-
map.remove("consoleurl");
111-
map.remove("sessionref");
112-
map.remove("ticket");
113-
map.remove("locale");
114-
map.remove("hypervHost");
115-
map.remove("username");
116-
map.remove("password");
124+
map.remove(HOST);
125+
map.remove(PORT);
126+
map.remove(TAG);
127+
map.remove(SID);
128+
map.remove(CONSOLE_URL);
129+
map.remove(SESSION_REF);
130+
map.remove(TICKET);
131+
map.remove(LOCALE);
132+
map.remove(HYPERV_HOST);
133+
map.remove(USERNAME);
134+
map.remove(PASSWORD);
117135
}
118136
}

0 commit comments

Comments
 (0)