diff --git a/ui/src/components/ClusterCard.js b/ui/src/components/ClusterCard.js index e702ed29dec..894b806ae2b 100644 --- a/ui/src/components/ClusterCard.js +++ b/ui/src/components/ClusterCard.js @@ -10,6 +10,7 @@ import { withStyles } from '@material-ui/core/styles'; import ConnectButton from './ConnectButton' import DeleteDialog from './DeleteDialog' +import StartButton from './StartButton' import StatusIcon from './StatusIcon' @@ -28,6 +29,7 @@ const unknownStatus = "Unknown"; const runningStatus = "Running"; const deletingStatus = "Deleting"; const deletedStatus = "Deleted"; +const stoppedStatus = "Stopped"; const errorString404 = "404/Not Found"; @@ -79,7 +81,12 @@ class ClusterCard extends React.Component { setClusterStatusDeleting = () => { this.setState({ clusterStatus: "Deleting" }); - this.checkForUpdatedState() + setTimeout(this.checkForUpdatedState, fastStatusCheckInterval) + } + + setClusterStatusStarting = () => { + this.setState({ clusterStatus: "Starting" }); + setTimeout(this.checkForUpdatedState, fastStatusCheckInterval) } /** @@ -193,6 +200,25 @@ class ClusterCard extends React.Component { var classes = this.props.classes; var model = this.props.clusterModel; var machineCfg = model.machineConfig; + var startOrConnect = null; + if (this.state.clusterStatus === stoppedStatus) { + startOrConnect = ( + ); + } else { + startOrConnect = ( + ); + } return ( @@ -230,13 +256,7 @@ class ClusterCard extends React.Component { - + {startOrConnect} { + var model = this.props.clusterModel; + // Fetch auth info which includes the Google Client ID. + var notebooksUrl = createApiUrl( + model.googleProject, model.clusterName); + fetch( + notebooksUrl + "/start", + { + method: "POST", + headers: { + "Authorization": "Bearer " + this.props.googleAuthToken + }, + credentials: "include" + }) + .then((response) => { + if (response.status == 409) { + throw new Error("Cluster cannot be started.") + } + if (response.status == 404) { + throw new Error("Cluster not found.") + } + if (response.status >= 400) { + console.log("Unexpected response, logging response object.") + console.log(response) + throw new Error("Bad response from server. Cluster may not start."); + } + return response; + }) + .then((response) => this.props.updateStatusToStarting()) + .catch((error) => { + this.props.errorHandler(error.toString()); + }); + } + + render() { + return ; + } +} + +export default StartButton;