summaryrefslogtreecommitdiff
path: root/src/com/nis/nmsclient/thread/task/AgentCommand.java
blob: c165fef577c3d45ac5f48d2d9a26fc0473bc6f48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
 package com.nis.nmsclient.thread.task;

import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import net.sf.json.JSONObject;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.nis.nmsclient.common.Common;
import com.nis.nmsclient.common.Contants;
import com.nis.nmsclient.common.VersionCfg;
import com.nis.nmsclient.model.CommandPO;
import com.nis.nmsclient.model.ParamBackup;
import com.nis.nmsclient.model.ParamCmdExec;
import com.nis.nmsclient.model.ParamCoverUpdate;
import com.nis.nmsclient.model.ParamUpgrade;
import com.nis.nmsclient.model.ReturnFilePO;
import com.nis.nmsclient.thread.socket.CommonSocket;
import com.nis.nmsclient.thread.socket.SSLClient;
import com.nis.nmsclient.util.CompressFileMgr;
import com.nis.nmsclient.util.FileUtil;
import com.nis.nmsclient.util.FileWrUtil;
import com.nis.nmsclient.util.ProcessUtil;
import com.nis.nmsclient.util.Utils;

public class AgentCommand {
	static Logger logger = Logger.getLogger(AgentCommand.class);
	public static final int RESULT_OK = 0;
	public static final int RESULT_FAIL = 1;
	public static final int RESULT_SEND_OK = 40;
	public static final int RESULT_SEND_FAIL = 41;
	public static final int RESULT_KILL_OK = 50;
	public static final int RESULT_KILL_FAIL = 51;
	public static final int RESULT_BACKUP_OK = 60;
	public static final int RESULT_BACKUP_FAIL = 61;
	public static final int RESULT_UPDATE_OK = 70;
	public static final int RESULT_UPDATE_FAIL = 71;
	public static final int RESULT_START_OK = 80;
	public static final int RESULT_START_FAIL = 81;
	public static final int RESULT_RECOVER_OK = 90;
	public static final int RESULT_RECOVER_FAIL = 91;
	public static final int MISSION_CANCEL_CREATE = 5;//任务准备撤消
	public static final int MISSION_CANCEL_START = 6;//任务撤消中
	public static final int MISSION_CANCEL_FINISH = 7;//任务撤消完成
	
	private static final String RESULT_SEPRATOR = Contants.COMMON_MSG_SEPRATOR;
	private static final String RESULT_SEPRATOR_SPLIT = Contants.COMMON_MSG_SEPRATOR_SPLIT;
	
	public static enum UpgradeSteps {
		upgrade_agent, upgrade_other,
		upgrade_server,	upgrade_kill_process,
		upgrade_backup, upgrade_update,
		upgrade_start, upgrade_recover,
		upgrade_exec, single_exec;
	}
	public static final String PARAM_SEPRATOR = "@&##&@";
	
	// NC/DC升级锁,确保NC与DC不同时升级
	private static final Byte[] upgradeLock = new Byte[0];
	
	private CommandPO command;
	private Thread thread;
	
	public AgentCommand(CommandPO command) {
		super();
		this.command = command;
	}
	
	public boolean exec(){
		Date execTime = new Date();
//		String resultDesc = "执行失败";
//		String resultDesc = "Failure to execute";
		String resultDesc = "i18n_client.AgentCommand.execFail_n81i";
		long resultState = RESULT_FAIL;
		boolean isServer = false;
		try {
			String commandParam = command.getCommandParam();
			if(commandParam==null || "".equals(commandParam)){
//				resultDesc = "执行失败:命令参数为空";
//				resultDesc = "Execution failure: command parameters are empty";
				resultDesc = "i18n_client.AgentCommand.execFailDesc1_n81i";
				resultState = RESULT_FAIL;
//				logger.warn(resultDesc);//i18nlog
			} else {
				logger.debug("commandParam 1--" + commandParam);
				//2012-4-28 任务参数中对路径的格式化将在界面上进行,原因此处会对转义字符的\也转换为/,故replace("\\", "/")去掉
				commandParam = commandParam.trim().replaceAll("[\n\t\r]","");//.replace("\\", "/");//[\\s*\n\t\r]
				logger.debug("commandParam 2--" + commandParam);
				String[] params = commandParam.trim().split(PARAM_SEPRATOR);
				if (params != null && params.length >= 1) {
					for(int i=0; i<params.length; i++){
						params[i] = params[i].trim();
					}
					UpgradeSteps step = Enum.valueOf(UpgradeSteps.class,command.getCommandName());
					String resultStr = "";
					switch (step) {
					case upgrade_server:// 命令参数,以;分隔的一个CommandForUpgrade对象的Json字符串
						isServer = true;
						synchronized (upgradeLock) {//DC升级时锁,确保不与NC同时升级
							resultStr = upgradeOther(params, command
									.getSrcPath(), command.getExecState(), command
									.getExecId(), command.getExecVersion(),
									isServer);
						}
						break;
					case upgrade_other:// 命令参数,以;分隔的多个CommandForUpgrade对象的Json字符串
						resultStr = upgradeOther(params, command
								.getSrcPath(), command.getExecState(), command
								.getExecId(), command.getExecVersion(),
								isServer);
						break;
					case upgrade_agent:// 命令参数,以;分隔的一个CommandForUpgrade对象的Json字符串
						//-- NC升级开始 关闭通讯
						Common.NC_UPGRADE_FLAG = true;
						synchronized (upgradeLock) {//NC升级时锁,确保不与DC同时升级
							resultStr = upgradeAgent(params[0], command
									.getSrcPath(), command.getExecState(), command
									.getExecId(), command.getExecVersion());
						}
						//-- NC升级完成 打开通讯
						Common.NC_UPGRADE_FLAG = false;
						break;
					case upgrade_kill_process:// 命令参数, 以;分隔的多个存放进程ID的文件
						resultStr = killProcessCmd(params);
						break;
					case upgrade_backup:// 命令参数,以;分隔的多个Backup对象的Json字符串
						ParamBackup[] backups = new ParamBackup[params.length];
						for (int i = 0; i < params.length; i++) {
							logger.debug("backupCmd-->param: " + params[i]);
							ParamBackup backup = (ParamBackup) JSONObject
									.toBean(JSONObject.fromObject(params[i]),
											ParamBackup.class);
							backups[i] = backup;
						}
						resultStr = backupCmd(backups, null, command
								.getExecId());
						break;
					case upgrade_update:// 命令参数,以;分隔多个CoverUpdate对象的Json字符串
					case upgrade_recover:// 命令参数,以;分隔多个CoverUpdate对象的Json字符串
						ParamCoverUpdate[] updates = new ParamCoverUpdate[params.length];
						for (int i = 0; i < params.length; i++) {
							logger.debug("updateCmd-->param: " + params[i]);
							ParamCoverUpdate update = (ParamCoverUpdate) JSONObject
									.toBean(JSONObject.fromObject(params[i]),
											ParamCoverUpdate.class);
							updates[i] = update;
						}
						resultStr = updateCmd(updates);
						break;
					case upgrade_start:// 命令参数,以;分隔多个CmdExec对象的Json字符串
					case upgrade_exec:// 可执行命令
						List<ParamCmdExec> execList = new ArrayList<ParamCmdExec>();
						for (String param : params) {
							logger.debug("startCmd-->param: " + param);
							ParamCmdExec exec = (ParamCmdExec) JSONObject
									.toBean(JSONObject.fromObject(param),
											ParamCmdExec.class);
							execList.add(exec);
						}
						resultStr = startCmd(execList, execTime, false, command.getExecState());
						break;
					case single_exec:// 单次执行命令,命令参数,以;分隔多个CmdExec对象的Json字符串
						List<ParamCmdExec> cmdExecList = new ArrayList<ParamCmdExec>();
						for (String param : params) {
							logger.debug("singleExecCmd-->param: " + param);
							ParamCmdExec exec = (ParamCmdExec) JSONObject
									.toBean(JSONObject.fromObject(param),
											ParamCmdExec.class);
							cmdExecList.add(exec);
						}
						resultStr = singleExecCmd(cmdExecList, execTime, command.getExecState());
						break;

					default:
//						resultDesc = "执行失败,不存在该命令";
//						resultDesc = "The execution failed and the command did not exist";
						resultDesc = "i18n_client.AgentCommand.execFailDesc2_n81i";
						resultState = RESULT_FAIL;
//						logger.warn(resultDesc);//i18nlog
						break;
					}

					String[] res = resultStr.split(RESULT_SEPRATOR_SPLIT);
					if (res != null && res.length >= 2) {
						resultState = Long.parseLong(res[0]);
						resultDesc = res[1];
					}
				} else {
//					resultDesc = "执行失败:命令参数不正确<" + commandParam + ">";
//					resultDesc = "Execution failure: incorrect command parameters<" + commandParam + ">";
					resultDesc = "i18n_client.AgentCommand.execFailDesc3_n81i<" + commandParam + ">";
					resultState = RESULT_FAIL;
//					logger.warn(resultDesc);//i18nlog
				}

			}
		} catch (Exception e) {
//			resultDesc = "执行失败:出现异常,详细信息请查看日志";
//			resultDesc = "Execution failure: abnormal. Please check log for details";
			resultDesc = "i18n_client.AgentCommand.execFailDesc4_n81i";
			resultState = RESULT_FAIL;
//			logger.error(resultDesc + "\n" + Utils.printExceptionStack(e));//i18nlog
		}
		
		// 发送信息
		TaskResultOper.sendTaskResult(command.getExecId(), command.getExecType(),
				resultState, resultDesc, "", execTime, new Date(), isServer, command.getIsLoop());
		
		return (resultState % 2 == 1) ? false : true;
	}
	
