Search in sources :

Example 1 with TimeBasedRetention

use of io.pravega.controller.server.rest.generated.model.TimeBasedRetention in project pravega by pravega.

the class StreamMetaDataTests method setup.

@Before
public void setup() throws Exception {
    mockControllerService = mock(ControllerService.class);
    serverConfig = RESTServerConfigImpl.builder().host("localhost").port(TestUtils.getAvailableListenPort()).build();
    LocalController controller = new LocalController(mockControllerService, false, "");
    connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().controllerURI(URI.create("tcp://localhost")).build());
    restServer = new RESTServer(serverConfig, Set.of(new StreamMetadataResourceImpl(controller, mockControllerService, authManager, connectionFactory, ClientConfig.builder().build())));
    restServer.startAsync();
    restServer.awaitRunning();
    client = ClientBuilder.newClient();
    scalingPolicyCommon.setType(ScalingConfig.TypeEnum.BY_RATE_IN_EVENTS_PER_SEC);
    scalingPolicyCommon.setTargetRate(100);
    scalingPolicyCommon.setScaleFactor(2);
    scalingPolicyCommon.setMinSegments(2);
    scalingPolicyCommon2.setType(ScalingConfig.TypeEnum.FIXED_NUM_SEGMENTS);
    scalingPolicyCommon2.setMinSegments(2);
    retentionPolicyCommon.setType(TypeEnum.LIMITED_DAYS);
    retentionPolicyCommon.setValue(123L);
    TimeBasedRetention timeRetention = new TimeBasedRetention();
    retentionPolicyCommon.setTimeBasedRetention(timeRetention.days(123L).hours(0L).minutes(0L));
    retentionPolicyCommon2.setType(null);
    retentionPolicyCommon2.setValue(null);
    retentionPolicyCommon2.setTimeBasedRetention(null);
    streamResponseExpected.setScopeName(scope1);
    streamResponseExpected.setStreamName(stream1);
    streamResponseExpected.setScalingPolicy(scalingPolicyCommon);
    streamResponseExpected.setRetentionPolicy(retentionPolicyCommon);
    retentionPolicyGran.setType(TypeEnum.LIMITED_DAYS);
    retentionPolicyGran.setValue(0L);
    TimeBasedRetention tr = new TimeBasedRetention();
    retentionPolicyGran.setTimeBasedRetention(tr.days(2L).hours(3L).minutes(5L));
    streamResponseGranExpected.setScopeName(scope1);
    streamResponseGranExpected.setStreamName(stream1);
    streamResponseGranExpected.setScalingPolicy(scalingPolicyCommon);
    streamResponseGranExpected.setRetentionPolicy(retentionPolicyGran);
    retentionPolicyDateMins.setType(TypeEnum.LIMITED_DAYS);
    retentionPolicyDateMins.setValue(0L);
    TimeBasedRetention tr1 = new TimeBasedRetention();
    retentionPolicyDateMins.setTimeBasedRetention(tr1.days(10L).hours(0L).minutes(50L));
    streamResponseRetDaysMinsExpected.setScopeName(scope1);
    streamResponseRetDaysMinsExpected.setStreamName(stream1);
    streamResponseRetDaysMinsExpected.setScalingPolicy(scalingPolicyCommon);
    streamResponseRetDaysMinsExpected.setRetentionPolicy(retentionPolicyDateMins);
    retentionPolicyHoursMins.setType(TypeEnum.LIMITED_DAYS);
    retentionPolicyHoursMins.setValue(0L);
    TimeBasedRetention tr2 = new TimeBasedRetention();
    retentionPolicyHoursMins.setTimeBasedRetention(tr2.days(0L).hours(13L).minutes(26L));
    streamResponseRetHoursMinsExpected.setScopeName(scope1);
    streamResponseRetHoursMinsExpected.setStreamName(stream1);
    streamResponseRetHoursMinsExpected.setScalingPolicy(scalingPolicyCommon);
    streamResponseRetHoursMinsExpected.setRetentionPolicy(retentionPolicyHoursMins);
    retentionPolicyOnlyHours.setType(TypeEnum.LIMITED_DAYS);
    retentionPolicyOnlyHours.setValue(0L);
    TimeBasedRetention tr3 = new TimeBasedRetention();
    retentionPolicyOnlyHours.setTimeBasedRetention(tr3.days(0L).hours(16L).minutes(0L));
    streamResponseRetOnlyHoursExpected.setScopeName(scope1);
    streamResponseRetOnlyHoursExpected.setStreamName(stream1);
    streamResponseRetOnlyHoursExpected.setScalingPolicy(scalingPolicyCommon);
    streamResponseRetOnlyHoursExpected.setRetentionPolicy(retentionPolicyOnlyHours);
    retentionPolicyOnlyMins.setType(TypeEnum.LIMITED_DAYS);
    retentionPolicyOnlyMins.setValue(0L);
    TimeBasedRetention tr4 = new TimeBasedRetention();
    retentionPolicyOnlyMins.setTimeBasedRetention(tr4.days(0L).hours(0L).minutes(32L));
    streamResponseRetOnlyMinsExpected.setScopeName(scope1);
    streamResponseRetOnlyMinsExpected.setStreamName(stream1);
    streamResponseRetOnlyMinsExpected.setScalingPolicy(scalingPolicyCommon);
    streamResponseRetOnlyMinsExpected.setRetentionPolicy(retentionPolicyOnlyMins);
    createStreamRequest.setStreamName(stream1);
    createStreamRequest.setScalingPolicy(scalingPolicyCommon);
    createStreamRequest.setRetentionPolicy(retentionPolicyCommon);
    createStreamRequest2.setStreamName(stream1);
    createStreamRequest2.setScalingPolicy(scalingPolicyCommon);
    createStreamRequest2.setRetentionPolicy(retentionPolicyCommon2);
    createStreamRequest3.setStreamName(stream1);
    createStreamRequest3.setScalingPolicy(scalingPolicyCommon);
    createStreamRequest3.setRetentionPolicy(retentionPolicyCommon);
    createStreamRequest4.setStreamName(stream3);
    createStreamRequest4.setScalingPolicy(scalingPolicyCommon);
    // stream 4 where targetRate and scalingFactor for Scaling Policy are null
    createStreamRequest5.setStreamName(stream4);
    createStreamRequest5.setScalingPolicy(scalingPolicyCommon2);
    createStreamRequest5.setRetentionPolicy(retentionPolicyCommon);
    streamResponseExpected2.setScopeName(scope1);
    streamResponseExpected2.setStreamName(stream3);
    streamResponseExpected2.setScalingPolicy(scalingPolicyCommon);
    streamResponseExpected3.setScopeName(scope1);
    streamResponseExpected3.setStreamName(stream4);
    streamResponseExpected3.setScalingPolicy(scalingPolicyCommon2);
    streamResponseExpected3.setRetentionPolicy(retentionPolicyCommon);
    updateStreamRequest.setScalingPolicy(scalingPolicyCommon);
    updateStreamRequest.setRetentionPolicy(retentionPolicyCommon);
    updateStreamRequest2.setScalingPolicy(scalingPolicyCommon);
    updateStreamRequest2.setRetentionPolicy(retentionPolicyCommon);
    updateStreamRequest3.setScalingPolicy(scalingPolicyCommon);
    updateStreamRequest3.setRetentionPolicy(retentionPolicyCommon2);
}
Also used : LocalController(io.pravega.controller.server.eventProcessor.LocalController) StreamMetadataResourceImpl(io.pravega.controller.server.rest.resources.StreamMetadataResourceImpl) RESTServer(io.pravega.shared.rest.RESTServer) SocketConnectionFactoryImpl(io.pravega.client.connection.impl.SocketConnectionFactoryImpl) ControllerService(io.pravega.controller.server.ControllerService) TimeBasedRetention(io.pravega.controller.server.rest.generated.model.TimeBasedRetention) Before(org.junit.Before)

Example 2 with TimeBasedRetention

use of io.pravega.controller.server.rest.generated.model.TimeBasedRetention in project pravega by pravega.

the class ModelHelperTest method testGetUpdateStreamConfig.

@Test(timeout = 10000)
public void testGetUpdateStreamConfig() {
    ScalingConfig scalingConfig = new ScalingConfig();
    scalingConfig.setType(ScalingConfig.TypeEnum.FIXED_NUM_SEGMENTS);
    scalingConfig.setMinSegments(2);
    UpdateStreamRequest updateStreamRequest = new UpdateStreamRequest();
    updateStreamRequest.setScalingPolicy(scalingConfig);
    updateStreamRequest.setTimestampAggregationTimeout(1000L);
    updateStreamRequest.setRolloverSizeBytes(1024L);
    StreamConfiguration streamConfig = getUpdateStreamConfig(updateStreamRequest);
    Assert.assertEquals(ScalingPolicy.ScaleType.FIXED_NUM_SEGMENTS, streamConfig.getScalingPolicy().getScaleType());
    Assert.assertEquals(2, streamConfig.getScalingPolicy().getMinNumSegments());
    Assert.assertNull(streamConfig.getRetentionPolicy());
    Assert.assertEquals(streamConfig.getTimestampAggregationTimeout(), 1000L);
    Assert.assertEquals(streamConfig.getRolloverSizeBytes(), 1024L);
    scalingConfig.setType(ScalingConfig.TypeEnum.BY_RATE_IN_EVENTS_PER_SEC);
    scalingConfig.setTargetRate(123);
    scalingConfig.setScaleFactor(2);
    RetentionConfig retentionConfig = new RetentionConfig();
    retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_DAYS);
    retentionConfig.setValue(1234L);
    updateStreamRequest.setScalingPolicy(scalingConfig);
    updateStreamRequest.setRetentionPolicy(retentionConfig);
    streamConfig = getUpdateStreamConfig(updateStreamRequest);
    Assert.assertEquals(ScalingPolicy.ScaleType.BY_RATE_IN_EVENTS_PER_SEC, streamConfig.getScalingPolicy().getScaleType());
    Assert.assertEquals(2, streamConfig.getScalingPolicy().getScaleFactor());
    Assert.assertEquals(123, streamConfig.getScalingPolicy().getTargetRate());
    Assert.assertEquals(RetentionPolicy.RetentionType.TIME, streamConfig.getRetentionPolicy().getRetentionType());
    Assert.assertEquals(Duration.ofDays(1234L).toMillis(), streamConfig.getRetentionPolicy().getRetentionParam());
    retentionConfig.setValue(0L);
    TimeBasedRetention tr = new TimeBasedRetention();
    tr.days(21L).hours(8L).minutes(25L);
    retentionConfig.setTimeBasedRetention(tr);
    streamConfig = getUpdateStreamConfig(updateStreamRequest);
    Assert.assertEquals(RetentionPolicy.RetentionType.TIME, streamConfig.getRetentionPolicy().getRetentionType());
    Duration retentionDuration = Duration.ofDays(21L).plusHours(8L).plusMinutes(25L);
    Assert.assertEquals(retentionDuration.toMillis(), streamConfig.getRetentionPolicy().getRetentionParam());
    scalingConfig.setType(ScalingConfig.TypeEnum.BY_RATE_IN_KBYTES_PER_SEC);
    scalingConfig.setTargetRate(1234);
    scalingConfig.setScaleFactor(23);
    retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_SIZE_MB);
    retentionConfig.setValue(12345L);
    updateStreamRequest.setScalingPolicy(scalingConfig);
    updateStreamRequest.setRetentionPolicy(retentionConfig);
    streamConfig = getUpdateStreamConfig(updateStreamRequest);
    Assert.assertEquals(ScalingPolicy.ScaleType.BY_RATE_IN_KBYTES_PER_SEC, streamConfig.getScalingPolicy().getScaleType());
    Assert.assertEquals(23, streamConfig.getScalingPolicy().getScaleFactor());
    Assert.assertEquals(1234, streamConfig.getScalingPolicy().getTargetRate());
    Assert.assertEquals(RetentionPolicy.RetentionType.SIZE, streamConfig.getRetentionPolicy().getRetentionType());
    Assert.assertEquals(12345L * 1024 * 1024, streamConfig.getRetentionPolicy().getRetentionParam());
}
Also used : ScalingConfig(io.pravega.controller.server.rest.generated.model.ScalingConfig) UpdateStreamRequest(io.pravega.controller.server.rest.generated.model.UpdateStreamRequest) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Duration(java.time.Duration) TimeBasedRetention(io.pravega.controller.server.rest.generated.model.TimeBasedRetention) RetentionConfig(io.pravega.controller.server.rest.generated.model.RetentionConfig) Test(org.junit.Test)

