@Override public ServiceRegistrar createForDomain(final String domain) { return new NopServiceRegistrar(); } }
/** * Load a {@link ServiceRegistrarFactory} using the current class loader. * * @return A {@link ServiceRegistrarFactory}, null if none could be found. * * @throws ServiceRegistrarLoadingException if loading failed. */ public static ServiceRegistrarFactory load() throws ServiceRegistrarLoadingException { return load("classpath", CURRENT); }
@Override public ServiceRegistrationHandle register(final ServiceRegistration registration) { return new NopServiceRegistrationHandle(); }
@Test public void test() throws Exception { startDefaultMaster("--service-registry=" + registryAddress); verify(registrar, timeout((int) SECONDS.toMillis(LONG_WAIT_SECONDS))) .register(registrationCaptor.capture()); final ServiceRegistration registration = registrationCaptor.getValue(); final ServiceRegistration.Endpoint endpoint = getOnlyElement(registration.getEndpoints()); assertEquals("http", endpoint.getProtocol()); assertEquals("helios", endpoint.getName()); assertEquals(masterPort(), endpoint.getPort()); } }
return factory.create(address); } else if (!Strings.isNullOrEmpty(domain)) { log.info("Creating service registrar for domain: {}", domain); ? factory.create("tcp://localhost:4999") : factory.createForDomain(domain); } else { log.info("No address nor domain configured, not creating service registrar."); return new NopServiceRegistrar();
/** * Load a {@link ServiceRegistrarFactory} from a plugin jar file with a parent class loader that * will not load classes from the jvm classpath. Any dependencies of the plugin must be included * in the plugin jar. * * @param plugin The plugin jar file to load. * * @return A {@link ServiceRegistrarFactory}, null if none could be found. * * @throws ServiceRegistrarLoadingException if loading failed. */ public static ServiceRegistrarFactory load(final Path plugin) throws ServiceRegistrarLoadingException { return load(plugin, CURRENT, extensionClassLoader(CURRENT)); }
/** * Load a {@link ServiceRegistrarFactory} from a plugin jar file with a specified parent class * loader and a list of exposed classes. * * @param plugin The plugin jar file to load. * @param environment The class loader to use for providing plugin interface dependencies. * @param parent The parent class loader to assign to the class loader of the jar. * * @return A {@link ServiceRegistrarFactory}, null if none could be found. * * @throws ServiceRegistrarLoadingException if loading failed. */ public static ServiceRegistrarFactory load(final Path plugin, final ClassLoader environment, final ClassLoader parent) throws ServiceRegistrarLoadingException { return load("plugin jar file: " + plugin, pluginClassLoader(plugin, environment, parent)); }
/** * Get a registrar factory from the application class loader. * * @return The ServiceRegistrarFactory object. */ private static ServiceRegistrarFactory createFactory() { final ServiceRegistrarFactory factory; final ServiceRegistrarFactory installed; try { installed = ServiceRegistrarLoader.load(); } catch (ServiceRegistrarLoadingException e) { throw new RuntimeException("Unable to load service registrar", e); } if (installed == null) { log.debug("No service registrar plugin configured"); factory = new NopServiceRegistrarFactory(); } else { factory = installed; final String name = factory.getClass().getName(); log.info("Loaded installed service registrar: {}", name); } return factory; } }
protected ServiceRegistrar mockServiceRegistrar() { final ServiceRegistrar registrar = mock(ServiceRegistrar.class); when(registrar.register(any(ServiceRegistration.class))).thenAnswer(new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { return mock(ServiceRegistrationHandle.class); } }); return registrar; }
public Builder endpoint(final String name, final String protocol, final int port, final String domain, final String host, final List<String> tags) { endpoints.add(new Endpoint(name, protocol, port, domain, host, tags, null)); return this; }
public static EndpointHealthCheck newHttpCheck(String path) { return new EndpointHealthCheck(HTTP, path); }
public ServiceRegistration build() { return new ServiceRegistration(endpoints); }
public static Builder newBuilder() { return new Builder(); }
/** * Unregister a set of service endpoints previously registered. * * @return boolean true if service registration handle was present, false otherwise */ public boolean unregister() { if (serviceRegistrationHandle.isPresent()) { registrar.unregister(serviceRegistrationHandle.get()); serviceRegistrationHandle = Optional.absent(); return true; } return false; }
/** * Load a {@link ServiceRegistrarFactory} using a class loader. * * @param source The source of the class loader. * @param classLoader The class loader to load from. * * @return A {@link ServiceRegistrarFactory}, null if none could be found. * * @throws ServiceRegistrarLoadingException if loading failed. */ public static ServiceRegistrarFactory load(final String source, final ClassLoader classLoader) throws ServiceRegistrarLoadingException { final ServiceLoader<ServiceRegistrarFactory> loader; try { loader = ServiceLoader.load(ServiceRegistrarFactory.class, classLoader); } catch (ServiceConfigurationError e) { throw new ServiceRegistrarLoadingException( "Failed to load service registrar from " + source, e); } final Iterator<ServiceRegistrarFactory> iterator = loader.iterator(); if (iterator.hasNext()) { return iterator.next(); } else { return null; } }
private void assertContainerRegistersAfterPoke(final HeliosClient client, final Job job) throws Exception { final JobId jobId = createJob(job); deployJob(jobId, testHost()); awaitTaskState(jobId, testHost(), HEALTHCHECKING); // wait a few seconds to see if the service gets registered Thread.sleep(3000); // shouldn't be registered, since we haven't poked it yet verify(registrar, never()).register(any(ServiceRegistration.class)); pokeAndVerifyRegistration(client, jobId, LONG_WAIT_SECONDS); final ServiceRegistration serviceRegistration = registrationCaptor.getValue(); final Map<String, Endpoint> registered = Maps.newHashMap(); for (final Endpoint endpoint : serviceRegistration.getEndpoints()) { registered.put(endpoint.getName(), endpoint); } assertEquals("wrong service", "foo_service", registered.get("foo_service").getName()); assertEquals("wrong protocol", "foo_proto", registered.get("foo_service").getProtocol()); }
@Override public ServiceRegistrar create(final String address) { return new NopServiceRegistrar(); }
public Builder endpoint(final String name, final String protocol, final int port, final String domain, final String host, final List<String> tags, final EndpointHealthCheck healthCheck) { endpoints.add(new Endpoint(name, protocol, port, domain, host, tags, healthCheck)); return this; }
public static EndpointHealthCheck newTcpCheck() { return new EndpointHealthCheck(TCP, null); }
public Builder endpoint(final String name, final String protocol, final int port, final String domain, final String host) { endpoints.add(new Endpoint(name, protocol, port, domain, host, null, null)); return this; }