ComponentEventRestService { @GET @Path( "/host/{host_id}/{event_source}" ) @Produces( "application/json" ) public List<Event> getComponnetEvents( @PathParam( "host_id" ) String host_id, @PathParam( "event_source" ) EventComponent event_source ) throws HMSRestException { if ( !serverConnector.getNodeMap().containsKey( host_id ) ) throw new HMSRestException( Status.NOT_FOUND.getStatusCode(), "Invalid Request", "Can't find host with id " + host_id ); else { ServerNode node = (ServerNode) serverConnector.getNodeMap().get( host_id ); try { ServerComponent component = EventMonitoringSubscriptionHolder.getMappedServerComponents( event_source ); executeServerMonitorTask( node, component ); return EventMonitoringSubscriptionHolder.getEventList( node, component ); } catch ( HmsOperationNotSupportedException e ) { logger.error( "Operation not supported for node :" + host_id + " component: " + event_source ); throw new HMSRestException( Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Server Error", e.getMessage() ); } catch ( HMSRestException e ) { logger.error( "Error getting sensor events for node :" + host_id + " component: " + event_source, e ); throw e; } catch ( HmsException e ) { logger.error( "Error getting sensor events for node :" + host_id + " component: " + event_source, e ); throw new HMSRestException( Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Server Error", e.getMessage() ); } catch ( Exception e ) { logger.error( "Error getting sensor events for node :" + host_id + " component: " + event_source, e ); throw new HMSRestException( Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Server Error", e.getMessage() ); } } }  @GET @Path( "/host/{host_id}/{event_source}" ) @Produces( "application/json" ) List<Event> getComponnetEvents( @PathParam( "host_id" ) String host_id,
                                           @PathParam( "event_source" ) EventComponent event_source ); @GET @Path( "/host/nme/{host_id}" ) @Produces( "application/json" ) List<Event> getComponnetNmeEvents( @PathParam( "host_id" ) String host_id ); @GET @Path( value = "/host/HMS" ) @Produces( "application/json" ) List<Event> getComponentEvents(); @GET @Path( "/switches/{switch_id}/{event_source}" ) @Produces( "application/json" ) List<Event> getSwitchComponentEvents( @PathParam( "switch_id" ) String switchId,
                                                 @PathParam( "event_source" ) EventComponent eventSource ); @GET @Path( "/switches/nme/{switch_id}" ) @Produces( "application/json" ) List<Event> getSwitchComponentNmeEvents( @PathParam( "switch_id" ) String switchId );  }
@Test( expected = HMSRestException.class ) public void getComponentEvents_nodeNotInNodeMap() throws HMSRestException { clearNodeMapAndBoardService(); ComponentEventRestService restService = new ComponentEventRestService(); restService.getComponnetEvents( "N1", EventComponent.CPU ); }
@Test( expected = HMSRestException.class ) public void getComponentEvents_nodeInNodeMap_noBoardService() throws HMSRestException { insertNodeInNodeMap( getServerNode() ); removeBoardServiceForNode(); ComponentEventRestService restService = new ComponentEventRestService(); restService.getComponnetEvents( "N1", EventComponent.CPU ); }
@Test public void getComponentEvents_nodeInNodeMap_boardServiceFound_CPU() throws Exception { insertNodeInNodeMap( getServerNode() ); addBoardServiceForNode(); ComponentEventRestService restService = new ComponentEventRestService(); List<Event> cpuEvents = restService.getComponnetEvents( "N1", EventComponent.CPU ); assertNotNull( cpuEvents ); assertTrue( cpuEvents.size() > 0 ); assertNotNull( cpuEvents.get( 0 ) ); }
@Test public void getComponentEvents_nodeInNodeMap_boardServiceFound_HDD() throws Exception { insertNodeInNodeMap( getServerNode() ); addBoardServiceForNode(); ComponentEventRestService restService = new ComponentEventRestService(); List<Event> hddEvents = restService.getComponnetEvents( "N1", EventComponent.STORAGE ); assertNotNull( hddEvents ); assertTrue( hddEvents.size() > 0 ); assertNotNull( hddEvents.get( 0 ) ); }