Search in sources :

Example 1 with HadoopClassLoader

use of org.apache.ignite.internal.processors.hadoop.HadoopClassLoader in project ignite by apache.

the class IgniteHadoopIgfsSecondaryFileSystem method start.

/** {@inheritDoc} */
@Override
public void start() throws IgniteException {
    HadoopClassLoader ldr = ctx.hadoopHelper().commonClassLoader();
    ClassLoader oldLdr = HadoopCommonUtils.setContextClassLoader(ldr);
    try {
        target = HadoopDelegateUtils.secondaryFileSystemDelegate(ldr, this);
        target.start();
    } finally {
        HadoopCommonUtils.restoreContextClassLoader(oldLdr);
    }
}
Also used : HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader) HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader)

Example 2 with HadoopClassLoader

use of org.apache.ignite.internal.processors.hadoop.HadoopClassLoader in project ignite by apache.

the class HadoopSnappyTest method testSnappy.

/**
     * Checks Snappy codec usage.
     *
     * @throws Exception On error.
     */
public void testSnappy() throws Throwable {
    // Run Snappy test in default class loader:
    checkSnappy();
    // Run the same in several more class loaders simulating jobs and tasks:
    for (int i = 0; i < 2; i++) {
        ClassLoader hadoopClsLdr = new HadoopClassLoader(null, "cl-" + i, null, new HadoopHelperImpl());
        Class<?> cls = (Class) Class.forName(HadoopSnappyTest.class.getName(), true, hadoopClsLdr);
        assertEquals(hadoopClsLdr, cls.getClassLoader());
        U.invoke(cls, null, "checkSnappy");
    }
}
Also used : HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader) HadoopHelperImpl(org.apache.ignite.internal.processors.hadoop.HadoopHelperImpl) HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader)

Example 3 with HadoopClassLoader

use of org.apache.ignite.internal.processors.hadoop.HadoopClassLoader in project ignite by apache.

the class HadoopJobTracker method start.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public void start(final HadoopContext ctx) throws IgniteCheckedException {
    super.start(ctx);
    busyLock = new GridSpinReadWriteLock();
    evtProcSvc = Executors.newFixedThreadPool(1);
    assert jobCls == null;
    HadoopClassLoader ldr = ctx.kernalContext().hadoopHelper().commonClassLoader();
    try {
        jobCls = (Class<HadoopJobEx>) ldr.loadClass(HadoopCommonUtils.JOB_CLS_NAME);
    } catch (Exception ioe) {
        throw new IgniteCheckedException("Failed to load job class [class=" + HadoopCommonUtils.JOB_CLS_NAME + ']', ioe);
    }
}
Also used : HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader) GridSpinReadWriteLock(org.apache.ignite.internal.util.GridSpinReadWriteLock) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HadoopJobEx(org.apache.ignite.internal.processors.hadoop.HadoopJobEx) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) HadoopTaskCancelledException(org.apache.ignite.internal.processors.hadoop.HadoopTaskCancelledException)

Example 4 with HadoopClassLoader

use of org.apache.ignite.internal.processors.hadoop.HadoopClassLoader in project ignite by apache.

the class HadoopV2Job method getTaskContext.

/** {@inheritDoc} */
@SuppressWarnings({ "unchecked", "MismatchedQueryAndUpdateOfCollection" })
@Override
public HadoopTaskContext getTaskContext(HadoopTaskInfo info) throws IgniteCheckedException {
    T2<HadoopTaskType, Integer> locTaskId = new T2<>(info.type(), info.taskNumber());
    GridFutureAdapter<HadoopTaskContext> fut = ctxs.get(locTaskId);
    if (fut != null)
        return fut.get();
    GridFutureAdapter<HadoopTaskContext> old = ctxs.putIfAbsent(locTaskId, fut = new GridFutureAdapter<>());
    if (old != null)
        return old.get();
    Class<? extends HadoopTaskContext> cls = taskCtxClsPool.poll();
    try {
        if (cls == null) {
            // If there is no pooled class, then load new one.
            // Note that the classloader identified by the task it was initially created for,
            // but later it may be reused for other tasks.
            HadoopClassLoader ldr = sharedClsLdr != null ? sharedClsLdr : createClassLoader(HadoopClassLoader.nameForTask(info, false));
            cls = (Class<? extends HadoopTaskContext>) ldr.loadClass(HadoopV2TaskContext.class.getName());
            fullCtxClsQueue.add(cls);
        }
        Constructor<?> ctr = cls.getConstructor(HadoopTaskInfo.class, HadoopJobEx.class, HadoopJobId.class, UUID.class, DataInput.class);
        if (jobConfData == null)
            synchronized (jobConf) {
                if (jobConfData == null) {
                    ByteArrayOutputStream buf = new ByteArrayOutputStream();
                    jobConf.write(new DataOutputStream(buf));
                    jobConfData = buf.toByteArray();
                }
            }
        HadoopTaskContext res = (HadoopTaskContext) ctr.newInstance(info, this, jobId, locNodeId, new DataInputStream(new ByteArrayInputStream(jobConfData)));
        fut.onDone(res);
        return res;
    } catch (Throwable e) {
        IgniteCheckedException te = transformException(e);
        fut.onDone(te);
        if (e instanceof Error)
            throw (Error) e;
        throw te;
    }
}
Also used : HadoopClassLoader(org.apache.ignite.internal.processors.hadoop.HadoopClassLoader) HadoopTaskType(org.apache.ignite.internal.processors.hadoop.HadoopTaskType) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) DataInputStream(java.io.DataInputStream) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) ByteArrayInputStream(java.io.ByteArrayInputStream) HadoopTaskContext(org.apache.ignite.internal.processors.hadoop.HadoopTaskContext) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) T2(org.apache.ignite.internal.util.typedef.T2)

Aggregations

HadoopClassLoader (org.apache.ignite.internal.processors.hadoop.HadoopClassLoader)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 HadoopHelperImpl (org.apache.ignite.internal.processors.hadoop.HadoopHelperImpl)1 HadoopJobEx (org.apache.ignite.internal.processors.hadoop.HadoopJobEx)1 HadoopTaskCancelledException (org.apache.ignite.internal.processors.hadoop.HadoopTaskCancelledException)1 HadoopTaskContext (org.apache.ignite.internal.processors.hadoop.HadoopTaskContext)1 HadoopTaskType (org.apache.ignite.internal.processors.hadoop.HadoopTaskType)1 GridSpinReadWriteLock (org.apache.ignite.internal.util.GridSpinReadWriteLock)1 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)1 T2 (org.apache.ignite.internal.util.typedef.T2)1