Search in sources :

Example 1 with RangerPluginInfo

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;
}
Also used : RangerPluginInfo(org.apache.ranger.plugin.model.RangerPluginInfo)

Example 2 with RangerPluginInfo

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;
}
Also used : XXPluginInfo(org.apache.ranger.entity.XXPluginInfo) RangerPluginInfo(org.apache.ranger.plugin.model.RangerPluginInfo)

Example 3 with RangerPluginInfo

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);
}
Also used : RangerRESTUtils(org.apache.ranger.plugin.util.RangerRESTUtils) Date(java.util.Date) RangerPluginInfo(org.apache.ranger.plugin.model.RangerPluginInfo)

Example 4 with RangerPluginInfo

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;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) RangerPluginInfoList(org.apache.ranger.view.RangerPluginInfoList) SearchFilter(org.apache.ranger.plugin.util.SearchFilter) RangerPluginInfo(org.apache.ranger.plugin.model.RangerPluginInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 5 with RangerPluginInfo

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;
}
Also used : PList(org.apache.ranger.plugin.store.PList) ArrayList(java.util.ArrayList) XXPluginInfo(org.apache.ranger.entity.XXPluginInfo) XXService(org.apache.ranger.entity.XXService) XXServiceVersionInfo(org.apache.ranger.entity.XXServiceVersionInfo) RangerPluginInfo(org.apache.ranger.plugin.model.RangerPluginInfo)

Aggregations

RangerPluginInfo (org.apache.ranger.plugin.model.RangerPluginInfo)6 XXPluginInfo (org.apache.ranger.entity.XXPluginInfo)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 XXService (org.apache.ranger.entity.XXService)1 XXServiceVersionInfo (org.apache.ranger.entity.XXServiceVersionInfo)1 PList (org.apache.ranger.plugin.store.PList)1 RangerRESTUtils (org.apache.ranger.plugin.util.RangerRESTUtils)1 SearchFilter (org.apache.ranger.plugin.util.SearchFilter)1 RangerPluginInfoList (org.apache.ranger.view.RangerPluginInfoList)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1