@Override public void execute(ILifecycleProgressMonitor monitor) throws SiteWhereException { monitor.pushContext(new LifecycleProgressContext(steps.size(), getName())); StringBuffer buffer = new StringBuffer(); buffer.append("About to process composite lifecycle with " + steps.size() + "steps:\n"); for (ILifecycleStep step : steps) { buffer.append(" " + step.getName() + "\n"); } LOGGER.debug(buffer.toString()); try { for (ILifecycleStep step : steps) { LOGGER.debug("Starting " + step.getName()); monitor.startProgress(step.getName()); step.execute(monitor); monitor.finishProgress(); } } finally { monitor.popContext(); } }
/** * Finish the currently executing progress operation. * * @param monitor * @throws SiteWhereException */ public static void finishProgressOperation(ILifecycleProgressMonitor monitor) throws SiteWhereException { ILifecycleProgressContext context = monitor.getContextStack().peek(); if (context == null) { throw new SiteWhereException("Unable to finish operation. No context available."); } // Report progress based on new operation. String task = monitor.getContextStack().getLast().getCurrentOperationMessage(); String current = monitor.getContextStack().getFirst().getCurrentOperationMessage(); Deque<ILifecycleProgressContext> queue = new ArrayDeque<>(monitor.getContextStack()); double progress = computeSubprogressFor(queue, 100.0); monitor.reportProgress(new ProgressMessage(task, progress, current)); }
try { span = monitor.createTracerSpan("Initialize " + getComponentName()); setLifecycleStatus(LifecycleStatus.InitializationError); getLogger().error(getComponentName() + " state transitioned to ERROR.", e); monitor.handleErrorInTracerSpan(span, e); } catch (Throwable t) { setLifecycleError(new SiteWhereException(t)); setLifecycleStatus(LifecycleStatus.InitializationError); getLogger().error(getComponentName() + " state transitioned to ERROR.", t); monitor.handleErrorInTracerSpan(span, t); } finally { monitor.finishTracerSpan(span);
/** * Common logic for starting an operation on an * {@link ILifecycleProgressMonitor}. * * @param monitor * @param operation * @throws SiteWhereException */ public static void startProgressOperation(ILifecycleProgressMonitor monitor, String operation) throws SiteWhereException { ILifecycleProgressContext context = monitor.getContextStack().peek(); if (context == null) { throw new SiteWhereException("Unable to start operation. No context available."); } int newIndex = context.getCurrentOperationIndex() + 1; if (newIndex > context.getOperationCount()) { throw new SiteWhereException( "Unable to start operation. Index will exceed expected operation count. Operation was: " + operation); } context.setCurrentOperationIndex(newIndex); context.setCurrentOperationMessage(operation); }
try { span = monitor.createTracerSpan("Start " + getComponentName()); setLifecycleStatus(LifecycleStatus.LifecycleError); getLogger().error(getComponentName() + " state transitioned to ERROR.", e); monitor.handleErrorInTracerSpan(span, e); } catch (Throwable t) { setLifecycleError(new SiteWhereException(t)); setLifecycleStatus(LifecycleStatus.LifecycleError); getLogger().error(getComponentName() + " state transitioned to ERROR.", t); monitor.handleErrorInTracerSpan(span, t); } finally { monitor.finishTracerSpan(span);
/** * Common logic for starting an operation on an * {@link ILifecycleProgressMonitor}. * * @param monitor * @param operation * @throws SiteWhereException */ public static void startProgressOperation(ILifecycleProgressMonitor monitor, String operation) throws SiteWhereException { ILifecycleProgressContext context = monitor.getContextStack().peek(); if (context == null) { throw new SiteWhereException("Unable to start operation. No context available."); } int newIndex = context.getCurrentOperationIndex() + 1; if (newIndex > context.getOperationCount()) { throw new SiteWhereException( "Unable to start operation. Index will exceed expected operation count. Operation was: " + operation); } context.setCurrentOperationIndex(newIndex); context.setCurrentOperationMessage(operation); }
@Override public void execute(ILifecycleProgressMonitor monitor) throws SiteWhereException { monitor.pushContext(new LifecycleProgressContext(steps.size(), getName())); try { for (ILifecycleStep step : steps) { LOGGER.debug("Starting " + step.getName()); ActiveSpan span = monitor.getMicroservice().getTracer().activeSpan(); try { TracerUtils.logToSpan(span, "Starting step '" + step.getName() + "'."); monitor.startProgress(step.getName()); step.execute(monitor); monitor.finishProgress(); } catch (SiteWhereException e) { TracerUtils.handleErrorInTracerSpan(span, e); throw e; } catch (Throwable t) { SiteWhereException e = new SiteWhereException("Unhandled exception in composite lifecycle step.", t); TracerUtils.handleErrorInTracerSpan(span, e); throw e; } } } finally { monitor.popContext(); } }
/** * Finish the currently executing progress operation. * * @param monitor * @throws SiteWhereException */ public static void finishProgressOperation(ILifecycleProgressMonitor monitor) throws SiteWhereException { ILifecycleProgressContext context = monitor.getContextStack().peek(); if (context == null) { throw new SiteWhereException("Unable to finish operation. No context available."); } // Report progress based on new operation. String task = monitor.getContextStack().getLast().getCurrentOperationMessage(); String current = monitor.getContextStack().getFirst().getCurrentOperationMessage(); Deque<ILifecycleProgressContext> queue = new ArrayDeque<>(monitor.getContextStack()); double progress = computeSubprogressFor(queue, 100.0); monitor.reportProgress(new ProgressMessage(task, progress, current)); }
try { span = monitor.createTracerSpan("Stop " + getComponentName()); setLifecycleStatus(LifecycleStatus.LifecycleError); getLogger().error(getComponentName() + " state transitioned to ERROR.", e); monitor.handleErrorInTracerSpan(span, e); } catch (Throwable t) { setLifecycleError(new SiteWhereException(t)); setLifecycleStatus(LifecycleStatus.LifecycleError); getLogger().error(getComponentName() + " state transitioned to ERROR.", t); monitor.handleErrorInTracerSpan(span, t); } finally { monitor.finishTracerSpan(span);