un-cli 0.0.82 → 0.0.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/index.mjs +304 -15
  2. package/package.json +1 -1
  3. package/un.mjs +3 -3
  4. package/cmd.txt +0 -2
package/index.mjs CHANGED
@@ -7,7 +7,7 @@ import { AdminLog } from "./adminlog.mjs"
7
7
  import logger from "./logger.mjs"
8
8
  import fetch from "node-fetch"
9
9
  //update version
10
- let version = "0.0.82";
10
+ let version = "0.0.84";
11
11
  const GENERATE_TOKEN_TIME_MIN = 30;
12
12
 
13
13
  let rl = null;
@@ -170,6 +170,7 @@ const inputs = {
170
170
  "topology --disable" : "Disable topology",
171
171
  "topology --enable" : "Enable topology",
172
172
  "topology --validate" : "Validate topology (full extent)",
173
+ "update subnetworks --subnetwork": "Update the input subnetwork synchronously",
173
174
  "update subnetworks --all": "Update all dirty subnetworks synchronously",
174
175
  "update subnetworks --deleted": "Update all deleted dirty subnetworks synchronously",
175
176
  "update subnetworks --all --async": "Update all dirty subnetworks asynchronously",
@@ -178,9 +179,15 @@ const inputs = {
178
179
  "export subnetworks --deleted": "Export all subnetworks with ACK that are deleted ",
179
180
  "updateisconnected": "Run update is connected ",
180
181
  "versions": "List all versions available to the current logged in user.",
182
+ "versions --summary": "Summary of versions.",
183
+ "versions --unreconciled": "List all versions that haven't been reconciled.",
184
+ "versions --version <version name>": "List the input version info",
181
185
  "reconcile --version <version name>": "Reconcile the input version synchronously",
182
- "reconcile --all": "Reconcile all versions available to the current user synchronously",
183
- "reconcile --all --async": "Reconcile all versions available to the current user asynchronously",
186
+ "reconcile --withpost --version <version name>": "Reconcile & Post the input version synchronously, oldest common ancestor first",
187
+ "reconcile --all": "Reconcile all versions available to the current user synchronously, oldest common ancestor first",
188
+ "reconcile --all --withpost": "Reconcile and post all versions available to the current user synchronously, oldest common ancestor first",
189
+ "reconcile --all --withpost --async": "Reconcile and post all versions available to the current user asynchronously, oldest common ancestor first",
190
+ "reconcile --all --async": "Reconcile all versions available to the current user asynchronously, oldest common ancestor first",
184
191
  "count": "Lists the number of rows in all feature layers and tables.",
185
192
  "count --system": "Lists the number of rows in system layers.",
186
193
  "connect --service": "Connects to the another service",
@@ -233,23 +240,100 @@ const inputs = {
233
240
 
234
241
  console.table(serviceDef)
235
242
  },
243
+
244
+
236
245
 
237
- "^versions$": async () => {
246
+ "^versions --version": async (input) => {
247
+
238
248
 
249
+ const inputParam = input.match(/--version .*/gm)
250
+ let versionName = null;
251
+ if (inputParam != null && inputParam.length > 0)
252
+ versionName = inputParam[0].replace("--version ", "")
253
+
254
+
255
+ let versions = await un.versions();
256
+ versions.versions = versions.versions.filter ( v => v.versionName.toString().toUpperCase() == versionName.toUpperCase())
257
+
258
+
259
+ if (versions.versions.length === 0) {
260
+ logger.info("No versions found.")
261
+ return;
262
+ }
263
+ const subs = versions.versions.sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) ). map( (a) => {
264
+ return {"versionName": a.versionName, "Id": a.versionId, "guid" : a.versionGuid, "modified": new Date(a.modifiedDate), "common": a.commonAncestorDate ? new Date( a.commonAncestorDate) : 'N/A' , "reconciled": a.reconcileDate ? new Date(a.reconcileDate) : 'N/A'};
265
+ })
266
+
267
+ console.table(subs)
268
+ const rowCount = subs.length;
269
+ logger.info (`${numberWithCommas(rowCount)} rows returned.`)
270
+ },
271
+
272
+
273
+
274
+ "^versions --unreconciled$": async () => {
239
275
  const versions = await un.versions();
240
276
  if (versions.versions.length === 0) {
241
277
  logger.info("No versions found.")
242
278
  return;
243
279
  }
244
- const subs = versions.versions.map( (a) => {
245
- return {"versionName": a.versionName, "Id": a.versionId, "guid" : a.versionGuid, "created": a.creationDate, "modified": a.modifiedDate, "access": a.access};
246
- })
280
+
281
+ const subs = versions.versions.filter( a => a.reconcileDate == null ).sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) ). map( (a) => {
282
+ return {"versionName": a.versionName, "Id": a.versionId, "guid" : a.versionGuid, "modified": new Date(a.modifiedDate), "common": a.commonAncestorDate ? new Date( a.commonAncestorDate) : 'N/A' , "reconciled": a.reconcileDate ? new Date(a.reconcileDate) : 'N/A'};
283
+ })
284
+
285
+ console.table(subs)
286
+ const rowCount = subs.length;
287
+ logger.info (`${numberWithCommas(rowCount)} rows returned.`)
288
+ },
289
+
290
+ "^versions$": async () => {
291
+ const versions = await un.versions();
292
+ if (versions.versions.length === 0) {
293
+ logger.info("No versions found.")
294
+ return;
295
+ }
296
+ const subs = versions.versions.sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) ). map( (a) => {
297
+ return {"versionName": a.versionName, "Id": a.versionId, "guid" : a.versionGuid, "modified": new Date(a.modifiedDate), "common": a.commonAncestorDate ? new Date( a.commonAncestorDate) : 'N/A' , "reconciled": a.reconcileDate ? new Date(a.reconcileDate) : 'N/A'};
298
+ })
247
299
 
