-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from celonis/TA-2747-listing-across-flavors-c…
…ommands [TA-2747] Command for listing active packages across flavors
- Loading branch information
Showing
13 changed files
with
450 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {PackageExportTransport} from "../interfaces/package-export-transport"; | ||
import {httpClientV2} from "../services/http-client-service.v2"; | ||
import {FatalError} from "../util/logger"; | ||
|
||
class BatchImportExportApi { | ||
public static readonly INSTANCE = new BatchImportExportApi(); | ||
|
||
public findAllActivePackages(flavors: string[], withDependencies: boolean = false): Promise<PackageExportTransport[]> { | ||
const queryParams = new URLSearchParams(); | ||
|
||
queryParams.set("withDependencies", withDependencies.toString()); | ||
flavors.forEach(flavor => queryParams.append("flavors", flavor)) | ||
|
||
return httpClientV2.get(`/package-manager/api/core/packages/export/list?${queryParams.toString()}`).catch(e => { | ||
throw new FatalError(`Problem getting active packages: ${e}`); | ||
}); | ||
} | ||
|
||
public findActivePackagesByKeys(packageKeys: string[], withDependencies: boolean = false): Promise<PackageExportTransport[]> { | ||
const queryParams = new URLSearchParams(); | ||
|
||
packageKeys.forEach(key => queryParams.append("packageKeys", key)) | ||
queryParams.set("withDependencies", withDependencies.toString()); | ||
|
||
return httpClientV2.get(`/package-manager/api/core/packages/export/list-by-keys?${queryParams.toString()}`).catch(e => { | ||
throw new FatalError(`Problem getting active packages by keys: ${e}`); | ||
}); | ||
} | ||
} | ||
|
||
export const batchImportExportApi = BatchImportExportApi.INSTANCE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {batchImportExportService} from "../services/package-manager/batch-import-export-service"; | ||
|
||
export class ConfigCommand { | ||
|
||
public async listActivePackages(jsonResponse: boolean, flavors: string[], withDependencies: boolean, packageKeys:string[]): Promise<void> { | ||
if (jsonResponse) { | ||
await batchImportExportService.findAndExportListOfActivePackages(flavors ?? [], packageKeys ?? [], withDependencies) | ||
} else { | ||
await batchImportExportService.listActivePackages(flavors ?? []); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import {ConfigCommand} from "./commands/config.command"; | ||
import commander = require("commander"); | ||
import {logger} from "./util/logger"; | ||
import {ContextInitializer} from "./util/context-initializer"; | ||
|
||
type CommanderStatic = commander.CommanderStatic; | ||
|
||
export class Config { | ||
public static list(program: CommanderStatic): CommanderStatic { | ||
program | ||
.command("list") | ||
.description("Command to list active packages that can be exported") | ||
.option("-p, --profile <profile>", "Profile which you want to use to list possible variable assignments") | ||
.option("--json", "Return response as json type", "") | ||
.option("--flavors <flavors...>", "Lists only active packages of the given flavors") | ||
.option("--withDependencies", "Include dependencies", "") | ||
.option("--packageKeys <packageKeys...>", "Lists only given package keys") | ||
.action(async cmd => { | ||
await new ConfigCommand().listActivePackages(cmd.json, cmd.flavors, cmd.withDependencies, cmd.packageKeys); | ||
process.exit(); | ||
}); | ||
|
||
return program; | ||
} | ||
} | ||
|
||
process.on("unhandledRejection", (e, promise) => { | ||
logger.error(e.toString()); | ||
}); | ||
|
||
const loadAllCommands = () => { | ||
Config.list(commander); | ||
commander.parse(process.argv); | ||
}; | ||
|
||
ContextInitializer.initContext() | ||
.then(loadAllCommands) | ||
.catch(e => { | ||
logger.error(e); | ||
}); | ||
|
||
if (!process.argv.slice(2).length) { | ||
commander.outputHelp(); | ||
process.exit(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import {StudioComputeNodeDescriptor} from "./package-manager.interfaces"; | ||
|
||
export interface DependencyTransport { | ||
key: string; | ||
version: string; | ||
} | ||
|
||
export interface PackageExportTransport { | ||
id: string; | ||
key: string; | ||
name: string; | ||
changeDate: string; | ||
activatedDraftId: string; | ||
workingDraftId: string; | ||
flavor: string; | ||
version: string; | ||
dependencies: DependencyTransport[]; | ||
spaceId?: string; | ||
datamodels?: StudioComputeNodeDescriptor[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/services/package-manager/batch-import-export-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {batchImportExportApi} from "../../api/batch-import-export-api"; | ||
import {logger} from "../../util/logger"; | ||
import {v4 as uuidv4} from "uuid"; | ||
import {PackageExportTransport} from "../../interfaces/package-export-transport"; | ||
import {FileService, fileService} from "../file-service"; | ||
import {studioService} from "../studio/studio.service"; | ||
|
||
class BatchImportExportService { | ||
|
||
public async listActivePackages(flavors: string[]): Promise<void> { | ||
const activePackages = await batchImportExportApi.findAllActivePackages(flavors); | ||
activePackages.forEach(pkg => { | ||
logger.info(`${pkg.name} - Key: "${pkg.key}"`) | ||
}); | ||
} | ||
|
||
public async findAndExportListOfActivePackages(flavors: string[], packageKeys: string[], withDependencies: boolean): Promise<void> { | ||
let packagesToExport: PackageExportTransport[]; | ||
|
||
if (packageKeys.length) { | ||
packagesToExport = await batchImportExportApi.findActivePackagesByKeys(packageKeys, withDependencies); | ||
} else { | ||
packagesToExport = await batchImportExportApi.findAllActivePackages(flavors, withDependencies); | ||
} | ||
|
||
packagesToExport = await studioService.getExportPackagesWithStudioData(packagesToExport, withDependencies); | ||
|
||
this.exportListOfPackages(packagesToExport); | ||
} | ||
|
||
private exportListOfPackages(packages: PackageExportTransport[]): void { | ||
const filename = uuidv4() + ".json"; | ||
fileService.writeToFileWithGivenName(JSON.stringify(packages), filename); | ||
logger.info(FileService.fileDownloadedMessage + filename); | ||
} | ||
} | ||
|
||
export const batchImportExportService = new BatchImportExportService(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import {PackageExportTransport} from "../../interfaces/package-export-transport"; | ||
import {packageApi} from "../../api/package-api"; | ||
import { | ||
PackageManagerVariableType, | ||
PackageWithVariableAssignments, | ||
StudioComputeNodeDescriptor | ||
} from "../../interfaces/package-manager.interfaces"; | ||
import {dataModelService} from "../package-manager/datamodel-service"; | ||
|
||
class StudioService { | ||
|
||
public async getExportPackagesWithStudioData(packagesToExport: PackageExportTransport[], withDependencies: boolean): Promise<PackageExportTransport[]> { | ||
const studioPackagesWithDataModels = await packageApi.findAllPackagesWithVariableAssignments(PackageManagerVariableType.DATA_MODEL); | ||
|
||
packagesToExport = studioService.setSpaceIdForStudioPackages(packagesToExport, studioPackagesWithDataModels); | ||
|
||
if (withDependencies) { | ||
const dataModelDetailsByNode = await dataModelService.getDataModelDetailsForPackages(studioPackagesWithDataModels); | ||
packagesToExport = studioService.setDataModelsForStudioPackages(packagesToExport, studioPackagesWithDataModels, dataModelDetailsByNode); | ||
} | ||
|
||
return packagesToExport; | ||
} | ||
|
||
private setSpaceIdForStudioPackages(packages: PackageExportTransport[], studioPackages: PackageWithVariableAssignments[]): PackageExportTransport[] { | ||
const studioPackageByKey = new Map<string, PackageWithVariableAssignments>(); | ||
studioPackages.forEach(pkg => studioPackageByKey.set(pkg.key, pkg)); | ||
|
||
return packages.map(pkg => { | ||
return studioPackageByKey.has(pkg.key) ? { | ||
...pkg, | ||
spaceId: studioPackageByKey.get(pkg.key).spaceId | ||
} : pkg; | ||
}); | ||
} | ||
|
||
private setDataModelsForStudioPackages(packages: PackageExportTransport[], | ||
studioPackageWithDataModels: PackageWithVariableAssignments[], | ||
dataModelDetailsByNode: Map<string, StudioComputeNodeDescriptor[]>): PackageExportTransport[] { | ||
const studioPackageByKey = new Map<string, PackageWithVariableAssignments>(); | ||
studioPackageWithDataModels.forEach(pkg => studioPackageByKey.set(pkg.key, pkg)); | ||
|
||
return packages.map(pkg => { | ||
return studioPackageByKey.has(pkg.key) ? { | ||
...pkg, | ||
datamodels: dataModelDetailsByNode.get(pkg.key) | ||
.map(dataModel => ({ | ||
name: dataModel.name, | ||
poolId: dataModel.poolId, | ||
dataModelId: dataModel.dataModelId | ||
})) | ||
} : pkg; | ||
}); | ||
} | ||
} | ||
|
||
export const studioService = new StudioService(); |
Oops, something went wrong.