Skip to content

Commit

Permalink
Merge pull request #2437 from codefori/fix/componentStateGetNewLibl
Browse files Browse the repository at this point in the history
Correctly check GetNewLibl component state
  • Loading branch information
sebjulliand authored Jan 7, 2025
2 parents ae2c38f + abb7741 commit 672d13d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 32 deletions.
9 changes: 0 additions & 9 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
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");
}
}

0 comments on commit 672d13d

Please sign in to comment.