Search in sources :

Example 1 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class ModelHelper method getUpdateStreamConfig.

/**
 * This method translates the REST request object UpdateStreamRequest into internal object StreamConfiguration.
 *
 * @param updateStreamRequest An object conforming to the updateStreamConfig REST API json
 * @param scope               The scope of stream
 * @param stream              The name of stream
 * @return StreamConfiguration internal object
 */
public static final StreamConfiguration getUpdateStreamConfig(final UpdateStreamRequest updateStreamRequest, final String scope, final String stream) {
    ScalingPolicy scalingPolicy;
    if (updateStreamRequest.getScalingPolicy().getType() == ScalingConfig.TypeEnum.FIXED_NUM_SEGMENTS) {
        scalingPolicy = ScalingPolicy.fixed(updateStreamRequest.getScalingPolicy().getMinSegments());
    } else if (updateStreamRequest.getScalingPolicy().getType() == ScalingConfig.TypeEnum.BY_RATE_IN_EVENTS_PER_SEC) {
        scalingPolicy = ScalingPolicy.byEventRate(updateStreamRequest.getScalingPolicy().getTargetRate(), updateStreamRequest.getScalingPolicy().getScaleFactor(), updateStreamRequest.getScalingPolicy().getMinSegments());
    } else {
        scalingPolicy = ScalingPolicy.byDataRate(updateStreamRequest.getScalingPolicy().getTargetRate(), updateStreamRequest.getScalingPolicy().getScaleFactor(), updateStreamRequest.getScalingPolicy().getMinSegments());
    }
    RetentionPolicy retentionPolicy = null;
    if (updateStreamRequest.getRetentionPolicy() != null) {
        switch(updateStreamRequest.getRetentionPolicy().getType()) {
            case LIMITED_SIZE_MB:
                retentionPolicy = RetentionPolicy.bySizeBytes(updateStreamRequest.getRetentionPolicy().getValue() * 1024 * 1024);
                break;
            case LIMITED_DAYS:
                retentionPolicy = RetentionPolicy.byTime(Duration.ofDays(updateStreamRequest.getRetentionPolicy().getValue()));
                break;
        }
    }
    return StreamConfiguration.builder().scope(scope).streamName(stream).scalingPolicy(scalingPolicy).retentionPolicy(retentionPolicy).build();
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) RetentionPolicy(io.pravega.client.stream.RetentionPolicy)

Example 2 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class ModelHelper method getCreateStreamConfig.

/**
 * This method translates the REST request object CreateStreamRequest into internal object StreamConfiguration.
 *
 * @param createStreamRequest An object conforming to the createStream REST API json
 * @param scope               The scope of stream
 * @return StreamConfiguration internal object
 */
public static final StreamConfiguration getCreateStreamConfig(final CreateStreamRequest createStreamRequest, final String scope) {
    ScalingPolicy scalingPolicy;
    if (createStreamRequest.getScalingPolicy().getType() == ScalingConfig.TypeEnum.FIXED_NUM_SEGMENTS) {
        scalingPolicy = ScalingPolicy.fixed(createStreamRequest.getScalingPolicy().getMinSegments());
    } else if (createStreamRequest.getScalingPolicy().getType() == ScalingConfig.TypeEnum.BY_RATE_IN_EVENTS_PER_SEC) {
        scalingPolicy = ScalingPolicy.byEventRate(createStreamRequest.getScalingPolicy().getTargetRate(), createStreamRequest.getScalingPolicy().getScaleFactor(), createStreamRequest.getScalingPolicy().getMinSegments());
    } else {
        scalingPolicy = ScalingPolicy.byDataRate(createStreamRequest.getScalingPolicy().getTargetRate(), createStreamRequest.getScalingPolicy().getScaleFactor(), createStreamRequest.getScalingPolicy().getMinSegments());
    }
    RetentionPolicy retentionPolicy = null;
    if (createStreamRequest.getRetentionPolicy() != null) {
        switch(createStreamRequest.getRetentionPolicy().getType()) {
            case LIMITED_SIZE_MB:
                retentionPolicy = RetentionPolicy.bySizeBytes(createStreamRequest.getRetentionPolicy().getValue() * 1024 * 1024);
                break;
            case LIMITED_DAYS:
                retentionPolicy = RetentionPolicy.byTime(Duration.ofDays(createStreamRequest.getRetentionPolicy().getValue()));
                break;
        }
    }
    return StreamConfiguration.builder().scope(scope).streamName(createStreamRequest.getStreamName()).scalingPolicy(scalingPolicy).retentionPolicy(retentionPolicy).build();
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) RetentionPolicy(io.pravega.client.stream.RetentionPolicy)

Example 3 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class ZkStreamTest method testZkCreateScope.

