use of io.pravega.client.stream.ReaderGroupNotFoundException in project pravega by pravega.
the class ControllerImpl method getReaderGroupConfig.
@Override
public CompletableFuture<ReaderGroupConfig> getReaderGroupConfig(final String scope, final String rgName) {
Exceptions.checkNotClosed(closed.get(), this);
Exceptions.checkNotNullOrEmpty(scope, "scope");
final String emptyUUID = "";
final long requestId = requestIdGenerator.get();
long traceId = LoggerHelpers.traceEnter(log, "getReaderGroupConfig", scope, rgName, requestId);
final String scopedRGName = NameUtils.getScopedReaderGroupName(scope, rgName);
final CompletableFuture<ReaderGroupConfigResponse> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<ReaderGroupConfigResponse> callback = new RPCAsyncCallback<>(requestId, "getReaderGroupConfig", scope, rgName);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, GET_READER_GROUP_CONFIG, scope, rgName).getReaderGroupConfig(ModelHelper.createReaderGroupInfo(scope, rgName, emptyUUID, 0L), callback);
return callback.getFuture();
}, this.executor);
return result.thenApplyAsync(x -> {
switch(x.getStatus()) {
case FAILURE:
log.warn(requestId, "Failed to get config for reader group: {}", scopedRGName);
throw new ControllerFailureException("Failed to get config for reader group: " + scopedRGName);
case RG_NOT_FOUND:
log.warn(requestId, "ReaderGroup not found: {}", scopedRGName);
throw new ReaderGroupNotFoundException(scopedRGName);
case SUCCESS:
log.info(requestId, "Successfully got config for Reader Group: {}", scopedRGName);
return encode(x.getConfig());
case UNRECOGNIZED:
default:
throw new ControllerFailureException("Unknown return status getting config for ReaderGroup " + scopedRGName + " " + x.getStatus());
}
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "getReaderGroupConfig failed for Reader Group: {}", scopedRGName, e);
}
LoggerHelpers.traceLeave(log, "getReaderGroupConfig", traceId, scope, rgName, requestId);
});
}
use of io.pravega.client.stream.ReaderGroupNotFoundException in project pravega by pravega.
the class StreamManagerImpl method deleteScope.
/**
* A new API is created hence this is going to be deprecated.
*
* @deprecated As of Pravega release 0.11.0, replaced by {@link #deleteScopeRecursive(String)}.
*/
@Override
@Deprecated
public boolean deleteScope(String scopeName, boolean forceDelete) throws DeleteScopeFailedException {
NameUtils.validateUserScopeName(scopeName);
if (forceDelete) {
log.info("Deleting scope recursively: {}", scopeName);
List<String> readerGroupList = new ArrayList<>();
Iterator<Stream> iterator = listStreams(scopeName);
while (iterator.hasNext()) {
Stream stream = iterator.next();
if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
readerGroupList.add(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()));
}
try {
Futures.getThrowingException(Futures.exceptionallyExpecting(controller.sealStream(stream.getScope(), stream.getStreamName()), e -> {
Throwable unwrap = Exceptions.unwrap(e);
// ignore failures if the stream doesn't exist or we are unable to seal it.
return unwrap instanceof InvalidStreamException || unwrap instanceof ControllerFailureException;
}, false).thenCompose(sealed -> controller.deleteStream(stream.getScope(), stream.getStreamName())));
} catch (Exception e) {
String message = String.format("Failed to seal and delete stream %s", stream.getStreamName());
throw new DeleteScopeFailedException(message, e);
}
}
Iterator<KeyValueTableInfo> kvtIterator = controller.listKeyValueTables(scopeName).asIterator();
while (kvtIterator.hasNext()) {
KeyValueTableInfo kvt = kvtIterator.next();
try {
Futures.getThrowingException(controller.deleteKeyValueTable(scopeName, kvt.getKeyValueTableName()));
} catch (Exception e) {
String message = String.format("Failed to delete key-value table %s", kvt.getKeyValueTableName());
throw new DeleteScopeFailedException(message, e);
}
}
for (String groupName : readerGroupList) {
try {
Futures.getThrowingException(controller.getReaderGroupConfig(scopeName, groupName).thenCompose(conf -> controller.deleteReaderGroup(scopeName, groupName, conf.getReaderGroupId())));
} catch (Exception e) {
if (Exceptions.unwrap(e) instanceof ReaderGroupNotFoundException) {
continue;
}
String message = String.format("Failed to delete reader group %s", groupName);
throw new DeleteScopeFailedException(message, e);
}
}
}
return Futures.getThrowingException(controller.deleteScope(scopeName));
}
use of io.pravega.client.stream.ReaderGroupNotFoundException in project pravega by pravega.
the class ReaderGroupManagerImplTest method testDeleteRGMigrationNoConfigOnController.
@Test
@SuppressWarnings("unchecked")
public void testDeleteRGMigrationNoConfigOnController() {
ReaderGroupConfig config = ReaderGroupConfig.builder().startFromStreamCuts(ImmutableMap.<Stream, StreamCut>builder().put(createStream("s1"), createStreamCut("s1", 2)).put(createStream("s2"), createStreamCut("s2", 3)).build()).retentionType(ReaderGroupConfig.StreamDataRetention.MANUAL_RELEASE_AT_USER_STREAMCUT).build();
when(clientFactory.createStateSynchronizer(anyString(), any(Serializer.class), any(Serializer.class), any(SynchronizerConfig.class))).thenReturn(synchronizer);
when(synchronizer.getState()).thenReturn(state);
when(state.getConfig()).thenReturn(config);
ReaderGroupConfig expectedConfig = ReaderGroupConfig.cloneConfig(config, UUID.randomUUID(), 0L);
when(controller.getReaderGroupConfig(SCOPE, GROUP_NAME)).thenThrow(new ReaderGroupNotFoundException(NameUtils.getScopedReaderGroupName(SCOPE, GROUP_NAME)));
when(controller.sealStream(SCOPE, NameUtils.getStreamForReaderGroup(GROUP_NAME))).thenReturn(CompletableFuture.completedFuture(true));
when(controller.deleteStream(SCOPE, NameUtils.getStreamForReaderGroup(GROUP_NAME))).thenReturn(CompletableFuture.completedFuture(true));
// Delete ReaderGroup
readerGroupManager.deleteReaderGroup(GROUP_NAME);
verify(controller, times(1)).getReaderGroupConfig(SCOPE, GROUP_NAME);
verify(controller, times(1)).deleteStream(SCOPE, NameUtils.getStreamForReaderGroup(GROUP_NAME));
verify(controller, times(0)).deleteReaderGroup(SCOPE, GROUP_NAME, expectedConfig.getReaderGroupId());
}
use of io.pravega.client.stream.ReaderGroupNotFoundException in project pravega by pravega.
the class ControllerImpl method deleteReaderGroup.
@Override
public CompletableFuture<Boolean> deleteReaderGroup(final String scope, final String rgName, final UUID readerGroupId) {
Exceptions.checkNotClosed(closed.get(), this);
Exceptions.checkNotNullOrEmpty(scope, "scope");
Exceptions.checkNotNullOrEmpty(rgName, "rgName");
Preconditions.checkNotNull(readerGroupId, "rgId");
final long requestId = requestIdGenerator.get();
long traceId = LoggerHelpers.traceEnter(log, "deleteReaderGroup", scope, rgName, requestId);
final String scopedRGName = NameUtils.getScopedReaderGroupName(scope, rgName);
final CompletableFuture<DeleteReaderGroupStatus> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<DeleteReaderGroupStatus> callback = new RPCAsyncCallback<>(requestId, "deleteReaderGroup", scope, rgName);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, DELETE_READER_GROUP, scope, rgName).deleteReaderGroup(ModelHelper.createReaderGroupInfo(scope, rgName, readerGroupId.toString(), 0L), callback);
return callback.getFuture();
}, this.executor);
return result.thenApplyAsync(x -> {
switch(x.getStatus()) {
case FAILURE:
log.warn(requestId, "Failed to delete reader group: {}", scopedRGName);
throw new ControllerFailureException("Failed to delete reader group: " + scopedRGName);
case RG_NOT_FOUND:
log.warn(requestId, "ReaderGroup not found: {}", scopedRGName);
throw new ReaderGroupNotFoundException(scopedRGName);
case SUCCESS:
log.info(requestId, "Successfully deleted Reader Group: {}", scopedRGName);
return true;
case UNRECOGNIZED:
default:
throw new ControllerFailureException("Unknown return status getting config for ReaderGroup " + scopedRGName + " " + x.getStatus());
}
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "deleteReaderGroup failed for Reader Group: {}", scopedRGName, e);
}
LoggerHelpers.traceLeave(log, "deleteReaderGroup", traceId, scope, rgName, requestId);
});
}
use of io.pravega.client.stream.ReaderGroupNotFoundException in project pravega by pravega.
the class ControllerImpl method updateReaderGroup.
@Override
public CompletableFuture<Long> updateReaderGroup(String scope, String rgName, final ReaderGroupConfig rgConfig) {
Exceptions.checkNotClosed(closed.get(), this);
Exceptions.checkNotNullOrEmpty(scope, "scope");
Exceptions.checkNotNullOrEmpty(rgName, "rgName");
Preconditions.checkNotNull(rgConfig, "rgConfig");
final long requestId = requestIdGenerator.get();
long traceId = LoggerHelpers.traceEnter(log, "updateReaderGroup", rgConfig, requestId);
final CompletableFuture<UpdateReaderGroupResponse> result = this.retryConfig.runAsync(() -> {
RPCAsyncCallback<UpdateReaderGroupResponse> callback = new RPCAsyncCallback<>(requestId, "updateReaderGroup", scope, rgName, rgConfig);
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, UPDATE_READER_GROUP, scope, rgName).updateReaderGroup(ModelHelper.decode(scope, rgName, rgConfig), callback);
return callback.getFuture();
}, this.executor);
return result.thenApplyAsync(x -> {
final String rgScopedName = NameUtils.getScopedReaderGroupName(scope, rgName);
switch(x.getStatus()) {
case FAILURE:
log.warn(requestId, "Failed to update Reader Group: {}", rgScopedName);
throw new ControllerFailureException("Failed to update Reader Group: " + rgScopedName);
case INVALID_CONFIG:
log.warn(requestId, "Failed to update Reader Group {} as Config was invalid: {}", rgScopedName, rgConfig);
throw new ReaderGroupConfigRejectedException("Invalid Reader Group Config: " + rgConfig.toString());
case RG_NOT_FOUND:
log.warn(requestId, "Failed to update Reader Group {} as Reader Group was not found.", rgScopedName);
throw new ReaderGroupNotFoundException(rgScopedName);
case SUCCESS:
log.info(requestId, "Reader Group updated successfully: {}", rgScopedName);
return x.getGeneration();
case UNRECOGNIZED:
default:
throw new ControllerFailureException("Unknown return status updating reader group " + rgScopedName + " " + x.getStatus());
}
}, this.executor).whenComplete((x, e) -> {
if (e != null) {
log.warn(requestId, "updateReaderGroup {}/{} failed: ", scope, rgName, e);
}
LoggerHelpers.traceLeave(log, "updateReaderGroup", traceId, rgConfig, requestId);
});
}
Aggregations