HostRegistrationManagerImpl extends HostListener implements HostRegistrationManager { @Override public void removeRequest( final String requestId ) throws HostRegistrationException { EnvironmentManager environmentManager = serviceLocator.getService( EnvironmentManager.class ); if ( environmentManager.rhHasEnvironments( requestId ) ) { throw new HostRegistrationException( "There are environments on this host" ); } try { RequestedHost requestedHost = requestDataService.find( requestId ); if ( requestedHost == null ) { return; } if ( requestedHost.getStatus() == ResourceHostRegistrationStatus.APPROVED ) { requestDataService.remove( requestedHost.getId() ); LocalPeer localPeer = serviceLocator.getService( LocalPeer.class ); localPeer.removeResourceHost( requestedHost.getId() ); } else if ( requestedHost.getStatus() == ResourceHostRegistrationStatus.REQUESTED ) { requestDataService.remove( requestedHost.getId() ); } } catch ( HostNotFoundException e ) { LOG.warn( "Resource host {} not found in registered hosts", requestId ); } catch ( Exception e ) { LOG.error( "Error removing registration request", e ); throw new HostRegistrationException( e ); } } HostRegistrationManagerImpl( final SecurityManager securityManager, final DaoManager daoManager ); void init(); @Override String generateContainerToken( final long ttlInMs ); @Override Boolean verifyTokenAndRegisterKey( final String token, String containerHostId, String publicKey ); void dispose(); @Override void changeRhHostname( final String rhId, String hostname ); @Override List<RequestedHost> getRequests(); @Override RequestedHost getRequest( final String requestId ); @RolesAllowed( "Resource-Management|Write" ) @Override synchronized void queueRequest( final RequestedHost requestedHost ); @Override void rejectRequest( final String requestId ); @Override void approveRequest( final String requestId ); @Override void removeRequest( final String requestId ); @Override void unblockRequest( final String requestId ); @Override void onHeartbeat( final ResourceHostInfo resourceHostInfo, final Set<QuotaAlertValue> alerts );  }
@Test( expected = HostRegistrationException.class ) public void testRemoveRequest() throws Exception { registrationManager.removeRequest( REQUEST_ID ); verify( localPeer ).removeResourceHost( anyString() ); doThrow( new HostNotFoundException( "" ) ).when( localPeer ).removeResourceHost( anyString() ); registrationManager.removeRequest( REQUEST_ID ); doThrow( new RuntimeException() ).when( localPeer ).removeResourceHost( anyString() ); registrationManager.removeRequest( REQUEST_ID ); }