Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { Result } from '../../shared/telemetry/telemetry'
import { StateMachineNode } from '../explorer/stepFunctionsNodes'
import { telemetry } from '../../shared/telemetry/telemetry'
import { fs } from '../../shared/fs/fs'
import { WorkflowStudioEditorProvider } from '../workflowStudio/workflowStudioEditorProvider'
import { openWorkflowStudioWithDefinition } from '../utils'

export async function downloadStateMachineDefinition(params: {
outputChannel: vscode.OutputChannel
Expand All @@ -35,16 +35,7 @@ export async function downloadStateMachineDefinition(params: {
})

if (params.isPreviewAndRender) {
const doc = await vscode.workspace.openTextDocument({
language: 'asl',
content: stateMachineDetails.definition,
})

const textEditor = await vscode.window.showTextDocument(doc)
await WorkflowStudioEditorProvider.openWithWorkflowStudio(textEditor.document.uri, {
preserveFocus: true,
viewColumn: vscode.ViewColumn.Beside,
})
await openWorkflowStudioWithDefinition(stateMachineDetails.definition)
} else {
const wsPath = vscode.workspace.workspaceFolders
? vscode.workspace.workspaceFolders[0].uri.fsPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export class ExecutionDetailProvider {
* Initializes a WebView panel with execution details.
* @param panel The WebView panel to initialize
* @param executionArn The ARN of the execution to display
* @param startTime Optional start time for the execution
*/
public async initializePanel(panel: vscode.WebviewPanel, executionArn: string, startTime?: string): Promise<void> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/

import * as nls from 'vscode-nls'
const localize = nls.loadMessageBundle()
import {
Command,
Message,
Expand All @@ -17,6 +19,12 @@ import {
handleUnsupportedMessage,
apiCallMessageHandler,
} from '../messageHandlers/handleMessageHelpers'
import { parseExecutionArnForStateMachine, openWFSfromARN } from '../utils'
import { ExecuteStateMachineWebview } from '../vue/executeStateMachine/executeStateMachine'
import { VueWebview } from '../../webviews/main'
import globals from '../../shared/extensionGlobals'
// import { ExecutionDetailProvider } from './executionDetailProvider'
// import { WorkflowStudioEditorProvider } from '../workflowStudio/workflowStudioEditorProvider'

/**
* Handles messages received from the ExecutionDetails webview. Depending on the message type and command,
Expand All @@ -34,6 +42,12 @@ export async function handleMessage(message: Message, context: ExecutionDetailsC
case Command.API_CALL:
void apiCallMessageHandler(message as ApiCallRequestMessage, context)
break
case Command.START_EXECUTION:
void startExecutionMessageHandler(context)
break
case Command.EDIT_STATE_MACHINE:
void editStateMachineMessageHandler(context)
break
default:
void handleUnsupportedMessage(context, message)
break
Expand Down Expand Up @@ -74,3 +88,24 @@ async function initMessageHandler(context: ExecutionDetailsContext) {
} as InitResponseMessage)
}
}

async function startExecutionMessageHandler(context: ExecutionDetailsContext) {
// Parsing execution ARN to get state machine info
const { region, stateMachineName, stateMachineArn } = parseExecutionArnForStateMachine(context.executionArn)

const Panel = VueWebview.compilePanel(ExecuteStateMachineWebview)
const wv = new Panel(globals.context, globals.outputChannel, {
arn: stateMachineArn,
name: stateMachineName,
region: region,
})

await wv.show({
title: localize('AWS.executeStateMachine.title', 'Start Execution'),
cssFiles: ['executeStateMachine.css'],
})
}

async function editStateMachineMessageHandler(context: ExecutionDetailsContext) {
await openWFSfromARN(context)
}
2 changes: 2 additions & 0 deletions packages/core/src/stepFunctions/messageHandlers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ export enum Command {
CLOSE_WFS = 'CLOSE_WFS',
API_CALL = 'API_CALL',
UNSUPPORTED_COMMAND = 'UNSUPPORTED_COMMAND',
START_EXECUTION = 'START_EXECUTION',
EDIT_STATE_MACHINE = 'EDIT_STATE_MACHINE',
}

export type FileWatchInfo = {
Expand Down
59 changes: 59 additions & 0 deletions packages/core/src/stepFunctions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ import {
} from 'amazon-states-language-service'
import { fromExtensionManifest } from '../shared/settings'
import { IamRole } from '../shared/clients/iam'
import { ExecutionDetailsContext } from './messageHandlers/types'
import { WorkflowStudioEditorProvider } from './workflowStudio/workflowStudioEditorProvider'

const documentSettings: DocumentLanguageSettings = { comments: 'error', trailingCommas: 'error' }
const languageService = getLanguageService({})

const arnResourceTypeSegmentIndex = 5
const expressExecutionArnSegmentCount = 9
const arnRegionSegmentIndex = 3
const arnAccountIdSegmentIndex = 4
const arnStateMachineNameSegmentIndex = 6

export async function* listStateMachines(
client: StepFunctionsClient
Expand Down Expand Up @@ -107,6 +112,60 @@ export const isExpressExecution = (arn: string): boolean => {
)
}

/**
* Parses an execution ARN to extract state machine information
* @param executionArn The execution ARN to parse
* @returns Object containing region, state machine name, and state machine ARN
*/
export const parseExecutionArnForStateMachine = (executionArn: string) => {
const arnSegments = executionArn.split(':')
const region = arnSegments[arnRegionSegmentIndex]
const stateMachineName = arnSegments[arnStateMachineNameSegmentIndex]
const stateMachineArn = `arn:aws:states:${region}:${arnSegments[arnAccountIdSegmentIndex]}:stateMachine:${stateMachineName}`

return {
region,
stateMachineName,
stateMachineArn,
}
}

/**
* Opens a state machine definition in Workflow Studio
* @param stateMachineArn The ARN of the state machine
* @param region The AWS region
*/
export const openWorkflowStudio = async (stateMachineArn: string, region: string) => {
const client: StepFunctionsClient = new StepFunctionsClient(region)
const stateMachineDetails: StepFunctions.DescribeStateMachineCommandOutput = await client.getStateMachineDetails({
stateMachineArn,
})

await openWorkflowStudioWithDefinition(stateMachineDetails.definition)
}

/**
* Opens a state machine definition in Workflow Studio using pre-fetched definition content
* @param definition The state machine definition content
*/
export const openWorkflowStudioWithDefinition = async (definition: string | undefined) => {
const doc = await vscode.workspace.openTextDocument({
language: 'asl',
content: definition,
})

const textEditor = await vscode.window.showTextDocument(doc)
await WorkflowStudioEditorProvider.openWithWorkflowStudio(textEditor.document.uri, {
preserveFocus: true,
viewColumn: vscode.ViewColumn.Beside,
})
}

export const openWFSfromARN = async (context: ExecutionDetailsContext) => {
const params = parseExecutionArnForStateMachine(context.executionArn)
await openWorkflowStudio(params.stateMachineArn, params.region)
}

const isInvalidJson = (content: string): boolean => {
try {
JSON.parse(content)
Expand Down
Loading
Loading