hardware.rb 18.9 KB
Newer Older
1
# coding: utf-8
Lucas Nussbaum's avatar
Lucas Nussbaum committed
2
require 'refrepo/gen/wiki/generators/site_hardware'
3 4 5 6 7 8 9 10

class G5KHardwareGenerator < WikiGenerator

  def initialize(page_name)
    super(page_name)
  end

  def generate_content
11
    @global_hash = get_global_hash
12
    @site_uids = G5K::SITES
13

14
    @generated_content = "__NOEDITSECTION__\n"
15
    @generated_content += "{{Portal|User}}\n"
16
    @generated_content += "<div class=\"sitelink\">[[Hardware|Global]] | " + G5K::SITES.map { |e| "[[#{e.capitalize}:Hardware|#{e.capitalize}]]" }.join(" | ") + "</div>\n"
17
    @generated_content += generate_summary
18 19 20
    @generated_content += "\n= Clusters =\n"
    @generated_content += SiteHardwareGenerator.generate_all_clusters
    @generated_content += generate_totals
21
    @generated_content += MW.italic(MW.small(generated_date_string))
22 23 24
    @generated_content += MW::LINE_FEED
  end

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  def generate_summary
    sites = @global_hash['sites'].length
    clusters = 0
    nodes = 0
    cores = 0
    gpus = 0
    hdds = 0
    ssds = 0
    storage_space = 0

    @global_hash['sites'].sort.to_h.each do |site_uid, site_hash|
      clusters += site_hash['clusters'].length
      site_hash['clusters'].sort.to_h.each do |cluster_uid, cluster_hash|
        cluster_hash['nodes'].sort.to_h.each do |node_uid, node_hash|
          next if node_hash['status'] == 'retired'
40
          nodes += 1
41
          cores += node_hash['architecture']['nb_cores']
42 43
          if node_hash['gpu_devices']
            gpus += node_hash['gpu_devices'].length
44
          end
45 46 47 48
          ssds += node_hash['storage_devices'].select { |d| d['storage'] == 'SSD' }.length
          hdds += node_hash['storage_devices'].select { |d| d['storage'] == 'HDD' }.length
          node_hash['storage_devices'].each do |i|
            storage_space += i['size']
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
          end
        end
      end
    end
    return <<-EOF
= Summary =
* #{sites} sites
* #{clusters} clusters
* #{nodes} nodes
* #{cores} CPU cores
* #{gpus} GPUs
* #{ssds} SSDs and #{hdds} HDDs on nodes (total: #{G5K.get_size(storage_space, 'metric')})
    EOF
  end

64 65 66 67 68 69 70
  def generate_totals
    data = {
      'proc_families' => {},
      'proc_models' => {},
      'core_models' => {},
      'ram_size' => {},
      'net_interconnects' => {},
71
      'net_models' => {},
72 73 74 75 76
      'acc_families' => {},
      'acc_models' => {},
      'acc_cores' => {},
      'node_models' => {}
    }
77

