Advertisement
Guest User

Untitled

a guest
May 25th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. @PATCH
  2. @Path(VX_PATH)
  3. @Consumes(SerenityMediaType.APPLICATION_VND_PELCO_PATCH_JSON)
  4. public Response modifyConfigVxStorage(@PathParam(Names.DEVICE_ID) String id, Map<String, Object> configPatch) throws DataStoreException
  5. {
  6. TransactionalDataStoreSupplier dsSupplier = Preconditions.checkIsPresent(dataStoreSupplierRef.get(), Preconditions.ServiceUnavailable);
  7. PatchHelper patch = new PatchHelper(configPatch);
  8. boolean isLocal;
  9. try (TransactionalDataStore dataStore = dsSupplier.getReadWrite())
  10. {
  11. RecorderDeviceInfo recorder = Preconditions.checkIsPresent(dataStore.getById(RecorderDeviceInfo.class, id), Preconditions.NotFound);
  12. isLocal = recorder.isLocal();
  13. StreamSourceEnum origStreamSource = recorder.getVideoStreamSource();
  14.  
  15. if (patch.hasField(ConfigVxStorage.Patch.VIDEO_STREAM_SOURCE) && !recorder.isFailoverEnabled())
  16. {
  17. StreamSourceEnum videoStreamSource = patch.get(ConfigVxStorage.Patch.VIDEO_STREAM_SOURCE).or(StreamSourceEnum.PRIMARY);
  18. recorder.setVideoStreamSource(videoStreamSource);
  19. }
  20.  
  21. if (patch.hasField(ConfigVxStorage.Patch.FAILOVER_ENABLED))
  22. {
  23. Boolean failoverEnabled = patch.get(ConfigVxStorage.Patch.FAILOVER_ENABLED).or(false);
  24. recorder.setFailoverEnabled(failoverEnabled);
  25. }
  26.  
  27. if (patch.hasField(ConfigVxStorage.Patch.XCAST))
  28. {
  29. XCastEnum xcast = patch.get(ConfigVxStorage.Patch.XCAST).or(XCastEnum.UNICAST);
  30. if (xcast != recorder.getXcast())
  31. {
  32. LOG.info("Updating transport preference to {}", xcast);
  33. mediaDataManager.doIfPresent(m -> m.setTransportPreference(TransportPreference.fromString(xcast.toString())));
  34. }
  35. recorder.setXcast(xcast);
  36. }
  37.  
  38. if (patch.hasField(ConfigVxStorage.Patch.RETENTION_LIMIT))
  39. {
  40. Integer retentionLimit = patch.get(ConfigVxStorage.Patch.RETENTION_LIMIT).or(0);
  41. Preconditions.checkCondition(retentionLimit >= 0,
  42. Preconditions.serenityErrorThrower(SerenityCode.INVALID_VALUE,
  43. ConfigVxStorage.Field.RETENTION_LIMIT),
  44. "Retention limit must not be negative");
  45. LOG.info("Setting retention limit to {}", retentionLimit);
  46. recorder.setRetentionLimit(retentionLimit);
  47. }
  48.  
  49. dataStore.commit();
  50. if (!recorder.getVideoStreamSource().equals(origStreamSource))
  51. {
  52. LOG.info("Switching stream source to {}", recorder.getVideoStreamSource());
  53. failoverMonitor.doIfPresent(f -> f.invalidateAssignmentCache());
  54. recorderRef.doIfPresent(r -> r.changeSessionStreamSource());
  55. }
  56.  
  57. failoverMonitor.doIfPresent(f -> f.refreshLocalRecorder(recorder));
  58. }
  59. if (isLocal && patch.hasField(ConfigVxStorage.Patch.FAILOVER_MONITOR))
  60. {
  61. try (TransactionalDataStore dataStore = dsSupplier.getReadWrite())
  62. {
  63. Collection<String> devicesToMonitor = patch.get(ConfigVxStorage.Patch.FAILOVER_MONITOR).or(ImmutableList::of);
  64. Preconditions.checkCondition(!devicesToMonitor.contains(id),
  65. Preconditions.serenityErrorThrower(SerenityCode.INVALID_VALUE, ConfigVxStorage.Field.FAILOVER_MONITOR),
  66. "Cannot monitor ourselves");
  67. for (RecorderDeviceInfo recorder : dataStore.readAll(RecorderDeviceInfo.class))
  68. {
  69. boolean enabled = devicesToMonitor.contains(recorder.getId());
  70. recorder.setFailoverEnabled(enabled);
  71. failoverMonitor.doIfPresent(f -> f.refresh(recorder));
  72. }
  73. dataStore.commit();
  74. }
  75. }
  76. reporter.doIfPresent(er -> er.report(InternalSituationTypeEnum.ADMIN_VXS_RECONFIGURED));
  77. return Response.noContent().build();
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement