use of org.apache.ranger.plugin.util.ServiceTags in project ranger by apache.
the class TagDBStore method getServiceTagsIfUpdated.
@Override
public ServiceTags getServiceTagsIfUpdated(String serviceName, Long lastKnownVersion) throws Exception {
if (LOG.isDebugEnabled()) {
LOG.debug("==> TagDBStore.getServiceTagsIfUpdated(" + serviceName + ", " + lastKnownVersion + ")");
}
ServiceTags ret = null;
XXService xxService = daoManager.getXXService().findByName(serviceName);
if (xxService == null) {
LOG.error("Requested Service not found. serviceName=" + serviceName);
throw restErrorUtil.createRESTException(HttpServletResponse.SC_NOT_FOUND, RangerServiceNotFoundException.buildExceptionMsg(serviceName), false);
}
XXServiceVersionInfo serviceVersionInfoDbObj = daoManager.getXXServiceVersionInfo().findByServiceName(serviceName);
if (serviceVersionInfoDbObj == null) {
LOG.warn("serviceVersionInfo does not exist. name=" + serviceName);
}
if (lastKnownVersion == null || serviceVersionInfoDbObj == null || serviceVersionInfoDbObj.getTagVersion() == null || !lastKnownVersion.equals(serviceVersionInfoDbObj.getTagVersion())) {
ret = RangerServiceTagsCache.getInstance().getServiceTags(serviceName, xxService.getId(), this);
}
if (ret != null && lastKnownVersion != null && lastKnownVersion.equals(ret.getTagVersion())) {
// ServiceTags are not changed
ret = null;
}
if (LOG.isDebugEnabled()) {
RangerServiceTagsCache.getInstance().dump();
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== TagDBStore.getServiceTagsIfUpdated(" + serviceName + ", " + lastKnownVersion + "): count=" + ((ret == null || ret.getTags() == null) ? 0 : ret.getTags().size()));
}
return ret;
}
use of org.apache.ranger.plugin.util.ServiceTags in project ranger by apache.
the class TagREST method getServiceTagsIfUpdated.
// This API is typically used by plug-in to get selected tagged resources from RangerAdmin
@GET
@Path(TagRESTConstants.TAGS_DOWNLOAD + "{serviceName}")
@Produces({ "application/json", "application/xml" })
public ServiceTags getServiceTagsIfUpdated(@PathParam("serviceName") String serviceName, @QueryParam(TagRESTConstants.LAST_KNOWN_TAG_VERSION_PARAM) Long lastKnownVersion, @DefaultValue("0") @QueryParam(TagRESTConstants.LAST_ACTIVATION_TIME) Long lastActivationTime, @QueryParam("pluginId") String pluginId, @Context HttpServletRequest request) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> TagREST.getServiceTagsIfUpdated(" + serviceName + ", " + lastKnownVersion + ", " + lastActivationTime + ", " + pluginId + ")");
}
ServiceTags ret = null;
int httpCode = HttpServletResponse.SC_OK;
String logMsg = null;
Long downloadedVersion = null;
try {
ret = tagStore.getServiceTagsIfUpdated(serviceName, lastKnownVersion);
if (ret == null) {
downloadedVersion = lastKnownVersion;
httpCode = HttpServletResponse.SC_NOT_MODIFIED;
logMsg = "No change since last update";
} else {
downloadedVersion = ret.getTagVersion();
httpCode = HttpServletResponse.SC_OK;
logMsg = "Returning " + (ret.getTags() != null ? ret.getTags().size() : 0) + " tags. Tag version=" + ret.getTagVersion();
}
} catch (WebApplicationException webException) {
httpCode = webException.getResponse().getStatus();
logMsg = webException.getResponse().getEntity().toString();
} catch (Exception excp) {
httpCode = HttpServletResponse.SC_BAD_REQUEST;
logMsg = excp.getMessage();
} finally {
assetMgr.createPluginInfo(serviceName, pluginId, request, RangerPluginInfo.ENTITY_TYPE_TAGS, downloadedVersion, lastKnownVersion, lastActivationTime, httpCode);
}
if (httpCode != HttpServletResponse.SC_OK) {
boolean logError = httpCode != HttpServletResponse.SC_NOT_MODIFIED;
throw restErrorUtil.createRESTException(httpCode, logMsg, logError);
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== TagREST.getServiceTagsIfUpdated(" + serviceName + ", " + lastKnownVersion + ", " + lastActivationTime + ", " + pluginId + ")");
}
return ret;
}
use of org.apache.ranger.plugin.util.ServiceTags in project ranger by apache.
the class TagAdminRESTSink method doUpload.
private ServiceTags doUpload(ServiceTags serviceTags) throws Exception {
if (isKerberized) {
try {
UserGroupInformation userGroupInformation = UserGroupInformation.getLoginUser();
if (userGroupInformation != null) {
try {
userGroupInformation.checkTGTAndReloginFromKeytab();
} catch (IOException ioe) {
LOG.error("Error renewing TGT and relogin", ioe);
userGroupInformation = null;
}
}
if (userGroupInformation != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Using Principal = " + userGroupInformation.getUserName());
}
final ServiceTags serviceTag = serviceTags;
ServiceTags ret = userGroupInformation.doAs(new PrivilegedAction<ServiceTags>() {
@Override
public ServiceTags run() {
try {
return uploadServiceTags(serviceTag);
} catch (Exception e) {
LOG.error("Upload of service-tags failed with message ", e);
}
return null;
}
});
return ret;
} else {
LOG.error("Failed to get UserGroupInformation.getLoginUser()");
// This will cause retries !!!
return null;
}
} catch (Exception e) {
LOG.error("Upload of service-tags failed with message ", e);
}
return null;
} else {
return uploadServiceTags(serviceTags);
}
}
use of org.apache.ranger.plugin.util.ServiceTags in project ranger by apache.
the class AtlasNotificationMapper method buildServiceTagsForEntityDeleteNotification.
@SuppressWarnings("unchecked")
private static ServiceTags buildServiceTagsForEntityDeleteNotification(RangerAtlasEntityWithTags entityWithTags) {
final ServiceTags ret;
RangerAtlasEntity entity = entityWithTags.getEntity();
String guid = entity.getGuid();
if (StringUtils.isNotBlank(guid)) {
ret = new ServiceTags();
RangerServiceResource serviceResource = new RangerServiceResource();
serviceResource.setGuid(guid);
ret.getServiceResources().add(serviceResource);
} else {
ret = buildServiceTags(entityWithTags, null);
if (ret != null) {
// tag-definitions should NOT be deleted as part of service-resource delete
ret.setTagDefinitions(MapUtils.EMPTY_MAP);
// Ranger deletes tags associated with deleted service-resource
ret.setTags(MapUtils.EMPTY_MAP);
}
}
if (ret != null) {
ret.setOp(ServiceTags.OP_DELETE);
}
return ret;
}
use of org.apache.ranger.plugin.util.ServiceTags in project ranger by apache.
the class AtlasRESTTagSource method synchUp.
public void synchUp() {
List<RangerAtlasEntityWithTags> rangerAtlasEntities = getAtlasActiveEntities();
if (CollectionUtils.isNotEmpty(rangerAtlasEntities)) {
if (LOG.isDebugEnabled()) {
for (RangerAtlasEntityWithTags element : rangerAtlasEntities) {
LOG.debug(element);
}
}
Map<String, ServiceTags> serviceTagsMap = AtlasNotificationMapper.processAtlasEntities(rangerAtlasEntities);
if (MapUtils.isNotEmpty(serviceTagsMap)) {
for (Map.Entry<String, ServiceTags> entry : serviceTagsMap.entrySet()) {
if (LOG.isDebugEnabled()) {
Gson gsonBuilder = new GsonBuilder().setDateFormat("yyyyMMdd-HH:mm:ss.SSS-Z").setPrettyPrinting().create();
String serviceTagsString = gsonBuilder.toJson(entry.getValue());
LOG.debug("serviceTags=" + serviceTagsString);
}
updateSink(entry.getValue());
}
}
}
}
Aggregations