Skip to content

Commit

Permalink
move getOnlineInstallStatus query to go
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed Jul 28, 2020
1 parent dffd59a commit 757fa67
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 36 deletions.
1 change: 1 addition & 0 deletions kotsadm/pkg/apiserver/server.go
Expand Up @@ -116,6 +116,7 @@ func Start() {
r.Path("/api/v1/imagerewritestatus").Methods("OPTIONS", "GET").HandlerFunc(handlers.GetImageRewriteStatus)

r.Path("/api/v1/metadata").Methods("OPTIONS", "GET").HandlerFunc(handlers.Metadata)
r.Path("/api/v1/app/online/status").Methods("OPTIONS", "GET").HandlerFunc(handlers.GetOnlineInstallStatus)
r.Path("/api/v1/app/{appSlug}/registry").Methods("OPTIONS", "PUT").HandlerFunc(handlers.UpdateAppRegistry)
r.Path("/api/v1/app/{appSlug}/registry").Methods("OPTIONS", "GET").HandlerFunc(handlers.GetAppRegistry)
r.Path("/api/v1/app/{appSlug}/registry/validate").Methods("OPTIONS", "POST").HandlerFunc(handlers.ValidateAppRegistry)
Expand Down
24 changes: 24 additions & 0 deletions kotsadm/pkg/handlers/license.go
Expand Up @@ -446,3 +446,27 @@ func ResumeInstallOnline(w http.ResponseWriter, r *http.Request) {

JSON(w, 200, resumeInstallOnlineResponse)
}

func GetOnlineInstallStatus(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Headers", "content-type, origin, accept, authorization")

if r.Method == "OPTIONS" {
w.WriteHeader(200)
return
}

if err := requireValidSession(w, r); err != nil {
logger.Error(err)
return
}

status, err := online.GetInstallStatus()
if err != nil {
logger.Error(err)
w.WriteHeader(500)
return
}

JSON(w, 200, status)
}
29 changes: 29 additions & 0 deletions kotsadm/pkg/online/online.go
Expand Up @@ -3,6 +3,7 @@ package online
import (
"bufio"
"context"
"database/sql"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -32,6 +33,34 @@ type PendingApp struct {
LicenseData string
}

type InstallStatus struct {
InstallStatus string `json:"installStatus"`
CurrentMessage string `json:"currentMessage"`
}

func GetInstallStatus() (*InstallStatus, error) {
db := persistence.MustGetPGSession()
query := `SELECT install_state from app ORDER BY created_at DESC LIMIT 1`
row := db.QueryRow(query)

var installState sql.NullString
if err := row.Scan(&installState); err != nil {
return nil, errors.Wrap(err, "failed to scan")
}

_, message, err := task.GetTaskStatus("online-install")
if err != nil {
return nil, errors.Wrap(err, "failed to get task status")
}

status := &InstallStatus{
InstallStatus: installState.String,
CurrentMessage: message,
}

return status, nil
}

func CreateAppFromOnline(pendingApp *PendingApp, upstreamURI string, isAutomated bool) (_ *kotsutil.KotsKinds, finalError error) {
logger.Debug("creating app from online",
zap.String("upstreamURI", upstreamURI))
Expand Down
4 changes: 1 addition & 3 deletions kotsadm/web/src/components/AirgapUploadProgress.jsx
Expand Up @@ -20,7 +20,7 @@ class AirgapUploadProgress extends React.Component {

componentDidMount() {
processingImages = null;
this.getAirgapInstallStatus();
this.state.getAirgapInstallStatusJob.start(this.getAirgapInstallStatus, 1000);
}

componentWillUnmount() {
Expand Down Expand Up @@ -105,8 +105,6 @@ class AirgapUploadProgress extends React.Component {
);
}

this.state.getAirgapInstallStatusJob.start(this.getAirgapInstallStatus, 1000);

let statusMsg = currentMessage;
try {
// Some of these messages will be JSON formatted progress reports.
Expand Down
91 changes: 58 additions & 33 deletions kotsadm/web/src/components/LicenseUploadProgress.jsx
@@ -1,46 +1,71 @@
import React from "react"
import { withRouter } from "react-router-dom";
import { compose, withApollo, graphql} from "react-apollo";
import { getOnlineInstallStatus } from "../queries/AppsQueries";
import { Utilities } from "@src/utilities/utilities";
import { Repeater } from "@src/utilities/repeater";
import "@src/scss/components/AirgapUploadProgress.scss";

function LicenseUploadProgress(props) {
const { getOnlineInstallStatus } = props.data;
class LicenseUploadProgress extends React.Component {
constructor(props) {
super(props);

props.data?.startPolling(2000);
this.state = {
installStatus: "",
currentMessage: "",
getOnlineInstallStatusJob: new Repeater(),
};
}

const statusMsg = getOnlineInstallStatus?.currentMessage;
componentDidMount() {
this.state.getOnlineInstallStatusJob.start(this.getOnlineInstallStatus, 2000);
}

let statusDiv = (
<div className={`u-marginTop--10 u-lineHeight--medium u-textAlign--center`}>
<p className="u-color--tundora u-fontSize--normal u-fontWeight--bold u-marginBottom--10 u-paddingBottom--5">{statusMsg}</p>
<p className="u-fontSize--small u-color--dustyGray u-fontWeight--medium">This may take a while depending on your network connection.</p>
</div>
);
componentWillUnmount() {
this.state.getOnlineInstallStatusJob.stop();
}

return (
<div className="AirgapUploadProgress--wrapper flex1 flex-column alignItems--center justifyContent--center">
<div className="flex1 flex-column alignItems--center justifyContent--center u-color--tuna">
<p className="u-marginTop--10 u-paddingTop--5 u-marginBottom--5 u-fontSize--header u-color--tuna u-fontWeight--bold">Installing your license</p>
<div className="u-marginTop--20">
<div className="progressbar medium">
<div id="myBar" className="progressbar-meter" style={{width: "0%"}}></div>
getOnlineInstallStatus = async () => {
try {
const res = await fetch(`${window.env.API_ENDPOINT}/app/online/status`, {
headers: {
"Authorization": Utilities.getToken(),
"Content-Type": "application/json",
},
method: "GET",
});

const response = await res.json();

this.setState({
installStatus: response.installStatus,
currentMessage: response.currentMessage,
});
} catch(err) {
console.log(err);
}
}

render() {
let statusDiv = (
<div className={`u-marginTop--10 u-lineHeight--medium u-textAlign--center`}>
<p className="u-color--tundora u-fontSize--normal u-fontWeight--bold u-marginBottom--10 u-paddingBottom--5">{this.state.currentMessage}</p>
<p className="u-fontSize--small u-color--dustyGray u-fontWeight--medium">This may take a while depending on your network connection.</p>
</div>
);

return (
<div className="AirgapUploadProgress--wrapper flex1 flex-column alignItems--center justifyContent--center">
<div className="flex1 flex-column alignItems--center justifyContent--center u-color--tuna">
<p className="u-marginTop--10 u-paddingTop--5 u-marginBottom--5 u-fontSize--header u-color--tuna u-fontWeight--bold">Installing your license</p>
<div className="u-marginTop--20">
<div className="progressbar medium">
<div id="myBar" className="progressbar-meter" style={{width: "0%"}}></div>
</div>
</div>
{statusDiv}
</div>
{statusDiv}
</div>
</div>
);
);
}
}

export default compose(
withRouter,
withApollo,
graphql(getOnlineInstallStatus, {
options: () => {
return {
fetchPolicy: "network-only"
};
}
})
)(LicenseUploadProgress);
export default withRouter(LicenseUploadProgress);

0 comments on commit 757fa67

Please sign in to comment.