public Optional<BaragonServiceState> getService(String serviceId) { final Optional<BaragonService> maybeServiceInfo = stateDatastore.getService(serviceId); if (!maybeServiceInfo.isPresent()) { return Optional.absent(); } try { return Optional.of( new BaragonServiceState( maybeServiceInfo.get(), stateDatastore.getUpstreamsMap(serviceId).values())); } catch (Exception e) { throw Throwables.propagate(e); } }
public BaragonResponse enqueueReloadServiceConfigs(String serviceId, boolean noValidate) { String requestId = String.format("%s-%s-%s", serviceId, System.currentTimeMillis(), "RELOAD"); Optional<BaragonService> maybeService = stateDatastore.getService(serviceId); if (maybeService.isPresent()) { try { return requestManager.enqueueRequest( buildReloadRequest(maybeService.get(), requestId, noValidate)); } catch (Exception e) { return BaragonResponse.failure(requestId, e.getMessage()); } } else { return BaragonResponse.serviceNotFound(requestId, serviceId); } }
private BaragonRequest buildRemoveRequest( BaragonService service, String requestId, boolean noValidate, boolean noReload) throws Exception { List<UpstreamInfo> empty = Collections.emptyList(); List<UpstreamInfo> remove; remove = new ArrayList<>(stateDatastore.getUpstreamsMap(service.getServiceId()).values()); return new BaragonRequest( requestId, service, empty, remove, empty, Optional.<String>absent(), Optional.of(RequestAction.DELETE), noValidate, noReload); }
public Collection<BaragonServiceState> getAllServices() { return stateDatastore.getGlobalState(); }