78 79 80
    @global_hash['sites'].sort.to_h.each { |site_uid, site_hash|
      site_hash['clusters'].sort.to_h.each { |cluster_uid, cluster_hash|
        cluster_hash['nodes'].sort.to_h.each { |node_uid, node_hash|
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
          begin
            next if node_hash['status'] == 'retired'
            @node = node_uid

            # Processors
            model = node_hash['processor']['model']
            version = "#{model} #{node_hash['processor']['version']}"
            microarchitecture = node_hash['processor']['microarchitecture']

            cluster_procs = node_hash['architecture']['nb_procs']
            cluster_cores = node_hash['architecture']['nb_cores']

            key = [model]
            init(data, 'proc_families', key)
            data['proc_families'][key][site_uid] += cluster_procs

            key = [{text: microarchitecture || ' ', sort: get_date(microarchitecture) + ', ' + microarchitecture.to_s}, {text: version, sort: get_date(microarchitecture) + ', ' + version.to_s}]
            init(data, 'proc_models', key)
            data['proc_models'][key][site_uid] += cluster_procs

            init(data, 'core_models', key)
            data['core_models'][key][site_uid] += cluster_cores

            # RAM size
            ram_size = node_hash['main_memory']['ram_size']
            key = [{ text: G5K.get_size(ram_size), sort: (ram_size / 2**30).to_s.rjust(6, '0') + ' GB' }]
            init(data, 'ram_size', key)
            data['ram_size'][key][site_uid] += 1

            # HPC Networks
111
            interfaces = node_hash['network_adapters'].select{ |v|
112 113 114
              v['enabled'] and
                (v['mounted'] or v['mountable']) and
                not v['management'] and
115 116
                (v['device'] =~ /\./).nil? # exclude PKEY / VLAN interfaces see #9417
            }.map{ |v|
117 118 119
              [
                {
                  text: v['interface'] + ' ' + G5K.get_rate(v['rate']),
120
                  sort: v['interface'] + ' ' + ((v['rate'])/10**6).to_s.rjust(6, '0') + ' Gbps'
121 122
                }
              ]
123
            }
124 125 126 127 128 129 130 131

            net_interconnects = interfaces.inject(Hash.new(0)){ |h, v| h[v] += 1; h }
            net_interconnects.sort_by { |k, v|  k.first[:sort] }.each { |k, v|
              init(data, 'net_interconnects', k)
              data['net_interconnects'][k][site_uid] += v
            }

            # NIC models
132
            interfaces = node_hash['network_adapters'].select{ |v|
133 134 135
              v['enabled'] and
                (v['mounted'] or v['mountable']) and
                not v['management'] and
136 137
                (v['device'] =~ /\./).nil? # exclude PKEY / VLAN interfaces see #9417
            }.map{ |v|
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
              t = (v['vendor'] || 'N/A') + ' ' + (v['model'] || 'N/A');
              [
                {
                  text: v['interface'],
                  sort: v['interface']
                },
                {
                  text: t, sort: t
                }
              ]
            }.uniq

            net_models = interfaces.inject(Hash.new(0)){ |h, v| h[v] += 1; h }
            net_models.sort_by { |k, v|  k.first[:sort] }.each { |k, v|
              init(data, 'net_models', k)
              data['net_models'][k][site_uid] += v
            }

            # Accelerators
            m = node_hash['mic']

            mic_families = {}
            mic_families[[m['mic_vendor']]] = m['mic_count'] if m and m['mic']
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
            mic_details = {}
            mic_details[["#{m['mic_vendor']} #{m['mic_model']}"]] = [m['mic_count'], m['mic_cores']] if m and m['mic']

            lg = node_hash['gpu_devices']
            gpu_families = {}
            gpu_details = {}
            unless lg.nil?
              lg.each { |g|
                d = g[1]
                vendor = d['vendor']
                cmodel = d['model']
                model = GPURef.getGrid5000LegacyNameFor(cmodel)
                nbcores = GPURef.getNumberOfCoresFor(cmodel)

                family = gpu_families[[vendor]]
                if family.nil?
                  gpu_families[[vendor]] = 1
                else
                  gpu_families[[vendor]] += 1
                end

                details = gpu_details[["#{vendor} #{model}"]]

                if details.nil?
                  gpu_details[["#{vendor} #{model}"]] = [1, nbcores]
                else
                  gpu_details[["#{vendor} #{model}"]] = [details[0]+1, details[1]+nbcores]
                end
              }
            end

192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
            gpu_families.merge(mic_families).sort.to_h.each { |k, v|
              init(data, 'acc_families', k)
              data['acc_families'][k][site_uid] += v
            }

            gpu_details.merge(mic_details).sort.to_h.each { |k, v|
              init(data, 'acc_models', k)
              data['acc_models'][k][site_uid] += v[0]

              init(data, 'acc_cores', k)
              data['acc_cores'][k][site_uid] += v[1]
            }

            # Nodes
            key = [cluster_hash['model']]
            init(data, 'node_models', key)
            data['node_models'][key][site_uid] += 1
          rescue
            puts "ERROR while processing #{node_uid}: #{$!}"
            raise
          end
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
        }
      }
    }

    # Table construction
    generated_content = "= Processors ="
    generated_content += "\n== Processors counts per families ==\n"
    sites = @site_uids.map{ |e| "[[#{e.capitalize}:Hardware|#{e.capitalize}]]" }
    table_options = 'class="wikitable sortable" style="text-align: center;"'
    table_columns = ['Processor family'] + sites + ['Processors total']
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'proc_families'))
    generated_content += "\n== Processors counts per models ==\n"
    table_columns = ['Microarchitecture', 'Processor model'] + sites + ['Processors total']
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'proc_models'))
    generated_content += "\n== Cores counts per models ==\n"
    table_columns =  ['Microarchitecture', 'Core model'] + sites + ['Cores total']
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'core_models'))

    generated_content += "\n= RAM size per node =\n"
    table_columns = ['RAM size'] + sites + ['Nodes total']
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'ram_size'))

