public Object getFieldValue(_Fields field) { switch (field) { case HAS_FULL_IMAGE: return Boolean.valueOf(isHasFullImage()); case PATHS_DUMP: return getPathsDump(); case SEQ_NUM: return Long.valueOf(getSeqNum()); case PATH_CHANGES: return getPathChanges(); } throw new IllegalStateException(); }
case HAS_FULL_IMAGE: if (value == null) { unsetHasFullImage(); } else { setHasFullImage((Boolean)value); unsetPathsDump(); } else { setPathsDump((TPathsDump)value); unsetSeqNum(); } else { setSeqNum((Long)value); unsetPathChanges(); } else { setPathChanges((List<TPathChanges>)value);
@Override public void read(org.apache.thrift.protocol.TProtocol prot, handle_hms_notification_args struct) throws org.apache.thrift.TException { TTupleProtocol iprot = (TTupleProtocol) prot; BitSet incoming = iprot.readBitSet(1); if (incoming.get(0)) { struct.pathsUpdate = new TPathsUpdate(); struct.pathsUpdate.read(iprot); struct.setPathsUpdateIsSet(true); } } }
/** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ public boolean isSet(_Fields field) { if (field == null) { throw new IllegalArgumentException(); } switch (field) { case HAS_FULL_IMAGE: return isSetHasFullImage(); case PATHS_DUMP: return isSetPathsDump(); case SEQ_NUM: return isSetSeqNum(); case PATH_CHANGES: return isSetPathChanges(); } throw new IllegalStateException(); }
@Override public UpdateableAuthzPaths updateFull(PathsUpdate update) { UpdateableAuthzPaths other = getPathsDump().initializeFromDump( update.toThrift().getPathsDump()); other.seqNum.set(update.getSeqNum()); return other; }
public void validate() throws org.apache.thrift.TException { // check for required fields if (!isSetHasFullImage()) { throw new org.apache.thrift.protocol.TProtocolException("Required field 'hasFullImage' is unset! Struct:" + toString()); } if (!isSetSeqNum()) { throw new org.apache.thrift.protocol.TProtocolException("Required field 'seqNum' is unset! Struct:" + toString()); } if (!isSetPathChanges()) { throw new org.apache.thrift.protocol.TProtocolException("Required field 'pathChanges' is unset! Struct:" + toString()); } // check for sub-struct validity if (pathsDump != null) { pathsDump.validate(); } }
@Override public void handle_hms_notification(TPathsUpdate update) throws TException { final Timer.Context timerContext = SentryHdfsMetricsUtil.getHandleHmsNotificationTimer.time(); try { PathsUpdate hmsUpdate = new PathsUpdate(update); if (SentryPlugin.instance != null) { SentryPlugin.instance.handlePathUpdateNotification(hmsUpdate); LOGGER.debug("Authz Paths update [" + hmsUpdate.getSeqNum() + "].."); } else { LOGGER.error("SentryPlugin not initialized yet !!"); } } catch (Exception e) { LOGGER.error("Error handling notification from HMS", e); SentryHdfsMetricsUtil.getFailedHandleHmsNotificationCounter.inc(); throw new TException(e); } finally { timerContext.stop(); SentryHdfsMetricsUtil.getHandleHmsPathChangeHistogram.update( update.getPathChangesSize()); if (update.isHasFullImage()) { SentryHdfsMetricsUtil.getHandleHmsHasFullImageCounter.inc(); } } }
@Override public PathsUpdate createFullImageUpdate(long currSeqNum) { PathsUpdate pathsUpdate = new PathsUpdate(currSeqNum, true); pathsUpdate.toThrift().setPathsDump(getPathsDump().createPathsDump()); return pathsUpdate; }
@Override public boolean hasFullImage() { return tPathsUpdate.isHasFullImage(); }
public TPathsUpdate deepCopy() { return new TPathsUpdate(this); }
@Override public boolean equals(Object that) { if (that == null) return false; if (that instanceof TPathsUpdate) return this.equals((TPathsUpdate)that); return false; }
@Override public long getSeqNum() { return tPathsUpdate.getSeqNum(); }
public List<TPathChanges> getPathChanges() { return tPathsUpdate.getPathChanges(); }
public TPathChanges newPathChange(String authzObject) { TPathChanges pathChanges = new TPathChanges(authzObject, new LinkedList<List<String>>(), new LinkedList<List<String>>()); tPathsUpdate.addToPathChanges(pathChanges); return pathChanges; }
/** * Test retrieveFullPathsImageUpdate() when no image is present. * @throws Exception */ @Test public void testRetrieveEmptyPathImage() throws Exception { String[] prefixes = {}; PathsUpdate pathsUpdate = sentryStore.retrieveFullPathsImageUpdate(prefixes); TPathsUpdate tPathsUpdate = pathsUpdate.toThrift(); TPathsDump pathDump = tPathsUpdate.getPathsDump(); Map<Integer, TPathEntry> nodeMap = pathDump.getNodeMap(); assertEquals(1, nodeMap.size()); System.out.printf(nodeMap.toString()); }
lastComparison = Boolean.valueOf(isSetHasFullImage()).compareTo(typedOther.isSetHasFullImage()); if (lastComparison != 0) { return lastComparison; if (isSetHasFullImage()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.hasFullImage, typedOther.hasFullImage); if (lastComparison != 0) { lastComparison = Boolean.valueOf(isSetPathsDump()).compareTo(typedOther.isSetPathsDump()); if (lastComparison != 0) { return lastComparison; if (isSetPathsDump()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.pathsDump, typedOther.pathsDump); if (lastComparison != 0) { lastComparison = Boolean.valueOf(isSetSeqNum()).compareTo(typedOther.isSetSeqNum()); if (lastComparison != 0) { return lastComparison; if (isSetSeqNum()) { lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.seqNum, typedOther.seqNum); if (lastComparison != 0) { lastComparison = Boolean.valueOf(isSetPathChanges()).compareTo(typedOther.isSetPathChanges()); if (lastComparison != 0) { return lastComparison; if (isSetPathChanges()) {
/** * Retrieves an up-to-date hive paths snapshot. * The image only contains PathsDump in it. * <p> * It reads hiveObj to paths mapping from {@link MAuthzPathsMapping} table and * gets the changeID of latest delta update, from {@link MSentryPathChange}, that * the snapshot corresponds to. * * @param prefixes path of Sentry managed prefixes. Ignore any path outside the prefix. * @return an up-to-date hive paths snapshot contains mapping of hiveObj to < Paths >. * For empty image return * {@link org.apache.sentry.core.common.utils.SentryConstants#EMPTY_CHANGE_ID} * and a empty map. * @throws Exception */ public PathsUpdate retrieveFullPathsImageUpdate(final String[] prefixes) throws Exception { return tm.executeTransaction( pm -> { pm.setDetachAllOnCommit(false); // No need to detach objects long curImageID = getCurrentAuthzPathsSnapshotID(pm); long curChangeID = getLastProcessedChangeIDCore(pm, MSentryPathChange.class); PathsUpdate pathUpdate = new PathsUpdate(curChangeID, curImageID, true); // We ignore anything in the update and set it later to the assembled PathsDump UpdateableAuthzPaths authzPaths = new UpdateableAuthzPaths(prefixes); // Extract all paths and put them into authzPaths retrieveFullPathsImageCore(pm, curImageID, authzPaths); pathUpdate.toThrift().setPathsDump(authzPaths.getPathsDump().createPathsDump(true)); return pathUpdate; }); }
public PathsUpdate(long seqNum, boolean hasFullImage) { tPathsUpdate = new TPathsUpdate(hasFullImage, seqNum, new LinkedList<TPathChanges>()); }
public boolean equals(handle_hms_notification_args that) { if (that == null) return false; boolean this_present_pathsUpdate = true && this.isSetPathsUpdate(); boolean that_present_pathsUpdate = true && that.isSetPathsUpdate(); if (this_present_pathsUpdate || that_present_pathsUpdate) { if (!(this_present_pathsUpdate && that_present_pathsUpdate)) return false; if (!this.pathsUpdate.equals(that.pathsUpdate)) return false; } return true; }
assertEquals(notificationID, pathsUpdate.getImgNum()); TPathsUpdate tPathsUpdate = pathsUpdate.toThrift(); TPathsDump pathDump = tPathsUpdate.getPathsDump(); Map<Integer, TPathEntry> nodeMap = pathDump.getNodeMap(); System.out.printf(nodeMap.toString());