Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 697601131
  • Loading branch information
Guest OS Images authored and copybara-github committed Dec 9, 2024
1 parent 1953625 commit fa339b2
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 2 deletions.
10 changes: 10 additions & 0 deletions compute/compute.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package compute
import (
"context"
"fmt"
logging "log"
"math/rand"
"net/http"
"strings"
Expand Down Expand Up @@ -1972,16 +1973,25 @@ func (c *client) SetCommonInstanceMetadata(project string, md *compute.Metadata)
// GetGuestAttributes gets a Guest Attributes.
func (c *client) GetGuestAttributes(project, zone, name, queryPath, variableKey string) (*compute.GuestAttributes, error) {
call := c.raw.Instances.GetGuestAttributes(project, zone, name)
logging.Printf("call %v", call)
logging.Printf("queryPath %v", queryPath)
if queryPath != "" {
call = call.QueryPath(queryPath)
}
logging.Printf("call 2 %v", call)
logging.Printf("variableKey %v", variableKey)
if variableKey != "" {
call = call.VariableKey(variableKey)
}
logging.Printf("call 3 %v", call)
a, err := call.Do()
logging.Printf("a %v", a)
logging.Printf("err %v", err)
if shouldRetryWithWait(c.hc.Transport, err, 2) {
return call.Do()
}
logging.Printf("a 2 %v", a)
logging.Printf("err 2 %v", err)
return a, err
}

Expand Down
4 changes: 4 additions & 0 deletions step.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package daisy
import (
"context"
"fmt"
logging "log"
"reflect"
"strings"
"time"
Expand Down Expand Up @@ -303,6 +304,7 @@ func (s *Step) recordStepTime(startTime time.Time) {
}

func (s *Step) run(ctx context.Context) DError {
logging.Println("in run @@@@@@@@@@@")
startTime := time.Now()
defer s.recordStepTime(startTime)
impl, err := s.stepImpl()
Expand All @@ -316,7 +318,9 @@ func (s *Step) run(ctx context.Context) DError {
st = t.Name()
}
s.w.LogWorkflowInfo("Running step %q (%s)", s.name, st)
logging.Println("in run 2 @@@@@@@@@@@")
if err = impl.run(ctx, s); err != nil {
logging.Println("in run 3 @@@@@@@@@@@")
return s.wrapRunError(err)
}
select {
Expand Down
35 changes: 35 additions & 0 deletions step_wait_for_instances_signal.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
logging "log"
"regexp"
"strings"
"sync"
Expand Down Expand Up @@ -235,15 +236,19 @@ func waitForSerialOutput(s *Step, project, zone, name string, so *SerialOutput,
}

func waitForGuestAttribute(s *Step, project, zone, name string, ga *GuestAttribute, interval time.Duration) DError {
logging.Println("in waitForGuestAttribute ========")
var keyTokens []string
if ga.Namespace != "" {
keyTokens = append(keyTokens, ga.Namespace)
}
logging.Printf("ga.Namespace ====== %v", ga.Namespace)
logging.Printf("ga.KeyName ====== %v", ga.KeyName)
keyTokens = append(keyTokens, ga.KeyName)
varkey := strings.Join(keyTokens, "/")

w := s.w
msg := fmt.Sprintf("Instance %q: watching for key %s", name, varkey)
logging.Printf("sucess value %q", ga.SuccessValue)
if ga.SuccessValue != "" {
msg += fmt.Sprintf(", SuccessValue: %q", ga.SuccessValue)
}
Expand All @@ -261,7 +266,10 @@ func waitForGuestAttribute(s *Step, project, zone, name string, ga *GuestAttribu
return nil
case <-tick:
resp, err := w.ComputeClient.GetGuestAttributes(project, zone, name, "", varkey)
logging.Printf("resp %v", resp)
// logging.Printf("resp VariableValue %q", resp.VariableValue)
if err != nil {
logging.Printf("error in compute client")
if apiErr, ok := err.(*googleapi.Error); ok && apiErr.Code == 404 {
// 404 is OK, that means the key isn't present yet. Retry until timeout.
continue
Expand Down Expand Up @@ -289,7 +297,9 @@ func waitForGuestAttribute(s *Step, project, zone, name string, ga *GuestAttribu
}

if ga.SuccessValue != "" {
logging.Printf("resp VariableValue %q", resp.VariableValue)
if resp.VariableValue != ga.SuccessValue {
logging.Printf("resp VariableValue %q", resp.VariableValue)
errMsg := strings.TrimSpace(resp.VariableValue)
format := "WaitForInstancesSignal bad guest attribute value found for %q: %q"
return Errf(format, name, errMsg)
Expand Down Expand Up @@ -336,20 +346,41 @@ func populateForWaitForInstancesSignal(w *[]*InstanceSignal, sn string) DError {
return nil
}

func printInstanceSignals(is *[]*InstanceSignal) {
if is == nil || *is == nil {
logging.Println("InstanceSignal slice is nil or empty")
return
}

for i, instance := range *is {
if instance != nil {
logging.Printf("Instance %d: %+v\n", i, *instance)
} else {
logging.Printf("Instance %d is nil\n", i)
}
}
}

func (w *WaitForInstancesSignal) run(ctx context.Context, s *Step) DError {
logging.Println("in run error $$$$$$$$$")
is := (*[]*InstanceSignal)(w)
printInstanceSignals(is)
return runForWaitForInstancesSignal(is, s, true)
}

func (w *WaitForAnyInstancesSignal) run(ctx context.Context, s *Step) DError {
logging.Println("in run error 2 $$$$$$$$$")
is := (*[]*InstanceSignal)(w)
printInstanceSignals(is)

return runForWaitForInstancesSignal(is, s, false)
}

func runForWaitForInstancesSignal(w *[]*InstanceSignal, s *Step, waitAll bool) DError {
var wg sync.WaitGroup
e := make(chan DError)
for _, is := range *w {
logging.Printf("is %v", is)
wg.Add(1)
go func(is *InstanceSignal) {
defer wg.Done()
Expand Down Expand Up @@ -386,12 +417,16 @@ func runForWaitForInstancesSignal(w *[]*InstanceSignal, s *Step, waitAll bool) D
close(serialSig)
}()
}
// logging.Println("in run 4 @@@@@@@@@@@")
if is.GuestAttribute != nil {
go func() {
logging.Println("in run 4.5 @@@@@@@@@@@")
if err := waitForGuestAttribute(s, m["project"], m["zone"], m["instance"], is.GuestAttribute, is.interval); err != nil || !waitAll {
// send a signal to end other waiting instances
logging.Println("in run 5 @@@@@@@@@@@")
e <- err
}
logging.Println("in run 5.5 @@@@@@@@@@@")
close(guestSig)
}()
}
Expand Down
21 changes: 19 additions & 2 deletions workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
loggings "log"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -269,18 +270,19 @@ type WorkflowModifier func(*Workflow)
// Run runs a workflow.
func (w *Workflow) Run(ctx context.Context) (err DError) {

loggings.Println("inside run =======")
w.externalLogging = true
if err = w.Validate(ctx); err != nil {
return err
}

loggings.Println("after validate =======")
defer w.cleanup()
defer func() {
if err != nil {
w.forceCleanup = w.ForceCleanupOnError
}
}()

loggings.Println("after cleanup =======")
if os.Getenv("BUILD_ID") != "" {
w.LogWorkflowInfo("Cloud Build ID: %s", os.Getenv("BUILD_ID"))
}
Expand All @@ -295,16 +297,19 @@ func (w *Workflow) Run(ctx context.Context) (err DError) {
w.CancelWorkflow()
return err
}
loggings.Println("after uploadSources =======")
w.LogWorkflowInfo("Running workflow")
defer func() {
for k, v := range w.serialControlOutputValues {
w.LogWorkflowInfo("Serial-output value -> %v:%v", k, v)
}
}()
loggings.Println("after defer func =======")
if err = w.run(ctx); err != nil {
w.LogWorkflowInfo("Error running workflow: %v", err)
return err
}
loggings.Println("after run =======")

return nil
}
Expand Down Expand Up @@ -803,9 +808,11 @@ func New() *Workflow {
// read during their populate step.
func NewFromFile(file string) (w *Workflow, err error) {
w = New()
loggings.Println("NewFromFile %v", file)
if err := readWorkflow(file, w); err != nil {
return nil, err
}
loggings.Println("End of newFromFile")
return w, nil
}

Expand Down Expand Up @@ -839,6 +846,8 @@ func JSONError(file string, data []byte, err error) error {

func readWorkflow(file string, w *Workflow) (derr DError) {
data, err := ioutil.ReadFile(file)
loggings.Println("THIS IS THE FILE ")
loggings.Println("data %v", string(data))
if err != nil {
return newErr("failed to read workflow file", err)
}
Expand All @@ -847,15 +856,23 @@ func readWorkflow(file string, w *Workflow) (derr DError) {
if err != nil {
return newErr("failed to get absolute path of workflow file", err)
}
loggings.Println("--------------------------------------------------")
loggings.Println("workflowDir %v", w.workflowDir)

if err := json.Unmarshal(data, &w); err != nil {
return newErr("failed to unmarshal workflow file", JSONError(file, data, err))
}
loggings.Println("--------------------------------------------------")
// loggings.Println("Unmarshalled Workflow: %+v\n", w)

if w.OAuthPath != "" && !filepath.IsAbs(w.OAuthPath) {
w.OAuthPath = filepath.Join(w.workflowDir, w.OAuthPath)
}

loggings.Println("--------------------------------------------------")
loggings.Println("w.vars %v", w.Vars)
loggings.Println("--------------------------------------------------")

for name, step := range w.Steps {
step.name = name
step.w = w
Expand Down

0 comments on commit fa339b2

Please sign in to comment.