use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoveryGoogleStorageIpFinder method getRegisteredAddresses.
/**
* {@inheritDoc}
*/
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
init();
Collection<InetSocketAddress> addrs = new ArrayList<>();
try {
Storage.Objects.List listObjects = storage.objects().list(bucketName);
com.google.api.services.storage.model.Objects objects;
do {
objects = listObjects.execute();
if (objects == null || objects.getItems() == null)
break;
for (StorageObject object : objects.getItems()) addrs.add(addrFromString(object.getName()));
listObjects.setPageToken(objects.getNextPageToken());
} while (null != objects.getNextPageToken());
} catch (Exception e) {
throw new IgniteSpiException("Failed to get content from the bucket: " + bucketName, e);
}
return addrs;
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class GridCheckpointManager method storeCheckpoint.
/**
* @param ses Task session.
* @param key Checkpoint key.
* @param state Checkpoint state to save.
* @param scope Checkpoint scope.
* @param timeout Checkpoint timeout.
* @param override Whether or not override checkpoint if it already exists.
* @return {@code true} if checkpoint has been actually saved, {@code false} otherwise.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
public boolean storeCheckpoint(GridTaskSessionInternal ses, String key, Object state, ComputeTaskSessionScope scope, long timeout, boolean override) throws IgniteCheckedException {
if (!enabled())
return false;
assert ses != null;
assert key != null;
long now = U.currentTimeMillis();
boolean saved = false;
try {
switch(scope) {
case GLOBAL_SCOPE:
{
byte[] data = state == null ? null : U.marshal(marsh, state);
saved = getSpi(ses.getCheckpointSpi()).saveCheckpoint(key, data, timeout, override);
if (saved)
record(EVT_CHECKPOINT_SAVED, key);
break;
}
case SESSION_SCOPE:
{
if (closedSess.contains(ses.getId())) {
U.warn(log, S.toString("Checkpoint will not be saved due to session invalidation", "key", key, true, "val", state, true, "ses", ses, false));
break;
}
if (now > ses.getEndTime()) {
U.warn(log, S.toString("Checkpoint will not be saved due to session timeout", "key", key, true, "val", state, true, "ses", ses, false));
break;
}
if (now + timeout > ses.getEndTime() || now + timeout < 0)
timeout = ses.getEndTime() - now;
// Save it first to avoid getting null value on another node.
byte[] data = state == null ? null : U.marshal(marsh, state);
Set<String> keys = keyMap.get(ses.getId());
if (keys == null) {
Set<String> old = keyMap.putIfAbsent(ses.getId(), (CheckpointSet) (keys = new CheckpointSet(ses.session())));
if (old != null)
keys = old;
// Double check.
if (closedSess.contains(ses.getId())) {
U.warn(log, S.toString("Checkpoint will not be saved due to session invalidation", "key", key, true, "val", state, true, "ses", ses, false));
keyMap.remove(ses.getId(), keys);
break;
}
}
if (log.isDebugEnabled())
log.debug(S.toString("Resolved keys for session", "keys", keys, true, "ses", ses, false, "keyMap", keyMap, false));
// checkpoint from GridFuture.
if (keys != null) {
// Notify master node.
if (ses.getJobId() != null) {
ClusterNode node = ctx.discovery().node(ses.getTaskNodeId());
if (node != null)
ctx.io().sendToGridTopic(node, TOPIC_CHECKPOINT, new GridCheckpointRequest(ses.getId(), key, ses.getCheckpointSpi()), GridIoPolicy.PUBLIC_POOL);
}
saved = getSpi(ses.getCheckpointSpi()).saveCheckpoint(key, data, timeout, override);
if (saved) {
keys.add(key);
record(EVT_CHECKPOINT_SAVED, key);
}
}
break;
}
default:
assert false : "Unknown checkpoint scope: " + scope;
}
} catch (IgniteSpiException e) {
throw new IgniteCheckedException(S.toString("Failed to save checkpoint", "key", key, true, "val", state, true, "scope", scope, false, "timeout", timeout, false), e);
}
return saved;
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class GridCheckpointManager method loadCheckpoint.
/**
* @param ses Task session.
* @param key Checkpoint key.
* @return Loaded checkpoint.
* @throws IgniteCheckedException Thrown in case of any errors.
*/
@Nullable
public Serializable loadCheckpoint(GridTaskSessionInternal ses, String key) throws IgniteCheckedException {
if (!enabled())
return null;
assert ses != null;
assert key != null;
try {
byte[] data = getSpi(ses.getCheckpointSpi()).loadCheckpoint(key);
Serializable state = null;
// Always deserialize with task/session class loader.
if (data != null)
state = U.unmarshal(marsh, data, U.resolveClassLoader(ses.getClassLoader(), ctx.config()));
record(EVT_CHECKPOINT_LOADED, key);
return state;
} catch (IgniteSpiException e) {
throw new IgniteCheckedException(S.includeSensitive() ? ("Failed to load checkpoint: " + key) : "Failed to load checkpoint", e);
}
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class TcpDiscoveryCloudIpFinder method getRegisteredAddresses.
/**
* {@inheritDoc}
*/
@Override
public Collection<InetSocketAddress> getRegisteredAddresses() throws IgniteSpiException {
initComputeService();
Collection<InetSocketAddress> addresses = new LinkedList<>();
try {
Set<NodeMetadata> nodes;
if (nodesFilter != null)
nodes = (Set<NodeMetadata>) computeService.listNodesDetailsMatching(nodesFilter);
else {
nodes = new HashSet<>();
for (ComputeMetadata metadata : computeService.listNodes()) nodes.add(computeService.getNodeMetadata(metadata.getId()));
}
for (NodeMetadata metadata : nodes) {
if (metadata.getStatus() != NodeMetadata.Status.RUNNING)
continue;
for (String addr : metadata.getPrivateAddresses()) addresses.add(new InetSocketAddress(addr, 0));
for (String addr : metadata.getPublicAddresses()) addresses.add(new InetSocketAddress(addr, 0));
}
} catch (Exception e) {
throw new IgniteSpiException("Failed to get registered addresses for the provider: " + provider, e);
}
return addresses;
}
use of org.apache.ignite.spi.IgniteSpiException in project ignite by apache.
the class ServerImpl method marshalCredentials.
/**
* Marshalls credentials with discovery SPI marshaller (will replace attribute value).
*
* @param node Node to marshall credentials for.
* @param cred Credentials for marshall.
* @throws IgniteSpiException If marshalling failed.
*/
private void marshalCredentials(TcpDiscoveryNode node, SecurityCredentials cred) throws IgniteSpiException {
try {
// Use security-unsafe getter.
Map<String, Object> attrs = new HashMap<>(node.getAttributes());
attrs.put(IgniteNodeAttributes.ATTR_SECURITY_CREDENTIALS, spi.marshaller().marshal(cred));
node.setAttributes(attrs);
} catch (IgniteCheckedException e) {
throw new IgniteSpiException("Failed to marshal node security credentials: " + node.id(), e);
}
}
Aggregations