class InventoryUtil {

    public static boolean removeServer( final String inventoryFilePath, final String hostId )
        throws HmsException, JsonGenerationException, JsonMappingException, IOException
    {

        // first read the inventory file.
        Map<String, Object[]> inventory = InventoryUtil.initializeInventory( inventoryFilePath );
        if ( inventory == null || !inventory.containsKey( Constants.HOSTS ) )
        {
            logger.error( "In removeServer, invalid inventory configuration in the file {}.", inventoryFilePath );
            return false;
        }

        // iterate through server and remove server entry from hosts list.
        ObjectMapper objectMapper = new ObjectMapper();
        Object[] hosts = inventory.get( Constants.HOSTS );
        if ( hosts != null && hosts.length > 0 )
        {
            List<ServerNode> serverNodesList = objectMapper.convertValue( hosts, new TypeReference<List<ServerNode>>()
            {
            } );
            ServerNode serverNode = null;
            for ( Iterator<ServerNode> iterator = serverNodesList.iterator(); iterator.hasNext(); )
            {
                serverNode = iterator.next();
                if ( StringUtils.equals( hostId, serverNode.getNodeID() ) )
                {
                    iterator.remove();
                    logger.debug( "In removeServer, removed hostId '{}' from the inventory '{}'.", hostId,
                                  inventoryFilePath );
                    break;
                }
            }
            inventory.put( Constants.HOSTS, serverNodesList.toArray() );
        }

        // save the data back to the file.
        String inventoryFileContent = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString( inventory );
        return InventoryUtil.createOrUpdateInventoryFile( inventoryFilePath, inventoryFileContent, true );
    }

}