Search in sources :

Example 21 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class IgniteNodeRunner method readCfgFromFileAndDeleteFile.

/**
 * Reads configuration from given file and delete the file after.
 *
 * @param fileName File name.
 * @return Readed configuration.
 * @throws IOException If failed.
 * @see #storeToFile(IgniteConfiguration, boolean)
 * @throws IgniteCheckedException On error.
 */
private static IgniteConfiguration readCfgFromFileAndDeleteFile(String fileName) throws IOException, IgniteCheckedException {
    try (BufferedReader cfgReader = new BufferedReader(new FileReader(fileName))) {
        IgniteConfiguration cfg = (IgniteConfiguration) new XStream().fromXML(cfgReader);
        if (cfg.getMarshaller() == null) {
            Marshaller marsh = IgniteTestResources.getMarshaller();
            cfg.setMarshaller(marsh);
        }
        X.println("Configured marshaller class: " + cfg.getMarshaller().getClass().getName());
        if (cfg.getDiscoverySpi() == null) {
            TcpDiscoverySpi disco = new TcpDiscoverySpi();
            disco.setIpFinder(GridCacheAbstractFullApiSelfTest.LOCAL_IP_FINDER);
            cfg.setDiscoverySpi(disco);
        }
        return cfg;
    } finally {
        new File(fileName).delete();
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) XStream(com.thoughtworks.xstream.XStream) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 22 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridServiceProcessor method deploy.

/**
     * @param cfg Service configuration.
     * @return Future for deployment.
     */
public IgniteInternalFuture<?> deploy(ServiceConfiguration cfg) {
    A.notNull(cfg, "cfg");
    ServicesCompatibilityState state = markCompatibilityStateAsUsed();
    validate(cfg);
    ctx.security().authorize(cfg.getName(), SecurityPermission.SERVICE_DEPLOY, null);
    if (!state.srvcCompatibility) {
        Marshaller marsh = ctx.config().getMarshaller();
        LazyServiceConfiguration cfg0;
        try {
            byte[] srvcBytes = U.marshal(marsh, cfg.getService());
            cfg0 = new LazyServiceConfiguration(cfg, srvcBytes);
        } catch (IgniteCheckedException e) {
            U.error(log, "Failed to marshal service with configured marshaller [srvc=" + cfg.getService() + ", marsh=" + marsh + "]", e);
            return new GridFinishedFuture<>(e);
        }
        cfg = cfg0;
    }
    GridServiceDeploymentFuture fut = new GridServiceDeploymentFuture(cfg);
    GridServiceDeploymentFuture old = depFuts.putIfAbsent(cfg.getName(), fut);
    if (old != null) {
        if (!old.configuration().equalsIgnoreNodeFilter(cfg)) {
            fut.onDone(new IgniteCheckedException("Failed to deploy service (service already exists with " + "different configuration) [deployed=" + old.configuration() + ", new=" + cfg + ']'));
            return fut;
        }
        return old;
    }
    if (ctx.clientDisconnected()) {
        fut.onDone(new IgniteClientDisconnectedCheckedException(ctx.cluster().clientReconnectFuture(), "Failed to deploy service, client node disconnected."));
        depFuts.remove(cfg.getName(), fut);
    }
    while (true) {
        try {
            GridServiceDeploymentKey key = new GridServiceDeploymentKey(cfg.getName());
            if (ctx.deploy().enabled())
                ctx.cache().context().deploy().ignoreOwnership(true);
            try {
                GridServiceDeployment dep = (GridServiceDeployment) cache.getAndPutIfAbsent(key, new GridServiceDeployment(ctx.localNodeId(), cfg));
                if (dep != null) {
                    if (!dep.configuration().equalsIgnoreNodeFilter(cfg)) {
                        // Remove future from local map.
                        depFuts.remove(cfg.getName(), fut);
                        fut.onDone(new IgniteCheckedException("Failed to deploy service (service already exists with " + "different configuration) [deployed=" + dep.configuration() + ", new=" + cfg + ']'));
                    } else {
                        Iterator<Cache.Entry<Object, Object>> it = serviceEntries(ServiceAssignmentsPredicate.INSTANCE);
                        while (it.hasNext()) {
                            Cache.Entry<Object, Object> e = it.next();
                            GridServiceAssignments assigns = (GridServiceAssignments) e.getValue();
                            if (assigns.name().equals(cfg.getName())) {
                                // Remove future from local map.
                                depFuts.remove(cfg.getName(), fut);
                                fut.onDone();
                                break;
                            }
                        }
                        if (!dep.configuration().equalsIgnoreNodeFilter(cfg))
                            U.warn(log, "Service already deployed with different configuration (will ignore) " + "[deployed=" + dep.configuration() + ", new=" + cfg + ']');
                    }
                }
            } finally {
                if (ctx.deploy().enabled())
                    ctx.cache().context().deploy().ignoreOwnership(false);
            }
            return fut;
        } catch (ClusterTopologyCheckedException e) {
            if (log.isDebugEnabled())
                log.debug("Topology changed while deploying service (will retry): " + e.getMessage());
        } catch (IgniteCheckedException e) {
            if (e.hasCause(ClusterTopologyCheckedException.class)) {
                if (log.isDebugEnabled())
                    log.debug("Topology changed while deploying service (will retry): " + e.getMessage());
                continue;
            }
            U.error(log, "Failed to deploy service: " + cfg.getName(), e);
            return new GridFinishedFuture<>(e);
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteClientDisconnectedCheckedException(org.apache.ignite.internal.IgniteClientDisconnectedCheckedException) GridTimeoutObject(org.apache.ignite.internal.processors.timeout.GridTimeoutObject) Cache(javax.cache.Cache) IgniteInternalCache(org.apache.ignite.internal.processors.cache.IgniteInternalCache) DiscoCache(org.apache.ignite.internal.managers.discovery.DiscoCache) ClusterTopologyCheckedException(org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)

Example 23 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class IgniteExternalizableAbstractTest method getMarshallers.

/**
 * @return Marshallers.
 */
protected List<Marshaller> getMarshallers() throws IgniteCheckedException {
    List<Marshaller> marshallers = new ArrayList<>();
    BinaryMarshaller bin = createStandaloneBinaryMarshaller();
    marshallers.add(new JdkMarshaller());
    marshallers.add(bin);
    return marshallers;
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) JdkMarshaller(org.apache.ignite.marshaller.jdk.JdkMarshaller) Marshaller(org.apache.ignite.marshaller.Marshaller) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) ArrayList(java.util.ArrayList) JdkMarshaller(org.apache.ignite.marshaller.jdk.JdkMarshaller)

Example 24 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByGridUuid.

/**
 * @throws Exception If failed.
 */
public void testSerializationTopicCreatedByGridUuid() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_GRID_UUID);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

Example 25 with Marshaller

use of org.apache.ignite.marshaller.Marshaller in project ignite by apache.

the class GridTopicExternalizableSelfTest method testSerializationTopicCreatedByString.

/**
 * @throws Exception If failed.
 */
public void testSerializationTopicCreatedByString() throws Exception {
    for (Marshaller marsh : getMarshallers()) {
        info("Test GridTopic externalization [marshaller=" + marsh + ']');
        for (GridTopic topic : GridTopic.values()) {
            Externalizable msgOut = (Externalizable) topic.topic(A_STRING);
            assertEquals(msgOut, GridTestIoUtils.externalize(msgOut, marsh));
        }
    }
}
Also used : Marshaller(org.apache.ignite.marshaller.Marshaller) Externalizable(java.io.Externalizable)

Aggregations

Marshaller (org.apache.ignite.marshaller.Marshaller)46 Externalizable (java.io.Externalizable)8 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)8 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 HttpURLConnection (java.net.HttpURLConnection)5 URL (java.net.URL)5 URLConnection (java.net.URLConnection)5 ArrayList (java.util.ArrayList)5 HttpSession (javax.servlet.http.HttpSession)5 IgniteException (org.apache.ignite.IgniteException)5 JdkMarshaller (org.apache.ignite.marshaller.jdk.JdkMarshaller)5 Ignite (org.apache.ignite.Ignite)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 Server (org.eclipse.jetty.server.Server)4 File (java.io.File)2 OutputStream (java.io.OutputStream)2 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)2 IgniteClientDisconnectedCheckedException (org.apache.ignite.internal.IgniteClientDisconnectedCheckedException)2 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)2 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)2