Search in sources :

Example 6 with DiscoveryDataBag

use of org.apache.ignite.spi.discovery.DiscoveryDataBag in project ignite by apache.

the class DiscoveryDataPacket method unmarshalGridData.

/**
 * @param marsh Marsh.
 * @param clsLdr Class loader.
 * @param clientNode Client node.
 * @param log Logger.
 */
public DiscoveryDataBag unmarshalGridData(Marshaller marsh, ClassLoader clsLdr, boolean clientNode, IgniteLogger log) {
    DiscoveryDataBag dataBag = new DiscoveryDataBag(joiningNodeId, joiningNodeClient);
    if (commonData != null && !commonData.isEmpty()) {
        Map<Integer, Serializable> unmarshCommonData = unmarshalData(commonData, marsh, clsLdr, clientNode, log);
        dataBag.commonData(unmarshCommonData);
    }
    if (nodeSpecificData != null && !nodeSpecificData.isEmpty()) {
        Map<UUID, Map<Integer, Serializable>> unmarshNodeSpecData = U.newLinkedHashMap(nodeSpecificData.size());
        for (Map.Entry<UUID, Map<Integer, byte[]>> nodeBinEntry : nodeSpecificData.entrySet()) {
            Map<Integer, byte[]> nodeBinData = nodeBinEntry.getValue();
            if (nodeBinData == null || nodeBinData.isEmpty())
                continue;
            Map<Integer, Serializable> unmarshData = unmarshalData(nodeBinData, marsh, clsLdr, clientNode, log);
            unmarshNodeSpecData.put(nodeBinEntry.getKey(), unmarshData);
        }
        dataBag.nodeSpecificData(unmarshNodeSpecData);
    }
    return dataBag;
}
Also used : Serializable(java.io.Serializable) DiscoveryDataBag(org.apache.ignite.spi.discovery.DiscoveryDataBag) UUID(java.util.UUID) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 7 with DiscoveryDataBag

use of org.apache.ignite.spi.discovery.DiscoveryDataBag in project ignite by apache.

the class DiscoveryDataPacket method unmarshalJoiningNodeData.

/**
 * @param marsh Marsh.
 * @param clsLdr Class loader.
 * @param clientNode Client node.
 * @param log Logger.
 */
public DiscoveryDataBag unmarshalJoiningNodeData(Marshaller marsh, ClassLoader clsLdr, boolean clientNode, IgniteLogger log) {
    DiscoveryDataBag dataBag = new DiscoveryDataBag(joiningNodeId, joiningNodeClient);
    if (joiningNodeData != null && !joiningNodeData.isEmpty()) {
        unmarshalledJoiningNodeData = unmarshalData(joiningNodeData, marsh, clsLdr, clientNode, log);
        dataBag.joiningNodeData(unmarshalledJoiningNodeData);
    }
    return dataBag;
}
Also used : DiscoveryDataBag(org.apache.ignite.spi.discovery.DiscoveryDataBag)

Example 8 with DiscoveryDataBag

use of org.apache.ignite.spi.discovery.DiscoveryDataBag in project ignite by apache.

the class GridSpiAbstractTest method spiStart.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "unchecked", "CastToIncompatibleInterface", "InstanceofIncompatibleInterface" })
protected final void spiStart() throws Exception {
    GridSpiTest spiTest = GridTestUtils.getAnnotation(getClass(), GridSpiTest.class);
    assert spiTest != null;
    T spi = (T) spiTest.spi().newInstance();
    // Set spi into test data.
    getTestData().setSpi(spi);
    if (!(spi instanceof DiscoverySpi)) {
        if (spiTest.triggerDiscovery())
            configureDiscovery(spiTest);
    } else
        getTestData().setDiscoverySpi((DiscoverySpi) spi);
    getTestResources().inject(spi);
    spiConfigure(spi);
    Map<String, Object> attrs = spi.getNodeAttributes();
    // Set up SPI class name and SPI version.
    Map<String, Serializable> spiAttrs = initSpiClassAndVersionAttributes(spi);
    if (attrs != null)
        getTestData().getAttributes().putAll(attrs);
    if (spiAttrs != null)
        getTestData().getAttributes().putAll(spiAttrs);
    Map<String, Serializable> nodeAttrs = getNodeAttributes();
    if (nodeAttrs != null)
        getTestData().getAttributes().putAll(nodeAttrs);
    DiscoverySpi discoSpi = getTestData().getDiscoverySpi();
    if (spiTest.triggerDiscovery() && !getTestData().isDiscoveryTest()) {
        getTestData().getAttributes().putAll(initSpiClassAndVersionAttributes(discoSpi));
        // Set all local node attributes into discovery SPI.
        discoSpi.setNodeAttributes(getTestData().getAttributes(), VERSION);
        discoSpi.setMetricsProvider(createMetricsProvider());
        discoSpi.setDataExchange(new DiscoverySpiDataExchange() {

            @Override
            public DiscoveryDataBag collect(DiscoveryDataBag dataBag) {
                return dataBag;
            }

            @Override
            public void onExchange(DiscoveryDataBag dataBag) {
            // No-op.
            }
        });
        try {
            spiStart(discoSpi);
        } catch (Exception e) {
            spiStop(discoSpi);
            throw e;
        }
    }
    if (spi instanceof DiscoverySpi) {
        getTestData().getAttributes().putAll(initSpiClassAndVersionAttributes(spi));
        ((DiscoverySpi) spi).setNodeAttributes(getTestData().getAttributes(), VERSION);
        ((DiscoverySpi) spi).setMetricsProvider(createMetricsProvider());
    }
    try {
        spiStart(spi);
    } catch (Exception e) {
        spiStop(spi);
        if (discoSpi != null && !discoSpi.equals(spi))
            spiStop(discoSpi);
        afterSpiStopped();
        throw e;
    }
    // Initialize SPI context.
    getTestData().setSpiContext(initSpiContext());
    // Initialize discovery SPI only once.
    if (discoSpi != null && !discoSpi.equals(spi))
        discoSpi.onContextInitialized(getSpiContext());
    spi.onContextInitialized(getTestData().getSpiContext());
}
Also used : Serializable(java.io.Serializable) DiscoveryDataBag(org.apache.ignite.spi.discovery.DiscoveryDataBag) DiscoverySpiDataExchange(org.apache.ignite.spi.discovery.DiscoverySpiDataExchange) DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) IgniteProductVersion.fromString(org.apache.ignite.lang.IgniteProductVersion.fromString) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

DiscoveryDataBag (org.apache.ignite.spi.discovery.DiscoveryDataBag)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 Serializable (java.io.Serializable)3 Collection (java.util.Collection)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 GridComponent (org.apache.ignite.internal.GridComponent)3 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 UUID (java.util.UUID)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)2 IgniteException (org.apache.ignite.IgniteException)2 IgniteInterruptedException (org.apache.ignite.IgniteInterruptedException)2 DiscoveryEvent (org.apache.ignite.events.DiscoveryEvent)2 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)2 IgniteKernal (org.apache.ignite.internal.IgniteKernal)2 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)2 SecurityContext (org.apache.ignite.internal.processors.security.SecurityContext)2