Search in sources :

Example 1 with NodeValidationFailedEvent

use of org.apache.ignite.events.NodeValidationFailedEvent in project ignite by apache.

the class IgniteNodeValidationFailedEventTest method testNodeValidationFailedEvent.

/**
 */
@Test
public void testNodeValidationFailedEvent() throws Exception {
    startGrid(0);
    CountDownLatch evtLatch = new CountDownLatch(1);
    AtomicReference<Event> listenedEvtRef = new AtomicReference<>();
    grid(0).events().localListen(evt -> {
        assertTrue(listenedEvtRef.compareAndSet(null, evt));
        evtLatch.countDown();
        return true;
    }, EVT_NODE_VALIDATION_FAILED);
    startGrid(1);
    String invalidNodeName = getTestIgniteInstanceName(2);
    IgniteConfiguration invalidCfg = getConfiguration(invalidNodeName).setPluginProviders(new TestSecurityPluginProvider("login", "", ALLOW_ALL, false));
    assertThrowsWithCause(() -> startGrid(optimize(invalidCfg)), IgniteSpiException.class);
    evtLatch.await();
    Event listenedEvt = listenedEvtRef.get();
    assertTrue(listenedEvt instanceof NodeValidationFailedEvent);
    NodeValidationFailedEvent validationEvt = (NodeValidationFailedEvent) listenedEvt;
    assertEquals(invalidNodeName, validationEvt.eventNode().attribute(ATTR_NODE_CONSISTENT_ID));
    IgniteNodeValidationResult validationRes = validationEvt.validationResult();
    assertNotNull(validationRes);
    String errMsg = validationRes.message();
    assertNotNull(errMsg);
    assertTrue(errMsg.contains("Local node's grid security processor class is not equal to remote node's grid security processor class"));
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TestSecurityPluginProvider(org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider) IgniteNodeValidationResult(org.apache.ignite.spi.IgniteNodeValidationResult) NodeValidationFailedEvent(org.apache.ignite.events.NodeValidationFailedEvent) Event(org.apache.ignite.events.Event) NodeValidationFailedEvent(org.apache.ignite.events.NodeValidationFailedEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 2 with NodeValidationFailedEvent

use of org.apache.ignite.events.NodeValidationFailedEvent in project ignite by apache.

the class ZookeeperDiscoveryImpl method validateJoiningNode.

/**
 * @param joiningNodeData Joining node data.
 * @return Validation result.
 */
private ZkNodeValidateResult validateJoiningNode(ZkJoiningNodeData joiningNodeData) {
    ZookeeperClusterNode node = joiningNodeData.node();
    ZookeeperClusterNode node0 = rtState.top.nodesById.get(node.id());
    if (node0 != null) {
        U.error(log, "Failed to include node in cluster, node with the same ID already exists [joiningNode=" + node + ", existingNode=" + node0 + ']');
        // Note: exception message is checked in tests.
        return new ZkNodeValidateResult("Node with the same ID already exists: " + node0);
    }
    ZkNodeValidateResult res = authenticateNode(node);
    if (res.err != null)
        return res;
    IgniteNodeValidationResult err = spi.getSpiContext().validateNode(node);
    if (err == null) {
        DiscoveryDataBag joiningNodeBag = new DiscoveryDataBag(node.id(), joiningNodeData.node().isClient());
        joiningNodeBag.joiningNodeData(joiningNodeData.discoveryData());
        err = spi.getSpiContext().validateNode(node, joiningNodeBag);
    }
    if (err != null) {
        spi.getSpiContext().recordEvent(new NodeValidationFailedEvent(locNode, node, err));
        LT.warn(log, err.message());
        res.err = err.sendMessage();
    }
    return res;
}
Also used : DiscoveryDataBag(org.apache.ignite.spi.discovery.DiscoveryDataBag) IgniteNodeValidationResult(org.apache.ignite.spi.IgniteNodeValidationResult) NodeValidationFailedEvent(org.apache.ignite.events.NodeValidationFailedEvent)

Aggregations

NodeValidationFailedEvent (org.apache.ignite.events.NodeValidationFailedEvent)2 IgniteNodeValidationResult (org.apache.ignite.spi.IgniteNodeValidationResult)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 Event (org.apache.ignite.events.Event)1 TestSecurityPluginProvider (org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider)1 DiscoveryDataBag (org.apache.ignite.spi.discovery.DiscoveryDataBag)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1