@Override
protected UGIWithPrincipal createUGI(ImpersonationRequest impersonationRequest) throws IOException {
ImpersonationRequest jsonRequest = new ImpersonationRequest(impersonationRequest.getEntityId(),
impersonationRequest.getImpersonatedOpType(),
impersonationRequest.getPrincipal());
PrincipalCredentials principalCredentials =
GSON.fromJson(executeRequest(jsonRequest).getResponseBodyAsString(), PrincipalCredentials.class);
LOG.debug("Received response: {}", principalCredentials);
Location location = locationFactory.create(URI.create(principalCredentials.getCredentialsPath()));
try {
String user = principalCredentials.getPrincipal();
if (impersonationRequest.getImpersonatedOpType() == ImpersonatedOpType.EXPLORE) {
user = new KerberosName(user).getShortName();
}
UserGroupInformation impersonatedUGI = UserGroupInformation.createRemoteUser(user);
impersonatedUGI.addCredentials(readCredentials(location));
return new UGIWithPrincipal(principalCredentials.getPrincipal(), impersonatedUGI);
} finally {
try {
if (!location.delete()) {
LOG.warn("Failed to delete location: {}", location);
}
} catch (IOException e) {
LOG.warn("Exception raised when deleting location {}", location, e);
}
}
}