Java Code Examples for org.apache.nifi.components.state.StateMap#getVersion()

The following examples show how to use org.apache.nifi.components.state.StateMap#getVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GetSplunk.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
private TimeRange loadState(StateManager stateManager) throws IOException {
    final StateMap stateMap = stateManager.getState(Scope.CLUSTER);

    if (stateMap.getVersion() < 0) {
        getLogger().debug("No previous state found");
        return null;
    }

    final String earliest = stateMap.get(EARLIEST_TIME_KEY);
    final String latest = stateMap.get(LATEST_TIME_KEY);
    getLogger().debug("Loaded state with earliestTime of {} and latestTime of {}", new Object[] {earliest, latest});

    if (StringUtils.isBlank(earliest) && StringUtils.isBlank(latest)) {
        return null;
    } else {
        return new TimeRange(earliest, latest);
    }
}
 
Example 2
Source File: GetSplunk.java    From nifi with Apache License 2.0 6 votes vote down vote up
private TimeRange loadState(StateManager stateManager) throws IOException {
    final StateMap stateMap = stateManager.getState(Scope.CLUSTER);

    if (stateMap.getVersion() < 0) {
        getLogger().debug("No previous state found");
        return null;
    }

    final String earliest = stateMap.get(EARLIEST_TIME_KEY);
    final String latest = stateMap.get(LATEST_TIME_KEY);
    getLogger().debug("Loaded state with earliestTime of {} and latestTime of {}", new Object[] {earliest, latest});

    if (StringUtils.isBlank(earliest) && StringUtils.isBlank(latest)) {
        return null;
    } else {
        return new TimeRange(earliest, latest);
    }
}
 
Example 3
Source File: AbstractListProcessor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public final void updateState(final ProcessContext context) throws IOException {
    final String path = getPath(context);
    final DistributedMapCacheClient client = context.getProperty(DISTRIBUTED_CACHE_SERVICE).asControllerService(DistributedMapCacheClient.class);

    // Check if state already exists for this path. If so, we have already migrated the state.
    final StateMap stateMap = context.getStateManager().getState(getStateScope(context));
    if (stateMap.getVersion() == -1L) {
        try {
            // Migrate state from the old way of managing state (distributed cache service and local file)
            // to the new mechanism (State Manager).
            migrateState(path, client, context.getStateManager(), getStateScope(context));
        } catch (final IOException ioe) {
            throw new IOException("Failed to properly migrate state to State Manager", ioe);
        }
    }

    // When scheduled to run, check if the associated timestamp is null, signifying a clearing of state and reset the internal timestamp
    if (lastListingTime != null && stateMap.get(LISTING_TIMESTAMP_KEY) == null) {
        getLogger().info("Detected that state was cleared for this component.  Resetting internal values.");
        resetTimeStates();
    }

    if (resetState) {
        context.getStateManager().clear(getStateScope(context));
        resetState = false;
    }
}
 
Example 4
Source File: ListGCSBucket.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
void restoreState(final ProcessContext context) throws IOException {
    final StateMap stateMap = context.getStateManager().getState(Scope.CLUSTER);
    if (stateMap.getVersion() == -1L || stateMap.get(CURRENT_TIMESTAMP) == null || stateMap.get(CURRENT_KEY_PREFIX+"0") == null) {
        currentTimestamp = 0L;
        currentKeys = new HashSet<>();
    } else {
        currentTimestamp = Long.parseLong(stateMap.get(CURRENT_TIMESTAMP));
        currentKeys = extractKeys(stateMap);
    }
}
 
Example 5
Source File: GetHBase.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private ScanResult getState(final StateManager stateManager) throws IOException {
    final StateMap stateMap = stateManager.getState(Scope.CLUSTER);
    if (stateMap.getVersion() < 0) {
        return null;
    }

    return ScanResult.fromFlatMap(stateMap.toMap());
}
 
Example 6
Source File: StateMapSerDe.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeRecord(final StateMapUpdate record, final DataOutputStream out) throws IOException {
    out.writeUTF(record.getComponentId());
    out.writeUTF(record.getUpdateType().name());
    if (record.getUpdateType() == UpdateType.DELETE) {
        return;
    }

    final StateMap stateMap = record.getStateMap();
    final long recordVersion = stateMap.getVersion();
    out.writeLong(recordVersion);

    final Map<String, String> map = stateMap.toMap();
    out.writeInt(map.size());
    for (final Map.Entry<String, String> entry : map.entrySet()) {
        final boolean hasKey = entry.getKey() != null;
        final boolean hasValue = entry.getValue() != null;
        out.writeBoolean(hasKey);
        if (hasKey) {
            out.writeUTF(entry.getKey());
        }

        out.writeBoolean(hasValue);
        if (hasValue) {
            out.writeUTF(entry.getValue());
        }
    }
}
 
Example 7
Source File: ScrollElasticsearchHttp.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private String loadScrollId(StateManager stateManager) throws IOException {
    final StateMap stateMap = stateManager.getState(Scope.LOCAL);

    if (stateMap.getVersion() < 0) {
        getLogger().debug("No previous state found");
        return null;
    }

    final String scrollId = stateMap.get(SCROLL_ID_STATE);
    getLogger().debug("Loaded state with scrollId {}", new Object[] { scrollId });

    return scrollId;
}
 