248
300
  console.table(subs)
249
301
  const rowCount = subs.length;
250
302
  logger.info (`${numberWithCommas(rowCount)} rows returned.`)
251
303
  },
252
304
 
305
+
306
+ "^versions --summary$": async () => {
307
+ /*
308
+ total versions,
309
+ total unreconciled versions
310
+ total versions behind default
311
+ */
312
+ const versions = await un.versions();
313
+ if (versions.versions.length === 0) {
314
+ logger.info("No versions found.")
315
+ return;
316
+ }
317
+
318
+ const summary = {
319
+ "totalVersions": 0,
320
+ "unreconciledVersions": 0,
321
+ "versionsBehindDefault": 0,
322
+ "defaultMoment": 0
323
+ }
324
+
325
+ const defaultVersion = versions.versions.filter(v => v.versionName.toString().toUpperCase() === "SDE.DEFAULT")[0];
326
+
327
+ summary.totalVersions = versions.versions.length;
328
+
329
+ summary.unreconciledVersions = versions.versions.filter( a => a.reconcileDate == null ).length
330
+
331
+ summary.versionsBehindDefault = versions.versions.filter( a => defaultVersion.modifiedDate > a?.commonAncestorDate ).length
332
+
333
+ summary.defaultMoment = (new Date(defaultVersion.modifiedDate)).toString()
334
+ console.table(summary)
335
+ },
336
+
253
337
 
