samuel

[ONOS-2383]Fixs the DeviceManager.java white-spacing/line-breaks

Change-Id: Ic2f44f5121fa5afbf64a216af301d690106efaf8
...@@ -77,6 +77,7 @@ import org.slf4j.Logger; ...@@ -77,6 +77,7 @@ import org.slf4j.Logger;
77 77
78 import com.google.common.collect.Lists; 78 import com.google.common.collect.Lists;
79 79
80 +
80 /** 81 /**
81 * Provides implementation of the device SB & NB APIs. 82 * Provides implementation of the device SB & NB APIs.
82 */ 83 */
...@@ -93,7 +94,8 @@ public class DeviceManager ...@@ -93,7 +94,8 @@ public class DeviceManager
93 94
94 private final Logger log = getLogger(getClass()); 95 private final Logger log = getLogger(getClass());
95 96
96 - protected final ListenerRegistry<DeviceEvent, DeviceListener> listenerRegistry = new ListenerRegistry<>(); 97 + protected final ListenerRegistry<DeviceEvent, DeviceListener> listenerRegistry =
98 + new ListenerRegistry<>();
97 99
98 private final DeviceStoreDelegate delegate = new InternalStoreDelegate(); 100 private final DeviceStoreDelegate delegate = new InternalStoreDelegate();
99 101
...@@ -122,8 +124,7 @@ public class DeviceManager ...@@ -122,8 +124,7 @@ public class DeviceManager
122 124
123 @Activate 125 @Activate
124 public void activate() { 126 public void activate() {
125 - backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos/device", 127 + backgroundService = newSingleThreadScheduledExecutor(groupedThreads("onos/device", "manager-background"));
126 - "manager-background"));
127 localNodeId = clusterService.getLocalNode().id(); 128 localNodeId = clusterService.getLocalNode().id();
128 129
129 store.setDelegate(delegate); 130 store.setDelegate(delegate);
...@@ -263,7 +264,8 @@ public class DeviceManager ...@@ -263,7 +264,8 @@ public class DeviceManager
263 } 264 }
264 265
265 @Override 266 @Override
266 - protected DeviceProviderService createProviderService(DeviceProvider provider) { 267 + protected DeviceProviderService createProviderService(
268 + DeviceProvider provider) {
267 return new InternalDeviceProviderService(provider); 269 return new InternalDeviceProviderService(provider);
268 } 270 }
269 271
...@@ -284,8 +286,7 @@ public class DeviceManager ...@@ -284,8 +286,7 @@ public class DeviceManager
284 continue; 286 continue;
285 } 287 }
286 288
287 - log.info("{} is reachable but did not have a valid role, reasserting", 289 + log.info("{} is reachable but did not have a valid role, reasserting", deviceId);
288 - deviceId);
289 290
290 // isReachable but was not MASTER or STANDBY, get a role and apply 291 // isReachable but was not MASTER or STANDBY, get a role and apply
291 // Note: NONE triggers request to MastershipService 292 // Note: NONE triggers request to MastershipService
...@@ -305,21 +306,20 @@ public class DeviceManager ...@@ -305,21 +306,20 @@ public class DeviceManager
305 /** 306 /**
306 * Apply role in reaction to provider event. 307 * Apply role in reaction to provider event.
307 * 308 *
308 - * @param deviceId device identifier 309 + * @param deviceId device identifier
309 - * @param newRole new role to apply to the device 310 + * @param newRole new role to apply to the device
310 * @return true if the request was sent to provider 311 * @return true if the request was sent to provider
311 */ 312 */
312 private boolean applyRole(DeviceId deviceId, MastershipRole newRole) { 313 private boolean applyRole(DeviceId deviceId, MastershipRole newRole) {
313 314
314 if (newRole.equals(MastershipRole.NONE)) { 315 if (newRole.equals(MastershipRole.NONE)) {
315 - // no-op 316 + //no-op
316 return true; 317 return true;
317 } 318 }
318 319
319 DeviceProvider provider = provider(); 320 DeviceProvider provider = provider();
320 if (provider == null) { 321 if (provider == null) {
321 - log.warn("Provider for {} was not found. Cannot apply role {}", 322 + log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
322 - deviceId, newRole);
323 return false; 323 return false;
324 } 324 }
325 provider.roleChanged(deviceId, newRole); 325 provider.roleChanged(deviceId, newRole);
...@@ -328,6 +328,7 @@ public class DeviceManager ...@@ -328,6 +328,7 @@ public class DeviceManager
328 return true; 328 return true;
329 } 329 }
330 330
331 +
331 @Override 332 @Override
332 public void deviceConnected(DeviceId deviceId, 333 public void deviceConnected(DeviceId deviceId,
333 DeviceDescription deviceDescription) { 334 DeviceDescription deviceDescription) {
...@@ -337,16 +338,14 @@ public class DeviceManager ...@@ -337,16 +338,14 @@ public class DeviceManager
337 338
338 log.info("Device {} connected", deviceId); 339 log.info("Device {} connected", deviceId);
339 // check my Role 340 // check my Role
340 - CompletableFuture<MastershipRole> role = mastershipService 341 + CompletableFuture<MastershipRole> role = mastershipService.requestRoleFor(deviceId);
341 - .requestRoleFor(deviceId);
342 try { 342 try {
343 // Device subsystem must wait for role assignment 343 // Device subsystem must wait for role assignment
344 // to avoid losing Device information. 344 // to avoid losing Device information.
345 // (This node could be the only Node connected to the Device.) 345 // (This node could be the only Node connected to the Device.)
346 role.get(); 346 role.get();
347 } catch (InterruptedException e) { 347 } catch (InterruptedException e) {
348 - log.warn("Interrupted while waiting role-assignment for {}", 348 + log.warn("Interrupted while waiting role-assignment for {}", deviceId);
349 - deviceId);
350 Thread.currentThread().interrupt(); 349 Thread.currentThread().interrupt();
351 } catch (ExecutionException e) { 350 } catch (ExecutionException e) {
352 log.error("Exception thrown while waiting role-assignment for {}", 351 log.error("Exception thrown while waiting role-assignment for {}",
...@@ -365,8 +364,7 @@ public class DeviceManager ...@@ -365,8 +364,7 @@ public class DeviceManager
365 } 364 }
366 365
367 DeviceEvent event = store.createOrUpdateDevice(provider().id(), 366 DeviceEvent event = store.createOrUpdateDevice(provider().id(),
368 - deviceId, 367 + deviceId, deviceDescription);
369 - deviceDescription);
370 368
371 if (event != null) { 369 if (event != null) {
372 log.trace("event: {} {}", event.type(), event); 370 log.trace("event: {} {}", event.type(), event);
...@@ -383,8 +381,10 @@ public class DeviceManager ...@@ -383,8 +381,10 @@ public class DeviceManager
383 381
384 List<Port> ports = store.getPorts(deviceId); 382 List<Port> ports = store.getPorts(deviceId);
385 List<PortDescription> descs = Lists.newArrayList(); 383 List<PortDescription> descs = Lists.newArrayList();
386 - ports.forEach(port -> descs.add(new DefaultPortDescription(port 384 + ports.forEach(port ->
387 - .number(), false, port.type(), port.portSpeed()))); 385 + descs.add(new DefaultPortDescription(port.number(),
386 + false, port.type(),
387 + port.portSpeed())));
388 store.updatePorts(this.provider().id(), deviceId, descs); 388 store.updatePorts(this.provider().id(), deviceId, descs);
389 try { 389 try {
390 if (mastershipService.getLocalRole(deviceId) == MASTER) { 390 if (mastershipService.getLocalRole(deviceId) == MASTER) {
...@@ -393,49 +393,37 @@ public class DeviceManager ...@@ -393,49 +393,37 @@ public class DeviceManager
393 } catch (IllegalStateException e) { 393 } catch (IllegalStateException e) {
394 log.warn("Failed to mark {} offline", deviceId); 394 log.warn("Failed to mark {} offline", deviceId);
395 // only the MASTER should be marking off-line in normal cases, 395 // only the MASTER should be marking off-line in normal cases,
396 - // but if I was the last STANDBY connection, etc. and no one 396 + // but if I was the last STANDBY connection, etc. and no one else
397 - // else 397 + // was there to mark the device offline, this instance may need to
398 - // was there to mark the device offline, this instance may need
399 - // to
400 // temporarily request for Master Role and mark offline. 398 // temporarily request for Master Role and mark offline.
401 399
402 - // there are times when this node will correctly have 400 + //there are times when this node will correctly have mastership, BUT
403 - // mastership, BUT 401 + //that isn't reflected in the ClockManager before the device disconnects.
404 - // that isn't reflected in the ClockManager before the device 402 + //we want to let go of the device anyways, so make sure this happens.
405 - // disconnects.
406 - // we want to let go of the device anyways, so make sure this
407 - // happens.
408 403
409 // FIXME: Store semantics leaking out as IllegalStateException. 404 // FIXME: Store semantics leaking out as IllegalStateException.
410 - // Consider revising store API to handle this scenario. 405 + // Consider revising store API to handle this scenario.
411 - CompletableFuture<MastershipRole> roleFuture = mastershipService 406 + CompletableFuture<MastershipRole> roleFuture = mastershipService.requestRoleFor(deviceId);
412 - .requestRoleFor(deviceId);
413 roleFuture.whenComplete((role, error) -> { 407 roleFuture.whenComplete((role, error) -> {
414 - MastershipTerm term = termService 408 + MastershipTerm term = termService.getMastershipTerm(deviceId);
415 - .getMastershipTerm(deviceId); 409 + // TODO: Move this type of check inside device clock manager, etc.
416 - // TODO: Move this type of check inside device clock 410 + if (term != null && localNodeId.equals(term.master())) {
417 - // manager, etc. 411 + log.info("Retry marking {} offline", deviceId);
418 - if (term != null && localNodeId.equals(term.master())) { 412 + deviceClockProviderService.setMastershipTerm(deviceId, term);
419 - log.info("Retry marking {} offline", deviceId); 413 + post(store.markOffline(deviceId));
420 - deviceClockProviderService 414 + } else {
421 - .setMastershipTerm(deviceId, term); 415 + log.info("Failed again marking {} offline. {}", deviceId, role);
422 - post(store.markOffline(deviceId)); 416 + }
423 - } else { 417 + });
424 - log.info("Failed again marking {} offline. {}",
425 - deviceId, role);
426 - }
427 - });
428 } finally { 418 } finally {
429 try { 419 try {
430 - // relinquish master role and ability to be backup. 420 + //relinquish master role and ability to be backup.
431 mastershipService.relinquishMastership(deviceId).get(); 421 mastershipService.relinquishMastership(deviceId).get();
432 } catch (InterruptedException e) { 422 } catch (InterruptedException e) {
433 - log.warn("Interrupted while reliquishing role for {}", 423 + log.warn("Interrupted while reliquishing role for {}", deviceId);
434 - deviceId);
435 Thread.currentThread().interrupt(); 424 Thread.currentThread().interrupt();
436 } catch (ExecutionException e) { 425 } catch (ExecutionException e) {
437 - log.error("Exception thrown while relinquishing role for {}", 426 + log.error("Exception thrown while relinquishing role for {}", deviceId, e);
438 - deviceId, e);
439 } 427 }
440 } 428 }
441 } 429 }
...@@ -450,14 +438,12 @@ public class DeviceManager ...@@ -450,14 +438,12 @@ public class DeviceManager
450 if (!deviceClockProviderService.isTimestampAvailable(deviceId)) { 438 if (!deviceClockProviderService.isTimestampAvailable(deviceId)) {
451 // Never been a master for this device 439 // Never been a master for this device
452 // any update will be ignored. 440 // any update will be ignored.
453 - log.trace("Ignoring {} port updates on standby node. {}", 441 + log.trace("Ignoring {} port updates on standby node. {}", deviceId, portDescriptions);
454 - deviceId, portDescriptions);
455 return; 442 return;
456 } 443 }
457 444
458 List<DeviceEvent> events = store.updatePorts(this.provider().id(), 445 List<DeviceEvent> events = store.updatePorts(this.provider().id(),
459 - deviceId, 446 + deviceId, portDescriptions);
460 - portDescriptions);
461 for (DeviceEvent event : events) { 447 for (DeviceEvent event : events) {
462 post(event); 448 post(event);
463 } 449 }
...@@ -473,13 +459,12 @@ public class DeviceManager ...@@ -473,13 +459,12 @@ public class DeviceManager
473 if (!deviceClockProviderService.isTimestampAvailable(deviceId)) { 459 if (!deviceClockProviderService.isTimestampAvailable(deviceId)) {
474 // Never been a master for this device 460 // Never been a master for this device
475 // any update will be ignored. 461 // any update will be ignored.
476 - log.trace("Ignoring {} port update on standby node. {}", 462 + log.trace("Ignoring {} port update on standby node. {}", deviceId, portDescription);
477 - deviceId, portDescription);
478 return; 463 return;
479 } 464 }
480 465
481 - final DeviceEvent event = store.updatePortStatus(this.provider() 466 + final DeviceEvent event = store.updatePortStatus(this.provider().id(),
482 - .id(), deviceId, portDescription); 467 + deviceId, portDescription);
483 if (event != null) { 468 if (event != null) {
484 log.info("Device {} port {} status changed", deviceId, event 469 log.info("Device {} port {} status changed", deviceId, event
485 .port().number()); 470 .port().number());
...@@ -488,8 +473,7 @@ public class DeviceManager ...@@ -488,8 +473,7 @@ public class DeviceManager
488 } 473 }
489 474
490 @Override 475 @Override
491 - public void receivedRoleReply(DeviceId deviceId, 476 + public void receivedRoleReply(DeviceId deviceId, MastershipRole requested,
492 - MastershipRole requested,
493 MastershipRole response) { 477 MastershipRole response) {
494 // Several things can happen here: 478 // Several things can happen here:
495 // 1. request and response match 479 // 1. request and response match
...@@ -502,50 +486,43 @@ public class DeviceManager ...@@ -502,50 +486,43 @@ public class DeviceManager
502 // FIXME: implement response to this notification 486 // FIXME: implement response to this notification
503 487
504 log.debug("got reply to a role request for {}: asked for {}, and got {}", 488 log.debug("got reply to a role request for {}: asked for {}, and got {}",
505 - deviceId, requested, response); 489 + deviceId, requested, response);
506 490
507 if (requested == null && response == null) { 491 if (requested == null && response == null) {
508 - // something was off with DeviceProvider, maybe check channel 492 + // something was off with DeviceProvider, maybe check channel too?
509 - // too? 493 + log.warn("Failed to assert role [{}] onto Device {}", requested, deviceId);
510 - log.warn("Failed to assert role [{}] onto Device {}",
511 - requested, deviceId);
512 mastershipService.relinquishMastership(deviceId); 494 mastershipService.relinquishMastership(deviceId);
513 return; 495 return;
514 } 496 }
515 497
516 if (Objects.equals(requested, response)) { 498 if (Objects.equals(requested, response)) {
517 - if (Objects.equals(requested, 499 + if (Objects.equals(requested, mastershipService.getLocalRole(deviceId))) {
518 - mastershipService.getLocalRole(deviceId))) {
519 return; 500 return;
520 } else { 501 } else {
521 return; 502 return;
522 - // FIXME roleManager got the device to comply, but doesn't 503 + // FIXME roleManager got the device to comply, but doesn't agree with
523 - // agree with
524 // the store; use the store's view, then try to reassert. 504 // the store; use the store's view, then try to reassert.
525 } 505 }
526 } else { 506 } else {
527 // we didn't get back what we asked for. Reelect someone else. 507 // we didn't get back what we asked for. Reelect someone else.
528 - log.warn("Failed to assert role [{}] onto Device {}", response, 508 + log.warn("Failed to assert role [{}] onto Device {}", response, deviceId);
529 - deviceId);
530 if (response == MastershipRole.MASTER) { 509 if (response == MastershipRole.MASTER) {
531 mastershipService.relinquishMastership(deviceId); 510 mastershipService.relinquishMastership(deviceId);
532 // TODO: Shouldn't we be triggering event? 511 // TODO: Shouldn't we be triggering event?
533 - // final Device device = getDevice(deviceId); 512 + //final Device device = getDevice(deviceId);
534 - // post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device)); 513 + //post(new DeviceEvent(DEVICE_MASTERSHIP_CHANGED, device));
535 } 514 }
536 } 515 }
537 } 516 }
538 517
539 @Override 518 @Override
540 - public void updatePortStatistics(DeviceId deviceId, 519 + public void updatePortStatistics(DeviceId deviceId, Collection<PortStatistics> portStatistics) {
541 - Collection<PortStatistics> portStatistics) {
542 checkNotNull(deviceId, DEVICE_ID_NULL); 520 checkNotNull(deviceId, DEVICE_ID_NULL);
543 checkNotNull(portStatistics, "Port statistics list cannot be null"); 521 checkNotNull(portStatistics, "Port statistics list cannot be null");
544 checkValidity(); 522 checkValidity();
545 523
546 - DeviceEvent event = store 524 + DeviceEvent event = store.updatePortStatistics(this.provider().id(),
547 - .updatePortStatistics(this.provider().id(), deviceId, 525 + deviceId, portStatistics);
548 - portStatistics);
549 post(event); 526 post(event);
550 } 527 }
551 } 528 }
...@@ -561,20 +538,19 @@ public class DeviceManager ...@@ -561,20 +538,19 @@ public class DeviceManager
561 /** 538 /**
562 * Apply role to device and send probe if MASTER. 539 * Apply role to device and send probe if MASTER.
563 * 540 *
564 - * @param deviceId device identifier 541 + * @param deviceId device identifier
565 - * @param newRole new role to apply to the device 542 + * @param newRole new role to apply to the device
566 * @return true if the request was sent to provider 543 * @return true if the request was sent to provider
567 */ 544 */
568 private boolean applyRoleAndProbe(DeviceId deviceId, MastershipRole newRole) { 545 private boolean applyRoleAndProbe(DeviceId deviceId, MastershipRole newRole) {
569 if (newRole.equals(MastershipRole.NONE)) { 546 if (newRole.equals(MastershipRole.NONE)) {
570 - // no-op 547 + //no-op
571 return true; 548 return true;
572 } 549 }
573 550
574 DeviceProvider provider = getProvider(deviceId); 551 DeviceProvider provider = getProvider(deviceId);
575 if (provider == null) { 552 if (provider == null) {
576 - log.warn("Provider for {} was not found. Cannot apply role {}", 553 + log.warn("Provider for {} was not found. Cannot apply role {}", deviceId, newRole);
577 - deviceId, newRole);
578 return false; 554 return false;
579 } 555 }
580 provider.roleChanged(deviceId, newRole); 556 provider.roleChanged(deviceId, newRole);
...@@ -589,11 +565,12 @@ public class DeviceManager ...@@ -589,11 +565,12 @@ public class DeviceManager
589 /** 565 /**
590 * Reaasert role for specified device connected to this node. 566 * Reaasert role for specified device connected to this node.
591 * 567 *
592 - * @param did device identifier 568 + * @param did device identifier
593 - * @param nextRole role to apply. If NONE is specified, it will ask 569 + * @param nextRole role to apply. If NONE is specified,
594 - * mastership service for a role and apply it. 570 + * it will ask mastership service for a role and apply it.
595 */ 571 */
596 - private void reassertRole(final DeviceId did, final MastershipRole nextRole) { 572 + private void reassertRole(final DeviceId did,
573 + final MastershipRole nextRole) {
597 574
598 MastershipRole myNextRole = nextRole; 575 MastershipRole myNextRole = nextRole;
599 if (myNextRole == NONE) { 576 if (myNextRole == NONE) {
...@@ -610,17 +587,18 @@ public class DeviceManager ...@@ -610,17 +587,18 @@ public class DeviceManager
610 case MASTER: 587 case MASTER:
611 final Device device = getDevice(did); 588 final Device device = getDevice(did);
612 if ((device != null) && !isAvailable(did)) { 589 if ((device != null) && !isAvailable(did)) {
613 - // flag the device as online. Is there a better way to do this? 590 + //flag the device as online. Is there a better way to do this?
614 - DefaultDeviceDescription deviceDescription = new DefaultDeviceDescription( 591 + DefaultDeviceDescription deviceDescription
615 - did.uri(), 592 + = new DefaultDeviceDescription(did.uri(),
616 - device.type(), 593 + device.type(),
617 - device.manufacturer(), 594 + device.manufacturer(),
618 - device.hwVersion(), 595 + device.hwVersion(),
619 - device.swVersion(), 596 + device.swVersion(),
620 - device.serialNumber(), 597 + device.serialNumber(),
621 - device.chassisId()); 598 + device.chassisId());
622 - DeviceEvent devEvent = store.createOrUpdateDevice(device 599 + DeviceEvent devEvent =
623 - .providerId(), did, deviceDescription); 600 + store.createOrUpdateDevice(device.providerId(), did,
601 + deviceDescription);
624 post(devEvent); 602 post(devEvent);
625 } 603 }
626 // TODO: should apply role only if there is mismatch 604 // TODO: should apply role only if there is mismatch
...@@ -662,8 +640,7 @@ public class DeviceManager ...@@ -662,8 +640,7 @@ public class DeviceManager
662 if (localNodeId.equals(event.roleInfo().master())) { 640 if (localNodeId.equals(event.roleInfo().master())) {
663 // confirm latest info 641 // confirm latest info
664 MastershipTerm term = termService.getMastershipTerm(did); 642 MastershipTerm term = termService.getMastershipTerm(did);
665 - final boolean iHaveControl = term != null 643 + final boolean iHaveControl = term != null && localNodeId.equals(term.master());
666 - && localNodeId.equals(term.master());
667 if (iHaveControl) { 644 if (iHaveControl) {
668 deviceClockProviderService.setMastershipTerm(did, term); 645 deviceClockProviderService.setMastershipTerm(did, term);
669 myNextRole = MASTER; 646 myNextRole = MASTER;
...@@ -676,13 +653,15 @@ public class DeviceManager ...@@ -676,13 +653,15 @@ public class DeviceManager
676 myNextRole = NONE; 653 myNextRole = NONE;
677 } 654 }
678 655
656 +
679 final boolean isReachable = isReachable(did); 657 final boolean isReachable = isReachable(did);
680 if (!isReachable) { 658 if (!isReachable) {
681 // device is not connected to this node 659 // device is not connected to this node
682 if (myNextRole != NONE) { 660 if (myNextRole != NONE) {
683 log.warn("Node was instructed to be {} role for {}, " 661 log.warn("Node was instructed to be {} role for {}, "
684 + "but this node cannot reach the device. " 662 + "but this node cannot reach the device. "
685 - + "Relinquishing role. ", myNextRole, did); 663 + + "Relinquishing role. ",
664 + myNextRole, did);
686 mastershipService.relinquishMastership(did); 665 mastershipService.relinquishMastership(did);
687 } 666 }
688 return; 667 return;
......