Ejemplo n.º 1
0
func (ws *WorkServer) SaveResult(w *Hyades.Work, res *Hyades.WorkResult) error {
	//Get Job work was part of, Get person Job belonged to and then save under
	//Person.JobFolder\Job.JobID\Work.partID\

	//Save 3 parts
	//Env.zip -- iff len(Env) > 0
	//StdOut.txt
	//ErrOut.txtlogFile

	folder := filepath.Join(ws.dataPath, w.PartOf().JobFolder, w.PartOf().Name+fmt.Sprint(w.PartOf().Id), strconv.Itoa(w.Index()))
	err := os.MkdirAll(folder, os.ModeDir|os.ModePerm)
	if err != nil {
		ws.Log.Println(err)
		return err
	}
	if res.EnvLength > 0 {
		envfile, err := os.Create(filepath.Join(folder, "Env.zip"))
		if err != nil {
			ws.Log.Println(err)
		}
		defer envfile.Close()
		_, err = io.CopyN(envfile, res.GetEnv(), int64(res.EnvLength))
		if err != nil {
			ws.Log.Println(err)
			log.Println("SaveResult", err)
			return err
		}
	}

	stdout, err := os.Create(filepath.Join(folder, "StdOut.txt"))
	if err != nil {
		ws.Log.Println(err)
		return err
	}
	defer stdout.Close()
	stdout.Write(res.StdOutStream)

	errout, err := os.Create(filepath.Join(folder, "ErrOut.txt"))
	if err != nil {
		ws.Log.Println(err)
	}
	defer errout.Close()
	errout.Write(res.ErrOutStream)

	return nil
}
Ejemplo n.º 2
0
func (c *Client) ServiceWork(wr io.ReadWriter) {
	reader := gob.NewDecoder(wr)
	writer := gob.NewEncoder(wr)

	defer func() {
		if c.Work != nil {
			work := c.clearWork()
			var err string
			if e := recover(); e != nil {
				err = fmt.Sprint(e)
			}
			c.Owner.retryWork(work, "ServiceWork loop ended "+err)
		}
	}()

	for {
		work, err := c.Owner.getWork()
		if err != nil {
			log.Println(err)
			continue
		}
		log.Println("got work from job", work.PartOf().Id)
		c.Work = work

		work.SetStatus("Sending work to client " + c.ClientInfo.ComputerName)
		work.Dispatch(c.ClientInfo)

		comms, err := work.PartOf().CreateWorkComms(work)
		if err != nil {
			log.Println("ServiceWork writer.Encode(comms) error", err)
			c.FrameWorkError(err)
			return
		}
		err = writer.Encode(comms)
		if err != nil {
			log.Println("ServiceWork writer.Encode(comms) error", err)
			c.FrameWorkError(err)
			return
		}

		work.SetStatus("Awaiting response from client " + c.ClientInfo.ComputerName)

		var res *Hyades.WorkResult = new(Hyades.WorkResult)
		err = reader.Decode(res)
		if err != nil {
			log.Println("ServiceWork reader.Decode(res) error", err)
			c.FrameWorkError(err)
			return
		}
		res.SetEnv(NopCloser(wr))

		c.clearWork()

		if res != nil && res.Error == "" {
			c.Owner.doneWork(work, res)
			c.Owner.Stats.DonePart(c.ClientInfo)
		} else {
			c.Owner.retryWork(work, res.Error)
			log.Println("ServiceWork ErrOutStream", res.ErrOutStream)
			log.Println("ServiceWork StdOutStream", res.StdOutStream)
			c.Owner.Log.Println("Client ", c.ClientInfo.ComputerName, "(", c.ClientInfo.OperatingSystem, ") terminated simulation with error:", res.Error)
			c.Owner.Stats.JobError()
		}

		err = c.Owner.db.SaveWork(work)
		if err != nil {
			log.Println("Saving work failed", err)
		} else {
			log.Println("Saved work", work.PartOf().Name, work.Command, work.Parameters)
		}
	}
}