Search in sources :

Example 66 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class GridUriDeploymentClassLoaderFactory method create.

/**
 * @param parent Parent class loader.
 * @param file Deployment archive or directory with an unpacked deployment archive.
 * @param log Logger.
 * @return Class Loader.
 * @throws org.apache.ignite.spi.IgniteSpiException In case of any error.
 */
public static ClassLoader create(ClassLoader parent, File file, IgniteLogger log) throws IgniteSpiException {
    assert parent != null;
    assert file != null;
    assert log != null;
    assert file.isDirectory();
    List<URL> urls = new ArrayList<>();
    try {
        String url = file.toURI().toURL().toString();
        URL mainUrl = url.length() > 0 && url.charAt(url.length() - 1) == '/' ? file.toURI().toURL() : new URL(url + '/');
        urls.add(mainUrl);
        File libDir = new File(file, DFLT_LIBS_DIR_PATH);
        if (libDir.exists()) {
            File[] files = libDir.listFiles(new FilenameFilter() {

                @Override
                public boolean accept(File dir, String name) {
                    return name.endsWith(".jar");
                }
            });
            if (files.length > 0) {
                for (File jarFile : files) {
                    urls.add(jarFile.toURI().toURL());
                }
            }
        }
        return new GridUriDeploymentClassLoader(urls.toArray(new URL[urls.size()]), parent);
    } catch (MalformedURLException e) {
        throw new IgniteSpiException("Failed to create class loader for a package: " + file, e);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) MalformedURLException(java.net.MalformedURLException) ArrayList(java.util.ArrayList) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) File(java.io.File) URL(java.net.URL)

Example 67 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class CacheRegisterMetadataLocallyTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    cfg.setDiscoverySpi(new TcpDiscoverySpi() {

        @Override
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
            if (msg instanceof CustomMessageWrapper) {
                DiscoveryCustomMessage realMsg = ((CustomMessageWrapper) msg).delegate();
                if (realMsg instanceof MetadataUpdateProposedMessage || realMsg instanceof MetadataUpdateAcceptedMessage)
                    customMessages.add(realMsg);
            }
            super.sendCustomEvent(msg);
        }
    });
    cfg.setCommunicationSpi(new TcpCommunicationSpi() {

        @Override
        public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) throws IgniteSpiException {
            if (msg instanceof GridIoMessage)
                communicationMessages.add(((GridIoMessage) msg).message());
            super.sendMessage(node, msg, ackC);
        }

        @Override
        public void sendMessage(ClusterNode node, Message msg) throws IgniteSpiException {
            if (msg instanceof GridIoMessage)
                communicationMessages.add(((GridIoMessage) msg).message());
            super.sendMessage(node, msg);
        }
    });
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
    cfg.setCacheConfiguration(cacheConfiguration(STATIC_CACHE_NAME, StaticKey.class, StaticValue.class));
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) MetadataUpdateAcceptedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) MetadataRequestMessage(org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) MetadataUpdateProposedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage) MetadataUpdateAcceptedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) MetadataResponseMessage(org.apache.ignite.internal.processors.cache.binary.MetadataResponseMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) MetadataUpdateProposedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 68 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class IgniteBaselineAffinityTopologyActivationTest method testNodeWithBltIsProhibitedToJoinNewCluster.

/**
 */
