Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @PATCH
- @Path(VX_PATH)
- @Consumes(SerenityMediaType.APPLICATION_VND_PELCO_PATCH_JSON)
- public Response modifyConfigVxStorage(@PathParam(Names.DEVICE_ID) String id, Map<String, Object> configPatch) throws DataStoreException
- {
- TransactionalDataStoreSupplier dsSupplier = Preconditions.checkIsPresent(dataStoreSupplierRef.get(), Preconditions.ServiceUnavailable);
- PatchHelper patch = new PatchHelper(configPatch);
- boolean isLocal;
- try (TransactionalDataStore dataStore = dsSupplier.getReadWrite())
- {
- RecorderDeviceInfo recorder = Preconditions.checkIsPresent(dataStore.getById(RecorderDeviceInfo.class, id), Preconditions.NotFound);
- isLocal = recorder.isLocal();
- StreamSourceEnum origStreamSource = recorder.getVideoStreamSource();
- if (patch.hasField(ConfigVxStorage.Patch.VIDEO_STREAM_SOURCE) && !recorder.isFailoverEnabled())
- {
- StreamSourceEnum videoStreamSource = patch.get(ConfigVxStorage.Patch.VIDEO_STREAM_SOURCE).or(StreamSourceEnum.PRIMARY);
- recorder.setVideoStreamSource(videoStreamSource);
- }
- if (patch.hasField(ConfigVxStorage.Patch.FAILOVER_ENABLED))
- {
- Boolean failoverEnabled = patch.get(ConfigVxStorage.Patch.FAILOVER_ENABLED).or(false);
- recorder.setFailoverEnabled(failoverEnabled);
- }
- if (patch.hasField(ConfigVxStorage.Patch.XCAST))
- {
- XCastEnum xcast = patch.get(ConfigVxStorage.Patch.XCAST).or(XCastEnum.UNICAST);
- if (xcast != recorder.getXcast())
- {
- LOG.info("Updating transport preference to {}", xcast);
- mediaDataManager.doIfPresent(m -> m.setTransportPreference(TransportPreference.fromString(xcast.toString())));
- }
- recorder.setXcast(xcast);
- }
- if (patch.hasField(ConfigVxStorage.Patch.RETENTION_LIMIT))
- {
- Integer retentionLimit = patch.get(ConfigVxStorage.Patch.RETENTION_LIMIT).or(0);
- Preconditions.checkCondition(retentionLimit >= 0,
- Preconditions.serenityErrorThrower(SerenityCode.INVALID_VALUE,
- ConfigVxStorage.Field.RETENTION_LIMIT),
- "Retention limit must not be negative");
- LOG.info("Setting retention limit to {}", retentionLimit);
- recorder.setRetentionLimit(retentionLimit);
- }
- dataStore.commit();
- if (!recorder.getVideoStreamSource().equals(origStreamSource))
- {
- LOG.info("Switching stream source to {}", recorder.getVideoStreamSource());
- failoverMonitor.doIfPresent(f -> f.invalidateAssignmentCache());
- recorderRef.doIfPresent(r -> r.changeSessionStreamSource());
- }
- failoverMonitor.doIfPresent(f -> f.refreshLocalRecorder(recorder));
- }
- if (isLocal && patch.hasField(ConfigVxStorage.Patch.FAILOVER_MONITOR))
- {
- try (TransactionalDataStore dataStore = dsSupplier.getReadWrite())
- {
- Collection<String> devicesToMonitor = patch.get(ConfigVxStorage.Patch.FAILOVER_MONITOR).or(ImmutableList::of);
- Preconditions.checkCondition(!devicesToMonitor.contains(id),
- Preconditions.serenityErrorThrower(SerenityCode.INVALID_VALUE, ConfigVxStorage.Field.FAILOVER_MONITOR),
- "Cannot monitor ourselves");
- for (RecorderDeviceInfo recorder : dataStore.readAll(RecorderDeviceInfo.class))
- {
- boolean enabled = devicesToMonitor.contains(recorder.getId());
- recorder.setFailoverEnabled(enabled);
- failoverMonitor.doIfPresent(f -> f.refresh(recorder));
- }
- dataStore.commit();
- }
- }
- reporter.doIfPresent(er -> er.report(InternalSituationTypeEnum.ADMIN_VXS_RECONFIGURED));
- return Response.noContent().build();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement