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();
}
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();
}
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());
}
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);
}
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();
}
Aggregations