use of io.pravega.client.admin.KeyValueTableInfo in project pravega by pravega.
the class KeyValueTableFactoryImpl method forKeyValueTable.
@Override
public KeyValueTable forKeyValueTable(@NonNull String keyValueTableName, @NonNull KeyValueTableClientConfiguration clientConfiguration) {
val kvt = new KeyValueTableInfo(this.scope, keyValueTableName);
val provider = DelegationTokenProviderFactory.create(this.controller, kvt.getScope(), kvt.getKeyValueTableName(), AccessOperation.READ_WRITE);
val tsf = new TableSegmentFactoryImpl(this.controller, this.connectionPool, clientConfiguration, provider);
return new KeyValueTableImpl(kvt, tsf, this.controller, this.connectionPool.getInternalExecutor());
}
use of io.pravega.client.admin.KeyValueTableInfo in project pravega by pravega.
the class LocalControllerTest method testListKeyValueTable.
@Test(timeout = 10000)
public void testListKeyValueTable() throws Exception {
List<String> tablelist = new ArrayList<String>();
tablelist.add("kvtable1");
Pair<List<String>, String> listOfKVTables = new ImmutablePair<>(tablelist, "");
when(this.mockControllerService.listKeyValueTables(anyString(), anyString(), anyInt(), anyLong())).thenReturn(CompletableFuture.completedFuture(listOfKVTables));
KeyValueTableInfo info = this.testController.listKeyValueTables("scope").getNext().get();
assertEquals("kvtable1", info.getKeyValueTableName());
}
use of io.pravega.client.admin.KeyValueTableInfo 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.client.admin.KeyValueTableInfo in project pravega by pravega.
the class ControllerImpl method listKeyValueTables.
@Override
public AsyncIterator<KeyValueTableInfo> listKeyValueTables(String scopeName) {
Exceptions.checkNotClosed(closed.get(), this);
long traceId = LoggerHelpers.traceEnter(log, "listKeyValueTables", scopeName);
long requestId = requestIdGenerator.get();
try {
final Function<ContinuationToken, CompletableFuture<Map.Entry<ContinuationToken, Collection<KeyValueTableInfo>>>> function = token -> this.retryConfig.runAsync(() -> {
RPCAsyncCallback<KVTablesInScopeResponse> callback = new RPCAsyncCallback<>(requestId, "listKeyValueTables", scopeName);
ScopeInfo scopeInfo = ScopeInfo.newBuilder().setScope(scopeName).build();
new ControllerClientTagger(client, timeoutMillis).withTag(requestId, LIST_KEY_VALUE_TABLES, scopeName).listKeyValueTables(KVTablesInScopeRequest.newBuilder().setScope(scopeInfo).setContinuationToken(token).build(), callback);
return callback.getFuture().thenApplyAsync(x -> {
switch(x.getStatus()) {
case SCOPE_NOT_FOUND:
log.warn(requestId, "Scope not found: {}", scopeName);
throw new NoSuchScopeException();
case FAILURE:
log.warn(requestId, "Internal Server Error while trying to list streams in scope: {}", scopeName);
throw new RuntimeException("Failure while trying to list streams");
case SUCCESS:
// compatibility reasons
default:
List<KeyValueTableInfo> kvtList = x.getKvtablesList().stream().map(y -> new KeyValueTableInfo(y.getScope(), y.getKvtName())).collect(Collectors.toList());
return new AbstractMap.SimpleEntry<>(x.getContinuationToken(), kvtList);
}
}, this.executor);
}, this.executor);
return new ContinuationTokenAsyncIterator<>(function, ContinuationToken.newBuilder().build());
} finally {
LoggerHelpers.traceLeave(log, "listKeyValueTables", traceId);
}
}
use of io.pravega.client.admin.KeyValueTableInfo in project pravega by pravega.
the class MockStreamManager method deleteScope.
/**
* A new API is created hence this is going to be deprecated.
*
* @deprecated As of Pravega release 0.11, replaced by {@link #deleteScopeRecursive(String)}.
*/
@Override
@Deprecated
public boolean deleteScope(String scopeName, boolean forceDelete) {
if (forceDelete) {
List<String> readerGroupList = new ArrayList<>();
Iterator<Stream> iterator = controller.listStreams(scopeName).asIterator();
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()));
}
Futures.getAndHandleExceptions(controller.sealStream(scope, stream.getStreamName()), RuntimeException::new);
Futures.getAndHandleExceptions(controller.deleteStream(scope, stream.getStreamName()), RuntimeException::new);
}
Iterator<KeyValueTableInfo> kvtIterator = controller.listKeyValueTables(scopeName).asIterator();
while (iterator.hasNext()) {
KeyValueTableInfo kvt = kvtIterator.next();
Futures.getAndHandleExceptions(controller.deleteKeyValueTable(scopeName, kvt.getKeyValueTableName()), RuntimeException::new);
}
for (String rg : readerGroupList) {
ReaderGroupConfig rgc = getAndHandleExceptions(controller.getReaderGroupConfig(scopeName, rg), RuntimeException::new);
Futures.getAndHandleExceptions(controller.deleteReaderGroup(scopeName, rg, rgc.getReaderGroupId()), RuntimeException::new);
}
}
return Futures.getAndHandleExceptions(controller.deleteScope(scope), RuntimeException::new);
}
Aggregations