Search in sources :

Example 1 with ConfigMismatchException

use of io.pravega.client.stream.ConfigMismatchException in project pravega by pravega.

the class ReaderGroupManagerImpl method createReaderGroup.

@Override
public boolean createReaderGroup(String groupName, ReaderGroupConfig config) throws ConfigMismatchException {
    log.info("Creating reader group: {} for streams: {} with configuration: {}", groupName, Arrays.toString(config.getStartingStreamCuts().keySet().toArray()), config);
    NameUtils.validateReaderGroupName(groupName);
    if (config.getReaderGroupId() == ReaderGroupConfig.DEFAULT_UUID) {
        // make sure we never attempt to create a ReaderGroup with default ReadrGroupId which is 0-0-0
        config = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
    }
    ReaderGroupConfig controllerConfig = getThrowingException(controller.createReaderGroup(scope, groupName, config));
    if (!controllerConfig.equals(config)) {
        log.warn("ReaderGroup {} already exists with pre-existing configuration {}", groupName, controllerConfig);
        throw new ConfigMismatchException(groupName, controllerConfig);
    } else if (controllerConfig.getGeneration() > 0) {
        log.info("ReaderGroup {} already exists", groupName);
        return false;
    } else {
        @Cleanup StateSynchronizer<ReaderGroupState> synchronizer = clientFactory.createStateSynchronizer(NameUtils.getStreamForReaderGroup(groupName), new ReaderGroupStateUpdatesSerializer(), new ReaderGroupStateInitSerializer(), SynchronizerConfig.builder().build());
        Map<SegmentWithRange, Long> segments = ReaderGroupImpl.getSegmentsForStreams(controller, controllerConfig);
        synchronizer.initialize(new ReaderGroupState.ReaderGroupStateInit(controllerConfig, segments, getEndSegmentsForStreams(controllerConfig), false));
        return true;
    }
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StateSynchronizer(io.pravega.client.state.StateSynchronizer) ConfigMismatchException(io.pravega.client.stream.ConfigMismatchException) Map(java.util.Map)

Aggregations

StateSynchronizer (io.pravega.client.state.StateSynchronizer)1 ConfigMismatchException (io.pravega.client.stream.ConfigMismatchException)1 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)1 Map (java.util.Map)1