Search in sources :

Example 11 with Kryo

use of com.esotericsoftware.kryo.Kryo in project hive by apache.

the class FSStatsAggregator method connect.

@Override
public boolean connect(StatsCollectionContext scc) {
    List<String> statsDirs = scc.getStatsTmpDirs();
    assert statsDirs.size() == 1 : "Found multiple stats dirs: " + statsDirs;
    Path statsDir = new Path(statsDirs.get(0));
    LOG.debug("About to read stats from : " + statsDir);
    statsMap = new HashMap<String, Map<String, String>>();
    try {
        fs = statsDir.getFileSystem(scc.getHiveConf());
        statsList = new ArrayList<Map<String, Map<String, String>>>();
        FileStatus[] status = fs.listStatus(statsDir, new PathFilter() {

            @Override
            public boolean accept(Path file) {
                return file.getName().startsWith(StatsSetupConst.STATS_FILE_PREFIX);
            }
        });
        for (FileStatus file : status) {
            Input in = new Input(fs.open(file.getPath()));
            Kryo kryo = SerializationUtilities.borrowKryo();
            try {
                statsMap = kryo.readObject(in, statsMap.getClass());
            } finally {
                SerializationUtilities.releaseKryo(kryo);
            }
            LOG.info("Read stats : " + statsMap);
            statsList.add(statsMap);
            in.close();
        }
        return true;
    } catch (IOException e) {
        LOG.error("Failed to read stats from filesystem ", e);
        return false;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) PathFilter(org.apache.hadoop.fs.PathFilter) FileStatus(org.apache.hadoop.fs.FileStatus) IOException(java.io.IOException) Input(com.esotericsoftware.kryo.io.Input) HashMap(java.util.HashMap) Map(java.util.Map) Kryo(com.esotericsoftware.kryo.Kryo)

Example 12 with Kryo

use of com.esotericsoftware.kryo.Kryo in project hive by apache.

the class FSStatsPublisher method closeConnection.

@Override
public boolean closeConnection(StatsCollectionContext context) {
    List<String> statsDirs = context.getStatsTmpDirs();
    assert statsDirs.size() == 1 : "Found multiple stats dirs: " + statsDirs;
    Path statsDir = new Path(statsDirs.get(0));
    try {
        Path statsFile = null;
        if (context.getIndexForTezUnion() != -1) {
            statsFile = new Path(statsDir, StatsSetupConst.STATS_FILE_PREFIX + conf.getInt("mapred.task.partition", 0) + "_" + context.getIndexForTezUnion());
        } else {
            statsFile = new Path(statsDir, StatsSetupConst.STATS_FILE_PREFIX + conf.getInt("mapred.task.partition", 0));
        }
        LOG.debug("About to create stats file for this task : " + statsFile);
        Output output = new Output(statsFile.getFileSystem(conf).create(statsFile, true));
        LOG.debug("Created file : " + statsFile);
        LOG.debug("Writing stats in it : " + statsMap);
        Kryo kryo = SerializationUtilities.borrowKryo();
        try {
            kryo.writeObject(output, statsMap);
        } finally {
            SerializationUtilities.releaseKryo(kryo);
        }
        output.close();
        return true;
    } catch (IOException e) {
        LOG.error("Failed to persist stats on filesystem", e);
        return false;
    }
}
Also used : Path(org.apache.hadoop.fs.Path) Output(com.esotericsoftware.kryo.io.Output) IOException(java.io.IOException) Kryo(com.esotericsoftware.kryo.Kryo)

Example 13 with Kryo

use of com.esotericsoftware.kryo.Kryo in project storm by apache.

the class SerializationFactoryTest method test_registers_when_valid_class_name.

@Test
public void test_registers_when_valid_class_name() {
    Class arbitraryClass = BlowfishTupleSerializer.class;
    String secretKey = "0123456789abcdef";
    Map conf = Utils.readDefaultConfig();
    conf.put(Config.TOPOLOGY_TUPLE_SERIALIZER, arbitraryClass.getName());
    conf.put(BlowfishTupleSerializer.SECRET_KEY, secretKey);
    Kryo kryo = SerializationFactory.getKryo(conf);
    Assert.assertEquals(arbitraryClass, kryo.getSerializer(ListDelegate.class).getClass());
}
Also used : BlowfishTupleSerializer(org.apache.storm.security.serialization.BlowfishTupleSerializer) Map(java.util.Map) Kryo(com.esotericsoftware.kryo.Kryo) Test(org.junit.Test)

Example 14 with Kryo

use of com.esotericsoftware.kryo.Kryo in project storm by apache.

the class SerializationFactoryTest method test_registers_default_when_not_in_conf.

@Test
public void test_registers_default_when_not_in_conf() throws ClassNotFoundException {
    Map conf = Utils.readDefaultConfig();
    String className = (String) conf.get(Config.TOPOLOGY_TUPLE_SERIALIZER);
    Class configuredClass = Class.forName(className);
    Kryo kryo = SerializationFactory.getKryo(conf);
    Assert.assertEquals(configuredClass, kryo.getSerializer(ListDelegate.class).getClass());
}
Also used : Map(java.util.Map) Kryo(com.esotericsoftware.kryo.Kryo) Test(org.junit.Test)

Example 15 with Kryo

use of com.esotericsoftware.kryo.Kryo in project storm by nathanmarz.

the class SerializationFactory method getKryo.

public static Kryo getKryo(Map conf) {
    IKryoFactory kryoFactory = (IKryoFactory) Utils.newInstance((String) conf.get(Config.TOPOLOGY_KRYO_FACTORY));
    Kryo k = kryoFactory.getKryo(conf);
    k.register(byte[].class);
    /* tuple payload serializer is specified via configuration */
    String payloadSerializerName = (String) conf.get(Config.TOPOLOGY_TUPLE_SERIALIZER);
    try {
        Class serializerClass = Class.forName(payloadSerializerName);
        Serializer serializer = resolveSerializerInstance(k, ListDelegate.class, serializerClass, conf);
        k.register(ListDelegate.class, serializer);
    } catch (ClassNotFoundException ex) {
        throw new RuntimeException(ex);
    }
    k.register(ArrayList.class, new ArrayListSerializer());
    k.register(HashMap.class, new HashMapSerializer());
    k.register(HashSet.class, new HashSetSerializer());
    k.register(BigInteger.class, new BigIntegerSerializer());
    k.register(TransactionAttempt.class);
    k.register(Values.class);
    k.register(backtype.storm.metric.api.IMetricsConsumer.DataPoint.class);
    k.register(backtype.storm.metric.api.IMetricsConsumer.TaskInfo.class);
    try {
        JavaBridge.registerPrimitives(k);
        JavaBridge.registerCollections(k);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    Map<String, String> registrations = normalizeKryoRegister(conf);
    kryoFactory.preRegister(k, conf);
    boolean skipMissing = (Boolean) conf.get(Config.TOPOLOGY_SKIP_MISSING_KRYO_REGISTRATIONS);
    for (String klassName : registrations.keySet()) {
        String serializerClassName = registrations.get(klassName);
        try {
            Class klass = Class.forName(klassName);
            Class serializerClass = null;
            if (serializerClassName != null)
                serializerClass = Class.forName(serializerClassName);
            if (serializerClass == null) {
                k.register(klass);
            } else {
                k.register(klass, resolveSerializerInstance(k, klass, serializerClass, conf));
            }
        } catch (ClassNotFoundException e) {
            if (skipMissing) {
                LOG.info("Could not find serialization or class for " + serializerClassName + ". Skipping registration...");
            } else {
                throw new RuntimeException(e);
            }
        }
    }
    kryoFactory.postRegister(k, conf);
    if (conf.get(Config.TOPOLOGY_KRYO_DECORATORS) != null) {
        for (String klassName : (List<String>) conf.get(Config.TOPOLOGY_KRYO_DECORATORS)) {
            try {
                Class klass = Class.forName(klassName);
                IKryoDecorator decorator = (IKryoDecorator) klass.newInstance();
                decorator.decorate(k);
            } catch (ClassNotFoundException e) {
                if (skipMissing) {
                    LOG.info("Could not find kryo decorator named " + klassName + ". Skipping registration...");
                } else {
                    throw new RuntimeException(e);
                }
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            }
        }
    }
    kryoFactory.postDecorate(k, conf);
    return k;
}
Also used : ArrayListSerializer(backtype.storm.serialization.types.ArrayListSerializer) HashMapSerializer(backtype.storm.serialization.types.HashMapSerializer) HashSetSerializer(backtype.storm.serialization.types.HashSetSerializer) BigIntegerSerializer(com.esotericsoftware.kryo.serializers.DefaultSerializers.BigIntegerSerializer) ArrayList(java.util.ArrayList) List(java.util.List) Kryo(com.esotericsoftware.kryo.Kryo) HashMapSerializer(backtype.storm.serialization.types.HashMapSerializer) HashSetSerializer(backtype.storm.serialization.types.HashSetSerializer) ListDelegateSerializer(backtype.storm.serialization.types.ListDelegateSerializer) Serializer(com.esotericsoftware.kryo.Serializer) BigIntegerSerializer(com.esotericsoftware.kryo.serializers.DefaultSerializers.BigIntegerSerializer) ArrayListSerializer(backtype.storm.serialization.types.ArrayListSerializer)

Aggregations

Kryo (com.esotericsoftware.kryo.Kryo)71 Input (com.esotericsoftware.kryo.io.Input)31 Output (com.esotericsoftware.kryo.io.Output)29 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 ByteArrayInputStream (java.io.ByteArrayInputStream)16 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)13 Test (org.junit.Test)10 Test (org.testng.annotations.Test)8 ArrayList (java.util.ArrayList)6 BigIntegerSerializer (com.esotericsoftware.kryo.serializers.DefaultSerializers.BigIntegerSerializer)5 File (java.io.File)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 List (java.util.List)5 Map (java.util.Map)5 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 ArrayListSerializer (backtype.storm.serialization.types.ArrayListSerializer)3 HashMapSerializer (backtype.storm.serialization.types.HashMapSerializer)3 HashSetSerializer (backtype.storm.serialization.types.HashSetSerializer)3 Serializer (com.esotericsoftware.kryo.Serializer)3