	/**
	 * Agent原生支持命令,Agent自身升级
	 * @param params 升级任务的参数
	 * @param upgradePath 升级文件存放路径
	 * @param stepState 任务执行步骤标志
	 * @param curVersion 当前升级版本
	 * @param reVersion 恢复到的版本
	 * @return
	 */
	public String upgradeAgent(String param, String upgradePath, long stepState, Long curVersion, Long reVersion) {
		logger.info("NC升级开始……");
//		String resultDesc = "执行失败";
//		String resultDesc = "Failure to execute";
		String resultDesc = "i18n_client.AgentCommand.execFail_n81i";
		int resultState = RESULT_FAIL;
		File tempUpdateDir = null;
		try {
			Long curVer = Long.parseLong(VersionCfg
					.getValue(VersionCfg.NAGENT_VERSION));
			if (curVer >= curVersion) {
//				resultDesc = "执行失败:当前Agent版本为最新";
//				resultDesc = "Execution failure: the current Agent version is the latest";
				resultDesc = "i18n_client.AgentCommand.execFailDesc5_n81i";

				logger.info("NC升级结果描述信息 >> " + resultDesc);
				logger.info("NC升级结束……");
				return resultState + RESULT_SEPRATOR + resultDesc;
			}

			/**
			 * 1、解析命令参数,包装到对象
			 */
			logger.debug("upgradeAgent-->param: " + param);
			ParamUpgrade cfu = (ParamUpgrade) JSONObject.toBean(
					JSONObject.fromObject(param), ParamUpgrade.class);
			//Agent的布署路径
			String homePath = new File(Contants.SYSTEM_PATH).getParent();
			/*
			 * 设置启动文件和PID文件
			 */
			String pidFile = Contants.localAgentPidFile;
			String startFile = null;
			String os = System.getProperty("os.name");
			if (os.startsWith("Windows")) {
				startFile = homePath + File.separator + "script" + File.separator + "restart.bat";
				if(!new File(startFile).exists()){
					startFile = Contants.SYSTEM_PATH + File.separator + "restart.bat";
				}
			} else if (os.startsWith("Linux")) {
				startFile = Contants.SYSTEM_PATH + File.separator + "restart.sh";
			}
			cfu.setStartupFile(new File(startFile).getCanonicalPath());
			cfu.setPidFile(new File(pidFile).getCanonicalPath());
			/*
			 * 处理覆盖目录
			 */
			if(cfu.getCover()!=null && !"".equals(cfu.getCover().trim())){
				cfu.setCover(getFilePath(cfu.getCover(), homePath));
			}else{//如果没有参数覆盖目录,则按默认Agent的布署路径
				cfu.setCover(homePath);
			}
			String backupOppDir = new File(cfu.getCover()).getCanonicalPath();
			
			logger.debug("AgentUpgrade homePath----" + homePath);
			logger.debug("AgentUpgrade restart file----" + cfu.getStartupFile());
			logger.debug("AgentUpgrade pid file----" + cfu.getPidFile());
			logger.debug("AgentUpgrade cover----" + cfu.getCover());
			
			/**
			 *  步骤2:判断是逆向任务还是正常升级,恢复版本不为空则为逆向任务,反之正常升级
			 */
			boolean next = true;
			String srcDesc = null;
			String destDesc = null;
			File upgradeFile = null;
			File coverDirFile = null;
			if (command.getExecVersion() != null
					&& command.getExecVersion().longValue() > 0) {//恢复
				if(cfu.getRecoverys()==null || cfu.getRecoverys().length<=0){
//					resultDesc = "执行失败:恢复参数为空";
//					resultDesc = "Execution failure: recovery parameters are empty";
					resultDesc = "i18n_client.AgentCommand.execFailDesc6_n81i";
//					logger.info("NC升级结果描述信息 >> " + resultDesc);//i18nlog
					logger.info("NC升级结束……");
					return resultState + RESULT_SEPRATOR + resultDesc;
				}
				ParamCoverUpdate recover = cfu.getRecoverys()[0];
				cfu.setIsAbs(recover.getIsAbs());
				//文件名称在此没有实际意义,只是为了下面验证时不为空
				cfu.setFileName(getRecoverSource(recover, reVersion));
				//-------必须先处理恢复目录,再处理恢复源文件,恢复源文件会用到恢复目录的名称,否则恢复目录如果是(.)这样的相对路径就会出问题
				//恢复目录若是相对,则相对升级的覆盖目录,若是绝对,则不变
				recover.setCover(getFilePath(recover.getCover(), cfu.getCover()));
//				destDesc = "恢复目录";
//				destDesc = "Recovery Directory";
				destDesc = "i18n_client.AgentCommand.destDesc_n81i";
				coverDirFile = new File(recover.getCover());
//				srcDesc = "恢复源文件";
//				srcDesc = "Recovery Source File";
				srcDesc = "i18n_client.AgentCommand.srcDesc_n81i";
				upgradeFile = new File(getRecoverSource(recover, reVersion));
				
				logger.debug("AgentUpgrade recover cover----" + recover.getCover());
			} else {
				// 处理是否创建覆盖目录
				cfu.setIsCreateCover(handleYesOrNoField(cfu.getIsCreateCover()));
//				srcDesc = "升级文件";
//				srcDesc = "Upgrade File";
				srcDesc = "i18n_client.AgentCommand.srcDesc_n81i";
				upgradeFile = new File(getFilePath(cfu.getFileName(), upgradePath));
//				destDesc = "更新目录";
//				destDesc = "Update Table Of Contents";
				destDesc = "i18n_client.AgentCommand.destDesc_n81i";
				coverDirFile = new File(cfu.getCover());
			}
			if(coverDirFile.isFile()){
				coverDirFile = coverDirFile.getParentFile();
			}
			// 处理解压时按绝对路径,还是相对路径, 只对LInux起作用, 默认按相对
			boolean isAbs = false;
			if ("Y".equals(handleYesOrNoField(cfu.getIsAbs()))) {
				isAbs = true;
			}
			/**
			 * 判断参数指定的升级文件与覆盖目录是否存在
			 */
			if (cfu.getFileName() == null
					|| cfu.getFileName().trim().length() <= 0) {
//				resultDesc = "执行失败:" + srcDesc + "为空";
//				resultDesc = "Failure to execute:" + srcDesc + "is empty";
				resultDesc = "i18n_client.AgentCommand.execFail_n81i:" + srcDesc + "i18n_client.AgentCommand.execFailDesc7_n81i";
				resultState = RESULT_FAIL;
//				logger.debug(resultDesc);//i18nlog
				next = false;
			} else if (!upgradeFile.exists()) {
//				resultDesc = "执行失败:" + srcDesc + "不存在--" + upgradeFile.getAbsolutePath();
//				resultDesc = "Failure to execute:" + srcDesc + "non-existent--" + upgradeFile.getAbsolutePath();
				resultDesc = "i18n_client.AgentCommand.execFail_n81i:" + srcDesc + "i18n_client.AgentCommand.execFailDesc8_n81i--" + upgradeFile.getAbsolutePath();
				resultState = RESULT_FAIL;
//				logger.debug(resultDesc + "--" + upgradeFile.getAbsolutePath());//i18nlog
				next = false;
			}
			// 判断用户和密码是否正确
			/*if (!ProcessUtil.checkUserPass(cfu.getUsername(), cfu.getParam1())) {
				resultDesc = "执行失败:用户名或密码不正确;";
				resultState = RESULT_FAIL;
				logger.debug(resultDesc);
				next = false;
			}*/
			// 判断用户名是否正确
			if(!ProcessUtil.checkUserOrGroupExist(cfu.getUsername(), null)){
//				resultDesc = "执行失败:属主不正确;";
//				resultDesc = "Failure of execution: the owner is not correct;";
				resultDesc = "i18n_client.AgentCommand.execFailDesc9_n81i;";
				resultState = RESULT_FAIL;
//				logger.debug(resultDesc);//i18nlog
				next = false;
			}
			boolean isCompressFile = false;
			if (next) {
				/**
				 * 判断覆盖目录是否存在:
				 * 1、必须判断:Window系统、或者Linux系统且不是压缩文件、或者Linux系统且是压缩文件且是相对路径
				 * 2、不用判断:Linux系统下源文件是压缩文件且绝对解压,该属性无效
				 */
				isCompressFile = CompressFileMgr.isCompressFile(upgradeFile);
				if (os.startsWith("Windows")
						|| (!os.startsWith("Windows") && !isCompressFile)
						|| (!os.startsWith("Windows") && isCompressFile && !isAbs)) {
					if (!coverDirFile.exists()
							&& "N".equalsIgnoreCase(cfu.getIsCreateCover())) {
//						resultDesc = "执行失败:" + destDesc + "不存在";
//						resultDesc = "Failure to execute:" + destDesc + "non-existent";
						resultDesc = "i18n_client.AgentCommand.execFail_n81i:" + destDesc + "i18n_client.AgentCommand.execFailDesc8_n81i";
						resultState = RESULT_FAIL;
//						logger.debug(resultDesc);//i18nlog
						next = false;
					} else if (!coverDirFile.exists()
							&& "Y".equalsIgnoreCase(cfu.getIsCreateCover())) {// Y
																				// 创建目录
						coverDirFile.mkdirs();
					}
				} else {
					coverDirFile = new File("/");
				}
			}
			/**
			 * 步骤3、对参数指定的备份目录进行备份
			 */
			boolean flag = false;
			String resultStr = "";
			if (next && (stepState > RESULT_OK && stepState < RESULT_BACKUP_OK)) {// 备份
				Date execTime = new Date();
				resultStr = this.backupCmd(cfu.getBackups(), backupOppDir, curVersion);
				String[] res = resultStr.split(RESULT_SEPRATOR_SPLIT);
				if (res != null && res.length >= 2) {
					resultState = Integer.parseInt(res[0]);
					resultDesc = res[1];
				}
				if (resultState == RESULT_OK) {// 备份成功,发送信息
					flag = true;
					resultState = RESULT_BACKUP_OK;
					TaskResultOper.sendTaskResult(command.getExecId(), command
							.getExecType(), resultState, resultDesc, "",
							execTime, new Date(), false, command.getIsLoop());
				} else {
					flag = false;
				}

			}
			
			/**
			 * 步骤4、覆盖并重启Agent
			 */
			if (next && flag) {// 解压成功,覆盖并重启Agent
				Date execTime = new Date();
				
				/**
				 * 4-1 发送重启请求
				 */
				TaskResultOper.sendTaskResult(command.getExecId(), command
//						.getExecType(), resultState, "正在覆盖并重启Agent", "",
//						.getExecType(), resultState, "Overlaying and restarting Agent", "",
						.getExecType(), resultState, "i18n_client.AgentCommand.coverRestart_n81i", "",
						execTime, new Date(), false, command.getIsLoop());
				
				// 判断是否解压升级文件,并放入临时目录
				tempUpdateDir = new File(Contants.localTempPath + File.separator
						+ "agent_updatedir_" + command.getExecId());
				if (upgradeFile.isDirectory()) {
					FileUtils.copyDirectoryToDirectory(upgradeFile, tempUpdateDir);
				} else {
					if (isCompressFile) {
						flag = new CompressFileMgr().decompressFile(
								upgradeFile.getAbsolutePath(), tempUpdateDir
										.getAbsolutePath(), false);
					} else {
						FileUtils.copyFileToDirectory(upgradeFile,tempUpdateDir);
					}
				}
				
				/**
				 * 4-2 删除文件,并写临时结果文件
				 */
				//准备临时结果文件内容,初始状态为升级失败
				String[] msgs = new String[1];
				msgs[0] = TaskResultOper.getTaskResultMsg(command
						.getExecId(), command.getExecType(),
//						(long) RESULT_FAIL, "升级失败", "", execTime, new Date(), command.getIsLoop());
//						(long) RESULT_FAIL, "Failure to upgrade", "", execTime, new Date(), command.getIsLoop());
						(long) RESULT_FAIL, "i18n_client.AgentCommand.upgradeFail_n81i", "", execTime, new Date(), command.getIsLoop());
				File resultFile = new File(TaskResultOper
						.getAgentUpgradeResultTempFile(command.getExecType(),
								command.getExecId()));
				if(!resultFile.getParentFile().exists()){
					resultFile.getParentFile().mkdirs();
				}
				// 删除指定的文件
				String delMsg = this.delete(cfu.getDelete(), coverDirFile.getAbsolutePath());
				// 将删除日志换行加入结果文件
				if(!StringUtils.isEmpty(delMsg)){
					msgs = new String[]{msgs[0], delMsg};
				}
				// 正式写入临时结果文件
				FileWrUtil.cfgFilePrinter(resultFile, Charset.defaultCharset().name(), msgs);

				/**
				 * 4-3 执行脚本(脚本中将覆盖操作的详细信息追加到结果文件;覆盖成功后将任务标识ID写入version.txt)
				 */
				List<ParamCmdExec> startList = new ArrayList<ParamCmdExec>();
				ParamCmdExec exec = new ParamCmdExec();
				exec.setExecCmd(cfu.getStartupFile());
				exec.setExecParams(new String[] { tempUpdateDir.getCanonicalPath(),
						coverDirFile.getCanonicalPath(),
						resultFile.getCanonicalPath() });
				exec.setExecResult(cfu.getPidFile());
				exec.setUsername(cfu.getUsername());
				exec.setParam1(cfu.getParam1());
				exec.setForceExec("Y");
				exec.setResidentFlag("Y");
				exec.setReturnFlag("N");
				startList.add(exec);
				resultStr = this.startCmd(startList, execTime, true, resultState);
				String[] res = resultStr.split(RESULT_SEPRATOR_SPLIT);
				if (res != null && res.length >= 2) {
					resultState = Integer.parseInt(res[0]);
					resultDesc = res[1];
				}
				if (resultState == RESULT_FAIL && resultFile.exists()) {// 如果失败直接返回结果,删除临时结果文件
					//resultFile.delete_bak();
					//使用删除文件公共方法
					FileUtil.delDir(resultFile);
					logger.debug("upgradeAgent delete file -- " + resultFile.getAbsolutePath());
					//FileUtil.checkParentDirExist(resultFile);
				}
			} else {
				if (stepState == RESULT_BACKUP_OK) {
//					resultDesc = "重启失败,手工启动成功";
//					resultDesc = "Restart failure and start success by hand";
					resultDesc = "i18n_client.AgentCommand.restartFail_n81i";
					resultState = RESULT_FAIL;
					String upgradeResultFile = TaskResultOper
							.getAgentUpgradeResultTempFile(command
									.getExecType(), command.getExecId());
					File resultFile = new File(upgradeResultFile);
					if (resultFile.exists()) {// 如果失败直接返回结果,删除临时结果文件
						//resultFile.delete_bak();
						//使用删除文件公共方法
						FileUtil.delDir(resultFile);
						logger.debug("upgradeAgent delete file 2 -- " + resultFile.getAbsolutePath());
						//FileUtil.checkParentDirExist(resultFile);
					}
				}

			}
		} catch (Exception e) {
//			resultDesc = "执行失败:出现异常," + e.getMessage() + ",详细信息请查看日志";
			resultDesc = "i18n_client.AgentCommand.execFailDesc10_n81i," + e.getMessage() + ",i18n_client.AgentCommand.execFailDesc10.showDetail_n81i";
			resultState = RESULT_FAIL;
			logger.error("NC upgrade exception:" + Utils.printExceptionStack(e));
		} finally {
			// 不能删除临时目录原因:覆盖操作在脚本中进行,可能出现脚本未运行完,临时目录被删除,这样覆盖操作就不能完成
			/*if(tempUpdateDir!=null && tempUpdateDir.exists()){
				try {
					FileUtils.deleteDirectory(tempUpdateDir);
					logger.debug("upgradeAgentNew-----finally delele tempUpdateDir = " + tempUpdateDir.getCanonicalPath());
					FileUtil.checkParentDirExist(tempUpdateDir);
				} catch (IOException e) {
				}
			}*/
		}
//		logger.info("NC升级结果描述信息 >> " + resultDesc);//i18nlog
		logger.info("NC升级结束……");
		
		return resultState + RESULT_SEPRATOR + resultDesc;
	}	 
	
