Search in sources :

Example 1 with XXDataHist

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

the class RangerDataHistService method createObjectDataHistory.

public void createObjectDataHistory(RangerBaseModelObject baseModelObj, String action) {
    if (baseModelObj == null || action == null) {
        throw restErrorUtil.createRESTException("Error while creating DataHistory. " + "Object or Action can not be null.", MessageEnums.DATA_NOT_FOUND);
    }
    Integer classType = null;
    String objectName = null;
    String content = null;
    Long objectId = baseModelObj.getId();
    String objectGuid = baseModelObj.getGuid();
    Date currentDate = DateUtil.getUTCDate();
    XXDataHist xDataHist = new XXDataHist();
    xDataHist.setObjectId(baseModelObj.getId());
    xDataHist.setObjectGuid(objectGuid);
    xDataHist.setCreateTime(currentDate);
    xDataHist.setAction(action);
    xDataHist.setVersion(baseModelObj.getVersion());
    xDataHist.setUpdateTime(currentDate);
    xDataHist.setFromTime(currentDate);
    if (baseModelObj instanceof RangerServiceDef) {
        RangerServiceDef serviceDef = (RangerServiceDef) baseModelObj;
        objectName = serviceDef.getName();
        classType = AppConstants.CLASS_TYPE_XA_SERVICE_DEF;
        content = writeObjectAsString(serviceDef);
    } else if (baseModelObj instanceof RangerService) {
        RangerService service = (RangerService) baseModelObj;
        objectName = service.getName();
        classType = AppConstants.CLASS_TYPE_XA_SERVICE;
        content = writeObjectAsString(service);
    } else if (baseModelObj instanceof RangerPolicy) {
        RangerPolicy policy = (RangerPolicy) baseModelObj;
        objectName = policy.getName();
        classType = AppConstants.CLASS_TYPE_RANGER_POLICY;
        XXService xXService = daoMgr.getXXService().findByName(policy.getService());
        XXServiceDef xxServiceDef = null;
        if (xXService != null) {
            xxServiceDef = daoMgr.getXXServiceDef().getById(xXService.getType());
        }
        if (xxServiceDef != null) {
            policy.setServiceType(xxServiceDef.getName());
        }
        content = writeObjectAsString(policy);
    }
    xDataHist.setObjectClassType(classType);
    xDataHist.setObjectName(objectName);
    xDataHist.setContent(content);
    xDataHist = daoMgr.getXXDataHist().create(xDataHist);
    if (ACTION_UPDATE.equalsIgnoreCase(action) || ACTION_DELETE.equalsIgnoreCase(action)) {
        XXDataHist prevHist = daoMgr.getXXDataHist().findLatestByObjectClassTypeAndObjectId(classType, objectId);
        if (prevHist == null) {
            throw restErrorUtil.createRESTException("Error updating DataHistory Object. ObjectName: " + objectName, MessageEnums.DATA_NOT_UPDATABLE);
        }
        prevHist.setUpdateTime(currentDate);
        prevHist.setToTime(currentDate);
        prevHist.setObjectName(objectName);
        prevHist = daoMgr.getXXDataHist().update(prevHist);
    }
}
Also used : XXDataHist(org.apache.ranger.entity.XXDataHist) XXServiceDef(org.apache.ranger.entity.XXServiceDef) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) RangerServiceDef(org.apache.ranger.plugin.model.RangerServiceDef) RangerService(org.apache.ranger.plugin.model.RangerService) XXService(org.apache.ranger.entity.XXService) Date(java.util.Date)

Example 2 with XXDataHist

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

the class ServiceDBStore method getPolicyFromEventTime.

public RangerPolicy getPolicyFromEventTime(String eventTime, Long policyId) {
    XXDataHist xDataHist = daoMgr.getXXDataHist().findObjByEventTimeClassTypeAndId(eventTime, AppConstants.CLASS_TYPE_RANGER_POLICY, policyId);
    if (xDataHist == null) {
        String errMsg = "No policy history found for given time: " + eventTime;
        LOG.error(errMsg);
        throw restErrorUtil.createRESTException(errMsg, MessageEnums.DATA_NOT_FOUND);
    }
    String content = xDataHist.getContent();
    RangerPolicy policy = (RangerPolicy) dataHistService.writeJsonToJavaObject(content, RangerPolicy.class);
    return policy;
}
Also used : XXDataHist(org.apache.ranger.entity.XXDataHist) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXString(org.apache.ranger.view.VXString)

Example 3 with XXDataHist

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

the class ServiceDBStore method getPolicyForVersionNumber.

public RangerPolicy getPolicyForVersionNumber(Long policyId, int versionNo) {
    XXDataHist xDataHist = daoMgr.getXXDataHist().findObjectByVersionNumber(policyId, AppConstants.CLASS_TYPE_RANGER_POLICY, versionNo);
    if (xDataHist == null) {
        throw restErrorUtil.createRESTException("No Policy found for given version.", MessageEnums.DATA_NOT_FOUND);
    }
    String content = xDataHist.getContent();
    RangerPolicy policy = (RangerPolicy) dataHistService.writeJsonToJavaObject(content, RangerPolicy.class);
    return policy;
}
Also used : XXDataHist(org.apache.ranger.entity.XXDataHist) RangerPolicy(org.apache.ranger.plugin.model.RangerPolicy) VXString(org.apache.ranger.view.VXString)

Aggregations

XXDataHist (org.apache.ranger.entity.XXDataHist)3 RangerPolicy (org.apache.ranger.plugin.model.RangerPolicy)3 VXString (org.apache.ranger.view.VXString)2 Date (java.util.Date)1 XXService (org.apache.ranger.entity.XXService)1 XXServiceDef (org.apache.ranger.entity.XXServiceDef)1 RangerService (org.apache.ranger.plugin.model.RangerService)1 RangerServiceDef (org.apache.ranger.plugin.model.RangerServiceDef)1