public static long getRegistryHeartbeatInterval() { return getLong(REGISTRY_HEARTBEAT_INTERVAL, 10000L); }
public static boolean getRegistryUseSSL() { return getBoolean(REGISTRY_USESSL, false); }
public static String getRegistryContextroot() { return getString(REGISTRY_CONTEXTROOT, "microverse-rest-registry"); }
long getLatency(final AbstractDescriptor descriptor) { long latency = Long.MAX_VALUE; try { final long startTime = System.currentTimeMillis(); ServiceUtils.executeRequest(descriptor, descriptor.getHeartbeatUri(), null); latency = System.currentTimeMillis() - startTime; } catch (final ServiceException e) { LOG.warn("Heartbeat to " + descriptor + " failed!"); } return latency; }
/** * Add the service for the specified service-bundle to the RestServiceServer at the host and port. * * @param serviceBundlePath the path to the service-bundle * @return the {@link ServiceDescriptor} filled with server parameters * @throws ServiceException */ public RestServiceServerUtil addService(final Path serviceBundlePath) throws ServiceException { try { final HttpPost post = new HttpPost(ServiceUtils.buildURL(host, port, useSSL, contextRoot + "/server/add")); // post.addHeader(HttpHeaders.CONTENT_TYPE, marshaller.getMimeType()); post.addHeader(HttpHeaders.ACCEPT, ServiceUtils.getAcceptedMimeTypes()); post.setEntity(EntityBuilder.create().setBinary(Files.readAllBytes(serviceBundlePath)).build()); ServiceUtils.executeRequest(post, useSSL); return this; } catch (final ServiceException e) { throw e; } catch (final Exception e) { throw new ServiceException("Could not add service-bundle " + serviceBundlePath, e); } }
public void removeService(final String serviceId, final String serviceVersion) throws ServiceException { final HttpPost post = new HttpPost(ServiceUtils.buildURL(host, port, useSSL, contextRoot + "/server/remove/" + serviceId + "/" + serviceVersion)); try { ServiceUtils.executeRequest(post, useSSL); } catch (final ServiceException e) { throw e; } catch (final Exception e) { throw new ServiceException("Could not remove service " + serviceId + ":" + serviceVersion, e); } }
/** * Gets a {@link IMarshaller} by querying the REST server's supported mime-types and trying to * find a match by the clients supported mime-types. * * @param host the host of the REST server * @param port the port of the REST server * @param restServerUri the URI which returns the mime-types in text/plain * @return the {@link IMarshaller} * @throws ServiceException */ public static IMarshaller getMarshallerToCommunicateWithRestServer(final String host, final int port, final String restServerUri) throws ServiceException { // first determine which mime-types the rest server supports final List<String> registryServerMimeTypes = ServiceUtils.getSupportedMediaTypesOfRestServer(host, port, restServerUri); // try to get a matching marshaller for the supported mime-type IMarshaller marshaller = null; for (final String mimeType : registryServerMimeTypes) { marshaller = MarshallerFactory.get(mimeType); if (marshaller != null) { break; } } // check if a common mime-type was found if (marshaller == null) { throw new ServiceException("Could not find common mime-type to communicate with reqistry server. A marshaller for one of the following mime-types must be provided: " + registryServerMimeTypes); } return marshaller; }
/** * Gets the fully qualified URL string to the service. * * @param serviceDescriptor the {@link ServiceDescriptor} * @return the URL string */ public static String getServiceURL(final ServiceDescriptor serviceDescriptor) { return buildURL(serviceDescriptor.getHost(), serviceDescriptor.getPort(), serviceDescriptor.isUseSSL(), serviceDescriptor.getServiceUri().getUri()); }
public static int getRegistryPort() { return getInt(REGISTRY_PORT, 8080); }
@PostConstruct public void init() { final String dir = Configuration.getServiceDeployDir(); if (dir != null) { serviceDir = Paths.get(dir); } else { LOG.warn("No deploy directory configured. Please set the system property '" + Configuration.getServiceDeployDir() + "'!"); serviceDir = Paths.get("."); } }
public static HttpResponse executeRequest(final AbstractDescriptor descriptor, final WebCall webCall, final Serializable entity) throws ServiceException { return executeRequest(descriptor.getHost(), descriptor.getPort(), descriptor.isUseSSL(), webCall, descriptor.getSupportedMimeTypes(), entity); }
public static long getServerHeartbeatInterval() { return getLong(SERVER_HEARTBEAT_INTERVAL, 10000L); }
public static String getServiceDeployDir() { return getString(SERVICE_DEPLOY_DIR, "./deploy"); }
public static boolean getServerUseSSL() { return getBoolean(SERVER_USESSL, false); }
public static int getServerPort() { return getInt(SERVER_PORT, 8080); }
/** * Register the specified {@link ServiceDescriptor} with the registry-server. * * @param serviceDescriptors the {@link ServiceDescriptor} * @throws ServiceException */ public void unregisterService(final ServiceDescriptor serviceDescriptor) throws ServiceException { // notify all know registries about the removed service for (final RegistryDescriptor registryDescriptor : RegistryDiscovererService.requestRegistries()) { try { ServiceUtils.executeRequest(registryDescriptor, registryDescriptor.getUnregisterUri(), serviceDescriptor); } catch (final Exception e) { LOG.error("Unable to unregister: " + serviceDescriptor, e); throw new ServiceException("Unable to unregister: " + serviceDescriptor, e); } } }
public static long getAutoDeployStartDelay() { return getLong(AUTODEPLOY_START_DELAY, 0L); }
public static String getRegistryHost() { return getString(REGISTRY_HOST, "localhost"); }
/** * Register the specified {@link ServiceDescriptor} with the registry servers. * * @param serviceDescriptors the {@link ServiceDescriptor} * @throws ServiceException */ public void registerService(final ServiceDescriptor serviceDescriptor) throws ServiceException { // notify all know registries about the new service for (final RegistryDescriptor registryDescriptor : RegistryDiscovererService.requestRegistries()) { try { ServiceUtils.executeRequest(registryDescriptor, registryDescriptor.getRegisterUri(), serviceDescriptor); } catch (final Exception e) { LOG.error("Unable to register: " + serviceDescriptor, e); throw new ServiceException("Unable to register: " + serviceDescriptor, e); } } }
/** * Propagates the specified service to all other known registries. The {@link Action} specifies * whether it was added or removed. * * @param propagateServiceDescriptor the {@link ServiceDescriptor} of the registry * @param action the {@link Action} */ void propagateServiceToOtherRegistries(final ServiceDescriptor propagateServiceDescriptor, final Action action) { // propagate the service to all other known registries for (final RegistryDescriptor otherRegistryDescriptor : registryCache.getAll()) { try { WebCall webCall = null; switch (action) { case ADD: webCall = otherRegistryDescriptor.getRegisterUri(); break; case REMOVE: webCall = otherRegistryDescriptor.getUnregisterUri(); break; } ServiceUtils.executeRequest(otherRegistryDescriptor, webCall, propagateServiceDescriptor); } catch (final Exception e) { LOG.warn("Unable to propagate service (" + propagateServiceDescriptor + ") to registry: " + registryDescriptor, e); } } }