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();
}
}
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);
}
}
}
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;
}
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));
}
}
}
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));
}
}
}
Aggregations