/** * ReadLink event triggered by FUSE. * * @param pid PID of the triggering process. * @param iotime IO time of the operation. * @param path Path indicating target file. */ public void readlink(int pid, int iotime, String path) { checkProgramTree(Integer.toString(pid)); path = sanitizePath(path); // Create the file artifact and populate the annotations with file information. long now = System.currentTimeMillis(); File linkFile = createLinkVertex(path); putVertex(linkFile); Used edge = new Used((Program) localCache.get(Integer.toString(pid)), linkFile); edge.addAnnotation("endtime", Long.toString(now)); edge.addAnnotation("operation", "readlink"); putEdge(edge); // If the given path represents a link, then perform the same operation on the // artifact to which the link points. if (links.containsKey(path)) { read(pid, iotime, links.get(path), 0); } }
/** * Rename event triggered by FUSE. * * @param pid PID of the triggering process. * @param iotime IO time of the operation. * @param pathfrom The source path. * @param pathto The destination path. * @param link An integer used to indicate whether the target was a link or not. * @param done An intiger used to indicate whether this event was triggered before or after the * rename operation. */ public void rename(int pid, int iotime, String pathfrom, String pathto, int link, int done) { checkProgramTree(Integer.toString(pid)); pathfrom = sanitizePath(pathfrom); pathto = sanitizePath(pathto); long now = System.currentTimeMillis(); // 'done' is used to indicate whether this is a pre-rename or a post-rename // call. In pre-rename, a Used edge is created from the process to the old // file. In post-rename, a WasGeneratedBy edge is created from the process // to the new file and a WasDerivedEdge created between the two file // artifacts. if (done == 0) { // Create file artifact depending on whether this is a link or not. // Link artifacts are created differently to avoid recursion that may // cause FUSE to crash. File fileVertex = (link == 1) ? createLinkVertex(pathfrom) : createFileVertex(pathfrom); putVertex(fileVertex); // Put the file artifact in the localCache to be removed on post-rename. localCache.put(pathfrom, fileVertex); Used edge = new Used((Program) localCache.get(Integer.toString(pid)), fileVertex); edge.addAnnotation("endtime", Long.toString(now)); putEdge(edge); } else { // Create file artifact depending on whether this is a link or not. // Link artifacts are created differently to avoid recursion that may // cause FUSE to crash. File fileVertex = (link == 1 ? createLinkVertex(pathto) : createFileVertex(pathto)); putVertex(fileVertex); WasGeneratedBy writeEdge = new WasGeneratedBy(fileVertex, (Program) localCache.get(Integer.toString(pid))); writeEdge.addAnnotation("endtime", Long.toString(now)); putEdge(writeEdge); WasDerivedFrom renameEdge = new WasDerivedFrom(fileVertex, (File) localCache.remove(pathfrom)); renameEdge.addAnnotation("iotime", Integer.toString(iotime)); renameEdge.addAnnotation("endtime", Long.toString(now)); renameEdge.addAnnotation("operation", "rename"); putEdge(renameEdge); if (links.containsKey(pathfrom)) { // If the rename is on a link then update the link name. String linkedLocation = links.get(pathfrom); links.remove(pathfrom); links.put(pathto, linkedLocation); } } }
/** * Read event triggered by FUSE. * * @param pid PID of the triggering process. * @param iotime IO time of the operation. * @param path Path indicating target file. * @param link An integer used to indicate whether the target was a link or not. */ public void read(int pid, int iotime, String path, int link) { checkProgramTree(Integer.toString(pid)); path = sanitizePath(path); long now = System.currentTimeMillis(); // Create file artifact depending on whether this is a link or not. // Link artifacts are created differently to avoid recursion that may // cause FUSE to crash. File fileVertex = (link == 1) ? createLinkVertex(path) : createFileVertex(path); putVertex(fileVertex); Used edge = new Used((Program) localCache.get(Integer.toString(pid)), fileVertex); edge.addAnnotation("iotime", Integer.toString(iotime)); edge.addAnnotation("endtime", Long.toString(now)); putEdge(edge); // If the given path represents a link, then perform the same operation on the // artifact to which the link points. if (link == 1 && links.containsKey(path)) { read(pid, iotime, links.get(path), 0); } }
void emitOPM(String pid, String connection) { try { String source, destination, port; String[] endPoint, endPoints; LinkedHashMap<String, String> annotations; boolean endPointMatched = false; Date currentTime; spade.vertex.opm.Process processVertex; spade.vertex.custom.Network networkVertex; WasGeneratedBy wasGeneratedByEdge; Used usedEdge; // Create process vertex. annotations = new LinkedHashMap<String, String>(); annotations.put("pid", pid); processVertex = new spade.vertex.opm.Process(); processVertex.getAnnotations().putAll(annotations); if (!putVertex(processVertex)) { errorStream.println("Buffer did not accept process artifact:" + "\n\t pid" + pid); } // Create network artifact. annotations = new LinkedHashMap<String, String>(); endPoints = connection.split("->"); endPoint = endPoints[0].split(":"); source = endPoint[0]; annotations.put("source host", source); port = endPoint[1]; annotations.put("source port", port); endPoint = endPoints[1].split(":"); destination = endPoint[0]; annotations.put("destination host", destination); port = endPoint[1]; annotations.put("destination port", port); networkVertex = new spade.vertex.custom.Network(); networkVertex.getAnnotations().putAll(annotations); if (!putVertex(networkVertex)) { errorStream.println("Buffer did not accept connection artifact:" + "\n\t " + connection); } // Create an outgoing edge. if (InetAddress.getByName(destination).isSiteLocalAddress()) { annotations = new LinkedHashMap<String, String>(); currentTime = new Date(); annotations.put("time", currentTime.toString()); usedEdge = new Used(processVertex, networkVertex); usedEdge.getAnnotations().putAll(annotations); if (!putEdge(usedEdge)) { errorStream.println( "Buffer did not accept outgoing " + "connection edge:\n\t pid: " + pid + "\n\t connection: " + connection + "\n\t time: " + currentTime.toString()); } endPointMatched = true; } // Create an incoming edge. if (InetAddress.getByName(source).isSiteLocalAddress()) { annotations = new LinkedHashMap<String, String>(); currentTime = new Date(); annotations.put("time", currentTime.toString()); wasGeneratedByEdge = new WasGeneratedBy(networkVertex, processVertex); wasGeneratedByEdge.getAnnotations().putAll(annotations); if (!putEdge(wasGeneratedByEdge)) { errorStream.println( "Buffer did not accept incoming " + "connection edge:\n\t pid: " + pid + "\n\t connection: " + connection + "\n\t time: " + currentTime.toString()); } endPointMatched = true; } if (!endPointMatched) { errorStream.println("Neither endpoint is local:\n\t" + connection); } } catch (Exception exception) { exception.printStackTrace(errorStream); } }