Search in sources :

Example 16 with ControllerServiceBlockingStub

use of io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub in project pravega by pravega.

the class ControllerGrpcAuthFocusedTest method createScopeAndStreams.

private void createScopeAndStreams(String scopeName, List<String> streamNames, ScalingPolicy scalingPolicy) {
    Exceptions.checkNotNullOrEmpty(scopeName, "scope");
    Preconditions.checkNotNull(streamNames, "stream");
    Preconditions.checkArgument(streamNames.size() > 0);
    Preconditions.checkNotNull(scalingPolicy, "scalingPolicy");
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.ADMIN, DEFAULT_PASSWORD);
    createScope(stub, scopeName);
    streamNames.stream().forEach(n -> createStream(stub, scopeName, n, scalingPolicy));
}
Also used : ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub)

Example 17 with ControllerServiceBlockingStub

use of io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub in project pravega by pravega.

the class ControllerGrpcAuthFocusedTest method createStream.

private void createStream(ControllerServiceBlockingStub stub, String scopeName, String streamName, ScalingPolicy scalingPolicy) {
    StreamConfig streamConfig = StreamConfig.newBuilder().setStreamInfo(Controller.StreamInfo.newBuilder().setScope(scopeName).setStream(streamName).build()).setScalingPolicy(scalingPolicy).build();
    Controller.CreateStreamStatus status = stub.createStream(streamConfig);
    if (!status.getStatus().equals(Controller.CreateStreamStatus.Status.SUCCESS)) {
        throw new RuntimeException("Failed to create stream");
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) StreamConfig(io.pravega.controller.stream.api.grpc.v1.Controller.StreamConfig) Controller(io.pravega.controller.stream.api.grpc.v1.Controller)

Example 18 with ControllerServiceBlockingStub

use of io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub in project pravega by pravega.

the class ControllerGrpcAuthFocusedTest method isSegmentValidSucceedsForAuthorizedUser.

@Test(timeout = 20000)
public void isSegmentValidSucceedsForAuthorizedUser() {
    String scope = "scope1";
    String stream = "stream1";
    createScopeAndStream(scope, stream, prepareFromFixedScaleTypePolicy(2));
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.SCOPE1_STREAM1_READ, DEFAULT_PASSWORD);
    assertTrue(stub.isSegmentValid(segmentId(scope, stream, 0)).getResponse());
    assertFalse(stub.isSegmentValid(segmentId(scope, stream, 3)).getResponse());
}
Also used : ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) AuthFileUtils.credentialsAndAclAsString(io.pravega.auth.AuthFileUtils.credentialsAndAclAsString) Test(org.junit.Test)

Example 19 with ControllerServiceBlockingStub

use of io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub in project pravega by pravega.

the class ControllerGrpcAuthFocusedTest method listStreamsReturnsAllWhenUserHasWildCardAccessUsingBlockingStub.

@Test(timeout = 20000)
public void listStreamsReturnsAllWhenUserHasWildCardAccessUsingBlockingStub() {
    // Arrange
    String scopeName = "scope1";
    createScopeAndStreams(scopeName, Arrays.asList("stream1", "stream2"), prepareFromFixedScaleTypePolicy(2));
    Controller.StreamsInScopeRequest request = Controller.StreamsInScopeRequest.newBuilder().setScope(Controller.ScopeInfo.newBuilder().setScope(scopeName).build()).setContinuationToken(Controller.ContinuationToken.newBuilder().build()).build();
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.ADMIN, DEFAULT_PASSWORD);
    // Act
    Controller.StreamsInScopeResponse response = stub.listStreamsInScope(request);
    // Assert
    assertEquals(2, response.getStreamsList().size());
}
Also used : ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) AuthFileUtils.credentialsAndAclAsString(io.pravega.auth.AuthFileUtils.credentialsAndAclAsString) Controller(io.pravega.controller.stream.api.grpc.v1.Controller) Test(org.junit.Test)

Example 20 with ControllerServiceBlockingStub

use of io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub in project pravega by pravega.

the class ControllerGrpcAuthFocusedTest method isSegmentValidFailsForUnauthorizedUser.

@Test(timeout = 20000)
public void isSegmentValidFailsForUnauthorizedUser() {
    String scope = "scope1";
    String stream = "stream1";
    createScopeAndStream(scope, stream, prepareFromFixedScaleTypePolicy(2));
    // Note that the user has READ access to scope1/stream2, not scope1/stream1.
    ControllerServiceBlockingStub stub = prepareBlockingCallStub(UserNames.SCOPE1_STREAM2_READ, DEFAULT_PASSWORD);
    // Set the expected exception
    thrown.expect(StatusRuntimeException.class);
    // thrown.expectMessage();
    thrown.expectMessage("PERMISSION_DENIED");
    stub.isSegmentValid(segmentId(scope, stream, 0));
}
Also used : ControllerServiceBlockingStub(io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub) AuthFileUtils.credentialsAndAclAsString(io.pravega.auth.AuthFileUtils.credentialsAndAclAsString) Test(org.junit.Test)

Aggregations

ControllerServiceBlockingStub (io.pravega.controller.stream.api.grpc.v1.ControllerServiceGrpc.ControllerServiceBlockingStub)20 Test (org.junit.Test)14 Controller (io.pravega.controller.stream.api.grpc.v1.Controller)10 AuthFileUtils.credentialsAndAclAsString (io.pravega.auth.AuthFileUtils.credentialsAndAclAsString)9 StatusRuntimeException (io.grpc.StatusRuntimeException)3 MoreCallCredentials (io.grpc.auth.MoreCallCredentials)2 PravegaCredentialsWrapper (io.pravega.client.control.impl.PravegaCredentialsWrapper)2 NodeUri (io.pravega.controller.stream.api.grpc.v1.Controller.NodeUri)2 PingTxnStatus (io.pravega.controller.stream.api.grpc.v1.Controller.PingTxnStatus)2 TxnId (io.pravega.controller.stream.api.grpc.v1.Controller.TxnId)2 Credentials (io.pravega.shared.security.auth.Credentials)2 DefaultCredentials (io.pravega.shared.security.auth.DefaultCredentials)2 StreamConfig (io.pravega.controller.stream.api.grpc.v1.Controller.StreamConfig)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1