Source:
public synchronized void commitRequest(BaragonRequest request) { Optional<BaragonService> maybeOriginalService = Optional.absent(); if (request.getReplaceServiceId().isPresent()) { maybeOriginalService = stateDatastore.getService(request.getReplaceServiceId().get()); } if (!maybeOriginalService.isPresent()) { maybeOriginalService = stateDatastore.getService(request.getLoadBalancerService().getServiceId()); } if (maybeOriginalService.isPresent() && !maybeOriginalService.get().getServiceBasePath().equals(request.getLoadBalancerService().getServiceBasePath())) { for (String loadBalancerGroup : maybeOriginalService.get().getLoadBalancerGroups()) { loadBalancerDatastore.clearBasePath(loadBalancerGroup, maybeOriginalService.get().getServiceBasePath()); } } if (maybeOriginalService.isPresent()) { Collection<String> removedLbGroups = maybeOriginalService.get().getLoadBalancerGroups(); removedLbGroups.removeAll(request.getLoadBalancerService().getLoadBalancerGroups()); if (!removedLbGroups.isEmpty()) { try { for (String loadbalancerGroup : removedLbGroups) { loadBalancerDatastore.clearBasePath(loadbalancerGroup, maybeOriginalService.get().getServiceBasePath()); } } catch (Exception e) { LOG.info(String.format("Error clearing base path %s", e)); } } } if (maybeOriginalService.isPresent() && !maybeOriginalService.get().getServiceId().equals(request.getLoadBalancerService().getServiceId())) { stateDatastore.removeService(maybeOriginalService.get().getServiceId()); } stateDatastore.addService(request.getLoadBalancerService()); stateDatastore.removeUpstreams(request.getLoadBalancerService().getServiceId(), request.getRemoveUpstreams()); stateDatastore.addUpstreams(request.getLoadBalancerService().getServiceId(), request.getAddUpstreams()); stateDatastore.updateStateNode(); try { if (stateDatastore.getUpstreamsMap(request.getLoadBalancerService().getServiceId()).isEmpty()) { for (String loadbalancerGroup : request.getLoadBalancerService().getLoadBalancerGroups()) { loadBalancerDatastore.clearBasePath(loadbalancerGroup, request.getLoadBalancerService().getServiceBasePath()); } } } catch (Exception e) { LOG.info(String.format("Error clearing base path %s", e)); } }

Target:
public synchronized void commitRequest(BaragonRequest request) { Optional<BaragonService> maybeOriginalService = Optional.absent(); if (request.getReplaceServiceId().isPresent()) { maybeOriginalService = stateDatastore.getService(request.getReplaceServiceId().get()); } if (!maybeOriginalService.isPresent()) { maybeOriginalService = stateDatastore.getService(request.getLoadBalancerService().getServiceId()); } if (maybeOriginalService.isPresent() && !maybeOriginalService.get().getServiceBasePath().equals(request.getLoadBalancerService().getServiceBasePath())) { for (String loadBalancerGroup : maybeOriginalService.get().getLoadBalancerGroups()) { loadBalancerDatastore.clearBasePath(loadBalancerGroup, maybeOriginalService.get().getServiceBasePath()); } } if (maybeOriginalService.isPresent()) { Set<String> removedLbGroups = maybeOriginalService.get().getLoadBalancerGroups(); removedLbGroups.removeAll(request.getLoadBalancerService().getLoadBalancerGroups()); if (!removedLbGroups.isEmpty()) { try { for (String loadbalancerGroup : removedLbGroups) { loadBalancerDatastore.clearBasePath(loadbalancerGroup, maybeOriginalService.get().getServiceBasePath()); } } catch (Exception e) { LOG.info(String.format("Error clearing base path %s", e)); } } } if (maybeOriginalService.isPresent() && !maybeOriginalService.get().getServiceId().equals(request.getLoadBalancerService().getServiceId())) { stateDatastore.removeService(maybeOriginalService.get().getServiceId()); } stateDatastore.addService(request.getLoadBalancerService()); stateDatastore.removeUpstreams(request.getLoadBalancerService().getServiceId(), request.getRemoveUpstreams()); stateDatastore.addUpstreams(request.getLoadBalancerService().getServiceId(), request.getAddUpstreams()); stateDatastore.updateStateNode(); try { if (stateDatastore.getUpstreamsMap(request.getLoadBalancerService().getServiceId()).isEmpty()) { for (String loadbalancerGroup : request.getLoadBalancerService().getLoadBalancerGroups()) { loadBalancerDatastore.clearBasePath(loadbalancerGroup, request.getLoadBalancerService().getServiceBasePath()); } } } catch (Exception e) { LOG.info(String.format("Error clearing base path %s", e)); } }