use of org.apache.ranger.plugin.model.RangerPluginInfo in project ranger by apache.
the class RangerPluginInfoService method populateViewObjectWithServiceVersionInfo.
private RangerPluginInfo populateViewObjectWithServiceVersionInfo(XXPluginInfo xObj, XXServiceVersionInfo xxServiceVersionInfo, boolean hasAssociatedTagService) {
RangerPluginInfo ret = new RangerPluginInfo();
ret.setId(xObj.getId());
ret.setCreateTime(xObj.getCreateTime());
ret.setUpdateTime(xObj.getUpdateTime());
ret.setServiceName(xObj.getServiceName());
ret.setHostName(xObj.getHostName());
ret.setAppType(xObj.getAppType());
ret.setIpAddress(xObj.getIpAddress());
ret.setInfo(jsonStringToMap(xObj.getInfo(), xxServiceVersionInfo, hasAssociatedTagService));
return ret;
}
use of org.apache.ranger.plugin.model.RangerPluginInfo in project ranger by apache.
the class AssetMgr method doCreateOrUpdateXXPluginInfo.
private XXPluginInfo doCreateOrUpdateXXPluginInfo(RangerPluginInfo pluginInfo, final boolean isPolicyDownloadRequest, final boolean isTagVersionResetNeeded) {
XXPluginInfo ret = null;
if (StringUtils.isNotBlank(pluginInfo.getServiceName())) {
XXPluginInfo xObj = rangerDaoManager.getXXPluginInfo().find(pluginInfo.getServiceName(), pluginInfo.getHostName(), pluginInfo.getAppType());
if (xObj == null) {
// ranger-admin is restarted, plugin contains latest versions and no earlier record for this plug-in client
if (isPolicyDownloadRequest) {
if (pluginInfo.getPolicyDownloadedVersion() != null && pluginInfo.getPolicyDownloadedVersion().equals(pluginInfo.getPolicyActiveVersion())) {
// This is our best guess of when policies may have been downloaded
pluginInfo.setPolicyDownloadTime(pluginInfo.getPolicyActivationTime());
}
} else if (pluginInfo.getTagDownloadedVersion() != null && pluginInfo.getTagDownloadedVersion().equals(pluginInfo.getTagActiveVersion())) {
// This is our best guess of when tags may have been downloaded
pluginInfo.setTagDownloadTime(pluginInfo.getTagActivationTime());
}
xObj = pluginInfoService.populateDBObject(pluginInfo);
if (logger.isDebugEnabled()) {
logger.debug("Creating RangerPluginInfo record for service-version");
}
ret = rangerDaoManager.getXXPluginInfo().create(xObj);
} else {
boolean needsUpdating = false;
RangerPluginInfo dbObj = pluginInfoService.populateViewObject(xObj);
if (!dbObj.getIpAddress().equals(pluginInfo.getIpAddress())) {
dbObj.setIpAddress(pluginInfo.getIpAddress());
needsUpdating = true;
}
if (isPolicyDownloadRequest) {
if (dbObj.getPolicyDownloadedVersion() == null || !dbObj.getPolicyDownloadedVersion().equals(pluginInfo.getPolicyDownloadedVersion())) {
dbObj.setPolicyDownloadedVersion(pluginInfo.getPolicyDownloadedVersion());
dbObj.setPolicyDownloadTime(pluginInfo.getPolicyDownloadTime());
needsUpdating = true;
}
Long lastKnownPolicyVersion = pluginInfo.getPolicyActiveVersion();
Long lastPolicyActivationTime = pluginInfo.getPolicyActivationTime();
if (lastKnownPolicyVersion != null && lastKnownPolicyVersion == -1) {
// First download request after plug-in's policy-refresher starts
dbObj.setPolicyDownloadTime(pluginInfo.getPolicyDownloadTime());
needsUpdating = true;
}
if (lastKnownPolicyVersion != null && lastKnownPolicyVersion > 0 && (dbObj.getPolicyActiveVersion() == null || !dbObj.getPolicyActiveVersion().equals(lastKnownPolicyVersion))) {
dbObj.setPolicyActiveVersion(lastKnownPolicyVersion);
needsUpdating = true;
}
if (lastPolicyActivationTime != null && lastPolicyActivationTime > 0 && (dbObj.getPolicyActivationTime() == null || !dbObj.getPolicyActivationTime().equals(lastPolicyActivationTime))) {
dbObj.setPolicyActivationTime(lastPolicyActivationTime);
needsUpdating = true;
}
} else {
if (dbObj.getTagDownloadedVersion() == null || !dbObj.getTagDownloadedVersion().equals(pluginInfo.getTagDownloadedVersion())) {
// First download for tags after tag-service is associated with resource-service
dbObj.setTagDownloadedVersion(pluginInfo.getTagDownloadedVersion());
dbObj.setTagDownloadTime(pluginInfo.getTagDownloadTime());
needsUpdating = true;
}
Long lastKnownTagVersion = pluginInfo.getTagActiveVersion();
Long lastTagActivationTime = pluginInfo.getTagActivationTime();
if (lastKnownTagVersion != null && lastKnownTagVersion == -1) {
// First download request after plug-in's tag-refresher restarts
dbObj.setTagDownloadTime(pluginInfo.getTagDownloadTime());
needsUpdating = true;
}
if (lastKnownTagVersion != null && lastKnownTagVersion > 0 && (dbObj.getTagActiveVersion() == null || !dbObj.getTagActiveVersion().equals(lastKnownTagVersion))) {
dbObj.setTagActiveVersion(lastKnownTagVersion);
needsUpdating = true;
}
if (lastTagActivationTime != null && lastTagActivationTime > 0 && (dbObj.getTagActivationTime() == null || !dbObj.getTagActivationTime().equals(lastTagActivationTime))) {
dbObj.setTagActivationTime(lastTagActivationTime);
needsUpdating = true;
}
}
if (isTagVersionResetNeeded) {
dbObj.setTagDownloadedVersion(null);
dbObj.setTagDownloadTime(null);
dbObj.setTagActiveVersion(null);
dbObj.setTagActivationTime(null);
needsUpdating = true;
}
if (needsUpdating) {
if (logger.isDebugEnabled()) {
logger.debug("Updating XXPluginInfo record for service-version");
}
xObj = pluginInfoService.populateDBObject(dbObj);
ret = rangerDaoManager.getXXPluginInfo().update(xObj);
}
}
} else {
logger.error("Invalid parameters: pluginInfo=" + pluginInfo + ")");
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPluginInfo in project ranger by apache.
the class AssetMgr method createPluginInfo.
public void createPluginInfo(String serviceName, String pluginId, HttpServletRequest request, int entityType, Long downloadedVersion, long lastKnownVersion, long lastActivationTime, int httpCode) {
RangerRESTUtils restUtils = new RangerRESTUtils();
final String ipAddress = getRemoteAddress(request);
final String appType = restUtils.getAppIdFromPluginId(pluginId);
String tmpHostName = null;
if (StringUtils.isNotBlank(pluginId)) {
tmpHostName = restUtils.getHostnameFromPluginId(pluginId, serviceName);
}
if (StringUtils.isBlank(tmpHostName) && request != null) {
tmpHostName = request.getRemoteHost();
}
final String hostName = (StringUtils.isBlank(tmpHostName)) ? ipAddress : tmpHostName;
RangerPluginInfo pluginSvcVersionInfo = new RangerPluginInfo();
pluginSvcVersionInfo.setServiceName(serviceName);
pluginSvcVersionInfo.setAppType(appType);
pluginSvcVersionInfo.setHostName(hostName);
pluginSvcVersionInfo.setIpAddress(ipAddress);
if (entityType == RangerPluginInfo.ENTITY_TYPE_POLICIES) {
pluginSvcVersionInfo.setPolicyActiveVersion(lastKnownVersion);
pluginSvcVersionInfo.setPolicyActivationTime(lastActivationTime);
pluginSvcVersionInfo.setPolicyDownloadedVersion(downloadedVersion);
pluginSvcVersionInfo.setPolicyDownloadTime(new Date().getTime());
} else {
pluginSvcVersionInfo.setTagActiveVersion(lastKnownVersion);
pluginSvcVersionInfo.setTagActivationTime(lastActivationTime);
pluginSvcVersionInfo.setTagDownloadedVersion(downloadedVersion);
pluginSvcVersionInfo.setTagDownloadTime(new Date().getTime());
}
createOrUpdatePluginInfo(pluginSvcVersionInfo, entityType == RangerPluginInfo.ENTITY_TYPE_POLICIES, httpCode);
}
use of org.apache.ranger.plugin.model.RangerPluginInfo in project ranger by apache.
the class ServiceREST method getPluginsInfo.
@GET
@Path("/plugins/info")
@Produces({ "application/json", "application/xml" })
@PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_PLUGINS_INFO + "\")")
public RangerPluginInfoList getPluginsInfo(@Context HttpServletRequest request) {
if (LOG.isDebugEnabled()) {
LOG.debug("==> ServiceREST.getPluginsInfo()");
}
RangerPluginInfoList ret = null;
SearchFilter filter = searchUtil.getSearchFilter(request, pluginInfoService.getSortFields());
try {
PList<RangerPluginInfo> paginatedPluginsInfo = pluginInfoService.searchRangerPluginInfo(filter);
if (paginatedPluginsInfo != null) {
ret = new RangerPluginInfoList();
ret.setPluginInfoList(paginatedPluginsInfo.getList());
ret.setPageSize(paginatedPluginsInfo.getPageSize());
ret.setResultSize(paginatedPluginsInfo.getResultSize());
ret.setStartIndex(paginatedPluginsInfo.getStartIndex());
ret.setTotalCount(paginatedPluginsInfo.getTotalCount());
ret.setSortBy(paginatedPluginsInfo.getSortBy());
ret.setSortType(paginatedPluginsInfo.getSortType());
}
} catch (WebApplicationException excp) {
throw excp;
} catch (Throwable excp) {
LOG.error("getPluginsInfo() failed", excp);
throw restErrorUtil.createRESTException(excp.getMessage());
}
if (LOG.isDebugEnabled()) {
LOG.debug("<== ServiceREST.getPluginsInfo()");
}
return ret;
}
use of org.apache.ranger.plugin.model.RangerPluginInfo in project ranger by apache.
the class RangerPluginInfoService method searchRangerPluginInfo.
public PList<RangerPluginInfo> searchRangerPluginInfo(SearchFilter searchFilter) {
PList<RangerPluginInfo> retList = new PList<RangerPluginInfo>();
List<RangerPluginInfo> objList = new ArrayList<RangerPluginInfo>();
List<XXService> servicesWithTagService = daoManager.getXXService().getAllServicesWithTagService();
List<XXPluginInfo> xObjList = searchRangerObjects(searchFilter, searchFields, sortFields, retList);
List<Object[]> objectsList = null;
if (CollectionUtils.isNotEmpty(xObjList)) {
objectsList = daoManager.getXXServiceVersionInfo().getAllWithServiceNames();
}
for (XXPluginInfo xObj : xObjList) {
XXServiceVersionInfo xxServiceVersionInfo = null;
boolean hasAssociatedTagService = false;
if (CollectionUtils.isNotEmpty(objectsList)) {
for (Object[] objects : objectsList) {
if (objects.length == 2) {
if (xObj.getServiceName().equals(objects[1])) {
if (objects[0] instanceof XXServiceVersionInfo) {
xxServiceVersionInfo = (XXServiceVersionInfo) objects[0];
for (XXService service : servicesWithTagService) {
if (service.getName().equals(xObj.getServiceName())) {
hasAssociatedTagService = true;
break;
}
}
} else {
LOG.warn("Expected first object to be XXServiceVersionInfo, got " + objects[0]);
}
break;
}
} else {
LOG.warn("Expected 2 objects in the list returned by getAllWithServiceNames(), received " + objects.length);
}
}
}
RangerPluginInfo obj = populateViewObjectWithServiceVersionInfo(xObj, xxServiceVersionInfo, hasAssociatedTagService);
objList.add(obj);
}
retList.setList(objList);
return retList;
}
Aggregations