	/**
	 * Agent原生支持命令,第三方升级
	 * @param params 升级任务的参数
	 * @param upgradePath 升级文件存放目录
	 * @param stepState 任务执行步骤标志
	 * @param curVersion 当前升级版本
	 * @param reVersion 恢复到的版本,如果是逆向任务即恢复时用到
	 * @param isServer 是否NmsServer升级
	 * @return
	 */
	public String upgradeOther(String[] params, String upgradePath, long stepState, long curVersion, Long reVersion, boolean isServer) {
//		String pre = "三方升级";
		String pre = "Three Party Upgrade";
		if (isServer) {// 如果是NmsServer升级,判断版本
//			pre = "DC升级";
			pre = "DC Upgrade";
		}
		logger.info(pre + "开始……");
//		String resultDesc = "执行失败";
		String resultDesc = "Failure to execute";
		int resultState = RESULT_FAIL;
		try {
			if(params==null || params.length==0){
//				resultDesc = "执行失败:参数为空";
//				resultDesc = "Execution failure: parameters are empty";
				resultDesc = "i18n_client.AgentCommand.execFailDesc11_n81i";
//				logger.info(pre + "结果描述信息 >> " + resultDesc);//i18nlog
				logger.info(pre + "结束……");
				return resultState + RESULT_SEPRATOR + resultDesc;
			}
			if (isServer) {// 如果是NmsServer升级,判断版本
				Long curVer = Long.parseLong(VersionCfg
						.getValue(VersionCfg.NSERVER_VERSION));
				if (curVer >= curVersion) {
//					resultDesc = "执行失败:当前Server版本为最新";
//					resultDesc = "Execution failure: the current Server version is the latest";
					resultDesc = "i18n_client.AgentCommand.execFailDesc12_n81i";
//					logger.info(pre + "结果描述信息 >> " + resultDesc);//i18nlog
					logger.info(pre + "结束……");
					return resultState + RESULT_SEPRATOR + resultDesc;
				}
				
			}
			/**
			 * 1、解析命令参数,包装到对象, 判断是否为逆向任务:
			 *       不是,判断所有参数指定的升级文件与覆盖目录是否存在;
			 *       是,设置默认强制执行并跳过判断
			 */
			boolean next = true;
			List<ParamUpgrade> cfuList = new ArrayList<ParamUpgrade>();
			for (String param : params) {
				if (param.trim().length() <= 0) {
					continue;
				}
				logger.debug("upgradeOther-->param: " + param);
				ParamUpgrade cfu = (ParamUpgrade) JSONObject.toBean(JSONObject
						.fromObject(param), ParamUpgrade.class);
				logger.debug("upgradeOther-->pidFile: " + cfu.getPidFile());
				
				// 判断用户和密码是否正确
				/*if (!ProcessUtil.checkUserPass(cfu.getUsername(), cfu.getParam1())) {
					resultDesc = "执行失败:用户名或密码不正确;";
					resultState = RESULT_FAIL;
					logger.debug(resultDesc);
					next = false;
					break;
				}*/
				// 判断用户名是否正确
				if(!ProcessUtil.checkUserOrGroupExist(cfu.getUsername(), null)){
//					resultDesc = "执行失败:属主不正确;";
//					resultDesc = "Failure of execution: the owner is not correct;";
					resultDesc = "i18n_client.AgentCommand.execFailDesc13_n81i;";
					resultState = RESULT_FAIL;
//					logger.debug(resultDesc);//i18nlog
					next = false;
				}
				
				// 恢复版本不为空则为逆向任务
				if (reVersion != null && reVersion.longValue() > 0) {// 恢复
					cfuList.add(cfu);
					continue;
				}

				cfu.setIsCreateCover(handleYesOrNoField(cfu.getIsCreateCover()));
				// 处理解压时按绝对路径,还是相对路径, 只对LInux起作用, 默认按相对
				boolean isAbs = false;
				if ("Y".equals(handleYesOrNoField(cfu.getIsAbs()))) {
					isAbs = true;
				}
				/**
				 * 判断升级文件是否存在
				 */
				if (cfu.getFileName() == null
						|| cfu.getFileName().trim().length() <= 0) {
//					resultDesc = "执行失败:升级文件名为空";
//					resultDesc = "Execution failure: the upgrade file name is empty";
					resultDesc = "i18n_client.AgentCommand.execFailDesc14_n81i";
					resultState = RESULT_FAIL;
//					logger.debug(resultDesc);//i18nlog
					next = false;
					break;
				}
				File upgradeFile = new File(getFilePath(cfu.getFileName(),
						upgradePath));
				if (!upgradeFile.exists()) {
//					resultDesc = "执行失败:升级文件“" + cfu.getFileName() + "”不存在--"
//					resultDesc = "Execution failure: upgrade file“" + cfu.getFileName() + "”non-existent--"
					resultDesc = "i18n_client.AgentCommand.execFailDesc15_n81i“" + cfu.getFileName() + "”i18n_client.AgentCommand.execFailDesc8_n81i--"
							+ upgradeFile.getAbsolutePath();
					resultState = RESULT_FAIL;
//					logger.debug(resultDesc);//i18nlog
					next = false;
					break;
				}
				/**
				 * 判断覆盖目录是否存在:
				 * 1、必须判断:Window系统、或者Linux系统且不是压缩文件、或者Linux系统且是压缩文件且是相对路径
				 * 2、不用判断:Linux系统下源文件是压缩文件且绝对解压,该属性无效
				 */
				File coverDirFile = null;
				boolean isCompressFile = CompressFileMgr.isCompressFile(upgradeFile);
				String os = System.getProperty("os.name");
				if (os.startsWith("Windows")
						|| (!os.startsWith("Windows") && !isCompressFile)
						|| (!os.startsWith("Windows") && isCompressFile && !isAbs)) {
					if (cfu.getCover() == null
							|| cfu.getCover().trim().length() <= 0) {
//						resultDesc = "执行失败:覆盖目录为空";
//						resultDesc = "Execution failure: overlay the directory to be empty";
						resultDesc = "i18n_client.AgentCommand.execFailDesc16_n81i";
						resultState = RESULT_FAIL;
//						logger.debug(resultDesc);//i18nlog
						next = false;
						break;
					}
					coverDirFile = new File(cfu.getCover());
					if (!coverDirFile.exists()
							&& "N".equalsIgnoreCase(cfu.getIsCreateCover())) {
//						resultDesc = "执行失败:覆盖目录不存在--"
//						resultDesc = "Execution failure: the overlay directory does not exist--"
						resultDesc = "i18n_client.AgentCommand.execFailDesc17_n81i--"
								+ coverDirFile.getAbsolutePath();
						resultState = RESULT_FAIL;
//						logger.debug(resultDesc);//i18nlog
						next = false;
						break;
					}
					// Y 创建目录
					if (!coverDirFile.exists()) {
						coverDirFile.mkdirs();
					}
				} else {
					coverDirFile = new File("/");
				}

				cfuList.add(cfu);
			}
			/**
			 * 步骤2、停用所有进程,所有对象同步进行,有一个失败则失败
			 */
			String resultStr = "";
			boolean flag = false;
			if (next && (stepState > RESULT_OK  && stepState < RESULT_KILL_OK)) {
				String temp = "";
				if (isServer) {// 如果是NmsServer升级,发送升级请求
					for (int i = 0; i < Contants.max_times; i++) {// 失败,尝试几次
						Future<?> future = Common.service
								.submit(new SSLClient(Thread.currentThread().getName() + " >> DC升级请求",
										CommonSocket.REQ_SERVER_UPGRADE,
										null, Utils.getLocalIp()));
						String msg = (String) future.get();
						temp = Contants.getDescByResult(msg);
						if(Contants.isSucessByResult(msg)){
							break;
						}
						try {// 如果更新失败,让当前线程暂停几秒,再重试
							Thread.sleep(1000 * Contants.max_delay_seconds);
						} catch (InterruptedException e) {
							logger.error(Utils.printExceptionStack(e));
							continue;
						}
					}
//					temp = "DC升级请求" + ((temp!=null && temp.trim().length()>0) ? temp : "失败") + ";";
//					temp = "DC upgrade request" + ((temp!=null && temp.trim().length()>0) ? temp : "失败") + ";";
					temp = "i18n_client.AgentCommand.DCupdate_n81i" + ((temp!=null && temp.trim().length()>0) ? temp : "i18n_client.AgentCommand.fail_n81i") + ";";
				}
				
				Date execTime = new Date();
				String[] pidArr = new String[cfuList.size()];
				int i = 0;
				for(ParamUpgrade cfu:cfuList){
					pidArr[i++] = cfu.getPidFile();
				}
				resultStr = this.killProcessCmd(pidArr);
				String[] res = resultStr.split(RESULT_SEPRATOR_SPLIT);
				if (res != null && res.length >= 2) {
					resultState = Integer.parseInt(res[0]);
					resultDesc = temp + res[1];
				}
				if(resultState == RESULT_OK){
					flag = true;
					resultState = RESULT_KILL_OK;
					// 发送信息
					TaskResultOper.sendTaskResult(command.getExecId(), command.getExecType(),
								resultState, resultDesc, "", execTime, new Date(), isServer, command.getIsLoop());
				}else{
					flag = false;
				}
			}
			/**
			 * 步骤3、对所有参数指定的备份目录进行备份,有一个失败则失败
			 */
			if (next && (flag || stepState == RESULT_KILL_OK)) {// 停用进程成功,再进行备份
				Date execTime = new Date();
				StringBuffer sb = new StringBuffer();
				for(ParamUpgrade cfu:cfuList){
					resultStr = this.backupCmd(cfu.getBackups(), cfu.getCover(), curVersion);
					String[] res = resultStr.split(RESULT_SEPRATOR_SPLIT);
					if (res != null && res.length >= 2) {
						resultState = Integer.parseInt(res[0]);
						sb.append(res[1] + ";");
					}
					if(resultState == RESULT_FAIL){
						break;
					}
				}
				resultDesc = sb.toString();
				if(resultState == RESULT_OK){
					flag = true;
					resultState = RESULT_BACKUP_OK;
					// 发送信息
					TaskResultOper.sendTaskResult(command.getExecId(), command.getExecType(),
							resultState, resultDesc, "", execTime, new Date(), isServer, command.getIsLoop());
				}else{
					flag = false;
				}
			}
			/**
			 * 步骤4、对所有参数指定的覆盖目录进行更新并删除指定的文件,有一个失败则失败
			 */
			if (next && (flag || stepState == RESULT_BACKUP_OK)) {// 备份成功,再进行覆盖即更新
				Date execTime = new Date();
				ParamCoverUpdate[] updates = handleCoverUpdates(cfuList, reVersion, upgradePath);
				for (int i = 0; i < Contants.max_times; i++) {
					resultStr = this.updateCmd(updates);
					String[] res = resultStr.split(RESULT_SEPRATOR_SPLIT);
					if (res != null && res.length >= 2) {
						resultState = Integer.parseInt(res[0]);
						resultDesc = res[1];
					}
					if (resultState == RESULT_OK) {
						break;
					}
					try {// 如果更新失败,让当前线程暂停几秒,再重试
						Thread.sleep(1000 * Contants.max_delay_seconds);
					} catch (InterruptedException e) {
						logger.error(Utils.printExceptionStack(e));
						continue;
					}
				}
				if (resultState == RESULT_OK) {
					flag = true;
					resultState = RESULT_UPDATE_OK;
					// 发送信息
					TaskResultOper.sendTaskResult(command.getExecId(), command.getExecType(),
							resultState, resultDesc, "", execTime, new Date(), isServer, command.getIsLoop());
				}else{
					flag = false;
				}
				if(flag && isServer){
					Long curVer = Long.parseLong(VersionCfg
							.getValue(VersionCfg.NSERVER_VERSION));
					if (curVer < curVersion) {
						VersionCfg.setValue(VersionCfg.NSERVER_VERSION, curVersion + "");
						logger.info("DC升级到版本" + curVersion);
					}
				}
			}
			/**
			 * 步骤5、顺序启动所有进程,有一个失败则失败
			 */
			if (next && (flag || stepState == RESULT_UPDATE_OK)) {// 更新成功,再启动进程
				Date execTime = new Date();
				List<ParamCmdExec> startList = new ArrayList<ParamCmdExec>();
				for(ParamUpgrade cfu:cfuList){
					ParamCmdExec exec = new ParamCmdExec();
					exec.setExecCmd(cfu.getStartupFile());
					exec.setExecParams(cfu.getExecParams());
					exec.setExecResult(cfu.getPidFile());
					exec.setMaxWaitTime(cfu.getMaxWaitTime());
					exec.setUsername(cfu.getUsername());
					exec.setParam1(cfu.getParam1());
					exec.setForceExec("Y");
					exec.setResidentFlag("Y");
					exec.setReturnFlag("N");
					startList.add(exec);
				}
				resultStr = this.startCmd(startList, execTime, false, resultState);
				String[] res = resultStr.split(RESULT_SEPRATOR_SPLIT);
				if (res != null && res.length >= 2) {
					resultState = Integer.parseInt(res[0]);
					resultDesc = res[1];
				}
			}
		} catch (Exception e) {
//			resultDesc = "执行失败:出现异常," + e.getMessage() + ",详细信息请查看日志";
//			resultDesc = "Execution failure: abnormality," + e.getMessage() + ",please check the log for details";
			resultDesc = "i18n_client.AgentCommand.execFailDesc18_n81i," + e.getMessage() + ",i18n_client.AgentCommand.execFailDesc10.showDetail_n81i";
			resultState = RESULT_FAIL;
			logger.error(pre + "anormly:" + Utils.printExceptionStack(e));
		}finally{
		}
//		logger.info(pre + "结果描述信息 >> " + resultDesc);//i18nlog
		logger.info(pre + "结束……");
		
		return resultState + RESULT_SEPRATOR + resultDesc;
	}
	
