use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoverySharedFsIpFinder method registerAddresses.
/**
* {@inheritDoc}
*/
@Override
public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
assert !F.isEmpty(addrs);
initFolder();
try {
for (String name : distinctNames(addrs)) {
File file = new File(folder, name);
file.createNewFile();
}
} catch (IOException e) {
throw new IgniteSpiException("Failed to create file.", e);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoverySharedFsIpFinder method initFolder.
/**
* Initializes folder to work with.
*
* @return Folder.
* @throws org.apache.ignite.spi.IgniteSpiException If failed.
*/
private File initFolder() throws IgniteSpiException {
if (initGuard.compareAndSet(false, true)) {
if (path == null)
throw new IgniteSpiException("Shared file system path is null " + "(it should be configured via setPath(..) configuration property).");
if (path.equals(DFLT_PATH) && warnGuard.compareAndSet(false, true))
U.warn(log, "Default local computer-only share is used by IP finder.");
try {
File tmp;
if (new File(path).exists())
tmp = new File(path);
else {
try {
tmp = U.resolveWorkDirectory(ignite.configuration().getWorkDirectory(), path, false);
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Failed to resolve directory [path=" + path + ", exception=" + e.getMessage() + ']');
}
}
if (!tmp.isDirectory())
throw new IgniteSpiException("Failed to initialize shared file system path " + "(path must point to folder): " + path);
if (!tmp.canRead() || !tmp.canWrite())
throw new IgniteSpiException("Failed to initialize shared file system path " + "(path must be readable and writable): " + path);
folder = tmp;
} finally {
initLatch.countDown();
}
} else {
try {
U.await(initLatch);
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
if (folder == null)
throw new IgniteSpiException("Failed to initialize shared file system folder (check logs for errors).");
}
return folder;
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoveryVmIpFinder method addresses.
/**
* Creates address from string with port information.
*
* @param ipStr Address string
* @param regexDelim Port regex delimiter.
* @param errMsg Error message.
* @return Socket addresses (may contain 1 or more addresses if provided string
* includes port range).
* @throws IgniteSpiException If failed.
*/
private static Collection<InetSocketAddress> addresses(String ipStr, String regexDelim, String errMsg) throws IgniteSpiException {
String[] tokens = ipStr.split(regexDelim);
if (tokens.length == 2) {
String addrStr = tokens[0];
String portStr = tokens[1];
int port1, port2;
if (portStr.contains("..")) {
port1 = Integer.parseInt(portStr.substring(0, portStr.indexOf("..")));
port2 = Integer.parseInt(portStr.substring(portStr.indexOf("..") + 2, portStr.length()));
} else
port1 = port2 = Integer.parseInt(portStr);
if ((port1 != port2 && port2 < port1) || port1 <= 0 || port2 <= 0)
throw new IgniteSpiException(errMsg);
try {
Collection<InetSocketAddress> res = new ArrayList<>();
InetAddress[] inetAddresses;
try {
inetAddresses = InetAddress.getAllByName(addrStr);
} catch (UnknownHostException e) {
// Ignore
for (int i = port1; i <= port2; i++) res.add(new InetSocketAddress(addrStr, i));
return res;
}
for (InetAddress curAddr : inetAddresses) {
// Upper bound included.
for (int i = port1; i <= port2; i++) res.add(new InetSocketAddress(curAddr, i));
}
return res;
} catch (IllegalArgumentException e) {
throw new IgniteSpiException(errMsg, e);
}
} else
throw new IgniteSpiException(errMsg);
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class KeystoreEncryptionSpi method decrypt.
/**
* {@inheritDoc}
*/
@Override
public byte[] decrypt(byte[] data, Serializable key) {
assert key instanceof KeystoreEncryptionKey;
ensureStarted();
try {
SecretKeySpec keySpec = new SecretKeySpec(((KeystoreEncryptionKey) key).key().getEncoded(), CIPHER_ALGO);
Cipher cipher = aesWithPadding.get();
cipher.init(DECRYPT_MODE, keySpec, new IvParameterSpec(data, 0, cipher.getBlockSize()));
return cipher.doFinal(data, cipher.getBlockSize(), data.length - cipher.getBlockSize());
} catch (InvalidAlgorithmParameterException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) {
throw new IgniteSpiException(e);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoveryImpl method registerLocalNodeAddress.
/**
* @throws IgniteSpiException If failed.
*/
protected final void registerLocalNodeAddress() throws IgniteSpiException {
long spiJoinTimeout = spi.getJoinTimeout();
// Make sure address registration succeeded.
// ... but limit it if join timeout is configured.
long startNanos = spiJoinTimeout > 0 ? System.nanoTime() : 0;
while (true) {
try {
spi.ipFinder.initializeLocalAddresses(U.resolveAddresses(spi.getAddressResolver(), locNode.socketAddresses()));
// Success.
break;
} catch (IllegalStateException e) {
throw new IgniteSpiException("Failed to register local node address with IP finder: " + locNode.socketAddresses(), e);
} catch (IgniteSpiException e) {
LT.error(log, e, "Failed to register local node address in IP finder on start " + "(retrying every " + spi.getReconnectDelay() + " ms; " + "change 'reconnectDelay' to configure the frequency of retries).");
}
;
if (spiJoinTimeout > 0 && U.millisSinceNanos(startNanos) > spiJoinTimeout)
throw new IgniteSpiException("Failed to register local addresses with IP finder within join timeout " + "(make sure IP finder configuration is correct, and operating system firewalls are disabled " + "on all host machines, or consider increasing 'joinTimeout' configuration property) " + "[joinTimeout=" + spiJoinTimeout + ']');
try {
U.sleep(spi.getReconnectDelay());
} catch (IgniteInterruptedCheckedException e) {
throw new IgniteSpiException("Thread has been interrupted.", e);
}
}
}
Aggregations