Search in sources :

Example 11 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.

the class LocalControllerTest method testCreateReaderGroup.

@Test(timeout = 10000)
public void testCreateReaderGroup() throws ExecutionException, InterruptedException {
    final Segment seg0 = new Segment("scope", "stream1", 0L);
    final Segment seg1 = new Segment("scope", "stream1", 1L);
    ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
    Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of("scope", "stream1"), new StreamCutImpl(Stream.of("scope", "stream1"), startStreamCut));
    ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
    Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of("scope", "stream1"), new StreamCutImpl(Stream.of("scope", "stream1"), endStreamCut));
    ReaderGroupConfig rgConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(30000L).groupRefreshTimeMillis(20000L).maxOutstandingCheckpointRequest(2).retentionType(ReaderGroupConfig.StreamDataRetention.AUTOMATIC_RELEASE_AT_LAST_CHECKPOINT).startingStreamCuts(startSC).endingStreamCuts(endSC).build();
    final ReaderGroupConfig config = ReaderGroupConfig.cloneConfig(rgConfig, UUID.randomUUID(), 0L);
    StreamMetadataTasks mockStreamMetaTasks = mock(StreamMetadataTasks.class);
    final String scope = "scope";
    final String rgName = "subscriber";
    when(this.mockControllerService.getStreamMetadataTasks()).thenReturn(mockStreamMetaTasks);
    Controller.ReaderGroupConfiguration expectedConfig = ModelHelper.decode(scope, rgName, config);
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setConfig(expectedConfig).setStatus(Controller.CreateReaderGroupResponse.Status.SUCCESS).build()));
    ReaderGroupConfig responseCfg = this.testController.createReaderGroup(scope, rgName, config).join();
    Assert.assertEquals(UUID.fromString(expectedConfig.getReaderGroupId()), responseCfg.getReaderGroupId());
    Assert.assertEquals(expectedConfig.getRetentionType(), responseCfg.getRetentionType().ordinal());
    Assert.assertEquals(expectedConfig.getGeneration(), responseCfg.getGeneration());
    Assert.assertEquals(expectedConfig.getGroupRefreshTimeMillis(), responseCfg.getGroupRefreshTimeMillis());
    Assert.assertEquals(expectedConfig.getAutomaticCheckpointIntervalMillis(), responseCfg.getAutomaticCheckpointIntervalMillis());
    Assert.assertEquals(expectedConfig.getMaxOutstandingCheckpointRequest(), responseCfg.getMaxOutstandingCheckpointRequest());
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setConfig(expectedConfig).setStatus(Controller.CreateReaderGroupResponse.Status.FAILURE).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.createReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof ControllerFailureException);
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setConfig(expectedConfig).setStatus(Controller.CreateReaderGroupResponse.Status.INVALID_RG_NAME).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.createReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof IllegalArgumentException);
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setConfig(expectedConfig).setStatus(Controller.CreateReaderGroupResponse.Status.SCOPE_NOT_FOUND).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.createReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof IllegalArgumentException);
    when(mockStreamMetaTasks.createReaderGroupInternal(anyString(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateReaderGroupResponse.newBuilder().setStatusValue(-1).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.createReaderGroup("scope", "subscriber", config).join(), ex -> ex instanceof ControllerFailureException);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Segment(io.pravega.client.segment.impl.Segment) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Test(org.junit.Test)

Example 12 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.

the class LocalControllerTest method testDeleteReaderGroup.

@Test(timeout = 10000)
public void testDeleteReaderGroup() throws ExecutionException, InterruptedException {
    final UUID someUUID = UUID.randomUUID();
    when(this.mockControllerService.deleteReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.DeleteReaderGroupStatus.newBuilder().setStatus(Controller.DeleteReaderGroupStatus.Status.SUCCESS).build()));
    Assert.assertTrue(this.testController.deleteReaderGroup("scope", "subscriber", someUUID).join());
    when(this.mockControllerService.deleteReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.DeleteReaderGroupStatus.newBuilder().setStatus(Controller.DeleteReaderGroupStatus.Status.FAILURE).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.deleteReaderGroup("scope", "subscriber", someUUID).join(), ex -> ex instanceof ControllerFailureException);
    when(this.mockControllerService.deleteReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.DeleteReaderGroupStatus.newBuilder().setStatus(Controller.DeleteReaderGroupStatus.Status.RG_NOT_FOUND).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.deleteReaderGroup("scope", "stream", someUUID).join(), ex -> ex instanceof IllegalArgumentException);
    when(this.mockControllerService.deleteReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.DeleteReaderGroupStatus.newBuilder().setStatus(Controller.DeleteReaderGroupStatus.Status.SUCCESS).build()));
    Assert.assertTrue(this.testController.deleteReaderGroup("scope", "subscriber", someUUID).join());
    when(this.mockControllerService.deleteReaderGroup(anyString(), anyString(), any(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.DeleteReaderGroupStatus.newBuilder().setStatusValue(-1).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.deleteReaderGroup("scope", "subscriber", someUUID).join(), ex -> ex instanceof ControllerFailureException);
}
Also used : ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) UUID(java.util.UUID) Test(org.junit.Test)

Example 13 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.

the class LocalControllerTest method testGetReaderGroupConfig.

@Test(timeout = 10000)
public void testGetReaderGroupConfig() throws ExecutionException, InterruptedException {
    final String scope = "scope";
    final String streamName = "stream1";
    final Segment seg0 = new Segment(scope, streamName, 0L);
    final Segment seg1 = new Segment(scope, streamName, 1L);
    ImmutableMap<Segment, Long> startStreamCut = ImmutableMap.of(seg0, 10L, seg1, 10L);
    Map<Stream, StreamCut> startSC = ImmutableMap.of(Stream.of(scope, streamName), new StreamCutImpl(Stream.of(scope, streamName), startStreamCut));
    ImmutableMap<Segment, Long> endStreamCut = ImmutableMap.of(seg0, 200L, seg1, 300L);
    Map<Stream, StreamCut> endSC = ImmutableMap.of(Stream.of(scope, streamName), new StreamCutImpl(Stream.of(scope, streamName), endStreamCut));
    ReaderGroupConfig rgConfig = ReaderGroupConfig.builder().automaticCheckpointIntervalMillis(30000L).groupRefreshTimeMillis(20000L).maxOutstandingCheckpointRequest(2).retentionType(ReaderGroupConfig.StreamDataRetention.AUTOMATIC_RELEASE_AT_LAST_CHECKPOINT).startingStreamCuts(startSC).endingStreamCuts(endSC).build();
    ReaderGroupConfig config = ReaderGroupConfig.cloneConfig(rgConfig, UUID.randomUUID(), 0L);
    final String rgName = "subscriber";
    Controller.ReaderGroupConfiguration expectedConfig = ModelHelper.decode(scope, rgName, config);
    when(this.mockControllerService.getReaderGroupConfig(anyString(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ReaderGroupConfigResponse.newBuilder().setStatus(Controller.ReaderGroupConfigResponse.Status.SUCCESS).setConfig(expectedConfig).build()));
    Assert.assertEquals(this.testController.getReaderGroupConfig(scope, rgName).join().getAutomaticCheckpointIntervalMillis(), config.getAutomaticCheckpointIntervalMillis());
    when(this.mockControllerService.getReaderGroupConfig(anyString(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ReaderGroupConfigResponse.newBuilder().setStatus(Controller.ReaderGroupConfigResponse.Status.FAILURE).setConfig(Controller.ReaderGroupConfiguration.getDefaultInstance()).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.getReaderGroupConfig("scope", "subscriber").join(), ex -> ex instanceof ControllerFailureException);
    when(this.mockControllerService.getReaderGroupConfig(anyString(), anyString(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ReaderGroupConfigResponse.newBuilder().setStatus(Controller.ReaderGroupConfigResponse.Status.RG_NOT_FOUND).setConfig(Controller.ReaderGroupConfiguration.getDefaultInstance()).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.getReaderGroupConfig("scope", "subscriber").join(), ex -> ex instanceof IllegalArgumentException);
    when(this.mockControllerService.getReaderGroupConfig(eq("scope"), eq("subscriber"), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.ReaderGroupConfigResponse.newBuilder().setStatusValue(-1).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.getReaderGroupConfig("scope", "subscriber").join(), ex -> ex instanceof ControllerFailureException);
}
Also used : ReaderGroupConfig(io.pravega.client.stream.ReaderGroupConfig) StreamCut(io.pravega.client.stream.StreamCut) StreamCutImpl(io.pravega.client.stream.impl.StreamCutImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Segment(io.pravega.client.segment.impl.Segment) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) Test(org.junit.Test)

Example 14 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException in project pravega by pravega.

the class LocalControllerTest method testCreateKeyValueTable.

@Test(timeout = 10000)
public void testCreateKeyValueTable() {
    val kvtConfig = KeyValueTableConfiguration.builder().partitionCount(1).primaryKeyLength(4).secondaryKeyLength(4).build();
    when(this.mockControllerService.createKeyValueTable(any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateKeyValueTableStatus.newBuilder().setStatus(Controller.CreateKeyValueTableStatus.Status.SUCCESS).build()));
    Assert.assertTrue(this.testController.createKeyValueTable("scope", "kvtable", kvtConfig).join());
    when(this.mockControllerService.createKeyValueTable(any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateKeyValueTableStatus.newBuilder().setStatus(Controller.CreateKeyValueTableStatus.Status.TABLE_EXISTS).build()));
    Assert.assertFalse(this.testController.createKeyValueTable("scope", "kvtable", kvtConfig).join());
    when(this.mockControllerService.createKeyValueTable(any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateKeyValueTableStatus.newBuilder().setStatus(Controller.CreateKeyValueTableStatus.Status.FAILURE).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.createKeyValueTable("scope", "kvtable", kvtConfig).join(), ex -> ex instanceof ControllerFailureException);
    when(this.mockControllerService.createKeyValueTable(any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateKeyValueTableStatus.newBuilder().setStatus(Controller.CreateKeyValueTableStatus.Status.INVALID_TABLE_NAME).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.createKeyValueTable("scope", "kvtable", kvtConfig).join(), ex -> ex instanceof IllegalArgumentException);
    when(this.mockControllerService.createKeyValueTable(any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateKeyValueTableStatus.newBuilder().setStatus(Controller.CreateKeyValueTableStatus.Status.SCOPE_NOT_FOUND).build()));
    assertThrows("Expected IllegalArgumentException", () -> this.testController.createKeyValueTable("scope", "kvtable", kvtConfig).join(), ex -> ex instanceof IllegalArgumentException);
    when(this.mockControllerService.createKeyValueTable(any(), any(), any(), anyLong(), anyLong())).thenReturn(CompletableFuture.completedFuture(Controller.CreateKeyValueTableStatus.newBuilder().setStatusValue(-1).build()));
    assertThrows("Expected ControllerFailureException", () -> this.testController.createKeyValueTable("scope", "kvtable1", kvtConfig).join(), ex -> ex instanceof ControllerFailureException);
}
Also used : lombok.val(lombok.val) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Test(org.junit.Test)

Example 15 with ControllerFailureException

use of io.pravega.client.control.impl.ControllerFailureException 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;
    });
}
Also used : OperationContext(io.pravega.controller.store.stream.OperationContext) StreamImpl(io.pravega.client.stream.impl.StreamImpl) Exceptions(io.pravega.common.Exceptions) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) TagLogger(io.pravega.common.tracing.TagLogger) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Stream(io.pravega.client.stream.Stream) Map(java.util.Map) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) StreamMetadataTasks(io.pravega.controller.task.Stream.StreamMetadataTasks) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) ControllerService(io.pravega.controller.server.ControllerService) Iterator(java.util.Iterator) Collection(java.util.Collection) DeleteScopeEvent(io.pravega.shared.controller.event.DeleteScopeEvent) AsyncIterator(io.pravega.common.util.AsyncIterator) UUID(java.util.UUID) Timer(io.pravega.common.Timer) TableMetadataTasks(io.pravega.controller.task.KeyValueTable.TableMetadataTasks) Collectors(java.util.stream.Collectors) KVTableMetadataStore(io.pravega.controller.store.kvtable.KVTableMetadataStore) READER_GROUP_STREAM_PREFIX(io.pravega.shared.NameUtils.READER_GROUP_STREAM_PREFIX) AbstractMap(java.util.AbstractMap) List(java.util.List) ContinuationTokenAsyncIterator(io.pravega.common.util.ContinuationTokenAsyncIterator) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) Preconditions(com.google.common.base.Preconditions) StreamMetadataStore(io.pravega.controller.store.stream.StreamMetadataStore) Futures(io.pravega.common.concurrent.Futures) HashMap(java.util.HashMap) InvalidStreamException(io.pravega.client.stream.InvalidStreamException) KeyValueTableInfo(io.pravega.client.admin.KeyValueTableInfo) Timer(io.pravega.common.Timer) ControllerFailureException(io.pravega.client.control.impl.ControllerFailureException) Stream(io.pravega.client.stream.Stream) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap)

Aggregations

ControllerFailureException (io.pravega.client.control.impl.ControllerFailureException)15 Test (org.junit.Test)12 Stream (io.pravega.client.stream.Stream)9 Controller (io.pravega.client.control.impl.Controller)6 ReaderGroupConfig (io.pravega.client.stream.ReaderGroupConfig)6 StreamImpl (io.pravega.client.stream.impl.StreamImpl)6 Futures (io.pravega.common.concurrent.Futures)6 ArrayList (java.util.ArrayList)6 Iterator (java.util.Iterator)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 KeyValueTableInfo (io.pravega.client.admin.KeyValueTableInfo)5 Segment (io.pravega.client.segment.impl.Segment)5 InvalidStreamException (io.pravega.client.stream.InvalidStreamException)5 StreamCut (io.pravega.client.stream.StreamCut)5 StreamCutImpl (io.pravega.client.stream.impl.StreamCutImpl)5 Exceptions (io.pravega.common.Exceptions)5 AsyncIterator (io.pravega.common.util.AsyncIterator)5 ClientConfig (io.pravega.client.ClientConfig)4 StreamInfo (io.pravega.client.admin.StreamInfo)4 StreamManager (io.pravega.client.admin.StreamManager)4