/** * Finds the next occurrence for monthly recurrence. * * @param startDate the start date of the previous calendar item. * @param endDate the end date of the previous calendar item. * @param lastDay if <tt>true</tt> we are interested in last day of the month * @return the next item */ public CalendarItemTimerTask nextMonth(Date startDate, Date endDate, boolean lastDay) { long duration = sourceTask.getEndDate().getTime() - sourceTask.getStartDate().getTime(); Calendar cal = Calendar.getInstance(); cal.setTime(startDate); cal = incrementMonths(cal, lastDay, period); Date currentDate = new Date(); if (cal.getTimeInMillis() + duration < currentDate.getTime()) { Calendar cal2 = Calendar.getInstance(); cal2.setTime(currentDate); int years = cal2.get(Calendar.YEAR) - cal.get(Calendar.YEAR); int months = (years * 12) + (cal2.get(Calendar.MONTH) - cal.get(Calendar.MONTH)); int monthsToAdd = months; monthsToAdd -= months % period; cal = incrementMonths(cal, lastDay, monthsToAdd); if (cal.getTimeInMillis() + duration < currentDate.getTime()) { cal = incrementMonths(cal, lastDay, period); } } Calendar cal2 = (Calendar) cal.clone(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); while (deletedInstances.contains(cal.getTime())) { cal = incrementMonths(cal, lastDay, period); cal2 = incrementMonths(cal2, lastDay, period); } startDate = cal2.getTime(); endDate = new Date(startDate.getTime() + duration); if (dateOutOfRange(endDate)) { return null; } boolean executeNow = false; if (startDate.before(currentDate)) { executeNow = true; } return new CalendarItemTimerTask( sourceTask.getStatus(), startDate, endDate, sourceTask.getId(), executeNow, this); }
/** * Searches for contact ids in history of recent messages. * * @param provider * @param after * @return */ List<String> getRecentContactIDs(String provider, Date after) { List<String> res = new ArrayList<String>(); try { History history = getHistory(); if (history != null) { Iterator<HistoryRecord> recs = history.getReader().findLast(NUMBER_OF_MSGS_IN_HISTORY); SimpleDateFormat sdf = new SimpleDateFormat(HistoryService.DATE_FORMAT); while (recs.hasNext()) { HistoryRecord hr = recs.next(); String contact = null; String recordProvider = null; Date timestamp = null; for (int i = 0; i < hr.getPropertyNames().length; i++) { String propName = hr.getPropertyNames()[i]; if (propName.equals(STRUCTURE_NAMES[0])) recordProvider = hr.getPropertyValues()[i]; else if (propName.equals(STRUCTURE_NAMES[1])) contact = hr.getPropertyValues()[i]; else if (propName.equals(STRUCTURE_NAMES[2])) { try { timestamp = sdf.parse(hr.getPropertyValues()[i]); } catch (ParseException e) { timestamp = new Date(Long.parseLong(hr.getPropertyValues()[i])); } } } if (recordProvider == null || contact == null) continue; if (after != null && timestamp != null && timestamp.before(after)) continue; if (recordProvider.equals(provider)) res.add(contact); } } } catch (IOException ex) { logger.error("cannot create recent_messages history", ex); } return res; }
/** * Finds the occurrence of the events in the next months * * @param startDate the start date if the calendar item * @param dayOfWeekInMonth the number of week days occurrences * @return the date of the next occurrence */ private Date getMonthNStartDate(Date startDate, int dayOfWeekInMonth) { Calendar cal = Calendar.getInstance(); cal.setTime(startDate); if (dayOfWeekInMonth == -1) { Date result = null; cal.set(Calendar.DAY_OF_WEEK_IN_MONTH, dayOfWeekInMonth); for (int day : allowedDaysOfWeek) { cal.set(Calendar.DAY_OF_WEEK, day); if (result == null || result.before(cal.getTime())) result = cal.getTime(); } return result; } else while (dayOfWeekInMonth > 0) { int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); if (allowedDaysOfWeek.contains(dayOfWeek)) dayOfWeekInMonth--; if (dayOfWeekInMonth > 0) cal.add(Calendar.DAY_OF_MONTH, 1); } return cal.getTime(); }
/** * Finds the next occurrence for monthly Nth recurrence. * * @param startDate the start date of the previous calendar item. * @param endDate the end date of the previous calendar item. * @return the next item */ public CalendarItemTimerTask nextMonthN(Date startDate, Date endDate) { int dayOfWeekInMonth = (patternSpecific2 == 5 ? -1 : patternSpecific2); long duration = sourceTask.getEndDate().getTime() - sourceTask.getStartDate().getTime(); Calendar cal = Calendar.getInstance(); cal.setTime(startDate); cal.set(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.MONTH, period); cal.setTime(getMonthNStartDate(cal.getTime(), dayOfWeekInMonth)); Date currentDate = new Date(); if (cal.getTimeInMillis() + duration < currentDate.getTime()) { Calendar cal2 = Calendar.getInstance(); cal2.setTime(currentDate); int years = cal2.get(Calendar.YEAR) - cal.get(Calendar.YEAR); int months = (years * 12) + (cal2.get(Calendar.MONTH) - cal.get(Calendar.MONTH)); int monthsToAdd = months; monthsToAdd -= months % period; cal.set(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.MONTH, monthsToAdd); cal.setTime(getMonthNStartDate(cal.getTime(), dayOfWeekInMonth)); if (cal.getTimeInMillis() + duration < currentDate.getTime()) { cal.set(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.MONTH, monthsToAdd); cal.setTime(getMonthNStartDate(cal.getTime(), dayOfWeekInMonth)); } } Calendar cal2 = (Calendar) cal.clone(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); while (deletedInstances.contains(cal.getTime())) { cal.set(Calendar.DAY_OF_MONTH, 1); cal.add(Calendar.MONTH, period); startDate = null; for (int dayOfWeek : allowedDaysOfWeek) { cal.set(Calendar.DAY_OF_WEEK, dayOfWeek); cal.set(Calendar.DAY_OF_WEEK_IN_MONTH, dayOfWeekInMonth); if ((cal.after(startDate) && dayOfWeekInMonth == -1) || (cal.before(startDate) && dayOfWeekInMonth != -1) || startDate == null) { startDate = cal.getTime(); cal2.set(Calendar.YEAR, cal.get(Calendar.YEAR)); cal2.set(Calendar.MONTH, cal.get(Calendar.MONTH)); cal2.set(Calendar.DATE, cal.get(Calendar.DATE)); } } } startDate = cal2.getTime(); endDate = new Date(startDate.getTime() + duration); if (dateOutOfRange(endDate)) return null; boolean executeNow = false; if (startDate.before(currentDate)) { executeNow = true; } return new CalendarItemTimerTask( sourceTask.getStatus(), startDate, endDate, sourceTask.getId(), executeNow, this); }
/** * Calculates and creates the next calendar item. * * @param previousStartDate the start date of the previous occurrence. * @param previousEndDate the end date of the previous occurrence. * @return the new calendar item or null if there are no more calendar items from that recurrent * series. */ public CalendarItemTimerTask next(Date previousStartDate, Date previousEndDate) { if (dateOutOfRange(new Date())) { return null; } Date startDate = previousStartDate; Date endDate = null; boolean executeNow = false; long duration = sourceTask.getEndDate().getTime() - sourceTask.getStartDate().getTime(); switch (patternType) { case Day: { startDate = new Date(startDate.getTime() + period * 60000); endDate = new Date(previousEndDate.getTime() + period * 60000); Date currentDate = new Date(); if (endDate.before(currentDate)) { long offset = currentDate.getTime() - endDate.getTime(); offset -= offset % (period * 60000); if (endDate.getTime() + offset < currentDate.getTime()) { offset += period * 60000; } startDate = new Date(startDate.getTime() + offset); } Calendar cal = Calendar.getInstance(); cal.setTime(startDate); Calendar cal2 = (Calendar) cal.clone(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); while (deletedInstances.contains(cal.getTime())) { cal.add(Calendar.MINUTE, period); cal2.add(Calendar.MINUTE, period); } if (dateOutOfRange(cal.getTime())) { return null; } startDate = cal2.getTime(); endDate = new Date(startDate.getTime() + duration); if (startDate.before(currentDate)) { executeNow = true; } return new CalendarItemTimerTask( sourceTask.getStatus(), startDate, endDate, sourceTask.getId(), executeNow, this); } case Week: { Calendar cal = Calendar.getInstance(); /** The enum for the firstDow field is the same as Calendar day of week enum + 1 day */ cal.setFirstDayOfWeek(firstDow + 1); cal.setTime(startDate); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); int index = allowedDaysOfWeek.indexOf(dayOfWeek); if (++index < allowedDaysOfWeek.size()) { cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(index)); startDate = cal.getTime(); endDate = new Date(startDate.getTime() + duration); } else { cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(0)); cal.add(Calendar.WEEK_OF_YEAR, period); startDate = cal.getTime(); endDate = new Date(startDate.getTime() + duration); } Date currentDate = new Date(); if (endDate.before(currentDate)) { cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(0)); endDate = new Date(cal.getTimeInMillis() + duration); long offset = (currentDate.getTime() - endDate.getTime()); // 1 week = 604800000 is milliseconds offset -= offset % (period * 604800000); if (endDate.getTime() + offset < currentDate.getTime()) { cal.add(Calendar.WEEK_OF_YEAR, (int) (offset / (period * 604800000))); int i = 1; while (((cal.getTimeInMillis() + duration) < (currentDate.getTime()))) { if (i == allowedDaysOfWeek.size()) { cal.add(Calendar.WEEK_OF_YEAR, period); i = 0; } cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(i)); i++; } startDate = cal.getTime(); } else { startDate = new Date(cal.getTimeInMillis() + offset); } } cal.setTime(startDate); Calendar cal2 = (Calendar) cal.clone(); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); index = allowedDaysOfWeek.indexOf(dayOfWeek) + 1; while (deletedInstances.contains(cal.getTime())) { if (index >= allowedDaysOfWeek.size()) { index = 0; cal.add(Calendar.WEEK_OF_YEAR, period); cal2.add(Calendar.WEEK_OF_YEAR, period); } cal.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(index)); cal2.set(Calendar.DAY_OF_WEEK, allowedDaysOfWeek.get(index)); index++; } startDate = cal2.getTime(); endDate = new Date(startDate.getTime() + duration); if (dateOutOfRange(endDate)) return null; if (startDate.before(currentDate)) { executeNow = true; } return new CalendarItemTimerTask( sourceTask.getStatus(), startDate, endDate, sourceTask.getId(), executeNow, this); } case Month: case MonthEnd: case HjMonth: case HjMonthEnd: { return nextMonth(startDate, endDate, false); } case MonthNth: case HjMonthNth: { if (patternSpecific1 == 0x7f && patternSpecific2 == 0x05) { return nextMonth(startDate, endDate, true); } return nextMonthN(startDate, endDate); } } return null; }
/** * Parses the binary data that describes the recurrent pattern. * * @param data the binary data. * @param sourceTask the calendar item. */ public RecurringPattern(byte[] data, CalendarItemTimerTask sourceTask) { this.sourceTask = sourceTask; dataBuffer = ByteBuffer.wrap(data).order(ByteOrder.LITTLE_ENDIAN); int offset = 4; recurFrequency = dataBuffer.getShort(offset); offset += 2; patternType = PatternType.getFromShort(dataBuffer.getShort(offset)); offset += 2; calendarType = dataBuffer.getShort(offset); offset += 2; firstDateTime = dataBuffer.getInt(offset); offset += 4; period = dataBuffer.getInt(offset); offset += 4; slidingFlag = dataBuffer.getInt(offset); offset += 4; switch (patternType) { case Week: case Month: case MonthEnd: case HjMonth: case HjMonthEnd: patternSpecific1 = dataBuffer.getInt(offset); patternSpecific2 = 0; offset += 4; if (patternType == PatternType.Week) { for (int day = firstDow; day < firstDow + 7; day++) { if ((patternSpecific1 & (weekOfDayMask[day % 7])) != 0) { allowedDaysOfWeek.add((day % 7) + 1); } } } break; case MonthNth: case HjMonthNth: patternSpecific1 = dataBuffer.getInt(offset); patternSpecific2 = dataBuffer.getInt(offset + 4); if (patternSpecific1 == 0x7f && patternSpecific2 != 0x5) { patternType = PatternType.Month; } for (int day = 0; day < 7; day++) { if ((patternSpecific1 & (weekOfDayMask[day])) != 0) { allowedDaysOfWeek.add((day) + 1); } } offset += 8; break; default: break; } // endType endType = dataBuffer.getInt(offset); offset += 4; occurenceCount = dataBuffer.getInt(offset); offset += 4; firstDow = dataBuffer.getInt(offset); offset += 4; deletedInstanceCount = dataBuffer.getInt(offset); offset += 4; // deleted instances for (int i = 0; i < deletedInstanceCount; i++) { deletedInstances.add(windowsTimeToDateObject(dataBuffer.getInt(offset))); offset += 4; } modifiedInstanceCount = dataBuffer.getInt(offset); offset += 4; // modified instances modifiedInstances = new int[modifiedInstanceCount]; for (int i = 0; i < modifiedInstanceCount; i++) { modifiedInstances[i] = dataBuffer.getInt(offset); offset += 4; } startDate = dataBuffer.getInt(offset); offset += 4; endDate = dataBuffer.getInt(offset); offset += 4; offset += 16; short exceptionCount = dataBuffer.getShort(offset); offset += 2; exceptionInfo = new ArrayList<ExceptionInfo>(exceptionCount); for (int i = 0; i < exceptionCount; i++) { ExceptionInfo tmpExceptionInfo = new ExceptionInfo(offset); exceptionInfo.add(tmpExceptionInfo); offset += tmpExceptionInfo.sizeInBytes(); CalendarService.BusyStatusEnum status = tmpExceptionInfo.getBusyStatus(); Date startTime = tmpExceptionInfo.getStartDate(); Date endTime = tmpExceptionInfo.getEndDate(); if (status == CalendarService.BusyStatusEnum.FREE || startTime == null || endTime == null) continue; Date currentTime = new Date(); if (endTime.before(currentTime) || endTime.equals(currentTime)) return; boolean executeNow = false; if (startTime.before(currentTime) || startTime.equals(currentTime)) executeNow = true; CalendarItemTimerTask task = new CalendarItemTimerTask( status, startTime, endTime, sourceTask.getId(), executeNow, this); task.scheduleTasks(); } }
/** Creates new form frmAsignarTransporte */ public frmAsignarTransporte() { initComponents(); gestorH.actualizarUsuario(labelusuario); txtFecha.setEditable(false); txtFecha.setEnabled(false); txtHora.setEditable(false); txtHora.setEnabled(false); // setear el campo de fecha con la del sistema GregorianCalendar gc = new GregorianCalendar(); GregorianCalendar.getInstance(); gc.setTimeZone(TimeZone.getTimeZone("GMT-3")); gc.get(Calendar.DAY_OF_WEEK); gc.get(Calendar.MONTH); gc.get(Calendar.YEAR); SimpleDateFormat formateador = new SimpleDateFormat("dd-MM-yyyy"); txtFecha.setText(formateador.format(gc.getTime())); // setear el campo de hora con la del sistema GregorianCalendar calendario = new GregorianCalendar(); GregorianCalendar.getInstance(); gc.setTimeZone(TimeZone.getTimeZone("GMT-3")); calendario.get(Calendar.HOUR); calendario.get(Calendar.MINUTE); SimpleDateFormat formateadorHora = new SimpleDateFormat("HH:mm"); txtHora.setText(formateadorHora.format(calendario.getTime())); // Las siguientes lineas son para dar a la pantalla el tamaño requerido y luego centrarla en la // pantalla. Toolkit kit = Toolkit.getDefaultToolkit(); Dimension tamanioPantalla = kit.getScreenSize(); int ancho = 820; int alto = 570; // int posX = (int) ((tamanioPantalla.width - ancho) / 2); // int posY = (int) ((tamanioPantalla.height - alto) / 2); this.setSize(ancho, alto); this.setLocation(260, 30); // redimensionar columnas tabla tblViaje.getColumnModel().getColumn(0).setPreferredWidth(50); tblViaje.getColumnModel().getColumn(1).setPreferredWidth(50); tblViaje.getColumnModel().getColumn(2).setPreferredWidth(100); tblVehiculo.getColumnModel().getColumn(0).setPreferredWidth(100); tblVehiculo.getColumnModel().getColumn(1).setPreferredWidth(100); // centrar cabecera jtable DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) tblVehiculo.getTableHeader().getDefaultRenderer(); renderer.setHorizontalAlignment(0); DefaultTableCellRenderer renderer2 = (DefaultTableCellRenderer) tblViaje.getTableHeader().getDefaultRenderer(); renderer2.setHorizontalAlignment(0); Iterator ite = gestorH.listarClase(Viaje.class).iterator(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy"); SimpleDateFormat sdfguion = new SimpleDateFormat("dd-MM-yyyy"); while (ite.hasNext()) { Viaje viaje = (Viaje) ite.next(); Date fecha1 = sdf.parse(viaje.getFecha(), new ParsePosition(0)); Date fecha3 = sdfguion.parse(txtFecha.getText(), new ParsePosition(0)); if (viaje.getEstado().equalsIgnoreCase("En Proceso") && (viaje.getTipoViaje().getNombreTipoViaje().equalsIgnoreCase("Traslado a Puerto") || viaje .getTipoViaje() .getNombreTipoViaje() .equalsIgnoreCase("Traslado a Establecimiento"))) { if (fecha1.before(fecha3)) { viaje.setEstado("Finalizado"); viaje.getVehiculo().setEstado("Disponible"); } } } gestorA.RellenarTablaViajes(tblViaje); }
public int run(String[] args) throws Exception { // printUsage(); /* * SETUP */ Configuration argConf = getConf(); Hashtable<String, String> confArg = new Hashtable<String, String>(); setup(confArg, argConf); Date currentTime = new Date(); Date endDate = new Date(new Long(confArg.get("timestamp_stop"))); Boolean full_run = confArg.get("intermediate").matches("(?i).*true.*"); Boolean quick_add = confArg.get("quick_add").matches("(?i).*true.*"); logger.info("Running GeStore"); // ZooKeeper setup Configuration config = HBaseConfiguration.create(); zkWatcher = new ZooKeeperWatcher(config, "Testing", new HBaseAdmin(config)); zkInstance = new ZooKeeper( ZKConfig.getZKQuorumServersString(config), config.getInt("zookeeper.session.timeout", -1), zkWatcher); if (!confArg.get("task_id").isEmpty()) { confArg.put("temp_path", confArg.get("temp_path") + confArg.get("task_id")); } String lockRequest = confArg.get("file_id"); if (!confArg.get("run_id").isEmpty()) lockRequest = lockRequest + "_" + confArg.get("run_id") + "_"; if (!confArg.get("task_id").isEmpty()) lockRequest = lockRequest + "_" + confArg.get("task_id") + "_"; // Get type of movement toFrom type_move = checkArgs(confArg); if (type_move == toFrom.LOCAL2REMOTE && !confArg.get("format").equals("unknown")) { List<String> arguments = new ArrayList<String>(); arguments.add("-Dinput=" + confArg.get("local_path")); arguments.add("-Dtable=" + confArg.get("file_id")); arguments.add("-Dtimestamp=" + confArg.get("timestamp_stop")); arguments.add("-Dtype=" + confArg.get("format")); arguments.add("-Dtarget_dir=" + confArg.get("base_path") + "_" + confArg.get("file_id")); arguments.add("-Dtemp_hdfs_path=" + confArg.get("temp_path")); arguments.add("-Drun_id=" + confArg.get("run_id")); if (!confArg.get("run_id").isEmpty()) arguments.add("-Drun_id=" + confArg.get("run_id")); if (!confArg.get("task_id").isEmpty()) arguments.add("-Dtask_id=" + confArg.get("task_id")); if (quick_add) arguments.add("-Dquick_add=" + confArg.get("quick_add")); String lockName = lock(lockRequest); String[] argumentString = arguments.toArray(new String[arguments.size()]); adddb.main(argumentString); unlock(lockName); System.exit(0); } // Database registration dbutil db_util = new dbutil(config); db_util.register_database(confArg.get("db_name_files"), true); db_util.register_database(confArg.get("db_name_runs"), true); db_util.register_database(confArg.get("db_name_updates"), true); FileSystem hdfs = FileSystem.get(config); FileSystem localFS = FileSystem.getLocal(config); // Get source type confArg.put("source", getSource(db_util, confArg.get("db_name_files"), confArg.get("file_id"))); confArg.put( "database", isDatabase(db_util, confArg.get("db_name_files"), confArg.get("file_id"))); if (!confArg.get("source").equals("local") && type_move == toFrom.REMOTE2LOCAL && !confArg.get("timestamp_stop").equals(Integer.toString(Integer.MAX_VALUE))) { confArg.put("timestamp_stop", Long.toString(latestVersion(confArg, db_util))); } /* * Get previous timestamp */ Get run_id_get = new Get(confArg.get("run_id").getBytes()); Result run_get = db_util.doGet(confArg.get("db_name_runs"), run_id_get); KeyValue run_file_prev = run_get.getColumnLatest( "d".getBytes(), (confArg.get("file_id") + "_db_timestamp").getBytes()); String last_timestamp = new String("0"); if (null != run_file_prev && !confArg.get("source").equals("local")) { long last_timestamp_real = run_file_prev.getTimestamp(); Long current_timestamp = new Long(confArg.get("timestamp_real")); if ((current_timestamp - last_timestamp_real) > 36000) { last_timestamp = new String(run_file_prev.getValue()); Integer lastTimestamp = new Integer(last_timestamp); lastTimestamp += 1; last_timestamp = lastTimestamp.toString(); logger.info("Last timestamp: " + last_timestamp + " End data: " + endDate); Date last_run = new Date(run_file_prev.getTimestamp()); if (last_run.before(endDate) && !full_run) { confArg.put("timestamp_start", last_timestamp); } } } Integer tse = new Integer(confArg.get("timestamp_stop")); Integer tss = new Integer(confArg.get("timestamp_start")); if (tss > tse) { logger.info("No new version of requested file."); return 0; } /* * Generate file */ String lockName = lock(lockRequest); Get file_id_get = new Get(confArg.get("file_id").getBytes()); Result file_get = db_util.doGet(confArg.get("db_name_files"), file_id_get); if (!file_get.isEmpty()) { boolean found = hasFile( db_util, hdfs, confArg.get("db_name_files"), confArg.get("file_id"), getFullPath(confArg)); if (confArg.get("source").equals("fullfile")) { found = false; } String filenames_put = getFileNames( db_util, confArg.get("db_name_files"), confArg.get("file_id"), getFullPath(confArg)); // Filename not found in file database if (!found && type_move == toFrom.REMOTE2LOCAL) { if (!confArg.get("source").equals("local")) { // Generate intermediate file if (getFile(hdfs, confArg, db_util) == null) { unlock(lockName); return 1; } // Put generated file into file database if (!confArg.get("format").equals("fullfile")) { putFileEntry( db_util, hdfs, confArg.get("db_name_files"), confArg.get("file_id"), confArg.get("full_file_name"), confArg.get("source")); } } else { logger.warn("Remote file not found, and cannot be generated! File: " + confArg); unlock(lockName); return 1; } } } else { if (type_move == toFrom.REMOTE2LOCAL) { logger.warn("Remote file not found, and cannot be generated."); unlock(lockName); return 1; } } /* * Copy file * Update tables */ if (type_move == toFrom.LOCAL2REMOTE) { if (!confArg.get("format").equals("fullfile")) { putFileEntry( db_util, hdfs, confArg.get("db_name_files"), confArg.get("file_id"), getFullPath(confArg), confArg.get("source")); } putRunEntry( db_util, confArg.get("db_name_runs"), confArg.get("run_id"), confArg.get("file_id"), confArg.get("type"), confArg.get("timestamp_real"), confArg.get("timestamp_stop"), getFullPath(confArg), confArg.get("delimiter")); hdfs.copyFromLocalFile(new Path(confArg.get("local_path")), new Path(getFullPath(confArg))); } else if (type_move == toFrom.REMOTE2LOCAL) { FileStatus[] files = hdfs.globStatus(new Path(getFullPath(confArg) + "*")); putRunEntry( db_util, confArg.get("db_name_runs"), confArg.get("run_id"), confArg.get("file_id"), confArg.get("type"), confArg.get("timestamp_real"), confArg.get("timestamp_stop"), getFullPath(confArg), confArg.get("delimiter")); unlock(lockName); for (FileStatus file : files) { Path cur_file = file.getPath(); Path cur_local_path = new Path(new String(confArg.get("local_path") + confArg.get("file_id"))); String suffix = getSuffix(getFileName(confArg), cur_file.getName()); if (suffix.length() > 0) { cur_local_path = cur_local_path.suffix(new String("." + suffix)); } if (confArg.get("copy").equals("true")) { String crc = hdfs.getFileChecksum(cur_file).toString(); if (checksumLocalTest(cur_local_path, crc)) { continue; } else { hdfs.copyToLocalFile(cur_file, cur_local_path); writeChecksum(cur_local_path, crc); } } else { System.out.println(cur_local_path + "\t" + cur_file); } } } unlock(lockName); return 0; }