@Override public void execute(List<RegisteredMigrationStep> steps) { Profiler globalProfiler = Profiler.create(LOGGER); globalProfiler.startInfo(GLOBAL_START_MESSAGE); boolean allStepsExecuted = false; try { steps.forEach(this::execute); allStepsExecuted = true; } finally { if (allStepsExecuted) { globalProfiler.stopInfo(GLOBAL_END_MESSAGE, "success"); } else { globalProfiler.stopError(GLOBAL_END_MESSAGE, "failure"); } } }
private void doDatabaseMigration() { migrationState.setStatus(Status.RUNNING); migrationState.setStartedAt(new Date()); migrationState.setError(null); Profiler profiler = Profiler.create(LOGGER); try { profiler.startInfo("Starting DB Migration and container restart"); doUpgradeDb(); doRestartContainer(); migrationState.setStatus(Status.SUCCEEDED); profiler.stopInfo("DB Migration and container restart: success"); } catch (MigrationStepExecutionException e) { profiler.stopError("DB migration failed"); LOGGER.error("DB migration ended with an exception", e); saveStatus(e); } catch (Throwable t) { profiler.stopError("Container restart failed"); LOGGER.error("Container restart failed", t); saveStatus(t); } finally { semaphore.release(); } }
@Test public void stopError_adds_context_after_time_by_default() { addSomeContext(underTest); underTest.start().stopError("Rules registered"); assertThat(tester.logs()).hasSize(1); assertThat(tester.logs(LoggerLevel.ERROR).get(0)) .startsWith("Rules registered | time=") .endsWith("ms | a_string=bar | an_int=42 | after_start=true"); }
@Test public void stopError_adds_context_before_time_if_logTimeLast_is_true() { addSomeContext(underTest); underTest.logTimeLast(true); underTest.start().stopError("Rules registered"); assertThat(tester.logs()).hasSize(1); assertThat(tester.logs(LoggerLevel.ERROR).get(0)) .startsWith("Rules registered | a_string=bar | an_int=42 | after_start=true | time=") .endsWith("ms"); }
private void execute(RegisteredMigrationStep step, MigrationStep migrationStep) { Profiler stepProfiler = Profiler.create(LOGGER); stepProfiler.startInfo(STEP_START_PATTERN, step); boolean done = false; try { migrationStep.execute(); migrationHistory.done(step); done = true; } catch (Exception e) { throw new MigrationStepExecutionException(step, e); } finally { if (done) { stepProfiler.stopInfo(STEP_STOP_PATTERN, step, "success"); } else { stepProfiler.stopError(STEP_STOP_PATTERN, step, "failure"); } } } }
private static void stopActivityProfiler(Profiler profiler, CeTask task, CeActivityDto.Status status) { addContext(profiler, task); if (status == CeActivityDto.Status.FAILED) { profiler.stopError("Executed task"); } else { profiler.stopInfo("Executed task"); } }
@Override public void execute(Stream<RegisteredMigrationStep> steps) { Profiler globalProfiler = Profiler.create(LOGGER); globalProfiler.startInfo(GLOBAL_START_MESSAGE); boolean allStepsExecuted = false; try { steps.forEachOrdered(this::execute); allStepsExecuted = true; } finally { if (allStepsExecuted) { globalProfiler.stopInfo(GLOBAL_END_MESSAGE, "success"); } else { globalProfiler.stopError(GLOBAL_END_MESSAGE, "failure"); } } }
private void doDatabaseMigration() { migrationState.setStatus(Status.RUNNING); migrationState.setStartedAt(new Date()); migrationState.setError(null); Profiler profiler = Profiler.create(LOGGER); try { profiler.startInfo("Starting DB Migration and container restart"); doUpgradeDb(); doRestartContainer(); migrationState.setStatus(Status.SUCCEEDED); profiler.stopInfo("DB Migration and container restart: success"); } catch (MigrationStepExecutionException e) { profiler.stopError("DB migration failed"); LOGGER.error("DB migration ended with an exception", e); saveStatus(e); } catch (Throwable t) { profiler.stopError("Container restart failed"); LOGGER.error("Container restart failed", t); saveStatus(t); } finally { semaphore.release(); } }
private void execute(RegisteredMigrationStep step, MigrationStep migrationStep) { Profiler stepProfiler = Profiler.create(LOGGER); stepProfiler.startInfo(STEP_START_PATTERN, step); boolean done = false; try { migrationStep.execute(); migrationHistory.done(step); done = true; } catch (Exception e) { throw new MigrationStepExecutionException(step, e); } finally { if (done) { stepProfiler.stopInfo(STEP_STOP_PATTERN, step, "success"); } else { stepProfiler.stopError(STEP_STOP_PATTERN, step, "failure"); } } } }