@Test public void test_current_tape_null_then_load_tape_with_empty_label_and_loaded_tape_not_empty_error() throws Exception { when(tapeDriveService.getTapeDriveConf()).thenAnswer(o -> mock(TapeDriveConf.class)); String file = getTarFileName(); WriteOrder writeOrder = new WriteOrder().setBucket(FAKE_BUCKET).setFilePath(FAKE_FILE_PATH).setArchiveId(file).setSize(10l); WriteTask writeTask = new WriteTask(writeOrder, null, new TapeLibraryServiceImpl(tapeDriveService, tapeRobotPool), tapeCatalogService, archiveReferentialRepository, "/tmp", false); TapeCatalog tapeCatalog = getTapeCatalog(false, false, TapeState.EMPTY); tapeCatalog.setCurrentLocation(new TapeLocation(1, TapeLocationType.SLOT)); when(tapeCatalogService.receive(any(), eq(QueueMessageType.TapeCatalog))).thenReturn( Optional.of(tapeCatalog)); when(tapeLoadUnloadService.loadTape(anyInt(), anyInt())).thenReturn(new TapeResponse(StatusCode.OK)); when(tapeDriveCommandService.rewind()) .thenReturn(new TapeDriveState(JsonHandler.createObjectNode(), StatusCode.OK)); TapeDriveState tapeDriveState = new TapeDriveState(StatusCode.OK); tapeDriveState.setCartridge("LTO-6"); when(tapeDriveCommandService.move(anyInt(), anyBoolean())) .thenReturn(new TapeResponse(StatusCode.OK)); ReadWriteResult result = writeTask.get(); verify(tapeRobotPool, new Times(1)).checkoutRobotService(); verify(tapeRobotService, new Times(1)).getLoadUnloadService(); verify(tapeDriveCommandService, new Times(1)).move(anyInt(), anyBoolean()); verify(tapeLoadUnloadService, new Times(1)).loadTape(anyInt(), anyInt()); verify(tapeDriveCommandService, times(1)).rewind(); assertThat(result).isNotNull(); assertThat(result.getStatus()).isEqualTo(StatusCode.FATAL); assertThat(result.getOrderState()).isEqualTo(QueueState.READY); assertThat(result.getCurrentTape()).isNotNull(); assertThat(result.getCurrentTape().getFileCount()).isEqualTo(0); assertThat(result.getCurrentTape().getType()).isEqualTo(tapeDriveState.getCartridge()); assertThat(result.getCurrentTape().getTapeState()).isEqualTo(TapeState.CONFLICT); TapeCatalogLabel label = result.getCurrentTape().getLabel(); assertThat(label).isNull(); }
@Override public ReadWriteResult get() { final ReadWriteResult readWriteResult = new ReadWriteResult(); try { File file = getWriteOrderFile(); if (null != workerCurrentTape) { if (canWriteOnTape()) { doWrite(file); } else { unloadThenLoadTapeAndWrite(file); } } else { loadTapeAndWrite(file); } retryable().execute(() -> updateTarReferential(file)); readWriteResult.setStatus(StatusCode.OK); readWriteResult.setOrderState(QueueState.COMPLETED); } catch (ReadWriteException e) { LOGGER.error(e); readWriteResult.setCode(e.getReadWriteErrorCode()); switch (e.getReadWriteErrorCode()) { case KO_LABEL_DISCORDING: case KO_LABEL_DISCORDING_NOT_EMPTY_TAPE: case KO_UNKNOWN_CURRENT_POSITION: workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); try { retryable().execute(() -> doUpdateTapeCatalog(workerCurrentTape)); } catch (ReadWriteException ex) { LOGGER.error(ex); } readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case KO_ON_WRITE_TO_TAPE: if (--cartridgeRetry >= 0) { workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); return get(); } else { readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); } break; case KO_ON_END_OF_TAPE: workerCurrentTape.setTapeState(TapeState.FULL); return get(); case KO_ON_GOTO_FILE_COUNT: case KO_ON_REWIND_FSF_BSF_TAPE: case KO_REWIND_BEFORE_UNLOAD_TAPE: case TAPE_LOCATION_CONFLICT_ON_LOAD: case TAPE_LOCATION_CONFLICT_ON_UNLOAD: case TAPE_LOCATION_UNKNOWN: case TAPE_NOT_FOUND_IN_CATALOG: case NO_EMPTY_SLOT_FOUND: case NULL_CURRENT_TAPE: case KO_ON_READ_FROM_TAPE: case KO_ON_REWIND_TAPE: case KO_ON_LOAD_TAPE: case KO_ON_UNLOAD_TAPE: case KO_ON_READ_LABEL: case KO_DB_PERSIST: case KO_TAPE_CURRENT_POSITION_GREATER_THAN_FILE_COUNT: case KO_ON_STATUS: case KO_ON_LOAD_THEN_STATUS: case KO_ON_UNLOAD_THEN_STATUS: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case FILE_NOT_FOUND: case INTERNAL_ERROR_SERVER: default: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.ERROR); } } readWriteResult.setCurrentTape(workerCurrentTape); return readWriteResult; }
WriteTask implements Future<ReadWriteResult> { @Override public ReadWriteResult get() { final ReadWriteResult readWriteResult = new ReadWriteResult(); try { File file = getWriteOrderFile(); if (null != workerCurrentTape) { if (canWriteOnTape()) { doWrite(file); } else { unloadThenLoadTapeAndWrite(file); } } else { loadTapeAndWrite(file); } retryable().execute(() -> updateTarReferential(file)); readWriteResult.setStatus(StatusCode.OK); readWriteResult.setOrderState(QueueState.COMPLETED); } catch (ReadWriteException e) { LOGGER.error(e); readWriteResult.setCode(e.getReadWriteErrorCode()); switch (e.getReadWriteErrorCode()) { case KO_LABEL_DISCORDING: case KO_LABEL_DISCORDING_NOT_EMPTY_TAPE: case KO_UNKNOWN_CURRENT_POSITION: workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); try { retryable().execute(() -> doUpdateTapeCatalog(workerCurrentTape)); } catch (ReadWriteException ex) { LOGGER.error(ex); } readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case KO_ON_WRITE_TO_TAPE: if (--cartridgeRetry >= 0) { workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); return get(); } else { readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); } break; case KO_ON_END_OF_TAPE: workerCurrentTape.setTapeState(TapeState.FULL); return get(); case KO_ON_GOTO_FILE_COUNT: case KO_ON_REWIND_FSF_BSF_TAPE: case KO_REWIND_BEFORE_UNLOAD_TAPE: case TAPE_LOCATION_CONFLICT_ON_LOAD: case TAPE_LOCATION_CONFLICT_ON_UNLOAD: case TAPE_LOCATION_UNKNOWN: case TAPE_NOT_FOUND_IN_CATALOG: case NO_EMPTY_SLOT_FOUND: case NULL_CURRENT_TAPE: case KO_ON_READ_FROM_TAPE: case KO_ON_REWIND_TAPE: case KO_ON_LOAD_TAPE: case KO_ON_UNLOAD_TAPE: case KO_ON_READ_LABEL: case KO_DB_PERSIST: case KO_TAPE_CURRENT_POSITION_GREATER_THAN_FILE_COUNT: case KO_ON_STATUS: case KO_ON_LOAD_THEN_STATUS: case KO_ON_UNLOAD_THEN_STATUS: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case FILE_NOT_FOUND: case INTERNAL_ERROR_SERVER: default: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.ERROR); } } readWriteResult.setCurrentTape(workerCurrentTape); return readWriteResult; } }
WriteTask implements Future<ReadWriteResult> { @Override public ReadWriteResult get() { final ReadWriteResult readWriteResult = new ReadWriteResult(); try { File file = getWriteOrderFile(); if (null != workerCurrentTape) { if (canWriteOnTape()) { doWrite(file); } else { unloadThenLoadTapeAndWrite(file); } } else { loadTapeAndWrite(file); } retryable().execute(() -> updateTarReferential(file)); readWriteResult.setStatus(StatusCode.OK); readWriteResult.setOrderState(QueueState.COMPLETED); } catch (ReadWriteException e) { LOGGER.error(e); readWriteResult.setCode(e.getReadWriteErrorCode()); switch (e.getReadWriteErrorCode()) { case KO_LABEL_DISCORDING: case KO_LABEL_DISCORDING_NOT_EMPTY_TAPE: case KO_UNKNOWN_CURRENT_POSITION: workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); try { retryable().execute(() -> doUpdateTapeCatalog(workerCurrentTape)); } catch (ReadWriteException ex) { LOGGER.error(ex); } readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case KO_ON_WRITE_TO_TAPE: if (--cartridgeRetry >= 0) { workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); return get(); } else { readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); } break; case KO_ON_END_OF_TAPE: workerCurrentTape.setTapeState(TapeState.FULL); return get(); case KO_ON_GOTO_FILE_COUNT: case KO_ON_REWIND_FSF_BSF_TAPE: case KO_REWIND_BEFORE_UNLOAD_TAPE: case TAPE_LOCATION_CONFLICT_ON_LOAD: case TAPE_LOCATION_CONFLICT_ON_UNLOAD: case TAPE_LOCATION_UNKNOWN: case TAPE_NOT_FOUND_IN_CATALOG: case NO_EMPTY_SLOT_FOUND: case NULL_CURRENT_TAPE: case KO_ON_READ_FROM_TAPE: case KO_ON_REWIND_TAPE: case KO_ON_LOAD_TAPE: case KO_ON_UNLOAD_TAPE: case KO_ON_READ_LABEL: case KO_DB_PERSIST: case KO_TAPE_CURRENT_POSITION_GREATER_THAN_FILE_COUNT: case KO_ON_STATUS: case KO_ON_LOAD_THEN_STATUS: case KO_ON_UNLOAD_THEN_STATUS: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case FILE_NOT_FOUND: case INTERNAL_ERROR_SERVER: default: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.ERROR); } } readWriteResult.setCurrentTape(workerCurrentTape); return readWriteResult; } WriteTask(
        WriteOrder writeOrder, TapeCatalog workerCurrentTape, TapeLibraryService tapeLibraryService,
        TapeCatalogService tapeCatalogService,
        ArchiveReferentialRepository archiveReferentialRepository, String inputTarPath,
        boolean forceOverrideNonEmptyCartridges); }
