use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class KeystoreEncryptionSpi method loadMasterKey.
/**
* Loads and returns a master key by name.
*
* @param masterKeyName Master key name.
* @return Master key.
*/
private KeystoreEncryptionKey loadMasterKey(String masterKeyName) {
assertParameter(!F.isEmpty(keyStorePath), "KeyStorePath shouldn't be empty");
assertParameter(keyStorePwd != null && keyStorePwd.length > 0, "KeyStorePassword shouldn't be empty");
try (InputStream keyStoreFile = keyStoreFile()) {
assertParameter(keyStoreFile != null, keyStorePath + " doesn't exists!");
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(keyStoreFile, keyStorePwd);
if (log != null && log.isInfoEnabled())
log.info("Successfully load keyStore [path=" + keyStorePath + "]");
Key key = ks.getKey(masterKeyName, keyStorePwd);
assertParameter(key != null, "No such master key found [masterKeyName=" + masterKeyName + ']');
return new KeystoreEncryptionKey(key, null);
} catch (GeneralSecurityException | IOException e) {
throw new IgniteSpiException(e);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoveryVmIpFinder method address.
/**
* Creates address from string.
*
* @param ipStr Address string.
* @return Socket addresses (may contain 1 or more addresses if provided string
* includes port range).
* @throws IgniteSpiException If failed.
*/
private static Collection<InetSocketAddress> address(String ipStr) throws IgniteSpiException {
ipStr = ipStr.trim();
String errMsg = "Failed to parse provided address: " + ipStr;
int colonCnt = ipStr.length() - ipStr.replace(":", "").length();
if (colonCnt > 1) {
// https://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:443).
if (ipStr.startsWith("[")) {
ipStr = ipStr.substring(1);
if (ipStr.contains("]:"))
return addresses(ipStr, "\\]\\:", errMsg);
else if (ipStr.endsWith("]"))
ipStr = ipStr.substring(0, ipStr.length() - 1);
else
throw new IgniteSpiException(errMsg);
}
} else {
// IPv4 address.
if (ipStr.endsWith(":"))
ipStr = ipStr.substring(0, ipStr.length() - 1);
else if (ipStr.indexOf(':') >= 0)
return addresses(ipStr, "\\:", errMsg);
}
Collection<InetSocketAddress> col = new LinkedHashSet<>();
try {
InetAddress[] inetAddresses = InetAddress.getAllByName(ipStr);
for (InetAddress addrs : inetAddresses) col.add(new InetSocketAddress(addrs, 0));
} catch (UnknownHostException ignored) {
// Preserve existing behavior on UnknownHostException
col = Collections.singleton(new InetSocketAddress(ipStr, 0));
}
return col;
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class GridSpiAbstractConfigTest method checkNegativeSpiProperty.
/**
* Checks that unacceptable property value prevents SPI from being started.
*
* @param spi Spi to test property on.
* @param propName name of property to check.
* @param val An illegal value.
* @param checkExMsg If {@code true} then additional info will be added to failure.
* @throws Exception If check failed.
*/
protected void checkNegativeSpiProperty(IgniteSpi spi, String propName, Object val, boolean checkExMsg) throws Exception {
assert spi != null;
assert propName != null;
getTestData().getTestResources().inject(spi);
String mtdName = "set" + propName.substring(0, 1).toUpperCase() + propName.substring(1);
Method mtd = null;
for (Method m : spi.getClass().getMethods()) if (m.getName().equals(mtdName)) {
mtd = m;
break;
}
assert mtd != null : "The setter is not found for property: " + propName;
boolean err = false;
try {
mtd.invoke(spi, val);
} catch (InvocationTargetException e) {
info("SPI property setter thrown exception: " + e);
if (e.getCause() instanceof IllegalArgumentException)
err = true;
else
throw e;
}
if (!err)
try {
if (!(spi instanceof DiscoverySpi))
spi.getNodeAttributes();
spi.spiStart(getTestIgniteInstanceName());
} catch (IgniteSpiException e) {
info("SPI start thrown exception: " + e);
if (checkExMsg)
assert e.getMessage().contains("SPI parameter failed condition check: ") : "SPI has returned wrong exception message [propName=" + propName + ", msg=" + e + ']';
err = true;
}
assert err : "No check for property [property=" + propName + ", value=" + val + ']';
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class IgniteTxPessimisticOriginatingNodeFailureAbstractSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setCommunicationSpi(new TcpCommunicationSpi() {
@Override
public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackClosure) throws IgniteSpiException {
if (getSpiContext().localNode().id().equals(failingNodeId)) {
if (ignoredMessage((GridIoMessage) msg) && ignoreMsgNodeIds != null) {
for (UUID ignored : ignoreMsgNodeIds) {
if (node.id().equals(ignored))
return;
}
}
}
super.sendMessage(node, msg, ackClosure);
}
});
cfg.getTransactionConfiguration().setDefaultTxConcurrency(PESSIMISTIC);
return cfg;
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class LocalWalModeChangeDuringRebalancingSelfTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setDataStorageConfiguration(new DataStorageConfiguration().setDefaultDataRegionConfiguration(new DataRegionConfiguration().setPersistenceEnabled(true).setInitialSize(DataStorageConfiguration.DFLT_DATA_REGION_INITIAL_SIZE).setMaxSize(DataStorageConfiguration.DFLT_DATA_REGION_INITIAL_SIZE)).setCheckpointFrequency(999_999_999_999L).setWalMode(WALMode.LOG_ONLY).setFileIOFactory(new TestFileIOFactory(new DataStorageConfiguration().getFileIOFactory())));
cfg.setCacheConfiguration(new CacheConfiguration(DEFAULT_CACHE_NAME).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setRebalanceDelay(-1).setAffinity(new RendezvousAffinityFunction(false, 32)).setBackups(dfltCacheBackupCnt), new CacheConfiguration(REPL_CACHE).setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL).setRebalanceDelay(-1).setCacheMode(CacheMode.REPLICATED));
cfg.setCommunicationSpi(new TcpCommunicationSpi() {
@Override
public void sendMessage(ClusterNode node, Message msg) throws IgniteSpiException {
if (msg instanceof GridIoMessage && ((GridIoMessage) msg).message() instanceof GridDhtPartitionSupplyMessage) {
int grpId = ((GridDhtPartitionSupplyMessage) ((GridIoMessage) msg).message()).groupId();
if (grpId == CU.cacheId(DEFAULT_CACHE_NAME)) {
CountDownLatch latch0 = supplyMessageLatch.get();
if (latch0 != null)
try {
latch0.await();
} catch (InterruptedException ex) {
throw new IgniteException(ex);
}
}
}
super.sendMessage(node, msg);
}
@Override
public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) throws IgniteSpiException {
if (msg instanceof GridIoMessage && ((GridIoMessage) msg).message() instanceof GridDhtPartitionSupplyMessage) {
int grpId = ((GridDhtPartitionSupplyMessage) ((GridIoMessage) msg).message()).groupId();
if (grpId == CU.cacheId(DEFAULT_CACHE_NAME)) {
CountDownLatch latch0 = supplyMessageLatch.get();
if (latch0 != null)
try {
latch0.await();
} catch (InterruptedException ex) {
throw new IgniteException(ex);
}
}
}
super.sendMessage(node, msg, ackC);
}
});
cfg.setConsistentId(igniteInstanceName);
System.setProperty(IgniteSystemProperties.IGNITE_DISABLE_WAL_DURING_REBALANCING, Boolean.toString(disableWalDuringRebalancing));
System.setProperty(IgniteSystemProperties.IGNITE_PENDING_TX_TRACKER_ENABLED, Boolean.toString(enablePendingTxTracker));
return cfg;
}
Aggregations