254
338
  "^reconcile --version": async (input) => {
255
339
 
@@ -258,8 +342,14 @@ const inputs = {
258
342
  if (inputParam != null && inputParam.length > 0)
259
343
  versionName = inputParam[0].replace("--version ", "")
260
344
 
261
- const versions = await un.versions();
345
+ let versions = await un.versions();
346
+ versions.versions = versions.versions.filter ( v => v.versionName.toString().toUpperCase() == versionName.toUpperCase())
262
347
 
348
+ if (versions.versions.length ==0 )
349
+ {
350
+ logger.info (`Version not found ${versionName}`)
351
+ return;
352
+ }
263
353
  for (let v = 0; v < versions.versions.length; v++)
264
354
  {
265
355
  if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
@@ -271,19 +361,55 @@ const inputs = {
271
361
  break;
272
362
  }
273
363
 
364
+ }
365
+
366
+ logger.info (`Reconciled ${versionName}`)
367
+ },
368
+
369
+
370
+
371
+ "^reconcile --withpost --version": async (input) => {
372
+
373
+ const inputParam = input.match(/--version .*/gm)
374
+ let versionName = null;
375
+ if (inputParam != null && inputParam.length > 0)
376
+ versionName = inputParam[0].replace("--version ", "")
377
+
378
+ let versions = await un.versions()
379
+ versions.versions = versions.versions.filter ( v => v.versionName.toString().toUpperCase() == versionName.toUpperCase())
380
+
381
+ if (versions.versions.length ==0 )
382
+ {
383
+ logger.info (`Version not found ${versionName}`)
384
+ return;
385
+ }
386
+
387
+ for (let v = 0; v < versions.versions.length; v++)
388
+ {
389
+ if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
390
+ if (versions.versions[v].versionName.toString().toUpperCase() == versionName.toUpperCase()) {
391
+ logger.info (`Reconciling and Posting version ${versions.versions[v].versionName} Common Ancestor ${new Date(versions.versions[v].commonAncestorDate)} ...`)
392
+
393
+ const result = await un.reconcile(versions.versions[v].versionGuid, true, false, true, false);
394
+ logger.info(JSON.stringify(result))
395
+ break;
396
+ }
397
+
274
398
  }
275
- logger.info (`Reconciled ${versionName}.`)
399
+ logger.info (`Reconciled and Posted ${versionName}.`)
276
400
  },
277
401
 
402
+
278
403
 
279
404
  "^reconcile --all$": async () => {
280
405
 
281
- const versions = await un.versions();
406
+ let versions = await un.versions()
407
+ versions.versions = versions.versions.sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) )
282
408
 
283
409
  for (let v = 0; v < versions.versions.length; v++)
284
410
  {
285
411
  if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
286
- logger.info (`Reconciling version ${versions.versions[v].versionName} ...`)
412
+ logger.info (`Reconciling version ${versions.versions[v].versionName} Common Ancestor ${new Date(versions.versions[v].commonAncestorDate)} ...`)
287
413
 
288
414
  const result = await un.reconcile(versions.versions[v].versionGuid, false, false, true, false);
289
415
  logger.info(JSON.stringify(result))
@@ -292,14 +418,33 @@ const inputs = {
292
418
  logger.info (`Reconciled ${numberWithCommas(rowCount)} versions.`)
293
419
  },
294
420
 
421
+
422
+ "^reconcile --all --withpost$": async () => {
423
+
424
+ let versions = await un.versions()
425
+ versions.versions = versions.versions.sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) )
426
+
427
+ for (let v = 0; v < versions.versions.length; v++)
428
+ {
429
+ if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
430
+ logger.info (`Reconciling version ${versions.versions[v].versionName} Common Ancestor ${new Date(versions.versions[v].commonAncestorDate)} ...`)
431
+
432
+ const result = await un.reconcile(versions.versions[v].versionGuid, true, false, true, false);
433
+ logger.info(JSON.stringify(result))
434
+ }
435
+ const rowCount = versions.versions.length;
436
+ logger.info (`Reconciled ${numberWithCommas(rowCount)} versions.`)
437
+ },
438
+
295
439
  "^reconcile --all --async$": async () => {
296
440
  //async
297
- const versions = await un.versions();
441
+ let versions = await un.versions()
442
+ versions.versions = versions.versions.sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) )
298
443
 
299
444
  for (let v = 0; v < versions.versions.length; v++)