235 236
    generated_content += "\n= Networking =\n"
    generated_content += "\n== Network interconnects ==\n"
237 238 239
    table_columns = ['Interconnect'] + sites + ['Cards total']
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'net_interconnects'))

240
    generated_content += "\n== Nodes with several Ethernet interfaces ==\n"
241
    generated_content +=  generate_interfaces
242 243

    generated_content += "\n== Network interface models ==\n"
244
    table_columns = ['Type', 'Model'] + sites + ['Cards total']
245
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'net_models'))
246

247 248 249 250
    generated_content += "\n= Storage ="
    generated_content += "\n== Nodes with several disks ==\n"
    generated_content +=  generate_storage

251 252 253 254 255 256 257 258 259 260
    generated_content += "\n= Accelerators (GPU, Xeon Phi) ="
    generated_content += "\n== Accelerator families ==\n"
    table_columns = ['Accelerator family'] + sites + ['Accelerators total']
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'acc_families'))
    table_columns = ['Accelerator model'] + sites + ['Accelerators total']
    generated_content += "\n== Accelerator models ==\n"
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'acc_models'))
    generated_content += "\n== Accelerator cores ==\n"
    table_columns = ['Accelerator model'] + sites + ['Cores total']
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'acc_cores'))
261

262 263 264
    generated_content += "\n= Nodes models =\n"
    table_columns = ['Nodes model'] + sites + ['Nodes total']
    generated_content += MW.generate_table(table_options, table_columns, get_table_data(data, 'node_models'))
Lucas Nussbaum's avatar
Lucas Nussbaum committed
265
    return generated_content
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
  end

  def init(data, key1, key2)
    if not data[key1].key?(key2)
      data[key1][key2] = {}
      @site_uids.each { |s| data[key1][key2][s] = 0 }
    end
  end

  # This method generates a wiki table from data[key] values, sorted by key
  # values in first column.
  def get_table_data(data, key)
    raw_data = []
    table_data = []
    index = 0
    k0 = 0
    data[key].sort_by{
283 284 285 286
      # Sort the table by the identifiers (e.g. Microarchitecture, or Microarchitecture + CPU name).
      # This colum is either just a text field, or a more complex hash with a :sort key that should be
      # used for sorting.
      |k, v| k.map { |c| c.kind_of?(Hash) ? c[:sort] : c }
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
    }.to_h.each { |k, v|
      k0 = k if index == 0
      index += 1
      elts = v.sort.to_h.values
      raw_data << elts
      table_data << k.map{ |e| e.kind_of?(Hash) ? "data-sort-value=\"#{e[:sort]}\"|#{e[:text]}" : "data-sort-value=\"#{index.to_s.rjust(3, '0')}\"|#{e}" } +
        elts.map{ |e| e.kind_of?(Hash) ? "data-sort-value=\"#{e[:sort]}\"|#{e[:text]}" : e }
        .map{ |e| e == 0 ? '' : e  } + ["'''#{elts.reduce(:+)}'''"]
    }
    elts = raw_data.transpose.map{ |e| e.reduce(:+)}
    table_data << {columns: ["'''Sites total'''"] +
                   [' '] * (k0.length - 1) +
                   (elts + [elts.reduce(:+)]).map{ |e| e == 0 ? '' : "'''#{e}'''" },
                   sort: false}
  end

  # See: https://en.wikipedia.org/wiki/List_of_Intel_Xeon_microprocessors
  # For a correct sort of the column, all dates must be in the same
  # format (same number of digits)
  def get_date(microarchitecture)
307
    return 'MISSING' if microarchitecture.nil?