@Test
public void testZkCreateScope() throws Exception {
    // create new scope test
    final StreamMetadataStore store = new ZKStreamMetadataStore(cli, executor);
    final String scopeName = "Scope1";
    CompletableFuture<CreateScopeStatus> createScopeStatus = store.createScope(scopeName);
    // createScope returns null on success, and exception on failure
    assertEquals("Create new scope :", CreateScopeStatus.Status.SUCCESS, createScopeStatus.get().getStatus());
    // create duplicate scope test
    createScopeStatus = store.createScope(scopeName);
    assertEquals("Create new scope :", CreateScopeStatus.Status.SCOPE_EXISTS, createScopeStatus.get().getStatus());
    // listStreamsInScope test
    final String streamName1 = "Stream1";
    final String streamName2 = "Stream2";
    final ScalingPolicy policy = ScalingPolicy.fixed(5);
    StreamConfiguration streamConfig = StreamConfiguration.builder().scope(scopeName).streamName(streamName1).scalingPolicy(policy).build();
    StreamConfiguration streamConfig2 = StreamConfiguration.builder().scope(scopeName).streamName(streamName2).scalingPolicy(policy).build();
    store.createStream(scopeName, streamName1, streamConfig, System.currentTimeMillis(), null, executor).get();
    store.setState(scopeName, streamName1, State.ACTIVE, null, executor).get();
    store.createStream(scopeName, streamName2, streamConfig2, System.currentTimeMillis(), null, executor).get();
    store.setState(scopeName, streamName2, State.ACTIVE, null, executor).get();
    List<StreamConfiguration> listOfStreams = store.listStreamsInScope(scopeName).get();
    assertEquals("Size of list", 2, listOfStreams.size());
    assertEquals("Name of stream at index zero", "Stream1", listOfStreams.get(0).getStreamName());
    assertEquals("Name of stream at index one", "Stream2", listOfStreams.get(1).getStreamName());
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) CreateScopeStatus(io.pravega.controller.stream.api.grpc.v1.Controller.CreateScopeStatus) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Test(org.junit.Test)

Example 4 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class ZkStreamTest method testCreateStreamState.

@Test
public void testCreateStreamState() throws Exception {
    final ScalingPolicy policy = ScalingPolicy.fixed(5);
    final StreamMetadataStore store = new ZKStreamMetadataStore(cli, executor);
    final String streamName = "testfail";
    StreamConfiguration streamConfig = StreamConfiguration.builder().scope(streamName).streamName(streamName).scalingPolicy(policy).build();
    store.createScope(SCOPE).get();
    store.createStream(SCOPE, streamName, streamConfig, System.currentTimeMillis(), null, executor).get();
    try {
        store.getConfiguration(SCOPE, streamName, null, executor).get();
    } catch (Exception e) {
        assert e.getCause() != null && e.getCause() instanceof IllegalStateException;
    }
    store.deleteScope(SCOPE);
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 5 with ScalingPolicy

use of io.pravega.client.stream.ScalingPolicy in project pravega by pravega.

the class ZkStreamTest method testZkConnectionLoss.

@Test
public void testZkConnectionLoss() throws Exception {
    final ScalingPolicy policy = ScalingPolicy.fixed(5);
    final String streamName = "testfail";
    final StreamConfiguration streamConfig = StreamConfiguration.builder().scope(streamName).streamName(streamName).scalingPolicy(policy).build();
    zkTestServer.stop();
    try {
        storePartialMock.createStream(SCOPE, streamName, streamConfig, System.currentTimeMillis(), null, executor).get();
    } catch (ExecutionException e) {
        assert e.getCause() instanceof StoreException.StoreConnectionException;
    }
    zkTestServer.start();
}
Also used : ScalingPolicy(io.pravega.client.stream.ScalingPolicy) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Aggregations

ScalingPolicy (io.pravega.client.stream.ScalingPolicy)47 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)44 Test (org.junit.Test)42 Before (org.junit.Before)16 TestingServerStarter (io.pravega.test.common.TestingServerStarter)15 Executors (java.util.concurrent.Executors)15 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)15 After (org.junit.After)15 Assert.assertEquals (org.junit.Assert.assertEquals)15 TestingServer (org.apache.curator.test.TestingServer)14 Assert.assertTrue (org.junit.Assert.assertTrue)14 ArrayList (java.util.ArrayList)13 Collections (java.util.Collections)13 HashMap (java.util.HashMap)13 List (java.util.List)13 RetentionPolicy (io.pravega.client.stream.RetentionPolicy)12 Map (java.util.Map)12 UUID (java.util.UUID)12 AbstractMap (java.util.AbstractMap)11 ExecutionException (java.util.concurrent.ExecutionException)11