本文整理匯總了Golang中github.com/MG-RAST/AWE/lib/logger.Event函數的典型用法代碼示例。如果您正苦於以下問題:Golang Event函數的具體用法?Golang Event怎麽用?Golang Event使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Event函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: MoveInputData
//fetch input data
func MoveInputData(work *core.Workunit) (size int64, err error) {
for _, io := range work.Inputs {
inputname := io.FileName
// skip if NoFile == true
if !io.NoFile { // is file !
dataUrl, uerr := io.DataUrl()
if uerr != nil {
return 0, uerr
}
inputFilePath := fmt.Sprintf("%s/%s", work.Path(), inputname)
if work.Rank == 0 {
if conf.CACHE_ENABLED && io.Node != "" {
if file_path, err := StatCacheFilePath(io.Node); err == nil {
//make a link in work dir from cached file
linkname := fmt.Sprintf("%s/%s", work.Path(), inputname)
fmt.Printf("input found in cache, making link: " + file_path + " -> " + linkname + "\n")
err = os.Symlink(file_path, linkname)
if err == nil {
logger.Event(event.FILE_READY, "workid="+work.Id+";url="+dataUrl)
}
return 0, err
}
}
} else {
dataUrl = fmt.Sprintf("%s&index=%s&part=%s", dataUrl, work.IndexType(), work.Part())
}
logger.Debug(2, "mover: fetching input file from url:"+dataUrl)
logger.Event(event.FILE_IN, "workid="+work.Id+";url="+dataUrl)
// download file
if datamoved, _, err := shock.FetchFile(inputFilePath, dataUrl, work.Info.DataToken, io.Uncompress, false); err != nil {
return size, errors.New("shock.FetchFile returned: " + err.Error())
} else {
size += datamoved
}
logger.Event(event.FILE_READY, "workid="+work.Id+";url="+dataUrl)
}
// download node attributes if requested
if io.AttrFile != "" {
// get node
node, err := shock.ShockGet(io.Host, io.Node, work.Info.DataToken)
if err != nil {
//return size, err
return size, errors.New("shock.ShockGet (node attributes) returned: " + err.Error())
}
logger.Debug(2, "mover: fetching input attributes from node:"+node.Id)
logger.Event(event.ATTR_IN, "workid="+work.Id+";node="+node.Id)
// print node attributes
attrFilePath := fmt.Sprintf("%s/%s", work.Path(), io.AttrFile)
attr_json, _ := json.Marshal(node.Attributes)
if err := ioutil.WriteFile(attrFilePath, attr_json, 0644); err != nil {
return size, err
}
logger.Event(event.ATTR_READY, "workid="+work.Id+";path="+attrFilePath)
}
}
return
}
示例2: ClientChecker
func (qm *CQMgr) ClientChecker() {
for {
time.Sleep(30 * time.Second)
for clientid, client := range qm.clientMap {
if client.Tag == true {
client.Tag = false
total_minutes := int(time.Now().Sub(client.RegTime).Minutes())
hours := total_minutes / 60
minutes := total_minutes % 60
client.Serve_time = fmt.Sprintf("%dh%dm", hours, minutes)
if len(client.Current_work) > 0 {
client.Idle_time = 0
} else {
client.Idle_time += 30
}
} else {
//now client must be gone as tag set to false 30 seconds ago and no heartbeat received thereafter
logger.Event(event.CLIENT_UNREGISTER, "clientid="+clientid+";name="+qm.clientMap[clientid].Name)
//requeue unfinished workunits associated with the failed client
workids := qm.getWorkByClient(clientid)
for _, workid := range workids {
if qm.workQueue.Has(workid) {
qm.workQueue.StatusChange(workid, WORK_STAT_QUEUED)
logger.Event(event.WORK_REQUEUE, "workid="+workid)
}
}
//delete the client from client map
delete(qm.clientMap, clientid)
}
}
}
}
示例3: moveInputData
//fetch input data
func moveInputData(work *core.Workunit) (size int64, err error) {
for _, io := range work.Inputs {
inputname := io.FileName
dataUrl, uerr := io.DataUrl()
if uerr != nil {
return 0, uerr
}
if work.Rank > 0 {
dataUrl = fmt.Sprintf("%s&index=%s&part=%s", dataUrl, work.IndexType(), work.Part())
}
inputFilePath := path.Join(work.Path(), inputname)
logger.Debug(2, "mover: fetching input from url:"+dataUrl)
logger.Event(event.FILE_IN, "workid="+work.Id+" url="+dataUrl)
// this gets file from any downloadable url, not just shock
if datamoved, _, err := shock.FetchFile(inputFilePath, dataUrl, work.Info.DataToken, io.Uncompress, false); err != nil {
return size, err
} else {
size += datamoved
}
logger.Event(event.FILE_READY, "workid="+work.Id+";url="+dataUrl)
}
return
}
示例4: UpdateMany
// PUT: /queue
func (cr *QueueController) UpdateMany(cx *goweb.Context) {
LogRequest(cx.Request)
// Try to authenticate user.
u, err := request.Authenticate(cx.Request)
if err != nil && err.Error() != e.NoAuth {
cx.RespondWithErrorMessage(err.Error(), http.StatusUnauthorized)
return
}
// must be admin user
if u == nil || u.Admin == false {
cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
return
}
// Gather query params
query := &Query{Li: cx.Request.URL.Query()}
if query.Has("resume") {
core.QMgr.ResumeQueue()
logger.Event(event.QUEUE_RESUME, "user="+u.Username)
cx.RespondWithData("work queue resumed")
return
}
if query.Has("suspend") {
core.QMgr.SuspendQueue()
logger.Event(event.QUEUE_SUSPEND, "user="+u.Username)
cx.RespondWithData("work queue suspended")
return
}
cx.RespondWithErrorMessage("requested queue operation not supported", http.StatusBadRequest)
return
}
示例5: RunWorkunit
func RunWorkunit(work *core.Workunit) (err error) {
args := work.Cmd.ParsedArgs
//change cwd to the workunit's working directory
if err := work.CDworkpath(); err != nil {
return err
}
commandName := work.Cmd.Name
cmd := exec.Command(commandName, args...)
msg := fmt.Sprintf("worker: start cmd=%s, args=%v", commandName, args)
fmt.Println(msg)
logger.Debug(1, msg)
logger.Event(event.WORK_START, "workid="+work.Id,
"cmd="+commandName,
fmt.Sprintf("args=%v", args))
var stdout, stderr io.ReadCloser
if conf.PRINT_APP_MSG {
stdout, err = cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err = cmd.StderrPipe()
if err != nil {
return err
}
}
if err := cmd.Start(); err != nil {
return errors.New(fmt.Sprintf("start_cmd=%s, err=%s", commandName, err.Error()))
}
if conf.PRINT_APP_MSG {
go io.Copy(os.Stdout, stdout)
go io.Copy(os.Stderr, stderr)
}
done := make(chan error)
go func() {
done <- cmd.Wait()
}()
select {
case <-chankill:
if err := cmd.Process.Kill(); err != nil {
fmt.Println("failed to kill" + err.Error())
}
<-done // allow goroutine to exit
fmt.Println("process killed")
return errors.New("process killed")
case err := <-done:
if err != nil {
return errors.New(fmt.Sprintf("wait_cmd=%s, err=%s", commandName, err.Error()))
}
}
logger.Event(event.WORK_END, "workid="+work.Id)
return
}
示例6: deliverer
func deliverer(control chan int) {
fmt.Printf("deliverer lanched, client=%s\n", core.Self.Id)
defer fmt.Printf("deliverer exiting...\n")
for {
processed := <-fromProcessor
work := processed.workunit
workmap[work.Id] = ID_DELIVERER
perfstat := processed.perfstat
//post-process for works computed successfully: push output data to Shock
move_start := time.Now().Unix()
if work.State == core.WORK_STAT_COMPUTED {
if err := core.PushOutputData(work); err != nil {
work.State = core.WORK_STAT_FAIL
logger.Error("[email protected]: workid=" + work.Id + ", err=" + err.Error())
} else {
work.State = core.WORK_STAT_DONE
}
}
move_end := time.Now().Unix()
perfstat.DataOut = move_end - move_start
perfstat.Deliver = move_end
perfstat.ClientResp = perfstat.Deliver - perfstat.Checkout
perfstat.ClientId = core.Self.Id
//notify server the final process results
if err := core.NotifyWorkunitProcessed(work, perfstat); err != nil {
time.Sleep(3 * time.Second) //wait 3 seconds and try another time
if err := core.NotifyWorkunitProcessed(work, perfstat); err != nil {
fmt.Printf("!!!NotifyWorkunitDone returned error: %s\n", err.Error())
logger.Error("[email protected]: workid=" + work.Id + ", err=" + err.Error())
//mark this work in Current_work map as false, something needs to be done in the future
//to clean this kind of work that has been proccessed but its result can't be sent to server!
core.Self.Current_work[work.Id] = false //server doesn't know this yet
}
}
//now final status report sent to server, update some local info
if work.State == core.WORK_STAT_DONE {
logger.Event(event.WORK_DONE, "workid="+work.Id)
core.Self.Total_completed += 1
if conf.AUTO_CLEAN_DIR {
if err := work.RemoveDir(); err != nil {
logger.Error("[email protected](): workid=" + work.Id + ", err=" + err.Error())
}
}
} else {
logger.Event(event.WORK_RETURN, "workid="+work.Id)
core.Self.Total_failed += 1
}
delete(core.Self.Current_work, work.Id)
delete(workmap, work.Id)
}
control <- ID_DELIVERER //we are ending
}
示例7: SuspendJob
func (qm *ServerMgr) SuspendJob(jobid string, reason string, id string) (err error) {
job, err := LoadJob(jobid)
if err != nil {
return
}
if id != "" {
job.LastFailed = id
}
if err := job.UpdateState(JOB_STAT_SUSPEND, reason); err != nil {
return err
}
qm.putSusJob(jobid)
//suspend queueing workunits
for _, workid := range qm.workQueue.List() {
if jobid == getParentJobId(workid) {
qm.workQueue.StatusChange(workid, WORK_STAT_SUSPEND)
}
}
//suspend parsed tasks
for _, task := range job.Tasks {
if task.State == TASK_STAT_QUEUED || task.State == TASK_STAT_INIT || task.State == TASK_STAT_INPROGRESS {
qm.taskStateChange(task.Id, TASK_STAT_SUSPEND)
task.State = TASK_STAT_SUSPEND
job.UpdateTask(task)
}
}
qm.LogJobPerf(jobid)
qm.removeActJob(jobid)
logger.Event(event.JOB_SUSPEND, "jobid="+jobid+";reason="+reason)
return
}
示例8: UpdateMany
// PUT: /logger
func (cr *LoggerController) UpdateMany(cx *goweb.Context) {
LogRequest(cx.Request)
// Try to authenticate user.
u, err := request.Authenticate(cx.Request)
if err != nil && err.Error() != e.NoAuth {
cx.RespondWithErrorMessage(err.Error(), http.StatusUnauthorized)
return
}
// must be admin user
if u == nil || u.Admin == false {
cx.RespondWithErrorMessage(e.NoAuth, http.StatusUnauthorized)
return
}
// Gather query params
query := &Query{Li: cx.Request.URL.Query()}
// currently can only reset debug level
if query.Has("debug") {
levelStr := query.Value("debug")
levelInt, err := strconv.Atoi(levelStr)
if err != nil {
cx.RespondWithErrorMessage("invalid debug level: "+err.Error(), http.StatusBadRequest)
}
conf.DEBUG_LEVEL = levelInt
logger.Event(event.DEBUG_LEVEL, "level="+levelStr+";user="+u.Username)
cx.RespondWithData(map[string]int{"debuglevel": conf.DEBUG_LEVEL})
return
}
cx.RespondWithError(http.StatusNotImplemented)
return
}
示例9: DeleteJob
func (qm *ServerMgr) DeleteJob(jobid string) (err error) {
job, err := LoadJob(jobid)
if err != nil {
return
}
if err := job.UpdateState(JOB_STAT_DELETED, "deleted"); err != nil {
return err
}
//delete queueing workunits
for workid, _ := range qm.workQueue.workMap {
if jobid == strings.Split(workid, "_")[0] {
qm.workQueue.Delete(workid)
}
}
//delete parsed tasks
for i := 0; i < len(job.TaskList()); i++ {
task_id := fmt.Sprintf("%s_%d", jobid, i)
delete(qm.taskMap, task_id)
}
qm.DeleteJobPerf(jobid)
delete(qm.susJobs, jobid)
logger.Event(event.JOB_DELETED, "jobid="+jobid)
return
}
示例10: ClientChecker
func (qm *CQMgr) ClientChecker() {
for {
time.Sleep(30 * time.Second)
logger.Debug(3, "time to update client list....\n")
for _, client := range qm.GetAllClients() {
if client.Tag == true {
client.Tag = false
total_minutes := int(time.Now().Sub(client.RegTime).Minutes())
hours := total_minutes / 60
minutes := total_minutes % 60
client.Serve_time = fmt.Sprintf("%dh%dm", hours, minutes)
if len(client.Current_work) > 0 {
client.Idle_time = 0
} else {
client.Idle_time += 30
}
qm.PutClient(client)
} else {
if ok := qm.HasClient(client.Id); !ok {
continue
}
//now client must be gone as tag set to false 30 seconds ago and no heartbeat received thereafter
logger.Event(event.CLIENT_UNREGISTER, "clientid="+client.Id+";name="+client.Name)
//requeue unfinished workunits associated with the failed client
qm.ReQueueWorkunitByClient(client.Id)
//delete the client from client map
qm.RemoveClient(client.Id)
}
}
}
}
示例11: DeleteJobByUser
func (qm *ServerMgr) DeleteJobByUser(jobid string, u *user.User) (err error) {
job, err := LoadJob(jobid)
if err != nil {
return
}
// User must have delete permissions on job or be job owner or be an admin
rights := job.Acl.Check(u.Uuid)
if job.Acl.Owner != u.Uuid && rights["delete"] == false && u.Admin == false {
return errors.New(e.UnAuth)
}
if err := job.UpdateState(JOB_STAT_DELETED, "deleted"); err != nil {
return err
}
//delete queueing workunits
for _, workid := range qm.workQueue.List() {
if jobid == getParentJobId(workid) {
qm.workQueue.Delete(workid)
}
}
//delete parsed tasks
for i := 0; i < len(job.TaskList()); i++ {
task_id := fmt.Sprintf("%s_%d", jobid, i)
qm.deleteTask(task_id)
}
qm.removeActJob(jobid)
qm.removeSusJob(jobid)
logger.Event(event.JOB_DELETED, "jobid="+jobid)
return
}
示例12: ClientChecker
func (qm *ProxyMgr) ClientChecker() {
for {
time.Sleep(30 * time.Second)
for _, client := range qm.GetAllClients() {
if client.Tag == true {
client.Tag = false
total_minutes := int(time.Now().Sub(client.RegTime).Minutes())
hours := total_minutes / 60
minutes := total_minutes % 60
client.Serve_time = fmt.Sprintf("%dh%dm", hours, minutes)
if client.Current_work_length() > 0 {
client.Idle_time = 0
} else {
client.Idle_time += 30
}
qm.PutClient(client)
} else {
//now client must be gone as tag set to false 30 seconds ago and no heartbeat received thereafter
logger.Event(event.CLIENT_UNREGISTER, "clientid="+client.Id+";name="+client.Name)
//requeue unfinished workunits associated with the failed client
qm.ReQueueWorkunitByClient(client.Id)
//delete the client from client map
qm.RemoveClient(client.Id)
//proxy specific
Self.SubClients -= 1
notifySubClients(Self.Id, Self.SubClients)
}
}
}
}
示例13: DeleteJob
func (qm *ServerMgr) DeleteJob(jobid string) (err error) {
job, err := LoadJob(jobid)
if err != nil {
return
}
if err := job.UpdateState(JOB_STAT_DELETED, "deleted"); err != nil {
return err
}
//delete queueing workunits
for _, workid := range qm.workQueue.List() {
if jobid == getParentJobId(workid) {
qm.workQueue.Delete(workid)
}
}
//delete parsed tasks
for i := 0; i < len(job.TaskList()); i++ {
task_id := fmt.Sprintf("%s_%d", jobid, i)
qm.deleteTask(task_id)
}
qm.removeActJob(jobid)
qm.removeSusJob(jobid)
logger.Event(event.JOB_DELETED, "jobid="+jobid)
return
}
示例14: SuspendJob
func (qm *ServerMgr) SuspendJob(jobid string, reason string) (err error) {
job, err := LoadJob(jobid)
if err != nil {
return
}
if err := job.UpdateState(JOB_STAT_SUSPEND, reason); err != nil {
return err
}
//qm.DeleteJobPerf(jobid)
qm.susJobs[jobid] = true
//suspend queueing workunits
for workid, _ := range qm.workQueue.workMap {
if jobid == strings.Split(workid, "_")[0] {
qm.workQueue.StatusChange(workid, WORK_STAT_SUSPEND)
}
}
//suspend parsed tasks
for _, task := range job.Tasks {
if task.State == TASK_STAT_QUEUED || task.State == TASK_STAT_INIT {
if _, ok := qm.taskMap[task.Id]; ok {
qm.taskMap[task.Id].State = TASK_STAT_SUSPEND
task.State = TASK_STAT_SUSPEND
job.UpdateTask(task)
}
}
}
qm.DeleteJobPerf(jobid)
logger.Event(event.JOB_SUSPEND, "jobid="+jobid+";reason="+reason)
return
}
示例15: updateJobTask
//update job info when a task in that job changed to a new state
func (qm *ServerMgr) updateJobTask(task *Task) (err error) {
parts := strings.Split(task.Id, "_")
jobid := parts[0]
job, err := LoadJob(jobid)
if err != nil {
return
}
remainTasks, err := job.UpdateTask(task)
if err != nil {
return err
}
logger.Debug(2, fmt.Sprintf("remaining tasks for task %s: %d", task.Id, remainTasks))
if remainTasks == 0 { //job done
qm.FinalizeJobPerf(jobid)
qm.LogJobPerf(jobid)
qm.removeActJob(jobid)
//delete tasks in task map
//delete from shock output flagged for deletion
for _, task := range job.TaskList() {
task.DeleteOutput()
task.DeleteInput()
qm.deleteTask(task.Id)
}
//log event about job done (JD)
logger.Event(event.JOB_DONE, "jobid="+job.Id+";jid="+job.Jid+";project="+job.Info.Project+";name="+job.Info.Name)
}
return
}