github.com/leonlxy/hyperledger@v1.0.0-alpha.0.20170427033203-34922035d248/bddtests/regression/go/ote/json2yml.js (about)

     1  var fs = require('fs');
     2  
     3  var cfgFile = process.argv[2];
     4  //var cfgFile = __dirname + "/" + "network-cfg.json";
     5  var dFile = __dirname + "/" + "docker-compose.yml";
     6  fs.createWriteStream(dFile);
     7  
     8  var CA=0;
     9  var CDB=0;
    10  var KAFKA=0;
    11  
    12  // Orderer environment var
    13  var ord_env_name=[];
    14  var ord_env_val=[];
    15  if ( process.env.CONFIGTX_ORDERER_BATCHSIZE_MAXMESSAGECOUNT != null ) {
    16      console.log(' CONFIGTX_ORDERER_BATCHSIZE_MAXMESSAGECOUNT= ', process.env.CONFIGTX_ORDERER_BATCHSIZE_MAXMESSAGECOUNT);
    17      ord_env_name.push('CONFIGTX_ORDERER_BATCHSIZE_MAXMESSAGECOUNT');
    18      ord_env_val.push(process.env.CONFIGTX_ORDERER_BATCHSIZE_MAXMESSAGECOUNT);
    19  }
    20  if ( process.env.CONFIGTX_ORDERER_ORDERERTYPE != null ) {
    21      console.log(' CONFIGTX_ORDERER_ORDERERTYPE= ', process.env.CONFIGTX_ORDERER_ORDERERTYPE);
    22      ord_env_name.push('CONFIGTX_ORDERER_ORDERERTYPE');
    23      ord_env_val.push(process.env.CONFIGTX_ORDERER_ORDERERTYPE);
    24      if ( process.env.CONFIGTX_ORDERER_ORDERERTYPE == 'kafka' ) {
    25         KAFKA=1;
    26      }
    27  }
    28  if ( process.env.CONFIGTX_ORDERER_BATCHTIMEOUT != null ) {
    29      console.log(' CONFIGTX_ORDERER_BATCHTIMEOUT= ', process.env.CONFIGTX_ORDERER_BATCHTIMEOUT);
    30      ord_env_name.push('CONFIGTX_ORDERER_BATCHTIMEOUT');
    31      ord_env_val.push(process.env.CONFIGTX_ORDERER_BATCHTIMEOUT);
    32  }
    33  
    34  console.log('ord_env_name: ', ord_env_name.length, ord_env_name);
    35  console.log('ord_env_val: ', ord_env_val.length, ord_env_val);
    36  
    37  // Peer environment var
    38  var peer_env_name=[];
    39  var peer_env_val=[];
    40  if ( process.env.CORE_LOGGING_LEVEL != null ) {
    41      console.log(' CORE_LOGGING_LEVEL= ', process.env.CORE_LOGGING_LEVEL);
    42      peer_env_name.push('CORE_LOGGING_LEVEL');
    43      peer_env_val.push(process.env.CORE_LOGGING_LEVEL);
    44  }
    45  if ( process.env.CORE_SECURITY_LEVEL != null ) {
    46      console.log(' CORE_SECURITY_LEVEL= ', process.env.CORE_SECURITY_LEVEL);
    47      peer_env_name.push('CORE_SECURITY_LEVEL');
    48      peer_env_val.push(process.env.CORE_SECURITY_LEVEL);
    49  }
    50  if ( process.env.CORE_SECURITY_HASHALGORITHM != null ) {
    51      console.log(' CORE_SECURITY_HASHALGORITHM= ', process.env.CORE_SECURITY_HASHALGORITHM);
    52      peer_env_name.push('CORE_SECURITY_HASHALGORITHM');
    53      peer_env_val.push(process.env.CORE_SECURITY_HASHALGORITHM);
    54  }
    55  
    56  console.log('peer_env_name: ', peer_env_name.length, peer_env_name);
    57  console.log('peer_env_val: ', peer_env_val.length, peer_env_val);
    58  
    59  //process.exit();
    60  console.log('network cfg: ', cfgFile);
    61  console.log('docker composer: ', dFile);
    62  
    63  var addVP = parseInt(process.argv[3]);
    64  console.log('add peer: ', addVP);
    65  
    66  var VPName = 'peer' + addVP;
    67  
    68  var addOrderer = parseInt(process.argv[4]);;
    69  console.log('add Orderer: ', addOrderer);
    70  
    71  var addBroker = parseInt(process.argv[5]);
    72  console.log('add Kafka Broker: ', addBroker);
    73  
    74  //console.log(' input argv length', process.argv.length);
    75  var dbType = 'none';
    76  if (process.argv.length == 7) {
    77     dbType = process.argv[6];
    78  }
    79  console.log('DB type: ', dbType);
    80  
    81  var cfgContent = JSON.parse(fs.readFileSync(cfgFile, 'utf8'));
    82  
    83  var top_key = Object.keys(cfgContent);
    84  
    85  var lvl1_obj;
    86  var lvl2_key;
    87  var lvl2_obj;
    88  var lvl3_key;
    89  var tmp_name;
    90  var tmp_port;
    91  var ordererAddr;
    92  var ordererPort;
    93  var couchdbAddr;
    94  var couchdbPort;
    95  var vp0Addr;
    96  var vp0Port;
    97  var tmp;
    98  var e;
    99  
   100  if ( addBroker > 0 ) {
   101     KAFKA=1;
   102  }
   103  
   104  if ( (dbType == 'couchdb') || (dbType == 'goleveldb') ){
   105     CDB=1;
   106  }
   107  
   108  //header 0
   109  for ( i0=0; i0<top_key.length; i0++ ) {
   110      var lvl0_obj = cfgContent[top_key[i0]];
   111      var lvl1_key = Object.keys(lvl0_obj);
   112      if ( top_key[i0] == 'ordererAddress' ) {
   113           ordererAddr = lvl0_obj;
   114           console.log('orderer address:', ordererAddr);
   115      } else if ( top_key[i0] == 'ordererPort' ) {
   116           ordererPort = parseInt(lvl0_obj);
   117           console.log('orderer Port:', ordererPort);
   118      } else if ( top_key[i0] == 'couchdbAddress' ) {
   119           couchdbAddr = lvl0_obj;
   120           console.log('couchdb address:', couchdbAddr);
   121      } else if ( top_key[i0] == 'couchdbPort' ) {
   122           couchdbPort = parseInt(lvl0_obj);
   123           console.log('couchdb Port:', couchdbPort);
   124      } else if ( top_key[i0] == 'vp0Address' ) {
   125           vp0Addr = lvl0_obj;
   126           console.log('peer0 address:', vp0Addr);
   127      } else if ( top_key[i0] == 'vp0Port' ) {
   128           vp0Port = parseInt(lvl0_obj);
   129           console.log('peer0 Port:', vp0Port);
   130      } else if ( top_key[i0] == 'version' ) {
   131           buff = top_key[i0] + ":" + " '" + lvl0_obj + "'" + "\n";
   132           fs.appendFileSync(dFile, buff);
   133      } else if ( top_key[i0] == 'networks' ) {
   134           buff = top_key[i0] + ":" + "\n";
   135           fs.appendFileSync(dFile, buff);
   136           buff = '    bridge:' + '\n';
   137           fs.appendFileSync(dFile, buff);
   138      } else if ( top_key[i0] == 'services' ) {
   139          buff = '\n';
   140          fs.appendFileSync(dFile, buff);
   141          buff = top_key[i0] + ':' + '\n';
   142          fs.appendFileSync(dFile, buff);
   143          //header 1
   144          for ( i=0; i<lvl1_key.length; i++ ) {
   145              lvl1_obj = lvl0_obj[lvl1_key[i]];
   146              lvl2_key = Object.keys(lvl1_obj);
   147  
   148              // header 2
   149               if (lvl1_key[i] == 'couchdb' ) {
   150                  if (dbType == 'couchdb') {
   151                  for ( v = 0; v < addVP; v++ ) {
   152                      tmp_name = lvl1_key[i] + v;
   153                      tmp_port = couchdbPort + v;
   154                      buff = '  ' + tmp_name +':' + '\n';
   155                      fs.appendFileSync(dFile, buff);
   156  
   157                      // header 3
   158                      for ( k=0; k<lvl2_key.length; k++ ) {
   159                          if ( lvl2_key[k] == 'environment' ) {
   160                              lvl2_obj = lvl1_obj[lvl2_key[k]];
   161                              lvl3_key = Object.keys(lvl2_obj);
   162  
   163                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   164                              fs.appendFileSync(dFile, buff);
   165  
   166                              // header 4
   167                              for ( m=0; m< lvl3_key.length; m++ ) {
   168                                  if ( lvl3_key[m] == 'CORE_PEER_ID' ) {
   169                                      buff = '  ' + '    - ' + lvl3_key[m] + '=' + tmp_name + '\n';
   170                                  } else if ( lvl3_key[m] == 'CORE_PEER_ADDRESS' ) {
   171                                      buff = '  ' + '    - ' + lvl3_key[m] + '=' + vp0Addr +':'+ tmp_port + '\n';
   172                                  } else if ( lvl3_key[m] == 'CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS' ) {
   173                                      buff = '  ' + '    - ' + lvl3_key[m] + '=' + 'couchdb'+v +':'+ couchdbPort + '\n';
   174                                  } else {
   175                                      buff = '  ' + '    - ' + lvl3_key[m] + '=' +lvl2_obj[lvl3_key[m]] + '\n';
   176                                  }
   177  
   178                                  fs.appendFileSync(dFile, buff);
   179                              }
   180                          } else if ( ( lvl2_key[k] == 'image' ) || ( lvl2_key[k] == 'command' ) || ( lvl2_key[k] == 'working_dir' )
   181                                      || ( lvl2_key[k] == 'restart') ) {
   182                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + lvl1_obj[lvl2_key[k]] + '\n';
   183                              fs.appendFileSync(dFile, buff);
   184  
   185                          } else if ( lvl2_key[k] == 'container_name' ) {
   186                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + tmp_name + '\n';
   187                              fs.appendFileSync(dFile, buff);
   188  
   189                          } else if ( lvl2_key[k] == 'ports' ) {
   190                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   191                              fs.appendFileSync(dFile, buff);
   192  
   193                              // header 4
   194                              buff = '  ' + '    - ' + tmp_port + ':' + couchdbPort + '\n';
   195                              fs.appendFileSync(dFile, buff);
   196  
   197                          } else if ( lvl2_key[k] == 'links' ) {
   198                              var lvl2_obj = lvl1_obj[lvl2_key[k]];
   199                              //console.log('lvl2_obj: %d ', lvl2_obj.length, lvl2_obj);
   200  
   201                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   202                              fs.appendFileSync(dFile, buff);
   203                              buff = '  ' + '    - ' + 'orderer' + '\n';
   204                              fs.appendFileSync(dFile, buff);
   205                              if ( CA == 1 ) {
   206                                  buff = '  ' + '    - ' + 'ca' + '\n';
   207                                  fs.appendFileSync(dFile, buff);
   208                              }
   209                              // header 4
   210                              for ( m=0; m< v; m++ ) {
   211                                  buff = '  ' + '    - ' +'peer'+m + '\n';
   212                                  fs.appendFileSync(dFile, buff);
   213                              }
   214  
   215                          } else if ( ( lvl2_key[k] == 'volumes' ) || ( lvl2_key[k] == 'depends_on' ) ){
   216                              var lvl2_obj = lvl1_obj[lvl2_key[k]];
   217                              //console.log('lvl2_obj: %d ', lvl2_obj.length, lvl2_obj);
   218  
   219                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   220                              fs.appendFileSync(dFile, buff);
   221  
   222                              // header 4
   223                              for ( m=0; m< lvl2_obj.length; m++ ) {
   224                                  buff = '  ' + '    - ' +lvl2_obj[m] + '\n';
   225                                  fs.appendFileSync(dFile, buff);
   226  
   227                              }
   228  
   229                          } else {
   230                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   231                              fs.appendFileSync(dFile, buff);
   232  
   233                              buff = '  ' + '    - ' + lvl1_obj[lvl2_key[k]] + '\n';
   234                              fs.appendFileSync(dFile, buff);
   235  
   236                          }
   237                      }
   238                      // add a blank line
   239                      buff = '\n';
   240                      fs.appendFileSync(dFile, buff);
   241  
   242                  }
   243                  }
   244               } else if (lvl1_key[i] == 'orderer' ) {
   245                  for ( v = 0; v < addOrderer; v++ ) {
   246                      tmp_name = lvl1_key[i] + v;
   247                      buff = '  ' + tmp_name +':' + '\n';
   248                      fs.appendFileSync(dFile, buff);
   249  
   250                      // header 3
   251                      for ( k=0; k<lvl2_key.length; k++ ) {
   252                          if ( (lvl2_key[k] == 'environment') ) {
   253                              lvl2_obj = lvl1_obj[lvl2_key[k]];
   254                              lvl3_key = Object.keys(lvl2_obj);
   255  
   256                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   257                              fs.appendFileSync(dFile, buff);
   258  
   259                                  // header 4
   260                                  for ( m=0; m< lvl3_key.length; m++ ) {
   261                                      tmp = ord_env_name.indexOf( lvl3_key[m] );
   262                                      if ( tmp >= 0 ) {
   263                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' + ord_env_val[tmp] + '\n';
   264                                          fs.appendFileSync(dFile, buff);
   265                                      } else if ( lvl3_key[m] == 'CONFIGTX_ORDERER_KAFKA_BROKERS' ) {
   266                                          if ( addBroker > 0 ) {
   267                                              buff = '  ' + '    - ' + lvl3_key[m] + '=[';
   268                                              for (n=0; n<addBroker; n++) {
   269                                                  buff = buff + 'kafka' + n +':9092' ;
   270                                                  if ( n < (addBroker-1) ) {
   271                                                       buff = buff + ',';
   272                                                  }
   273                                              }
   274                                              buff = buff + ']' + '\n';
   275                                              fs.appendFileSync(dFile, buff);
   276                                          }
   277                                      } else if ( lvl3_key[m] == 'CONFIGTX_ORDERER_ORDERERTYPE' ) {
   278                                              if ( addBroker > 0 ) {
   279                                                  buff = '  ' + '    - ' + lvl3_key[m] + '=' + 'kafka' + '\n';
   280                                                  fs.appendFileSync(dFile, buff);
   281                                              } else {
   282                                                  buff = '  ' + '    - ' + lvl3_key[m] + '=' + 'solo' + '\n';
   283                                                  fs.appendFileSync(dFile, buff);
   284                                              }
   285                                      } else if ( lvl3_key[m] == 'ORDERER_GENERAL_LISTENPORT' ) {
   286                                              buff = '  ' + '    - ' + lvl3_key[m] + '=' + ordererPort + '\n';
   287                                              fs.appendFileSync(dFile, buff);
   288                                      } else if ( ( lvl3_key[m] == 'ORDERER_GENERAL_GENESISMETHOD' ) || ( lvl3_key[m] == 'ORDERER_GENERAL_GENESISFILE' ) ) {
   289                                          if ( addBroker > 0 ) {
   290                                              buff = '  ' + '    - ' + lvl3_key[m] + '=' + lvl2_obj[lvl3_key[m]] + '\n';
   291                                              fs.appendFileSync(dFile, buff);
   292                                          } else {
   293                                              //buff = '  ' + '    - ' + lvl3_key[m] + '=' + 'solo' + '\n';
   294                                              //fs.appendFileSync(dFile, buff);
   295                                          }
   296                                      } else {
   297                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' +lvl2_obj[lvl3_key[m]] + '\n';
   298                                          fs.appendFileSync(dFile, buff);
   299                                      }
   300  
   301                                  }
   302                          } else if ( ( lvl2_key[k] == 'image' ) || ( lvl2_key[k] == 'command' ) || ( lvl2_key[k] == 'working_dir' )
   303                                      || ( lvl2_key[k] == 'restart') ) {
   304                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + lvl1_obj[lvl2_key[k]] + '\n';
   305                              fs.appendFileSync(dFile, buff);
   306                          } else if ( lvl2_key[k] == 'container_name' ) {
   307                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + tmp_name + '\n';
   308                              fs.appendFileSync(dFile, buff);
   309                          } else if ( lvl2_key[k] == 'ports' ) {
   310                                  lvl2_obj = lvl1_obj[lvl2_key[k]];
   311                                  lvl3_key = Object.keys(lvl2_obj);
   312  
   313                                  buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   314                                  fs.appendFileSync(dFile, buff);
   315                                  tmp_port = ordererPort + v;
   316  
   317                                  buff = '  ' + '    - ' + tmp_port +':' + ordererPort + '\n' ;
   318                                  fs.appendFileSync(dFile, buff);
   319  
   320                          } else if ( (lvl2_key[k] == 'depends_on') ) {
   321                              if ( addBroker > 0 ) {
   322                                  lvl2_obj = lvl1_obj[lvl2_key[k]];
   323                                  lvl3_key = Object.keys(lvl2_obj);
   324  
   325                                  buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   326                                  fs.appendFileSync(dFile, buff);
   327  
   328                                  buff = '  ' + '    - ' + 'zookeeper' + '\n' ;
   329                                  fs.appendFileSync(dFile, buff);
   330                                  if ( KAFKA==1 ) {
   331                                      for (n=0; n<addBroker; n++) {
   332                                          buff = '  ' + '    - ' + 'kafka' + n + '\n' ;
   333                                          fs.appendFileSync(dFile, buff);
   334                                      }
   335                                  }
   336                              }
   337                          } else {
   338                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   339                              fs.appendFileSync(dFile, buff);
   340  
   341                              buff = '  ' + '    - ' + lvl1_obj[lvl2_key[k]] + '\n';
   342                              fs.appendFileSync(dFile, buff);
   343  
   344                          }
   345                      }
   346                      // add a blank line
   347                      buff = '\n';
   348                      fs.appendFileSync(dFile, buff);
   349  
   350                  }
   351               } else if (lvl1_key[i] == 'kafka' ) {
   352                  for ( v = 0; v < addBroker; v++ ) {
   353                      tmp_name = lvl1_key[i] + v;
   354                      tmp_port = vp0Port + v;
   355                      buff = '  ' + tmp_name +':' + '\n';
   356                      fs.appendFileSync(dFile, buff);
   357  
   358                      // header 3
   359                      for ( k=0; k<lvl2_key.length; k++ ) {
   360                          if ( (lvl2_key[k] == 'environment') ) {
   361                                  lvl2_obj = lvl1_obj[lvl2_key[k]];
   362                                  lvl3_key = Object.keys(lvl2_obj);
   363  
   364                                  buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   365                                  fs.appendFileSync(dFile, buff);
   366  
   367                                  // header 4
   368                                  for ( m=0; m< lvl3_key.length; m++ ) {
   369                                      if ( lvl3_key[m] == 'KAFKA_BROKER_ID' ) {
   370                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' + v + '\n';
   371                                          fs.appendFileSync(dFile, buff);
   372                                      } else if ( lvl3_key[m] == 'KAFKA_DEFAULT_REPLICATION_FACTOR' ) {
   373                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' + addBroker + '\n';
   374                                          fs.appendFileSync(dFile, buff);
   375                                      } else {
   376                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' +lvl2_obj[lvl3_key[m]] + '\n';
   377                                          fs.appendFileSync(dFile, buff);
   378                                      }
   379  
   380                                  }
   381                          } else if ( ( lvl2_key[k] == 'image' ) || ( lvl2_key[k] == 'command' ) || ( lvl2_key[k] == 'working_dir' )
   382                                      || ( lvl2_key[k] == 'restart') ) {
   383                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + lvl1_obj[lvl2_key[k]] + '\n';
   384                              fs.appendFileSync(dFile, buff);
   385                          } else if ( lvl2_key[k] == 'container_name' ) {
   386                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + tmp_name + '\n';
   387                              fs.appendFileSync(dFile, buff);
   388  
   389                          } else {
   390                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   391                              fs.appendFileSync(dFile, buff);
   392  
   393                              buff = '  ' + '    - ' + lvl1_obj[lvl2_key[k]] + '\n';
   394                              fs.appendFileSync(dFile, buff);
   395  
   396                          }
   397                      }
   398                      // add a blank line
   399                      buff = '\n';
   400                      fs.appendFileSync(dFile, buff);
   401  
   402                  }
   403               } else if (lvl1_key[i] == 'zookeeper' ) {
   404                  if ( KAFKA == 1 ) {
   405                      tmp_name = lvl1_key[i];
   406                      buff = '  ' + tmp_name +':' + '\n';
   407                      fs.appendFileSync(dFile, buff);
   408  
   409                      // header 3
   410                      for ( k=0; k<lvl2_key.length; k++ ) {
   411                          if ( (lvl2_key[k] == 'environment') ) {
   412                                  lvl2_obj = lvl1_obj[lvl2_key[k]];
   413                                  lvl3_key = Object.keys(lvl2_obj);
   414  
   415                                  buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   416                                  fs.appendFileSync(dFile, buff);
   417  
   418                                  // header 4
   419                                  for ( m=0; m< lvl3_key.length; m++ ) {
   420                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' +lvl2_obj[lvl3_key[m]] + '\n';
   421                                          fs.appendFileSync(dFile, buff);
   422                                  }
   423                          } else if ( ( lvl2_key[k] == 'image' ) || ( lvl2_key[k] == 'command' ) || ( lvl2_key[k] == 'working_dir' )
   424                                      || ( lvl2_key[k] == 'restart') ) {
   425                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + lvl1_obj[lvl2_key[k]] + '\n';
   426                              fs.appendFileSync(dFile, buff);
   427                          } else if ( lvl2_key[k] == 'container_name' ) {
   428                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + tmp_name + '\n';
   429                              fs.appendFileSync(dFile, buff);
   430  
   431                          } else {
   432                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   433                              fs.appendFileSync(dFile, buff);
   434  
   435                              buff = '  ' + '    - ' + lvl1_obj[lvl2_key[k]] + '\n';
   436                              fs.appendFileSync(dFile, buff);
   437  
   438                          }
   439                      }
   440                      // add a blank line
   441                      buff = '\n';
   442                      fs.appendFileSync(dFile, buff);
   443  
   444                  }
   445               } else if (lvl1_key[i] == 'peer' ) {
   446                  for ( v = 0; v < addVP; v++ ) {
   447                      tmp_name = lvl1_key[i] + v;
   448                      tmp_port = vp0Port + v;
   449                      buff = '  ' + tmp_name +':' + '\n';
   450                      fs.appendFileSync(dFile, buff);
   451  
   452                      // header 3
   453                      for ( k=0; k<lvl2_key.length; k++ ) {
   454                          if ( (lvl2_key[k] == 'environment') ) {
   455                              lvl2_obj = lvl1_obj[lvl2_key[k]];
   456                              lvl3_key = Object.keys(lvl2_obj);
   457  
   458                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   459                              fs.appendFileSync(dFile, buff);
   460  
   461                                  // header 4
   462                                  for ( m=0; m< lvl3_key.length; m++ ) {
   463                                      tmp = peer_env_name.indexOf( lvl3_key[m] );
   464                                      if ( tmp >= 0 ) {
   465                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' + peer_env_val[tmp] + '\n';
   466                                          fs.appendFileSync(dFile, buff);
   467                                      } else if ( lvl3_key[m] == 'CORE_PEER_ID' ) {
   468                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' + tmp_name + '\n';
   469                                          fs.appendFileSync(dFile, buff);
   470                                      } else if ( lvl3_key[m] == 'CORE_PEER_NETWORKID' ) {
   471                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' + tmp_name + '\n';
   472                                          fs.appendFileSync(dFile, buff);
   473                                      } else if ( lvl3_key[m] == 'CORE_PEER_COMMITTER_LEDGER_ORDERER' ) {
   474                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' + 'orderer0' +':'+ ordererPort + '\n';
   475                                          fs.appendFileSync(dFile, buff);
   476                                      } else if ( lvl3_key[m] == 'CORE_PEER_ADDRESS' ) {
   477                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' + vp0Addr +':'+ tmp_port + '\n';
   478                                          fs.appendFileSync(dFile, buff);
   479                                      } else if ( lvl3_key[m] == 'CORE_PEER_DISCOVERY_ROOTNODE' ) {
   480                                          if ( v != 0 ) {
   481                                              buff = '  ' + '    - ' + lvl3_key[m] + '=' + vp0Addr +':'+ vp0Port + '\n';
   482                                              fs.appendFileSync(dFile, buff);
   483                                          }
   484                                      } else if ( lvl3_key[m] == 'CORE_LEDGER_STATE_STATEDATABASE' ) {
   485                                          if (dbType == 'couchdb') {
   486                                              buff = '  ' + '    - ' + lvl3_key[m] + '=' + 'CouchDB' + '\n';
   487                                              fs.appendFileSync(dFile, buff);
   488                                          } else if (dbType == 'goleveldb') {
   489                                              buff = '  ' + '    - ' + lvl3_key[m] + '=' + 'goleveldb' + '\n';
   490                                              fs.appendFileSync(dFile, buff);
   491                                          }
   492                                      } else if ( lvl3_key[m] == 'CORE_LEDGER_STATE_COUCHDBCONFIG_COUCHDBADDRESS' ) {
   493                                          if (dbType == 'couchdb') {
   494                                              tmp = couchdbPort+v;
   495                                              buff = '  ' + '    - ' + lvl3_key[m] + '=' + 'couchdb'+v +':'+ tmp + '\n';
   496                                              fs.appendFileSync(dFile, buff);
   497                                          }
   498                                      } else {
   499                                          buff = '  ' + '    - ' + lvl3_key[m] + '=' +lvl2_obj[lvl3_key[m]] + '\n';
   500                                          fs.appendFileSync(dFile, buff);
   501                                      }
   502  
   503                                  }
   504                          } else if ( ( lvl2_key[k] == 'image' ) || ( lvl2_key[k] == 'command' ) || ( lvl2_key[k] == 'working_dir' )
   505                                      || ( lvl2_key[k] == 'restart') ) {
   506                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + lvl1_obj[lvl2_key[k]] + '\n';
   507                              fs.appendFileSync(dFile, buff);
   508  
   509                          } else if ( lvl2_key[k] == 'container_name' ) {
   510                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + tmp_name + '\n';
   511                              fs.appendFileSync(dFile, buff);
   512  
   513                          } else if ( lvl2_key[k] == 'ports' ) {
   514                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   515                              fs.appendFileSync(dFile, buff);
   516  
   517                              // header 4
   518                              buff = '  ' + '    - ' + tmp_port + ':' + vp0Port + '\n';
   519                              fs.appendFileSync(dFile, buff);
   520  
   521                          } else if ( lvl2_key[k] == 'links' ) {
   522                              var lvl2_obj = lvl1_obj[lvl2_key[k]];
   523                              //console.log('lvl2_obj: %d ', lvl2_obj.length, lvl2_obj);
   524  
   525                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   526                              fs.appendFileSync(dFile, buff);
   527                              buff = '  ' + '    - ' + 'orderer0' + '\n';
   528                              fs.appendFileSync(dFile, buff);
   529                              if (dbType == 'couchdb') {
   530                                  buff = '  ' + '    - ' + 'couchdb'+v + '\n';
   531                                  fs.appendFileSync(dFile, buff);
   532                              }
   533                              if ( CA == 1 ) {
   534                                  buff = '  ' + '    - ' + 'ca' + '\n';
   535                                  fs.appendFileSync(dFile, buff);
   536                              }
   537                              // header 4
   538                              for ( m=0; m< v; m++ ) {
   539                                  buff = '  ' + '    - ' +'peer'+m + '\n';
   540                                  fs.appendFileSync(dFile, buff);
   541                              }
   542  
   543                          } else if ( lvl2_key[k] == 'volumes' ) {
   544                              var lvl2_obj = lvl1_obj[lvl2_key[k]];
   545                              //console.log('lvl2_obj: %d ', lvl2_obj.length, lvl2_obj);
   546  
   547                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   548                              fs.appendFileSync(dFile, buff);
   549  
   550                              // header 4
   551                              for ( m=0; m< lvl2_obj.length; m++ ) {
   552                                  buff = '  ' + '    - ' +lvl2_obj[m] + '\n';
   553                                  fs.appendFileSync(dFile, buff);
   554  
   555                              }
   556  
   557                          } else if ( lvl2_key[k] == 'depends_on'  ){
   558                              var lvl2_obj = lvl1_obj[lvl2_key[k]];
   559  
   560                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   561                              fs.appendFileSync(dFile, buff);
   562  
   563                              // header 4
   564                              for ( m=0; m< lvl2_obj.length; m++ ) {
   565                                  buff = '  ' + '    - ' +lvl2_obj[m] + '\n';
   566                                  fs.appendFileSync(dFile, buff);
   567                              }
   568  
   569                          } else {
   570                              buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   571                              fs.appendFileSync(dFile, buff);
   572  
   573                              buff = '  ' + '    - ' + lvl1_obj[lvl2_key[k]] + '\n';
   574                              fs.appendFileSync(dFile, buff);
   575  
   576                          }
   577                      }
   578                      // add a blank line
   579                      buff = '\n';
   580                      fs.appendFileSync(dFile, buff);
   581  
   582                  }
   583               } else if (lvl1_key[i] == 'cli' ) {
   584                  buff = '  ' + lvl1_key[i] +':' + '\n';
   585                  fs.appendFileSync(dFile, buff);
   586  
   587                  // header 3
   588                  for ( k=0; k<lvl2_key.length; k++ ) {
   589                      if ( lvl2_key[k] == 'environment' ) {
   590                          lvl2_obj = lvl1_obj[lvl2_key[k]];
   591                          lvl3_key = Object.keys(lvl2_obj);
   592                          //console.log('lvl2_obj: ', lvl2_obj);
   593                          //console.log('lvl3_key: ', lvl3_key);
   594  
   595                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   596                          fs.appendFileSync(dFile, buff);
   597  
   598                          // header 4
   599                          for ( m=0; m< lvl3_key.length; m++ ) {
   600                              if ( lvl3_key[m] == 'CORE_PEER_COMMITTER_LEDGER_ORDERER' ) {
   601                                  buff = '  ' + '    - ' + lvl3_key[m] + '=' + 'orderer0' +':'+ ordererPort + '\n';
   602                                  fs.appendFileSync(dFile, buff);
   603                              } else {
   604                                  buff = '  ' + '    - ' + lvl3_key[m] + '=' +lvl2_obj[lvl3_key[m]] + '\n';
   605                                  fs.appendFileSync(dFile, buff);
   606                              }
   607  
   608                          }
   609                      } else if ( ( lvl2_key[k] == 'image' ) || ( lvl2_key[k] == 'command' ) || ( lvl2_key[k] == 'working_dir' )
   610                              || ( lvl2_key[k] == 'restart') || ( lvl2_key[k] == 'container_name') || ( lvl2_key[k] == 'tty') ) {
   611                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + lvl1_obj[lvl2_key[k]] + '\n';
   612                          fs.appendFileSync(dFile, buff);
   613  
   614                      } else if ( lvl2_key[k] == 'links' ) {
   615                          var lvl2_obj = lvl1_obj[lvl2_key[k]];
   616                          //console.log('lvl2_obj: %d ', lvl2_obj.length, lvl2_obj);
   617  
   618                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   619                          fs.appendFileSync(dFile, buff);
   620  
   621                          // header 4
   622                              buff = '  ' + '    - ' +'orderer0:orderer0' + '\n';
   623                              fs.appendFileSync(dFile, buff);
   624                              buff = '  ' + '    - ' +'peer0:peer0' + '\n';
   625                              fs.appendFileSync(dFile, buff);
   626  
   627                      } else if ( lvl2_key[k] == 'depends_on' ) {
   628                          var lvl2_obj = lvl1_obj[lvl2_key[k]];
   629                          //console.log('lvl2_obj: %d ', lvl2_obj.length, lvl2_obj);
   630  
   631                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   632                          fs.appendFileSync(dFile, buff);
   633  
   634                          // header 4
   635                              buff = '  ' + '    - ' +'orderer0' + '\n';
   636                              fs.appendFileSync(dFile, buff);
   637                              buff = '  ' + '    - ' +'peer0' + '\n';
   638                              fs.appendFileSync(dFile, buff);
   639  
   640                      } else if ( ( lvl2_key[k] == 'ports' ) || ( lvl2_key[k] == 'volumes' )  ){
   641                          var lvl2_obj = lvl1_obj[lvl2_key[k]];
   642                          //console.log('lvl2_obj: %d ', lvl2_obj.length, lvl2_obj);
   643  
   644                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   645                          fs.appendFileSync(dFile, buff);
   646  
   647                          // header 4
   648                          for ( m=0; m< lvl2_obj.length; m++ ) {
   649                              buff = '  ' + '    - ' +lvl2_obj[m] + '\n';
   650                              fs.appendFileSync(dFile, buff);
   651  
   652                          }
   653  
   654                      } else {
   655                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   656                          fs.appendFileSync(dFile, buff);
   657  
   658                          buff = '  ' + '    - ' + lvl1_obj[lvl2_key[k]] + '\n';
   659                          fs.appendFileSync(dFile, buff);
   660  
   661                      }
   662                  }
   663                  // add a blank line
   664                  buff = '\n';
   665                  fs.appendFileSync(dFile, buff);
   666  
   667               } else {
   668                  if (lvl1_key[i] == 'ca' ) {
   669                      CA=1;
   670                  }
   671                  buff = '  ' + lvl1_key[i] +':' + '\n';
   672                  fs.appendFileSync(dFile, buff);
   673  
   674                  // header 3
   675                  for ( k=0; k<lvl2_key.length; k++ ) {
   676                      if ( lvl2_key[k] == 'environment' ) {
   677                          lvl2_obj = lvl1_obj[lvl2_key[k]];
   678                          lvl3_key = Object.keys(lvl2_obj);
   679                          //console.log('lvl2_obj: ', lvl2_obj);
   680                          //console.log('lvl3_key: ', lvl3_key);
   681  
   682                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   683                          fs.appendFileSync(dFile, buff);
   684  
   685                          // header 4
   686                          for ( m=0; m< lvl3_key.length; m++ ) {
   687                              buff = '  ' + '    - ' + lvl3_key[m] + '=' +lvl2_obj[lvl3_key[m]] + '\n';
   688                              fs.appendFileSync(dFile, buff);
   689  
   690                          }
   691                      } else if ( ( lvl2_key[k] == 'image' ) || ( lvl2_key[k] == 'command' ) || ( lvl2_key[k] == 'working_dir' )
   692                              || ( lvl2_key[k] == 'restart') || ( lvl2_key[k] == 'container_name') || ( lvl2_key[k] == 'tty') ) {
   693                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + lvl1_obj[lvl2_key[k]] + '\n';
   694                          fs.appendFileSync(dFile, buff);
   695  
   696                      } else if ( ( lvl2_key[k] == 'ports' ) || ( lvl2_key[k] == 'links' ) || ( lvl2_key[k] == 'volumes' )
   697                              || ( lvl2_key[k] == 'depends_on' ) ){
   698                          var lvl2_obj = lvl1_obj[lvl2_key[k]];
   699                          //console.log('lvl2_obj: %d ', lvl2_obj.length, lvl2_obj);
   700  
   701                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   702                          fs.appendFileSync(dFile, buff);
   703  
   704                          // header 4
   705                          for ( m=0; m< lvl2_obj.length; m++ ) {
   706                              buff = '  ' + '    - ' +lvl2_obj[m] + '\n';
   707                              fs.appendFileSync(dFile, buff);
   708  
   709                          }
   710  
   711                      } else {
   712                          buff = '  ' + '  ' + lvl2_key[k] + ': ' + '\n';
   713                          fs.appendFileSync(dFile, buff);
   714  
   715                          buff = '  ' + '    - ' + lvl1_obj[lvl2_key[k]] + '\n';
   716                          fs.appendFileSync(dFile, buff);
   717  
   718                      }
   719                  }
   720                  // add a blank line
   721                  buff = '\n';
   722                  fs.appendFileSync(dFile, buff);
   723  
   724              }
   725          }
   726      }
   727  }