ComponentEventRestService { @GET @Path( value = "/host/HMS" ) @Produces( "application/json" ) public List<Event> getComponentEvents() throws HmsException { ServerNode node = ServerNodeConnector.getInstance().getApplicationNode(); try { executeHealthMonitorTask( node, ServerComponent.HMS ); List<Event> eventList = EventMonitoringSubscriptionHolder.getEventList( node, ServerComponent.HMS ); return eventList; } catch ( HmsException e ) { throw new HMSRestException( Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Server Error", e.getMessage() ); } catch ( Exception 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 public void getComponentEvents_monitor_HMS_On_STARTED() throws Exception { insertNodeInNodeMap( getServerNode() ); addBoardServiceForNode(); server = initMocks( AbstractLifeCycle.STARTED ); ComponentEventRestService restService = new ComponentEventRestService(); List<Event> hmsEvents = restService.getComponentEvents(); assertNotNull( hmsEvents ); assertTrue( hmsEvents.size() > 0 ); Event event = hmsEvents.get( 0 ); assertNotNull( event ); Header header = event.getHeader(); assertEquals( "HMS", header.getAgent() ); assertEquals( "HMS_AGENT_UP", header.getEventName().name() ); assertEquals( "NORMAL", header.getEventType().name() ); assertEquals( "[MANAGEMENT, SOFTWARE]", header.getEventCategoryList().toString() ); assertEquals( "INFORMATIONAL", header.getSeverity().name() ); Body body = event.getBody(); Map<String, String> data = body.getData(); assertEquals( "DISCRETE", data.get( "unit" ) ); assertEquals( "HMS_OOBAGENT_STATUS", data.get( "eventId" ) ); assertEquals( "HMS Agent is up", data.get( "value" ) ); assertEquals( "HMS_AGENT_UP", data.get( "eventName" ) ); assertEquals( "HMS Agent is up - rack {RACK_NAME}", body.getDescription() ); resetMocks( server ); }
@Test public void getComponentEvents_monitor_HMS_On_NOT_STARTED() throws Exception { insertNodeInNodeMap( getServerNode() ); addBoardServiceForNode(); server = initMocks( AbstractLifeCycle.FAILED ); ComponentEventRestService restService = new ComponentEventRestService(); List<Event> hmsEvents = restService.getComponentEvents(); assertNotNull( hmsEvents ); assertTrue( hmsEvents.size() > 0 ); Event event = hmsEvents.get( 0 ); assertNotNull( event ); Header header = event.getHeader(); assertEquals( "HMS", header.getAgent() ); assertEquals( "HMS_AGENT_DOWN", header.getEventName().name() ); assertEquals( "NORMAL", header.getEventType().name() ); assertEquals( "[MANAGEMENT, SOFTWARE]", header.getEventCategoryList().toString() ); assertEquals( "CRITICAL", header.getSeverity().name() ); Body body = event.getBody(); Map<String, String> data = body.getData(); assertEquals( "DISCRETE", data.get( "unit" ) ); assertEquals( "HMS_OOBAGENT_STATUS", data.get( "eventId" ) ); assertEquals( "HMS Agent is down", data.get( "value" ) ); assertEquals( "HMS_AGENT_DOWN", data.get( "eventName" ) ); assertEquals( "HMS Agent is down - rack {RACK_NAME}", body.getDescription() ); resetMocks( server ); }