use of co.cask.cdap.proto.StreamProperties in project cdap by caskdata.
the class FileStreamAdmin method updateConfig.
@Override
public void updateConfig(final StreamId streamId, final StreamProperties properties) throws Exception {
Location streamLocation;
// User should have admin access on the stream to update its configuration
ensureAccess(streamId, Action.ADMIN);
streamLocation = impersonator.doAs(streamId.getParent(), new Callable<Location>() {
@Override
public Location call() throws Exception {
return getStreamLocation(streamId);
}
});
Preconditions.checkArgument(streamLocation.isDirectory(), "Stream '%s' does not exist.", streamId);
SecurityUtil.verifyOwnerPrincipal(streamId, properties.getOwnerPrincipal(), ownerAdmin);
streamCoordinatorClient.updateProperties(streamId, new Callable<CoordinatorStreamProperties>() {
@Override
public CoordinatorStreamProperties call() throws Exception {
StreamProperties oldProperties = updateProperties(streamId, properties);
FormatSpecification format = properties.getFormat();
if (format != null) {
// if the schema has changed, we need to recreate the hive table.
// Changes in format and settings don't require
// a hive change, as they are just properties used by the stream storage handler.
Schema currSchema = oldProperties.getFormat().getSchema();
Schema newSchema = format.getSchema();
if (!Objects.equals(currSchema, newSchema)) {
alterExploreStream(streamId, false, null);
alterExploreStream(streamId, true, format);
}
}
publishAudit(streamId, AuditType.UPDATE);
return new CoordinatorStreamProperties(properties.getTTL(), properties.getFormat(), properties.getNotificationThresholdMB(), null, properties.getDescription(), properties.getOwnerPrincipal());
}
});
}
use of co.cask.cdap.proto.StreamProperties in project cdap by caskdata.
the class FileStreamAdmin method updateProperties.
private StreamProperties updateProperties(StreamId streamId, StreamProperties properties) throws Exception {
StreamConfig config = getConfig(streamId);
StreamConfig.Builder builder = StreamConfig.builder(config);
if (properties.getTTL() != null) {
builder.setTTL(properties.getTTL());
}
if (properties.getFormat() != null) {
builder.setFormatSpec(properties.getFormat());
}
if (properties.getNotificationThresholdMB() != null) {
builder.setNotificationThreshold(properties.getNotificationThresholdMB());
}
// update stream description
String description = properties.getDescription();
if (description != null) {
streamMetaStore.addStream(streamId, description);
}
final StreamConfig newConfig = builder.build();
impersonator.doAs(streamId, new Callable<Void>() {
@Override
public Void call() throws Exception {
writeConfig(newConfig);
return null;
}
});
// Update system metadata for stream
SystemMetadataWriter systemMetadataWriter = new StreamSystemMetadataWriter(metadataStore, streamId, newConfig, description);
systemMetadataWriter.write();
return new StreamProperties(config.getTTL(), config.getFormat(), config.getNotificationThresholdMB());
}
use of co.cask.cdap.proto.StreamProperties in project cdap by caskdata.
the class FileStreamAdmin method getProperties.
@Override
public StreamProperties getProperties(StreamId streamId) throws Exception {
// User should have any access on the stream to read its properties
ensureAccess(streamId);
// get the principal which will be used for impersonation to display as owner
String ownerPrincipal = ownerAdmin.getOwnerPrincipal(streamId);
StreamConfig config = getConfig(streamId);
StreamSpecification spec = streamMetaStore.getStream(streamId);
return new StreamProperties(config.getTTL(), config.getFormat(), config.getNotificationThresholdMB(), spec.getDescription(), ownerPrincipal);
}
use of co.cask.cdap.proto.StreamProperties in project cdap by caskdata.
the class StreamHandlerTest method verifyUpdateOwnerFailure.
private void verifyUpdateOwnerFailure(String streamName, @Nullable String ownerPrincipal) throws IOException, URISyntaxException {
StreamProperties newProps = new StreamProperties(1L, null, null, null, ownerPrincipal);
HttpURLConnection urlConn = openURL(createPropertiesURL(streamName), HttpMethod.PUT);
urlConn.setDoOutput(true);
urlConn.getOutputStream().write(GSON.toJson(newProps).getBytes(Charsets.UTF_8));
Assert.assertEquals(HttpResponseStatus.FORBIDDEN.getCode(), urlConn.getResponseCode());
urlConn.disconnect();
}
use of co.cask.cdap.proto.StreamProperties in project cdap by caskdata.
the class StreamHandlerTest method testUpdateDescription.
@Test
public void testUpdateDescription() throws Exception {
// Create a stream with some ttl and description
String desc = "large stream";
HttpURLConnection urlConn = openURL(createURL("streams/stream1"), HttpMethod.PUT);
urlConn.setDoOutput(true);
Schema schema = Schema.recordOf("event", Schema.Field.of("purchase", Schema.of(Schema.Type.STRING)));
FormatSpecification formatSpecification = new FormatSpecification(TextRecordFormat.class.getCanonicalName(), schema, ImmutableMap.of(TextRecordFormat.CHARSET, "utf8"));
StreamProperties properties = new StreamProperties(1L, formatSpecification, 128, desc, null);
urlConn.getOutputStream().write(GSON.toJson(properties).getBytes(Charsets.UTF_8));
Assert.assertEquals(HttpResponseStatus.OK.getCode(), urlConn.getResponseCode());
urlConn.disconnect();
// Check whether ttl and description got persisted
urlConn = openURL(createStreamInfoURL("stream1"), HttpMethod.GET);
Assert.assertEquals(HttpResponseStatus.OK.getCode(), urlConn.getResponseCode());
StreamProperties actual = GSON.fromJson(new String(ByteStreams.toByteArray(urlConn.getInputStream()), Charsets.UTF_8), StreamProperties.class);
urlConn.disconnect();
Assert.assertEquals(properties, actual);
// Update desc and ttl and check whether the changes were persisted
StreamProperties newProps = new StreamProperties(2L, null, null, "small stream", null);
urlConn = openURL(createPropertiesURL("stream1"), HttpMethod.PUT);
urlConn.setDoOutput(true);
urlConn.getOutputStream().write(GSON.toJson(newProps).getBytes(Charsets.UTF_8));
Assert.assertEquals(HttpResponseStatus.OK.getCode(), urlConn.getResponseCode());
urlConn.disconnect();
urlConn = openURL(createStreamInfoURL("stream1"), HttpMethod.GET);
Assert.assertEquals(HttpResponseStatus.OK.getCode(), urlConn.getResponseCode());
actual = GSON.fromJson(new String(ByteStreams.toByteArray(urlConn.getInputStream()), Charsets.UTF_8), StreamProperties.class);
urlConn.disconnect();
StreamProperties expected = new StreamProperties(newProps.getTTL(), properties.getFormat(), properties.getNotificationThresholdMB(), newProps.getDescription(), properties.getOwnerPrincipal());
Assert.assertEquals(expected, actual);
}
Aggregations