IBM / nodejs-itoolkit

A JavaScript (Node.js) library for communicating with IBM i
MIT License
43 stars 38 forks source link

itoolkit npm #3

Closed abmusse closed 6 years ago

abmusse commented 7 years ago

Original report by Aaron Bartell (Bitbucket: aaronbartell, GitHub: aaronbartell).


I think it would be good to create an itoolkit npm so it can be stored as a dependency and be easily obtained via npm install.

Is IBM ok with doing this? If so, I can accomplish the task if you'd like.

abmusse commented 6 years ago

Original comment by Xu Meng (Bitbucket: mengxumx, GitHub: dmabupt).


Close it because itoolkit is already a npm pacakge now

abmusse commented 7 years ago

Original comment by Danny Roessner (Bitbucket: droessner, GitHub: droessner).


Thanks for the examples Tony. I will play around with them.

I do think having itoolkit in npm and being able to reference the dependency through package.json is the much preferred way and is a crucial missing piece. Unfortunately, converting C code into a module is over my head :-(

Appreciate your work on this Aaron, definitely looking forward to more updates!

abmusse commented 7 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


The db2a module is now open sourced in the nodejs-idb-connector so do we need to ask permission?

Yes. Ask Jesse.

BTW -- Perhaps obvious, I am not a lawyer. I cannot represent any more than personal opinion (2 cents and a cup of coffee == my opinion here). I only suspect we MAY cross some kind of legal line when 'binaries' IBM built are involved. Therefore, ask Jesse 'IBM i Rochester Open Source Architect' is my answer.

abmusse commented 7 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


More of what I am talking about is the "Fat Gem" concept ...

I dunno. I have not built a npm with c code binary (if possible even).

Oh boy ... cylon.js - Creating Multiplatform Precompiled Binaries for Node.js Modules

When we compiled ruby-ibm_db I am remembering we had to compile on a v7.1 machine for it to work on v7.1+.

Oh yes, expect binary version(s) to happen (someday). That is, today, we will likely be able to compile V7R1 and 'install' forward in time db2a (one binary for all). Tomorrow, well, most likely nodejs moves toward latest and greatest of everything. However, this question belongs more with IBM China team owners.

future ... maybe db2sock "re-tool"

So, i find current db2a driver (and itoolkit) to be, well, not great, especially in 'async'. I believe this is largely due to poor function in the base PASE libdb400.a driver (no async at all). That is, this current 'interface' does not help people with the understanding and need for connection pools, etc. Also, itoolkit based on XMLSRVICE is too slow for many older IBM i applications (RPG big data). Therefore, when litmis/db2sock finally gets ready, I would suggest there MAY be another "go 'round" of db2/itoolkit interfaces.

abmusse commented 7 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Another test of Aaron's npm itoolkit with REST, but a lot more fun.

#!JavaScript

var it = require("itoolkit");
// var conn = new it.iConn("*LOCAL"); -- db2 driver required (npm install itoolkit not have one)
// Let's try REST to IBM i (XMLSERVICE)
var conn = new it.iConn("*LOCAL", "*NONE", "*NONE",
    { host : "yips.idevcloud.com", port : 80, path : "/cgi-bin/xmlcgi.pgm",
      ipc : "*na",
      ctl : "*here"});
conn.add(it.iQsh('system wrkactjob'));
conn.run(function(str) {
  console.log(str);
});
#!bash

bash-4.3$ pwd        
/home/node6/tryagain
bash-4.3$ ls
app.js
bash-4.3$ npm install itoolkit          
/home/node6/tryagain
└── itoolkit@0.1.1 

npm WARN enoent ENOENT: no such file or directory, open '/home/node6/tryagain/package.json'
npm WARN tryagain No description
npm WARN tryagain No repository field.
npm WARN tryagain No README data
npm WARN tryagain No license field.

bash-4.3$ node app.js 
<?xml version='1.0'?><myscript><qsh error='fast'>
CPD4090:  Printer device PRT01 not found. Output queue changed to QPRINT in library QGPL.
  5770SS1 V7R1M0 100423                  Work with Active Jobs                                   10/04/17 17:01:35        Page    1
  Reset . . . . . . . . . . . . . . . . . :   *NO
  Subsystems  . . . . . . . . . . . . . . :   *ALL
  CPU Percent Limit . . . . . . . . . . . :   *NONE
  Response Time Limit . . . . . . . . . . :   *NONE
  Sequence  . . . . . . . . . . . . . . . :   *SBS
  Job name  . . . . . . . . . . . . . . . :   *ALL
  CPU %  . . . :      .0          Elapsed time . . . . . . . :   00:00:00           Active jobs . . . . . . :    272
                                      Current                             --------Elapsed---------
  Subsystem/Job  User        Number   User        Type Pool Pty     CPU   Int    Rsp  AuxIO   CPU%  Function       Status   Threads
  QBATCH         QSYS        550837   QSYS        SBS    2   0        .0                  0     .0                  DEQW          2
  QCMN           QSYS        550838   QSYS        SBS    2   0        .5                  0     .0                  DEQW          2
    QACSOTP      QUSER       550866   QUSER       PJ     2  20        .0                  0     .0                  PSRW          1

Again ...above sample will run on any platform supporting node 6 "as is" (you do nothing beyond npm install itoolkit).

abmusse commented 7 years ago

Original comment by Aaron Bartell (Bitbucket: aaronbartell, GitHub: aaronbartell).


That is to say, legal(ish), not sure you can 'steal' the db2a binary directly from PASE distribution to package in your npm (IBM i machine -- check with Jesse).

The db2a module is now open sourced in the nodejs-idb-connector so do we need to ask permission?

More of what I am talking about is the "Fat Gem" concept where you include the precompiled C binaries in the distribution (so they don't need to be compiled during normal developer install, and in turn create a dependency on gcc). This is for 1-tier situations where the SQL CLI APIs will be called (vs. HTTP).

When we compiled ruby-ibm_db I am remembering we had to compile on a v7.1 machine for it to work on v7.1+. I don't recall the reason for this other than I am guessing it had to do with the IBM i /includes?

abmusse commented 7 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Yes, it works as npm REST ...

#!bash

bash-4.3$ pwd
/home/node6/tryit
bash-4.3$ ls
app.js
bash-4.3$ node --version
v6.9.1
bash-4.3$ npm install itoolkit
/home/node6/tryit
└── itoolkit@0.1.1 

npm WARN enoent ENOENT: no such file or directory, open '/home/node6/tryit/package.json'
npm WARN tryit No description
npm WARN tryit No repository field.
npm WARN tryit No README data
npm WARN tryit No license field.
bash-4.3$ ls                                                                           
app.js        node_modules
bash-4.3$ 
bash-4.3$ node app.js 
<?xml version='1.0'?><myscript><cmd exec='rexx' error='fast'><success>+++ success RTVJOBA USER(?)</success>
<row>
<data desc='USER'>QUSER</data>
</row>
</cmd>
</myscript>
bash-4.3$ cat app.js 
var it = require("itoolkit");
// var conn = new it.iConn("*LOCAL");
var conn = new it.iConn("*LOCAL", "*NONE", "*NONE",
    { host : "yips.idevcloud.com", port : 80, path : "/cgi-bin/xmlcgi.pgm",
      ipc : "*na",
      ctl : "*here"});
conn.add(it.iCmd('RTVJOBA USER(?)'));
conn.run(function(str) {
  console.log(str);
});

BTW -- Danny R. This will work from Linux, Windows, Unix, Bluemix, whatever with node 6. You can try/copy my app.js "as is", because will connect Yips machine using uid/pwd *NONE. Aka, Yips, our community demo machine and wiki (don't abuse this IBM i Yips machine).

#!node

var it = require("itoolkit");
// var conn = new it.iConn("*LOCAL");
var conn = new it.iConn("*LOCAL", "*NONE", "*NONE",
    { host : "yips.idevcloud.com", port : 80, path : "/cgi-bin/xmlcgi.pgm",
      ipc : "*na",
      ctl : "*here"});
conn.add(it.iCmd('RTVJOBA USER(?)'));
conn.run(function(str) {
  console.log(str);
});
abmusse commented 7 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


Hoping it is simpler than the RubyGems approach :-|

Bad news (remote other guy question) ... Nope. Compiling c code, you will need to hook up with remote LUW db2 driver transport ... most likely ... db2 connect (cost license money).

Ok news (on IBM i) ... Still compiling c code 'somewhere', but obviously 'free' because PASE ships libdb400.a (or litmis/db2sock someday). That is to say, legal(ish), not sure you can 'steal' the db2a binary directly from PASE distribution to package in your npm (IBM i machine -- check with Jesse).

Good news ... However cheap folk unite, as might work as npm right now using REST connection host : conf.Host, port : conf.Port, path : conf.Path.

#!node
config.js:
var Database = "*LOCAL";
var User = "*NONE";
var Password = "*NONE";
//var Host = "174.79.32.155";
//var Host = "65.183.160.36";
//var Host = "yips.idevcloud.com";
var Host = "127.0.0.1";
var Port = 80;
var Path = "/cgi-bin/xmlcgi.pgm";
var IPC = "*na";
var CTL = "*here";
var DemoLib = "HATS";
var DemoAsset = "/silly_public/images/";

exports.Database = Database;
exports.User = User;
exports.Password = Password;
exports.Host = Host;
exports.Port = Port;
exports.Path = Path;
exports.IPC = IPC;
exports.CTL = CTL;
exports.DemoLib = DemoLib;
exports.DemoAsset = DemoAsset;

app.js:

// xmlservice - REST connection (IBM node.js toolkit PTF)
var xt = require('./lib/itoolkit');
var conf = require('./lib/config');

RestConn = function(idx) {
  this.inuse = false;
  this.idx = idx;
  this.conn = new xt.iConn(conf.Database, conf.User, conf.Password,
    { host : conf.Host, port : conf.Port, path : conf.Path,
      ipc : "/tmp/silly" + this.idx,
      ctl : "*sbmjob"});
}
abmusse commented 7 years ago

Original comment by Aaron Bartell (Bitbucket: aaronbartell, GitHub: aaronbartell).


Is itoolkit in npm yet?

Ran a quick test of publishing iToolkit to npmjs.com to see what we're up against.

Progress...

app.js

var it = require("itoolkit");
var conn = new it.iConn("*LOCAL");
conn.add(it.iCmd('RTVJOBA USER(?)'));
conn.run(function(str) {
  console.log(str);
});
$ node app.js
{ [Error: Cannot find module '../../db2i/lib/db2'] code: 'MODULE_NOT_FOUND' }

We will need to make nodejs-idb-connector a dependency, which means we'll first need to make nodejs-idb-connector an npm. I haven't looked into the effort involved with making a native (C code) Node.js npm. Hoping it is simpler than the RubyGems approach :-|

Stay tuned.

abmusse commented 7 years ago

Original comment by Tony Cairns (Bitbucket: rangercairns, GitHub: rangercairns).


It looks like one of the dependencies only runs on IBM i, unless I'm doing something wrong.

The itoolkit can be run remote to IBM i using the REST interface.

Important: The examples are running on an IBM i node 6, but you can simple copy the code to Linux, BlueMix, etc., and run them from these platforms using REST to your IBM i (xmlservice configure below). In fact, the silly hats REST to IBM i sample was completely developed on bluemix long before ported to IBM i.

how can i do it ...

Bottom line ... really all you have to do is copy xstoolkit to your Linux, Windows, Bluemix, etc.

#!bash

bash-4.3$ ls /QOpenSys/QIBM/ProdData/OPS/Node6/os400/xstoolkit/lib/
idataq.js      iobj.js        irest.js       itoolkit.js    iwork.js
inetwork.js    iprod.js       istoredp.js    iuserSpace.js  ixml.js

You will have to set-up XMLSERVICE on IBM i to handle REST requests.

#!bash

test library XMLSERVICE 

ScriptAlias /cgi-bin/ /QSYS.LIB/XMLSERVICE.LIB/
<Directory /QSYS.LIB/XMLSERVICE.LIB/>
  AllowOverride None
  order allow,deny
  allow from all
  SetHandler cgi-script
  Options +ExecCGI
</Directory>

-- or --

IBM PTFs library QXMLSERV

ScriptAlias /cgi-bin/ /QSYS.LIB/QXMLSERV.LIB/
<Directory /QSYS.LIB/QXMLSERV.LIB/>
  AllowOverride None
  order allow,deny
  allow from all
  SetHandler cgi-script
  Options +ExecCGI
</Directory>
abmusse commented 7 years ago

Original comment by Danny Roessner (Bitbucket: droessner, GitHub: droessner).


Is itoolkit in npm yet? Also, can itoolkit be run on anything other than IBM i? It looks like one of the dependencies only runs on IBM i, unless I'm doing something wrong.

abmusse commented 7 years ago

Original comment by Xu Meng (Bitbucket: mengxumx, GitHub: dmabupt).


Aaron, It is OK to make the npm package of itoolkit. And we really need version information of itoolkit.

abmusse commented 7 years ago

Original comment by Aaron Bartell (Bitbucket: aaronbartell, GitHub: aaronbartell).


Jesse, when the rpm toolkit is ready, shall we remove itoolkit from Node.js PTF to avoid conficts?

I know you pointed this at Jesse, but I wanted to comment on it. If iToolkit was an npm then it would be require()'d differently, or rather, with a different path than that of the PTF.

PTF:

var xt = require("/QOpenSys/QIBM/ProdData/OPS/Node6/os400/xstoolkit/lib/itoolkit");

npm:

var xt = require("itoolkit");

Regardless of the above, I think the PTF option should be End Of Life'd in favor of the npm approach so people don't get confused about which to use. We have that confusion today over the "GCC" (aka IBM i Chroot) option on 5733OPS vs. obtaining it via git clone (what I recommend to people so they can get the latest version).

abmusse commented 7 years ago

Original comment by Xu Meng (Bitbucket: mengxumx, GitHub: dmabupt).


I agree. And the itoolkit package.json should refer to the local DB2 addon as dependency. Jesse, when the rpm toolkit is ready, shall we remove itoolkit from Node.js PTF to avoid conficts?

abmusse commented 7 years ago

Original comment by Jesse G (Bitbucket: ThePrez, GitHub: ThePrez).


Sounds like a good idea to me