use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class UserGroupEntityMerger method mergeComponents.
/**
* Merges the UserGroupEntity responses.
*
* @param clientEntity the entity being returned to the client
* @param entityMap all node responses
*/
public void mergeComponents(final UserGroupEntity clientEntity, final Map<NodeIdentifier, UserGroupEntity> entityMap) {
final UserGroupDTO clientDto = clientEntity.getComponent();
final Map<NodeIdentifier, UserGroupDTO> dtoMap = new HashMap<>();
for (final Map.Entry<NodeIdentifier, UserGroupEntity> entry : entityMap.entrySet()) {
final UserGroupEntity nodeUserGroupEntity = entry.getValue();
final UserGroupDTO nodeUserGroupDto = nodeUserGroupEntity.getComponent();
dtoMap.put(entry.getKey(), nodeUserGroupDto);
}
mergeDtos(clientDto, dtoMap);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class UserGroupEntityMerger method mergeDtos.
private static void mergeDtos(final UserGroupDTO clientDto, final Map<NodeIdentifier, UserGroupDTO> dtoMap) {
// if unauthorized for the client dto, simple return
if (clientDto == null) {
return;
}
final Set<AccessPolicyEntity> accessPolicyEntities = new HashSet<>(clientDto.getAccessPolicies());
final Set<TenantEntity> userEntities = new HashSet<>(clientDto.getUsers());
for (final Map.Entry<NodeIdentifier, UserGroupDTO> nodeEntry : dtoMap.entrySet()) {
final UserGroupDTO nodeUserGroup = nodeEntry.getValue();
if (nodeUserGroup != null) {
accessPolicyEntities.retainAll(nodeUserGroup.getAccessPolicies());
userEntities.retainAll(nodeUserGroup.getUsers());
}
}
clientDto.setAccessPolicies(accessPolicyEntities);
clientDto.setUsers(userEntities);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class TestAbstractHeartbeatMonitor method setup.
@Before
public void setup() throws Exception {
System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, "src/test/resources/conf/nifi.properties");
nodeId = new NodeIdentifier(UUID.randomUUID().toString(), "localhost", 9999, "localhost", 8888, "localhost", null, null, false);
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class TestAbstractHeartbeatMonitor method testDisconnectionOfTerminatedNodeDueToLackOfHeartbeat.
@Test
public void testDisconnectionOfTerminatedNodeDueToLackOfHeartbeat() throws Exception {
final NodeIdentifier nodeId1 = nodeId;
final NodeIdentifier nodeId2 = new NodeIdentifier(UUID.randomUUID().toString(), "localhost", 7777, "localhost", 6666, "localhost", null, null, false);
final ClusterCoordinatorAdapter adapter = new ClusterCoordinatorAdapter();
final TestFriendlyHeartbeatMonitor monitor = createMonitor(adapter);
// set state to connecting
adapter.requestNodeConnect(nodeId1);
adapter.requestNodeConnect(nodeId2);
// ensure each node is connected
assertTrue(adapter.getNodeIdentifiers(NodeConnectionState.CONNECTING).containsAll(Arrays.asList(nodeId1, nodeId2)));
// let each node heartbeat in
monitor.addHeartbeat(createHeartbeat(nodeId1, NodeConnectionState.CONNECTED));
monitor.addHeartbeat(createHeartbeat(nodeId2, NodeConnectionState.CONNECTED));
monitor.waitForProcessed();
// ensure each node is now connected
assertTrue(adapter.getNodeIdentifiers(NodeConnectionState.CONNECTED).containsAll(Arrays.asList(nodeId1, nodeId2)));
// purge the heartbeats, simulate nodeId2 termination by only having a nodeId1 heartbeat be present
monitor.purgeHeartbeats();
monitor.addHeartbeat(createHeartbeat(nodeId1, NodeConnectionState.CONNECTED));
monitor.waitForProcessed();
// the node that did not heartbeat in should be disconnected
assertTrue(adapter.getNodeIdentifiers(NodeConnectionState.CONNECTED).contains(nodeId1));
assertTrue(adapter.getNodeIdentifiers(NodeConnectionState.DISCONNECTED).contains(nodeId2));
}
use of org.apache.nifi.cluster.protocol.NodeIdentifier in project nifi by apache.
the class CurrentUserEndpointMergerTest method testMergeUserPermissions.
@Test
public void testMergeUserPermissions() {
final NodeIdentifier nodeId1 = new NodeIdentifier("1", "localhost", 9000, "localhost", 9001, "localhost", 9002, 9003, false);
final CurrentUserEntity userNode1 = new CurrentUserEntity();
userNode1.setControllerPermissions(buildPermissions(true, false));
userNode1.setCountersPermissions(buildPermissions(true, true));
userNode1.setPoliciesPermissions(buildPermissions(true, true));
userNode1.setProvenancePermissions(buildPermissions(false, false));
userNode1.setRestrictedComponentsPermissions(buildPermissions(false, false));
userNode1.setSystemPermissions(buildPermissions(true, true));
userNode1.setTenantsPermissions(buildPermissions(false, true));
final Set<ComponentRestrictionPermissionDTO> componentRestrictionsNode1 = new HashSet<>();
componentRestrictionsNode1.add(buildComponentRestriction(RequiredPermission.ACCESS_KEYTAB, true, true));
componentRestrictionsNode1.add(buildComponentRestriction(RequiredPermission.WRITE_FILESYSTEM, false, true));
componentRestrictionsNode1.add(buildComponentRestriction(RequiredPermission.READ_FILESYSTEM, true, true));
userNode1.setComponentRestrictionPermissions(componentRestrictionsNode1);
final NodeIdentifier nodeId2 = new NodeIdentifier("2", "localhost", 8000, "localhost", 8001, "localhost", 8002, 8003, false);
final CurrentUserEntity userNode2 = new CurrentUserEntity();
userNode2.setControllerPermissions(buildPermissions(false, true));
userNode2.setCountersPermissions(buildPermissions(true, false));
userNode2.setPoliciesPermissions(buildPermissions(true, true));
userNode2.setProvenancePermissions(buildPermissions(false, false));
userNode2.setRestrictedComponentsPermissions(buildPermissions(true, true));
userNode2.setSystemPermissions(buildPermissions(false, false));
userNode2.setTenantsPermissions(buildPermissions(true, true));
final Set<ComponentRestrictionPermissionDTO> componentRestrictionsNode2 = new HashSet<>();
componentRestrictionsNode2.add(buildComponentRestriction(RequiredPermission.ACCESS_KEYTAB, true, false));
componentRestrictionsNode2.add(buildComponentRestriction(RequiredPermission.WRITE_FILESYSTEM, true, false));
componentRestrictionsNode2.add(buildComponentRestriction(RequiredPermission.EXECUTE_CODE, true, true));
userNode2.setComponentRestrictionPermissions(componentRestrictionsNode2);
final Map<NodeIdentifier, CurrentUserEntity> entityMap = new HashMap<>();
entityMap.put(nodeId1, userNode1);
entityMap.put(nodeId2, userNode2);
final CurrentUserEndpointMerger merger = new CurrentUserEndpointMerger();
merger.mergeResponses(userNode1, entityMap, Collections.emptySet(), Collections.emptySet());
assertFalse(userNode1.getControllerPermissions().getCanRead());
assertFalse(userNode1.getControllerPermissions().getCanWrite());
assertTrue(userNode1.getCountersPermissions().getCanRead());
assertFalse(userNode1.getCountersPermissions().getCanWrite());
assertTrue(userNode1.getPoliciesPermissions().getCanRead());
assertTrue(userNode1.getPoliciesPermissions().getCanWrite());
assertFalse(userNode1.getProvenancePermissions().getCanRead());
assertFalse(userNode1.getProvenancePermissions().getCanWrite());
assertFalse(userNode1.getRestrictedComponentsPermissions().getCanRead());
assertFalse(userNode1.getRestrictedComponentsPermissions().getCanWrite());
assertFalse(userNode1.getSystemPermissions().getCanRead());
assertFalse(userNode1.getSystemPermissions().getCanWrite());
assertFalse(userNode1.getTenantsPermissions().getCanRead());
assertTrue(userNode1.getTenantsPermissions().getCanWrite());
userNode1.getComponentRestrictionPermissions().forEach(componentRestriction -> {
if (RequiredPermission.ACCESS_KEYTAB.getPermissionIdentifier().equals(componentRestriction.getRequiredPermission().getId())) {
assertTrue(componentRestriction.getPermissions().getCanRead());
assertFalse(componentRestriction.getPermissions().getCanWrite());
} else if (RequiredPermission.WRITE_FILESYSTEM.getPermissionIdentifier().equals(componentRestriction.getRequiredPermission().getId())) {
assertFalse(componentRestriction.getPermissions().getCanRead());
assertFalse(componentRestriction.getPermissions().getCanWrite());
} else {
fail();
}
});
}
Aggregations