19886: crunch-run records initial log with PDH
[arvados.git] / lib / crunchrun / crunchrun.go
index d322a3ac3c03f1eb178b9b2e6919de20cf30a390..6384f6a1cd7149998c6fa63588b2ec2745bc9bc7 100644 (file)
@@ -1427,18 +1427,25 @@ func (runner *ContainerRunner) saveLogCollection(final bool) (response arvados.C
 }
 
 // UpdateContainerRunning updates the container state to "Running"
-func (runner *ContainerRunner) UpdateContainerRunning() error {
+func (runner *ContainerRunner) UpdateContainerRunning(logId string) error {
        runner.cStateLock.Lock()
        defer runner.cStateLock.Unlock()
        if runner.cCancelled {
                return ErrCancelled
        }
-       return runner.DispatcherArvClient.Update("containers", runner.Container.UUID,
-               arvadosclient.Dict{"container": arvadosclient.Dict{
-                       "state":           "Running",
-                       "gateway_address": runner.gateway.Address,
-                       "log":             runner.logUUID,
-               }}, nil)
+       updates := arvadosclient.Dict{
+               "gateway_address": runner.gateway.Address,
+               "state":           "Running",
+       }
+       if logId != "" {
+               updates["log"] = logId
+       }
+       return runner.DispatcherArvClient.Update(
+               "containers",
+               runner.Container.UUID,
+               arvadosclient.Dict{"container": updates},
+               nil,
+       )
 }
 
 // ContainerToken returns the api_token the container (and any
@@ -1629,11 +1636,14 @@ func (runner *ContainerRunner) Run() (err error) {
                return
        }
 
-       _, err = runner.saveLogCollection(false)
-       if err != nil {
+       logCollection, err := runner.saveLogCollection(false)
+       var logId string
+       if err == nil {
+               logId = logCollection.PortableDataHash
+       } else {
                runner.CrunchLog.Printf("Error committing initial log collection: %v", err)
        }
-       err = runner.UpdateContainerRunning()
+       err = runner.UpdateContainerRunning(logId)
        if err != nil {
                return
        }