Example 8
Source File: ListS3.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
private void restoreState(final ProcessContext context) throws IOException {
    final StateMap stateMap = context.getStateManager().getState(Scope.CLUSTER);
    if (stateMap.getVersion() == -1L || stateMap.get(CURRENT_TIMESTAMP) == null || stateMap.get(CURRENT_KEY_PREFIX+"0") == null) {
        currentTimestamp = 0L;
        currentKeys = new HashSet<>();
    } else {
        currentTimestamp = Long.parseLong(stateMap.get(CURRENT_TIMESTAMP));
        currentKeys = extractKeys(stateMap);
    }
}
 
Example 9
Source File: AbstractListProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
@OnScheduled
public final void updateState(final ProcessContext context) throws IOException {
    final String path = getPath(context);
    final DistributedMapCacheClient client = context.getProperty(DISTRIBUTED_CACHE_SERVICE).asControllerService(DistributedMapCacheClient.class);

    // Check if state already exists for this path. If so, we have already migrated the state.
    final StateMap stateMap = context.getStateManager().getState(getStateScope(context));
    if (stateMap.getVersion() == -1L) {
        try {
            // Migrate state from the old way of managing state (distributed cache service and local file)
            // to the new mechanism (State Manager).
            migrateState(path, client, context.getStateManager(), getStateScope(context));
        } catch (final IOException ioe) {
            throw new IOException("Failed to properly migrate state to State Manager", ioe);
        }
    }

    // When scheduled to run, check if the associated timestamp is null, signifying a clearing of state and reset the internal timestamp
    if (lastListedLatestEntryTimestampMillis != null && stateMap.get(LATEST_LISTED_ENTRY_TIMESTAMP_KEY) == null) {
        getLogger().info("Detected that state was cleared for this component.  Resetting internal values.");
        resetTimeStates();
    }

    if (resetState) {
        context.getStateManager().clear(getStateScope(context));
        resetState = false;
    }
}
 
Example 10
Source File: ListGCSBucket.java    From nifi with Apache License 2.0 5 votes vote down vote up
void restoreState(final ProcessContext context) throws IOException {
    final StateMap stateMap = context.getStateManager().getState(Scope.CLUSTER);
    if (stateMap.getVersion() == -1L || stateMap.get(CURRENT_TIMESTAMP) == null || stateMap.get(CURRENT_KEY_PREFIX+"0") == null) {
        currentTimestamp = 0L;
        currentKeys.clear();
    } else {
        currentTimestamp = Long.parseLong(stateMap.get(CURRENT_TIMESTAMP));
        currentKeys.clear();
        currentKeys.addAll(extractKeys(stateMap));
    }
}
 
Example 11
Source File: GetHBase.java    From nifi with Apache License 2.0 5 votes vote down vote up
private ScanResult getState(final StateManager stateManager) throws IOException {
    final StateMap stateMap = stateManager.getState(Scope.CLUSTER);
    if (stateMap.getVersion() < 0) {
        return null;
    }

    return ScanResult.fromFlatMap(stateMap.toMap());
}
 
Example 12
Source File: StateMapSerDe.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Override
public void serializeRecord(final StateMapUpdate record, final DataOutputStream out) throws IOException {
    out.writeUTF(record.getComponentId());
    out.writeUTF(record.getUpdateType().name());
    if (record.getUpdateType() == UpdateType.DELETE) {
        return;
    }

    final StateMap stateMap = record.getStateMap();
    final long recordVersion = stateMap.getVersion();
    out.writeLong(recordVersion);

    final Map<String, String> map = stateMap.toMap();
    out.writeInt(map.size());
    for (final Map.Entry<String, String> entry : map.entrySet()) {
        final boolean hasKey = entry.getKey() != null;
        final boolean hasValue = entry.getValue() != null;
        out.writeBoolean(hasKey);
        if (hasKey) {
            out.writeUTF(entry.getKey());
        }

        out.writeBoolean(hasValue);
        if (hasValue) {
            out.writeUTF(entry.getValue());
        }
    }
}
 
Example 13
Source File: ScrollElasticsearchHttp.java    From nifi with Apache License 2.0 5 votes vote down vote up
private String loadScrollId(StateManager stateManager) throws IOException {
    final StateMap stateMap = stateManager.getState(Scope.LOCAL);

    if (stateMap.getVersion() < 0) {
        getLogger().debug("No previous state found");
        return null;
    }

    final String scrollId = stateMap.get(SCROLL_ID_STATE);
    getLogger().debug("Loaded state with scrollId {}", new Object[] { scrollId });

    return scrollId;
}
 
Example 14
Source File: ListS3.java    From nifi with Apache License 2.0 5 votes vote down vote up
private void restoreState(final ProcessContext context) throws IOException {
    final StateMap stateMap = context.getStateManager().getState(Scope.CLUSTER);
    if (stateMap.getVersion() == -1L || stateMap.get(CURRENT_TIMESTAMP) == null || stateMap.get(CURRENT_KEY_PREFIX+"0") == null) {
        currentTimestamp = 0L;
        currentKeys = new HashSet<>();
    } else {
        currentTimestamp = Long.parseLong(stateMap.get(CURRENT_TIMESTAMP));
        currentKeys = extractKeys(stateMap);
    }
}