MCPcopy Index your code
hub / github.com/cloudfoundry/multiapps-cli-plugin / doUploadFromUrl

Method doUploadFromUrl

commands/deploy_command.go:509–598  ·  view source on GitHub ↗
(encodedFileUrl string, mtaClient mtaclient.MtaClientOperations, namespace string, progressBar *pb.ProgressBar)

Source from the content-addressed store, hash-verified

507}
508
509func (c *DeployCommand) doUploadFromUrl(encodedFileUrl string, mtaClient mtaclient.MtaClientOperations, namespace string, progressBar *pb.ProgressBar) UploadFromUrlStatus {
510 responseHeaders, err := mtaClient.StartUploadMtaArchiveFromUrl(encodedFileUrl, &namespace)
511 if err != nil {
512 ui.Failed("Could not upload from url: %s", err)
513 return UploadFromUrlStatus{
514 FileId: "",
515 MtaId: "",
516 SchemaVersion: "",
517 ClientActions: make([]string, 0),
518 ExecutionStatus: Failure,
519 }
520 }
521
522 var totalBytesProcessed int64 = 0
523 if progressBar != nil {
524 progressBar.Start()
525 defer progressBar.Finish()
526 }
527
528 uploadJobUrl := responseHeaders.Get("Location")
529 jobUrlParts := strings.Split(uploadJobUrl, "/")
530 jobId := jobUrlParts[len(jobUrlParts)-1]
531
532 timeout := time.NewTimer(time.Hour)
533 defer timeout.Stop()
534 ticker := time.NewTicker(2 * time.Second)
535 defer ticker.Stop()
536
537 var file *models.FileMetadata
538 var jobResult mtaclient.AsyncUploadJobResult
539 for file == nil {
540 jobResult, err = mtaClient.GetAsyncUploadJob(jobId, &namespace)
541 if err != nil {
542 ui.Failed("Could not upload from url: %s", err)
543 return UploadFromUrlStatus{
544 FileId: "",
545 MtaId: "",
546 SchemaVersion: "",
547 ClientActions: jobResult.ClientActions,
548 ExecutionStatus: Failure,
549 }
550 }
551 file = jobResult.File
552 if len(jobResult.Error) != 0 {
553 ui.Failed("Async upload job failed: %s", jobResult.Error)
554 return UploadFromUrlStatus{
555 FileId: "",
556 MtaId: "",
557 SchemaVersion: "",
558 ClientActions: jobResult.ClientActions,
559 ExecutionStatus: Failure,
560 }
561 }
562
563 if progressBar != nil && jobResult.BytesProcessed != -1 {
564 if jobResult.BytesProcessed < totalBytesProcessed {
565 //retry happened in backend, rewind the progress bar
566 progressBar.Add64(-totalBytesProcessed + jobResult.BytesProcessed)

Callers 1

uploadFromUrlMethod · 0.95

Calls 3

FailedFunction · 0.92
GetAsyncUploadJobMethod · 0.65

Tested by

no test coverage detected