Example 3 with TimeBasedRetention

use of io.pravega.controller.server.rest.generated.model.TimeBasedRetention in project pravega by pravega.

the class ModelHelperTest method testGetCreateStreamConfig.

@Test(timeout = 10000)
public void testGetCreateStreamConfig() {
    ScalingConfig scalingConfig = new ScalingConfig();
    scalingConfig.setType(ScalingConfig.TypeEnum.FIXED_NUM_SEGMENTS);
    scalingConfig.setMinSegments(2);
    CreateStreamRequest createStreamRequest = new CreateStreamRequest();
    createStreamRequest.setStreamName("stream");
    createStreamRequest.setScalingPolicy(scalingConfig);
    // Stream with Fixed Scaling Policy and no Retention Policy and default rolloverSize
    StreamConfiguration streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(ScalingPolicy.ScaleType.FIXED_NUM_SEGMENTS, streamConfig.getScalingPolicy().getScaleType());
    Assert.assertEquals(2, streamConfig.getScalingPolicy().getMinNumSegments());
    Assert.assertNull(streamConfig.getRetentionPolicy());
    Assert.assertEquals(streamConfig.getTimestampAggregationTimeout(), 0);
    Assert.assertEquals(streamConfig.getRolloverSizeBytes(), 0);
    // Stream with Fixed Scaling Policy and no Retention Policy and positive rolloverSize
    createStreamRequest = new CreateStreamRequest();
    createStreamRequest.setStreamName("stream");
    createStreamRequest.setScalingPolicy(scalingConfig);
    createStreamRequest.setTimestampAggregationTimeout(1000L);
    createStreamRequest.setRolloverSizeBytes(1024L);
    streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(streamConfig.getTimestampAggregationTimeout(), 1000L);
    Assert.assertEquals(streamConfig.getRolloverSizeBytes(), 1024L);
    // Stream with Fixed Scaling Policy & Size based Retention Policy with min & max limits
    RetentionConfig retentionConfig = new RetentionConfig();
    retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_SIZE_MB);
    retentionConfig.setValue(1234L);
    retentionConfig.setMaxValue(4567L);
    createStreamRequest.setRetentionPolicy(retentionConfig);
    streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(ScalingPolicy.ScaleType.FIXED_NUM_SEGMENTS, streamConfig.getScalingPolicy().getScaleType());
    Assert.assertEquals(2, streamConfig.getScalingPolicy().getMinNumSegments());
    Assert.assertNotNull(streamConfig.getRetentionPolicy());
    Assert.assertEquals(RetentionPolicy.RetentionType.SIZE, streamConfig.getRetentionPolicy().getRetentionType());
    Assert.assertEquals(1234L * 1024 * 1024, streamConfig.getRetentionPolicy().getRetentionParam());
    Assert.assertEquals(4567L * 1024 * 1024, streamConfig.getRetentionPolicy().getRetentionMax());
    scalingConfig.setType(ScalingConfig.TypeEnum.BY_RATE_IN_EVENTS_PER_SEC);
    scalingConfig.setTargetRate(123);
    scalingConfig.setScaleFactor(2);
    retentionConfig = new RetentionConfig();
    retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_DAYS);
    retentionConfig.setValue(1234L);
    createStreamRequest.setStreamName("stream");
    createStreamRequest.setScalingPolicy(scalingConfig);
    createStreamRequest.setRetentionPolicy(retentionConfig);
    streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(ScalingPolicy.ScaleType.BY_RATE_IN_EVENTS_PER_SEC, streamConfig.getScalingPolicy().getScaleType());
    Assert.assertEquals(2, streamConfig.getScalingPolicy().getScaleFactor());
    Assert.assertEquals(123, streamConfig.getScalingPolicy().getTargetRate());
    Assert.assertEquals(RetentionPolicy.RetentionType.TIME, streamConfig.getRetentionPolicy().getRetentionType());
    Assert.assertEquals(Duration.ofDays(1234L).toMillis(), streamConfig.getRetentionPolicy().getRetentionParam());
    Assert.assertEquals(Long.MAX_VALUE, streamConfig.getRetentionPolicy().getRetentionMax());
    retentionConfig.setValue(0L);
    TimeBasedRetention tr = new TimeBasedRetention();
    tr.days(10L).hours(4L).minutes(7L);
    retentionConfig.setTimeBasedRetention(tr);
    streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(RetentionPolicy.RetentionType.TIME, streamConfig.getRetentionPolicy().getRetentionType());
    Duration retentionDuration = Duration.ofDays(10L).plusHours(4L).plusMinutes(7L);
    Assert.assertEquals(retentionDuration.toMillis(), streamConfig.getRetentionPolicy().getRetentionParam());
    Assert.assertEquals(Long.MAX_VALUE, streamConfig.getRetentionPolicy().getRetentionMax());
    retentionConfig = new RetentionConfig();
    retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_DAYS);
    retentionConfig.setValue(3L);
    tr = new TimeBasedRetention();
    tr.days(200L).hours(2L).minutes(5L);
    retentionConfig.setMaxTimeBasedRetention(tr);
    createStreamRequest.setStreamName("stream");
    createStreamRequest.setScalingPolicy(scalingConfig);
    createStreamRequest.setRetentionPolicy(retentionConfig);
    streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(RetentionPolicy.RetentionType.TIME, streamConfig.getRetentionPolicy().getRetentionType());
    Assert.assertEquals(Duration.ofDays(3L).toMillis(), streamConfig.getRetentionPolicy().getRetentionParam());
    retentionDuration = Duration.ofDays(200L).plusHours(2L).plusMinutes(5L);
    Assert.assertEquals(retentionDuration.toMillis(), streamConfig.getRetentionPolicy().getRetentionMax());
    retentionConfig = new RetentionConfig();
    retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_DAYS);
    retentionConfig.setValue(3L);
    tr = new TimeBasedRetention();
    tr.days(200L).hours(2L).minutes(5L);
    retentionConfig.setMaxTimeBasedRetention(tr);
    createStreamRequest.setStreamName("stream");
    createStreamRequest.setScalingPolicy(scalingConfig);
    createStreamRequest.setRetentionPolicy(retentionConfig);
    streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(RetentionPolicy.RetentionType.TIME, streamConfig.getRetentionPolicy().getRetentionType());
    Assert.assertEquals(Duration.ofDays(3L).toMillis(), streamConfig.getRetentionPolicy().getRetentionParam());
    retentionDuration = Duration.ofDays(200L).plusHours(2L).plusMinutes(5L);
    Assert.assertEquals(retentionDuration.toMillis(), streamConfig.getRetentionPolicy().getRetentionMax());
    retentionConfig = new RetentionConfig();
    retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_DAYS);
    retentionConfig.setValue(0L);
    tr = new TimeBasedRetention();
    tr.days(2L).hours(2L).minutes(20L);
    retentionConfig.setTimeBasedRetention(tr);
    TimeBasedRetention trMax = new TimeBasedRetention();
    trMax.days(300L).hours(3L).minutes(30L);
    retentionConfig.setMaxTimeBasedRetention(trMax);
    createStreamRequest.setStreamName("stream");
    createStreamRequest.setScalingPolicy(scalingConfig);
    createStreamRequest.setRetentionPolicy(retentionConfig);
    streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(RetentionPolicy.RetentionType.TIME, streamConfig.getRetentionPolicy().getRetentionType());
    Duration retentionDurationMin = Duration.ofDays(2L).plusHours(2L).plusMinutes(20L);
    Assert.assertEquals(retentionDurationMin.toMillis(), streamConfig.getRetentionPolicy().getRetentionParam());
    Duration retentionDurationMax = Duration.ofDays(300L).plusHours(3L).plusMinutes(30L);
    Assert.assertEquals(retentionDurationMax.toMillis(), streamConfig.getRetentionPolicy().getRetentionMax());
    retentionConfig = new RetentionConfig();
    retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_DAYS);
    retentionConfig.setValue(2L);
    tr = new TimeBasedRetention();
    tr.days(2L).hours(2L).minutes(20L);
    retentionConfig.setTimeBasedRetention(tr);
    retentionConfig.setMaxValue(100L);
    trMax = new TimeBasedRetention();
    trMax.days(400L).hours(4L).minutes(40L);
    retentionConfig.setMaxTimeBasedRetention(trMax);
    createStreamRequest.setStreamName("stream");
    createStreamRequest.setScalingPolicy(scalingConfig);
    createStreamRequest.setRetentionPolicy(retentionConfig);
    streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(RetentionPolicy.RetentionType.TIME, streamConfig.getRetentionPolicy().getRetentionType());
    Assert.assertEquals(Duration.ofDays(2L).toMillis(), streamConfig.getRetentionPolicy().getRetentionParam());
    Assert.assertEquals(Duration.ofDays(100L).toMillis(), streamConfig.getRetentionPolicy().getRetentionMax());
    scalingConfig.setType(ScalingConfig.TypeEnum.BY_RATE_IN_KBYTES_PER_SEC);
    scalingConfig.setTargetRate(1234);
    scalingConfig.setScaleFactor(23);
    retentionConfig = new RetentionConfig();
    retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_SIZE_MB);
    retentionConfig.setValue(12345L);
    createStreamRequest.setStreamName("stream");
    createStreamRequest.setScalingPolicy(scalingConfig);
    createStreamRequest.setRetentionPolicy(retentionConfig);
    streamConfig = getCreateStreamConfig(createStreamRequest);
    Assert.assertEquals(ScalingPolicy.ScaleType.BY_RATE_IN_KBYTES_PER_SEC, streamConfig.getScalingPolicy().getScaleType());
    Assert.assertEquals(23, streamConfig.getScalingPolicy().getScaleFactor());
    Assert.assertEquals(1234, streamConfig.getScalingPolicy().getTargetRate());
    Assert.assertEquals(RetentionPolicy.RetentionType.SIZE, streamConfig.getRetentionPolicy().getRetentionType());
    Assert.assertEquals(12345L * 1024 * 1024, streamConfig.getRetentionPolicy().getRetentionParam());
    Assert.assertEquals(Long.MAX_VALUE, streamConfig.getRetentionPolicy().getRetentionMax());
}
Also used : ScalingConfig(io.pravega.controller.server.rest.generated.model.ScalingConfig) CreateStreamRequest(io.pravega.controller.server.rest.generated.model.CreateStreamRequest) StreamConfiguration(io.pravega.client.stream.StreamConfiguration) Duration(java.time.Duration) TimeBasedRetention(io.pravega.controller.server.rest.generated.model.TimeBasedRetention) RetentionConfig(io.pravega.controller.server.rest.generated.model.RetentionConfig) Test(org.junit.Test)

