HMSManagementRestService { @GET @Path( "/nodes" ) @Produces( "application/json" ) public Map<String, Object[]> getHMSNodes() throws HMSRestException { Map<String, Object[]> nodes = new HashMap<String, Object[]>(); try { Object[] hosts = serverConnector.getNodeMap().values().toArray(); Object[] switches = switchConnector.switchNodeMap.values().toArray(); List<ServerNode> copyHosts = new ArrayList<ServerNode>(); List<SwitchNode> copySwitches = new ArrayList<SwitchNode>(); if ( hosts != null && hosts.length > 0 ) { for ( Object obj : hosts ) { ServerNode serverNode = (ServerNode) obj; ServerNode copy = (ServerNode) HmsGenericUtil.maskPassword( serverNode ); copyHosts.add( copy ); } } if ( switches != null && switches.length > 0 ) { for ( Object obj : switches ) { SwitchNode switchNode = (SwitchNode) obj; SwitchNode copy = (SwitchNode) HmsGenericUtil.maskPassword( switchNode ); copySwitches.add( copy ); } } nodes.put( Constants.HOSTS, copyHosts.toArray() ); nodes.put( Constants.SWITCHES, copySwitches.toArray() ); } catch ( Exception e ) { throw new HMSRestException( Status.INTERNAL_SERVER_ERROR.getStatusCode(), "Server Error", "Error while fetching HMS nodes" ); } return nodes; }  @GET @Path( "/nodes" ) @Produces( "application/json" ) Map<String, Object[]> getHMSNodes(); @GET @Path( "/discover" ) @Produces( "application/json" ) NodeDiscoveryResponse discoverNodes(); @POST @Path( "/handshake" ) @Consumes( MediaType.APPLICATION_JSON ) @Produces( "application/json" ) BaseResponse handshake(); @POST @Path( "/handshake/{aggregator_ip}/{source}" ) @Consumes( MediaType.APPLICATION_JSON ) @Produces( "application/json" ) BaseResponse handshake( @PathParam( "aggregator_ip" ) String aggregatorIp,
                                   @PathParam( "source" ) String source ); @GET @Path( "/service/operations" ) @Produces( "application/json" ) Map<String, List<HmsApi>> getSupportedOOBOperations(); @GET @Path( "/debug/threads" ) @Produces( "application/json" ) Map<String, String> executeThreadStackLogger(); @PUT @Path( "/refreshinventory" ) @Produces( MediaType.APPLICATION_JSON ) @Deprecated Response refreshInventory( final String inventory ); @GET @Path( "/hmslogs" ) @Produces( MediaType.APPLICATION_OCTET_STREAM ) Response getHmsLogs(); @DELETE @Path( "/hmslogs" ) @Produces( "application/json" ) BaseResponse deleteTemporaryHmsLogFile(); boolean isFileDeleteable( File logArchiveName ); @GET @Path( "/newhosts" ) @Produces( MediaType.APPLICATION_JSON ) Response getNewHosts(); static final String GRANT_EXECUTE_RIGHTS; final String TIMESTAMP_FORMAT; }
@Test public void testGetHMSNodes() throws HMSRestException { ServerNodeConnector.getInstance().setNodeMap( new ConcurrentHashMap<String, HmsNode>() ); ComponentEventRestServiceTest.insertNodeInNodeMap( ComponentEventRestServiceTest.getServerNode() ); SwitchNode switchNode = new SwitchNode( "Arista", "SSH", "10.28.197.248", 22, "lanier", "l@ni3r2o14" ); ConcurrentHashMap<String, SwitchNode> switchMap = new ConcurrentHashMap<String, SwitchNode>(); switchMap.put( "S1", switchNode ); SwitchNodeConnector.getInstance().switchNodeMap = switchMap; HMSManagementRestService service = new HMSManagementRestService(); Map<String, Object[]> hmsNodes = service.getHMSNodes(); Object[] serverNodes = hmsNodes.get( Constants.HOSTS ); for ( Object serverNode : serverNodes ) { ServerNode servNode = (ServerNode) serverNode; assertEquals( servNode.getNodeID(), "N1" ); assertEquals( servNode.getBoardProductName(), "S2600GZ" ); assertEquals( servNode.getBoardVendor(), "Intel" ); assertEquals( servNode.getIbIpAddress(), "10.28.197.28" ); assertEquals( servNode.getManagementIp(), "10.28.197.208" ); assertEquals( servNode.getOsUserName(), "testuser" ); assertEquals( servNode.getOsPassword(), "****" ); } Object[] switches = hmsNodes.get( Constants.SWITCHES ); for ( Object obj : switches ) { SwitchNode sNode = (SwitchNode) obj; assertEquals( sNode.getSwitchId(), "Arista" ); assertEquals( sNode.getProtocol(), "SSH" ); assertEquals( sNode.getPort(), new Integer( 22 ) ); assertEquals( sNode.getUsername(), "lanier" ); assertEquals( sNode.getPassword(), "****" ); } Map<String, HmsNode> nodeMap = ServerNodeConnector.getInstance().getNodeMap(); ServerNode servNode = (ServerNode) nodeMap.get( "N1" ); assertEquals( servNode.getNodeID(), "N1" ); assertEquals( servNode.getBoardProductName(), "S2600GZ" ); assertEquals( servNode.getBoardVendor(), "Intel" ); assertEquals( servNode.getIbIpAddress(), "10.28.197.28" ); assertEquals( servNode.getManagementIp(), "10.28.197.208" ); assertEquals( servNode.getOsUserName(), "testuser" ); assertEquals( servNode.getOsPassword(), "ospassword" ); Map<String, SwitchNode> switchNodeMap = SwitchNodeConnector.getInstance().switchNodeMap; SwitchNode sNode = (SwitchNode) switchNodeMap.get( "S1" ); assertEquals( sNode.getSwitchId(), "Arista" ); assertEquals( sNode.getProtocol(), "SSH" ); assertEquals( sNode.getPort(), new Integer( 22 ) ); assertEquals( sNode.getUsername(), "lanier" ); assertEquals( sNode.getPassword(), "l@ni3r2o14" ); }