308 309 310 311 312 313 314 315 316 317 318 319
    release_dates = {
      'K8' => '2003',
      'K10' => '2007',
      'Clovertown' => '2006',
      'Harpertown' => '2007',
      'Dunnington' => '2008',
      'Lynnfield' => '2009',
      'Nehalem' => '2010',
      'Westmere' => '2011',
      'Sandy Bridge' => '2012',
      'Haswell' => '2013',
      'Broadwell' => '2015',
320 321
      'Skylake' => '2016',
      'Zen' => '2017'
322
    }
Lucas Nussbaum's avatar
Lucas Nussbaum committed
323 324
    date = release_dates[microarchitecture]
    raise "ERROR: microarchitecture not found: '#{microarchitecture}'. Add in hardware.rb" if date.nil?
325 326
    date
  end
327 328

  def generate_storage
329
    table_columns = ["Site", "Cluster", "Number of nodes", "Main disk", "Additional HDDs", "Additional SSDs", "[[Disk_reservation|Disk reservation]]"]
330 331 332 333 334 335 336 337 338 339
    table_data = []
    global_hash = get_global_hash

    # Loop over Grid'5000 sites
    global_hash["sites"].sort.to_h.each do |site_uid, site_hash|
      site_hash.fetch("clusters").sort.to_h.each do |cluster_uid, cluster_hash|
        nodes_data = []
        cluster_hash.fetch('nodes').sort.to_h.each do |node_uid, node_hash|
          next if node_hash['status'] == 'retired'
          sd = node_hash['storage_devices']
340 341
          reservable_disks = sd.select{ |v| v['reservation'] == true }.count > 0
          maindisk = sd.select { |v| v['device'] == 'sda' }[0]
342
          maindisk_t = maindisk['storage'] + ' ' + G5K.get_size(maindisk['size'],'metric')
343 344
          other = sd.select { |d| d['device'] != 'sda' }
          hdds = other.select { |d| d['storage'] == 'HDD' }
345 346 347
          if hdds.count == 0
            hdd_t = "0"
          else
348
            hdd_t = hdds.count.to_s + " (" + hdds.map { |d| G5K.get_size(d['size'],'metric') }.join(', ') + ")"
349
          end
350
          ssds = other.select { |d| d['storage'] == 'SSD' }
351 352 353
          if ssds.count == 0
            ssd_t = "0"
          else
354
            ssd_t = ssds.count.to_s + " (" + ssds.map { |d| G5K.get_size(d['size'],'metric') }.join(', ') + ")"
355
          end
356 357 358
          queues = cluster_hash['queues'] - ['admin', 'default']
          queue_t = (queues.nil? || (queues.empty? ? '' : "_.28" + queues[0].gsub(' ', '_') + ' queue.29'))
          nodes_data << { 'uid' => node_uid, 'data' => { 'main' => maindisk_t, 'hdd' => hdd_t, 'ssd' => ssd_t, 'reservation' => reservable_disks, 'queue' => queue_t } }
359 360 361 362 363 364 365 366 367 368 369 370
        end
        nd = nodes_data.group_by { |d| d['data'] }
        nd.each do |data, nodes|
          # only keep nodes with more than one disk
          next if data['hdd'] == "0" and data['ssd'] == "0"
          if nd.length == 1
            nodesetname = cluster_uid
          else
            nodesetname = G5K.nodeset(nodes.map { |n| n['uid'].split('-')[1].to_i })
          end
          table_data << [
            "[[#{site_uid.capitalize}:Hardware|#{site_uid.capitalize}]]",
371
              "[[#{site_uid.capitalize}:Hardware##{cluster_uid}#{data['queue']}|#{nodesetname}]]",
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
              nodes.length,
              data['main'],
              data['hdd'],
              data['ssd'],
              data['reservation'] ? 'yes' : 'no'
          ]
        end
      end
    end
    # Sort by site and cluster name
    table_data.sort_by! { |row|
      [row[0], row[1]]
    }

    # Table construction
Lucas Nussbaum's avatar
Lucas Nussbaum committed
387
    table_options = 'class="wikitable sortable" style="text-align: center;"'
388 389 390
    return MW.generate_table(table_options, table_columns, table_data)
  end

391 392
  def generate_interfaces
    table_data = []
