Search in sources :

Example 1 with XXPluginInfo

use of org.apache.ranger.entity.XXPluginInfo in project ranger by apache.

the class RangerPluginInfoService method searchRangerObjects.

private List<XXPluginInfo> searchRangerObjects(SearchFilter searchCriteria, List<SearchField> searchFieldList, List<SortField> sortFieldList, PList<RangerPluginInfo> pList) {
    // Get total count of the rows which meet the search criteria
    long count = -1;
    if (searchCriteria.isGetCount()) {
        count = getCountForSearchQuery(searchCriteria, searchFieldList);
        if (count == 0) {
            return Collections.emptyList();
        }
    }
    String sortClause = searchUtil.constructSortClause(searchCriteria, sortFieldList);
    String queryStr = "SELECT obj FROM " + XXPluginInfo.class.getName() + " obj ";
    Query query = createQuery(queryStr, sortClause, searchCriteria, searchFieldList, false);
    List<XXPluginInfo> resultList = daoManager.getXXPluginInfo().executeQueryInSecurityContext(XXPluginInfo.class, query);
    if (pList != null) {
        pList.setResultSize(resultList.size());
        pList.setPageSize(query.getMaxResults());
        pList.setSortBy(searchCriteria.getSortBy());
        pList.setSortType(searchCriteria.getSortType());
        pList.setStartIndex(query.getFirstResult());
        pList.setTotalCount(count);
    }
    return resultList;
}
Also used : Query(javax.persistence.Query) XXPluginInfo(org.apache.ranger.entity.XXPluginInfo)

Example 2 with XXPluginInfo

use of org.apache.ranger.entity.XXPluginInfo 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 XXPluginInfo

use of org.apache.ranger.entity.XXPluginInfo in project ranger by apache.

the class RangerPluginInfoService method populateDBObject.

public XXPluginInfo populateDBObject(RangerPluginInfo modelObj) {
    XXPluginInfo ret = new XXPluginInfo();
    ret.setId(modelObj.getId());
    ret.setCreateTime(modelObj.getCreateTime());
    ret.setUpdateTime(modelObj.getUpdateTime());
    ret.setServiceName(modelObj.getServiceName());
    ret.setHostName(modelObj.getHostName());
    ret.setAppType(modelObj.getAppType());
    ret.setIpAddress(modelObj.getIpAddress());
    ret.setInfo(mapToJsonString(modelObj.getInfo()));
    return ret;
}
Also used : XXPluginInfo(org.apache.ranger.entity.XXPluginInfo)

Example 4 with XXPluginInfo

use of org.apache.ranger.entity.XXPluginInfo 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

XXPluginInfo (org.apache.ranger.entity.XXPluginInfo)4 RangerPluginInfo (org.apache.ranger.plugin.model.RangerPluginInfo)2 ArrayList (java.util.ArrayList)1 Query (javax.persistence.Query)1 XXService (org.apache.ranger.entity.XXService)1 XXServiceVersionInfo (org.apache.ranger.entity.XXServiceVersionInfo)1 PList (org.apache.ranger.plugin.store.PList)1