void addToList(Object toAdd) { if (toAdd instanceof Undefined) { // Missing argument do nothing... return; } if (toAdd instanceof XMLList) { XMLList xmlSrc = (XMLList)toAdd; for (int i = 0; i < xmlSrc.length(); i++) { this._add((xmlSrc.item(i)).getAnnotation()); } } else if (toAdd instanceof XML) { this._add(((XML)(toAdd)).getAnnotation()); } else if (toAdd instanceof XmlNode) { this._add((XmlNode)toAdd); } }
Scriptable compile(Context cx, Scriptable scope, Object[] args) { if (args.length > 0 && args[0] instanceof NativeRegExp) { if (args.length > 1 && args[1] != Undefined.instance) { // report error throw ScriptRuntime.typeError0("msg.bad.regexp.compile"); } NativeRegExp thatObj = (NativeRegExp) args[0]; this.re = thatObj.re; this.lastIndex = thatObj.lastIndex; return this; } String s = args.length == 0 || args[0] instanceof Undefined ? "" : escapeRegExp(args[0]); String global = args.length > 1 && args[1] != Undefined.instance ? ScriptRuntime.toString(args[1]) : null; this.re = compileRE(cx, s, global, false); this.lastIndex = 0d; return this; }
@Override protected boolean stepExecute(Context javascriptContext, Scriptable scope) throws EngineException { variables.clear(); if (isEnabled()) { for (RequestableVariable var : getParentSequence().getAllVariables()) { try { //evaluate(javascriptContext, scope, var.getName(), "expression", true); evaluated = scope.get(var.getName(), scope); if (evaluated != null && !(evaluated instanceof Undefined)) { if (evaluated instanceof NativeJavaObject) { evaluated = ((NativeJavaObject) evaluated).unwrap(); } variables.put(var.getName(), evaluated); } } catch (Exception e) { evaluated = null; Engine.logBeans.warn(e.getMessage()); } } return super.stepExecute(javascriptContext, scope); } return false; }
@Override public Object getParameterValue(String parameterName) throws EngineException { Object variableValue = null; int variableVisibility = getVariableVisibility(parameterName); // Scope parameter if (scope != null) { variableValue = scope.get(parameterName, scope); if (variableValue instanceof Undefined) variableValue = null; if (variableValue instanceof UniqueTag && ((UniqueTag) variableValue).equals(UniqueTag.NOT_FOUND)) variableValue = null; if (variableValue != null) Engine.logBeans.trace("(SqlTransaction) scope value: "+ Visibility.Logs.printValue(variableVisibility,variableValue)); } if (variableValue == null) { variableValue = super.getParameterValue(parameterName); } return variableValue = ((variableValue == null)? new String(""):variableValue); }
protected Integer evaluateToInteger(Context javascriptContext, Scriptable scope, String source, String sourceName, boolean bDialog) throws EngineException { Integer value = getValueOfInteger(source); if (value == null) { evaluate(javascriptContext, scope, source, sourceName, true); if (evaluated instanceof Undefined || evaluated.equals("")) value = -1; else if (evaluated instanceof Number) { value = Integer.valueOf(((Number)evaluated).intValue()); } else { try {value = Integer.valueOf(String.valueOf(evaluated), 10);} catch (NumberFormatException nfe) {} } if (value == null) { EngineException ee = new EngineException( "Invalid \""+sourceName+"\" value.\n" + "Step: \"" + getName()+ "\""); throw ee; } } return value; }
Scriptable compile(Context cx, Scriptable scope, Object[] args) { if (args.length > 0 && args[0] instanceof NativeRegExp) { if (args.length > 1 && args[1] != Undefined.instance) { // report error throw ScriptRuntime.typeError0("msg.bad.regexp.compile"); } NativeRegExp thatObj = (NativeRegExp) args[0]; this.re = thatObj.re; this.lastIndex = thatObj.lastIndex; return this; } String s = args.length == 0 ? "" : ScriptRuntime.toString(args[0]); String global = args.length > 1 && args[1] != Undefined.instance ? ScriptRuntime.toString(args[1]) : null; this.re = (RECompiled)compileRE(cx, s, global, false); this.lastIndex = 0; return this; }
Scriptable compile(Context cx, Scriptable scope, Object[] args) { if (args.length > 0 && args[0] instanceof NativeRegExp) { if (args.length > 1 && args[1] != Undefined.instance) { // report error throw ScriptRuntime.typeError0("msg.bad.regexp.compile"); } NativeRegExp thatObj = (NativeRegExp) args[0]; this.re = thatObj.re; this.lastIndex = thatObj.lastIndex; return this; } String s = args.length == 0 ? "" : escapeRegExp(args[0]); String global = args.length > 1 && args[1] != Undefined.instance ? ScriptRuntime.toString(args[1]) : null; this.re = compileRE(cx, s, global, false); this.lastIndex = 0; return this; }
private void importVariables(@NonNull ScriptableObject scope) throws StethoJsException { // Define the variables for (Map.Entry<String, Object> entrySet : mVariables.entrySet()) { String varName = entrySet.getKey(); Object varValue = entrySet.getValue(); try { Object jsValue; if (varValue instanceof Scriptable || varValue instanceof Undefined) { jsValue = varValue; } else { jsValue = Context.javaToJS(varValue, scope); } ScriptableObject.putProperty(scope, varName, jsValue); } catch (Exception e) { throw new StethoJsException(e, "Failed to setup variable: %s", varName); } } }
@Override public Object wrap(Context cx, Scriptable scope, Object obj, Class<?> staticType) { if (obj == null || obj == Undefined.instance || obj instanceof Scriptable) { return obj; } if (staticType != null) { if (obj instanceof String || obj instanceof Number || obj instanceof Boolean || obj instanceof Character) { return Context.javaToJS(obj, scope); } } if (obj.getClass().isArray()) { if (obj.getClass().getComponentType() != Object.class) { Object[] array = new Object[Array.getLength(obj)]; for (int i = 0; i < array.length; i++) { array[i] = Context.javaToJS(Array.get(obj, i), scope); } return cx.newArray(scope, array); } } return super.wrap(cx, scope, obj, staticType); }
public Object getValueFromView(Object view, String[] path) { if(view instanceof Scriptable) { Scriptable o = (Scriptable)view; for(int i = 0; i < path.length; ++i) { if(o == null || (o instanceof Undefined)) { return null; } Object value = ScriptableObject.getProperty(o, path[i]); if(value instanceof Scriptable) { o = (Scriptable)value; } else { // Scriptable values can be any Object, allow this in last entry in path if(i == (path.length - 1)) { return hasValue(value) ? value : null; } o = null; } } return hasValue(o) ? o : null; } else if(path.length == 0) { return view; // to allow . value to work } return null; }
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { InvocableMember<?> nearestInvocable = getNearestObjectFunction(args, objectFunctions); if (nearestInvocable == null) { throw new FunctionException("Unable to match nearest function"); } FunctionMember nearestFunctionObject = (FunctionMember)nearestInvocable; Method functionMethod = nearestFunctionObject.getMember(); Class<?> returnType = functionMethod.getReturnType(); Class<?> expectedTypes[] = functionMethod.getParameterTypes(); Object[] castedArgs = castArgs(expectedTypes, args); try { Object returned = functionMethod.invoke(object, castedArgs); return (returnType == Void.class)? Undefined.instance : returned; } catch (Exception e) { throw new UnknownException("Unable to invoke function " + nearestFunctionObject.getName(), e); } }
Scriptable compile(Context cx, Scriptable scope, Object[] args) { if (args.length > 0 && args[0] instanceof NativeRegExp) { if (args.length > 1 && args[1] != Undefined.instance) { // report error throw ScriptRuntime.typeError0("msg.bad.regexp.compile"); } NativeRegExp thatObj = (NativeRegExp) args[0]; this.re = thatObj.re; this.lastIndex = thatObj.lastIndex; return this; } String s = args.length == 0 || args[0] instanceof Undefined ? "" : escapeRegExp(args[0]); String global = args.length > 1 && args[1] != Undefined.instance ? ScriptRuntime.toString(args[1]) : null; this.re = compileRE(cx, s, global, false); this.lastIndex = 0; return this; }
/** * Wraps {@link Configuration#setInt(String, int)}. * * @param ctx the JavaScript context (unused) * @param thisObj the 'this' object of the caller * @param args the arguments for the call * @param func the function called (unused) * * @return this */ @JSFunction public static Object setInt(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 (!(arg1 instanceof Number)) { throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_ARG_MUST_BE_NUM); } ((ConfigurationWrap)thisObj).conf.setInt(arg0.toString(), JavaScriptUtils.fromNumber(arg1).intValue()); return thisObj; }
/** * Wraps {@link CounterGroup#findCounter(String)}. * * @param ctx the JavaScript context (unused) * @param thisObj the 'this' object of the caller * @param args the arguments for the call * @param func the function called (unused) * * @return the counter */ @JSFunction public static Object findCounter(final Context ctx, final Scriptable thisObj, final Object[] args, final Function func) { final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance; if (args.length < 1) { throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED); } else if (!JavaScriptUtils.isDefined(arg0)) { throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED); } final CounterGroupWrap self = (CounterGroupWrap)thisObj; final Counter counter = self.counterGroup.findCounter(arg0.toString()); CounterWrap counterWrap = null; if (counter != null) { counterWrap = CounterWrap.getInstance(self.runtime, counter); } return counterWrap == null ? Undefined.instance : counterWrap; }
/** * Wraps {@link Counters#incrAllCounters(Counters)}. * * @param ctx the JavaScript context (unused) * @param thisObj the 'this' object of the caller * @param args the arguments for the call * @param func the function called (unused) * * @return this */ @JSFunction public static Object incrAllCounters(final Context ctx, final Scriptable thisObj, final Object[] args, final Function func) { final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance; if (!JavaScriptUtils.isDefined(arg0)) { throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED); } else if (!(arg0 instanceof CountersWrap)) { throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_COUNTERS); } ((CountersWrap)thisObj).counters.incrAllCounters(((CountersWrap)arg0).counters); return thisObj; }
/** * Wraps {@link Counters#getGroup(String)}. * * @param ctx the JavaScript context (unused) * @param thisObj the 'this' object of the caller * @param args the arguments for the call * @param func the function called (unused) * * @return the counter group */ @JSFunction public static Object getGroup(final Context ctx, final Scriptable thisObj, final Object[] args, final Function func) { final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance; if (args.length < 1) { throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED); } else if (!JavaScriptUtils.isDefined(arg0)) { throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED); } final CountersWrap self = (CountersWrap)thisObj; final CounterGroup counterGroup = self.counters.getGroup(arg0.toString()); CounterGroupWrap counterGroupWrap = null; if (counterGroup != null) { counterGroupWrap = CounterGroupWrap.getInstance(self.runtime, counterGroup); } return counterGroupWrap == null ? Undefined.instance : counterGroupWrap; }
/** * Java wrapper for {@link FileInputFormat#getMinSplitSize(JobContext)}. * * @param clazz the class to invoke the method of * @param ctx the JavaScript context * @param thisObj the 'this' object * @param args the function arguments * * @return the max split size */ public static Object getMinSplitSize(final Class<?> clazz, final Context ctx, final Scriptable thisObj, final Object[] args) { validateClass(clazz, ctx, thisObj); final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance; if (args.length < 1) { throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED); } else if (!JavaScriptUtils.isDefined(arg0)) { throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED); } else if (!(arg0 instanceof JobWrap)) { throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_JOB); } try { return ReflectionUtils.invokeStatic(clazz, "getMinSplitSize", new Class<?>[] { JobContext.class }, new Object[] { ((JobWrap)arg0).getJob() }); } catch (Exception e) { e.printStackTrace(); throw Utils.makeError(ctx, thisObj, e.getMessage()); } }
/** * Wraps {@link Counter#increment(long)}. * * @param ctx the JavaScript context (unused) * @param thisObj the 'this' object of the caller * @param args the arguments for the call * @param func the function called (unused) * * @return this */ @JSFunction public static Object increment(final Context ctx, final Scriptable thisObj, final Object[] args, final Function func) { final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance; if (!JavaScriptUtils.isDefined(arg0)) { throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED); } else if (!(arg0 instanceof Number)) { throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_NUM); } ((CounterWrap)thisObj).counter.increment(JavaScriptUtils.fromNumber(arg0).longValue()); return thisObj; }
/** * Wraps {@link Job#getCounters()}. * * @param ctx the JavaScript context (unused) * @param thisObj the 'this' object of the caller * @param args the arguments for the call * @param func the function called (unused) * * @return the counters wrapper */ @JSFunction public static Object getCounters(final Context ctx, final Scriptable thisObj, final Object[] args, final Function func) { final JobWrap self = (JobWrap)thisObj; Counters counters; try { counters = self.job.getCounters(); } catch (IOException e) { throw Utils.makeError(ctx, thisObj, e.getMessage()); } CountersWrap countersWrap = null; if (counters != null) { countersWrap = CountersWrap.getInstance(self.runtime, counters); } return countersWrap == null ? Undefined.instance : countersWrap; }
/** * Wraps {@link Configuration#setFloat(String, float)}. * * @param ctx the JavaScript context (unused) * @param thisObj the 'this' object of the caller * @param args the arguments for the call * @param func the function called (unused) * * @return this */ @JSFunction public static Object setFloat(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 (!(arg1 instanceof Number)) { throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_ARG_MUST_BE_NUM); } ((ConfigurationWrap)thisObj).conf.setFloat(arg0.toString(), JavaScriptUtils.fromNumber(arg1).floatValue()); return thisObj; }
private Object jsToPigMap(Scriptable object, Schema schema, int depth) { debugConvertJSToPig(depth, "Map", object, schema); Map<String, Object> map = new HashMap<String, Object>(); Object[] ids = object.getIds(); for (Object id : ids) { if (id instanceof String) { String name = (String) id; Object value = object.get(name, object); if (value instanceof NativeJavaObject) { value = ((NativeJavaObject)value).unwrap(); } else if (value instanceof Undefined) { value = null; } map.put(name, value); } } debugReturn(depth, map); return map; }
@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { InvocableMember<?> nearestInvocable = getNearestObjectFunction(args, objectFunctions); if (nearestInvocable == null) { throw new FunctionException("Unable to match nearest function"); } FunctionMember nearestFunctionObject = (FunctionMember)nearestInvocable; Method functionMethod = nearestFunctionObject.getMember(); Class<?> returnType = functionMethod.getReturnType(); Class<?> expectedTypes[] = functionMethod.getParameterTypes(); Object[] castedArgs = castArgs(expectedTypes, args); try { Object returned = functionMethod.invoke(object, castedArgs); return (returnType == Void.class)? Undefined.instance : returned; } catch (Exception e) { throw new UnknownException(e); } }
public JsFunction(String functionName) { this.jsScriptEngine = JsScriptEngine.getInstance(); this.functionName = functionName; Object outputSchemaObj = jsScriptEngine.jsEval(this.getClass().getName() + "(String)", functionName + ".outputSchema"); //if no schema defined, fall back to bytearray if (outputSchemaObj == null || outputSchemaObj instanceof Undefined) { this.outputSchema = new Schema(new Schema.FieldSchema(null, DataType.BYTEARRAY)); } else { try { this.outputSchema = Utils.getSchemaFromString(outputSchemaObj.toString()); } catch (ParserException e) { throw new IllegalArgumentException(functionName + ".outputSchema is not a valid schema: " + e.getMessage(), e); } } }
/** * Java wrapper for {@link NLineInputFormat#setNumLinesPerSplit(org.apache.hadoop.mapreduce.Job, int)}. * * @param ctx the JavaScript context * @param thisObj the 'this' object * @param args the function arguments * @param func the function called (unused) */ @JSStaticFunction public static void setNumLinesPerSplit(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 JobWrap)) { throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_JOB); } else if (!(arg1 instanceof Number)) { throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_ARG_MUST_BE_NUM); } NLineInputFormat.setNumLinesPerSplit(((JobWrap)arg0).getJob(), JavaScriptUtils.fromNumber(arg1).intValue()); }
/** * Java wrapper for {@link FileInputFormat#getMaxSplitSize(JobContext)}. * * @param clazz the class to invoke the method of * @param ctx the JavaScript context * @param thisObj the 'this' object * @param args the function arguments * * @return the max split size */ public static Object getMaxSplitSize(final Class<?> clazz, final Context ctx, final Scriptable thisObj, final Object[] args) { validateClass(clazz, ctx, thisObj); final Object arg0 = args.length >= 1 ? args[0] : Undefined.instance; if (args.length < 1) { throw Utils.makeError(ctx, thisObj, LembosMessages.ONE_ARG_EXPECTED); } else if (!JavaScriptUtils.isDefined(arg0)) { throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_REQUIRED); } else if (!(arg0 instanceof JobWrap)) { throw Utils.makeError(ctx, thisObj, LembosMessages.FIRST_ARG_MUST_BE_JOB); } try { return ReflectionUtils.invokeStatic(clazz, "getMaxSplitSize", new Class<?>[] { JobContext.class }, new Object[] { ((JobWrap)arg0).getJob() }); } catch (Exception e) { e.printStackTrace(); throw Utils.makeError(ctx, thisObj, e.getMessage()); } }
/** * Java wrapper for {@link DistributedCache#addArchiveToClassPath(Path, Configuration)} and * {@link DistributedCache#addArchiveToClassPath(Path, Configuration, org.apache.hadoop.fs.FileSystem)}. * * @param ctx the JavaScript context * @param thisObj the 'this' object * @param args the function arguments * @param func the function being called */ @JSStaticFunction public static void addArchiveToClassPath(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 (!(arg1 instanceof ConfigurationWrap)) { throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_CONF); } final Configuration conf = ((ConfigurationWrap)arg1).getConf(); final Path path = new Path(URI.create(arg0.toString())); try { DistributedCache.addArchiveToClassPath(path, conf, path.getFileSystem(conf)); } catch (IOException e) { throw Utils.makeError(ctx, thisObj, e.getMessage()); } }
/** * Java wrapper for {@link DistributedCache#addCacheArchive(URI, Configuration)}. * * @param ctx the JavaScript context * @param thisObj the 'this' object * @param args the function arguments * @param func the function being called */ @JSStaticFunction public static void addCacheArchive(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 (!(arg1 instanceof ConfigurationWrap)) { throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_CONF); } DistributedCache.addCacheArchive(URI.create(arg0.toString()), ((ConfigurationWrap)arg1).getConf()); }
/** * Java wrapper for {@link DistributedCache#addCacheFile(URI, Configuration)}. * * @param ctx the JavaScript context * @param thisObj the 'this' object * @param args the function arguments * @param func the function being called */ @JSStaticFunction public static void addCacheFile(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 (!(arg1 instanceof ConfigurationWrap)) { throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_CONF); } DistributedCache.addCacheFile(URI.create(arg0.toString()), ((ConfigurationWrap)arg1).getConf()); }
/** * Java wrapper for {@link DistributedCache#addFileToClassPath(Path, Configuration)} and * {@link DistributedCache#addFileToClassPath(Path, Configuration, org.apache.hadoop.fs.FileSystem)}. * * @param ctx the JavaScript context * @param thisObj the 'this' object * @param args the function arguments * @param func the function being called */ @JSStaticFunction public static void addFileToClassPath(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 (!(arg1 instanceof ConfigurationWrap)) { throw Utils.makeError(ctx, thisObj, LembosMessages.SECOND_ARG_MUST_BE_CONF); } final Configuration conf = ((ConfigurationWrap)arg1).getConf(); final Path path = new Path(URI.create(arg0.toString())); try { DistributedCache.addFileToClassPath(path, conf, path.getFileSystem(conf)); } catch (IOException e) { throw Utils.makeError(ctx, thisObj, e.getMessage()); } }
/** * Java wrapper for {@link DistributedCache#addLocalArchives(Configuration, String)}. * * @param ctx the JavaScript context * @param thisObj the 'this' object * @param args the function arguments * @param func the function being called */ @JSStaticFunction public static void addLocalArchives(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); } DistributedCache.addLocalArchives(((ConfigurationWrap)arg0).getConf(), arg1.toString()); }
/** * Java wrapper for {@link DistributedCache#addLocalFiles(Configuration, String)}. * * @param ctx the JavaScript context * @param thisObj the 'this' object * @param args the function arguments * @param func the function being called */ @JSStaticFunction public static void addLocalFiles(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); } DistributedCache.addLocalFiles(((ConfigurationWrap)arg0).getConf(), arg1.toString()); }