	/**
	 * Agent原生支持命令,备份
	 * @param backups 备份文件包装对象数组(需要备份的目录、备份到的目录、排除的目录)
	 * @param version 
	 * @return
	 */
	public String backupCmd(ParamBackup[] backups, String oppositeBackupDir, Long version){
		logger.info("备份开始……");
		String resultDesc = "";
		long resultState = RESULT_FAIL;
		try {
			if(backups==null || backups.length<=0){
//				resultDesc = "备份成功:未指定备份参数,不需要备份";
//				resultDesc = "Backup success: no backup parameters specified, no backup required";
				resultDesc = "i18n_client.AgentCommand.backupSuccess1_n81i";
				resultState = RESULT_OK;
//				logger.debug(resultDesc);//i18nlog
			}else{
				StringBuffer sb = new StringBuffer();
				CompressFileMgr cfmImpl = new CompressFileMgr();
				for(int i=0; i<backups.length; i++){
					ParamBackup backup = backups[i];
					// 处理需要备份的目录
					logger.debug("backupCmd---->oppositeBackupDir=" + oppositeBackupDir);
					if(oppositeBackupDir!=null && oppositeBackupDir.trim().length()>0){
						backup.setBackup(getFilePath(backup.getBackup(), oppositeBackupDir));
					}
					// 判断需要备份的文件是否存在
					String backupPath = backup.getBackup();
					if(backup.getBackup()==null || backup.getBackup().trim().length()<=0){
//						resultDesc = "备份失败,需要备份的文件属性为空";
//						resultDesc = "Backup failed, the file property that needs to be backed up is empty";
						resultDesc = "i18n_client.AgentCommand.backupFail1_n81i";
						sb.append(resultDesc + ";");
						resultState = RESULT_FAIL;
//						logger.debug(resultDesc);//i18nlog
						break;
					}
					File srcFile = new File(backup.getBackup().trim());
					if(!srcFile.exists()){
//						resultDesc = "备份“" +  backupPath + "”失败,需要备份的文件不存在--" + srcFile.getAbsolutePath();
//						resultDesc = "Backup“" +  backupPath + "” failed, the file that needs to be backed up does not exist--" + srcFile.getAbsolutePath();
						resultDesc = "i18n_client.AgentCommand.backup_n81i“" +  backupPath + "” i18n_client.AgentCommand.backupFail2_n81i--" + srcFile.getAbsolutePath();
						sb.append(resultDesc + ";");
						resultState = RESULT_FAIL;
//						logger.debug(resultDesc);//i18nlog
						break;
					}else if(srcFile.isDirectory() && srcFile.list().length<=0){
//						resultDesc = "备份“" +  backupPath + "”成功,需要备份的文件目录为空,不用进行备份";
//						resultDesc = "Backup“" +  backupPath + "”successful, the backup file directory is empty without backup";
						resultDesc = "i18n_client.AgentCommand.backup_n81i“" +  backupPath + "”i18n_client.AgentCommand.backupSuccess2_n81i";
						sb.append(resultDesc + ";");
						resultState = RESULT_OK;
//						logger.debug(resultDesc);//i18nlog
						continue;
					}
					// 处理压缩时按绝对路径,还是相对路径, 只对LInux起作用, 默认按相对
					boolean isAbs = false;
					if("Y".equals(handleYesOrNoField(backup.getIsAbs()))){
						isAbs = true;
					}
					// 处理备份到的目录
					if(backup.getBackupTo()==null || backup.getBackupTo().trim().length()<=0){
						backup.setBackupTo(Contants.localBackupPath);
					}else{
						backup.setBackupTo(Contants.localBackupPath
								+ File.separator + backup.getBackupTo().trim());
					}
					// 处理备份操作
					String compressName = backup.getBackupTo() + File.separator
							+ getBakFileName(srcFile.getName(), version, isAbs);
					File destDirFile = new File(compressName);
					if (!destDirFile.exists()) {
						if (!destDirFile.getParentFile().exists()) {
							destDirFile.getParentFile().mkdirs();
						}
						if (destDirFile.getParentFile().canWrite()) {
							String[] excepts = backup.getExcept();
							if(excepts!=null && excepts.length>0){
								for(int j=0; j<excepts.length; j++){
									if(excepts[j]!=null && excepts[j].trim().length()>0){
										excepts[j] = getFilePath(excepts[j], backup.getBackup());
									}
								}
							}
							boolean flag = cfmImpl.compressFile(srcFile.getAbsolutePath(), destDirFile.getAbsolutePath(), excepts, isAbs);
							
//							resultDesc = flag ? "备份“" + backupPath
//									+ "”成功,备份文件" + destDirFile.getAbsolutePath()
//									: "备份“" + backupPath + "”失败";
							resultDesc = flag ? "i18n_client.AgentCommand.backup_n81i“" + backupPath
									+ "”i18n_client.AgentCommand.backupSuccess3_n81i" + destDirFile.getAbsolutePath()
									: "i18n_client.AgentCommand.backup_n81i“" + backupPath + "”i18n_client.AgentCommand.backupFail3_n81i";
							sb.append(resultDesc + ";");
							resultState = flag ? RESULT_OK : RESULT_FAIL;
							logger.debug(resultDesc + ": "
//									+ srcFile.getAbsolutePath() + " 到 "
									+ srcFile.getAbsolutePath() + " to "
									+ destDirFile.getAbsolutePath());
							if (resultState == RESULT_FAIL) {
								break;
							}
						}else{
//							resultDesc = "备份“" +  backupPath + "”失败,备份到的目录”" + backup.getBackupTo() + "“只读";
//							resultDesc = "Backup“" +  backupPath + "”failed, backup to the directory”" + backup.getBackupTo() + "“read-only";
							resultDesc = "i18n_client.AgentCommand.backup_n81i“" +  backupPath + "”i18n_client.AgentCommand.backupFail4_n81i”" + backup.getBackupTo() + "“i18n_client.AgentCommand.readonly_n81i";
							sb.append(resultDesc + ";");
							resultState = RESULT_FAIL;
//							logger.debug(resultDesc + "--" + destDirFile.getParent());//i18nlog
							break;
						}
					}else{
//						resultDesc = "备份“" +  backupPath + "”成功,已存在该版本备份,不用备份--备份文件" + destDirFile.getAbsolutePath();
//						resultDesc = "Backup“" +  backupPath + "”Successful version already exists, without backup - backup files" + destDirFile.getAbsolutePath();
						resultDesc = "i18n_client.AgentCommand.backup_n81i“" +  backupPath + "”i18n_client.AgentCommand.backupSuccess4_n81i" + destDirFile.getAbsolutePath();
						sb.append(resultDesc + ";");
						resultState = RESULT_OK;
//						logger.debug(resultDesc + "--" + destDirFile.getAbsolutePath());//i18nlog
					}
				}//for end
//				resultDesc = resultState==RESULT_OK ? "备份成功,详情信息如下:" + sb.toString() : "备份失败,详情信息如下:" + sb.toString();
//				resultDesc = resultState==RESULT_OK ? "The backup is successful, and the details are as follows:" + sb.toString() : "Backup failed, the details are as follows:" + sb.toString();
				resultDesc = resultState==RESULT_OK ? "i18n_client.AgentCommand.backupSuccess5_n81i:" + sb.toString() : "i18n_client.AgentCommand.backupFail5_n81i:" + sb.toString();
			}
		} catch (Exception e) {
//			resultDesc = "备份失败:出现异常," + e.getMessage() + ",详细信息请查看日志";
//			resultDesc = "Backup failure: Exception," + e.getMessage() + ",please check the log for details";
			resultDesc = "i18n_client.AgentCommand.backupFail6_n81i," + e.getMessage() + ",i18n_client.AgentCommand.execFailDesc10.showDetail_n81i";
			resultState = RESULT_FAIL;
			logger.error("备份异常:" + Utils.printExceptionStack(e));
		}
//		logger.info("备份结果描述信息 >> " + resultDesc);//i18nlog
		logger.info("备份结束……");
		
		return resultState + RESULT_SEPRATOR + resultDesc;
	}
	
