-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace odo analyze command #4330
Merged
datho7561
merged 17 commits into
redhat-developer:main
from
msivasubramaniaan:added-alizer-analyze-command
Aug 16, 2024
Merged
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
3f34d5c
chaged the image path and removed (formerly Red Hat CodeReady Contain…
msivasubramaniaan 23e0616
removed odo analyze command
msivasubramaniaan 1b01f49
Merge branch 'main' into added-alizer-analyze-command
msivasubramaniaan 6338174
addressed review comments
msivasubramaniaan 8a9264e
added alizer test
msivasubramaniaan f8dcc69
fixed no-unused-vars error
msivasubramaniaan 71031a3
fixed no-unused-vars error
msivasubramaniaan 265507d
fixed no-unused-vars error
msivasubramaniaan e42fd0c
fixed no-unused-vars error
msivasubramaniaan 3be7b53
fixed no-unused-vars error
msivasubramaniaan c614dd5
fixed no-unused-vars error
msivasubramaniaan 6a3ca0b
fixed test case fails
msivasubramaniaan e105c2d
added deleteComponentConfiguration
msivasubramaniaan ddbb56b
fixed mapping component description
msivasubramaniaan f57469b
Merge branch 'main' into added-alizer-analyze-command
msivasubramaniaan c82fa22
addressed review comments
msivasubramaniaan 7b2a13b
addressed review comments
msivasubramaniaan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,35 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
import { CommandText } from '../base/command'; | ||
import { CliChannel } from '../cli'; | ||
import { Uri } from 'vscode'; | ||
import { CliExitData } from '../util/childProcessUtil'; | ||
import { AlizerAnalyzeResponse } from './types'; | ||
|
||
/** | ||
* A wrapper around the `alizer` CLI tool. | ||
* | ||
* This class is a stateless singleton. | ||
* This makes it easier to stub its methods than if it were a bunch of directly exported functions. | ||
*/ | ||
export class Alizer { | ||
private static INSTANCE = new Alizer(); | ||
|
||
static get Instance() { | ||
return Alizer.INSTANCE; | ||
} | ||
|
||
public async alizerAnalyze(currentFolderPath: Uri): Promise<AlizerAnalyzeResponse> { | ||
const cliData: CliExitData = await CliChannel.getInstance().executeTool( | ||
new CommandText('alizer', `devfile ${currentFolderPath.fsPath}`), undefined, false | ||
); | ||
if (cliData.error || cliData.stderr.length > 0) { | ||
return undefined; | ||
} | ||
const parse = JSON.parse(cliData.stdout) as AlizerAnalyzeResponse[]; | ||
return parse[0]; | ||
} | ||
} |
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,19 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
|
||
|
||
interface Version { | ||
SchemaVersion: number; | ||
Default: boolean; | ||
Version: string; | ||
} | ||
|
||
export interface AlizerAnalyzeResponse { | ||
Name: string; | ||
Language: string; | ||
ProjectType: string; | ||
Tags: string[]; | ||
Versions: Version[]; | ||
} |
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
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
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,144 @@ | ||
/*----------------------------------------------------------------------------------------------- | ||
* Copyright (c) Red Hat, Inc. All rights reserved. | ||
* Licensed under the MIT License. See LICENSE file in the project root for license information. | ||
*-----------------------------------------------------------------------------------------------*/ | ||
import { fail } from 'assert'; | ||
import { expect } from 'chai'; | ||
import * as fs from 'fs/promises'; | ||
import { suite, suiteSetup } from 'mocha'; | ||
import * as tmp from 'tmp'; | ||
import * as path from 'path'; | ||
import { promisify } from 'util'; | ||
import { Uri, workspace } from 'vscode'; | ||
import { Oc } from '../../src/oc/ocWrapper'; | ||
import { Odo } from '../../src/odo/odoWrapper'; | ||
import { LoginUtil } from '../../src/util/loginUtil'; | ||
import { Alizer } from '../../src/alizer/alizerWrapper'; | ||
|
||
suite('./alizer/alizerWrapper.ts', function () { | ||
const isOpenShift: boolean = Boolean(parseInt(process.env.IS_OPENSHIFT, 10)) || false; | ||
const clusterUrl = process.env.CLUSTER_URL || 'https://api.crc.testing:6443'; | ||
const username = process.env.CLUSTER_USER || 'developer'; | ||
const password = process.env.CLUSTER_PASSWORD || 'developer'; | ||
|
||
suiteSetup(async function () { | ||
if (isOpenShift) { | ||
try { | ||
await LoginUtil.Instance.logout(); | ||
} catch { | ||
// do nothing | ||
} | ||
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password); | ||
} | ||
}); | ||
|
||
suiteTeardown(async function () { | ||
// ensure projects are cleaned up | ||
try { | ||
await Oc.Instance.deleteProject('my-test-project-1'); | ||
} catch { | ||
// do nothing | ||
} | ||
try { | ||
await Oc.Instance.deleteProject('my-test-project-2'); | ||
} catch { | ||
// do nothing | ||
} | ||
|
||
if (isOpenShift) { | ||
await LoginUtil.Instance.logout(); | ||
} | ||
}); | ||
|
||
suite('analyse folder', function () { | ||
const project1 = 'my-test-project-1'; | ||
|
||
let tmpFolder1: Uri; | ||
let tmpFolder2: Uri; | ||
|
||
suiteSetup(async function () { | ||
await Oc.Instance.createProject(project1); | ||
tmpFolder1 = Uri.parse(await promisify(tmp.dir)()); | ||
tmpFolder2 = Uri.parse(await promisify(tmp.dir)()); | ||
await Odo.Instance.createComponentFromFolder( | ||
'nodejs', | ||
undefined, | ||
'component1', | ||
tmpFolder1, | ||
'nodejs-starter', | ||
); | ||
await Odo.Instance.createComponentFromFolder( | ||
'go', | ||
undefined, | ||
'component2', | ||
tmpFolder2, | ||
'go-starter', | ||
); | ||
}); | ||
|
||
suiteTeardown(async function () { | ||
if (isOpenShift) { | ||
await Oc.Instance.loginWithUsernamePassword(clusterUrl, username, password); | ||
} | ||
const newWorkspaceFolders = workspace.workspaceFolders.filter((workspaceFolder) => { | ||
const fsPath = workspaceFolder.uri.fsPath; | ||
return (fsPath !== tmpFolder1.fsPath && fsPath !== tmpFolder2.fsPath); | ||
}); | ||
workspace.updateWorkspaceFolders(0, workspace.workspaceFolders.length, ...newWorkspaceFolders); | ||
await fs.rm(tmpFolder1.fsPath, { force: true, recursive: true }); | ||
await fs.rm(tmpFolder2.fsPath, { force: true, recursive: true }); | ||
await Oc.Instance.deleteProject(project1); | ||
}); | ||
|
||
test('analyze()', async function () { | ||
const analysis1 = await Alizer.Instance.alizerAnalyze(tmpFolder1); | ||
expect(analysis1).to.exist; | ||
expect(analysis1.Name).to.equal('nodejs'); | ||
const analysis2 = await Alizer.Instance.alizerAnalyze(tmpFolder2); | ||
expect(analysis2).to.exist; | ||
expect(analysis2.Name).to.equal('go'); | ||
}); | ||
}); | ||
|
||
suite('create component', function() { | ||
|
||
const COMPONENT_TYPE = 'dotnet50'; | ||
|
||
let tmpFolder: string; | ||
|
||
suiteSetup(async function() { | ||
tmpFolder = await promisify(tmp.dir)(); | ||
}); | ||
|
||
suiteTeardown(async function() { | ||
await fs.rm(tmpFolder, { recursive: true, force: true }); | ||
}); | ||
|
||
test('createComponentFromTemplateProject()', async function() { | ||
await Odo.Instance.createComponentFromTemplateProject(tmpFolder, 'my-component', 8080, COMPONENT_TYPE, 'DefaultDevfileRegistry', 'dotnet50-example'); | ||
try { | ||
await fs.access(path.join(tmpFolder, 'devfile.yaml')); | ||
} catch { | ||
fail('Expected devfile to be created'); | ||
} | ||
}); | ||
|
||
test('analyze()', async function() { | ||
const analysis = await Alizer.Instance.alizerAnalyze(Uri.file(tmpFolder)); | ||
expect(analysis.Name).to.equal(COMPONENT_TYPE); | ||
}); | ||
|
||
test('deleteComponentConfiguration()', async function() { | ||
datho7561 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await Odo.Instance.deleteComponentConfiguration(tmpFolder); | ||
try { | ||
await fs.access(path.join(tmpFolder, 'devfile.yaml')); | ||
fail('devfile.yaml should have been deleted') | ||
} catch { | ||
// deleted successfully | ||
} | ||
}); | ||
|
||
}); | ||
|
||
test('deleteComponentConfiguration'); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the same as
If you find the first version easier to understand feel free to keep it, but I personally tend to prefer the second version.