Example 4 with TimeBasedRetention

use of io.pravega.controller.server.rest.generated.model.TimeBasedRetention in project pravega by pravega.

the class ModelHelper method encodeStreamResponse.

/**
 * The method translates the internal object StreamConfiguration into REST response object.
 *
 * @param scope               the scope of the stream
 * @param streamName          the name of the stream
 * @param streamConfiguration The configuration of stream
 * @return Stream properties wrapped in StreamResponse object
 */
public static final StreamProperty encodeStreamResponse(String scope, String streamName, final StreamConfiguration streamConfiguration) {
    ScalingConfig scalingPolicy = new ScalingConfig();
    if (streamConfiguration.getScalingPolicy().getScaleType() == ScalingPolicy.ScaleType.FIXED_NUM_SEGMENTS) {
        scalingPolicy.setType(ScalingConfig.TypeEnum.valueOf(streamConfiguration.getScalingPolicy().getScaleType().name()));
        scalingPolicy.setMinSegments(streamConfiguration.getScalingPolicy().getMinNumSegments());
    } else {
        scalingPolicy.setType(ScalingConfig.TypeEnum.valueOf(streamConfiguration.getScalingPolicy().getScaleType().name()));
        scalingPolicy.setTargetRate(streamConfiguration.getScalingPolicy().getTargetRate());
        scalingPolicy.setScaleFactor(streamConfiguration.getScalingPolicy().getScaleFactor());
        scalingPolicy.setMinSegments(streamConfiguration.getScalingPolicy().getMinNumSegments());
    }
    RetentionConfig retentionConfig = null;
    if (streamConfiguration.getRetentionPolicy() != null) {
        retentionConfig = new RetentionConfig();
        switch(streamConfiguration.getRetentionPolicy().getRetentionType()) {
            case SIZE:
                retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_SIZE_MB);
                retentionConfig.setValue(streamConfiguration.getRetentionPolicy().getRetentionParam() / (1024 * 1024));
                break;
            case TIME:
                retentionConfig.setType(RetentionConfig.TypeEnum.LIMITED_DAYS);
                TimeBasedRetention timeRetention = new TimeBasedRetention();
                long totalMilliSecs = streamConfiguration.getRetentionPolicy().getRetentionParam();
                long days = Duration.ofMillis(streamConfiguration.getRetentionPolicy().getRetentionParam()).toDays();
                long daysInMs = Duration.ofDays(days).toMillis();
                long hours = 0L, minutes = 0L;
                if (totalMilliSecs == daysInMs) {
                    // retention is specified only in days
                    hours = 0L;
                    minutes = 0L;
                    retentionConfig.setValue(days);
                } else {
                    hours = TimeUnit.MILLISECONDS.toHours(totalMilliSecs - daysInMs);
                    minutes = getMinsFromMillis(totalMilliSecs, daysInMs, hours);
                    retentionConfig.setValue(0L);
                }
                retentionConfig.setTimeBasedRetention(timeRetention.days(days).hours(hours).minutes(minutes));
                break;
            default:
                throw new NotImplementedException("consumption type not supported");
        }
    }
    TagsList tagList = new TagsList();
    tagList.addAll(streamConfiguration.getTags());
    StreamProperty streamProperty = new StreamProperty();
    streamProperty.setScopeName(scope);
    streamProperty.setStreamName(streamName);
    streamProperty.setScalingPolicy(scalingPolicy);
    streamProperty.setRetentionPolicy(retentionConfig);
    streamProperty.setTags(tagList);
    streamProperty.setTimestampAggregationTimeout(streamConfiguration.getTimestampAggregationTimeout());
    streamProperty.setRolloverSizeBytes(streamConfiguration.getRolloverSizeBytes());
    return streamProperty;
}
Also used : ScalingConfig(io.pravega.controller.server.rest.generated.model.ScalingConfig) NotImplementedException(org.apache.commons.lang3.NotImplementedException) StreamProperty(io.pravega.controller.server.rest.generated.model.StreamProperty) TagsList(io.pravega.controller.server.rest.generated.model.TagsList) TimeBasedRetention(io.pravega.controller.server.rest.generated.model.TimeBasedRetention) RetentionConfig(io.pravega.controller.server.rest.generated.model.RetentionConfig)

