Example usage for org.apache.hadoop.filecache DistributedCache getFileStatus

List of usage examples for org.apache.hadoop.filecache DistributedCache getFileStatus

Introduction

In this page you can find the example usage for org.apache.hadoop.filecache DistributedCache getFileStatus.

Prototype

@Deprecated
public static FileStatus getFileStatus(Configuration conf, URI cache) throws IOException 

Source Link

Document

Returns FileStatus of a given cache file on hdfs.

Usage

From source file:io.apigee.lembos.node.types.DistributedCacheWrap.java

License:Apache License

/**
 * Java wrapper for {@link DistributedCache#getFileStatus(Configuration, URI)}.
 *
 * @param ctx the JavaScript context//from  www  .  j  ava2 s.c  o m
 * @param thisObj the 'this' object
 * @param args the function arguments
 * @param func the function being called
 *
 * @return array of archive class paths
 */
@JSStaticFunction
public static Object getFileStatus(final Context ctx, final Scriptable thisObj, final Object[] args,
        final Function func) {
    final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance;
    final Object arg1 = args.length >= 2 ? args[1] : Undefined.instance;

    if (args.length < 2) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.TWO_ARGS_EXPECTED);
    } else if (!JavaScriptUtils.isDefined(arg0)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED);
    } else if (!JavaScriptUtils.isDefined(arg1)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_REQUIRED);
    } else if (!(arg0 instanceof ConfigurationWrap)) {
        throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_CONF);
    }

    final URI hdfsUri = URI.create(arg1.toString());
    FileStatus status;

    try {
        status = DistributedCache.getFileStatus(((ConfigurationWrap) arg0).getConf(), hdfsUri);
    } catch (IOException e) {
        throw Utils.makeError(ctx, thisObj, e.getMessage());
    }

    if (status == null) {
        throw Utils.makeError(ctx, thisObj, "Unable to get file status for HDFS uri: " + hdfsUri.toString());
    }

    final Scriptable jsStatus = ctx.newObject(thisObj);

    ScriptableObject.defineProperty(jsStatus, "accessTime", status.getAccessTime(), ScriptableObject.READONLY);
    ScriptableObject.defineProperty(jsStatus, "blockSize", status.getBlockSize(), ScriptableObject.READONLY);
    ScriptableObject.defineProperty(jsStatus, "group", status.getGroup(), ScriptableObject.READONLY);
    ScriptableObject.defineProperty(jsStatus, "len", status.getLen(), ScriptableObject.READONLY);
    ScriptableObject.defineProperty(jsStatus, "modificationTime", status.getModificationTime(),
            ScriptableObject.READONLY);
    ScriptableObject.defineProperty(jsStatus, "owner", status.getOwner(), ScriptableObject.READONLY);
    ScriptableObject.defineProperty(jsStatus, "path", status.getPath().toString(), ScriptableObject.READONLY);
    ScriptableObject.defineProperty(jsStatus, "permission", status.getPermission().toString(),
            ScriptableObject.READONLY);
    ScriptableObject.defineProperty(jsStatus, "replication", status.getReplication(),
            ScriptableObject.READONLY);

    return jsStatus;
}