HostRegistrationManagerImpl extends HostListener implements HostRegistrationManager { @RolesAllowed( "Resource-Management|Write" ) @Override public synchronized void queueRequest( final RequestedHost requestedHost ) throws HostRegistrationException { Preconditions.checkNotNull( requestedHost, "'Invalid registration request" ); Preconditions .checkArgument( PGPKeyUtil.isValidPublicKeyring( requestedHost.getPublicKey() ), "Invalid public key" ); Preconditions.checkArgument( !StringUtils.isBlank( requestedHost.getId() ), "Invalid host id" ); try { RequestedHostImpl requestedHostImpl = requestDataService.find( requestedHost.getId() ); if ( requestedHostImpl != null ) { LOG.info( "Already requested registration" ); requestedHostImpl.setHostname( requestedHost.getHostname() ); requestedHostImpl.setHostInfos( requestedHost.getHostInfos() ); requestedHostImpl.setAddress( requestedHost.getAddress() ); requestedHostImpl.refreshDateUpdated(); requestDataService.update( requestedHostImpl ); } else { RequestedHostImpl registrationRequest = new RequestedHostImpl( requestedHost ); registrationRequest.setStatus( ResourceHostRegistrationStatus.REQUESTED ); requestDataService.update( registrationRequest ); checkManagement( registrationRequest ); } } catch ( Exception e ) { LOG.error( "Error queueing 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 public void testQueueRequest() throws Exception { RequestedHost requestedHost = mock( RequestedHost.class ); when( requestedHost.getId() ).thenReturn( REQUEST_ID ); doReturn( TestHelper.PGP_PUBLIC_KEY ).when( requestedHost ).getPublicKey(); doReturn( "hostname" ).when( requestedHost ).getHostname(); registrationManager.queueRequest( requestedHost ); verify( requestDataService ).update( isA( RequestedHostImpl.class ) ); doReturn( null ).when( requestDataService ).find( REQUEST_ID ); registrationManager.queueRequest( requestedHost ); verify( registrationManager ).checkManagement( isA( RequestedHost.class ) ); }