1616import org .zstack .core .timeout .ApiTimeoutManager ;
1717import org .zstack .core .workflow .FlowChainBuilder ;
1818import org .zstack .core .workflow .ShareFlow ;
19+ import org .zstack .header .HasThreadContext ;
1920import org .zstack .header .cluster .ClusterVO ;
2021import org .zstack .header .cluster .ClusterVO_ ;
2122import org .zstack .header .core .*;
23+ import org .zstack .header .core .progress .TaskProgressRange ;
2224import org .zstack .header .core .validation .Validation ;
2325import org .zstack .header .core .workflow .*;
2426import org .zstack .header .errorcode .ErrorCode ;
6971
7072import static org .zstack .core .Platform .i18n ;
7173import static org .zstack .core .Platform .operr ;
74+ import static org .zstack .core .progress .ProgressReportService .getTaskStage ;
75+ import static org .zstack .core .progress .ProgressReportService .markTaskStage ;
7276import static org .zstack .core .progress .ProgressReportService .reportProgress ;
73- import static org .zstack .header .storage .backup .BackupStorageConstant .*;
7477import static org .zstack .utils .CollectionDSL .list ;
75- import static org .zstack .utils .ProgressUtils .*;
7678
7779/**
7880 * Created by frank on 7/28/2015.
@@ -409,7 +411,8 @@ public static class SftpDownloadRsp extends AgentResponse {
409411 APICreateRootVolumeTemplateFromRootVolumeMsg .class ,
410412 APICreateDataVolumeTemplateFromVolumeMsg .class
411413 })
412- public static class SftpUpLoadCmd extends AgentCommand {
414+ public static class SftpUpLoadCmd extends AgentCommand implements HasThreadContext {
415+ String sendCommandUrl ;
413416 String primaryStorageInstallPath ;
414417 String backupStorageInstallPath ;
415418 String hostname ;
@@ -464,6 +467,14 @@ public String getSshKey() {
464467 public void setSshKey (String sshKey ) {
465468 this .sshKey = sshKey ;
466469 }
470+
471+ public void setSendCommandUrl (String sendCommandUrl ) {
472+ this .sendCommandUrl = sendCommandUrl ;
473+ }
474+
475+ public String getSendCommandUrl () {
476+ return sendCommandUrl ;
477+ }
467478 }
468479
469480 public static class SftpUploadRsp extends AgentResponse {
@@ -585,7 +596,8 @@ public static class UnprotectedSnapshotRsp extends AgentResponse {
585596 APICreateDataVolumeFromVolumeSnapshotMsg .class ,
586597 APICreateRootVolumeTemplateFromVolumeSnapshotMsg .class
587598 })
588- public static class CpCmd extends AgentCommand {
599+ public static class CpCmd extends AgentCommand implements HasThreadContext {
600+ String sendCommandUrl ;
589601 String resourceUuid ;
590602 String srcPath ;
591603 String dstPath ;
@@ -597,7 +609,8 @@ public static class CpCmd extends AgentCommand {
597609 APICreateDataVolumeFromVolumeSnapshotMsg .class ,
598610 APICreateRootVolumeTemplateFromVolumeSnapshotMsg .class
599611 })
600- public static class UploadCmd extends AgentCommand {
612+ public static class UploadCmd extends AgentCommand implements HasThreadContext {
613+ public String sendCommandUrl ;
601614 public String imageUuid ;
602615 public String hostname ;
603616 public String srcPath ;
@@ -1091,6 +1104,9 @@ public void upload(final ReturnValueCompletion<String> completion) {
10911104 checkParam ();
10921105
10931106 final UploadParam uparam = (UploadParam ) param ;
1107+ final TaskProgressRange parentStage = getTaskStage ();
1108+ final TaskProgressRange PREPARATION_STAGE = new TaskProgressRange (0 , 10 );
1109+ final TaskProgressRange UPLOAD_STAGE = new TaskProgressRange (10 , 100 );
10941110
10951111 FlowChain chain = FlowChainBuilder .newShareFlowChain ();
10961112 chain .setName (String .format ("upload-image-ceph-%s-to-sftp-%s" , self .getUuid (), backupStorage .getUuid ()));
@@ -1131,6 +1147,8 @@ public void fail(ErrorCode errorCode) {
11311147
11321148 @ Override
11331149 public void run (final FlowTrigger trigger , Map data ) {
1150+ TaskProgressRange stage = markTaskStage (parentStage , PREPARATION_STAGE );
1151+
11341152 BackupStorageAskInstallPathMsg msg = new BackupStorageAskInstallPathMsg ();
11351153 msg .setBackupStorageUuid (backupStorage .getUuid ());
11361154 msg .setImageUuid (uparam .image .getUuid ());
@@ -1143,7 +1161,7 @@ public void run(MessageReply reply) {
11431161 trigger .fail (reply .getError ());
11441162 } else {
11451163 backupStorageInstallPath = ((BackupStorageAskInstallPathReply ) reply ).getInstallPath ();
1146- reportProgress (getEndFromStage ( CREATE_ROOT_VOLUME_TEMPLATE_PREPARATION_STAGE ));
1164+ reportProgress (stage . getEnd (). toString ( ));
11471165 trigger .next ();
11481166 }
11491167 }
@@ -1156,7 +1174,10 @@ public void run(MessageReply reply) {
11561174
11571175 @ Override
11581176 public void run (final FlowTrigger trigger , Map data ) {
1177+ TaskProgressRange stage = markTaskStage (parentStage , UPLOAD_STAGE );
1178+
11591179 SftpUpLoadCmd cmd = new SftpUpLoadCmd ();
1180+ cmd .setSendCommandUrl (restf .getSendCommandUrl ());
11601181 cmd .setBackupStorageInstallPath (backupStorageInstallPath );
11611182 cmd .setHostname (hostname );
11621183 cmd .setUsername (username );
@@ -1167,7 +1188,7 @@ public void run(final FlowTrigger trigger, Map data) {
11671188 httpCall (SFTP_UPLOAD_PATH , cmd , SftpUploadRsp .class , new ReturnValueCompletion <SftpUploadRsp >(trigger ) {
11681189 @ Override
11691190 public void success (SftpUploadRsp returnValue ) {
1170- reportProgress (getEndFromStage ( CREATE_ROOT_VOLUME_TEMPLATE_UPLOAD_STAGE ));
1191+ reportProgress (stage . getEnd (). toString ( ));
11711192 trigger .next ();
11721193 }
11731194
@@ -1182,6 +1203,7 @@ public void fail(ErrorCode errorCode) {
11821203 done (new FlowDoneHandler (completion ) {
11831204 @ Override
11841205 public void handle (Map data ) {
1206+ reportProgress (parentStage .getEnd ().toString ());
11851207 completion .success (backupStorageInstallPath );
11861208 }
11871209 });
@@ -1249,7 +1271,7 @@ public void upload(final ReturnValueCompletion<String> completion) {
12491271 checkParam ();
12501272
12511273 final UploadParam uparam = (UploadParam ) param ;
1252-
1274+ final TaskProgressRange parentStage = getTaskStage ();
12531275 FlowChain chain = FlowChainBuilder .newShareFlowChain ();
12541276 chain .setName (String .format ("upload-image-ceph-%s-to-ceph-%s" , self .getUuid (), backupStorage .getUuid ()));
12551277 chain .then (new ShareFlow () {
@@ -1274,7 +1296,6 @@ public void run(MessageReply reply) {
12741296 trigger .fail (reply .getError ());
12751297 } else {
12761298 backupStorageInstallPath = ((BackupStorageAskInstallPathReply ) reply ).getInstallPath ();
1277- reportProgress (getEndFromStage (CREATE_ROOT_VOLUME_TEMPLATE_PREPARATION_STAGE ));
12781299 trigger .next ();
12791300 }
12801301 }
@@ -1288,12 +1309,12 @@ public void run(MessageReply reply) {
12881309 @ Override
12891310 public void run (final FlowTrigger trigger , Map data ) {
12901311 CpCmd cmd = new CpCmd ();
1312+ cmd .sendCommandUrl = restf .getSendCommandUrl ();
12911313 cmd .srcPath = uparam .primaryStorageInstallPath ;
12921314 cmd .dstPath = backupStorageInstallPath ;
12931315 httpCall (CP_PATH , cmd , CpRsp .class , new ReturnValueCompletion <CpRsp >(trigger ) {
12941316 @ Override
12951317 public void success (CpRsp returnValue ) {
1296- reportProgress (getEndFromStage (CREATE_ROOT_VOLUME_TEMPLATE_UPLOAD_STAGE ));
12971318 trigger .next ();
12981319 }
12991320
@@ -1308,6 +1329,7 @@ public void fail(ErrorCode errorCode) {
13081329 done (new FlowDoneHandler (completion ) {
13091330 @ Override
13101331 public void handle (Map data ) {
1332+ reportProgress (parentStage .getEnd ().toString ());
13111333 completion .success (backupStorageInstallPath );
13121334 }
13131335 });
@@ -1899,6 +1921,9 @@ private void checkCephFsId(String psUuid, String bsUuid) {
18991921 @ Override
19001922 protected void handle (final CreateTemplateFromVolumeOnPrimaryStorageMsg msg ) {
19011923 final CreateTemplateFromVolumeOnPrimaryStorageReply reply = new CreateTemplateFromVolumeOnPrimaryStorageReply ();
1924+ final TaskProgressRange parentStage = getTaskStage ();
1925+ final TaskProgressRange CREATE_SNAPSHOT_STAGE = new TaskProgressRange (0 , 10 );
1926+ final TaskProgressRange CREATE_IMAGE_STAGE = new TaskProgressRange (10 , 100 );
19021927
19031928 checkCephFsId (msg .getPrimaryStorageUuid (), msg .getBackupStorageUuid ());
19041929
@@ -1921,6 +1946,7 @@ public void setup() {
19211946 @ Override
19221947 public void run (final FlowTrigger trigger , Map data ) {
19231948 String volumeAccountUuid = acntMgr .getOwnerAccountUuidOfResource (volumeUuid );
1949+ TaskProgressRange stage = markTaskStage (parentStage , CREATE_SNAPSHOT_STAGE );
19241950
19251951 // 1. create snapshot
19261952 CreateVolumeSnapshotMsg cmsg = new CreateVolumeSnapshotMsg ();
@@ -1940,7 +1966,7 @@ public void run(MessageReply r) {
19401966
19411967 CreateVolumeSnapshotReply createVolumeSnapshotReply = (CreateVolumeSnapshotReply )r ;
19421968 snapshot = createVolumeSnapshotReply .getInventory ();
1943- reportProgress (getEndFromStage ( CREATE_ROOT_VOLUME_TEMPLATE_PREPARATION_STAGE ));
1969+ reportProgress (stage . getEnd (). toString ( ));
19441970 trigger .next ();
19451971 }
19461972 });
@@ -1954,6 +1980,7 @@ public void run(MessageReply r) {
19541980 @ Override
19551981 public void run (final FlowTrigger trigger , Map data ) {
19561982 // 2.create image
1983+ TaskProgressRange stage = markTaskStage (parentStage , CREATE_IMAGE_STAGE );
19571984
19581985 VolumeSnapshotVO vo = dbf .findByUuid (snapshot .getUuid (), VolumeSnapshotVO .class );
19591986 String treeUuid = vo .getTreeUuid ();
@@ -1976,7 +2003,7 @@ public void run(MessageReply r) {
19762003 }
19772004
19782005 imageReply = (CreateTemplateFromVolumeSnapshotReply )r ;
1979- reportProgress (getEndFromStage ( CREATE_ROOT_VOLUME_TEMPLATE_PREPARATION_STAGE ));
2006+ reportProgress (stage . getEnd (). toString ( ));
19802007 trigger .next ();
19812008 }
19822009 });
@@ -3147,6 +3174,7 @@ private void handle(final UploadBitsToBackupStorageMsg msg) {
31473174 }
31483175
31493176 UploadCmd cmd = new UploadCmd ();
3177+ cmd .sendCommandUrl = restf .getSendCommandUrl ();
31503178 cmd .fsId = getSelf ().getFsid ();
31513179 cmd .srcPath = msg .getPrimaryStorageInstallPath ();
31523180 cmd .dstPath = msg .getBackupStorageInstallPath ();
0 commit comments