/** * builds an ScheduleItem object from a Result object obtained from a Scan or Get in the * underlying storage * * @param result * @return */ public static ScheduleItem fromResultObject(Schedule schedule, Result result) { ScheduleItem r = ScheduleItem.fromRowKey(schedule, result.getRowKey()); byte[] stat = result.getValue("bigs", "status"); if (stat != null) { r.setStatusFromString(new String(stat)); } byte[] etime = result.getValue("bigs", "elapsedtime"); if (etime != null) { r.setElapsedTime(new Long(new String(etime))); } byte[] lastupdate = result.getValue("bigs", "lastupdate"); if (lastupdate != null) { r.setLastUpdateFromString(new String(lastupdate)); } byte[] suuid = result.getValue("bigs", "uuid"); if (suuid != null) { r.setUuidStored(new String(suuid)); } byte[] smethod = result.getValue("scheduling", "method"); if (smethod != null) { r.setMethodName(new String(smethod)); } byte[] shostname = result.getValue("bigs", "hostname"); if (shostname != null) { r.setHostnameStored(new String(shostname)); } String parentsIdsString = new String(result.getValue("scheduling", "parents")); if (parentsIdsString != null && !parentsIdsString.trim().isEmpty()) { r.parentsRowkeys = Text.parseObjectList(parentsIdsString, " ", String.class); } r.preparedTask = TaskHelper.fromResultObject(result, "scheduling", "task.class", "task.object"); r.processState = State.fromResultObject(result, "content", "class", "data"); r.preparedTaskContainer = TaskContainer.fromResultObject( result, "scheduling", "task.container.class", "task.container.object"); if (schedule != null) { r.preparedTaskContainer.setPipelineStage(schedule.getPipelineStage()); } r.tags = result.getFamilyMap("tags"); return r; }
@Override public void run(String[] args) throws Exception { String tableName = args[0]; File destinationDir = new File("."); if (args.length == 2) destinationDir = new File(args[1]); DataSource dataSource = BIGS.globalProperties.getPreparedDataSource(); Table table = dataSource.getTable(tableName); ResultScanner scanner = table.getScan(table.createScanObject()); Result r = null; while ((r = scanner.next()) != null) { File destFile = new File(destinationDir, r.getRowKey()); Log.info("downloading to file " + destFile.getName()); DataItem dataItem = DataItem.fromResult(r); FileOutputStream fstream = new FileOutputStream(destFile); fstream.write(dataItem.asFileContent()); fstream.close(); } }