	/**
	 * Agent原生支持命令,覆盖更新或恢复
	 * @param updates 覆盖更新包装对象数组(备份的文件、恢复的目录、删除的文件或目录)
	 * @return
	 */
	public String updateCmd(ParamCoverUpdate[] updates){
		logger.info("更新或恢复开始……");
		String resultDesc = "";
		long resultState = RESULT_FAIL;
		try {
			if(updates==null || updates.length<=0){
//				resultDesc = "覆盖成功:未指定参数,不需要覆盖";
//				resultDesc = "Overwrite success: unspecified parameters, no need to cover";
				resultDesc = "i18n_client.AgentCommand.coverSuccess1_n81i";
				resultState = RESULT_OK;
//				logger.debug(resultDesc);//i18nlog
			} else {
				StringBuffer sb = new StringBuffer();
				CompressFileMgr cfmImpl = new CompressFileMgr();
				for(int i=0; i<updates.length; i++){
					ParamCoverUpdate update = updates[i];

					
					
					// 处理是否创建覆盖目录
					update.setIsCreateCover(handleYesOrNoField(update.getIsCreateCover()));
					// 处理解压时按绝对路径,还是相对路径, 只对LInux起作用, 默认按相对
					boolean isAbs = false;
					if("Y".equals(handleYesOrNoField(update.getIsAbs()))){
						isAbs = true;
					}
					/**
					 * 判断源文件是否存在
					 */
					if(update.getSource()==null || update.getSource().trim().length()<=0){
//						resultDesc = "覆盖“" + update.getCover() + "”失败,源文件为空";
//						resultDesc = "Overwrite“" + update.getCover() + "”failure, source file is empty";
						resultDesc = "i18n_client.AgentCommand.coverFail1_n81i“" + update.getCover() + "”i18n_client.AgentCommand.coverFail1_n81i";
						sb.append(resultDesc + ";");
						resultState = RESULT_FAIL;
//						logger.debug(resultDesc);//i18nlog
						break;
					}
					File sourceFile = new File(update.getSource().trim());
					if (!sourceFile.exists()) {
//						resultDesc = "覆盖“" + update.getCover() + "”失败,源文件不存在--" + sourceFile.getAbsolutePath();
//						resultDesc = "Overwrite“" + update.getCover() + "”failure, source files do not exist--" + sourceFile.getAbsolutePath();
						resultDesc = "i18n_client.AgentCommand.coverFail1_n81i“" + update.getCover() + "”i18n_client.AgentCommand.coverFail2_n81i--" + sourceFile.getAbsolutePath();
						sb.append(resultDesc + ";");
						resultState = RESULT_FAIL;
//						logger.debug(resultDesc);//i18nlog
						break;
					} 
					/**
					 * 判断覆盖目录是否存在:
					 *    1、必须判断:Window系统、或者Linux系统且不是压缩文件、或者Linux系统且是压缩文件且是相对路径
					 *    2、不用判断:Linux系统下源文件是压缩文件且绝对解压,该属性无效
					 */
					File coverDir = null;
					boolean isCompressFile = CompressFileMgr.isCompressFile(sourceFile);
					String os = System.getProperty("os.name");
					if (os.startsWith("Windows")
							|| (!os.startsWith("Windows") && !isCompressFile)
							|| (!os.startsWith("Windows") && isCompressFile && !isAbs)) {
						if(update.getCover()==null || update.getCover().trim().length()<=0){
//							resultDesc = "覆盖“" + update.getCover() + "”失败,覆盖目录为空";
//							resultDesc = "Overwrite“" + update.getCover() + "”overwrite directory is empty";
							resultDesc = "i18n_client.AgentCommand.coverFail1_n81i“" + update.getCover() + "”i18n_client.AgentCommand.coverFail3_n81i";
							sb.append(resultDesc + ";");
							resultState = RESULT_FAIL;
//							logger.debug(resultDesc);//i18nlog
							break;
						}
						coverDir = new File(update.getCover().trim());
						if (!coverDir.exists() && "N".equals(update.getIsCreateCover())) {
//							resultDesc = "覆盖“" + update.getCover() + "”失败:覆盖目录不存在--" + coverDir.getAbsolutePath();
//							resultDesc = "Overwrite“" + update.getCover() + "”failed: Overwrite directory does not exist--" + coverDir.getAbsolutePath();
							resultDesc = "i18n_client.AgentCommand.coverFail1_n81i“" + update.getCover() + "”i18n_client.AgentCommand.coverFail4_n81i--" + coverDir.getAbsolutePath();
							sb.append(resultDesc + ";");
							resultState = RESULT_FAIL;
//							logger.debug(resultDesc);//i18nlog
							break;
						}
						// Y 创建目录
						if (!coverDir.exists()) {
							coverDir.mkdirs();
						}
					}else{
						coverDir = new File("/");
						if(update.getCover()==null || update.getCover().trim().length()<=0){
							update.setCover("/");
						}
					}
					
					//判断源文件或目录是否和覆盖目录相同
					if(sourceFile.getPath().equals(coverDir.getPath())){
//						resultDesc = "覆盖“" + update.getCover() + "”失败:覆盖目录“" + update.getCover() + "”和源目录相同!";
						resultDesc = "i18n_client.AgentCommand.coverFail1_n81i“" + update.getCover() + "”i18n_client.AgentCommand.coverFail5_n81i“" + update.getCover() + "”i18n_client.AgentCommand.coverFail5.sameDir_n81i";
						sb.append(resultDesc + ";");
						resultState = RESULT_FAIL;
//						logger.debug(resultDesc);//i18nlog
						break;
					}
					
					if (coverDir.canWrite()) {
						String delMsg = this.delete(update.getDelete(), coverDir.getAbsolutePath());
						if(!StringUtils.isEmpty(delMsg)){
							sb.append(delMsg + ";");
						}
						boolean flag = true;
						if (sourceFile.isDirectory()) {
							FileUtils.copyDirectoryToDirectory(sourceFile, coverDir);
						} else {
							if (isCompressFile) {
								flag = cfmImpl.decompressFile(sourceFile.getAbsolutePath(), coverDir.getAbsolutePath(), isAbs);
							} else {
								if (coverDir.isFile()) {
									coverDir = coverDir.getParentFile();
								}
								FileUtils.copyFileToDirectory(sourceFile,coverDir);
							}
						}
						if (flag) {
//							resultDesc = "覆盖“" + update.getCover() + "”成功, "
//									+ sourceFile.getAbsolutePath() + " 到 "
//									+ coverDir.getAbsolutePath();
//							resultDesc = "Overwrite“" + update.getCover() + "”success, "
//									+ sourceFile.getAbsolutePath() + " to "
//									+ coverDir.getAbsolutePath();
							resultDesc = "i18n_client.AgentCommand.coverFail1_n81i“" + update.getCover() + "”i18n_client.AgentCommand.coverSuccess2_n81i, "
									+ sourceFile.getAbsolutePath() + "i18n_client.AgentCommand.coverSuccess2.to_n81i "
									+ coverDir.getAbsolutePath();
						} else {
//							resultDesc = "覆盖“" + update.getCover() + "”失败";
//							resultDesc = "Overwrite“" + update.getCover() + "”failed";
							resultDesc = "i18n_client.AgentCommand.coverFail1_n81i“" + update.getCover() + "”i18n_client.AgentCommand.coverFail6_n81i";
						}
						sb.append(resultDesc + ";");
						resultState = flag ? RESULT_OK : RESULT_FAIL;
						logger.debug(resultDesc);
						if (resultState == RESULT_FAIL) {
							break;
						}
					} else {
//						resultDesc = "覆盖“" + update.getCover() + "”失败:要覆盖的目录只读--" + coverDir.getAbsolutePath();
//						resultDesc = "Overwrite“" + update.getCover() + "”failed: The directory to be overwritten is read-only--" + coverDir.getAbsolutePath();
						resultDesc = "i18n_client.AgentCommand.coverFail1_n81i“" + update.getCover() + "”i18n_client.AgentCommand.coverFail7_n81i--" + coverDir.getAbsolutePath();
						sb.append(resultDesc + ";");
						resultState = RESULT_FAIL;
//						logger.debug(resultDesc);//i18nlog
						break;
					}
				}// for end
//				resultDesc = resultState==RESULT_OK ? "覆盖成功,详情信息如下:" + sb.toString() : "覆盖失败,详情信息如下:" + sb.toString();
//				resultDesc = resultState==RESULT_OK ? "Overwrite success, details are as follows:" + sb.toString() : "Overwrite failed, details are as follows:" + sb.toString();
				resultDesc = resultState==RESULT_OK ? "i18n_client.AgentCommand.coverSuccess3_n81i:" + sb.toString() : "i18n_client.AgentCommand.coverFail8_n81i:" + sb.toString();
			}
		} catch (Exception e) {
//			resultDesc = "覆盖失败:出现异常," + e.getMessage() + ",详细信息请查看日志";
//			resultDesc = "Overwrite failed: An exception occurred," + e.getMessage() + ",see the logs for details";
			resultDesc = "i18n_client.AgentCommand.coverFail9_n81i," + e.getMessage() + ",i18n_client.AgentCommand.execFailDesc10.showDetail_n81i";
			resultState = RESULT_FAIL;
			logger.error("覆盖命令异常:" + Utils.printExceptionStack(e));
		}
		
//		logger.info("更新或恢复结果描述信息 >> " + resultDesc);//i18nlog
		logger.info("更新或恢复结束……");
		
		return resultState + RESULT_SEPRATOR + resultDesc;
	}
	
