@Override public StreamId getParent() { return new StreamId(namespace, stream); }
@Override public void addStream(StreamId streamId) throws Exception { streams.put(streamId.getNamespace(), streamId.getEntityName()); }
private StreamViewId deserializeViewId(JsonObject id) { StreamId streamId = deserializeStreamId(id.getAsJsonObject("stream")); String view = id.get("id").getAsString(); return new StreamViewId(streamId.getNamespace(), streamId.getStream(), view); } }
@SuppressWarnings("unused") public static StreamId fromIdParts(Iterable<String> idString) { Iterator<String> iterator = idString.iterator(); return new StreamId(next(iterator, "namespace"), nextAndEnd(iterator, "stream")); }
private String getHiveTableName(StreamId streamId) { return String.format("stream_%s", streamId.getEntityName()); }
String streamName = streamId.getStream(); LOG.debug("Enabling explore for stream {} with table {}", streamId, tableName); Constants.Explore.STREAM_NAMESPACE, streamId.getNamespace(), Constants.Explore.FORMAT_SPEC, GSON.toJson(formatSpec)); return exploreService.execute(streamId.getParent(), createStatement);
/** * Returns the location for the given stream. */ private Location getStreamLocation(StreamId streamId) throws IOException { return getStreamBaseLocation(streamId.getParent()).append(streamId.getEntityName()); }
@Override public String getEntityName() { return getStream(); }
public static Stream fromEntityId(StreamId streamId) { return from(Id.Namespace.fromEntityId(streamId.getNamespaceId()), streamId.getStream()); }
/** * Disable exploration on the given stream by dropping the Hive table for the stream. * * @param tableName name of the table to delete * @param streamId the ID of the stream to disable * @return the query handle for disabling the stream * @throws ExploreException if there was an exception dropping the table * @throws SQLException if there was a problem with the drop table statement */ public QueryHandle disableStream(String tableName, StreamId streamId) throws ExploreException, SQLException { LOG.debug("Disabling explore for stream {} with table {}", streamId, tableName); String deleteStatement = generateDeleteTableStatement(null, tableName); return exploreService.execute(streamId.getParent(), deleteStatement); }
@Override public void dropAll(StreamId streamId, String namespace, Iterable<Long> groupIds) throws IOException { // A bit hacky to assume namespace is formed by appId.flowId. See AbstractDataFabricFacade // String namespace = String.format("%s.%s", // programId.getApplicationId(), // programId.getId()); String invalidNamespaceError = String.format("Namespace string %s must be of the form <app>.<flow>", namespace); Iterator<String> namespaceParts = Splitter.on('.').split(namespace).iterator(); Preconditions.checkArgument(namespaceParts.hasNext(), invalidNamespaceError); String appId = namespaceParts.next(); Preconditions.checkArgument(namespaceParts.hasNext(), invalidNamespaceError); String flowId = namespaceParts.next(); queueService.truncateAllWithPrefix(QueueName.prefixForFlow(new FlowId(streamId.getNamespace(), appId, flowId))); } }
public byte[] toBytes() { if (idBytes == null) { idBytes = Bytes.toBytes(toString()); } return idBytes; } }
@Nullable @Override public StreamConfig create(StreamId streamId, @Nullable Properties props) throws Exception { String specifiedOwnerPrincipal = props != null && props.containsKey(Constants.Security.PRINCIPAL) ? props.getProperty(Constants.Security.PRINCIPAL) : null; // need to enforce on the principal id if impersonation is involved KerberosPrincipalId effectiveOwner = SecurityUtil.getEffectiveOwner(ownerAdmin, streamId.getNamespaceId(), specifiedOwnerPrincipal); Principal requestingUser = authenticationContext.getPrincipal(); if (effectiveOwner != null) { authorizationEnforcer.enforce(effectiveOwner, requestingUser, Action.ADMIN); } ensureAccess(streamId, Action.ADMIN); return delegate.create(streamId, props); }
@Override public Map<String, String> getSystemPropertiesToAdd() { ImmutableMap.Builder<String, String> properties = ImmutableMap.builder(); properties.put(ENTITY_NAME_KEY, config.getStreamId().getEntityName()); properties.put(TTL_KEY, String.valueOf(config.getTTL())); if (creationTime > 0) { properties.put(CREATION_TIME_KEY, String.valueOf(creationTime)); } if (description != null) { properties.put(DESCRIPTION_KEY, description); } return properties.build(); }
@Override public StreamMetricsCollector createMetricsCollector(final StreamId streamId) { MetricsContext streamMetricsContext = streamMetricsCollectors.getUnchecked(streamId.getParent()); final MetricsContext childCollector = streamMetricsContext.childContext(Constants.Metrics.Tag.STREAM, streamId.getEntityName()); return new StreamMetricsCollector() { @Override public void emitMetrics(long bytesWritten, long eventsWritten) { if (bytesWritten > 0) { childCollector.increment("collect.bytes", bytesWritten); sizeCollector.received(streamId, bytesWritten); } if (eventsWritten > 0) { childCollector.increment("collect.events", eventsWritten); } } }; } };
public String getTableName(StreamId streamId) { return String.format("stream_%s", cleanTableName(streamId.getStream())); }
@Override public void updateConfig(final StreamId streamId, final StreamProperties properties) throws Exception { Location streamLocation; streamLocation = impersonator.doAs(streamId.getParent(), new Callable<Location>() { @Override public Location call() throws Exception {
/** * Updates stream properties in the property store. */ private ListenableFuture<CoordinatorStreamProperties> updateProperties(StreamId streamId, final CoordinatorStreamProperties properties) { return propertyStore.update(streamId.toString(), new SyncPropertyUpdater<CoordinatorStreamProperties>() { @Override protected CoordinatorStreamProperties compute(@Nullable CoordinatorStreamProperties oldProperties) { if (oldProperties == null) { return properties; } // Merge the old and new properties. return new CoordinatorStreamProperties( firstNotNull(properties.getTTL(), oldProperties.getTTL()), firstNotNull(properties.getFormat(), oldProperties.getFormat()), firstNotNull(properties.getNotificationThresholdMB(), oldProperties.getNotificationThresholdMB()), firstNotNull(properties.getGeneration(), oldProperties.getGeneration()), firstNotNull(properties.getDescription(), oldProperties.getDescription()), firstNotNull(properties.getOwnerPrincipal(), oldProperties.getOwnerPrincipal())); } }); }
@Override public void removeStream(StreamId streamId) throws Exception { streams.remove(streamId.getNamespace(), streamId.getEntityName()); }
public StreamId stream(String stream) { return new StreamId(namespace, stream); }