use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class Nimbus method getTopologyInfoWithOpts.
@Override
public TopologyInfo getTopologyInfoWithOpts(String topoId, GetInfoOptions options) throws NotAliveException, AuthorizationException, TException {
try {
getTopologyInfoWithOptsCalls.mark();
CommonTopoInfo common = getCommonTopoInfo(topoId, "getTopologyInfo");
if (common.base == null) {
throw new NotAliveException(topoId);
}
IStormClusterState state = stormClusterState;
NumErrorsChoice numErrChoice = OR(options.get_num_err_choice(), NumErrorsChoice.ALL);
Map<String, List<ErrorInfo>> errors = new HashMap<>();
for (String component : common.allComponents) {
switch(numErrChoice) {
case NONE:
errors.put(component, Collections.emptyList());
break;
case ONE:
List<ErrorInfo> errList = new ArrayList<>();
ErrorInfo info = state.lastError(topoId, component);
if (info != null) {
errList.add(info);
}
errors.put(component, errList);
break;
case ALL:
errors.put(component, state.errors(topoId, component));
break;
default:
LOG.warn("Got invalid NumErrorsChoice '{}'", numErrChoice);
errors.put(component, state.errors(topoId, component));
break;
}
}
List<ExecutorSummary> summaries = new ArrayList<>();
if (common.assignment != null) {
for (Entry<List<Long>, NodeInfo> entry : common.assignment.get_executor_node_port().entrySet()) {
NodeInfo ni = entry.getValue();
ExecutorInfo execInfo = toExecInfo(entry.getKey());
String host = entry.getValue().get_node();
Map<String, Object> heartbeat = common.beats.get(StatsUtil.convertExecutor(entry.getKey()));
if (heartbeat == null) {
heartbeat = Collections.emptyMap();
}
ExecutorSummary summ = new ExecutorSummary(execInfo, common.taskToComponent.get(execInfo.get_task_start()), ni.get_node(), ni.get_port_iterator().next().intValue(), (Integer) heartbeat.getOrDefault("uptime", 0));
//heartbeats "stats"
Map<String, Object> hb = (Map<String, Object>) heartbeat.get("heartbeat");
if (hb != null) {
Map ex = (Map) hb.get("stats");
if (ex != null) {
ExecutorStats stats = StatsUtil.thriftifyExecutorStats(ex);
summ.set_stats(stats);
}
}
summaries.add(summ);
}
}
TopologyInfo topoInfo = new TopologyInfo(topoId, common.topoName, Time.deltaSecs(common.launchTimeSecs), summaries, extractStatusStr(common.base), errors);
if (common.base.is_set_owner()) {
topoInfo.set_owner(common.base.get_owner());
}
String schedStatus = idToSchedStatus.get().get(topoId);
if (schedStatus != null) {
topoInfo.set_sched_status(schedStatus);
}
TopologyResources resources = getResourcesForTopology(topoId, common.base);
if (resources != null) {
topoInfo.set_requested_memonheap(resources.getRequestedMemOnHeap());
topoInfo.set_requested_memoffheap(resources.getRequestedMemOffHeap());
topoInfo.set_requested_cpu(resources.getRequestedCpu());
topoInfo.set_assigned_memonheap(resources.getAssignedMemOnHeap());
topoInfo.set_assigned_memoffheap(resources.getAssignedMemOffHeap());
topoInfo.set_assigned_cpu(resources.getAssignedCpu());
}
if (common.base.is_set_component_debug()) {
topoInfo.set_component_debug(common.base.get_component_debug());
}
topoInfo.set_replication_count(getBlobReplicationCount(ConfigUtils.masterStormCodeKey(topoId)));
return topoInfo;
} catch (Exception e) {
LOG.warn("Get topo info exception. (topology id='{}')", topoId, e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class DRPC method checkAuthorization.
@VisibleForTesting
static void checkAuthorization(ReqContext reqContext, IAuthorizer auth, String operation, String function) throws AuthorizationException {
if (reqContext != null) {
ThriftAccessLogger.logAccessFunction(reqContext.requestID(), reqContext.remoteAddress(), reqContext.principal(), operation, function);
}
if (auth != null) {
Map<String, String> map = new HashMap<>();
map.put(DRPCAuthorizerBase.FUNCTION_NAME, function);
if (!auth.permit(reqContext, operation, map)) {
Principal principal = reqContext.principal();
String user = (principal != null) ? principal.getName() : "unknown";
throw new AuthorizationException("DRPC request '" + operation + "' for '" + user + "' user is not authorized");
}
}
}
use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class UpdateBlobs method updateBlobsForTopology.
/**
* Update each blob listed in the topology configuration if the latest version of the blob has not been downloaded.
*
* @param conf
* @param stormId
* @param localizer
* @throws IOException
*/
private void updateBlobsForTopology(Map conf, String stormId, Localizer localizer) throws IOException {
Map stormConf = ConfigUtils.readSupervisorStormConf(conf, stormId);
Map<String, Map<String, Object>> blobstoreMap = (Map<String, Map<String, Object>>) stormConf.get(Config.TOPOLOGY_BLOBSTORE_MAP);
String user = (String) stormConf.get(Config.TOPOLOGY_SUBMITTER_USER);
List<LocalResource> localresources = SupervisorUtils.blobstoreMapToLocalresources(blobstoreMap);
try {
localizer.updateBlobs(localresources, user);
} catch (AuthorizationException authExp) {
LOG.error("AuthorizationException error", authExp);
} catch (KeyNotFoundException knf) {
LOG.error("KeyNotFoundException error", knf);
}
}
use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class ReturnResults method execute.
@Override
public void execute(Tuple input) {
String result = (String) input.getValue(0);
String returnInfo = (String) input.getValue(1);
if (returnInfo != null) {
Map retMap = null;
try {
retMap = (Map) JSONValue.parseWithException(returnInfo);
} catch (ParseException e) {
LOG.error("Parseing returnInfo failed", e);
_collector.fail(input);
return;
}
final String host = (String) retMap.get("host");
final int port = Utils.getInt(retMap.get("port"));
String id = (String) retMap.get("id");
DistributedRPCInvocations.Iface client;
if (local) {
client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host);
} else {
List server = new ArrayList() {
{
add(host);
add(port);
}
};
if (!_clients.containsKey(server)) {
try {
_clients.put(server, new DRPCInvocationsClient(_conf, host, port));
} catch (TTransportException ex) {
throw new RuntimeException(ex);
}
}
client = _clients.get(server);
}
int retryCnt = 0;
int maxRetries = 3;
while (retryCnt < maxRetries) {
retryCnt++;
try {
client.result(id, result);
_collector.ack(input);
break;
} catch (AuthorizationException aze) {
LOG.error("Not authorized to return results to DRPC server", aze);
_collector.fail(input);
throw new RuntimeException(aze);
} catch (TException tex) {
if (retryCnt >= maxRetries) {
LOG.error("Failed to return results to DRPC server", tex);
_collector.fail(input);
}
reconnectClient((DRPCInvocationsClient) client);
}
}
}
}
use of org.apache.storm.generated.AuthorizationException in project storm by apache.
the class Nimbus method getTopologyInfo.
@Override
public TopologyInfo getTopologyInfo(String id) throws NotAliveException, AuthorizationException, TException {
try {
getTopologyInfoCalls.mark();
GetInfoOptions options = new GetInfoOptions();
options.set_num_err_choice(NumErrorsChoice.ALL);
return getTopologyInfoWithOpts(id, options);
} catch (Exception e) {
LOG.warn("get topology ino exception. (topology id={})", id, e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
Aggregations