	/**
	 * Agent原生支持命令,停用进程
	 * @param pidFileArr 存放进程ID的文件的数组集
	 * @return
	 */
	public String killProcessCmd(String[] pidFileArr) {
		logger.info("停用进程集开始……");
		String resultDesc = "";
		long resultState = RESULT_FAIL;
		
		try {
			if(pidFileArr==null || pidFileArr.length<=0){
//				resultDesc = "停用进程失败:未指定PID文件参数";
//				resultDesc = "Deactivation process failed: PID file parameter not specified";
				resultDesc = "i18n_client.AgentCommand.killProcFail1_n81i";
				resultState = RESULT_FAIL;
//				logger.debug(resultDesc);//i18nlog
			}else {
				StringBuffer sb = new StringBuffer();
				for(String pidFileStr : pidFileArr){
					logger.debug("upgradeKillProcess pidFile------->" + pidFileStr);
					File pidFile = new File(pidFileStr);
					if(pidFileStr==null || pidFileStr.trim().length()<=0){
						resultState = RESULT_OK;
//						resultDesc = "停用成功,进程PID文件为空";
//						resultDesc = "Disabled, process PID file is empty";
						resultDesc = "i18n_client.AgentCommand.killProcSuccess1_n81i";
						sb.append(resultDesc + ";");
//						logger.debug(resultDesc + "--" + pidFile.getAbsolutePath() );//i18nlog
					}else if(!pidFile.exists()){
						resultState = RESULT_OK;
//						resultDesc = "停用“" + pidFileStr + "”成功,进程PID文件找不到";
						resultDesc = "i18n_client.AgentCommand.deactivate_n81i“" + pidFileStr + "”i18n_client.AgentCommand.killProcSuccess2_n81i";
						sb.append(resultDesc + ";");
//						logger.debug(resultDesc + "--" + pidFile.getAbsolutePath() );//i18nlog
					} else {
						String[] pidArr = ProcessUtil.getProcessIdByFile(pidFile);
						boolean isExist = false;
						if (pidArr != null && pidArr.length > 0) {
							for (int i = 0; i < pidArr.length; i++) {// 目前考虑只有一个PID的情况
								isExist = ProcessUtil
										.isProcessExistByPid(pidArr[i]);
								if (isExist) {// 只要有一个PID存在,就认为是进程存在
									break;
								}
							}
						}
						if (!isExist) {
//							resultDesc = "停用“" + pidFileStr + "”成功:进程原本不存在";
//							resultDesc = "Deactivate“" + pidFileStr + "”Success: Process does not exist originally";
							resultDesc = "i18n_client.AgentCommand.deactivate_n81i“" + pidFileStr + "”i18n_client.AgentCommand.killProcSuccess3_n81i";
							sb.append(resultDesc + ";");
							resultState = RESULT_OK;
//							logger.debug(resultDesc);//i18nlog
						} else {
							for (int i = 0; i < pidArr.length; i++) {
								ProcessUtil.killProcess(pidArr[i]);// 杀进程
							}
							for (int i = 0; i < Contants.max_times; i++) {
								pidArr = ProcessUtil.getProcessIdByFile(new File(pidFileStr));
								isExist = false;
								if (pidArr != null && pidArr.length > 0) {
									for (int j = 0; j < pidArr.length; j++) {
										isExist = ProcessUtil
												.isProcessExistByPid(pidArr[j]);
										if (isExist) {// 只要有一个PID存在,就认为是停用进程失败
											break;
										}
									}
								}
								if (!isExist) {
									break;
								}
								try {// 如果停用进程失败,让当前线程暂停几秒,再重试
									Thread
											.sleep(1000 * Contants.max_delay_seconds);
								} catch (InterruptedException e) {
									logger.error(Utils.printExceptionStack(e));
									continue;
								}
							}
							resultState = !isExist ? RESULT_OK : RESULT_FAIL;
//							resultDesc = !isExist ? "停用“" + pidFileStr + "”成功"
//									: "停用“" + pidFileStr
//											+ "”失败, 进程存在,请查看是否有守护进程";
//							resultDesc = !isExist ? "Deactivation of“" + pidFileStr + "”succeeded"
//									: "Deactivate“" + pidFileStr
//									+ "”Failed, process exists, see if there is a daemon";
							resultDesc = !isExist ? "i18n_client.AgentCommand.deactivate_n81i“" + pidFileStr + "”i18n_client.AgentCommand.killProcSuccess4_n81i"
									: "i18n_client.AgentCommand.deactivate_n81i“" + pidFileStr
											+ "”i18n_client.AgentCommand.killProcFail2_n81i";
							sb.append(resultDesc + ";");
//							logger.debug(resultDesc);//i18nlog
							if (resultState == RESULT_FAIL) {
								break;
							}
						}
					}
					
				}//for end
//				resultDesc = resultState == RESULT_OK ? "停用进程成功,详情信息如下:" + sb.toString() : "停用进程失败,详情信息如下:" + sb.toString();
//				resultDesc = resultState == RESULT_OK ? "Deactivation process is successful. Details are as follows:" + sb.toString() : "Deactivation process failed, details are as follows:" + sb.toString();
				resultDesc = resultState == RESULT_OK ? "i18n_client.AgentCommand.killProcSuccess5_n81i:" + sb.toString() : "i18n_client.AgentCommand.killProcFail3_n81i:" + sb.toString();
			}
		} catch (Exception e) {
//			resultDesc = "停用进程失败:出现异常," + e.getMessage() + ",详细信息请查看日志";
			resultDesc = "i18n_client.AgentCommand.killProcFail4_n81i," + e.getMessage() + ",i18n_client.AgentCommand.execFailDesc10.showDetail_n81i";
			resultState = RESULT_FAIL;
			logger.error("Disable process set exception:" + Utils.printExceptionStack(e));
		}
//		logger.info("停用进程集结果描述信息 >> " + resultDesc);//i18nlog
		logger.info("停用进程集结束……");
		
		return resultState + RESULT_SEPRATOR + resultDesc;
	}
	
