func LoadWorldmap(_hood *hood.Hood) { if loaded { panic("Worldmap has already been loaded!") } // Load maps var maps []entities.Map if err := _hood.Find(&maps); err != nil { panic(err) } if len(maps) > 0 { for _, mapEntity := range maps { mapId := int(mapEntity.MapId) worldmap[mapId] = NewTilePointTable(mapEntity.Name) } numOfProcessRoutines = len(maps) go internalLoadWorldmap(_hood) waitForLoadComplete() } else { log.Warning("World", "LoadWorldmap", "No maps found in the database") } loaded = true }
func (m *M) CreateUsersTable_1385792513_Up(hd *hood.Hood) { type Users struct { Id hood.Id First string Last string } hd.CreateTable(&Users{}) }
func (m *M) CreatePostsTable_1385803004_Up(hd *hood.Hood) { type Posts struct { Id hood.Id Title string `validate:"presence len(2:255)" sql:"size(255)"` Body string `validate:"presence"` AuthorId int64 CreatedAt hood.Created UpdatedAt hood.Updated } hd.CreateTable(&Posts{}) }
func GetNumAliveWorkers(tx *hood.Hood) int { var results []IntStruct err := tx.FindSql(&results, `select count(*) as value from worker where status=$1`, WORKER_ALIVE) if err != nil { panic(err) } return results[0].Value }
func (p *PlayerPokemon) loadMoves(_hood *hood.Hood) { var pokemonMoves []entities.PlayerPokemonMove if err := _hood.Where("pokemon_id", "=", p.GetPlayerPokemonId()).Find(&pokemonMoves); err != nil { log.Error("PlayerPokemon", "loadMoves", "Failed to load PlayerPokemonMoves for PlayerPokemon: %d. Error: %s", p.GetPlayerPokemonId(), err.Error()) } else { for _, move := range pokemonMoves { if playerPokemonMove := NewPlayerPokemonMove(&move); playerPokemonMove != nil { p.moves[playerPokemonMove.GetPlayerPokemonMoveId()] = playerPokemonMove } } } }
func (rdd *Rdd) GetWorkflowBatch(tx *hood.Hood) *WorkflowBatch { var results []WorkflowBatch err := tx.Where("id", "=", rdd.WorkflowBatchId).Find(&results) if err != nil { panic(err) } if len(results) == 0 { panic("workflow batch for rdd not found") } else { return &results[0] } }
func GetWorker(tx *hood.Hood, id int64) *Worker { var results []Worker err := tx.Where("id", "=", id).Find(&results) if err != nil { panic(err) } if len(results) == 0 { return nil } else { return &results[0] } }
func GetSegmentCopy(tx *hood.Hood, segmentCopyId int64) *SegmentCopy { var results []SegmentCopy err := tx.Where("id", "=", segmentCopyId).Find(&results) if err != nil { panic(err) } if len(results) == 0 { panic("could not find segment copy with given id") } else { return &results[0] } }
func (rdd *Rdd) GetNumSegmentsComplete(tx *hood.Hood, include *Segment) int { var results []IntStruct err := tx.FindSql(&results, `select count(*) as value from segment where (rdd_id = $1 and status=$3) or id = $2`, rdd.Id, include.Id, SEGMENT_COMPLETE) if err != nil { panic(err) } return results[0].Value }
func (segment *Segment) GetRdd(tx *hood.Hood) *Rdd { var results []Rdd err := tx.Where("id", "=", segment.RddId).Find(&results) if err != nil { panic(err) } if len(results) == 0 { panic("could not find rdd with given id") } else { return &results[0] } }
func (segment *Segment) GetWorker(tx *hood.Hood) *Worker { var results []Worker err := tx.Where("id", "=", segment.WorkerId).Find(&results) if err != nil { panic(err) } if len(results) == 0 { panic("could not find worker for segment") } else { return &results[0] } }
func (workflowBatch *WorkflowBatch) GetWorkflow(tx *hood.Hood) *Workflow { var results []Workflow err := tx.Where("id", "=", workflowBatch.WorkflowId).Find(&results) if err != nil { panic(err) } if len(results) == 0 { panic("could not find workflow for the given workflow batch") } else { return &results[0] } }
func (rdd *Rdd) GetProtojob(tx *hood.Hood) *Protojob { var results []Protojob err := tx.Where("id", "=", rdd.ProtojobId).Find(&results) if err != nil { panic(err) } if len(results) == 0 { panic("Rdd is missing protojob") } else { return &results[0] } }
func (workflow *Workflow) GetLastWorkflowBatch(tx *hood.Hood) *WorkflowBatch { var results []WorkflowBatch err := tx.Where("workflow_id", "=", workflow.Id).OrderBy("start_time").Desc().Limit(1).Find(&results) if err != nil { panic(err) } if len(results) == 0 { return nil } else { return &results[0] } }
func loadMoves(_hood *hood.Hood) { log.Verbose("Pokemon.Manager", "loadMoves", "Loading pokemon moves from database") var moves []entities.Move if err := _hood.Find(&moves); err != nil { log.Error("Pokemon.Manager", "loadMoves", "Error while loading moves: %s", err.Error()) } else { for _, moveEntity := range moves { move := NewMove(&moveEntity) movesStore[move.GetMoveId()] = move } } }
func (segmentCopy *SegmentCopy) GetSegment(tx *hood.Hood) *Segment { var results []Segment err := tx.Where("id", "=", segmentCopy.SegmentId).Find(&results) if err != nil { panic(err) } if len(results) == 0 { panic("could not find rdd with given id") } else { return &results[0] } }
func GetWorkflow(tx *hood.Hood, workflowId int64) *Workflow { var results []Workflow err := tx.Where("id", "=", workflowId).Find(&results) if err != nil { panic(err) } if len(results) == 0 { panic("could not find workflow with given id") } else { return &results[0] } }
func apply(stamp, current int, count *int, hd *hood.Hood, info *Migrations, structVal reflect.Value, method reflect.Method) { log.Printf("applying %s...", method.Name) txn := hd.Begin() method.Func.Call([]reflect.Value{structVal, reflect.ValueOf(txn)}) info.Current = current txn.Save(info) err := txn.Commit() if err != nil { panic(err) } else { *count++ } }
func (workflowBatch *WorkflowBatch) GetRdds(tx *hood.Hood) []*Rdd { var results []Rdd err := tx.Where("workflow_batch_id", "=", workflowBatch.Id).Find(&results) if err != nil { panic(err) } // Should return pointers to the result objects so that // they can be mutated pointerResults := make([]*Rdd, len(results)) for i := range results { pointerResults[i] = &results[i] } return pointerResults }
func GetWorkersAtAddress(tx *hood.Hood, address string) []*Worker { var results []Worker err := tx.Where("url", "=", address).Find(&results) if err != nil { panic(err) } // Should return pointers to the result objects so that // they can be mutated pointerResults := make([]*Worker, len(results)) for i := range results { pointerResults[i] = &results[i] } return pointerResults }
func GetWorkflows(tx *hood.Hood) []*Workflow { var results []Workflow err := tx.Find(&results) if err != nil { panic(err) } // Should return pointers to the result objects so that // they can be mutated pointerResults := make([]*Workflow, len(results)) for i := range results { pointerResults[i] = &results[i] } return pointerResults }
func (workflow *Workflow) GetProtojobs(tx *hood.Hood) []*Protojob { var results []Protojob err := tx.Where("workflow_id", "=", workflow.Id).Find(&results) if err != nil { panic(err) } // Should return pointers to the result objects so that // they can be mutated pointerResults := make([]*Protojob, len(results)) for i := range results { pointerResults[i] = &results[i] } return pointerResults }
func (rdd *Rdd) GetInputEdges(tx *hood.Hood) []*RddEdge { var results []RddEdge err := tx.Where("dest_rdd_id", "=", rdd.Id).Find(&results) if err != nil { panic(err) } // Should return pointers to the result objects so that // they can be mutated pointerResults := make([]*RddEdge, len(results)) for i := range results { pointerResults[i] = &results[i] } return pointerResults }
func GetAliveWorkers(tx *hood.Hood) []*Worker { var results []Worker err := tx.Where("status", "=", WORKER_ALIVE).Find(&results) if err != nil { panic(err) } // Should return pointers to the result objects so that // they can be mutated pointerResults := make([]*Worker, len(results)) for i := range results { pointerResults[i] = &results[i] } return pointerResults }
func (protojob *Protojob) GetInputEdges(tx *hood.Hood) []*WorkflowEdge { var results []WorkflowEdge err := tx.Where("dest_job_id", "=", protojob.Id).Find(&results) if err != nil { panic(err) } // Should return pointers to the result objects so that // they can be mutated pointerResults := make([]*WorkflowEdge, len(results)) for i := range results { pointerResults[i] = &results[i] } return pointerResults }
func (segment *Segment) GetSegmentCopies(tx *hood.Hood) []*SegmentCopy { var results []SegmentCopy err := tx.Where("segment_id", "=", segment.Id).Find(&results) if err != nil { panic(err) } // Should return pointers to the result objects so that // they can be mutated pointerResults := make([]*SegmentCopy, len(results)) for i := range results { pointerResults[i] = &results[i] } return pointerResults }
func loadPokemon(_hood *hood.Hood) { log.Verbose("Pokemon.Manager", "loadPokemon", "Loading pokemon from database") var pokemon []entities.Pokemon if err := _hood.Find(&pokemon); err != nil { log.Error("Pokemon.Manager", "loadPokemon", "Error while loading pokemon: %s", err.Error()) } else { for _, pokemonEntity := range pokemon { poke := NewPokemon(&pokemonEntity) if err := poke.LinkMoves(_hood); err != nil { log.Error("Pokemon.Manager", "loadPokemon", "Failed to link moves to Pokemon %d. Error: %s", poke.GetPokemonId(), err.Error()) } else { pokemonStore[poke.GetPokemonId()] = poke } } } }
func GetRandomAliveWorker(tx *hood.Hood) *Worker { var results []Worker err := tx.FindSql(&results, `select * from worker where status=$1 order by random() limit 1`, WORKER_ALIVE) if err != nil { panic(err) } if len(results) == 0 { return nil } else { return &results[0] } }
func GetRddByStartTime(tx *hood.Hood, protojobId int64, startTime int64) *Rdd { var results []Rdd err := tx.FindSql(&results, `select rdd.* from rdd inner join workflow_batch on rdd.workflow_batch_id = workflow_batch.id where rdd.protojob_id = $1 and workflow_batch.start_time = $2`, protojobId, startTime) if err != nil { panic(err) } if len(results) == 0 { return nil } else { return &results[0] } }
func GetPendingRdds(tx *hood.Hood) []*Rdd { var results []Rdd err := tx.FindSql(&results, `select rdd.* from rdd where rdd.state = $1`, RDD_PENDING) if err != nil { panic(err) } // Should return pointers to the result objects so that // they can be mutated pointerResults := make([]*Rdd, len(results)) for i := range results { pointerResults[i] = &results[i] } return pointerResults }