300
445
  {
301
446
  if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
302
- logger.info (`Reconciling version ${versions.versions[v].versionName} ...`)
447
+ logger.info (`Reconciling version ${versions.versions[v].versionName} Common Ancestor ${new Date(versions.versions[v].commonAncestorDate)} ...`)
303
448
 
304
449
  const result = await un.reconcile(versions.versions[v].versionGuid, false, false, true, true);
305
450
  logger.info(JSON.stringify(result))
@@ -308,7 +453,23 @@ const inputs = {
308
453
  logger.info (`Reconciled ${numberWithCommas(rowCount)} versions.`)
309
454
  },
310
455
 
311
-
456
+ "^reconcile --all --withpost --async$": async () => {
457
+ //async
458
+ let versions = await un.versions()
459
+ versions.versions = versions.versions.sort ( (a,b)=> (a?.commonAncestorDate - b?.commonAncestorDate) )
460
+
461
+ for (let v = 0; v < versions.versions.length; v++)
462
+ {
463
+ if (versions.versions[v].versionName.toString().toUpperCase() === "SDE.DEFAULT") continue;
464
+ logger.info (`Reconciling & Posting version ${versions.versions[v].versionName} Common Ancestor ${new Date(versions.versions[v].commonAncestorDate)} ...`)
465
+
466
+ const result = await un.reconcile(versions.versions[v].versionGuid, true, false, true, true);
467
+ logger.info(JSON.stringify(result))
468
+ }
469
+ const rowCount = versions.versions.length;
470
+ logger.info (`Reconciled & Posted ${numberWithCommas(rowCount)} versions.`)
471
+ },
472
+
312
473
  "^versions --disconnect$": async () => {
313
474
  //disconnect all versions
314
475
  const versions = await un.versions();
@@ -521,6 +682,40 @@ const inputs = {
521
682
  logger.info (`${numberWithCommas(rowCount)} rows returned.`)
522
683
  },
523
684
 
685
+
686
+
687
+
688
+
689
+ "^update subnetworks --subnetwork" : async (input) => {
690
+
691
+
692
+ const inputParam = input.match(/--subnetwork .*/gm)
693
+ let subnetworkName = null;
694
+ if (inputParam != null && inputParam.length > 0)
695
+ subnetworkName = inputParam[0].replace("--subnetwork ", "")
696
+
697
+
698
+
699
+ let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "1=1 AND subnetworkname = '" + subnetworkName + "'","domainnetworkname,tiername,subnetworkname");
700
+ logger.info(`Discovered ${subnetworks.features.length} subnetworks.`);
701
+ for (let i = 0; i < subnetworks.features.length; i++) {
702
+ const f = subnetworks.features[i]
703
+ logger.info("Updating Subnetwork " + v(f.attributes,"subnetworkName"));
704
+
705
+ const fromDate = new Date();
706
+
707
+ const subnetworkResult = await un.updateSubnetworks(v(f.attributes,"domainNetworkName"), v(f.attributes,"tierName"), v(f.attributes,"subnetworkName"),false);
708
+
709
+ //code
710
+
711
+ const toDate = new Date();
712
+ const timeEnable = toDate.getTime() - fromDate.getTime();
713
+ subnetworkResult.duration = numberWithCommas(Math.round(timeEnable)) + " ms"
714
+
715
+
716
+ logger.info(`Result ${JSON.stringify(subnetworkResult)}`)
717
+ }
718
+ },
524
719
  "^update subnetworks --deleted$" : async () => {
525
720
  logger.info("Querying all subnetworks that are dirty and deleted.");
526
721
  let subnetworks = await un.queryDistinct(500002, "domainnetworkname,tiername,subnetworkname", "isdirty=1 and isdeleted=1","domainnetworkname,tiername,subnetworkname");
@@ -1007,7 +1202,19 @@ const inputs = {
1007
1202
  },
1008
1203
 
1009
1204
 
1010
-
1205
+ "^reconcilelogs --age" : async input => {
1206
+ const topLogCount = 1000;
1207
+ const pageSize = 10000
1208
+
1209
+ const inputParam = input.match(/--age .*/gm)
1210
+ let mins = 30; //query logs for the last 30 minutes
1211
+ if (inputParam != null && inputParam.length > 0)
1212
+ mins = inputParam[0].replace("--age ", "")
1213
+
1214
+
1215
+ reconcileLogs(mins, parameters.service)
1216
+
1217
+ },
1011
1218
  "^validatelogs --age": async input => {
1012
1219
 
1013
1220
  const topLogCount = 1000;
@@ -1553,6 +1760,88 @@ function decodeHTMLEntities (x) {
1553
1760
  }
1554
1761
 
1555
1762
 
1763
+
1764
+ async function reconcileLogs (mins, service) {
1765
+
1766
+
1767
+ parameters.service = service
1768
+
1769
+
1770
+ console.log(`Querying reconcile logs for ${parameters.service} for the last ${mins} minutes ...`)
1771
+
1772
+ //startTime is the most recent
1773
+ //endTime is the oldest
1774
+
1775
+
1776
+ //page query the admin log , search for /applyEdits logs by methodname
1777
+ let allMessages = await adminLog.query(mins, parameters.service, [102003,102024,102023], "", "DEBUG")
1778
+
1779
+
1780
+
1781
+ //build out the dictionary, key is request id, value is another dictionary
1782
+ const queryLogs = {}
1783
+ //sort by time
1784
+ allMessages = allMessages.sort ( (m1, m2) => m2.time - m1.time )
1785
+ allMessages.forEach (m => {
1786
+
1787
+ if (!queryLogs[m.requestID])
1788
+ queryLogs[m.requestID] = {"message": "Time,Method,Elapsed_ms,Message"}
1789
+
1790
+ queryLogs[m.requestID].message += "\r\n" + m.time + "," + m.methodName + "," + Math.round(m.elapsed*1000) + "," + m.message
1791
+
1792
+ //get elapsed
1793
+ //check for async (method GPReconcileVersionAsync::Execute)
1794
+ //sync
1795
+ //VersionManagementServer::HandleREST_ReconcileOperation
1796
+ //message Returned moment:
1797
+ if (m.message.indexOf("Returned moment: ")> -1 &&
1798
+ ( m.methodName.indexOf("VersionManagementServer::HandleREST_ReconcileOperation") > -1 ||
1799
+ m.methodName.indexOf("GPReconcileVersionAsync::Execute") > -1
1800
+ )
1801
+ )
1802
+ {
1803
+ queryLogs[m.requestID].elapsed = m.elapsed
1804
+ queryLogs[m.requestID].source = m.source.replace(".MapServer", "")
1805
+ queryLogs[m.requestID].user = m.user
1806
+ queryLogs[m.requestID].time = m.time
1807
+ queryLogs[m.requestID].requestID = m.requestID
1808
+ queryLogs[m.requestID].methodName = m.methodName
1809
+
1810
+ }
1811
+
1812
+ if (m.message.indexOf("EndReconcile;") > -1)
1813
+ {
1814
+ queryLogs[m.requestID].gdbVersion = m.message.replace("EndReconcile;","")
1815
+
1816
+
1817
+ }
1818
+
1819
+
1820
+
1821
+ })
1822
+
1823
+ allMessages = []
1824
+
1825
+ Object.keys(queryLogs).forEach(k =>
1826
+ {
1827
+ const m = queryLogs[k]
1828
+ if (m.methodName)
1829
+ allMessages.push(m)
1830
+
1831
+ })
1832
+
1833
+
1834
+
1835
+ console.log ("Filtering messages...")
1836
+
1837
+ allMessages = filterMessages(allMessages)
1838
+ .sort( (m1,m2) => Math.round(m2.elapsed*1000) -Math.round(m1.elapsed*1000))
1839
+ console.table(allMessages)
1840
+
1841
+ }
1842
+
1843
+
1844
+
1556
1845
  function printFishnet(fishnet) {
1557
1846
 
1558
1847
  //y is flipped x is ok
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "un-cli",
3
- "version": "0.0.82",
3
+ "version": "0.0.84",
4
4
  "description": "Command line interface for working with ArcGIS Utility Network Extension",
5
5
  "main": "index.mjs",
6
6
  "bin": {
package/un.mjs CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node --experimental-modules
2
-
3
- import {run} from "./index.mjs"
1
+ #!/usr/bin/env node --experimental-modules
2
+
3
+ import {run} from "./index.mjs"
4
4
  run();
package/cmd.txt DELETED
@@ -1,2 +0,0 @@
1
- arlogs --age 10
2
- exit