<commit_before>/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

import React from 'react';
import { connect } from 'react-redux';
import { Progress, Table } from 'reactstrap';
import { AnyAction, compose, Dispatch } from 'redux';

import { withErrors, withLoadingMessage, withFetchData } from '@alluxio/common-ui/src/components';
import { INodeInfo } from '../../../constants';
import { IApplicationState } from '../../../store';
import { fetchRequest } from '../../../store/workers/actions';
import { IWorkers } from '../../../store/workers/types';
import { IInit } from '../../../store/init/types';
import { createAlertErrors } from '@alluxio/common-ui/src/utilities';
import { ICommonState } from '@alluxio/common-ui/src/constants';

interface IPropsFromState extends ICommonState {
  initData: IInit;
  workersData: IWorkers;
}

interface IPropsFromDispatch {
  fetchRequest: typeof fetchRequest;
}

export type AllProps = IPropsFromState & IPropsFromDispatch;

export class WorkersPresenter extends React.Component<AllProps> {
  public render(): JSX.Element {
    const { initData, workersData } = this.props;

    return (
      <div className="workers-page">
        <div className="container-fluid">
          <div className="row">
            <div className="col-12">
              <h5>Live Workers</h5>
              <Table hover={true}>
                <thead>
                  <tr>
                    <th>Node Name</th>
                    {initData.debug && (
                      <React.Fragment>
                        <th>[D]Worker Id</th>
                        <th>[D]Uptime</th>
                      </React.Fragment>
                    )}
                    <th>Last Heartbeat</th>
                    <th>State</th>
                    <th>Block Count</th>
                    <th>Workers Capacity</th>
                    <th>Space Used</th>
                    <th>Space Usage</th>
                  </tr>
                </thead>
                <tbody>
                  {workersData.normalNodeInfos.map((nodeInfo: INodeInfo) => (
                    <tr key={nodeInfo.workerId}>
                      <td>
                        <a href={`//${nodeInfo.host}:${initData.workerPort}`} rel="noopener noreferrer" target="_blank">
                          {nodeInfo.host}
                        </a>
                      </td>
                      {initData.debug && (
                        <React.Fragment>
                          <td>{nodeInfo.workerId}</td>
                          <td>{nodeInfo.uptimeClockTime}</td>
                        </React.Fragment>
                      )}
                      <td>{nodeInfo.lastHeartbeat}</td>
                      <td>{nodeInfo.state}</td>
                      <td>{nodeInfo.blockCount}</td><commit_msg>Fix url address of the alive workers  when workers start with kubernetes<commit_after>/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

import React from 'react';
import { connect } from 'react-redux';
import { Progress, Table } from 'reactstrap';
import { AnyAction, compose, Dispatch } from 'redux';

import { withErrors, withLoadingMessage, withFetchData } from '@alluxio/common-ui/src/components';
import { INodeInfo } from '../../../constants';
import { IApplicationState } from '../../../store';
import { fetchRequest } from '../../../store/workers/actions';
import { IWorkers } from '../../../store/workers/types';
import { IInit } from '../../../store/init/types';
import { createAlertErrors } from '@alluxio/common-ui/src/utilities';
import { ICommonState } from '@alluxio/common-ui/src/constants';

interface IPropsFromState extends ICommonState {
  initData: IInit;
  workersData: IWorkers;
}

interface IPropsFromDispatch {
  fetchRequest: typeof fetchRequest;
}

export type AllProps = IPropsFromState & IPropsFromDispatch;

export class WorkersPresenter extends React.Component<AllProps> {
  public render(): JSX.Element {
    const { initData, workersData } = this.props;

    return (
      <div className="workers-page">
        <div className="container-fluid">
          <div className="row">
            <div className="col-12">
              <h5>Live Workers</h5>
              <Table hover={true}>
                <thead>
                  <tr>
                    <th>Node Name</th>
                    {initData.debug && (
                      <React.Fragment>
                        <th>[D]Worker Id</th>
                        <th>[D]Uptime</th>
                      </React.Fragment>
                    )}
                    <th>Last Heartbeat</th>
                    <th>State</th>
                    <th>Block Count</th>
                    <th>Workers Capacity</th>
                    <th>Space Used</th>
                    <th>Space Usage</th>
                  </tr>
                </thead>
                <tbody>
                  {workersData.normalNodeInfos.map((nodeInfo: INodeInfo) => (
                    <tr key={nodeInfo.workerId}>
                      <td>
                        <a
                          href={
                            // When workers start with kubernetes. `nodeInfo.host` is `hostIp (podIp)`
                            nodeInfo.host.includes('(')
                              ? `//${nodeInfo.host.substring(0, nodeInfo.host.indexOf('(')).trim()}:${
                                  initData.workerPort
                                }`
                              : `//${nodeInfo.host}:${initData.workerPort}`
                          }
                          rel="noopener noreferrer"
                          target="_blank"
                        >
                          {nodeInfo.host}
                        </a>
                      </td>
                      {initData.debug && (
                        <React.Fragment>
                          <td>{nodeInfo.workerId}</td>
                          <td>{nodeInfo.uptimeClockTime}</td>
                        </React.Fragment>
                      )}
                      <td>{nodeInfo.lastHeartbeat}</td>
                      <td>{nodeInfo.state}</td>
                      <td>{nodeInfo.blockCount}</td>
{'fraction_non_alphanumeric': 0.12149400986610288, 'fraction_numerical': 0.0023960535588442564, 'mean_word_length': 1.5645102999638598, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 105, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4225533', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1783, 'n_words': 454}