	/**
	 * Agent原生支持命令,启动进程
	 * @param execList 命令参数对象集
	 * @param isRestart 当前运行的文件或命令,是否是重新启动,若是则不用判断进程是否存在,直接执行
	 * @return
	 */
	public String startCmd(List<ParamCmdExec> execList, Date startTime, boolean isRestart, long stepState){
		logger.info("启动开始……");
		String resultDesc = "";
		StringBuffer sb = new StringBuffer();
		long resultState = RESULT_FAIL;
		try {
			if(execList==null || execList.size()<=0){
//				resultDesc = "执行成功:未指定内容,不需要执行";
//				resultDesc = "Execution success: unspecified content, no need to execute";
				resultDesc = "i18n_client.AgentCommand.startCmdSuccess1_n81i";
				resultState = RESULT_OK;
				logger.debug(resultDesc);
			} else {
				List<String> returnFileList = new ArrayList<String>();
				
				for(ParamCmdExec exec : execList){
					if (stepState != RESULT_START_OK
							&& stepState != RESULT_START_FAIL) {// 若还未执行过,则继续执行,否则,只进行回传文件
						/**
						 * 步骤1、判断执行文件是否存在且可执行
						 */
						if(exec.getExecCmd()==null || exec.getExecCmd().trim().length()<=0){
//							sb.append("执行“" + exec.getExecCmd() + "”失败,执行命令为空;");
//							sb.append("Execute“" + exec.getExecCmd() + "”Failure, the result file is empty;");
							sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.startCmdFail1_n81i;");
							resultState = RESULT_FAIL;
							break;
						}
						if(exec.getExecResult()==null || exec.getExecResult().trim().length()<=0){
//							sb.append("执行“" + exec.getExecCmd() + "”失败,结果文件为空;");
//							sb.append("Execute“" + exec.getExecCmd() + "”Failure, the result file is empty;");
							sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.startCmdFail2_n81i;");
							resultState = RESULT_FAIL;
							break;
						}
						// 2013-4-26 由于DC改为Windows服务后升级要支持命令,若命令复杂的话,无法正确判断,做不作此步判断,待以后确定执行方案后考虑此步要不要
						/*boolean existFlag= ProcessUtil.isFileOrCmdExist(exec.getExecCmd());
						if(!existFlag){
							sb.append("执行“" + exec.getExecCmd() + "”失败,执行文件不存在或不是可执行命令;");
							resultState = RESULT_FAIL;
							break;
						}*/
						// 判断用户和密码是否正确
						/*boolean flag = ProcessUtil.checkUserPass(exec.getUsername(), exec.getParam1());
						if (!flag) {
							sb.append("执行“" + exec.getExecCmd() + "”失败,用户名或密码不正确;");
							resultState = RESULT_FAIL;
							break;
						}*/
						// 判断用户名是否正确
						if(!ProcessUtil.checkUserOrGroupExist(exec.getUsername(), null)){
//							sb.append("执行“" + exec.getExecCmd() + "”失败,用户名不正确;");
//							sb.append("Execute“" + exec.getExecCmd() + "”Failure, incorrect username");
							sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.startCmdFail3_n81i");
							resultState = RESULT_FAIL;
							break;
						}
						//判断用户是否有执行命令的权限
						//------------待完成su - -c "[ -x jzz_test.py ];echo $?" nmstest;
						/**
						 * 步骤2、判断是否常驻内存
						 *    (1) 常驻内存,判断进程是否存在,是否强制执行;
						 *    (2) 非常驻内存,直接执行
						 */
						boolean residentFlag = false;
						if ("Y".equals(handleYesOrNoField(exec.getResidentFlag()))) {
							residentFlag = true;
						}
						// 如果不是重启操作,则判断进程是否存在,反之,不判断进程是否存在,直接进行下面的执行部分
						if (residentFlag && !isRestart) {//----常驻内存,针对PID判断操作,execResult存放PID的文件
							//----步骤2-1-0、判断进程是否存在: 先判断进程PID文件是否存在--不存在认为进程不存在,存在判断进程PID是否存在
							File pidFile = new File(exec.getExecResult());
							boolean isExist = false;
							String[] pidArr = null;
							if(pidFile.exists()){
								pidArr = ProcessUtil.getProcessIdByFile(pidFile);
								if (pidArr != null) {
									for(int i=0; i<pidArr.length; i++){
										isExist = ProcessUtil.isProcessExistByPid(pidArr[i]);
										if(isExist){//如果有一个PID存在,就认为进程存在
											break;
										}
									}
								}
							}
							// ----步骤2-1-1、进程存在:则判断是否是强制执行; 进程不存在:则直接执行
							if (isExist) {
								// -------进程存在:强制执行,则杀进程继续执行
								if ("Y".equals(handleYesOrNoField(exec.getForceExec()))) {
									for (int i = 0; i < pidArr.length; i++) {
										ProcessUtil.killProcess(pidArr[i]);// 杀进程
									}
								}else{// --------进程存在:非强制执行,则不执行(continue, 跳过下面执行的部分)
									resultState = RESULT_OK;
//									sb.append("执行“" + exec.getExecCmd() + "”成功,进程原本存在,不用执行;");
//									sb.append("Execute“" + exec.getExecCmd() + "”Execution success: unspecified content, no need to execute;");
									sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.startCmdSuccess2_n81i;");
									continue;
								}
							}
						}
						/**
						 * 步骤3、执行文件或命令部分
						 *    A、常驻内存,结果文件存放PID,查看是否成功;
						 *    B、非常驻内存,结果文件存放结果标识,解析结果文件判断是否成功
						 */ 
						String resultMsg = ProcessUtil.runExec(exec.getExecCmd(), exec.getExecParams(), exec.getUsername(), exec.getParam1());
						// -------------步骤3-0、暂停最终结果获取最大等待时间(单位秒)
						long delay = 3;
						if (exec.getMaxWaitTime() != null
								&& !"".equals(exec.getMaxWaitTime().trim())) {
							delay = Long.parseLong(exec.getMaxWaitTime().trim());
						}
						if(delay>0){
							synchronized (this) {
								logger.debug("wait: " + delay + " seconds");
								this.wait(delay * 1000);
							}
						}
						// -------------步骤3-1、判断进程启动成功与否
						if (residentFlag) {// ---常驻内存,针对PID判断操作
							File pidFile = new File(exec.getExecResult());
							boolean isExist = false;
							if (pidFile.exists()) {
								String[] pidArr = ProcessUtil.getProcessIdByFile(pidFile);
								isExist = false;
								String notExitPids = null;
								if (pidArr != null) {
									for (int i = 0; i < pidArr.length; i++) {
										isExist = ProcessUtil.isProcessExistByPid(pidArr[i]);
										if (!isExist) {// 如果有一个PID不存在,就认为启动不成功
											notExitPids = pidArr[i];
											break;
										}
									}
								}
								resultState = isExist ? RESULT_OK : RESULT_FAIL;
								if(isExist){
//									sb.append("执行“" + exec.getExecCmd() + "”成功;");
//									sb.append("Execute“" + exec.getExecCmd() + "”success;");
									sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.success_n81i;");
								}else{
//									sb.append("执行“" + exec.getExecCmd() + "”失败, " + (notExitPids==null ? "PID为空;" : ("PID“"+notExitPids+"”不存在;")));
//									sb.append("Execute" + exec.getExecCmd() + "”failed, " + (notExitPids==null ? "PID is empty;" : ("PID is empty“"+notExitPids+"”do not exist;")));
									sb.append("i18n_client.AgentCommand.exec_n81i" + exec.getExecCmd() + "”failed, " + (notExitPids==null ? "i18n_client.AgentCommand.startCmdFail4_n81i;" : ("PID “"+notExitPids+"”i18n_client.AgentCommand.execFailDesc8_n81i;")));
								}
							} else {
								resultState = RESULT_FAIL;
//								sb.append("Failure to execute“" + exec.getExecCmd() + "”process PID file“" + pidFile.getAbsolutePath() + "”do not exist;");
								sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.startCmdFail6_n81i“" + pidFile.getAbsolutePath() + "”i18n_client.AgentCommand.execFailDesc8_n81i;");
							}
						} else {// ---非常驻内存,解析结果文件:结果标识(0 成功 1失败)|结果描述
							File resultFile = new File(exec.getExecResult());
							if (resultFile.exists()) {
								String[] result = FileWrUtil.cfgFileReader(resultFile);
								if (result != null && result.length > 0) {
									String[] res = result[0].split("\\|");
									if (res != null && res.length >= 1) {
										resultState = Long.parseLong(res[0]);
										logger.debug("startCmd resultState-->" + resultState);
//										String tt = (resultState == RESULT_OK ? "成功" : "失败");
										String tt = (resultState == RESULT_OK ? "Success" : "Failed");
										if(res.length >= 2){
//											sb.append("Execute“" + exec.getExecCmd() + "”" + tt + "," + res[1] + ";");
											sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”" + tt + "," + res[1] + ";");
										}else{
//											sb.append("Execute“" + exec.getExecCmd() + "”" + tt + ";");
											sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”" + tt + ";");
										}
									}
								} else {
									resultState = RESULT_FAIL;
//									sb.append("Failure to execute“" + exec.getExecCmd() + "”result file is not written in result file;");
									sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.startCmdFail7_n81i;");
								}
							} else {
								resultState = RESULT_FAIL;
//								sb.append("Failure to execute“" + exec.getExecCmd() + "”result file“" + resultFile.getAbsolutePath() + "”does not exist;");
								sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.startCmdFail8_n81i“" + resultFile.getAbsolutePath() + "”i18n_client.AgentCommand.execFailDesc8_n81i;");
							}
						}// -------------步骤3-1结束
						if(resultMsg!=null && resultMsg.length()>0){
							sb.append(resultMsg + ";");
						}
					}else{
						resultState = (stepState == RESULT_START_OK ? RESULT_OK : RESULT_FAIL);
					}
					
					/**
					 * 步骤4 判断是否回传文件
					 */
					if(exec.getReturnFlag()!=null && "Y".equalsIgnoreCase(exec.getReturnFlag().trim())){
						returnFileList.add(exec.getReturnPath());
					}
					
					if(resultState == RESULT_FAIL){//如果有一个失败,就停止执行
						break;
					}
				}// for end
				
				/**
				 * 步骤5 如果有回传文件,则回传文件并修改结果为中间结果;如果无回传文件,不回传且结果为最终结果
				 */
				if(returnFileList.size()>0){
					ReturnFilePO rfPO = new ReturnFilePO();
					rfPO.setTaskId(command.getExecId());
					rfPO.setTaskType(command.getExecType());
					rfPO.setUuid(Contants.AGENT_HOST_UUID);
					rfPO.setState(resultState);
					//rfPO.setFilePaths(returnFileList);
					rfPO.setStartTime(startTime);
					rfPO.setEndTime(new Date());
					rfPO.setIsLoop(command.getIsLoop());
					TaskReturnHandle.startTaskReturnFileThread(rfPO, returnFileList);
					resultState = (resultState == RESULT_OK) ? RESULT_START_OK : RESULT_START_FAIL;
				}
				
				if(resultState == RESULT_OK || resultState == RESULT_START_OK){
//					resultDesc = "执行成功,详细信息如下:" + sb.toString();
//					resultDesc = "Execution succeeded, details are as follows:" + sb.toString();
					resultDesc = "i18n_client.AgentCommand.startCmdSuccess4_n81i:" + sb.toString();
				}else{
//					resultDesc = "执行失败,详细信息如下:" + sb.toString();
//					resultDesc = "Execution failed with the following details:" + sb.toString();
					resultDesc = "i18n_client.AgentCommand.startCmdFail9_n81i:" + sb.toString();
				}
//				logger.debug(resultDesc);//i18nlog
			}
				
		} catch (Exception e) {
//			resultDesc = "执行失败:出现异常," + e.getMessage() + ",详细信息请查看日志";
//			resultDesc = "Execution failed: An exception occurred," + e.getMessage() + ",see the logs for details";
			resultDesc = "i18n_client.AgentCommand.startCmdFail10_n81i," + e.getMessage() + ",i18n_client.AgentCommand.execFailDesc10.showDetail_n81i";
			resultState = RESULT_FAIL;
			logger.error("Start abnormity: " + Utils.printExceptionStack(e));
		}
//		logger.info("启动结果描述信息 >> " + resultDesc);//i18nlog
		logger.info("启动结束……");
		
		return resultState + RESULT_SEPRATOR + resultDesc;
	}
	
	/**
	 * 可执行命令,单次执行命令
	 * @param execList 命令参数对象集
	 * @return
	 */
	public String singleExecCmd(List<ParamCmdExec> execList, Date startTime, long stepState){
		logger.info("单次命令执行开始……");
		String resultDesc = "";
		StringBuffer sb = new StringBuffer();
		long resultState = RESULT_FAIL;
		try {
			if(execList==null || execList.size()<=0){
//				resultDesc = "执行成功:未指定内容,不需要执行";
				resultDesc = "Execution succeeded: no content specified, no need to execute";
				resultState = RESULT_OK;
				logger.debug(resultDesc);
			} else {
				List<String> returnFileList = new ArrayList<String>();
				for(ParamCmdExec exec : execList){
					if (stepState != RESULT_START_OK
							&& stepState != RESULT_START_FAIL) {// 若还未执行过,则继续执行,否则,只进行回传文件
						/**
						 * 步骤1、必要的空判断
						 */
						if(exec.getExecCmd()==null || exec.getExecCmd().trim().length()<=0){
//							sb.append("执行“" + exec.getExecCmd() + "”失败,执行命令为空;");
							sb.append("The execution of“" + exec.getExecCmd() + "”failed and the execution command was empty;");
							resultState = RESULT_FAIL;
							break;
						}
						// 判断用户和密码是否正确
						/*boolean flag = ProcessUtil.checkUserPass(exec.getUsername(), exec.getParam1());
						if (!flag) {
							sb.append("执行“" + exec.getExecCmd() + "”失败,用户名或密码不正确;");
							resultState = RESULT_FAIL;
							break;
						}*/
						// 判断用户名是否正确
						if(!ProcessUtil.checkUserOrGroupExist(exec.getUsername(), null)){
//							sb.append("执行“" + exec.getExecCmd() + "”失败,用户名不正确;");
//							sb.append("Failure to execute“" + exec.getExecCmd() + "” with incorrect user name;");
							sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "” i18n_client.AgentCommand.singleCmdFail2_n81i;");
							resultState = RESULT_FAIL;
							break;
						}
						//判断用户是否有执行命令的权限
						//------------待完成su - -c "[ -x jzz_test.py ];echo $?" nmstest;
						/**
						 * 步骤2、执行命令部分
						 */
						final String execCmd = exec.getExecCmd();
						final String username = exec.getUsername();
						final String pass = exec.getParam1();
						final String threadName = Thread.currentThread().getName();
						Future<String> future = Common.service.submit(new Callable<String>(){
							@Override
							public String call() throws Exception {
								thread = Thread.currentThread();
								Thread.currentThread().setName(threadName);
								String result = ProcessUtil.runExecGetResult(execCmd, username, pass);
								return result;
							}
						});
						// ----获取最大等待时间(单位秒)
						long delay = 3;
						if (exec.getMaxWaitTime() != null
								&& !"".equals(exec.getMaxWaitTime().trim())) {
							delay = Long.parseLong(exec.getMaxWaitTime().trim());
							logger.debug("singleExecCmd Timeout time value: " + delay + " seconds");
						}
						// ----超过一定时间,终止执行线程,返回结果超时
						try {
							String result = future.get(delay, TimeUnit.SECONDS);
							logger.debug("singleExecCmd result-->" + result);
							// ---解析结果:结果标识(0 成功 1失败)|结果描述
							if (result != null && !result.isEmpty()) {
								String[] res = result.split("\\|");
								if (res != null && res.length >= 1) {
									resultState = Long.parseLong(res[0]);
									logger.debug("singleExecCmd resultState-->" + resultState);
//									String tt = (resultState == RESULT_OK ? "成功" : "失败");
//									String tt = (resultState == RESULT_OK ? "Success" : "Failed");
									String tt = (resultState == RESULT_OK ? "i18n_client.AgentCommand.success_n81i" : "i18n_client.AgentCommand.fail_n81i");
									if(res.length >= 2){
//										sb.append("Execute“" + exec.getExecCmd() + "”" + tt + "," + res[1] + ";");
										sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”" + tt + "," + res[1] + ";");
									}else{
//										sb.append("Execute“" + exec.getExecCmd() + "”" + tt + ";");
										sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”" + tt + ";");
									}
								}
							} else {
								resultState = RESULT_FAIL;
//								sb.append("Execute“" + exec.getExecCmd() + "”failed");
								sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.singleCmdFail3_n81i");
							}
						} catch (TimeoutException e) {
							if(thread!=null && thread.isAlive()){
								thread.stop();
								logger.debug(execCmd + "---singleExecCmd Timeout stop thread--" + thread.isAlive());
							}
							future.cancel(true);
							resultState = RESULT_FAIL;
//							sb.append("执行“" + exec.getExecCmd() + "”失败, 超时;");
//							sb.append("Failed to execute“" + exec.getExecCmd() + "”timeout;");
							sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.singleCmdFail4_n81i;");
							logger.debug("---------singleExecCmd timeout----------");
						}catch (InterruptedException e) {
							if(thread!=null && thread.isAlive()){
								thread.stop();
								logger.debug(execCmd + "---singleExecCmd Interrupted stop thread--" + thread.isAlive());
							}
							future.cancel(true);
							resultState = RESULT_FAIL;
//							sb.append("Failure to execute“" + exec.getExecCmd() + "”thread was interrupted;");
							sb.append("i18n_client.AgentCommand.exec_n81i“" + exec.getExecCmd() + "”i18n_client.AgentCommand.singleCmdFail5_n81i;");
							logger.debug("---------singleExecCmd Interrupted----------");
						}
					}else{
						resultState = (stepState == RESULT_START_OK ? RESULT_OK : RESULT_FAIL);
					}
						
					/**
					 * 步骤3 判断是否回传文件
					 */
					if(exec.getReturnFlag()!=null && "Y".equalsIgnoreCase(exec.getReturnFlag().trim())){
						returnFileList.add(exec.getReturnPath());
					}
					
					if(resultState == RESULT_FAIL){//如果有一个失败,就停止执行
						break;
					}
				}// for end
				
				/**
				 * 步骤4 如果有回传文件,则回传文件并修改结果为中间结果;如果无回传文件,不回传且结果为最终结果
				 */
				if(returnFileList.size()>0){
					ReturnFilePO rfPO = new ReturnFilePO();
					rfPO.setTaskId(command.getExecId());
					rfPO.setTaskType(command.getExecType());
					rfPO.setUuid(Contants.AGENT_HOST_UUID);
					rfPO.setState(resultState);
					//rfPO.setFilePaths(returnFileList);
					rfPO.setStartTime(startTime);
					rfPO.setEndTime(new Date());
					rfPO.setIsLoop(command.getIsLoop());
					TaskReturnHandle.startTaskReturnFileThread(rfPO, returnFileList);
					resultState = (resultState == RESULT_OK) ? RESULT_START_OK : RESULT_START_FAIL;
				}
				
				if(resultState == RESULT_OK || resultState == RESULT_START_OK){
//					resultDesc = "执行成功,详细信息如下:" + sb.toString();
//					resultDesc = "The execution was successful. The details are as follows:" + sb.toString();
					resultDesc = "i18n_client.AgentCommand.singleCmdSuccess2_n81i:" + sb.toString();
				}else{
//					resultDesc = "执行失败,详细信息如下:" + sb.toString();
//					resultDesc = "Execution failed with the following details:" + sb.toString();
					resultDesc = "i18n_client.AgentCommand.singleCmdFail6_n81i:" + sb.toString();
				}
			}
				
		} catch (Exception e) {
//			resultDesc = "执行失败:出现异常," + e.getMessage() + ",详细信息请查看日志";
//			resultDesc = "Execution failed: An exception occurred," + e.getMessage() + ", See the logs for details";
			resultDesc = "i18n_client.AgentCommand.singleCmdFail7_n81i," + e.getMessage() + ",i18n_client.AgentCommand.execFailDesc10.showDetail_n81i";
			resultState = RESULT_FAIL;
			logger.error("Single command execution exception: " + Utils.printExceptionStack(e));
		}
//		logger.info("单次命令执行结果描述信息 >> " + resultDesc);//i18nlog
		logger.info("单次命令执行结束……");
		
