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);
}
}
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;
}
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);
}
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);
}
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());
}
Aggregations