server/boot/load-model.js
function pullFromAPIm(apimanager, currdir, uid, cb) {
  logger.debug('pullFromAPIm entry');
  // Have an APIm, grab latest if we can..
  var snapdir = path.join(process.env.ROOTCONFIGDIR, uid);

  fs.mkdirs(snapdir, function(err) {
    if (err) {
      logger.warn('Failed to create snapshot directory');
      logger.debug('pullFromAPIm exit(1)');
      cb(err, '');
      return;
    }
    /*
    var options = {
      host: host of APIm
      port: port of APIm
      timeout: opts.timeout * 1000 || 30 * 1000,
      clikey: opts.clikey ? opts.clikey : null,
      clicert: opts.clicert ? opts.clicert  : null,
      clientid: opts.clientid || '1111-1111',
      outdir: opts.outdir || 'apim' };
    */

    var options = {};
    options.host = apimanager.host;
    options.port = apimanager.port;
    options.clikey = apimanager.clikey;
    options.clicert = apimanager.clicert;
    options.clientid = apimanager.clientid;
    options.indir = currdir;
    options.outdir = snapdir;

    logger.debug('apimpull start');
    apimpull(options, function(err, response) {
      if (err) {
        logger.error(err);
        try {
          fs.removeSync(snapdir);
        } catch (e) {
          logger.error(e);
          //continue
        }
        snapdir = '';
        // falling through
        // try loading from local files
      } else {
        logger.info('Successfully pulled snapshot from API Connect server');
      }
      logger.debug(response);
      logger.debug('pullFromAPIm exit(2)');
      cb(err, snapdir);
    });
  });
}
function pullFromAPIm(apimanager, currdir, uid, cb) {
  logger.debug('pullFromAPIm entry');
  // Have an APIm, grab latest if we can..
  var snapdir = path.join(process.env.ROOTCONFIGDIR, uid);

  fs.mkdirs(snapdir, function(err) {
    if (err) {
      logger.warn('Failed to create snapshot directory');
      logger.debug('pullFromAPIm exit(1)');
      cb(err, '');
      return;
    }
    /*
    var options = {
      host: host of APIm
      port: port of APIm
      timeout: opts.timeout * 1000 || 30 * 1000,
      clikey: opts.clikey ? opts.clikey : null,
      clicert: opts.clicert ? opts.clicert  : null,
      clientid: opts.clientid || '1111-1111',
      outdir: opts.outdir || 'apim' };
    */

    var options = {};
    options.host = apimanager.host;
    options.port = apimanager.port;
    options.clikey = apimanager.clikey;
    options.clicert = apimanager.clicert;
    options.clientid = apimanager.clientid;
    options.indir = currdir;
    options.outdir = snapdir;

    logger.debug('apimpull start');
    apimpull(options, function(err, response) {
      if (err) {
        logger.error(err);
        try {
          fs.removeSync(snapdir);
        } catch (e) {
          logger.error(e);
          //continue
        }
        snapdir = '';
        // falling through
        // try loading from local files
      } else {
        logger.info('Successfully pulled snapshot from API Connect server');
      }
      logger.debug(response);
      logger.debug('pullFromAPIm exit(2)');
      cb(err, snapdir);
    });
  });
}
function pullFromAPIm ( apimanager , currdir , uid , cb ) { logger . debug ( 'pullFromAPIm entry' ) ; // Have an APIm, grab latest if we can.. var snapdir = path . join ( process . env . ROOTCONFIGDIR , uid ) ; fs . mkdirs ( snapdir , function ( err ) { if ( err ) { logger . warn ( 'Failed to create snapshot directory' ) ; logger . debug ( 'pullFromAPIm exit(1)' ) ; cb ( err , '' ) ; return ; } /*
    var options = {
      host: host of APIm
      port: port of APIm
      timeout: opts.timeout * 1000 || 30 * 1000,
      clikey: opts.clikey ? opts.clikey : null,
      clicert: opts.clicert ? opts.clicert  : null,
      clientid: opts.clientid || '1111-1111',
      outdir: opts.outdir || 'apim' };
    */ var options = { } ; options . host = apimanager . host ; options . port = apimanager . port ; options . clikey = apimanager . clikey ; options . clicert = apimanager . clicert ; options . clientid = apimanager . clientid ; options . indir = currdir ; options . outdir = snapdir ; logger . debug ( 'apimpull start' ) ; apimpull ( options , function ( err , response ) { if ( err ) { logger . error ( err ) ; try { fs . removeSync ( snapdir ) ; } catch ( e ) { logger . error ( e ) ; //continue } snapdir = '' ; // falling through // try loading from local files } else { logger . info ( 'Successfully pulled snapshot from API Connect server' ) ; } logger . debug ( response ) ; logger . debug ( 'pullFromAPIm exit(2)' ) ; cb ( err , snapdir ) ; } ) ; } ) ; }
Attempt to request data from APIm server and persist to disk
@param {Object} config - configuration pointing to APIm server
@param {string} currdir - current snapshot symbolic link path
@param {string} uid - snapshot identifier
@param {callback} cb - callback that handles error or path to
snapshot directory
Attempt to request data from APIm server and persist to disk