use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class StateMapSerDe method serializeRecord.
@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());
}
}
}
use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class WriteAheadLocalStateProvider method getProvider.
private ComponentProvider getProvider(final String componentId) {
ComponentProvider componentProvider = componentProviders.get(componentId);
if (componentProvider == null) {
final StateMap stateMap = new StandardStateMap(Collections.<String, String>emptyMap(), -1L);
componentProvider = new ComponentProvider(writeAheadLog, versionGenerator, componentId, stateMap, alwaysSync);
final ComponentProvider existingComponentProvider = componentProviders.putIfAbsent(componentId, componentProvider);
if (existingComponentProvider != null) {
componentProvider = existingComponentProvider;
}
}
return componentProvider;
}
use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class ZooKeeperStateProvider method getState.
@Override
public StateMap getState(final String componentId) throws IOException {
verifyEnabled();
try {
final Stat stat = new Stat();
final String path = getComponentPath(componentId);
final byte[] data = getZooKeeper().getData(path, false, stat);
final StateMap stateMap = deserialize(data, stat.getVersion(), componentId);
return stateMap;
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + ", due to interruption", e);
} catch (final KeeperException ke) {
final Code exceptionCode = ke.code();
if (Code.NONODE == exceptionCode) {
return new StandardStateMap(null, -1L);
}
if (Code.SESSIONEXPIRED == exceptionCode) {
invalidateClient();
return getState(componentId);
}
throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId + " with exception code " + exceptionCode, ke);
} catch (final IOException ioe) {
// provide more context in the error message
throw new IOException("Failed to obtain value from ZooKeeper for component with ID " + componentId, ioe);
}
}
use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class StandardNiFiServiceFacade method getControllerServiceState.
@Override
public ComponentStateDTO getControllerServiceState(final String controllerServiceId) {
final StateMap clusterState = isClustered() ? controllerServiceDAO.getState(controllerServiceId, Scope.CLUSTER) : null;
final StateMap localState = controllerServiceDAO.getState(controllerServiceId, Scope.LOCAL);
// controller service will be non null as it was already found when getting the state
final ControllerServiceNode controllerService = controllerServiceDAO.getControllerService(controllerServiceId);
return dtoFactory.createComponentStateDTO(controllerServiceId, controllerService.getControllerServiceImplementation().getClass(), localState, clusterState);
}
use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class ComponentStateAuditor method clearReportingTaskStateAdvice.
/**
* Audits clearing of state from a Processor.
*
* @param proceedingJoinPoint join point
* @param reportingTask the reporting task
* @throws java.lang.Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.ComponentStateDAO+) && " + "execution(void clearState(org.apache.nifi.controller.ReportingTaskNode)) && " + "args(reportingTask)")
public StateMap clearReportingTaskStateAdvice(ProceedingJoinPoint proceedingJoinPoint, ReportingTaskNode reportingTask) throws Throwable {
// update the reporting task state
final StateMap stateMap = (StateMap) proceedingJoinPoint.proceed();
// if no exception were thrown, add the clear action...
// get the current user
NiFiUser user = NiFiUserUtils.getNiFiUser();
// ensure the user was found
if (user != null) {
Collection<Action> actions = new ArrayList<>();
// create the reporting task details
FlowChangeExtensionDetails reportingTaskDetails = new FlowChangeExtensionDetails();
reportingTaskDetails.setType(reportingTask.getReportingTask().getClass().getSimpleName());
// create the clear action
FlowChangeAction configAction = new FlowChangeAction();
configAction.setUserIdentity(user.getIdentity());
configAction.setOperation(Operation.ClearState);
configAction.setTimestamp(new Date());
configAction.setSourceId(reportingTask.getIdentifier());
configAction.setSourceName(reportingTask.getName());
configAction.setSourceType(Component.ReportingTask);
configAction.setComponentDetails(reportingTaskDetails);
actions.add(configAction);
// record the action
saveActions(actions, logger);
}
return stateMap;
}
Aggregations