ServerRestService { @DELETE @Path( "/{hostId}" ) @Produces( "application/json" ) public Response removeServer( @PathParam( "hostId" ) String hostId ) throws HmsException, Exception { logger.info( "In removeServer, removing host with hostId: {}.", hostId ); BaseResponse response = null; String message = null; if ( !serverConnector.getNodeMap().containsKey( hostId ) ) { logger.debug( "In removeServer, Server with NodeID: {} not found in inventory.", hostId ); response = HmsGenericUtil.getBaseResponse( Status.BAD_REQUEST, "Invalid HostId: " + hostId ); return Response.status( Status.BAD_REQUEST ).entity( response ).build(); } NodeAdminStatus nodeAdminStatus = NodeAdminStatus.DECOMISSION; ServerNode serverNode = (ServerNode) serverConnector.getNodeMap().get( hostId ); serverNode.setAdminStatus( nodeAdminStatus ); logger.debug( "In removeServer, set host with hostId: {} admin status as {}.", hostId, nodeAdminStatus.toString() ); ServerNode serverNode1 = (ServerNode) serverConnector.removeServer( hostId ); if ( serverNode1 == null ) { message = String.format( "Failed to remove host '%1$s' from inventory.", hostId ); logger.error( "In removeServer, {}.", message ); response = HmsGenericUtil.getBaseResponse( Status.INTERNAL_SERVER_ERROR, message ); serverNode.setAdminStatus( NodeAdminStatus.OPERATIONAL ); logger.info( "In removeServer, as {}, set host '{}' admin status to {}.", message, hostId, NodeAdminStatus.OPERATIONAL.toString() ); return Response.status( Status.INTERNAL_SERVER_ERROR ).entity( response ).build(); } BoardServiceProvider.removeBoardServiceClass( hostId ); BoardServiceProvider.removeNodeSupportedOperations( hostId ); message = String.format( "Removed host '%1$s' from inventory.", hostId ); logger.info( "In removeServer, {}", message ); response = HmsGenericUtil.getBaseResponse( Status.OK, message ); return Response.status( Status.OK ).entity( response ).build(); }  @GET @Path( "/" ) @Produces( "application/json" ) Map<String, HmsNode> getHosts(); @GET @Path( "/{host_id}" ) @Produces( "application/json" ) ServerNode getHostNode( @PathParam( "host_id" ) String host_id ); @GET @Path( "/jnlpRemoteConsoleSupportFiles/{host_id}/{path : .*}" ) @Produces( MediaType.APPLICATION_OCTET_STREAM ) Response getJnlpSupportFiles( @PathParam( "host_id" ) String host_id, @PathParam( "path" ) String path ); @GET @Path( "/{host_id}/startremoteconsole" ) @Produces( "application/json" ) RemoteConsoleConnectionInfo startRemoteConsoleConnection( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/remoteconsoledetails" ) @Produces( "application/json" ) RemoteConsoleCapabilities getHostRemoteConsoleCapabilities( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/powerstatus" ) @Produces( "application/json" ) ServerNodePowerStatus getHostPowerStatus( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/selftest" ) @Produces( "application/json" ) SelfTestResults getHostSelfTestResults( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/bmcusers" ) @Produces( "application/json" ) List<BmcUser> getBmcUsers( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/cpuinfo" ) @Produces( "application/json" ) List<CPUInfo> getCpuInfo( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/storageinfo" ) @Produces( "application/json" ) List<HddInfo> getHddInfo( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/storagecontrollerinfo" ) @Produces( "application/json" ) List<StorageControllerInfo> getStorageControllerInfo( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/memoryinfo" ) @Produces( "application/json" ) List<PhysicalMemory> getMemoryInfo( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/acpipowerstate" ) @Produces( "application/json" ) AcpiPowerState getHostAcpiPowerState( @PathParam( "host_id" ) String host_id ); @GET @Path( "/{host_id}/nicinfo" ) @Produces( "application/json" ) List<EthernetController> getNicInfo( @PathParam( "host_id" ) String host_id ); @PUT @Path( "/update" ) @Consumes( MediaType.APPLICATION_FORM_URLENCODED ) @Produces( "application/json" ) BaseResponse updateNodes( @Form HMSRestServerActionsForm actions ); @PUT @Path( "/{host_id}" ) @Produces( "application/json" ) BaseResponse updateNodes( @PathParam( "host_id" ) String host_id, @QueryParam( "action" ) String action ); @GET @Path( "/{host_id}/bootoptions" ) @Produces( "application/json" ) SystemBootOptions getSystemBootOptions( @PathParam( "host_id" ) String host_id ); @PUT @Path( "/{host_id}/bootoptions" ) @Consumes( MediaType.APPLICATION_JSON ) @Produces( "application/json" ) BaseResponse getSystemBootOptions( @PathParam( "host_id" ) String host_id,
                                              SystemBootOptions systemBootOptions ); @PUT @Path( "/{host_id}/chassisidentify" ) @Consumes( MediaType.APPLICATION_JSON ) @Produces( "application/json" ) BaseResponse chassisIdentify( @PathParam( "host_id" ) String host_id,
                                         ChassisIdentifyOptions chassisIdentifyOptions ); @PUT @Path( "/{host_id}/selinfo" ) @Consumes( MediaType.APPLICATION_JSON ) @Produces( "application/json" ) SelInfo selInfo( @PathParam( "host_id" ) String host_id, SelOption selOption ); @PUT @Path( "/{host_id}/setpassword" ) @Consumes( MediaType.APPLICATION_JSON ) @Produces( "application/json" ) BaseResponse setBmcPassword( @PathParam( "host_id" ) String host_id, SetNodePassword nodePassword ); @GET @Path( "/{host_id}/supportedAPI" ) @Produces( "application/json" ) List<HmsApi> getAvailableNodeOperations( @PathParam( "host_id" ) String host_id ); @DELETE @Path( "/{hostId}" ) @Produces( "application/json" ) Response removeServer( @PathParam( "hostId" ) String hostId );  }
