use of org.apache.storm.shade.com.google.common.annotations.VisibleForTesting in project storm by apache.
the class Nimbus method checkAuthorization.
@VisibleForTesting
public void checkAuthorization(String topoName, Map<String, Object> topoConf, String operation, ReqContext context) throws AuthorizationException {
IAuthorizer impersonationAuthorizer = impersonationAuthorizationHandler;
if (context == null) {
context = ReqContext.context();
}
Map<String, Object> checkConf = new HashMap<>();
if (topoConf != null) {
checkConf.putAll(topoConf);
} else if (topoName != null) {
checkConf.put(Config.TOPOLOGY_NAME, topoName);
}
if (context.isImpersonating()) {
LOG.info("principal: {} is trying to impersonate principal: {}", context.realPrincipal(), context.principal());
if (impersonationAuthorizer == null) {
LOG.warn("impersonation attempt but {} has no authorizer configured. potential security risk, " + "please see SECURITY.MD to learn how to configure impersonation authorizer.", DaemonConfig.NIMBUS_IMPERSONATION_AUTHORIZER);
} else {
if (!impersonationAuthorizer.permit(context, operation, checkConf)) {
ThriftAccessLogger.logAccess(context.requestID(), context.remoteAddress(), context.principal(), operation, topoName, "access-denied");
throw new WrappedAuthorizationException("principal " + context.realPrincipal() + " is not authorized to impersonate principal " + context.principal() + " from host " + context.remoteAddress() + " Please see SECURITY.MD to learn how to configure impersonation acls.");
}
}
}
IAuthorizer aclHandler = authorizationHandler;
if (aclHandler != null) {
if (!aclHandler.permit(context, operation, checkConf)) {
ThriftAccessLogger.logAccess(context.requestID(), context.remoteAddress(), context.principal(), operation, topoName, "access-denied");
throw new WrappedAuthorizationException(operation + (topoName != null ? " on topology " + topoName : "") + " is not authorized");
} else {
ThriftAccessLogger.logAccess(context.requestID(), context.remoteAddress(), context.principal(), operation, topoName, "access-granted");
}
}
}
use of org.apache.storm.shade.com.google.common.annotations.VisibleForTesting in project storm by apache.
the class Nimbus method rmDependencyJarsInTopology.
@VisibleForTesting
public void rmDependencyJarsInTopology(String topoId) {
try {
BlobStore store = blobStore;
IStormClusterState state = stormClusterState;
StormTopology topo = readStormTopologyAsNimbus(topoId, topoCache);
List<String> dependencyJars = topo.get_dependency_jars();
LOG.info("Removing dependency jars from blobs - {}", dependencyJars);
if (dependencyJars != null && !dependencyJars.isEmpty()) {
for (String key : dependencyJars) {
rmBlobKey(store, key, state);
}
}
} catch (Exception e) {
// Yes eat the exception
LOG.info("Exception {}", e);
}
}
use of org.apache.storm.shade.com.google.common.annotations.VisibleForTesting in project storm by apache.
the class Nimbus method cleanInbox.
/**
* Deletes jar files in dirLoc older than seconds.
*
* @param dirLoc the location to look in for file
* @param seconds how old is too old and should be deleted
*/
@VisibleForTesting
public static void cleanInbox(String dirLoc, int seconds) {
final long now = Time.currentTimeMillis();
final long ms = Time.secsToMillis(seconds);
File dir = new File(dirLoc);
for (File f : dir.listFiles((file) -> file.isFile() && ((file.lastModified() + ms) <= now))) {
if (f.delete()) {
LOG.info("Cleaning inbox ... deleted: {}", f.getName());
} else {
LOG.error("Cleaning inbox ... error deleting: {}", f.getName());
}
}
}
use of org.apache.storm.shade.com.google.common.annotations.VisibleForTesting in project storm by apache.
the class Nimbus method setUpAckerExecutorConfigs.
@VisibleForTesting
public static void setUpAckerExecutorConfigs(String topoName, Map<String, Object> totalConfToSave, Map<String, Object> totalConf, int estimatedNumWorker) {
int numAckerExecs;
int numAckerExecsPerWorker;
if (totalConf.get(Config.TOPOLOGY_ACKER_EXECUTORS) == null) {
numAckerExecsPerWorker = ObjectReader.getInt(totalConf.get(Config.TOPOLOGY_RAS_ACKER_EXECUTORS_PER_WORKER));
numAckerExecs = estimatedNumWorker * numAckerExecsPerWorker;
} else {
numAckerExecs = ObjectReader.getInt(totalConf.get(Config.TOPOLOGY_ACKER_EXECUTORS));
if (estimatedNumWorker == 0) {
numAckerExecsPerWorker = 0;
} else {
numAckerExecsPerWorker = (int) Math.ceil((double) numAckerExecs / (double) estimatedNumWorker);
}
}
totalConfToSave.put(Config.TOPOLOGY_RAS_ACKER_EXECUTORS_PER_WORKER, numAckerExecsPerWorker);
totalConfToSave.put(Config.TOPOLOGY_ACKER_EXECUTORS, numAckerExecs);
LOG.info("Config {} set to: {} for topology: {}", Config.TOPOLOGY_RAS_ACKER_EXECUTORS_PER_WORKER, numAckerExecsPerWorker, topoName);
LOG.info("Config {} set to: {} for topology: {}", Config.TOPOLOGY_ACKER_EXECUTORS, numAckerExecs, topoName);
}
Aggregations