		return resultState + RESULT_SEPRATOR + resultDesc;
	}
	
	/**
	 * 取得备份文件的名称:原文件名_version_bak_压缩文件的相应后缀
	 * @param oldFileName
	 * @param version
	 * @param isAbs
	 * @return
	 */
	private String getBakFileName(String oldFileName, long version, boolean isAbs){
		String fileName = "";
		if(oldFileName!=null){
			fileName += oldFileName + "_";
		}
		fileName += version + "_bak" + CompressFileMgr.getCompressSuffixByOs(isAbs);
		
		return fileName;
	}
	
	/**
	 * 处理相对和绝对文件路径:如果文件本身是绝对路径不做处理;如果文件是相对路径则相对parent下
	 * @param filepath 相对或绝对路径的文件
	 * @param parent 相对路径文件的父目录
	 * @return
	 * @throws Exception
	 */
	private String getFilePath(String filepath, String parent) throws Exception{
		if(filepath!=null && filepath.trim().length()>0){
			File file = new File(filepath);
			if(file.isAbsolute()){
				return file.getCanonicalPath();
			}else if(parent!=null && parent.trim().length()>0){
				File parentFile = new File(parent);
				if(!parentFile.isDirectory()){
					parent = parentFile.getParent();
				}
				return new File(parent + File.separator + filepath).getCanonicalPath();
			}else {
				return file.getCanonicalPath();
			}
		}
		return null;
	}
	
	/**
	 * 删除文件,先对删除的文件做处理:如果是绝对路径直接删除;如果是相对路径则相应处理
	 * @param dels 将要删除的文件集
	 * @param oppositeDelDir 如果删除文件是相对路径,则为相对路径文件的父目录
	 * @return 删除文件的描述信息
	 * @throws Exception
	 */
	private String delete(String[] dels, String oppositeDelDir) throws Exception{
		StringBuffer sb = new StringBuffer();
		if(dels!=null && dels.length>0){
			for(String del : dels){
				if(del==null || del.trim().length()<=0){
					continue;
				}
				del = getFilePath(del, oppositeDelDir);
				if(del==null){
					continue;
				}
				File file = new File(del);
				if(file.exists()){
					FileUtil.delDir(file);
//					sb.append("删除”" + file.getCanonicalPath() + "“成功;");
//					sb.append("Delete”" + file.getCanonicalPath() + "“success;");
					sb.append("i18n_client.AgentCommand.deleteSuccess_n81i”" + file.getCanonicalPath() + "“i18n_client.AgentCommand.success_n81i;");
				}else{
//					sb.append("删除”" + file.getCanonicalPath() + "“,文件不存在;");
//					sb.append("Delete”" + file.getCanonicalPath() + "“,the file does not exist;");
					sb.append("i18n_client.AgentCommand.deleteFail_n81i”" + file.getCanonicalPath() + "“,i18n_client.AgentCommand.deleteFail.noFile_n81i;");
				}
			}
		}
		if(sb.length()>0){
			sb.deleteCharAt(sb.length()-1);
		}
		return sb.toString();
	}
	
    /**
     * 对是否字段(Y\N)的默认值处理
     * @param field
     * @return
     */
	private String handleYesOrNoField(String field){
		if(field==null || field.trim().length()<=0){
			return "N";
		}else if("Y".equalsIgnoreCase(field.trim())){
			return "Y";
		}else{
			return "N";
		}
	}
	
	/**
	 * 升级中的覆盖更新参数处理:
	 * *逆向任务,按恢复到的版本和本地备份目录来处理覆盖源文件;恢复目录,如果是相对则相对升级的覆盖目录,如果是绝对则不变
	 * *升级任务,按升级文件的路径处理源文件
	 * @param cfuList 升级参数列表
	 * @param reVersion 恢复到的版本
	 * @param upgradePath 升级文件的路径
	 * @return 覆盖更新数组集
	 * @throws Exception
	 */
	private ParamCoverUpdate[] handleCoverUpdates(List<ParamUpgrade> cfuList,
			Long reVersion, String upgradePath) throws Exception {
		List<ParamCoverUpdate> pcuList = new ArrayList<ParamCoverUpdate>();
		for (ParamUpgrade cfu : cfuList) {
			if (reVersion != null && reVersion.longValue() > 0) {//逆向任务,恢复
				for (ParamCoverUpdate update : cfu.getRecoverys()) {
					//必须先处理恢复目录
					update.setCover(getFilePath(update.getCover(), cfu.getCover()));
					//再处理恢复源文件
					update.setSource(getRecoverSource(update, reVersion));
					pcuList.add(update);
				}
			} else {//升级任务
				ParamCoverUpdate update = new ParamCoverUpdate();
				update = new ParamCoverUpdate();
				update.setSource(getFilePath(cfu.getFileName(), upgradePath));
				update.setCover(cfu.getCover());
				update.setIsCreateCover(cfu.getIsCreateCover());
				update.setIsAbs(cfu.getIsAbs());
				update.setDelete(cfu.getDelete());

				pcuList.add(update);
			}
		}
		ParamCoverUpdate[] updates = new ParamCoverUpdate[cfuList.size()];
		return pcuList.toArray(updates);
	}
	
	/**
	 * 升级中的恢复参数的源处理:source应为 localBackupPath + source + bakFileName(coverFileName_version_bak_压缩后缀)
	 * @param update 覆盖更新对象
	 * @param reVersion 恢复到的版本
	 * @return 恢复参数的源文件
	 * @throws Exception
	 */
	private String getRecoverSource(ParamCoverUpdate update, Long reVersion)
			throws Exception {
		// 逆向任务,source是原任务的备份目标目录(相对的),cover是原任务的备份过的文件
		// source还可以是操作人员自己备份的文件(完整的绝对路径且必须存在),如果source文件不存在,则按上面默认的方法重新拼写
		String source = update.getSource();
		logger.debug("getRecoverSource source----" + update.getSource());
		logger.debug("getRecoverSource cover----" + update.getCover());
		if (update.getSource() != null
				&& !new File(update.getSource()).exists()) {
			String oldFileName = "";
			if (update.getCover() != null) {
				oldFileName = new File(update.getCover()).getCanonicalFile().getName();
			}
			boolean isAbs = false;
			if ("Y".equals(handleYesOrNoField(update.getIsAbs()))) {
				isAbs = true;
			}
			source = Contants.localBackupPath + File.separator
					+ update.getSource() + File.separator
					+ getBakFileName(oldFileName, reVersion, isAbs);
		}
		return source;
	}
	
	private void backup(File srcFile, File destDir, String[] excepts) throws Exception{
		if (!srcFile.exists()) {
			return;
		}
		if (!srcFile.isDirectory()) {
			boolean flag = true;
			if (excepts != null && excepts.length > 0) {
				for (String except : excepts) {
					if (srcFile.getCanonicalPath().equalsIgnoreCase(except)) {
						flag = false;
						break;
					}
				}
			}
			if (flag) {
				FileUtils.copyFileToDirectory(srcFile, destDir);
			}
		} else if (srcFile.isDirectory()) {
			destDir = new File(destDir.getAbsolutePath() + File.separator
					+ srcFile.getName());
			for (File f : srcFile.listFiles()) {
				boolean flag = true;
				if (excepts != null && excepts.length > 0) {
					for (String except : excepts) {
						if (f.getCanonicalPath().equalsIgnoreCase(except)) {
							flag = false;
							break;
						}
					}
				}
				if (flag) {
					if (!f.isDirectory()) {
						FileUtils.copyFileToDirectory(f, destDir);
					} else if (f.isDirectory()) {
						backup(f, new File(destDir.getAbsolutePath()), excepts);
					}
				}
			}
		}
	}
	
}