Aggregations

TimeBasedRetention (io.pravega.controller.server.rest.generated.model.TimeBasedRetention)4 RetentionConfig (io.pravega.controller.server.rest.generated.model.RetentionConfig)3 ScalingConfig (io.pravega.controller.server.rest.generated.model.ScalingConfig)3 StreamConfiguration (io.pravega.client.stream.StreamConfiguration)2 Duration (java.time.Duration)2 Test (org.junit.Test)2 SocketConnectionFactoryImpl (io.pravega.client.connection.impl.SocketConnectionFactoryImpl)1 ControllerService (io.pravega.controller.server.ControllerService)1 LocalController (io.pravega.controller.server.eventProcessor.LocalController)1 CreateStreamRequest (io.pravega.controller.server.rest.generated.model.CreateStreamRequest)1 StreamProperty (io.pravega.controller.server.rest.generated.model.StreamProperty)1 TagsList (io.pravega.controller.server.rest.generated.model.TagsList)1 UpdateStreamRequest (io.pravega.controller.server.rest.generated.model.UpdateStreamRequest)1 StreamMetadataResourceImpl (io.pravega.controller.server.rest.resources.StreamMetadataResourceImpl)1 RESTServer (io.pravega.shared.rest.RESTServer)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 Before (org.junit.Before)1