WriteTask implements Future<ReadWriteResult> { @Override public ReadWriteResult get() { final ReadWriteResult readWriteResult = new ReadWriteResult(); try { File file = getWriteOrderFile(); if (null != workerCurrentTape) { if (canWriteOnTape()) { doWrite(file); } else { unloadThenLoadTapeAndWrite(file); } } else { loadTapeAndWrite(file); } retryable().execute(() -> updateTarReferential(file)); readWriteResult.setStatus(StatusCode.OK); readWriteResult.setOrderState(QueueState.COMPLETED); } catch (ReadWriteException e) { LOGGER.error(e); readWriteResult.setCode(e.getReadWriteErrorCode()); switch (e.getReadWriteErrorCode()) { case KO_LABEL_DISCORDING: case KO_LABEL_DISCORDING_NOT_EMPTY_TAPE: case KO_UNKNOWN_CURRENT_POSITION: workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); try { retryable().execute(() -> doUpdateTapeCatalog(workerCurrentTape)); } catch (ReadWriteException ex) { LOGGER.error(ex); } readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case KO_ON_WRITE_TO_TAPE: if (--cartridgeRetry >= 0) { workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); return get(); } else { readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); } break; case KO_ON_END_OF_TAPE: workerCurrentTape.setTapeState(TapeState.FULL); return get(); case KO_ON_GOTO_FILE_COUNT: case KO_ON_REWIND_FSF_BSF_TAPE: case KO_REWIND_BEFORE_UNLOAD_TAPE: case TAPE_LOCATION_CONFLICT_ON_LOAD: case TAPE_LOCATION_CONFLICT_ON_UNLOAD: case TAPE_LOCATION_UNKNOWN: case TAPE_NOT_FOUND_IN_CATALOG: case NO_EMPTY_SLOT_FOUND: case NULL_CURRENT_TAPE: case KO_ON_READ_FROM_TAPE: case KO_ON_REWIND_TAPE: case KO_ON_LOAD_TAPE: case KO_ON_UNLOAD_TAPE: case KO_ON_READ_LABEL: case KO_DB_PERSIST: case KO_TAPE_CURRENT_POSITION_GREATER_THAN_FILE_COUNT: case KO_ON_STATUS: case KO_ON_LOAD_THEN_STATUS: case KO_ON_UNLOAD_THEN_STATUS: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case FILE_NOT_FOUND: case INTERNAL_ERROR_SERVER: default: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.ERROR); } } readWriteResult.setCurrentTape(workerCurrentTape); return readWriteResult; } WriteTask(
        WriteOrder writeOrder, TapeCatalog workerCurrentTape, TapeLibraryService tapeLibraryService,
        TapeCatalogService tapeCatalogService,
        ArchiveReferentialRepository archiveReferentialRepository, String inputTarPath,
        boolean forceOverrideNonEmptyCartridges); @Override ReadWriteResult get(); @Override ReadWriteResult get(long timeout, TimeUnit unit); @Override boolean cancel(boolean mayInterruptIfRunning); @Override boolean isCancelled(); @Override boolean isDone(); }
