in plugins/toolkit/jetbrains-gateway/src/software/aws/toolkits/jetbrains/gateway/CawsConnectorViewPanels.kt [123:229]
override fun onMultistagePanelDone(context: CawsSettings) {
val productType = context.productType ?: throw RuntimeException("CAWS wizard finished but productType was not set")
val connectionSettings = context.connectionSettings ?: throw RuntimeException("CAWS wizard finished but connectionSettings was not set")
lifetime.startWithModalProgressAsync(
owner = ModalTaskOwner.guess(),
title = message("caws.creating_workspace"),
cancellation = TaskCancellation.nonCancellable()
) {
val userId = lazilyGetUserId()
val start = System.currentTimeMillis()
val env = try {
val cawsClient = connectionSettings.awsClient<CodeCatalystClient>()
if (context.cloneType == CawsWizardCloneType.UNLINKED_3P) {
error("Not implemented")
}
if (context.is3P) {
context.branchCloneType = BranchCloneType.EXISTING
}
if (context.branchCloneType == BranchCloneType.NEW_FROM_EXISTING) {
indeterminateStep(message("caws.creating_branch")) {
cawsClient.createSourceRepositoryBranch {
val project = context.project ?: throw RuntimeException("project was null")
val commitId = context.linkedRepoBranch?.headCommitId ?: throw RuntimeException("source commit id was not defined")
it.spaceName(project.space)
it.projectName(project.project)
it.sourceRepositoryName(context.linkedRepoName)
it.name(context.createBranchName)
it.headCommitId(commitId)
}
}
}
IdeBackendActions.createWorkspace(cawsClient, context).also {
val repoType = when (context.cloneType) {
CawsWizardCloneType.CAWS -> CodecatalystCreateDevEnvironmentRepoType.Linked
CawsWizardCloneType.UNLINKED_3P -> CodecatalystCreateDevEnvironmentRepoType.Unlinked
CawsWizardCloneType.NONE -> CodecatalystCreateDevEnvironmentRepoType.None
}
CodecatalystTelemetry.devEnvironmentWorkflowStatistic(
project = null,
userId = userId,
result = TelemetryResult.Succeeded,
duration = (System.currentTimeMillis() - start).toDouble(),
codecatalystDevEnvironmentWorkflowStep = "createDevEnvironment"
)
CodecatalystTelemetry.createDevEnvironment(
project = null,
userId = userId,
codecatalystCreateDevEnvironmentRepoType = repoType,
result = TelemetryResult.Succeeded
)
}
} catch (e: Exception) {
val message = message("caws.workspace.creation.failed")
getLogger<CawsInstanceSetupPanel>().error(e) { message }
withUiContext {
Messages.showErrorDialog(e.message ?: message("general.unknown_error"), message)
}
CodecatalystTelemetry.devEnvironmentWorkflowStatistic(
project = null,
userId = userId,
result = TelemetryResult.Failed,
duration = (System.currentTimeMillis() - start).toDouble(),
codecatalystDevEnvironmentWorkflowStep = "createDevEnvironment"
)
CodecatalystTelemetry.createDevEnvironment(project = null, userId = userId, result = TelemetryResult.Failed)
return@startWithModalProgressAsync
}
val currentConnection = service<ToolkitConnectionManager>()
.activeConnectionForFeature(CodeCatalystConnection.getInstance()) as AwsBearerTokenConnection?
?: error("Connection cannot be null")
val parameters = mapOf(
CawsConnectionParameters.CAWS_SPACE to env.identifier.project.space,
CawsConnectionParameters.CAWS_PROJECT to env.identifier.project.project,
CawsConnectionParameters.CAWS_ENV_ID to env.identifier.id,
CawsConnectionParameters.DEV_SETTING_USE_BUNDLED_TOOLKIT to context.useBundledToolkit.toString(),
CawsConnectionParameters.DEV_SETTING_S3_STAGING to context.s3StagingBucket,
CawsConnectionParameters.DEV_SETTING_TOOLKIT_PATH to context.toolkitLocation,
CawsConnectionParameters.SSO_START_URL to currentConnection.startUrl,
CawsConnectionParameters.SSO_REGION to currentConnection.region
) + buildMap {
when (context.cloneType) {
CawsWizardCloneType.CAWS -> {
val repoName = context.linkedRepoName ?: throw RuntimeException("CAWS wizard finished but linkedRepoName was not set")
put(CawsConnectionParameters.CAWS_GIT_REPO_NAME, repoName)
}
CawsWizardCloneType.UNLINKED_3P -> {
val branch = context.unlinkedRepoBranch ?: throw RuntimeException("CAWS wizard finished but unlinkedRepoBranch was not set")
put(CawsConnectionParameters.CAWS_UNLINKED_GIT_REPO_URL, context.unlinkedRepoUrl)
put(CawsConnectionParameters.CAWS_UNLINKED_GIT_REPO_BRANCH, branch)
}
CawsWizardCloneType.NONE -> {}
}
}
withUiContext {
GatewayUI.getInstance().connect(parameters)
}
}
}