Search in sources :

Example 81 with IgniteSpiException

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;
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) GeneralSecurityException(java.security.GeneralSecurityException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException)

Example 82 with IgniteSpiException

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;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) Set(java.util.Set) GridConcurrentHashSet(org.apache.ignite.internal.util.GridConcurrentHashSet) GridBoundedConcurrentLinkedHashSet(org.apache.ignite.internal.util.GridBoundedConcurrentLinkedHashSet) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Example 83 with IgniteSpiException

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);
    }
}
Also used : Serializable(java.io.Serializable) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Nullable(org.jetbrains.annotations.Nullable)

Example 84 with IgniteSpiException

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;
}
Also used : NodeMetadata(org.jclouds.compute.domain.NodeMetadata) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) InetSocketAddress(java.net.InetSocketAddress) ComputeMetadata(org.jclouds.compute.domain.ComputeMetadata) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) LinkedList(java.util.LinkedList) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteInterruptedCheckedException(org.apache.ignite.internal.IgniteInterruptedCheckedException) IOException(java.io.IOException)

Example 85 with IgniteSpiException

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);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException)

Aggregations

IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)131 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)59 IOException (java.io.IOException)32 InetSocketAddress (java.net.InetSocketAddress)22 ClusterNode (org.apache.ignite.cluster.ClusterNode)21 IgniteInterruptedCheckedException (org.apache.ignite.internal.IgniteInterruptedCheckedException)21 IgniteException (org.apache.ignite.IgniteException)20 ArrayList (java.util.ArrayList)14 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)14 HashMap (java.util.HashMap)13 UUID (java.util.UUID)13 Nullable (org.jetbrains.annotations.Nullable)12 Test (org.junit.Test)12 File (java.io.File)10 Message (org.apache.ignite.plugin.extensions.communication.Message)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)9 SSLException (javax.net.ssl.SSLException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 SocketTimeoutException (java.net.SocketTimeoutException)7 Ignite (org.apache.ignite.Ignite)7