WriteTask implements Future<ReadWriteResult> { @Override public ReadWriteResult get() { final ReadWriteResult readWriteResult = new ReadWriteResult(); try { File file = getWriteOrderFile(); if (null != workerCurrentTape) { if (canWriteOnTape()) { doWrite(file); } else { unloadThenLoadTapeAndWrite(file); } } else { loadTapeAndWrite(file); } retryable().execute(() -> updateTarReferential(file)); readWriteResult.setStatus(StatusCode.OK); readWriteResult.setOrderState(QueueState.COMPLETED); } catch (ReadWriteException e) { LOGGER.error(e); readWriteResult.setCode(e.getReadWriteErrorCode()); switch (e.getReadWriteErrorCode()) { case KO_LABEL_DISCORDING: case KO_LABEL_DISCORDING_NOT_EMPTY_TAPE: case KO_UNKNOWN_CURRENT_POSITION: workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); try { retryable().execute(() -> doUpdateTapeCatalog(workerCurrentTape)); } catch (ReadWriteException ex) { LOGGER.error(ex); } readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case KO_ON_WRITE_TO_TAPE: if (--cartridgeRetry >= 0) { workerCurrentTape.setTapeState(TapeState.CONFLICT); LOGGER.warn(MSG_PREFIX + TAPE_MSG + workerCurrentTape.getCode() + " is marked as conflict (incident close tape)"); return get(); } else { readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); } break; case KO_ON_END_OF_TAPE: workerCurrentTape.setTapeState(TapeState.FULL); return get(); case KO_ON_GOTO_FILE_COUNT: case KO_ON_REWIND_FSF_BSF_TAPE: case KO_REWIND_BEFORE_UNLOAD_TAPE: case TAPE_LOCATION_CONFLICT_ON_LOAD: case TAPE_LOCATION_CONFLICT_ON_UNLOAD: case TAPE_LOCATION_UNKNOWN: case TAPE_NOT_FOUND_IN_CATALOG: case NO_EMPTY_SLOT_FOUND: case NULL_CURRENT_TAPE: case KO_ON_READ_FROM_TAPE: case KO_ON_REWIND_TAPE: case KO_ON_LOAD_TAPE: case KO_ON_UNLOAD_TAPE: case KO_ON_READ_LABEL: case KO_DB_PERSIST: case KO_TAPE_CURRENT_POSITION_GREATER_THAN_FILE_COUNT: case KO_ON_STATUS: case KO_ON_LOAD_THEN_STATUS: case KO_ON_UNLOAD_THEN_STATUS: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.READY); break; case FILE_NOT_FOUND: case INTERNAL_ERROR_SERVER: default: readWriteResult.setStatus(StatusCode.FATAL); readWriteResult.setOrderState(QueueState.ERROR); } } readWriteResult.setCurrentTape(workerCurrentTape); return readWriteResult; } WriteTask(
        WriteOrder writeOrder, TapeCatalog workerCurrentTape, TapeLibraryService tapeLibraryService,
        TapeCatalogService tapeCatalogService,
        ArchiveReferentialRepository archiveReferentialRepository, String inputTarPath,
        boolean forceOverrideNonEmptyCartridges); @Override ReadWriteResult get(); @Override ReadWriteResult get(long timeout, TimeUnit unit); @Override boolean cancel(boolean mayInterruptIfRunning); @Override boolean isCancelled(); @Override boolean isDone(); static final String TAPE_MSG; static final String TAPE_LABEL; static final int SLEEP_TIME; static final int CARTRIDGE_RETRY; final String MSG_PREFIX; }