@Override public void validate(final Configuration configuration) throws Exception { checkNotNull(configuration); Set<ConstraintViolation<?>> violations = new HashSet<>(); MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets) { log.debug("Validating facet: {}", facet); try { facet.validate(configuration); } catch (ConstraintViolationException e) { log.debug("Facet validation produced violations: {}", facet, e); violations.addAll(e.getConstraintViolations()); } catch (Throwable t) { log.error("Failed to validate facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to validate facets"); if (!violations.isEmpty()) { throw new ConstraintViolationException(violations); } }
@Override @Transitions(from = NEW, to = INITIALISED) public void init(final Configuration configuration) throws Exception { this.configuration = checkNotNull(configuration); this.name = configuration.getRepositoryName(); MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets) { try { log.debug("Initializing facet: {}", facet); facet.init(); } catch (Throwable t) { log.error("Failed to initialize facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to initialize facets"); }
/** * Stop all managed components. * * Stop order is reverse of start order. * * @throws MultipleFailuresException */ @Override protected void doStop() throws Exception { int count = components.size(); log.debug("Stopping {} components", count); MultipleFailures failures = new MultipleFailures(count); for (Lifecycle component : Lists.reverse(components)) { try { component.stop(); } catch (Throwable failure) { logTransitionFailure("Failed to stop component: " + component, failure); failures.add(failure); } } failures.maybePropagate("Failed to stop " + failures.size() + " components"); } }
@Override @Guarded(by = STOPPED) public void update(final Configuration configuration) throws Exception { checkNotNull(configuration); // Ensure configuration sanity validate(configuration); this.configuration = configuration; MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets) { try { log.debug("Updating facet: {}", facet); facet.update(); } catch (Throwable t) { log.error("Failed to update facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to update facets"); }
@Override @Transitions(from = STOPPED, to = DELETED) public void delete() throws Exception { MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets.reverse()) { try { log.debug("Deleting facet: {}", facet); facet.delete(); } catch (Throwable t) { log.error("Failed to delete facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to delete facets"); }
@Override @Transitions(from = {INITIALISED, STOPPED}, to = STARTED) public void start() throws Exception { MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets) { try { log.debug("Starting facet: {}", facet); facet.start(); } catch (Throwable t) { log.error("Failed to start facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to start facets"); eventManager.post(new RepositoryStartedEvent(this)); }
/** * Start all managed components. * * Components are started in the order added. * * @throws MultipleFailuresException */ @Override protected void doStart() throws Exception { int count = components.size(); log.debug("Starting {} components", count); MultipleFailures failures = new MultipleFailures(count); for (Lifecycle component : components) { try { component.start(); } catch (Throwable failure) { logTransitionFailure("Failed to start component: " + component, failure); failures.add(failure); } } failures.maybePropagate("Failed to start " + failures.size() + " components"); }
@Override protected Object execute() throws Exception { List<Callable<Void>> jobs = Lists.newArrayList(); final LocalDateTime timestamp = LocalDateTime.now(); log.info("task named '{}' database backup to location {}", getName(), location); MultipleFailures failures = new MultipleFailures(); final FreezeRequest request = freezeService.requestFreeze(InitiatorType.SYSTEM, getConfiguration().getName()); if (request == null) { throw new RuntimeException("unable to perform backup task, as attempt to freeze databases failed"); } for (String dbName : databaseBackup.dbNames()) { try { log.info("database backup of {} starting", dbName); Callable<Void> job = databaseBackup.fullBackup(location, dbName, timestamp); jobs.add(job); } catch (Exception e) { failures.add(new RuntimeException(String.format( "database backup of %s to location: %s please check filesystem permissions and that the location exists", dbName, location), e)); } } monitorBackupResults(jobs, failures); if (!freezeService.releaseRequest(request)) { failures.add(new RuntimeException( "failed to automatically release read-only state; view the nodes screen to disable read-only mode.")); } failures.maybePropagate(); return null; }
@Override @Transitions(from = STARTED, to = STOPPED) public void stop() throws Exception { MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets.reverse()) { try { log.debug("Stopping facet: {}", facet); facet.stop(); } catch (Throwable t) { log.error("Failed to stop facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to stop facets"); eventManager.post(new RepositoryStoppedEvent(this)); }
@Override protected Object execute() throws Exception { processedRepositories = Sets.newHashSet(); MultipleFailures failures = new MultipleFailures(); for (Repository repository : findRepositories()) { if (isCanceled()) { break; } try { execute(repository); } catch (TaskInterruptedException e) { // NOSONAR throw e; } catch (Exception e) { log.error("Failed to run task '{}' on repository '{}'", getMessage(), repository.getName(), e); failures.add(e); } } failures.maybePropagate(String.format("Failed to run task '%s'", getMessage())); return null; }
@Override @Transitions(to = DESTROYED) public void destroy() throws Exception { if (states.is(STARTED)) { stop(); } MultipleFailures failures = new MultipleFailures(); for (Facet facet : facets.reverse()) { try { log.debug("Destroying facet: {}", facet); facet.destroy(); } catch (Throwable t) { log.error("Failed to destroy facet: {}", facet, t); failures.add(t); } } failures.maybePropagate("Failed to destroy facets"); facets.clear(); configuration = null; eventManager.post(new RepositoryDestroyedEvent(this)); }