@Test public void testRemoveInvalidServer() throws Exception { insertNodeInNodeMap( getServerNode() ); ServerRestService serverRestService = new ServerRestService(); Response response = serverRestService.removeServer( "N" + getDateTimeStamp() ); assertNotNull( response ); assertTrue( response.getStatus() == Response.Status.BAD_REQUEST.getStatusCode() ); HmsGenericUtil.deleteLatestInventoryBackup(); }
@Test public void testRemoveValidServer() throws Exception { final String serverId = "N" + getDateTimeStamp(); ServerNode serverNode = getServerNode( serverId ); ServerNodeConnector.getInstance().setNodeMap( new ConcurrentHashMap<String, HmsNode>() ); ServerNodeConnector.getInstance().getNodeMap().put( serverId, serverNode ); BoardServiceProvider.addBoardServiceClass( serverNode.getServiceObject(), BoardService_TEST.class, true ); HmsGenericUtil.deleteLatestInventoryBackup(); ServerItem serverItem = getServerItem( serverId ); List<ServerItem> serverItemLst = new ArrayList<ServerItem>(); serverItemLst.add( serverItem ); HmsInventoryConfiguration hmsInventoryConfiguration = new HmsInventoryConfiguration(); hmsInventoryConfiguration.setServers( serverItemLst ); HmsConfigHolder.setHmsInventoryConfiguration( hmsInventoryConfiguration ); HmsGenericUtil.deleteLatestInventoryBackup(); ServerRestService serverRestService = new ServerRestService(); Response response = serverRestService.removeServer( serverId ); assertNotNull( response ); assertTrue( response.getStatus() == Response.Status.OK.getStatusCode() ); HmsGenericUtil.deleteLatestInventoryBackup(); }