Skip to content

Commit

Permalink
Merge pull request #990 from replicatedhq/laverya/getUpdateDownloadSt…
Browse files Browse the repository at this point in the history
…atus

move getUpdateDownloadStatus to golang
  • Loading branch information
laverya committed Aug 22, 2020
2 parents 0117fba + 51b46e6 commit 3075d12
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 48 deletions.
4 changes: 0 additions & 4 deletions kotsadm/api/src/kots_app/kots_app_store.ts
Expand Up @@ -1770,10 +1770,6 @@ WHERE app_id = $1 AND cluster_id = $2 AND sequence = $3`;
await this.updateApiTaskStatusLiveness("image-rewrite");
}

async getUpdateDownloadStatus(): Promise<{ currentMessage: string, status: string }> {
return this.getApiTaskStatus("update-download");
}

async setUpdateDownloadStatus(msg: string, status: string): Promise<void> {
await this.setApiTaskStatus("update-download", msg, status);
}
Expand Down
4 changes: 0 additions & 4 deletions kotsadm/api/src/kots_app/resolvers/kots_app_queries.ts
Expand Up @@ -77,10 +77,6 @@ export function KotsQueries(stores: Stores, params: Params) {
return await stores.kotsAppStore.getImageRewriteStatus();
},

async getUpdateDownloadStatus(root: any, args: any, context: Context): Promise<{ currentMessage: string, status: string}> {
return await stores.kotsAppStore.getUpdateDownloadStatus();
},

async getKotsDownstreamOutput(root: any, args: any, context: Context): Promise<KotsDownstreamOutput> {
const appId = await stores.kotsAppStore.getIdFromSlug(args.appSlug);
const app = await context.getApp(appId);
Expand Down
1 change: 0 additions & 1 deletion kotsadm/api/src/schema/query.ts
Expand Up @@ -39,7 +39,6 @@ export const Query = `
getAirgapInstallStatus: InstallStatus
getOnlineInstallStatus: InstallStatus
getImageRewriteStatus: ImageRewriteStatus
getUpdateDownloadStatus: UpdateDownloadStatus
kurl: Kurl
Expand Down
3 changes: 3 additions & 0 deletions kotsadm/pkg/apiserver/server.go
Expand Up @@ -177,6 +177,9 @@ func Start() {
r.Path("/api/v1/gitops/app/{appId}/cluster/{clusterId}/initconnection").Methods("OPTIONS", "POST").HandlerFunc(handlers.InitGitOpsConnection)
r.Path("/api/v1/gitops/reset").Methods("OPTIONS", "POST").HandlerFunc(handlers.ResetGitOps)

// task status
r.Path("/api/v1/task/updatedownload").Methods("OPTIONS", "GET").HandlerFunc(handlers.GetUpdateDownloadStatus)

// to avoid confusion, we don't serve this in the dev env...
if os.Getenv("DISABLE_SPA_SERVING") != "1" {
spa := handlers.SPAHandler{StaticPath: filepath.Join("web", "dist"), IndexPath: "index.html"}
Expand Down
40 changes: 40 additions & 0 deletions kotsadm/pkg/handlers/status.go
@@ -0,0 +1,40 @@
package handlers

import (
"net/http"

"github.com/replicatedhq/kots/kotsadm/pkg/logger"
"github.com/replicatedhq/kots/kotsadm/pkg/store"
)

type GetUpdateDownloadStatusResponse struct {
CurrentMessage string `json:"currentMessage"`
Status string `json:"status"`
}

func GetUpdateDownloadStatus(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(http.StatusOK)
return
}

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

status, message, err := store.GetStore().GetTaskStatus("update-download")
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
logger.Error(err)
return
}

JSON(w, http.StatusOK, GetUpdateDownloadStatusResponse{
CurrentMessage: message,
Status: status,
})
}
34 changes: 19 additions & 15 deletions kotsadm/web/src/components/apps/AppVersionHistory.jsx
Expand Up @@ -19,7 +19,7 @@ import DownstreamWatchVersionDiff from "@src/components/watches/DownstreamWatchV
import AirgapUploadProgress from "@src/components/AirgapUploadProgress";
import UpdateCheckerModal from "@src/components/modals/UpdateCheckerModal";
import ShowDetailsModal from "@src/components/modals/ShowDetailsModal";
import { getKotsDownstreamHistory, getUpdateDownloadStatus } from "../../queries/AppsQueries";
import { getKotsDownstreamHistory } from "../../queries/AppsQueries";
import { Utilities, isAwaitingResults, secondsAgo, getPreflightResultState, getGitProviderDiffUrl, getCommitHashFromUrl } from "../../utilities/utilities";
import { Repeater } from "../../utilities/repeater";
import has from "lodash/has";
Expand Down Expand Up @@ -520,32 +520,36 @@ class AppVersionHistory extends Component {

updateStatus = () => {
return new Promise((resolve, reject) => {
this.props.client.query({
query: getUpdateDownloadStatus,
fetchPolicy: "no-cache",
}).then((res) => {

this.setState({
checkingForUpdates: true,
checkingUpdateMessage: res.data.getUpdateDownloadStatus?.currentMessage,
});
fetch(`${window.env.API_ENDPOINT}/task/updatedownload`, {
headers: {
"Authorization": Utilities.getToken(),
"Content-Type": "application/json",
},
method: "GET",
})
.then(async (res) => {
const response = await res.json();

if (res.data.getUpdateDownloadStatus.status !== "running" && !this.props.isBundleUploading) {
if (response.status !== "running" && !this.props.isBundleUploading) {
this.state.updateChecker.stop();

this.setState({
checkingForUpdates: false,
checkingForUpdateError: res.data.getUpdateDownloadStatus.status === "failed",
checkingUpdateMessage: res.data.getUpdateDownloadStatus?.currentMessage
checkingUpdateMessage: response.currentMessage,
checkingForUpdateError: response === "failed"
});

if (this.props.updateCallback) {
this.props.updateCallback();
}
this.props.data.refetch();
} else {
this.setState({
checkingForUpdates: true,
checkingUpdateMessage: response.currentMessage,
});
}

resolve();

}).catch((err) => {
console.log("failed to get rewrite status", err);
reject();
Expand Down
31 changes: 17 additions & 14 deletions kotsadm/web/src/components/apps/Dashboard.jsx
Expand Up @@ -12,7 +12,6 @@ import UpdateCheckerModal from "@src/components/modals/UpdateCheckerModal";
import Modal from "react-modal";
import { Repeater } from "../../utilities/repeater";
import { Utilities } from "../../utilities/utilities";
import { getUpdateDownloadStatus } from "@src/queries/AppsQueries";

import { XYPlot, XAxis, YAxis, HorizontalGridLines, VerticalGridLines, LineSeries, DiscreteColorLegend, Crosshair } from "react-vis";

Expand Down Expand Up @@ -221,30 +220,34 @@ class Dashboard extends Component {

updateStatus = () => {
return new Promise((resolve, reject) => {
this.props.client.query({
query: getUpdateDownloadStatus,
fetchPolicy: "no-cache",
}).then((res) => {

this.setState({
checkingForUpdates: true,
checkingUpdateMessage: res.data.getUpdateDownloadStatus.currentMessage,
});
fetch(`${window.env.API_ENDPOINT}/task/updatedownload`, {
headers: {
"Authorization": Utilities.getToken(),
"Content-Type": "application/json",
},
method: "GET",
})
.then(async (res) => {
const response = await res.json();

if (res.data.getUpdateDownloadStatus.status !== "running" && !this.props.isBundleUploading) {
if (response.status !== "running" && !this.props.isBundleUploading) {
this.state.updateChecker.stop();

this.setState({
checkingForUpdates: false,
checkingUpdateMessage: res.data.getUpdateDownloadStatus?.currentMessage,
checkingForUpdateError: res.data.getUpdateDownloadStatus.status === "failed"
checkingUpdateMessage: response.currentMessage,
checkingForUpdateError: response === "failed"
});

if (this.props.updateCallback) {
this.props.updateCallback();
}
} else {
this.setState({
checkingForUpdates: true,
checkingUpdateMessage: response.currentMessage,
});
}

resolve();
}).catch((err) => {
console.log("failed to get rewrite status", err);
Expand Down
10 changes: 0 additions & 10 deletions kotsadm/web/src/queries/AppsQueries.js
Expand Up @@ -277,16 +277,6 @@ export const getImageRewriteStatusRaw = `
`;
export const getImageRewriteStatus = gql(getImageRewriteStatusRaw);

export const getUpdateDownloadStatusRaw = `
query getUpdateDownloadStatus {
getUpdateDownloadStatus {
currentMessage
status
}
}
`;
export const getUpdateDownloadStatus = gql(getUpdateDownloadStatusRaw);

export const getKotsDownstreamOutput = gql`
query getKotsDownstreamOutput($appSlug: String!, $clusterSlug: String!, $sequence: Int!) {
getKotsDownstreamOutput(appSlug: $appSlug, clusterSlug: $clusterSlug, sequence: $sequence) {
Expand Down

0 comments on commit 3075d12

Please sign in to comment.