mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-26 07:26:58 +00:00
Changes to reset container workflow (#1155)
* reset changes * undid config context changes * renamed method
This commit is contained in:
parent
e3d5ad2ce8
commit
5597a1e8b6
@ -394,7 +394,7 @@ export default class Explorer {
|
|||||||
useNotebook.getState().setConnectionInfo(connectionStatus);
|
useNotebook.getState().setConnectionInfo(connectionStatus);
|
||||||
try {
|
try {
|
||||||
useNotebook.getState().setIsAllocating(true);
|
useNotebook.getState().setIsAllocating(true);
|
||||||
const connectionInfo = await this.phoenixClient.containerConnectionInfo(provisionData);
|
const connectionInfo = await this.phoenixClient.allocateContainer(provisionData);
|
||||||
await this.setNotebookInfo(connectionInfo, connectionStatus);
|
await this.setNotebookInfo(connectionInfo, connectionStatus);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
connectionStatus.status = ConnectionStatusType.Failed;
|
connectionStatus.status = ConnectionStatusType.Failed;
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
import { PhoenixClient } from "Phoenix/PhoenixClient";
|
import { PhoenixClient } from "Phoenix/PhoenixClient";
|
||||||
import * as Constants from "../../Common/Constants";
|
import * as Constants from "../../Common/Constants";
|
||||||
import { ConnectionStatusType, HttpHeaders, HttpStatusCodes } from "../../Common/Constants";
|
import { ConnectionStatusType, HttpHeaders } from "../../Common/Constants";
|
||||||
import { getErrorMessage } from "../../Common/ErrorHandlingUtils";
|
import { getErrorMessage } from "../../Common/ErrorHandlingUtils";
|
||||||
import * as Logger from "../../Common/Logger";
|
import * as Logger from "../../Common/Logger";
|
||||||
import * as DataModels from "../../Contracts/DataModels";
|
import * as DataModels from "../../Contracts/DataModels";
|
||||||
@ -23,8 +23,10 @@ import { useNotebook } from "./useNotebook";
|
|||||||
export class NotebookContainerClient {
|
export class NotebookContainerClient {
|
||||||
private clearReconnectionAttemptMessage? = () => {};
|
private clearReconnectionAttemptMessage? = () => {};
|
||||||
private isResettingWorkspace: boolean;
|
private isResettingWorkspace: boolean;
|
||||||
|
private phoenixClient: PhoenixClient;
|
||||||
|
|
||||||
constructor(private onConnectionLost: () => void) {
|
constructor(private onConnectionLost: () => void) {
|
||||||
|
this.phoenixClient = new PhoenixClient();
|
||||||
const notebookServerInfo = useNotebook.getState().notebookServerInfo;
|
const notebookServerInfo = useNotebook.getState().notebookServerInfo;
|
||||||
if (notebookServerInfo?.notebookServerEndpoint) {
|
if (notebookServerInfo?.notebookServerEndpoint) {
|
||||||
this.scheduleHeartbeat(Constants.Notebook.heartbeatDelayMs);
|
this.scheduleHeartbeat(Constants.Notebook.heartbeatDelayMs);
|
||||||
@ -143,10 +145,7 @@ export class NotebookContainerClient {
|
|||||||
return Promise.reject(error);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { notebookServerEndpoint, authToken } = this.getNotebookServerConfig();
|
|
||||||
try {
|
try {
|
||||||
let data: IPhoenixConnectionInfoResult;
|
|
||||||
let response: Response;
|
|
||||||
if (NotebookUtil.isPhoenixEnabled()) {
|
if (NotebookUtil.isPhoenixEnabled()) {
|
||||||
const provisionData: IProvisionData = {
|
const provisionData: IProvisionData = {
|
||||||
aadToken: userContext.authorizationToken,
|
aadToken: userContext.authorizationToken,
|
||||||
@ -155,24 +154,9 @@ export class NotebookContainerClient {
|
|||||||
dbAccountName: userContext.databaseAccount.name,
|
dbAccountName: userContext.databaseAccount.name,
|
||||||
cosmosEndpoint: userContext.databaseAccount.properties.documentEndpoint,
|
cosmosEndpoint: userContext.databaseAccount.properties.documentEndpoint,
|
||||||
};
|
};
|
||||||
response = await fetch(`${PhoenixClient.getPhoenixEndpoint()}/api/controlplane/toolscontainer/reset`, {
|
return await this.phoenixClient.resetContainer(provisionData);
|
||||||
method: "POST",
|
|
||||||
headers: this.getHeaders(),
|
|
||||||
body: JSON.stringify(provisionData),
|
|
||||||
});
|
|
||||||
if (response.status === HttpStatusCodes.OK) {
|
|
||||||
data = await response.json();
|
|
||||||
}
|
}
|
||||||
} else {
|
return null;
|
||||||
response = await fetch(`${notebookServerEndpoint}/api/shutdown`, {
|
|
||||||
method: "POST",
|
|
||||||
headers: { Authorization: authToken },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
status: response.status,
|
|
||||||
data,
|
|
||||||
};
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.logError(getErrorMessage(error), "NotebookContainerClient/resetWorkspace");
|
Logger.logError(getErrorMessage(error), "NotebookContainerClient/resetWorkspace");
|
||||||
if (!NotebookUtil.isPhoenixEnabled()) {
|
if (!NotebookUtil.isPhoenixEnabled()) {
|
||||||
|
@ -14,15 +14,27 @@ import { userContext } from "../UserContext";
|
|||||||
import { getAuthorizationHeader } from "../Utils/AuthorizationUtils";
|
import { getAuthorizationHeader } from "../Utils/AuthorizationUtils";
|
||||||
|
|
||||||
export class PhoenixClient {
|
export class PhoenixClient {
|
||||||
public async containerConnectionInfo(
|
private containerHealthHandler: NodeJS.Timeout;
|
||||||
provisionData: IProvisionData
|
|
||||||
|
public async allocateContainer(provisionData: IProvisionData): Promise<IResponse<IPhoenixConnectionInfoResult>> {
|
||||||
|
return this.executeContainerAssignmentOperation(provisionData, "allocate");
|
||||||
|
}
|
||||||
|
|
||||||
|
public async resetContainer(provisionData: IProvisionData): Promise<IResponse<IPhoenixConnectionInfoResult>> {
|
||||||
|
return this.executeContainerAssignmentOperation(provisionData, "reset");
|
||||||
|
}
|
||||||
|
|
||||||
|
private async executeContainerAssignmentOperation(
|
||||||
|
provisionData: IProvisionData,
|
||||||
|
operation: string
|
||||||
): Promise<IResponse<IPhoenixConnectionInfoResult>> {
|
): Promise<IResponse<IPhoenixConnectionInfoResult>> {
|
||||||
try {
|
try {
|
||||||
const response = await window.fetch(`${this.getPhoenixContainerPoolingEndPoint()}/allocate`, {
|
const response = await fetch(`${this.getPhoenixContainerPoolingEndPoint()}/${operation}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: PhoenixClient.getHeaders(),
|
headers: PhoenixClient.getHeaders(),
|
||||||
body: JSON.stringify(provisionData),
|
body: JSON.stringify(provisionData),
|
||||||
});
|
});
|
||||||
|
|
||||||
let data: IPhoenixConnectionInfoResult;
|
let data: IPhoenixConnectionInfoResult;
|
||||||
if (response.status === HttpStatusCodes.OK) {
|
if (response.status === HttpStatusCodes.OK) {
|
||||||
data = await response.json();
|
data = await response.json();
|
||||||
@ -38,12 +50,15 @@ export class PhoenixClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async initiateContainerHeartBeat(containerData: { forwardingId: string; dbAccountName: string }) {
|
public async initiateContainerHeartBeat(containerData: { forwardingId: string; dbAccountName: string }) {
|
||||||
this.getContainerHealth(Notebook.containerStatusHeartbeatDelayMs, containerData);
|
if (this.containerHealthHandler) {
|
||||||
|
clearTimeout(this.containerHealthHandler);
|
||||||
|
}
|
||||||
|
await this.getContainerHealth(Notebook.containerStatusHeartbeatDelayMs, containerData);
|
||||||
}
|
}
|
||||||
|
|
||||||
private scheduleContainerHeartbeat(delayMs: number, containerData: IContainerData): void {
|
private scheduleContainerHeartbeat(delayMs: number, containerData: IContainerData): void {
|
||||||
setTimeout(() => {
|
this.containerHealthHandler = setTimeout(async () => {
|
||||||
this.getContainerHealth(delayMs, containerData);
|
await this.getContainerHealth(delayMs, containerData);
|
||||||
}, delayMs);
|
}, delayMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,14 +94,12 @@ export class PhoenixClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getContainerHealth(delayMs: number, containerData: { forwardingId: string; dbAccountName: string }) {
|
private async getContainerHealth(delayMs: number, containerData: { forwardingId: string; dbAccountName: string }) {
|
||||||
this.getContainerStatusAsync(containerData)
|
const containerInfo = await this.getContainerStatusAsync(containerData);
|
||||||
.then((ContainerInfo) => useNotebook.getState().setContainerStatus(ContainerInfo))
|
useNotebook.getState().setContainerStatus(containerInfo);
|
||||||
.finally(() => {
|
|
||||||
if (useNotebook.getState().containerStatus?.status === ContainerStatusType.Active) {
|
if (useNotebook.getState().containerStatus?.status === ContainerStatusType.Active) {
|
||||||
this.scheduleContainerHeartbeat(delayMs, containerData);
|
this.scheduleContainerHeartbeat(delayMs, containerData);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static getPhoenixEndpoint(): string {
|
public static getPhoenixEndpoint(): string {
|
||||||
@ -104,6 +117,7 @@ export class PhoenixClient {
|
|||||||
public getPhoenixContainerPoolingEndPoint(): string {
|
public getPhoenixContainerPoolingEndPoint(): string {
|
||||||
return `${PhoenixClient.getPhoenixEndpoint()}/api/controlplane/toolscontainer`;
|
return `${PhoenixClient.getPhoenixEndpoint()}/api/controlplane/toolscontainer`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static getHeaders(): HeadersInit {
|
private static getHeaders(): HeadersInit {
|
||||||
const authorizationHeader = getAuthorizationHeader();
|
const authorizationHeader = getAuthorizationHeader();
|
||||||
return {
|
return {
|
||||||
|
Loading…
Reference in New Issue
Block a user