@Test public void try_commit_current_with_no_autoreload_haproxy() throws IncompleteConfigurationException { EntryPointKey key = new EntryPointKeyDefaultImpl("some_key"); String correlationId = CorrelationId.newCorrelationId(); TryCommitCurrentConfigurationEvent event = new TryCommitCurrentConfigurationEvent(correlationId, key); EntryPoint entryPoint = EntryPoint .onHaproxy("haproxy", 1) .withUser("hapuser") .withVersion("hapversion") .definesFrontends(ImmutableSet.of()) .definesBackends(ImmutableSet.of()) .withGlobalContext(ImmutableMap.of()) .build(); when(stateManager.lock(key)).thenReturn(true); when(stateManager.tryCommitCurrent(correlationId, key)).thenReturn(Optional.of(entryPoint)); when(portRepository.getPort(key, EntryPoint.SYSLOG_PORT_ID)).thenReturn(Optional.of(666)); when(templateLocator.readTemplate(entryPoint)).thenReturn(Optional.of("some template")); when(templateGenerator.generate(eq("some template"), eq(entryPoint), any())).thenReturn("some template"); when(templateGenerator.generateSyslogFragment(eq(entryPoint), any())).thenReturn("some syslog conf"); when(haproxyRepository.getHaproxyProperty("haproxy", "binding/1")).thenReturn(Optional.of("127.0.0.1")); when(haproxyRepository.isAutoreload("haproxy")).thenReturn(false); handler.handle(event); verify(stateManager).tryCommitCurrent(correlationId, key); verify(stateManager).cancelCommit(key); verify(commitRequestedSubscriber, never()).onNext(any(CommitRequestedEvent.class)); }
public void handle(RegisterServerEvent event) { LOGGER.info("handles {}", event); EntryPointKey key = event.getKey(); try { if (this.stateManager.lock(key)) { Optional<EntryPoint> existingConfiguration = Optional.ofNullable( stateManager.getPendingConfiguration(key) .orElseGet(() -> stateManager.getCommittingConfiguration(key) .orElseGet(() -> stateManager.getCurrentConfiguration(key) .orElseGet(() -> { LOGGER.warn("can't find an entrypoint for key {} from register server event {}", key, event); return null; }))) ); existingConfiguration.map(c -> c.registerServers(event.getBackend(), event.getServers())).ifPresent(c -> { Optional<EntryPoint> preparedConfiguration = stateManager.prepare(key, c); if (preparedConfiguration.isPresent()) { LOGGER.info("new servers registered for EntryPoint {}", event.getKey().getID()); if (LOGGER.isDebugEnabled()) { for (IncomingEntryPointBackendServer server : event.getServers()) { LOGGER.debug("- registered server {}", server); } } } else { LOGGER.warn("can't prepare configuration on key {}", key); } }); } } catch (Exception e) { LOGGER.error("Following error occurred while registering server {} for entry point {}", event, key, e); } finally { this.stateManager.release(key); } }
EntryPointEventHandler { public void handle(RegisterServerEvent event) { LOGGER.info("handles {}", event); EntryPointKey key = event.getKey(); try { if (this.stateManager.lock(key)) { Optional<EntryPoint> existingConfiguration = Optional.ofNullable( stateManager.getPendingConfiguration(key) .orElseGet(() -> stateManager.getCommittingConfiguration(key) .orElseGet(() -> stateManager.getCurrentConfiguration(key) .orElseGet(() -> { LOGGER.warn("can't find an entrypoint for key {} from register server event {}", key, event); return null; }))) ); existingConfiguration.map(c -> c.registerServers(event.getBackend(), event.getServers())).ifPresent(c -> { Optional<EntryPoint> preparedConfiguration = stateManager.prepare(key, c); if (preparedConfiguration.isPresent()) { LOGGER.info("new servers registered for EntryPoint {}", event.getKey().getID()); if (LOGGER.isDebugEnabled()) { for (IncomingEntryPointBackendServer server : event.getServers()) { LOGGER.debug("- registered server {}", server); } } } else { LOGGER.warn("can't prepare configuration on key {}", key); } }); } } catch (Exception e) { LOGGER.error("Following error occurred while registering server {} for entry point {}", event, key, e); } finally { this.stateManager.release(key); } } }
EntryPointEventHandler { public void handle(RegisterServerEvent event) { LOGGER.info("handles {}", event); EntryPointKey key = event.getKey(); try { if (this.stateManager.lock(key)) { Optional<EntryPoint> existingConfiguration = Optional.ofNullable( stateManager.getPendingConfiguration(key) .orElseGet(() -> stateManager.getCommittingConfiguration(key) .orElseGet(() -> stateManager.getCurrentConfiguration(key) .orElseGet(() -> { LOGGER.warn("can't find an entrypoint for key {} from register server event {}", key, event); return null; }))) ); existingConfiguration.map(c -> c.registerServers(event.getBackend(), event.getServers())).ifPresent(c -> { Optional<EntryPoint> preparedConfiguration = stateManager.prepare(key, c); if (preparedConfiguration.isPresent()) { LOGGER.info("new servers registered for EntryPoint {}", event.getKey().getID()); if (LOGGER.isDebugEnabled()) { for (IncomingEntryPointBackendServer server : event.getServers()) { LOGGER.debug("- registered server {}", server); } } } else { LOGGER.warn("can't prepare configuration on key {}", key); } }); } } catch (Exception e) { LOGGER.error("Following error occurred while registering server {} for entry point {}", event, key, e); } finally { this.stateManager.release(key); } } EntryPointEventHandler(EntryPointStateManager stateManager, PortRepository portRepository,
                                  HaproxyRepository haproxyRepository, TemplateLocator templateLocator,
                                  TemplateGenerator templateGenerator,
                                  Subscriber<CommitRequestedEvent> commitRequestedSubscriber); }
