This is an automated email from the ASF dual-hosted git repository. marat pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
commit c047c8438175a69d508c21bb4a8883a380e9b76a Author: Marat Gubaidullin <ma...@talismancloud.io> AuthorDate: Fri Feb 9 17:59:22 2024 -0500 Split client api --- .../src/main/webui/src/api/KaravanApi.tsx | 34 ------------- .../src/main/webui/src/api/LogWatchApi.tsx | 58 ++++++++++++++++++++++ .../src/main/webui/src/api/NotificationApi.tsx | 57 +++++++++++++++++++++ .../main/webui/src/project/log/ProjectLogPanel.tsx | 3 +- 4 files changed, 117 insertions(+), 35 deletions(-) diff --git a/karavan-web/karavan-app/src/main/webui/src/api/KaravanApi.tsx b/karavan-web/karavan-app/src/main/webui/src/api/KaravanApi.tsx index 0e963238..2efbeeb6 100644 --- a/karavan-web/karavan-app/src/main/webui/src/api/KaravanApi.tsx +++ b/karavan-web/karavan-app/src/main/webui/src/api/KaravanApi.tsx @@ -640,38 +640,4 @@ export class KaravanApi { const uri = `/api/file/openapi/${generateRest}/${generateRoutes}/${integrationName}`; return instance.post(encodeURI(uri), file); } - - static async fetchData(type: 'container' | 'build' | 'none', podName: string, controller: AbortController) { - const fetchData = async () => { - const headers: any = { Accept: "text/event-stream" }; - if (KaravanApi.authType === 'oidc') { - headers.Authorization = "Bearer " + SsoApi.keycloak?.token - } - await fetchEventSource("/api/logwatch/" + type + "/" + podName, { - method: "GET", - headers: headers, - signal: controller.signal, - async onopen(response) { - if (response.ok && response.headers.get('content-type') === EventStreamContentType) { - return; // everything's good - } else if (response.status >= 400 && response.status < 500 && response.status !== 429) { - // client-side errors are usually non-retriable: - console.log("Server side error ", response); - } else { - console.log("Error ", response); - } - }, - onmessage(event) { - ProjectEventBus.sendLog('add', event.data); - }, - onclose() { - console.log("Connection closed by the server"); - }, - onerror(err) { - console.log("There was an error from server", err); - }, - }); - }; - return fetchData(); - } } diff --git a/karavan-web/karavan-app/src/main/webui/src/api/LogWatchApi.tsx b/karavan-web/karavan-app/src/main/webui/src/api/LogWatchApi.tsx new file mode 100644 index 00000000..49f4b134 --- /dev/null +++ b/karavan-web/karavan-app/src/main/webui/src/api/LogWatchApi.tsx @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {SsoApi} from "./SsoApi"; +import {EventStreamContentType, fetchEventSource} from "@microsoft/fetch-event-source"; +import {ProjectEventBus} from "./ProjectEventBus"; +import {KaravanApi} from "./KaravanApi"; + +export class LogWatchApi { + + static async fetchData(type: 'container' | 'build' | 'none', podName: string, controller: AbortController) { + const fetchData = async () => { + const headers: any = { Accept: "text/event-stream" }; + if (KaravanApi.authType === 'oidc') { + headers.Authorization = "Bearer " + SsoApi.keycloak?.token + } + await fetchEventSource("/api/logwatch/" + type + "/" + podName, { + method: "GET", + headers: headers, + signal: controller.signal, + async onopen(response) { + if (response.ok && response.headers.get('content-type') === EventStreamContentType) { + return; // everything's good + } else if (response.status >= 400 && response.status < 500 && response.status !== 429) { + // client-side errors are usually non-retriable: + console.log("Server side error ", response); + } else { + console.log("Error ", response); + } + }, + onmessage(event) { + ProjectEventBus.sendLog('add', event.data); + }, + onclose() { + console.log("Connection closed by the server"); + }, + onerror(err) { + console.log("There was an error from server", err); + }, + }); + }; + return fetchData(); + } +} diff --git a/karavan-web/karavan-app/src/main/webui/src/api/NotificationApi.tsx b/karavan-web/karavan-app/src/main/webui/src/api/NotificationApi.tsx new file mode 100644 index 00000000..20ea0c1f --- /dev/null +++ b/karavan-web/karavan-app/src/main/webui/src/api/NotificationApi.tsx @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import {SsoApi} from "./SsoApi"; +import {EventStreamContentType, fetchEventSource} from "@microsoft/fetch-event-source"; +import {KaravanApi} from "./KaravanApi"; + +export class NotificationApi { + + static async notification(controller: AbortController) { + const fetchData = async () => { + const headers: any = { Accept: "text/event-stream" }; + if (KaravanApi.authType === 'oidc') { + headers.Authorization = "Bearer " + SsoApi.keycloak?.token + } + await fetchEventSource("/api/notification", { + method: "GET", + headers: headers, + signal: controller.signal, + async onopen(response) { + if (response.ok && response.headers.get('content-type') === EventStreamContentType) { + return; // everything's good + } else if (response.status >= 400 && response.status < 500 && response.status !== 429) { + // client-side errors are usually non-retriable: + console.log("Server side error ", response); + } else { + console.log("Error ", response); + } + }, + onmessage(event) { + console.log(event) + }, + onclose() { + console.log("Connection closed by the server"); + }, + onerror(err) { + console.log("There was an error from server", err); + }, + }); + }; + return fetchData(); + } +} diff --git a/karavan-web/karavan-app/src/main/webui/src/project/log/ProjectLogPanel.tsx b/karavan-web/karavan-app/src/main/webui/src/project/log/ProjectLogPanel.tsx index 672a72dc..99d62b43 100644 --- a/karavan-web/karavan-app/src/main/webui/src/project/log/ProjectLogPanel.tsx +++ b/karavan-web/karavan-app/src/main/webui/src/project/log/ProjectLogPanel.tsx @@ -27,6 +27,7 @@ import {KaravanApi} from "../../api/KaravanApi"; import {shallow} from "zustand/shallow"; import {ProjectEventBus} from "../../api/ProjectEventBus"; import {ProjectLog} from "./ProjectLog"; +import {LogWatchApi} from "../../api/LogWatchApi"; const INITIAL_LOG_HEIGHT = "50%"; @@ -44,7 +45,7 @@ export function ProjectLogPanel () { useEffect(() => { const controller = new AbortController(); if (showLog && type !== 'none' && podName !== undefined) { - const f = KaravanApi.fetchData(type, podName, controller).then(value => { + const f = LogWatchApi.fetchData(type, podName, controller).then(value => { console.log("Fetch Started for: " + podName) }); console.log("new fetch")