@Test
public void testNodeWithBltIsProhibitedToJoinNewCluster() throws Exception {
    BaselineTopologyVerifier nullVerifier = new BaselineTopologyVerifier() {

        @Override
        public void verify(BaselineTopology blt) {
            assertNull(blt);
        }
    };
    Ignite nodeC = startGridWithConsistentId("C");
    nodeC.cluster().active(true);
    stopGrid("C", false);
    Ignite nodeA = startGridWithConsistentId("A");
    Ignite nodeB = startGridWithConsistentId("B");
    verifyBaselineTopologyOnNodes(nullVerifier, new Ignite[] { nodeA, nodeB });
    boolean expectedExceptionThrown = false;
    try {
        startGridWithConsistentId("C");
    } catch (IgniteCheckedException e) {
        expectedExceptionThrown = true;
        if (e.getCause() != null && e.getCause().getCause() != null) {
            Throwable rootCause = e.getCause().getCause();
            if (!(rootCause instanceof IgniteSpiException) || !rootCause.getMessage().contains("Node with set up BaselineTopology"))
                Assert.fail("Unexpected ignite exception was thrown: " + e);
        } else
            throw e;
    }
    assertTrue("Expected exception wasn't thrown.", expectedExceptionThrown);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BaselineTopology(org.apache.ignite.internal.processors.cluster.BaselineTopology) Ignite(org.apache.ignite.Ignite) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 69 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class IgniteBaselineAffinityTopologyActivationTest method testNodeFailsToJoinWithIncompatiblePreviousBaselineTopology.

/**
 */
@Test
public void testNodeFailsToJoinWithIncompatiblePreviousBaselineTopology() throws Exception {
    startGridWithConsistentId("A");
    startGridWithConsistentId("B");
    Ignite nodeC = startGridWithConsistentId("C");
    nodeC.cluster().baselineAutoAdjustEnabled(false);
    nodeC.active(true);
    stopAllGrids(false);
    Ignite nodeA = startGridWithConsistentId("A");
    startGridWithConsistentId("B").active(true);
    nodeA.cluster().setBaselineTopology(baselineNodes(nodeA.cluster().forServers().nodes()));
    stopAllGrids(false);
    startGridWithConsistentId("C").active(true);
    stopGrid("C", false);
    startGridWithConsistentId("A");
    startGridWithConsistentId("B");
    boolean expectedExceptionThrown = false;
    try {
        startGridWithConsistentId("C");
    } catch (IgniteCheckedException e) {
        expectedExceptionThrown = true;
        if (e.getCause() != null && e.getCause().getCause() != null) {
            Throwable rootCause = e.getCause().getCause();
            if (!(rootCause instanceof IgniteSpiException) || !rootCause.getMessage().contains("not compatible"))
                Assert.fail("Unexpected ignite exception was thrown: " + e);
        } else
            throw e;
    }
    assertTrue("Expected exception wasn't thrown.", expectedExceptionThrown);
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Ignite(org.apache.ignite.Ignite) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 70 with IgniteSpiException

use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.

the class GridTcpCommunicationSpiRecoverySelfTest method checkBlockListener.

/**
 * @throws Exception If failed.
 */
private void checkBlockListener() throws Exception {
    TcpCommunicationSpi spi0 = spis.get(0);
    TcpCommunicationSpi spi1 = spis.get(1);
    final TestListener lsnr0 = (TestListener) spi0.getListener();
    final TestListener lsnr1 = (TestListener) spi1.getListener();
    ClusterNode node0 = nodes.get(0);
    ClusterNode node1 = nodes.get(1);
    lsnr1.block();
    int msgId = 0;
    for (int j = 0; j < 10; j++) {
        spi0.sendMessage(node1, new GridTestMessage(node0.id(), ++msgId, 0));
        spi1.sendMessage(node0, new GridTestMessage(node1.id(), ++msgId, 0));
    }
    lsnr1.blockLatch.await();
    lsnr1.unblock();
    Thread.sleep(500);
    int errCnt = 0;
    int msgs = 0;
    while (true) {
        try {
            int id = msgId + 1;
            spi0.sendMessage(node1, new GridTestMessage(node0.id(), id, 0));
            msgId++;
            msgs++;
            if (msgs == 10)
                break;
        } catch (IgniteSpiException e) {
            errCnt++;
            if (errCnt > 10)
                fail("Failed to send message: " + e);
        }
    }
    for (int j = 0; j < 10; j++) spi1.sendMessage(node0, new GridTestMessage(node1.id(), ++msgId, 0));
    final int expMsgs = 20;
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            return lsnr0.rcvCnt.get() >= expMsgs && lsnr1.rcvCnt.get() >= expMsgs;
        }
    }, awaitForSocketWriteTimeout());
    assertEquals(expMsgs, lsnr0.rcvCnt.get());
    assertEquals(expMsgs, lsnr1.rcvCnt.get());
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Aggregations

IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)131 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)59 IOException (java.io.IOException)32 InetSocketAddress (java.net.InetSocketAddress)22 ClusterNode (org.apache.ignite.cluster.ClusterNode)21 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)21 IgniteException (org.apache.ignite.IgniteException)20 ArrayList (java.util.ArrayList)14 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)14 HashMap (java.util.HashMap)13 UUID (java.util.UUID)13 Nullable (org.jetbrains.annotations.Nullable)12 Test (org.junit.Test)12 File (java.io.File)10 Message (org.apache.ignite.plugin.extensions.communication.Message)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 SSLException (javax.net.ssl.SSLException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 SocketTimeoutException (java.net.SocketTimeoutException)7 Ignite (org.apache.ignite.Ignite)7