public static Map<String, String> service(ServiceId serviceId) { return ImmutableMap.of( Constants.Metrics.Tag.NAMESPACE, serviceId.getNamespace(), Constants.Metrics.Tag.APP, serviceId.getApplication(), Constants.Metrics.Tag.SERVICE, serviceId.getProgram()); }
public static Map<String, String> service(ServiceId serviceId) { return ImmutableMap.of( Constants.Metrics.Tag.NAMESPACE, serviceId.getNamespace(), Constants.Metrics.Tag.APP, serviceId.getApplication(), Constants.Metrics.Tag.SERVICE, serviceId.getProgram()); }
public static Map<String, String> serviceHandler(ServiceId id, String handlerId) { return ImmutableMap.of( Constants.Metrics.Tag.NAMESPACE, id.getNamespace(), Constants.Metrics.Tag.APP, id.getApplication(), Constants.Metrics.Tag.SERVICE, id.getProgram(), Constants.Metrics.Tag.HANDLER, handlerId); } }
public static Map<String, String> serviceHandler(ServiceId id, String handlerId) { return ImmutableMap.of( Constants.Metrics.Tag.NAMESPACE, id.getNamespace(), Constants.Metrics.Tag.APP, id.getApplication(), Constants.Metrics.Tag.SERVICE, id.getProgram(), Constants.Metrics.Tag.HANDLER, handlerId); } }
/** * Constructs URL to reach RouteConfig REST API endpoints of a service. * * @param serviceId {@link ServiceId} of the service with the application version part ignored */ private URL buildRouteConfigUrl(ServiceId serviceId) throws MalformedURLException { String path = String.format("apps/%s/services/%s/routeconfig", serviceId.getApplication(), serviceId.getEntityName()); return config.resolveNamespacedURLV3(serviceId.getNamespaceId(), path); } }
/** * Gets a {@link URL} to call methods for the endpoint of a {@link Service} with no application version. If multiple * versions exist, traffic to the {@link URL} will be distributed to each version according to routing strategy. If * only one version exists, this version will always be reached with the {@link URL}. * * @param service {@link ServiceId} of the service * @return a URL to call methods of the service * @throws NotFoundException @throws NotFoundException if the app or service could not be found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public URL getServiceURL(ServiceId service) throws NotFoundException, IOException, UnauthenticatedException, UnauthorizedException { return config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/services/%s/methods/", service.getApplication(), service.getEntityName())); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { ServiceId serviceId = new ServiceId(parseProgramId(arguments, ElementType.SERVICE)); String appName = serviceId.getApplication(); String serviceName = serviceId.getProgram(); serviceClient.deleteRouteConfig(serviceId); output.printf("Successfully deleted route configuration of %s '%s' of application '%s'\n", ElementType.SERVICE.getName(), serviceName, appName); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { ServiceId serviceId = new ServiceId(parseProgramId(arguments, ElementType.SERVICE)); String appName = serviceId.getApplication(); String serviceName = serviceId.getProgram(); serviceClient.deleteRouteConfig(serviceId); output.printf("Successfully deleted route configuration of %s '%s' of application '%s'\n", ElementType.SERVICE.getName(), serviceName, appName); }
/** * Calls the non-versioned service endpoint for a given method and get routed to a specific version by the Router * * @param serviceId {@link ServiceId} of the service with the application version part ignored * @param methodPath the path specifying only the method * @return {@link HttpResponse} from the service method */ public HttpResponse callServiceMethod(ServiceId serviceId, String methodPath) throws IOException, UnauthorizedException, UnauthenticatedException { String path = String.format("apps/%s/services/%s/methods/%s", serviceId.getApplication(), serviceId.getEntityName(), methodPath); URL url = config.resolveNamespacedURLV3(serviceId.getNamespaceId(), path); return restClient.execute(HttpMethod.GET, url, config.getAccessToken()); }
/** * Gets a {@link URL} to call methods for a specific version of a {@link Service}. * * @param service {@link ServiceId} of the service * @return a URL to call methods of the service * @throws NotFoundException @throws NotFoundException if the app or service could not be found * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public URL getVersionedServiceURL(ServiceId service) throws NotFoundException, IOException, UnauthenticatedException, UnauthorizedException { // Make sure the service actually exists get(service); return config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/versions/%s/services/%s/methods/", service.getApplication(), service.getVersion(), service.getEntityName())); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { ServiceId serviceId = new ServiceId(parseProgramId(arguments, ElementType.SERVICE)); String routeConfig = arguments.get(ArgumentName.ROUTE_CONFIG.getName()); serviceClient.storeRouteConfig(serviceId, ArgumentParser.parseStringIntegerMap( routeConfig, ArgumentName.ROUTE_CONFIG.toString())); output.printf("Successfully set route configuration of %s '%s' of application '%s' to '%s'\n", ElementType.SERVICE.getName(), serviceId.getProgram(), serviceId.getApplication(), routeConfig); }
@Override public void perform(Arguments arguments, PrintStream output) throws Exception { ServiceId serviceId = new ServiceId(parseProgramId(arguments, ElementType.SERVICE)); String routeConfig = arguments.get(ArgumentName.ROUTE_CONFIG.getName()); serviceClient.storeRouteConfig(serviceId, ArgumentParser.parseStringIntegerMap( routeConfig, ArgumentName.ROUTE_CONFIG.toString())); output.printf("Successfully set route configuration of %s '%s' of application '%s' to '%s'\n", ElementType.SERVICE.getName(), serviceId.getProgram(), serviceId.getApplication(), routeConfig); }
/** * Sets the number of instances of a service. * * @param service the service * @param instances number of instances for the service * @throws IOException if a network error occurred * @throws NotFoundException if the application or service could not be found * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public void setServiceInstances(ServiceId service, int instances) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/services/%s/instances", service.getApplication(), service.getProgram())); HttpRequest request = HttpRequest.put(url).withBody(GSON.toJson(new Instances(instances))).build(); HttpResponse response = restClient.execute(request, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NotFoundException(service); } }
/** * Gets the number of instances of a service. * * @param service the service * @return number of instances of the service handler * @throws IOException if a network error occurred * @throws NotFoundException if the application or service could not found * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server */ public int getServiceInstances(ServiceId service) throws IOException, NotFoundException, UnauthenticatedException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/services/%s/instances", service.getApplication(), service.getProgram())); HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NotFoundException(service); } return ObjectResponse.fromJsonBody(response, Instances.class).getResponseObject().getInstances(); }
/** * Checks whether the {@link Service} is active. * * @param service ID of the service * @throws IOException if a network error occurred * @throws UnauthenticatedException if the request is not authorized successfully in the gateway server * @throws NotFoundException if the app or service could not be found * @throws ServiceUnavailableException if the service is not available */ public void checkAvailability(ServiceId service) throws IOException, UnauthenticatedException, NotFoundException, ServiceUnavailableException, UnauthorizedException { URL url = config.resolveNamespacedURLV3(service.getNamespaceId(), String.format("apps/%s/versions/%s/services/%s/available", service.getApplication(), service.getVersion(), service.getProgram())); HttpResponse response = restClient.execute(HttpMethod.GET, url, config.getAccessToken(), HttpURLConnection.HTTP_NOT_FOUND, HttpURLConnection.HTTP_BAD_REQUEST, HttpURLConnection.HTTP_UNAVAILABLE); if (response.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { throw new NotFoundException(service); } if (response.getResponseCode() == HttpURLConnection.HTTP_UNAVAILABLE) { throw new ServiceUnavailableException(service.getProgram()); } }