use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class ComponentStateAuditor method clearProcessorStateAdvice.
/**
* Audits clearing of state from a Processor.
*
* @param proceedingJoinPoint join point
* @param processor the processor
* @throws java.lang.Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.ComponentStateDAO+) && " + "execution(void clearState(org.apache.nifi.controller.ProcessorNode)) && " + "args(processor)")
public StateMap clearProcessorStateAdvice(ProceedingJoinPoint proceedingJoinPoint, ProcessorNode processor) throws Throwable {
// update the processors 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 processor details
FlowChangeExtensionDetails processorDetails = new FlowChangeExtensionDetails();
processorDetails.setType(processor.getComponentType());
// create the clear action
FlowChangeAction configAction = new FlowChangeAction();
configAction.setUserIdentity(user.getIdentity());
configAction.setOperation(Operation.ClearState);
configAction.setTimestamp(new Date());
configAction.setSourceId(processor.getIdentifier());
configAction.setSourceName(processor.getName());
configAction.setSourceType(Component.Processor);
configAction.setComponentDetails(processorDetails);
actions.add(configAction);
// record the action
saveActions(actions, logger);
}
return stateMap;
}
use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class ComponentStateAuditor method clearControllerServiceStateAdvice.
/**
* Audits clearing of state from a Controller Service.
*
* @param proceedingJoinPoint join point
* @param controllerService the controller service
* @throws java.lang.Throwable ex
*/
@Around("within(org.apache.nifi.web.dao.ComponentStateDAO+) && " + "execution(void clearState(org.apache.nifi.controller.service.ControllerServiceNode)) && " + "args(controllerService)")
public StateMap clearControllerServiceStateAdvice(ProceedingJoinPoint proceedingJoinPoint, ControllerServiceNode controllerService) throws Throwable {
// update the controller service 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 controller service details
FlowChangeExtensionDetails controllerServiceDetails = new FlowChangeExtensionDetails();
controllerServiceDetails.setType(controllerService.getComponentType());
// create the clear action
FlowChangeAction configAction = new FlowChangeAction();
configAction.setUserIdentity(user.getIdentity());
configAction.setOperation(Operation.ClearState);
configAction.setTimestamp(new Date());
configAction.setSourceId(controllerService.getIdentifier());
configAction.setSourceName(controllerService.getName());
configAction.setSourceType(Component.ControllerService);
configAction.setComponentDetails(controllerServiceDetails);
actions.add(configAction);
// record the action
saveActions(actions, logger);
}
return stateMap;
}
use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class AbstractTestStateProvider method testToMap.
@Test
public void testToMap() throws IOException {
final String key = "testKeySet";
final StateProvider provider = getProvider();
Map<String, String> map = provider.getState(componentId).toMap();
assertNotNull(map);
assertTrue(map.isEmpty());
provider.setState(Collections.singletonMap(key, "value"), componentId);
map = provider.getState(componentId).toMap();
assertNotNull(map);
assertEquals(1, map.size());
assertEquals("value", map.get(key));
provider.setState(Collections.<String, String>emptyMap(), componentId);
final StateMap stateMap = provider.getState(componentId);
map = stateMap.toMap();
assertNotNull(map);
assertTrue(map.isEmpty());
assertEquals(1, stateMap.getVersion());
}
use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class AbstractTestStateProvider method testReplaceSuccessful.
@Test
public void testReplaceSuccessful() throws IOException {
final String key = "testReplaceSuccessful";
final StateProvider provider = getProvider();
StateMap map = provider.getState(componentId);
assertNotNull(map);
assertEquals(-1, map.getVersion());
assertNotNull(map.toMap());
assertTrue(map.toMap().isEmpty());
provider.setState(Collections.singletonMap(key, "value1"), componentId);
map = provider.getState(componentId);
assertNotNull(map);
assertEquals(0, map.getVersion());
assertEquals("value1", map.get(key));
assertEquals("value1", map.toMap().get(key));
final Map<String, String> newMap = new HashMap<>(map.toMap());
newMap.put(key, "value2");
assertTrue(provider.replace(map, newMap, componentId));
map = provider.getState(componentId);
assertEquals("value2", map.get(key));
assertEquals(1L, map.getVersion());
}
use of org.apache.nifi.components.state.StateMap in project nifi by apache.
the class StandardStateManager method getState.
@Override
public StateMap getState(final Scope scope) throws IOException {
final StateMap stateMap = getProvider(scope).getState(componentId);
getLogger(componentId).debug("Returning {} State: {}", new Object[] { scope, stateMap });
return stateMap;
}
Aggregations