|
|
@@ -49,99 +49,102 @@ export default class Provisioner extends Component<PropsType, StateType> {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- componentDidMount() {
|
|
|
- let { currentProject } = this.context;
|
|
|
- let protocol = process.env.NODE_ENV == 'production' ? 'wss' : 'ws'
|
|
|
- let viewData = this.props.viewData || []
|
|
|
+ setupWebsocket = (ws: WebSocket, infra: any) => {
|
|
|
+ ws.onopen = () => {
|
|
|
+ console.log('connected to websocket')
|
|
|
+ }
|
|
|
|
|
|
- let websockets = viewData.map((infra: any) => {
|
|
|
- let ws = new WebSocket(`${protocol}://${process.env.API_SERVER}/api/projects/${currentProject.id}/provision/${infra.kind}/${infra.infra_id}/logs`)
|
|
|
+ ws.onmessage = (evt: MessageEvent) => {
|
|
|
+ let event = JSON.parse(evt.data);
|
|
|
+ let validEvents = [] as any[];
|
|
|
+ let err = null;
|
|
|
|
|
|
- ws.onopen = () => {
|
|
|
- console.log('connected to websocket')
|
|
|
- }
|
|
|
+ for (var i = 0; i < event.length; i++) {
|
|
|
+ let msg = event[i];
|
|
|
+ if (msg["Values"] && msg["Values"]["data"] && this.isJSON(msg["Values"]["data"])) {
|
|
|
+ let d = JSON.parse(msg["Values"]["data"]);
|
|
|
+
|
|
|
+ if (d["kind"] == "error") {
|
|
|
+ err = d["log"];
|
|
|
+ break;
|
|
|
+ }
|
|
|
|
|
|
- ws.onmessage = (evt: MessageEvent) => {
|
|
|
- let event = JSON.parse(evt.data);
|
|
|
- let validEvents = [] as any[];
|
|
|
- let err = null;
|
|
|
-
|
|
|
- for (var i = 0; i < event.length; i++) {
|
|
|
- let msg = event[i];
|
|
|
- if (msg["Values"] && msg["Values"]["data"] && this.isJSON(msg["Values"]["data"])) {
|
|
|
- let d = JSON.parse(msg["Values"]["data"]);
|
|
|
-
|
|
|
- if (d["kind"] == "error") {
|
|
|
- err = d["log"];
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- // add only valid events
|
|
|
- if (d["log"] != null && d["created_resources"] != null && d["total_resources"] != null) {
|
|
|
- validEvents.push(d);
|
|
|
- }
|
|
|
+ // add only valid events
|
|
|
+ if (d["log"] != null && d["created_resources"] != null && d["total_resources"] != null) {
|
|
|
+ validEvents.push(d);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- if (err) {
|
|
|
- let e = ansiparse(err).map((el: any) => {
|
|
|
- return el.text;
|
|
|
- })
|
|
|
- this.setState({ logs: e, error: true });
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (validEvents.length == 0) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (!this.state.maxStep[infra.kind] || !this.state.maxStep[infra.kind]["total_resources"]) {
|
|
|
- this.setState({
|
|
|
- maxStep: {
|
|
|
- ...this.state.maxStep,
|
|
|
- [infra.kind] : validEvents[validEvents.length - 1]["total_resources"]
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- let logs = [] as any[]
|
|
|
- validEvents.forEach((e: any) => {
|
|
|
- logs.push(...ansiparse(e["log"]))
|
|
|
- })
|
|
|
+ }
|
|
|
|
|
|
- logs = logs.map((log: any) => {
|
|
|
- return log.text
|
|
|
- })
|
|
|
-
|
|
|
- this.setState({
|
|
|
- logs: [...this.state.logs, ...logs],
|
|
|
- currentStep: {
|
|
|
- ...this.state.currentStep,
|
|
|
- [infra.kind] : validEvents[validEvents.length - 1]["created_resources"]
|
|
|
- },
|
|
|
- }, () => {
|
|
|
- this.scrollToBottom()
|
|
|
+ if (err) {
|
|
|
+ let e = ansiparse(err).map((el: any) => {
|
|
|
+ return el.text;
|
|
|
})
|
|
|
+ this.setState({ logs: e, error: true });
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- ws.onerror = (err: ErrorEvent) => {
|
|
|
- console.log(err)
|
|
|
+ if (validEvents.length == 0) {
|
|
|
+ return;
|
|
|
}
|
|
|
-
|
|
|
- ws.onclose = () => {
|
|
|
- console.log('closing provisioner websocket')
|
|
|
+
|
|
|
+ if (!this.state.maxStep[infra.kind] || !this.state.maxStep[infra.kind]["total_resources"]) {
|
|
|
+ this.setState({
|
|
|
+ maxStep: {
|
|
|
+ ...this.state.maxStep,
|
|
|
+ [infra.kind] : validEvents[validEvents.length - 1]["total_resources"]
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
+
|
|
|
+ let logs = [] as any[]
|
|
|
+ validEvents.forEach((e: any) => {
|
|
|
+ logs.push(...ansiparse(e["log"]))
|
|
|
+ })
|
|
|
+
|
|
|
+ logs = logs.map((log: any) => {
|
|
|
+ return log.text
|
|
|
+ })
|
|
|
+
|
|
|
+ this.setState({
|
|
|
+ logs: [...this.state.logs, ...logs],
|
|
|
+ currentStep: {
|
|
|
+ ...this.state.currentStep,
|
|
|
+ [infra.kind] : validEvents[validEvents.length - 1]["created_resources"]
|
|
|
+ },
|
|
|
+ }, () => {
|
|
|
+ this.scrollToBottom()
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- return ws
|
|
|
+ ws.onerror = (err: ErrorEvent) => {
|
|
|
+ console.log(err)
|
|
|
+ }
|
|
|
+
|
|
|
+ ws.onclose = () => {
|
|
|
+ console.log('closing provisioner websocket')
|
|
|
+ }
|
|
|
+
|
|
|
+ return ws
|
|
|
+ }
|
|
|
+
|
|
|
+ componentDidMount() {
|
|
|
+ let { currentProject } = this.context;
|
|
|
+ let protocol = process.env.NODE_ENV == 'production' ? 'wss' : 'ws'
|
|
|
+ let viewData = this.props.viewData || []
|
|
|
+
|
|
|
+ let websockets = viewData.map((infra: any) => {
|
|
|
+ let ws = new WebSocket(`${protocol}://${process.env.API_SERVER}/api/projects/${currentProject.id}/provision/${infra.kind}/${infra.infra_id}/logs`)
|
|
|
+ return this.setupWebsocket(ws, infra)
|
|
|
});
|
|
|
|
|
|
- this.setState({ websockets, logs: [] });
|
|
|
+ this.setState({ websockets, logs: ["Provisioning EKS cluster and ECR registry..."] });
|
|
|
}
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
if (!this.state.websockets) { return; }
|
|
|
|
|
|
- this.state.websockets.forEach((ws) => {
|
|
|
+ this.state.websockets.forEach((ws: any) => {
|
|
|
ws.close()
|
|
|
})
|
|
|
}
|
|
|
@@ -211,15 +214,18 @@ export default class Provisioner extends Component<PropsType, StateType> {
|
|
|
let currentStep = 0;
|
|
|
|
|
|
for (let key in this.state.maxStep) {
|
|
|
- console.log(key)
|
|
|
- maxStep += this.state.maxStep[key]
|
|
|
+ if (key == 'eks') {
|
|
|
+ maxStep += this.state.maxStep[key]
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
for (let key in this.state.currentStep) {
|
|
|
- currentStep += this.state.currentStep[key]
|
|
|
+ if (key == 'eks') {
|
|
|
+ currentStep += this.state.currentStep[key]
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- if (true && !this.state.triggerEnd) {
|
|
|
+ if (maxStep !== 0 && currentStep === maxStep && !this.state.triggerEnd) {
|
|
|
this.onEnd()
|
|
|
this.setState({ triggerEnd: true });
|
|
|
}
|