@Override public void truncate(final StreamId streamId) throws Exception { impersonator.doAs(streamId, new Callable<Void>() { @Override public Void call() throws Exception { doTruncate(streamId, getStreamLocation(streamId)); return null; } }); }
private static UserGroupInformation getUgiForDataset(Impersonator impersonator, DatasetId datasetInstanceId) throws IOException { // for system dataset do not look up owner information in store as we know that it will be null. // Also, this is required for CDAP to start, because initially we don't want to look up owner admin // (causing its own lookup) as the SystemDatasetInitiator.getDataset is called when CDAP starts UserGroupInformation ugi; if (NamespaceId.SYSTEM.equals(datasetInstanceId.getParent())) { ugi = UserGroupInformation.getCurrentUser(); } else { ugi = impersonator.getUGI(datasetInstanceId); } LOG.debug("Using {} user for dataset {}", ugi.getUserName(), datasetInstanceId); return ugi; }
@Override public void kill() { try { impersonator.doAs(programId, new Callable<Void>() { @Override public Void call() throws Exception { delegate.kill(); return null; } }); } catch (Exception e) { throw Throwables.propagate(e); } }
private static UserGroupInformation getUgiForDataset(Impersonator impersonator, DatasetId datasetInstanceId) throws IOException { // for system dataset do not look up owner information in store as we know that it will be null. // Also, this is required for CDAP to start, because initially we don't want to look up owner admin // (causing its own lookup) as the SystemDatasetInitiator.getDataset is called when CDAP starts UserGroupInformation ugi; if (NamespaceId.SYSTEM.equals(datasetInstanceId.getParent())) { ugi = UserGroupInformation.getCurrentUser(); } else { ugi = impersonator.getUGI(datasetInstanceId); } LOG.debug("Using {} user for dataset {}", ugi.getUserName(), datasetInstanceId); return ugi; }
@Override public void kill() { try { impersonator.doAs(programId, new Callable<Void>() { @Override public Void call() throws Exception { delegate.kill(); return null; } }); } catch (Exception e) { throw Throwables.propagate(e); } }
userId = impersonator.getUGI(schedule.getProgramId()).getUserName(); } catch (IOException e) { LOG.error("Exception occurs when looking up user group information for program {} in schedule {}",
@Override public void drop(final StreamId streamId) throws Exception { Location streamLocation = impersonator.doAs(streamId, new Callable<Location>() { @Override public Location call() throws Exception { return getStreamLocation(streamId); } }); doDrop(streamId, streamLocation); }
userId = impersonator.getUGI(schedule.getProgramId()).getUserName(); } catch (IOException e) { LOG.error("Exception occurs when looking up user group information for program {} in schedule {}",
private <T> T execute(final Callable<T> callable) throws IOException { try { return impersonator.doAs(datasetId, callable); } catch (IOException ioe) { throw ioe; } catch (Exception t) { Throwables.propagateIfPossible(t); // since the callables we execute only throw IOException (besides unchecked exceptions), // this should never happen LOG.warn("Unexpected exception while executing dataset admin operation in namespace {}.", datasetId, t); // the only checked exception that the Callables in this class is IOException, and we handle that in the previous // catch statement. So, no checked exceptions should be wrapped by the following statement. However, we need it // because ImpersonationUtils#doAs declares 'throws Exception', because it can throw other checked exceptions // in the general case throw Throwables.propagate(t); } } }
ugi = UserGroupInformation.getCurrentUser(); } else { ugi = impersonator.getUGI(namespace);
@Override public T call() throws Exception { return impersonator.doAs(namespaceMeta.getNamespaceId(), callable); } };
ugi = UserGroupInformation.getCurrentUser(); } else { ugi = impersonator.getUGI(namespace);
private <T> T execute(final Callable<T> callable) throws IOException { try { return impersonator.doAs(datasetId, callable); } catch (IOException ioe) { throw ioe; } catch (Exception t) { Throwables.propagateIfPossible(t); // since the callables we execute only throw IOException (besides unchecked exceptions), // this should never happen LOG.warn("Unexpected exception while executing dataset admin operation in namespace {}.", datasetId, t); // the only checked exception that the Callables in this class is IOException, and we handle that in the previous // catch statement. So, no checked exceptions should be wrapped by the following statement. However, we need it // because ImpersonationUtils#doAs declares 'throws Exception', because it can throw other checked exceptions // in the general case throw Throwables.propagate(t); } } }
String userId = impersonator.getUGI(sched1.getProgramId()).getUserName(); for (long runTime : runTimesSchedule1) { expectedRunRecords.add(
@Override public StreamConfig getConfig(final StreamId streamId) throws IOException { try { // No Authorization check performed in this method. If required, it should be added before this method is invoked return impersonator.doAs(streamId, new Callable<StreamConfig>() { @Override public StreamConfig call() throws IOException { Location configLocation = getConfigLocation(streamId); if (!configLocation.exists()) { throw new FileNotFoundException(String.format("Configuration file %s for stream '%s' does not exist.", configLocation.toURI().getPath(), streamId)); } StreamConfig config = GSON.fromJson( CharStreams.toString(CharStreams.newReaderSupplier(Locations.newInputSupplier(configLocation), Charsets.UTF_8)), StreamConfig.class); int threshold = config.getNotificationThresholdMB(); if (threshold <= 0) { // Need to default it for existing configs that were created before notification threshold was added. threshold = cConf.getInt(Constants.Stream.NOTIFICATION_THRESHOLD); } return new StreamConfig(streamId, config.getPartitionDuration(), config.getIndexInterval(), config.getTTL(), getStreamLocation(streamId), config.getFormat(), threshold); } }); } catch (Exception ex) { Throwables.propagateIfPossible(ex, IOException.class); throw new IOException(ex); } }
@Override public Future<? extends ServiceController> terminate() { try { return impersonator.doAs(programId, new Callable<Future<? extends ServiceController>>() { @Override public Future<? extends ServiceController> call() throws Exception { return delegate.terminate(); } }); } catch (Exception e) { return Futures.immediateFailedFuture(e); } }
@Override public Future<? extends ServiceController> terminate() { try { return impersonator.doAs(programId, new Callable<Future<? extends ServiceController>>() { @Override public Future<? extends ServiceController> call() throws Exception { return delegate.terminate(); } }); } catch (Exception e) { return Futures.immediateFailedFuture(e); } }
@Nullable @Override public ResourceReport getResourceReport() { try { return impersonator.doAs(programId, new Callable<ResourceReport>() { @Nullable @Override public ResourceReport call() throws Exception { return delegate.getResourceReport(); } }); } catch (Exception e) { // The delegate.getResourceReport() call never throws exception, hence exception caught must due to // impersonation failure. if (Throwables.getRootCause(e) instanceof ServiceUnavailableException) { // If it is due to some underlying service unavailability, log a debug message and return null // It is expected to happen during master process startup LOG.debug("Failed in impersonation for program {}", programId, e); } else { LOG.warn("Unexpected exception in impersonation for program {}", programId, e); } return null; } }
@Nullable @Override public ResourceReport getResourceReport() { try { return impersonator.doAs(programId, new Callable<ResourceReport>() { @Nullable @Override public ResourceReport call() throws Exception { return delegate.getResourceReport(); } }); } catch (Exception e) { // The delegate.getResourceReport() call never throws exception, hence exception caught must due to // impersonation failure. if (Throwables.getRootCause(e) instanceof ServiceUnavailableException) { // If it is due to some underlying service unavailability, log a debug message and return null // It is expected to happen during master process startup LOG.debug("Failed in impersonation for program {}", programId, e); } else { LOG.warn("Unexpected exception in impersonation for program {}", programId, e); } return null; } }
@Override public boolean exists(final StreamId streamId) throws Exception { try { boolean metaExists = streamMetaStore.streamExists(streamId); if (!metaExists) { return false; } return impersonator.doAs(streamId, new Callable<Boolean>() { @Override public Boolean call() throws Exception { return getConfigLocation(streamId).exists(); } }); } catch (IOException e) { LOG.error("Exception when check for stream exist.", e); return false; } }