EntryPointEventHandler { public void handle(RegisterServerEvent event) { LOGGER.info("handles {}", event); EntryPointKey key = event.getKey(); try { if (this.stateManager.lock(key)) { Optional<EntryPoint> existingConfiguration = Optional.ofNullable( stateManager.getPendingConfiguration(key) .orElseGet(() -> stateManager.getCommittingConfiguration(key) .orElseGet(() -> stateManager.getCurrentConfiguration(key) .orElseGet(() -> { LOGGER.warn("can't find an entrypoint for key {} from register server event {}", key, event); return null; }))) ); existingConfiguration.map(c -> c.registerServers(event.getBackend(), event.getServers())).ifPresent(c -> { Optional<EntryPoint> preparedConfiguration = stateManager.prepare(key, c); if (preparedConfiguration.isPresent()) { LOGGER.info("new servers registered for EntryPoint {}", event.getKey().getID()); if (LOGGER.isDebugEnabled()) { for (IncomingEntryPointBackendServer server : event.getServers()) { LOGGER.debug("- registered server {}", server); } } } else { LOGGER.warn("can't prepare configuration on key {}", key); } }); } } catch (Exception e) { LOGGER.error("Following error occurred while registering server {} for entry point {}", event, key, e); } finally { this.stateManager.release(key); } } EntryPointEventHandler(EntryPointStateManager stateManager, PortRepository portRepository,
                                  HaproxyRepository haproxyRepository, TemplateLocator templateLocator,
                                  TemplateGenerator templateGenerator,
                                  Subscriber<CommitRequestedEvent> commitRequestedSubscriber); void handle(RegisterServerEvent event); void handle(TryCommitCurrentConfigurationEvent event); void handle(TryCommitPendingConfigurationEvent event); void handle(CommitCompletedEvent event); void handle(CommitFailedEvent event); }
EntryPointEventHandler { public void handle(RegisterServerEvent event) { LOGGER.info("handles {}", event); EntryPointKey key = event.getKey(); try { if (this.stateManager.lock(key)) { Optional<EntryPoint> existingConfiguration = Optional.ofNullable( stateManager.getPendingConfiguration(key) .orElseGet(() -> stateManager.getCommittingConfiguration(key) .orElseGet(() -> stateManager.getCurrentConfiguration(key) .orElseGet(() -> { LOGGER.warn("can't find an entrypoint for key {} from register server event {}", key, event); return null; }))) ); existingConfiguration.map(c -> c.registerServers(event.getBackend(), event.getServers())).ifPresent(c -> { Optional<EntryPoint> preparedConfiguration = stateManager.prepare(key, c); if (preparedConfiguration.isPresent()) { LOGGER.info("new servers registered for EntryPoint {}", event.getKey().getID()); if (LOGGER.isDebugEnabled()) { for (IncomingEntryPointBackendServer server : event.getServers()) { LOGGER.debug("- registered server {}", server); } } } else { LOGGER.warn("can't prepare configuration on key {}", key); } }); } } catch (Exception e) { LOGGER.error("Following error occurred while registering server {} for entry point {}", event, key, e); } finally { this.stateManager.release(key); } } EntryPointEventHandler(EntryPointStateManager stateManager, PortRepository portRepository,
                                  HaproxyRepository haproxyRepository, TemplateLocator templateLocator,
                                  TemplateGenerator templateGenerator,
                                  Subscriber<CommitRequestedEvent> commitRequestedSubscriber); void handle(RegisterServerEvent event); void handle(TryCommitCurrentConfigurationEvent event); void handle(TryCommitPendingConfigurationEvent event); void handle(CommitCompletedEvent event); void handle(CommitFailedEvent event);  }