Skip to content

Commit b720675

Browse files
committed
Merge branch 'master' into api_refactoring
Getting ready for merge request for master, sync changes Conflicts: client/tomcatconf/commands.properties.in Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
2 parents 21d6cd3 + 7235ba3 commit b720675

7 files changed

Lines changed: 103 additions & 51 deletions

File tree

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public enum Config {
167167
RouterStatsInterval("Advanced", NetworkManager.class, Integer.class, "router.stats.interval", "300", "Interval (in seconds) to report router statistics.", null),
168168
ExternalNetworkStatsInterval("Advanced", NetworkManager.class, Integer.class, "external.network.stats.interval", "300", "Interval (in seconds) to report external network statistics.", null),
169169
RouterCheckInterval("Advanced", NetworkManager.class, Integer.class, "router.check.interval", "30", "Interval (in seconds) to report redundant router status.", null),
170+
RouterCheckPoolSize("Advanced", NetworkManager.class, Integer.class, "router.check.poolsize", "10", "Numbers of threads using to check redundant router status.", null),
170171
RouterTemplateId("Advanced", NetworkManager.class, Long.class, "router.template.id", "1", "Default ID for template.", null),
171172
RouterExtraPublicNics("Advanced", NetworkManager.class, Integer.class, "router.extra.public.nics", "2", "specify extra public nics used for virtual router(up to 5)", "0-5"),
172173
StartRetry("Advanced", AgentManager.class, Integer.class, "start.retry", "10", "Number of times to retry create and start commands", null),

‎server/src/com/cloud/network/dao/NetworkDao.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,5 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
110110

111111
List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, Network.GuestType type, boolean isSystem);
112112

113+
List<NetworkVO> listRedundantNetworks();
113114
}

‎server/src/com/cloud/network/dao/NetworkDaoImpl.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ protected NetworkDaoImpl() {
103103
AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ);
104104
SearchBuilder<NetworkOfferingVO> join1 = _ntwkOffDao.createSearchBuilder();
105105
join1.and("isSystem", join1.entity().isSystemOnly(), Op.EQ);
106+
join1.and("isRedundant", join1.entity().getRedundantRouter(), Op.EQ);
106107
AllFieldsSearch.join("offerings", join1, AllFieldsSearch.entity().getNetworkOfferingId(), join1.entity().getId(), JoinBuilder.JoinType.INNER);
107108
AllFieldsSearch.done();
108109

@@ -574,4 +575,12 @@ public List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, Networ
574575
List<NetworkVO> networks = search(sc, null);
575576
return networks;
576577
}
578+
579+
@Override
580+
public List<NetworkVO> listRedundantNetworks() {
581+
SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
582+
sc.setJoinParameters("offerings", "isRedundant", true);
583+
584+
return listBy(sc, null);
585+
}
577586
}

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,14 @@
2727
import java.util.Iterator;
2828
import java.util.List;
2929
import java.util.Map;
30+
import java.util.Queue;
3031
import java.util.Set;
3132
import java.util.TimeZone;
33+
import java.util.concurrent.BlockingQueue;
34+
import java.util.concurrent.ConcurrentLinkedQueue;
35+
import java.util.concurrent.ExecutorService;
3236
import java.util.concurrent.Executors;
37+
import java.util.concurrent.LinkedBlockingQueue;
3338
import java.util.concurrent.ScheduledExecutorService;
3439
import java.util.concurrent.TimeUnit;
3540

@@ -336,6 +341,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
336341

337342
int _routerStatsInterval = 300;
338343
int _routerCheckInterval = 30;
344+
int _rvrStatusUpdatePoolSize = 10;
339345
protected ServiceOfferingVO _offering;
340346
private String _dnsBasicZoneUpdates = "all";
341347
private Set<String> _guestOSNeedGatewayOnNonDefaultNetwork = new HashSet<String>();
@@ -350,8 +356,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
350356
ScheduledExecutorService _executor;
351357
ScheduledExecutorService _checkExecutor;
352358
ScheduledExecutorService _networkStatsUpdateExecutor;
359+
ExecutorService _rvrStatusUpdateExecutor;
353360

354361
Account _systemAcct;
362+
363+
BlockingQueue<Long> _vrUpdateQueue = null;
355364

