Skip to content

Commit

Permalink
feat: Show experiment status in json (#853)
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege authored and k8s-ci-robot committed Oct 9, 2019
1 parent 2be5f93 commit 5cdbde6
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/ui/v1alpha3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func main() {
//TODO: Add it in Katib client
http.HandleFunc("/katib/delete_experiment/", kuh.DeleteExperiment)

http.HandleFunc("/katib/fetch_hp_job/", kuh.FetchHPJob)
http.HandleFunc("/katib/fetch_hp_job_info/", kuh.FetchHPJobInfo)
http.HandleFunc("/katib/fetch_hp_job_trial_info/", kuh.FetchHPJobTrialInfo)
http.HandleFunc("/katib/fetch_nas_job_info/", kuh.FetchNASJobInfo)
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/v1alpha3/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"react-app-polyfill": "^0.2.2",
"react-dev-utils": "^8.0.0",
"react-dom": "^16.8.3",
"react-json-view": "^1.19.1",
"react-html-parser": "^2.0.2",
"react-plotly.js": "^2.3.0",
"react-redux": "^6.0.1",
Expand Down
10 changes: 10 additions & 0 deletions pkg/ui/v1alpha3/frontend/src/actions/hpMonitorActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export const fetchHPJobInfo = (name, namespace) => ({
namespace,
})

export const FETCH_HP_JOB_REQUEST = "FETCH_HP_JOB_REQUEST";
export const FETCH_HP_JOB_SUCCESS = "FETCH_HP_JOB_SUCCESS";
export const FETCH_HP_JOB_FAILURE = "FETCH_HP_JOB_FAILURE";

export const fetchHPJob = (name, namespace) => ({
type: FETCH_HP_JOB_REQUEST,
name,
namespace,
})

export const FETCH_HP_JOB_TRIAL_INFO_REQUEST = "FETCH_HP_JOB_TRIAL_INFO_REQUEST";
export const FETCH_HP_JOB_TRIAL_INFO_SUCCESS = "FETCH_HP_JOB_TRIAL_INFO_SUCCESS";
export const FETCH_HP_JOB_TRIAL_INFO_FAILURE = "FETCH_HP_JOB_TRIAL_INFO_FAILURE";
Expand Down
10 changes: 8 additions & 2 deletions pkg/ui/v1alpha3/frontend/src/components/HP/Monitor/HPJobInfo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ import Button from '@material-ui/core/Button';
import { Link } from 'react-router-dom';
import LinearProgress from '@material-ui/core/LinearProgress';

// import the react-json-view component
import ReactJson from 'react-json-view'

import { fetchHPJobInfo } from '../../../actions/hpMonitorActions';
import { fetchHPJobInfo, fetchHPJob } from '../../../actions/hpMonitorActions';

import HPJobPlot from './HPJobPlot';
import HPJobTable from './HPJobTable';
Expand Down Expand Up @@ -35,6 +37,8 @@ class HPJobInfo extends React.Component {
componentDidMount() {
this.props.fetchHPJobInfo(
this.props.match.params.name, this.props.match.params.namespace);
this.props.fetchHPJob(
this.props.match.params.name, this.props.match.params.namespace)
}

render () {
Expand All @@ -59,6 +63,7 @@ class HPJobInfo extends React.Component {
<br />
<HPJobPlot name={this.props.match.params.name} />
<HPJobTable name={this.props.match.params.name} />
<ReactJson src={this.props.experiment} />
<TrialInfoDialog />
</div>
}
Expand All @@ -69,7 +74,8 @@ class HPJobInfo extends React.Component {

const mapStateToProps = (state) => ({
loading: state[module].loading,
experiment: state[module].experiment,
})


export default connect(mapStateToProps, { fetchHPJobInfo })(withStyles(styles)(HPJobInfo));
export default connect(mapStateToProps, { fetchHPJobInfo, fetchHPJob })(withStyles(styles)(HPJobInfo));
16 changes: 16 additions & 0 deletions pkg/ui/v1alpha3/frontend/src/reducers/hpMonitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ const hpMonitorReducer = (state = initialState, action) => {
...state,
loading: false,
}
case actions.FETCH_HP_JOB_REQUEST:
return {
...state,
loading: true,
}
case actions.FETCH_HP_JOB_SUCCESS:
return {
...state,
experiment: action.experiment,
loading: false,
}
case actions.FETCH_HP_JOB_FAILURE:
return {
...state,
loading: false,
}
case actions.FETCH_HP_JOB_TRIAL_INFO_SUCCESS:
return {
...state,
Expand Down
42 changes: 42 additions & 0 deletions pkg/ui/v1alpha3/frontend/src/sagas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,47 @@ const goFetchHPJobs = function* () {
}
}

export const fetchHPJob = function* () {
while (true) {
const action = yield take(hpMonitorActions.FETCH_HP_JOB_REQUEST);
try {
const result = yield call(
goFetchHPJob,
action.name,
action.namespace
)
if (result.status === 200) {
yield put({
type: hpMonitorActions.FETCH_HP_JOB_SUCCESS,
experiment: result.data
})
} else {
yield put({
type: hpMonitorActions.FETCH_HP_JOB_FAILURE,
})
}
} catch (err) {
yield put({
type: hpMonitorActions.FETCH_HP_JOB_FAILURE,
})
}
}
}

const goFetchHPJob = function* (name, namespace) {
try {
const result = yield call(
axios.get,
`/katib/fetch_hp_job/?experimentName=${name}&namespace=${namespace}`,
)
return result
} catch (err) {
yield put({
type: hpMonitorActions.FETCH_HP_JOB_FAILURE,
})
}
}

export const fetchHPJobInfo = function* () {
while (true) {
const action = yield take(hpMonitorActions.FETCH_HP_JOB_INFO_REQUEST);
Expand Down Expand Up @@ -639,6 +680,7 @@ export default function* rootSaga() {
fork(submitHPJob),
fork(submitNASJob),
fork(fetchHPJobInfo),
fork(fetchHPJob),
fork(fetchHPJobTrialInfo),
fork(fetchNASJobInfo)
]);
Expand Down
19 changes: 19 additions & 0 deletions pkg/ui/v1alpha3/hp.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ func (k *KatibUIHandler) FetchAllHPJobs(w http.ResponseWriter, r *http.Request)
w.Write(response)
}

// FetchAllHPJobs gets experiments in all namespaces.
func (k *KatibUIHandler) FetchHPJob(w http.ResponseWriter, r *http.Request) {
experimentName := r.URL.Query()["experimentName"][0]
namespace := r.URL.Query()["namespace"][0]

experiment, err := k.katibClient.GetExperiment(experimentName, namespace)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
response, err := json.Marshal(experiment)
if err != nil {
log.Printf("Marshal HP job failed: %v", err)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Write(response)
}

func (k *KatibUIHandler) FetchHPJobInfo(w http.ResponseWriter, r *http.Request) {
//enableCors(&w)
experimentName := r.URL.Query()["experimentName"][0]
Expand Down

0 comments on commit 5cdbde6

Please sign in to comment.