use of org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl in project ignite by apache.
the class GridCommandHandlerTest method testConnectivityCommandWithFailedNodes.
/**
* Test connectivity command works via control.sh with one node failing.
*/
@Test
public void testConnectivityCommandWithFailedNodes() throws Exception {
UUID okId = UUID.randomUUID();
UUID failingId = UUID.randomUUID();
UnaryOperator<IgniteConfiguration> operator = configuration -> {
configuration.setCommunicationSpi(new TcpCommunicationSpi() {
/**
* {inheritDoc}
*/
@Override
public IgniteFuture<BitSet> checkConnection(List<ClusterNode> nodes) {
BitSet bitSet = new BitSet();
int idx = 0;
for (ClusterNode remoteNode : nodes) {
if (!remoteNode.id().equals(failingId))
bitSet.set(idx);
idx++;
}
return new IgniteFinishedFutureImpl<>(bitSet);
}
});
return configuration;
};
IgniteEx ignite = startGrid("normal", configuration -> {
operator.apply(configuration);
configuration.setConsistentId(okId);
configuration.setNodeId(okId);
return configuration;
});
IgniteEx failure = startGrid("failure", configuration -> {
operator.apply(configuration);
configuration.setConsistentId(failingId);
configuration.setNodeId(failingId);
return configuration;
});
ignite.cluster().state(ACTIVE);
failure.cluster().state(ACTIVE);
injectTestSystemOut();
int connectivity = execute("--diagnostic", "connectivity");
assertEquals(EXIT_CODE_OK, connectivity);
String out = testOut.toString();
String what = "There is no connectivity between the following nodes";
assertContains(log, out.replaceAll("[\\W_]+", "").trim(), what.replaceAll("[\\W_]+", "").trim());
}
use of org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl in project ignite by apache.
the class GridEncryptionManager method changeMasterKey.
/**
* {@inheritDoc}
*/
@Override
public IgniteFuture<Void> changeMasterKey(String masterKeyName) {
if (ctx.clientNode()) {
return new IgniteFinishedFutureImpl<>(new UnsupportedOperationException("Client and daemon nodes can not " + "perform this operation."));
}
if (!IgniteFeatures.allNodesSupports(ctx.grid().cluster().nodes(), MASTER_KEY_CHANGE)) {
return new IgniteFinishedFutureImpl<>(new IllegalStateException("Not all nodes in the cluster support " + "the master key change process."));
}
// can be partially re-encrypted in case of node stop without the possibility of recovery.
if (!ctx.state().clusterState().active()) {
return new IgniteFinishedFutureImpl<>(new IgniteException("Master key change was rejected. " + "The cluster is inactive."));
}
if (masterKeyName.equals(getMasterKeyName())) {
return new IgniteFinishedFutureImpl<>(new IgniteException("Master key change was rejected. " + "New name equal to the current."));
}
byte[] digest;
try {
digest = masterKeyDigest(masterKeyName);
} catch (Exception e) {
return new IgniteFinishedFutureImpl<>(new IgniteException("Master key change was rejected. " + "Unable to get the master key digest.", e));
}
MasterKeyChangeRequest request = new MasterKeyChangeRequest(UUID.randomUUID(), encryptKeyName(masterKeyName), digest);
synchronized (opsMux) {
if (disconnected) {
return new IgniteFinishedFutureImpl<>(new IgniteClientDisconnectedException(ctx.cluster().clientReconnectFuture(), "Master key change was rejected. Client node disconnected."));
}
if (stopped) {
return new IgniteFinishedFutureImpl<>(new IgniteException("Master key change was rejected. " + "Node is stopping."));
}
if (masterKeyChangeFut != null && !masterKeyChangeFut.isDone()) {
return new IgniteFinishedFutureImpl<>(new IgniteException("Master key change was rejected. " + "The previous change was not completed."));
}
masterKeyChangeFut = new KeyChangeFuture(request.requestId());
prepareMKChangeProc.start(request.requestId(), request);
return new IgniteFutureImpl<>(masterKeyChangeFut);
}
}
use of org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl in project ignite by apache.
the class CacheAsyncContinuationExecutorTest method testRemoteOperationContinuesOnDefaultExecutor.
/**
* Tests future chain / listen with default executor.
*
* This test would hang before {@link IgniteConfiguration#setAsyncContinuationExecutor(Executor)}
* was introduced, or if we set {@link Runnable#run()} as the executor.
*/
private void testRemoteOperationContinuesOnDefaultExecutor(boolean chain) throws Exception {
final String key = getPrimaryKey(1);
IgniteCache<String, Integer> cache = jcache(0);
CyclicBarrier barrier = new CyclicBarrier(2);
AtomicReference<String> listenThreadName = new AtomicReference<>("");
IgniteInClosure<IgniteFuture<Void>> clos = f -> {
listenThreadName.set(Thread.currentThread().getName());
if (allowCacheOperationsInContinuation()) {
// Check that cache operations do not deadlock.
cache.replace(key, 2);
}
try {
barrier.await(10, TimeUnit.SECONDS);
} catch (Exception e) {
e.printStackTrace();
}
};
IgniteFuture<Void> fut = cache.putAsync(key, 1);
if (chain)
fut.chain(f -> {
clos.apply(f);
return new IgniteFinishedFutureImpl<>();
});
else
fut.listen(clos);
barrier.await(10, TimeUnit.SECONDS);
assertEquals(allowCacheOperationsInContinuation() ? 2 : 1, cache.get(key).intValue());
assertTrue(listenThreadName.get(), listenThreadName.get().startsWith(expectedThreadNamePrefix()));
}
use of org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl in project ignite by apache.
the class ComputeTaskInternalFuture method finishedFuture.
/**
* @param ctx Context.
* @param taskCls Task class.
* @param e Error.
* @return Finished task future.
*/
public static <R> ComputeTaskInternalFuture<R> finishedFuture(final GridKernalContext ctx, final Class<?> taskCls, IgniteCheckedException e) {
assert ctx != null;
assert taskCls != null;
assert e != null;
final long time = U.currentTimeMillis();
final IgniteUuid id = IgniteUuid.fromUuid(ctx.localNodeId());
ComputeTaskSession ses = new ComputeTaskSession() {
@Override
public String getTaskName() {
return taskCls.getName();
}
@Override
public UUID getTaskNodeId() {
return ctx.localNodeId();
}
@Override
public long getStartTime() {
return time;
}
@Override
public long getEndTime() {
return time;
}
@Override
public IgniteUuid getId() {
return id;
}
@Override
public ClassLoader getClassLoader() {
return null;
}
@Override
public Collection<ComputeJobSibling> getJobSiblings() throws IgniteException {
return Collections.emptyList();
}
@Override
public Collection<ComputeJobSibling> refreshJobSiblings() throws IgniteException {
return Collections.emptyList();
}
@Nullable
@Override
public ComputeJobSibling getJobSibling(IgniteUuid jobId) throws IgniteException {
return null;
}
@Override
public void setAttribute(Object key, @Nullable Object val) throws IgniteException {
}
@Nullable
@Override
public <K, V> V getAttribute(K key) {
return null;
}
@Override
public void setAttributes(Map<?, ?> attrs) throws IgniteException {
// No-op.
}
@Override
public Map<?, ?> getAttributes() {
return Collections.emptyMap();
}
@Override
public void addAttributeListener(ComputeTaskSessionAttributeListener lsnr, boolean rewind) {
// No-op.
}
@Override
public boolean removeAttributeListener(ComputeTaskSessionAttributeListener lsnr) {
return false;
}
@Override
public <K, V> V waitForAttribute(K key, long timeout) throws InterruptedException {
throw new InterruptedException("Session was closed.");
}
@Override
public <K, V> boolean waitForAttribute(K key, @Nullable V val, long timeout) throws InterruptedException {
throw new InterruptedException("Session was closed.");
}
@Override
public Map<?, ?> waitForAttributes(Collection<?> keys, long timeout) throws InterruptedException {
throw new InterruptedException("Session was closed.");
}
@Override
public boolean waitForAttributes(Map<?, ?> attrs, long timeout) throws InterruptedException {
throw new InterruptedException("Session was closed.");
}
@Override
public void saveCheckpoint(String key, Object state) {
throw new IgniteException("Session was closed.");
}
@Override
public void saveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout) {
throw new IgniteException("Session was closed.");
}
@Override
public void saveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout, boolean overwrite) {
throw new IgniteException("Session was closed.");
}
@Nullable
@Override
public <T> T loadCheckpoint(String key) throws IgniteException {
throw new IgniteException("Session was closed.");
}
@Override
public boolean removeCheckpoint(String key) throws IgniteException {
throw new IgniteException("Session was closed.");
}
@Override
public Collection<UUID> getTopology() {
return Collections.emptyList();
}
@Override
public IgniteFuture<?> mapFuture() {
return new IgniteFinishedFutureImpl<Object>();
}
};
ComputeTaskInternalFuture<R> fut = new ComputeTaskInternalFuture<>(ses, ctx);
fut.onDone(e);
return fut;
}
use of org.apache.ignite.internal.util.future.IgniteFinishedFutureImpl in project ignite by apache.
the class IgniteClientReconnectMassiveShutdownTest method getRetryFuture.
/**
* Gets retry or reconnect future if passed in {@code 'Exception'} has corresponding class in {@code 'cause'}
* hierarchy.
*
* @param e {@code Exception}.
* @return Internal future.
* @throws Exception If unable to find retry or reconnect future.
*/
private IgniteFuture<?> getRetryFuture(Exception e) throws Exception {
if (X.hasCause(e, IgniteClientDisconnectedException.class)) {
IgniteClientDisconnectedException cause = X.cause(e, IgniteClientDisconnectedException.class);
assertNotNull(cause);
return cause.reconnectFuture();
} else if (X.hasCause(e, ClusterTopologyException.class)) {
ClusterTopologyException cause = X.cause(e, ClusterTopologyException.class);
assertNotNull(cause);
return cause.retryReadyFuture();
} else if (X.hasCause(e, CacheInvalidStateException.class)) {
// All partition owners have left the cluster, partition data has been lost.
return new IgniteFinishedFutureImpl<>();
} else
throw e;
}
Aggregations