EnvironmentManagerImpl extends HostListener implements EnvironmentManager, PeerActionListener, AlertListener, BazaarEventListener, LocalPeerEventListener { @Override public EnvironmentAlertHandlers getEnvironmentAlertHandlers( final EnvironmentId environmentId ) throws EnvironmentNotFoundException { Environment environment = loadEnvironment( environmentId.getId() ); Set<EnvironmentAlertHandler> handlerList = environment.getAlertHandlers(); EnvironmentAlertHandlers handlers = new EnvironmentAlertHandlersImpl( environment.getEnvironmentId() ); for ( EnvironmentAlertHandler environmentAlertHandler : handlerList ) { handlers.add( environmentAlertHandler, alertHandlers.get( environmentAlertHandler.getAlertHandlerId() ) ); } return handlers; } EnvironmentManagerImpl( final TemplateManager templateManager, final PeerManager peerManager,
                                   SecurityManager securityManager, final IdentityManager identityManager,
                                   final Tracker tracker, final RelationManager relationManager,
                                   BazaaarAdapter bazaaarAdapter, final EnvironmentService environmentService,
                                   final SystemManager systemManager ); void init(); void dispose(); IdentityManager getIdentityManager(); RelationManager getRelationManager(); @Override String getName(); @Override PeerActionResponse onPeerAction( final PeerAction peerAction ); @Override Set<Environment> getEnvironments(); void setTransientFields( Set<Environment> envs ); @Override Set<Environment> getEnvironmentsByOwnerId( long userId ); @Override EnvironmentCreationRef createEnvironment( final Topology topology, final boolean async ); @Override Set<EnvironmentContainerHost> growEnvironment( final String environmentId, final Topology topology,
                                                          final boolean async ); @Override EnvironmentCreationRef modifyEnvironment( final String environmentId, final Topology topology,
                                                     final Set<String> removedContainers,
                                                     final Map<String, ContainerQuota> changedContainers,
                                                     final boolean async ); @Override void addSshKey( final String environmentId, final String sshKey, final boolean async ); @Override void removeSshKey( final String environmentId, final String sshKey, final boolean async ); @Override SshKeys getSshKeys( final String environmentId, final SshEncryptionType encType ); @Override SshKeys createSshKey( final String environmentId, final String hostname, final SshEncryptionType encType ); @Override void resetP2PSecretKey( final String environmentId, final String newP2pSecretKey,
                                   final long p2pSecretKeyTtlSec, final boolean async ); @Override void destroyEnvironment( final String environmentId, final boolean async ); @Override void destroyContainer( final String environmentId, final String containerId, final boolean async ); @Override void changeContainerHostname( final ContainerId containerId, final String newHostname, final boolean async ); @Override void createTemplate( final String environmentId, final String containerId, final String templateName,
                                final String version, final boolean privateTemplate ); @Override void cancelEnvironmentWorkflow( final String environmentId ); @Override Map<String, CancellableWorkflow> getActiveWorkflows(); @Override Environment loadEnvironment( final String environmentId ); @Override SshTunnel setupSshTunnelForContainer( final String containerHostId, final String environmentId ); void registerListener( final EnvironmentEventListener listener ); void unregisterListener( final EnvironmentEventListener listener ); void notifyOnEnvironmentCreated( final Environment environment ); void notifyOnEnvironmentGrown( final Environment environment,
                                          final Set<EnvironmentContainerHost> containers ); @Override void notifyOnContainerDestroyed( final Environment environment, final String containerId ); @Override void notifyOnEnvironmentDestroyed( final String environmentId ); void notifyOnContainerStarted( final Environment environment, final String containerId ); void notifyOnContainerStopped( final Environment environment, final String containerId ); @Override void onContainerDestroyed( final ContainerHostInfo containerInfo ); Peer resolvePeer( final String peerId ); void save( final LocalEnvironment environment ); synchronized LocalEnvironment update( LocalEnvironment environment ); void remove( final LocalEnvironment environment ); synchronized EnvironmentContainerImpl update( final EnvironmentContainerImpl container ); @Override void addAlertHandler( final AlertHandler alertHandler ); @Override void removeAlertHandler( final AlertHandler alertHandler ); @Override Collection<AlertHandler> getRegisteredAlertHandlers(); @Override String getId(); @Override void onAlert( final AlertEvent alertEvent ); @Override EnvironmentAlertHandlers getEnvironmentAlertHandlers( final EnvironmentId environmentId ); @Override void startMonitoring( final String handlerId, final AlertHandlerPriority handlerPriority,
                                 final String environmentId ); @Override void stopMonitoring( final String handlerId, final AlertHandlerPriority handlerPriority,
                                final String environmentId ); @Override void addSshKeyToEnvironmentEntity( final String environmentId, final String sshKey ); @Override void excludePeerFromEnvironment( final String environmentId, final String peerId ); @Override void excludeContainerFromEnvironment( final String environmentId, final String containerId ); @Override void updateContainerHostname( final String environmentId, final String containerId, final String hostname ); @Override Set<EnvironmentDto> getTenantEnvironments(); @Override String getEnvironmentOwnerName( Environment environment ); @Override void onRegistrationSucceeded(); @Override void onUnregister(); Set<RemoteEnvironment> getLocallyRegisteredBazaarEnvironments(); boolean rhHasEnvironments( String rhId ); @Override void onContainerHostnameChanged( final ContainerHostInfo containerInfo, final String previousHostname,
                                            final String currentHostname ); @Override void onContainerDestroyed( final ContainerHost containerHost ); @Override Set<String> getDeletedEnvironmentsFromBazaar(); @Override void placeEnvironmentInfoByContainerIp( final String containerIp ); @Override Environment getEnvironment( String environmentId ); @Override void placeEnvironmentInfoByContainerId( final String environmentId, final String containerId ); void cleanupEnvironment( EnvironmentId environmentId );  }
@Test public void testGetEnvironmentAlertHandlers() throws Exception { EnvironmentAlertHandler environmentAlertHandler = mock( EnvironmentAlertHandler.class ); doReturn( Sets.newHashSet( environmentAlertHandler ) ).when( environment ).getAlertHandlers(); doReturn( "ID" ).when( environmentAlertHandler ).getAlertHandlerId(); doReturn( AlertHandlerPriority.HIGH ).when( environmentAlertHandler ).getAlertHandlerPriority(); AlertHandler alertHandler = mock( AlertHandler.class ); environmentManager.alertHandlers.put( "ID", alertHandler ); assertFalse( environmentManager.getEnvironmentAlertHandlers( TestHelper.ENVIRONMENT_ID ).getAllHandlers() .isEmpty() ); }