/** * validate HDFSResource Site and File Path * @param site * @param filePath * @throws Exception */ public void validate( String site, String filePath ) throws Exception { if (isNullOrEmpty(site)) throw new Exception("Invalid Request Received ... Site is Empty Or Null.."); if (isNullOrEmpty(filePath)) throw new Exception("Invalid Request Received ... file/Directory Path is Empty Or Null.."); }
public String fNameToFid(String name) throws Exception { String id = "FID NOT FOUND"; name = "maprfs://"+name; String cmds[] = {"-lsd",name}; String results = run(cmds); Pattern pattern = Pattern.compile("\\sp\\s([\\d\\.]+)\\s"); Matcher matcher = pattern.matcher(results); if (matcher.find()){ id = matcher.group(1); } return id; }
/** * rest api : convert volume name to id by calling mapr's rest api * @param vName volume name * @param site site Name * */ @Path(MAPRFSResourceConstants.MAPRFS_VNAME_RESOLVER) @GET // The Java method will produce content identified by the MIME Media type "text/plain" @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public String getVid(@QueryParam("vName") String vName, @QueryParam("site") String site) { String ans= "VOLUME ID NOT FOUDN"; try{ // call mapr rest api to get corresponding id; Map<String, Object> config = getAppConfig(site, MAPRFS_APPLICATION); String username; String password; username = (String) config.get(MAPRFSResourceConstants.MAPRFS_USERNAME); password = (String) config.get(MAPRFSResourceConstants.MAPRFS_PASSWORD); // call String restUrl = (String) config.get(MAPRFSResourceConstants.MAPRFS_WEBUI_HTTPS) + MAPRFSResourceConstants.MAPRFS_VOLUME_INFO + "?name=" + vName; JSONObject response = HttpRequest.executeGet(restUrl,username,password); ans = extractVolumeId(response); }catch (Exception e){ LOG.info("maprfs: can not convert volume name" + vName + " to id", e); } return ans; }
@GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public HDFSResourceWebResponse getHDFSResource(@QueryParam("site") String site, @QueryParam("path") String filePath) { LOG.info("Starting HDFS Resource Browsing. Query Parameters ==> Site :" + site + " Path : " + filePath); HDFSResourceWebResponse response = new HDFSResourceWebResponse(); HDFSResourceWebRequestValidator validator = new HDFSResourceWebRequestValidator(); List<FileStatusEntity> result = new ArrayList<>(); List<FileStatus> fileStatuses = null; try { validator.validate(site, filePath); // First Step would be validating Request Map<String, Object> config = getAppConfig(site, HDFS_APPLICATION); Configuration conf = convert(config); HDFSFileSystem fileSystem = new HDFSFileSystem(conf); fileStatuses = fileSystem.browse(filePath); // Join with File Sensitivity Info HDFSResourceSensitivityDataJoiner joiner = new HDFSResourceSensitivityDataJoiner(dao); result = joiner.joinFileSensitivity(site, fileStatuses); LOG.info("Successfully browsed files in HDFS ."); } catch (Exception ex) { response.setException(EagleExceptionWrapper.wrap(ex)); LOG.error(" Exception When browsing Files for the HDFS Path :" + filePath + " ", ex); } response.setObj(result); return response; }
@GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public HDFSResourceWebResponse getHDFSResource(@QueryParam("site") String site , @QueryParam("path") String filePath ) { LOG.info("Starting MAPRFS Resource Browsing. Query Parameters ==> Site :"+site+" Path : "+filePath ); HDFSResourceWebResponse response = new HDFSResourceWebResponse(); HDFSResourceWebRequestValidator validator = new HDFSResourceWebRequestValidator(); List<FileStatusEntity> result = new ArrayList<>(); List<FileStatus> fileStatuses = null; try { validator.validate(site, filePath); // First Step would be validating Request Map<String, Object> config = getAppConfig(site, MAPRFS_APPLICATION); Configuration conf = convert(config); HDFSFileSystem fileSystem = new HDFSFileSystem(conf); fileStatuses = fileSystem.browse(filePath); // Join with File Sensitivity Info HDFSResourceSensitivityDataJoiner joiner = new HDFSResourceSensitivityDataJoiner(dao); result = joiner.joinFileSensitivity(site, fileStatuses); LOG.info("Successfully browsed files in MAPRFS ."); } catch( Exception ex ) { response.setException(EagleExceptionWrapper.wrap(ex)); LOG.error(" Exception When browsing Files for the MAPRFS Path :"+filePath+" " , ex); } response.setObj(result); return response; }
@GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) public HDFSResourceWebResponse getHDFSResource( @QueryParam("site") String site , @QueryParam("path") String filePath ) { LOG.info("Starting HDFS Resource Browsing. Query Parameters ==> Site :"+site+" Path : "+filePath ); HDFSResourceWebResponse response = new HDFSResourceWebResponse(); HDFSResourceWebRequestValidator validator = new HDFSResourceWebRequestValidator(); MetadataAccessConfigRepo repo = new MetadataAccessConfigRepo(); List<FileStatusEntity> result = new ArrayList<>(); List<FileStatus> fileStatuses = null; try { validator.validate(site, filePath); // First Step would be validating Request Config config = repo.getConfig(HDFSResourceConstants.HDFS_APPLICATION, site); Configuration conf = repo.convert(config); HDFSFileSystem fileSystem = new HDFSFileSystem(conf); fileStatuses = fileSystem.browse(filePath); // Join with File Sensitivity Info HDFSResourceSensitivityDataJoiner joiner = new HDFSResourceSensitivityDataJoiner(); result = joiner.joinFileSensitivity(site, fileStatuses); LOG.info("Successfully browsed files in HDFS ."); } catch( Exception ex ) { response.setException(EagleExceptionWrapper.wrap(ex)); LOG.error(" Exception When browsing Files for the HDFS Path :"+filePath+" " , ex); } response.setObj(result); return response; } }
/** * rest api : convert file/folder name to id * @param fName file/folder name * @param site sitename * */ @Path(MAPRFSResourceConstants.MAPRFS_FNAME_RESOLVER) @GET @Consumes(MediaType.TEXT_PLAIN) @Produces(MediaType.TEXT_PLAIN) public String getFid(@QueryParam("fName") String fName, @QueryParam("site") String site) { String ans = "FID NOT FOUND"; try{ Map<String, Object> config = getAppConfig(site, MAPRFS_APPLICATION); String defaultFS; defaultFS = (String) config.get("fs.defaultFS"); Configuration conf = new Configuration(); conf.set("fs.defaultFS",defaultFS); mprcmd = new MapRCliCommands(conf); ans = fNameToFid(fName); return ans; }catch (Exception e){ LOG.info("maprfs: can not convert file/dir name " + fName + "to fid", e); ans = "CAN NOT RESOLVE THIS FID"; } return ans; }
JSONObject response = HttpRequest.executeGet(restUrl,username,password); volumelist = extractVolumeList(response); List<String> res = new ArrayList<>();
/** * validate HDFSResource Site and File Path * @param site * @param filePath * @throws Exception */ public void validate( String site, String filePath ) throws Exception { if (isNullOrEmpty(site)) throw new Exception("Invalid Request Received ... Site is Empty Or Null.."); if (isNullOrEmpty(filePath)) throw new Exception("Invalid Request Received ... file/Directory Path is Empty Or Null.."); }
public String fidToFname(String id) throws Exception { String name = "FNAME NOT FOUND"; String cmds[] = {"-lsfid",id}; String results = run(cmds); Pattern pattern = Pattern.compile("\\s(/.*)\\s"); Matcher matcher = pattern.matcher(results); if (matcher.find()){ name = matcher.group(1); } return name; }