356365
@Override
357366
public boolean sendSshKeysToHost(Long hostId, String pubKey, String prvKey) {
@@ -579,7 +588,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
579588
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterMonitor"));
580589
_checkExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterStatusMonitor"));
581590
_networkStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("NetworkStatsUpdater"));
582-
591+
583592
final ComponentLocator locator = ComponentLocator.getCurrentLocator();
584593

585594
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
@@ -606,7 +615,18 @@ public boolean configure(final String name, final Map<String, Object> params) th
606615

607616
value = configs.get("router.check.interval");
608617
_routerCheckInterval = NumbersUtil.parseInt(value, 30);
609-
618+
619+
value = configs.get("router.check.poolsize");
620+
_rvrStatusUpdatePoolSize = NumbersUtil.parseInt(value, 10);
621+
622+
/*
623+
* We assume that one thread can handle 20 requests in 1 minute in normal situation, so here we give the queue size up to 50 minutes.
624+
* It's mostly for buffer, since each time CheckRouterTask running, it would add all the redundant networks in the queue immediately
625+
*/
626+
_vrUpdateQueue = new LinkedBlockingQueue<Long>(_rvrStatusUpdatePoolSize * 1000);
627+
628+
_rvrStatusUpdateExecutor = Executors.newFixedThreadPool(_rvrStatusUpdatePoolSize, new NamedThreadFactory("RedundantRouterStatusMonitor"));
629+
610630
_instance = configs.get("instance.name");
611631
if (_instance == null) {
612632
_instance = "DEFAULT";
@@ -704,6 +724,9 @@ public boolean start() {
704724

705725
if (_routerCheckInterval > 0) {
706726
_checkExecutor.scheduleAtFixedRate(new CheckRouterTask(), _routerCheckInterval, _routerCheckInterval, TimeUnit.SECONDS);
727+
for (int i = 0; i < _rvrStatusUpdatePoolSize; i++) {
728+
_rvrStatusUpdateExecutor.execute(new RvRStatusUpdateTask());
729+
}
707730
} else {
708731
s_logger.debug("router.check.interval - " + _routerCheckInterval+ " so not scheduling the redundant router checking thread");
709732
}
@@ -1039,14 +1062,11 @@ protected void updateRoutersRedundantState(List<DomainRouterVO> routers) {
10391062
if (host == null || host.getStatus() != Status.Up) {
10401063
router.setRedundantState(RedundantState.UNKNOWN);
10411064
updated = true;
1042-
} else if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
1043-
/* Only cover hosts managed by this management server */
1044-
continue;
10451065
} else if (privateIP != null) {
10461066
final CheckRouterCommand command = new CheckRouterCommand();
10471067
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
10481068
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
1049-
command.setWait(60);
1069+
command.setWait(30);
10501070
final Answer origAnswer = _agentMgr.easySend(router.getHostId(), command);
10511071
CheckRouterAnswer answer = null;
10521072
if (origAnswer instanceof CheckRouterAnswer) {
@@ -1128,11 +1148,11 @@ private int getRealPriority(DomainRouterVO router) {
11281148
return priority;
11291149
}
11301150

1131-
protected class CheckRouterTask implements Runnable {
1151+
protected class RvRStatusUpdateTask implements Runnable {
11321152

1133-
public CheckRouterTask() {
1153+
public RvRStatusUpdateTask() {
11341154
}
1135-
1155+
11361156
/*
11371157
* In order to make fail-over works well at any time, we have to ensure:
11381158
* 1. Backup router's priority = Master's priority - DELTA + 1
@@ -1195,9 +1215,9 @@ private void checkDuplicateMaster(List <DomainRouterVO> routers) {
11951215
String title = "More than one redundant virtual router is in MASTER state! Router " + router.getHostName() + " and router " + dupRouter.getHostName();
11961216
String context = "Virtual router (name: " + router.getHostName() + ", id: " + router.getId() + " and router (name: "
11971217
+ dupRouter.getHostName() + ", id: " + router.getId() + ") are both in MASTER state! If the problem persist, restart both of routers. ";
1198-
11991218
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterIdToDeployIn(), router.getPodIdToDeployIn(), title, context);
12001219
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, dupRouter.getDataCenterIdToDeployIn(), dupRouter.getPodIdToDeployIn(), title, context);
1220+
s_logger.warn(context);
12011221
} else {
12021222
networkRouterMaps.put(routerGuestNtwkId, router);
12031223
}
@@ -1206,19 +1226,61 @@ private void checkDuplicateMaster(List <DomainRouterVO> routers) {
12061226
}
12071227
}
12081228

1229+
@Override
1230+
public void run() {
1231+
while (true) {
1232+
try {
1233+
Long networkId = _vrUpdateQueue.take();
1234+
List <DomainRouterVO> routers = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER);
1235+
1236+
if (routers.size() != 2) {
1237+
continue;
1238+
}
1239+
/*
1240+
* We update the router pair which the lower id router owned by this mgmt server, in order
1241+
* to prevent duplicate update of router status from cluster mgmt servers
1242+
*/
1243+
DomainRouterVO router = routers.get(0);
1244+
if (routers.get(1).getId() < router.getId()) {
1245+
router = routers.get(1);
1246+
}
1247+
HostVO host = _hostDao.findById(router.getHostId());
1248+
if (host == null || host.getManagementServerId() == null ||
1249+
host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
1250+
continue;
1251+
}
1252+
updateRoutersRedundantState(routers);
1253+
checkDuplicateMaster(routers);
1254+
checkSanity(routers);
1255+
} catch (Exception ex) {
1256+
s_logger.error("Fail to complete the RvRStatusUpdateTask! ", ex);
1257+
}
1258+
}
1259+
}
1260+
1261+
}
1262+
1263+
protected class CheckRouterTask implements Runnable {
1264+
1265+
public CheckRouterTask() {
1266+
}
1267+
12091268
@Override
12101269
public void run() {
12111270
try {
12121271
final List<DomainRouterVO> routers = _routerDao.listIsolatedByHostId(null);
1213-
s_logger.debug("Found " + routers.size() + " routers. ");
1272+
s_logger.debug("Found " + routers.size() + " routers to update status. ");
12141273

1215-
updateRoutersRedundantState(routers);
12161274
updateSite2SiteVpnConnectionState(routers);
12171275

1218-
/* FIXME assumed the a pair of redundant routers managed by same mgmt server,
1219-
* then the update above can get the latest status */
1220-
checkDuplicateMaster(routers);
1221-
checkSanity(routers);
1276+
final List<NetworkVO> networks = _networkDao.listRedundantNetworks();
1277+
s_logger.debug("Found " + networks.size() + " networks to update RvR status. ");
1278+
for (NetworkVO network : networks) {
1279+
if (!_vrUpdateQueue.offer(network.getId(), 500, TimeUnit.MILLISECONDS)) {
1280+
s_logger.warn("Cannot insert into virtual router update queue! Adjustment of router.check.interval and router.check.poolsize maybe needed.");
1281+
break;
1282+
}
1283+
}
12221284
} catch (Exception ex) {
12231285
s_logger.error("Fail to complete the CheckRouterTask! ", ex);
12241286
}

‎server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,10 @@ public List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, GuestT
351351
return null;
352352
}
353353

354+
@Override
355+
public List<NetworkVO> listRedundantNetworks() {
356+
// TODO Auto-generated method stub
357+
return null;
358+
}
359+
354360
}

‎setup/db/db/schema-40to410.sql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ CREATE TABLE `cloud`.`template_s3_ref` (
5252

5353
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 's3.enable', 'false', 'enable s3');
5454

55+
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.check.poolsize' , '10', 'Numbers of threads using to check redundant router status.');
56+
5557
ALTER TABLE `cloud`.`snapshots` ADD COLUMN `s3_id` bigint unsigned COMMENT 'S3 to which this snapshot will be stored';
5658

5759
ALTER TABLE `cloud`.`snapshots` ADD CONSTRAINT `fk_snapshots__s3_id` FOREIGN KEY `fk_snapshots__s3_id` (`s3_id`) REFERENCES `s3` (`id`);

‎tools/cli/cloudmonkey/cloudmonkey.py‎

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ def __init__(self):
8484
config = self.write_config()
8585
print "Welcome! Using `set` configure the necessary settings:"
8686
print " ".join(sorted(self.config_fields.keys()))
87+
print "Config file:", self.config_file
8788
print "For debugging, tail -f", self.log_file, "\n"
8889

8990
for key in self.config_fields.keys():
@@ -204,7 +205,7 @@ def print_result_tabular(result, result_filter=None):
204205

205206
def print_result_as_dict(result, result_filter=None):
206207
for key in sorted(result.keys(),
207-
key=lambda x: x!='id' and x!='count' and x):
208+
key=lambda x: x != 'id' and x != 'count' and x):
208209
if not (isinstance(result[key], list) or
209210
isinstance(result[key], dict)):
210211
self.print_shell("%s = %s" % (key, result[key]))
@@ -267,8 +268,8 @@ def process_json(response):
267268
requests = {'jobid': jobId}
268269
timeout = int(self.timeout)
269270
pollperiod = 3
271+
progress = 1
270272
while timeout > 0:
271-
progress = int((int(self.timeout) - timeout) / pollperiod ) + 1
272273
print '\r' + '.' * progress,
273274
sys.stdout.flush()
274275
response = process_json(conn.make_request_with_auth(command,
@@ -290,6 +291,7 @@ def process_json(response):
290291
return response
291292
time.sleep(pollperiod)
292293
timeout = timeout - pollperiod
294+
progress += 1
293295
logger.debug("job: %s to timeout in %ds" % (jobId, timeout))
294296
self.print_shell("Error:", "Async query timeout for jobid=", jobId)
295297

@@ -363,30 +365,6 @@ def default(self, args):
363365
except Exception as e:
364366
self.print_shell("🙈 Error on parsing and printing", e)
365367

366-
def cache_verb_miss(self, verb):
367-
self.print_shell("Oops: Verb %s should have been precached" % verb)
368-
completions_found = filter(lambda x: x.startswith(verb), completions)
369-
self.cache_verbs[verb] = {}
370-
for api_name in completions_found:
371-
api_cmd_str = "%sCmd" % api_name
372-
api_mod = self.get_api_module(api_name, [api_cmd_str])
373-
if api_mod is None:
374-
continue
375-
try:
376-
api_cmd = getattr(api_mod, api_cmd_str)()
377-
required = api_cmd.required
378-
doc = api_mod.__doc__
379-
except AttributeError, e:
380-
self.print_shell("Error: API attribute %s not found!" % e)
381-
params = filter(lambda x: '__' not in x and 'required' not in x,
382-
dir(api_cmd))
383-
if len(required) > 0:
384-
doc += "\nRequired args: %s" % " ".join(required)
385-
doc += "\nArgs: %s" % " ".join(params)
386-
api_name_lower = api_name.replace(verb, '').lower()
387-
self.cache_verbs[verb][api_name_lower] = [api_name, params, doc,
388-
required]
389-
390368
def completedefault(self, text, line, begidx, endidx):
391369
partitions = line.partition(" ")
392370
verb = partitions[0]
@@ -401,9 +379,6 @@ def completedefault(self, text, line, begidx, endidx):
401379
autocompletions = []
402380
search_string = ""
403381

404-
if verb not in self.cache_verbs:
405-
self.cache_verb_miss(verb)
406-
407382
if separator != " ": # Complete verb subjects
408383
autocompletions = self.cache_verbs[verb].keys()
409384
search_string = subject
@@ -445,8 +420,8 @@ def do_set(self, args):
445420
"""
446421
args = args.strip().partition(" ")
447422
key, value = (args[0], args[2])
448-
# Note: keys and class attributes should have same names
449-
setattr(self, key, value)
423+
setattr(self, key, value) # keys and attributes should have same names
424+
self.prompt += " " # prompt fix
450425
self.write_config()
451426

452427
def complete_set(self, text, line, begidx, endidx):
@@ -484,8 +459,6 @@ def do_help(self, args):
484459
else:
485460
verb = fields[0]
486461
subject = fields[2].partition(" ")[0]
487-
if verb not in self.cache_verbs:
488-
self.cache_verb_miss(verb)
489462

490463
if subject in self.cache_verbs[verb]:
491464
self.print_shell(self.cache_verbs[verb][subject][2])
@@ -537,8 +510,6 @@ def grammar_closure(self, args):
537510
prog_name = "python " + prog_name
538511
self.do_shell("%s %s %s" % (prog_name, rule, args))
539512
return
540-
if not rule in self.cache_verbs:
541-
self.cache_verb_miss(rule)
542513
try:
543514
args_partition = args.partition(" ")
544515
res = self.cache_verbs[rule][args_partition[0]]

0 commit comments

Comments
 (0)