Search in sources :

Example 31 with NodeIdentifier

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);
}
Also used : HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) UserGroupDTO(org.apache.nifi.web.api.dto.UserGroupDTO) UserGroupEntity(org.apache.nifi.web.api.entity.UserGroupEntity) Map(java.util.Map) HashMap(java.util.HashMap)

Example 32 with NodeIdentifier

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);
}
Also used : TenantEntity(org.apache.nifi.web.api.entity.TenantEntity) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) UserGroupDTO(org.apache.nifi.web.api.dto.UserGroupDTO) Map(java.util.Map) HashMap(java.util.HashMap) AccessPolicyEntity(org.apache.nifi.web.api.entity.AccessPolicyEntity) HashSet(java.util.HashSet)

Example 33 with NodeIdentifier

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);
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Before(org.junit.Before)

Example 34 with NodeIdentifier

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));
}
Also used : NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) Test(org.junit.Test)

Example 35 with NodeIdentifier

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();
        }
    });
}
Also used : ComponentRestrictionPermissionDTO(org.apache.nifi.web.api.dto.ComponentRestrictionPermissionDTO) HashMap(java.util.HashMap) NodeIdentifier(org.apache.nifi.cluster.protocol.NodeIdentifier) CurrentUserEntity(org.apache.nifi.web.api.entity.CurrentUserEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

NodeIdentifier (org.apache.nifi.cluster.protocol.NodeIdentifier)141 HashMap (java.util.HashMap)72 Map (java.util.Map)71 NodeResponse (org.apache.nifi.cluster.manager.NodeResponse)42 Test (org.junit.Test)34 Set (java.util.Set)30 URI (java.net.URI)26 HashSet (java.util.HashSet)26 ArrayList (java.util.ArrayList)24 List (java.util.List)18 ClusterCoordinator (org.apache.nifi.cluster.coordination.ClusterCoordinator)15 ProcessorEntity (org.apache.nifi.web.api.entity.ProcessorEntity)15 NodeConnectionStatus (org.apache.nifi.cluster.coordination.node.NodeConnectionStatus)14 NiFiProperties (org.apache.nifi.util.NiFiProperties)11 Collections (java.util.Collections)10 Pattern (java.util.regex.Pattern)10 NiFiUserDetails (org.apache.nifi.authorization.user.NiFiUserDetails)10 NiFiAuthenticationToken (org.apache.nifi.web.security.token.NiFiAuthenticationToken)10 Authentication (org.springframework.security.core.Authentication)10 Response (javax.ws.rs.core.Response)9