Skip to content
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

Correctly check GetNewLibl component state #2437

Merged
merged 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 1 addition & 10 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IBMiComponent } from "../components/component";
import { CopyToImport } from "../components/copyToImport";
import { CustomQSh } from '../components/cqsh';
import { ComponentManager } from "../components/manager";
import { CommandData, CommandResult, ConnectionData, IBMiMember, RemoteCommand, SpecialAuthorities, WrapResult } from "../typings";
import { CommandData, CommandResult, ConnectionData, IBMiMember, RemoteCommand, WrapResult } from "../typings";
import { CompileTools } from "./CompileTools";
import { ConnectionConfiguration } from "./Configuration";
import IBMiContent from "./IBMiContent";
Expand Down Expand Up @@ -408,15 +408,6 @@ export default class IBMi {
message: `Checking installed components on host IBM i.`
});

// We need to check if our remote programs are installed.
remoteApps.push(
{
path: `/QSYS.lib/${this.upperCaseName(this.config.tempLibrary)}.lib/`,
names: [`GETNEWLIBL.PGM`],
specific: `GE*.PGM`
}
);

//Next, we see what pase features are available (installed via yum)
//This may enable certain features in the future.
for (const feature of remoteApps) {
Expand Down
3 changes: 1 addition & 2 deletions src/components/getMemberInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ export class GetMemberInfo implements IBMiComponent {
}

async update(connection: IBMi): Promise<ComponentState> {
const config = connection.config!;
return connection.withTempDirectory(async tempDir => {
const tempSourcePath = posix.join(tempDir, `getMemberInfo.sql`);
await connection.content.writeStreamfileRaw(tempSourcePath, getSource(config.tempLibrary, this.procedureName, this.currentVersion));
await connection.getContent().writeStreamfileRaw(tempSourcePath, getSource(connection.getConfig().tempLibrary, this.procedureName, this.currentVersion));
const result = await connection.runCommand({
command: `RUNSQLSTM SRCSTMF('${tempSourcePath}') COMMIT(*NONE) NAMING(*SQL)`,
cwd: `/`,
Expand Down
62 changes: 41 additions & 21 deletions src/components/getNewLibl.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,43 @@
import { posix } from "path";
import IBMi from "../api/IBMi";
import { instance } from "../instantiate";
import { ComponentState, IBMiComponent } from "./component";

export class GetNewLibl implements IBMiComponent {
static ID = "GetNewLibl";
private readonly procedureName = 'GETNEWLIBL';
private readonly currentVersion = 1;
private installedVersion = 0;

reset() {
this.installedVersion = 0;
}

getIdentification() {
return { name: GetNewLibl.ID, version: 1 };
return { name: GetNewLibl.ID, version: this.installedVersion };
}

async getRemoteState(connection: IBMi): Promise<ComponentState> {
return connection.remoteFeatures[`GETNEWLIBL.PGM`] ? `Installed` : `NotInstalled`;
const [result] = await connection.runSQL(`select cast(LONG_COMMENT as VarChar(200)) LONG_COMMENT from qsys2.sysprocs where routine_schema = '${connection.getConfig().tempLibrary.toUpperCase()}' and routine_name = '${this.procedureName}'`);
if (result?.LONG_COMMENT) {
const comment = result.LONG_COMMENT as string;
const dash = comment.indexOf('-');
if (dash > -1) {
this.installedVersion = Number(comment.substring(0, dash).trim());
}
}
if (this.installedVersion < this.currentVersion) {
return `NeedsUpdate`;
}

return `Installed`;
}

update(connection: IBMi): Promise<ComponentState> {
const config = connection.config!
const content = instance.getContent();
return connection.withTempDirectory(async (tempDir): Promise<ComponentState> => {
const tempSourcePath = posix.join(tempDir, `getnewlibl.sql`);

await content!.writeStreamfileRaw(tempSourcePath, getSource(config.tempLibrary));
await connection.getContent().writeStreamfileRaw(tempSourcePath, this.getSource(config.tempLibrary));
const result = await connection.runCommand({
command: `RUNSQLSTM SRCSTMF('${tempSourcePath}') COMMIT(*NONE) NAMING(*SQL)`,
cwd: `/`,
Expand All @@ -36,7 +54,7 @@ export class GetNewLibl implements IBMiComponent {

async getLibraryListFromCommand(connection: IBMi, ileCommand: string) {
const tempLib = connection.config!.tempLibrary;
const resultSet = await connection.runSQL(`CALL ${tempLib}.GETNEWLIBL('${ileCommand.replace(new RegExp(`'`, 'g'), `''`)}')`);
const resultSet = await connection.runSQL(`CALL ${tempLib}.${this.procedureName}('${ileCommand.replace(new RegExp(`'`, 'g'), `''`)}')`);

const result = {
currentLibrary: `QGPL`,
Expand All @@ -57,20 +75,22 @@ export class GetNewLibl implements IBMiComponent {

return result;
}
}

function getSource(library: string) {
return Buffer.from([
`CREATE OR REPLACE PROCEDURE ${library}.GETNEWLIBL(IN COMMAND VARCHAR(2000))`,
`DYNAMIC RESULT SETS 1 `,
`BEGIN`,
` DECLARE clibl CURSOR FOR `,
` SELECT ORDINAL_POSITION, TYPE as PORTION, SYSTEM_SCHEMA_NAME`,
` FROM QSYS2.LIBRARY_LIST_INFO;`,
` CALL QSYS2.QCMDEXC(COMMAND);`,
` OPEN clibl;`,
`END;`,
``,
`call QSYS2.QCMDEXC( 'grtobjaut ${library}/GETNEWLIBL *PGM *PUBLIC *ALL' );`
].join(`\n`), "utf8");
private getSource(library: string) {
return Buffer.from([
`CREATE OR REPLACE PROCEDURE ${library}.${this.procedureName}(IN COMMAND VARCHAR(2000))`,
`DYNAMIC RESULT SETS 1 `,
`BEGIN`,
` DECLARE clibl CURSOR FOR `,
` SELECT ORDINAL_POSITION, TYPE as PORTION, SYSTEM_SCHEMA_NAME`,
` FROM QSYS2.LIBRARY_LIST_INFO;`,
` CALL QSYS2.QCMDEXC(COMMAND);`,
` OPEN clibl;`,
`END;`,
``,
`comment on procedure ${library}.${this.procedureName} is '${this.currentVersion} - Validate member information';`,
``,
`call QSYS2.QCMDEXC( 'grtobjaut ${library}/${this.procedureName} *PGM *PUBLIC *ALL' );`
].join(`\n`), "utf8");
}
}
Loading