/** * Infrastructure use only */ static boolean validateServiceOptions(ServiceHost host, Service service, Operation post) { for (ServiceOption o : service.getOptions()) { String error = Utils.validateServiceOption(service.getOptions(), o); if (error != null) { host.log(Level.WARNING, "%s", error); post.fail(new IllegalArgumentException(error)); return false; } } if (service.getMaintenanceIntervalMicros() > 0 && service.getMaintenanceIntervalMicros() < host.getMaintenanceCheckIntervalMicros()) { host.setMaintenanceCheckIntervalMicros(service.getMaintenanceIntervalMicros()); } return true; }
continue; if (s.getMaintenanceIntervalMicros() == 0) { continue; if (s.getMaintenanceIntervalMicros() < micros) { String error = String.format( "Service %s has a small maintenance interval %d than new interval %d", s.getSelfLink(), s.getMaintenanceIntervalMicros(), micros); log(Level.WARNING, error); minInterval = s.getMaintenanceIntervalMicros();
public void schedule(Service s, long now) { long interval = s.getMaintenanceIntervalMicros(); if (interval == 0) { interval = this.host.getMaintenanceIntervalMicros(); } if (interval < this.host.getMaintenanceCheckIntervalMicros()) { this.host.setMaintenanceCheckIntervalMicros(interval); } long nextExpirationMicros = Math.max(now, now + interval - SCHEDULING_EPSILON_MICROS); String selfLink = s.getSelfLink(); synchronized (this) { // To avoid double scheduling the same self-link // we lookup the self-link in our trackedServices map and remove // it before adding the new schedule. Long expiration = this.trackedServices.get(selfLink); if (expiration != null) { Set<String> services = this.nextExpiration.get(expiration); if (services != null) { services.remove(selfLink); } } this.trackedServices.put(selfLink, nextExpirationMicros); Set<String> services = this.nextExpiration.get(nextExpirationMicros); if (services == null) { services = new HashSet<>(); this.nextExpiration.put(nextExpirationMicros, services); } services.add(selfLink); } }
/** * Construct common data in {@link ServiceConfiguration}. */ public static <T extends ServiceConfiguration> T buildServiceConfig(T config, Service service) { ServiceDocumentDescription desc = service.getHost().buildDocumentDescription(service); config.options = service.getOptions(); config.maintenanceIntervalMicros = service.getMaintenanceIntervalMicros(); config.versionRetentionLimit = desc.versionRetentionLimit; config.versionRetentionFloor = desc.versionRetentionFloor; config.peerNodeSelectorPath = service.getPeerNodeSelectorPath(); config.documentIndexPath = service.getDocumentIndexPath(); return config; } }
long actual = now - start[0]; long limit = Math.max(this.host.getMaintenanceIntervalMicros(), s.getMaintenanceIntervalMicros()); if (s.hasOption(ServiceOption.INSTRUMENTATION)) { updateStats(s, actual, limit, servicePath);
@Test public void testBuildServiceConfig() { Service exampleService = new ExampleService(); exampleService.setHost(VerificationHost.create()); ServiceConfiguration config = new ServiceConfiguration(); Utils.buildServiceConfig(config, exampleService); assertEquals(exampleService.getOptions(), config.options); assertEquals(exampleService.getMaintenanceIntervalMicros(), config.maintenanceIntervalMicros); assertEquals(ExampleServiceState.VERSION_RETENTION_LIMIT, config.versionRetentionLimit); assertEquals(ExampleServiceState.VERSION_RETENTION_FLOOR, config.versionRetentionFloor); assertEquals(exampleService.getPeerNodeSelectorPath(), config.peerNodeSelectorPath); assertEquals(exampleService.getDocumentIndexPath(), config.documentIndexPath); }
@Test public void testBuildServiceConfig() { Service exampleService = new ExampleService(); exampleService.setHost(VerificationHost.create()); ServiceConfiguration config = new ServiceConfiguration(); Utils.buildServiceConfig(config, exampleService); assertEquals(exampleService.getOptions(), config.options); assertEquals(exampleService.getMaintenanceIntervalMicros(), config.maintenanceIntervalMicros); assertEquals(ExampleServiceState.VERSION_RETENTION_LIMIT, config.versionRetentionLimit); assertEquals(ExampleServiceState.VERSION_RETENTION_FLOOR, config.versionRetentionFloor); assertEquals(exampleService.getPeerNodeSelectorPath(), config.peerNodeSelectorPath); assertEquals(exampleService.getDocumentIndexPath(), config.documentIndexPath); }