393 394
    @global_hash["sites"].sort.to_h.each { |site_uid, site_hash|
      site_hash.fetch("clusters").sort.to_h.each { |cluster_uid, cluster_hash|
395
        network_interfaces = {}
396
        cluster_hash.fetch('nodes').sort.to_h.each { |node_uid, node_hash|
397 398
          next if node_hash['status'] == 'retired'
          if node_hash['network_adapters']
399 400 401 402 403 404
            node_interfaces = node_hash['network_adapters'].select{ |v|
              v['interface'] == 'Ethernet' and
              v['enabled'] == true and
              (v['mounted'] == true or v['mountable'] == true) and
              v['management'] == false
            }
405 406

            interfaces = {}
407 408 409 410
            interfaces['25g_count'] = node_interfaces.select { |v| v['rate'] == 25_000_000_000 }.count
            interfaces['10g_count'] = node_interfaces.select { |v| v['rate'] == 10_000_000_000 }.count
            interfaces['1g_count'] = node_interfaces.select { |v| v['rate'] == 1_000_000_000 }.count
            interfaces['details'] = node_interfaces.map{ |v| v['device'] + (v['name'].nil? ? '' : '/' + v['name'])  + ' (' + G5K.get_rate(v['rate']) + ')' }.sort.join(', ')
411
            queues = cluster_hash['queues'] - ['admin', 'default', 'testing']
412
            interfaces['queues'] = (queues.nil? || (queues.empty? ? '' : queues[0] + G5K.pluralize(queues.count, ' queue')))
413
            interface_add(network_interfaces, node_uid, interfaces) if node_interfaces.count > 1
414 415 416 417 418 419 420 421 422
          end
        }

        # One line for each group of nodes with the same interfaces
        network_interfaces.sort.to_h.each { |num, interfaces|
          table_data << [
            "[[#{site_uid.capitalize}:Network|#{site_uid.capitalize}]]",
            "[[#{site_uid.capitalize}:Hardware##{cluster_uid}" + (interfaces['queues'] == '' ? '' : "_.28#{queues.gsub(' ', '_')}.29") + "|#{cluster_uid}" + (network_interfaces.size==1 ? '' : '-' + G5K.nodeset(num)) + "]]",
            num.count,
DELABROYE Dimitri's avatar
DELABROYE Dimitri committed
423
            interfaces['25g_count'].zero? ? '' : interfaces['25g_count'],
424 425 426 427 428 429 430 431 432 433 434 435 436
            interfaces['10g_count'].zero? ? '' : interfaces['10g_count'],
            interfaces['1g_count'].zero? ? '' : interfaces['1g_count'],
            interfaces['details']
          ]
        }
      }
    }
    # Sort by site and cluster name
    table_data.sort_by! { |row|
      [row[0], row[1]]
    }

    table_options = 'class="wikitable sortable" style="text-align: center;"'
437
    table_columns = ["Site", "Cluster", "Nodes", "25G interfaces", "10G interfaces", "1G interfaces", "Interfaces (throughput)"]
438
    MW.generate_table(table_options, table_columns, table_data)
439 440 441 442 443 444
  end

  # This methods adds the array interfaces to the hash
  # network_interfaces. If nodes 2,3,7 have the same interfaces, they
  # will be gathered in the same key and we will have
  # network_interfaces[[2,3,7]] = interfaces
445
  def interface_add(network_interfaces, node_uid, interfaces)
446 447 448 449 450 451 452 453
    num1 = node_uid.split('-')[1].to_i
    if network_interfaces.has_value?(interfaces) == false
      network_interfaces[[num1]] = interfaces
    else
      num2 = network_interfaces.key(interfaces)
      network_interfaces.delete(num2)
      network_interfaces[num2.push(num1)] = interfaces
    end
454
  end
455 456
end

Lucas Nussbaum's avatar
Lucas Nussbaum committed
457 458
if __FILE__ == $0
  generator = G5KHardwareGenerator.new("Hardware")
459

Lucas Nussbaum's avatar
Lucas Nussbaum committed
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474
  options = WikiGenerator::parse_options
  if (options)
    ret = 2
    begin
      ret = generator.exec(options)
    rescue MediawikiApi::ApiError => e
      puts e, e.backtrace
      ret = 3
    rescue StandardError => e
      puts "Error with node: #{generator.instance_variable_get(:@node)}"
      puts e, e.backtrace
      ret = 4
    ensure
      exit(ret)
    end
475 476
  end
end