use of io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX 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.shared.NameUtils.READER_GROUP_STREAM_PREFIX in project pravega by pravega.
the class DeleteScopeTask method deleteScopeContent.
public CompletableFuture<Void> deleteScopeContent(String scopeName, OperationContext context, long requestId) {
Map<String, String> readerGroupMap = new HashMap<>();
Iterator<Stream> iterator = listStreams(scopeName, context).asIterator();
// Seal and delete streams and add entry to RGList
while (iterator.hasNext()) {
Stream stream = iterator.next();
Timer timer = new Timer();
if (stream.getStreamName().startsWith(READER_GROUP_STREAM_PREFIX)) {
readerGroupMap.put(stream.getStreamName().substring(READER_GROUP_STREAM_PREFIX.length()), stream.getStreamName());
}
log.debug("Processing seal and delete stream for Stream {}", stream);
Futures.getThrowingException(Futures.exceptionallyExpecting(streamMetadataTasks.sealStream(scopeName, stream.getStreamName(), requestId), 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;
}, Controller.UpdateStreamStatus.Status.STREAM_NOT_FOUND).thenCompose(sealed -> {
ControllerService.reportSealStreamMetrics(scopeName, stream.getStreamName(), sealed, timer.getElapsed());
return CompletableFuture.completedFuture(null);
}).thenCompose(x -> streamMetadataTasks.deleteStream(stream.getScope(), stream.getStreamName(), requestId).thenCompose(status -> {
ControllerService.reportDeleteStreamMetrics(scopeName, stream.getStreamName(), status, timer.getElapsed());
return CompletableFuture.completedFuture(null);
})));
}
// Delete ReaderGroups
for (Map.Entry<String, String> rgMapEntry : readerGroupMap.entrySet()) {
log.debug("Processing delete ReaderGroup for {}", rgMapEntry.getKey());
Timer timer = new Timer();
Futures.getThrowingException(streamMetadataTasks.getReaderGroupConfig(scopeName, rgMapEntry.getKey(), requestId).thenCompose(conf -> streamMetadataTasks.deleteReaderGroup(scopeName, rgMapEntry.getKey(), conf.getConfig().getReaderGroupId(), requestId).thenCompose(status -> {
ControllerService.reportDeleteReaderGroupMetrics(scopeName, rgMapEntry.getValue(), status, timer.getElapsed());
return CompletableFuture.completedFuture(null);
})));
}
// Delete KVTs
Iterator<KeyValueTableInfo> kvtIterator = listKVTs(scopeName, requestId, context).asIterator();
while (kvtIterator.hasNext()) {
String kvt = kvtIterator.next().getKeyValueTableName();
Timer timer = new Timer();
log.debug("Processing delete kvt for {}", kvt);
Futures.getThrowingException(kvtMetadataTasks.deleteKeyValueTable(scopeName, kvt, context.getRequestId()).thenCompose(status -> {
ControllerService.reportDeleteKVTableMetrics(scopeName, kvt, status, timer.getElapsed());
return CompletableFuture.completedFuture(null);
}));
}
return streamMetadataStore.deleteScopeRecursive(scopeName, context, executor).thenApply(status -> {
log.debug("Recursive Delete Scope returned with a status {}", status);
return null;
});
}
use of io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX in project pravega by pravega.
the class StreamMetadataResourceImpl method listReaderGroups.
@Override
public void listReaderGroups(final String scopeName, final SecurityContext securityContext, final AsyncResponse asyncResponse) {
long traceId = LoggerHelpers.traceEnter(log, "listReaderGroups");
long requestId = requestIdGenerator.nextLong();
try {
restAuthHelper.authenticateAuthorize(getAuthorizationHeader(), authorizationResource.ofReaderGroupsInScope(scopeName), READ);
} catch (AuthException e) {
log.warn(requestId, "Get reader groups for {} failed due to authentication failure.", scopeName);
asyncResponse.resume(Response.status(Status.fromStatusCode(e.getResponseCode())).build());
LoggerHelpers.traceLeave(log, "listReaderGroups", traceId);
return;
}
// Each reader group is represented by a stream within the mentioned scope.
controllerService.listStreamsInScope(scopeName, requestId).thenApply(streamsList -> {
ReaderGroupsList readerGroups = new ReaderGroupsList();
streamsList.forEach((stream, config) -> {
if (stream.startsWith(READER_GROUP_STREAM_PREFIX)) {
ReaderGroupsListReaderGroups readerGroup = new ReaderGroupsListReaderGroups();
readerGroup.setReaderGroupName(stream.substring(READER_GROUP_STREAM_PREFIX.length()));
readerGroups.addReaderGroupsItem(readerGroup);
}
});
log.info(requestId, "Successfully fetched readerGroups for scope: {}", scopeName);
return Response.status(Status.OK).entity(readerGroups).build();
}).exceptionally(exception -> {
if (exception.getCause() instanceof StoreException.DataNotFoundException || exception instanceof StoreException.DataNotFoundException) {
log.warn(requestId, "Scope name: {} not found", scopeName);
return Response.status(Status.NOT_FOUND).build();
} else {
log.warn(requestId, "listReaderGroups for {} failed with exception: ", scopeName, exception);
return Response.status(Status.INTERNAL_SERVER_ERROR).build();
}
}).thenApply(asyncResponse::resume).thenAccept(x -> LoggerHelpers.traceLeave(log, "listReaderGroups", traceId));
}
Aggregations