@Override public void remove(String raptureURI) { api.getDoc().deleteDoc(raptureURI); }
@Override public Map<String, byte[]> call() throws Exception { log.info(String.format("Cache miss, loading classes for jar [%s]", jarUri)); BlobContainer bc = api.getJar().getJar(jarUri); if (bc == null) { throw new ExecutionException(String.format("No jar found at uri [%s]", jarUri), null); } try { return JarUtils.getClassNamesAndBytesFromJar(bc.getContent()); } catch (IOException e) { throw new ExecutionException("IOException extracting classes and bytes from jar", e); } } });
@Override public void printLog(String text) { task.getStatus().addToOutput(text); if (api != null) { api.getPipeline().publishTopicMessage("main", "raptureTopic", "reflexOut", text); } }
public ReflexValue pullData(RaptureURI uri) { switch (uri.getScheme()) { case DOCUMENT: String strContent = api.getDoc().getDoc(uri.toString()); return (strContent == null) ? new ReflexNullValue() List<SeriesPoint> series = api.getSeries().getPoints(uri.toString()); ReflexValue retSeries = new ReflexValue(series); return retSeries; BlobContainer blobContainer = api.getBlob().getBlob(uri.toString()); if (blobContainer == null) return null; String input = new String(blobContainer.getContent());
String blobEndPoint = handler.getApi().getEndPoint() + "/blob/"; String sourceString = sourceVal.asString(); if (sourceString.startsWith("blob://")) { String myCookie = "raptureContext=" + handler.getApi().getSerializedContext(); conn.setRequestProperty("Cookie", myCookie); ReadableByteChannel rbc = Channels.newChannel(conn.getInputStream());
@Override public String getScript(String name) { name = URIParser.convertDocURI(name); return api.getScript().getScript(name).getScript(); }
protected ReflexValue writeAudit(IReflexDebugger debugger, String comment) { if (disableAudit) return new ReflexVoidValue(); // scope.setPendingComment(comment); if (handler.getApi() == null) { String errorMessage = "API is null - " + comment; log.error(errorMessage); System.err.println(errorMessage); return new ReflexVoidValue(); } debugger.stepStart(this, scope); handler.getApi().getAudit().writeAuditEntry(RaptureConstants.DEFAULT_AUDIT_URI, "reflex", 0, comment); ReflexValue reflexRetVal = new ReflexVoidValue(); debugger.stepEnd(this, reflexRetVal, scope); return reflexRetVal; }
@Override public ReflexValue evaluate(IReflexDebugger debugger, Scope scope) { debugger.stepStart(this, scope); if (handler.getApi() == null) { throw new ReflexException(lineNumber, "There is no api handler registered"); } List<ReflexValue> callParams = new ArrayList<ReflexValue>(params.size()); // Now coerce the types... for (int i = 0; i < params.size(); i++) { ReflexValue v = params.get(i).evaluate(debugger, scope); callParams.add(v); } debugger.recordMessage(String.format("Calling %s.%s", areaName, fnName)); ReflexValue retVal = new ReflexNullValue(lineNumber); ; if (sdkName == null) { retVal = KernelExecutor.executeFunction(lineNumber, handler.getApi(), areaName, fnName, callParams); } else { InstallableKernelScript sdkKernel = handler.getApi().getInstalledKernel(sdkName).getKernelScript(); if (sdkKernel == null) { throw new ReflexException(lineNumber, "NO installed kernel named " + sdkName + " found"); } else { retVal = KernelExecutor.executeFunction(lineNumber, sdkKernel, areaName, fnName, callParams); } } debugger.stepEnd(this, retVal, scope); return retVal; }
/** * Download the encoded contents from the specified client * * @return true if the contents were changed as a result of this call */ public boolean download(ScriptingApi client, boolean force) { if (force || needExtract()) { PluginTransportItem item = null; try { item = client.getPlugin().getPluginItem(uri.toString()); } catch (RaptureException ex) { return false; } if (item == null) return false; return setContentFromRemote(item.getContent(), item.getHash()); } return false; }
@Override public ReflexValue evaluate(IReflexDebugger debugger, Scope scope) { debugger.stepStart(this, scope); // Check on whether the value is a blob or a file String name = fileNameExpr.evaluate(debugger, scope).asString(); ReflexValue ret = new ReflexNullValue(); if (!name.startsWith("blob://")) { ReflexFileValue fVal = new ReflexFileValue(name); ret = new ReflexValue(fVal); } else { BlobContainer container = handler.getApi().getBlob().getBlob(name); ReflexStringStreamValue sVal = new ReflexStringStreamValue(); sVal.setContent(new String(container.getContent())); ret = new ReflexValue(sVal); } if (encodingNode != null) { ret.asFile().setEncoding(encodingNode.evaluate(debugger, scope).asString()); } if (fileType != null) { ReflexValue fileTypeValue = fileType.evaluate(debugger, scope); ReflexValue fileTypeValue1 = fileTypeExpr1 != null ? fileTypeExpr1.evaluate(debugger, scope) : new ReflexNullValue(); ReflexValue fileTypeValue2 = fileTypeExpr2 != null ? fileTypeExpr2.evaluate(debugger, scope) : new ReflexNullValue(); if (!fileTypeValue.isNull()) { ret.asStream().setFileType(fileTypeValue, fileTypeValue1.isNull() ? null : fileTypeValue1.asString(), fileTypeValue2.isNull() ? null : fileTypeValue2.asString()); } } debugger.stepEnd(this, ret, scope); return ret; }
if (val.isString()) api.getSeries().addStringToSeries(uriStr, l0.get(i).toString(), val.toString()); else if (val.isNumber()) api.getSeries().addDoubleToSeries(uriStr, l0.get(i).toString(), val.asDouble()); for (ReflexValue rv : series) { SeriesPoint sp = (SeriesPoint) rv.getValue(); api.getSeries().addStringToSeries(uriStr, sp.getColumn(), sp.getValue()); if (val.isString()) api.getSeries().addStringToSeries(newUri, entry.get(lengthExpect - 2).toString(), val.toString()); else if (val.isNumber()) api.getSeries().addDoubleToSeries(newUri, entry.get(lengthExpect - 2).toString(), val.asDouble()); } else throw new ReflexException(-1, "Cannot write " + data.getTypeAsString() + " to " + uri); api.getDoc().putDoc(uriStr, JacksonUtil.prettyfy(JacksonUtil.jsonFromObject(map))); break; byte[] bytes = data.asByteArray(); if (bytes == null) throw new ReflexException(-1, "Cannot write " + data.getTypeAsString() + " to " + uri); api.getBlob().putBlob(uriStr, bytes, metadata.toString()); break;
@Override public String rawPushData(String raptureURI, String content) { raptureURI = URIParser.convertDocURI(raptureURI); String ret = api.getDoc().putDoc(raptureURI, content); return ret; }
@Override public void printOutput(String text) { task.getStatus().addToOutput(text); if (api != null) { api.getPipeline().publishTopicMessage("main", "raptureTopic", "reflexOut", text); } }
public static List<String> expandWildcardUri(ScriptingApi api, String jarUriStr) { String jarUri = new RaptureURI(jarUriStr, Scheme.JAR).toString(); if (!jarUri.endsWith("*")) { return Arrays.asList(jarUri); } List<String> ret = new ArrayList<>(); String prefix = jarUri.substring(0, jarUri.indexOf("*")); Map<String, RaptureFolderInfo> jars = api.getJar().listJarsByUriPrefix(prefix, 1); for (Map.Entry<String, RaptureFolderInfo> entry : jars.entrySet()) { if (entry.getValue().isFolder()) { continue; } ret.add(prefix + entry.getValue().getName()); } Collections.sort(ret); return ret; }
@Override public void remove(String raptureURI) { raptureURI = URIParser.convertDocURI(raptureURI); api.getDoc().deleteDoc(raptureURI); }
@Override public String rawPushData(String raptureURI, String content) { raptureURI = URIParser.convertDocURI(raptureURI); String ret = api.getDoc().putDoc(raptureURI, content); return ret; }
@Override public List<String> batchPushRawData(List<String> displayNames, List<String> datas) { List<List<String>> displayBatches = TypeUtil.getBatches(displayNames, 50); List<List<String>> dataBatches = TypeUtil.getBatches(datas, 50); List<String> ret = new ArrayList<String>(); for (int i = 0; i < displayBatches.size(); i++) { List<String> batchDisplayNames = displayBatches.get(i); List<String> dataBatch = dataBatches.get(i); List<String> parsedDisplayNames = new ArrayList<String>(); for (String disp : batchDisplayNames) { disp = URIParser.convertDocURI(disp); parsedDisplayNames.add(disp); } api.getDoc().putDocs(parsedDisplayNames, dataBatch); ret.addAll(parsedDisplayNames); } return ret; }
@Override public List<Map<String, Object>> batchPullData(List<String> displayNames) { // Run in batches of 50 List<String> content = new ArrayList<String>(); List<List<String>> batches = getBatches(displayNames, 50); for (List<String> batch : batches) { List<String> batchDisplayNames = new ArrayList<String>(); for (String disp : batch) { disp = URIParser.convertDocURI(disp); batchDisplayNames.add(disp); } Map<String, String> contents = api.getDoc().getDocs(batchDisplayNames); content.addAll(contents.values()); } List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>(); for (String c : content) { ret.add((Map<String, Object>) JacksonUtil.getMapFromJson(c)); } return ret; }
@Override public List<String> batchPushRawData(List<String> displayNames, List<String> datas) { if (displayNames.size() != datas.size()) { throw RaptureExceptionFactory.create(HttpURLConnection.HTTP_INTERNAL_ERROR, "Batch push raw data and display different sizes. Data is " + datas.size() + ", displays are " + displayNames.size()); } List<List<String>> displayBatches = TypeUtil.getBatches(displayNames, 50); List<List<String>> dataBatches = TypeUtil.getBatches(datas, 50); List<String> ret = new ArrayList<String>(); for (int i = 0; i < displayBatches.size(); i++) { List<String> batchDisplayNames = displayBatches.get(i); List<String> dataBatch = dataBatches.get(i); List<String> parsedDisplayNames = new ArrayList<String>(); for (String disp : batchDisplayNames) { disp = URIParser.convertDocURI(disp); parsedDisplayNames.add(disp); } api.getDoc().putDocs( parsedDisplayNames, dataBatch); ret.addAll(parsedDisplayNames); } return ret; }
@Override public List<Map<String, Object>> batchPullData(List<String> displayNames) { // Run in batches of 50 List<String> content = new ArrayList<String>(); List<List<String>> batches = StringUtil.getBatches(displayNames, 50); for (List<String> batch : batches) { List<String> batchDisplayNames = new ArrayList<String>(); for (String disp : batch) { disp = URIParser.convertDocURI(disp); batchDisplayNames.add(disp); } Map<String, String> contents = api.getDoc().getDocs(batchDisplayNames); content.addAll(contents.values()); } List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>(); for (String c : content) { ret.add((Map<String, Object>) JacksonUtil.getMapFromJson(c)); } return ret; }