Ejemplo n.º 1
0
func runStepFuncOnNode(name string, c TxnCtx, node uuid.UUID, done chan<- error) {
	if uuid.Equal(node, gdctx.MyUUID) {
		done <- runStepFuncLocal(name, c)
	} else {
		done <- runStepFuncRemote(name, c, node)
	}
}
Ejemplo n.º 2
0
func TestBlankNode(t *testing.T) {
	for i := uint64(0); i < 10; i++ {
		b := NewBlankNode()
		bID := uuid.Parse(b.ID().String())
		if uuid.Equal(bID, uuid.NIL) {
			t.Fatalf("NewBlankNode %s could not be decoded properly", b)
		}
	}
}
Ejemplo n.º 3
0
func (s *Supervisor) RemoveTaskFromRunq(id uuid.UUID) {
	l := make([]*db.Task, 0)
	for _, task := range s.runq {
		if uuid.Equal(task.UUID, id) {
			continue
		}
		l = append(l, task)
	}
	s.runq = l
}
Ejemplo n.º 4
0
func NewUUID() string {
	uuidLock.Lock()
	defer uuidLock.Unlock()
	result := uuid.NewUUID()
	// The UUID package is naive and can generate identical UUIDs if the
	// time interval is quick enough.
	// The UUID uses 100 ns increments so it's short enough to actively
	// wait for a new value.
	for uuid.Equal(lastUUID, result) == true {
		result = uuid.NewUUID()
	}
	lastUUID = result
	return result.String()
}
Ejemplo n.º 5
0
func checkStatus(ctx transaction.TxnCtx) error {
	var volname string

	if err := ctx.Get("volname", &volname); err != nil {
		ctx.Logger().WithFields(log.Fields{
			"error": err,
			"key":   "volname",
		}).Error("checkStatus: Failed to get key from transaction context.")
		return err
	}

	vol, err := volume.GetVolume(volname)
	if err != nil {
		ctx.Logger().WithFields(log.Fields{
			"error": err,
			"key":   "volname",
		}).Error("checkStatus: Failed to get volume information from store.")
		return err
	}

	var brickStatuses []*brick.Brickstatus

	for _, binfo := range vol.Bricks {
		// Skip bricks that aren't on this node.
		// TODO: Rename Brickinfo field 'ID' to 'NodeUUID'
		if uuid.Equal(binfo.ID, gdctx.MyUUID) == false {
			continue
		}

		// TODO: Check actual brick status when we get them running.
		fakeStatus := &brick.Brickstatus{
			Hostname: binfo.Hostname,
			Path:     binfo.Path,
			ID:       binfo.ID,
			Online:   false,
			Pid:      1234,
		}
		brickStatuses = append(brickStatuses, fakeStatus)
	}

	// Store the results in transaction context. This will be consumed by
	// the node that initiated the transaction.
	ctx.SetNodeResult(gdctx.MyUUID, brickStatusTxnKey, brickStatuses)

	return nil
}
Ejemplo n.º 6
0
func undoStartBricks(c transaction.TxnCtx) error {
	var volname string
	if e := c.Get("volname", &volname); e != nil {
		c.Logger().WithFields(log.Fields{
			"error": e,
			"key":   "volname",
		}).Error("failed to get value for key from context")
		return e
	}

	vol, e := volume.GetVolume(volname)
	if e != nil {
		// this shouldn't happen
		c.Logger().WithFields(log.Fields{
			"error":   e,
			"volname": volname,
		}).Error("failed to get volinfo for volume")
		return e
	}

	for _, b := range vol.Bricks {
		if uuid.Equal(b.ID, gdctx.MyUUID) {
			c.Logger().WithFields(log.Fields{
				"volume": volname,
				"brick":  b.Hostname + ":" + b.Path,
			}).Info("volume start failed, stopping bricks")
			//TODO: Stop started brick processes once the daemon management package is ready

			brickDaemon, err := brick.NewDaemon(vol.Name, b)
			if err != nil {
				return err
			}

			err = daemon.Stop(brickDaemon, true)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
Ejemplo n.º 7
0
// Nodes returns the a list of nodes on which this volume has bricks
func (v *Volinfo) Nodes() []uuid.UUID {
	var nodes []uuid.UUID

	// This shouldn't be very inefficient for small slices.
	var present bool
	for _, b := range v.Bricks {
		// Add node to the slice only if it isn't present already
		present = false
		for _, n := range nodes {
			if uuid.Equal(b.ID, n) == true {
				present = true
				break
			}
		}

		if present == false {
			nodes = append(nodes, b.ID)
		}
	}
	return nodes
}
Ejemplo n.º 8
0
func stopBricks(c transaction.TxnCtx) error {
	var volname string
	if e := c.Get("volname", &volname); e != nil {
		c.Logger().WithFields(log.Fields{
			"error": e,
			"key":   "volname",
		}).Error("failed to get value for key from context")
		return e
	}

	vol, e := volume.GetVolume(volname)
	if e != nil {
		// this shouldn't happen
		c.Logger().WithFields(log.Fields{
			"error":   e,
			"volname": volname,
		}).Error("failed to get volinfo for volume")
		return e
	}

	for _, b := range vol.Bricks {
		if uuid.Equal(b.ID, gdctx.MyUUID) {
			c.Logger().WithFields(log.Fields{
				"volume": volname,
				"brick":  b.Hostname + ":" + b.Path,
			}).Info("would stop brick")

			brickDaemon, err := brick.NewDaemon(vol.Name, b)
			if err != nil {
				return err
			}

			err = daemon.Stop(brickDaemon, false)
			if err != nil {
				return err
			}
		}
	}
	return nil
}
Ejemplo n.º 9
0
// ValidateBrickEntries validates the brick list
func ValidateBrickEntries(bricks []brick.Brickinfo, volID uuid.UUID, force bool) (int, error) {

	for _, b := range bricks {
		if !uuid.Equal(b.ID, gdctx.MyUUID) {
			continue
		}

		local, err := utils.IsLocalAddress(b.Hostname)
		if err != nil {
			log.WithField("Host", b.Hostname).Error(err.Error())
			return http.StatusInternalServerError, err
		}
		if local == false {
			log.WithField("Host", b.Hostname).Error("Host is not local")
			return http.StatusBadRequest, errors.ErrBrickNotLocal
		}
		err = utils.ValidateBrickPathLength(b.Path)
		if err != nil {
			return http.StatusBadRequest, err
		}
		err = utils.ValidateBrickSubDirLength(b.Path)
		if err != nil {
			return http.StatusBadRequest, err
		}
		err = isBrickPathAvailable(b.Hostname, b.Path)
		if err != nil {
			return http.StatusBadRequest, err
		}
		err = validateBrickPathStatsFunc(b.Path, b.Hostname, force)
		if err != nil {
			return http.StatusBadRequest, err
		}
		err = utils.ValidateXattrSupport(b.Path, b.Hostname, volID, force)
		if err != nil {
			return http.StatusBadRequest, err
		}
	}
	return 0, nil
}
Ejemplo n.º 10
0
Archivo: id.go Proyecto: jonasi/project
func (i ID) Equal(id ID) bool {
	return uuid.Equal(uuid.UUID(i), uuid.UUID(id))
}
Ejemplo n.º 11
0
// Equal checks if two triples are identical.
func (t *Triple) Equal(t2 *Triple) bool {
	return uuid.Equal(t.UUID(), t2.UUID())
}
Ejemplo n.º 12
0
func (s *Supervisor) ScheduleAdhoc(a *db.Task) {
	log.Infof("schedule adhoc %s job", a.Op)

	switch a.Op {
	case db.BackupOperation:
		// expect a JobUUID to move to the schedq Immediately
		for _, job := range s.jobq {
			if !uuid.Equal(job.UUID, a.JobUUID) {
				continue
			}

			log.Infof("scheduling immediate (ad hoc) execution of job %s [%s]", job.Name, job.UUID)
			task, err := s.Database.CreateBackupTask(a.Owner, job)
			if err != nil {
				log.Errorf("job -> task conversion / database update failed: %s", err)
				if a.TaskUUIDChan != nil {
					a.TaskUUIDChan <- &db.TaskInfo{
						Err:  true,
						Info: err.Error(),
					}
				}
				continue
			}
			if a.TaskUUIDChan != nil {
				a.TaskUUIDChan <- &db.TaskInfo{
					Err:  false,
					Info: task.UUID.String(),
				}
			}

			s.ScheduleTask(task)
		}

	case db.RestoreOperation:
		archive, err := s.Database.GetArchive(a.ArchiveUUID)
		if err != nil {
			log.Errorf("unable to find archive %s for restore task: %s", a.ArchiveUUID, err)
			return
		}
		target, err := s.Database.GetTarget(a.TargetUUID)
		if err != nil {
			log.Errorf("unable to find target %s for restore task: %s", a.TargetUUID, err)
			return
		}
		task, err := s.Database.CreateRestoreTask(a.Owner, archive, target)
		if err != nil {
			log.Errorf("restore task database creation failed: %s", err)
			if a.TaskUUIDChan != nil {
				a.TaskUUIDChan <- &db.TaskInfo{
					Err:  true,
					Info: err.Error(),
				}
			}
			return
		}
		if a.TaskUUIDChan != nil {
			a.TaskUUIDChan <- &db.TaskInfo{
				Err:  false,
				Info: task.UUID.String(),
			}
		}

		s.ScheduleTask(task)
	}
}
Ejemplo n.º 13
0
func interfaceStatus(client *contrail.Client, flagSet *flag.FlagSet) {
	if len(interfaceStatusOpts.vrouter) == 0 {
		fmt.Fprintln(os.Stderr, "virtual-router must be specified.")
		os.Exit(1)
	}
	url := fmt.Sprintf("http://%s:8085/Snh_ItfReq",
		interfaceStatusOpts.vrouter)
	resp, err := http.Get(url)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}
	// see: controller/src/vnsw/agent/oper/agent.sandesh
	// struct ItfSandeshData
	type InterfaceData struct {
		Name             string `xml:"name"`
		Uuid             string `xml:"uuid"`
		VrfName          string `xml:"vrf_name"`
		Status           string `xml:"active"`
		NetworkName      string `xml:"vn_name"`
		InstanceName     string `xml:"vm_name"`
		IpAddress        string `xml:"ip_addr"`
		LinkLocalAddress string `xml:"mdata_ip_addr"`
	}

	type Envelope struct {
		XMLName xml.Name        `xml:"ItfResp"`
		Data    []InterfaceData `xml:"itf_list>list>ItfSandeshData"`
	}

	var m Envelope
	err = xml.Unmarshal(body, &m)
	if err != nil {
		fmt.Fprintln(os.Stderr, err)
		os.Exit(1)
	}

	const interfaceStatusTmpl = `
  Interface: {{.Uuid}}
    Instance: {{.InstanceName}}
    Network: {{.NetworkName}}
    IpAddress: {{.IpAddress}} Link Local: {{.LinkLocalAddress}}
    Status: {{.Status}}
`
	var writer *tabwriter.Writer
	var tmpl *template.Template

	if interfaceStatusOpts.detail {
		tmpl = template.Must(template.New("interface-status").Parse(
			interfaceStatusTmpl))
	} else {
		writer = new(tabwriter.Writer)
		writer.Init(os.Stdout, 0, 0, 1, ' ', 0)
		fmt.Fprintf(writer, "Instance\tNetwork\tIpAddress\n")
	}
	for _, ifdata := range m.Data {
		id := uuid.Parse(ifdata.Uuid)
		if uuid.Equal(id, uuid.NIL) {
			continue
		}
		if interfaceStatusOpts.detail {
			tmpl.Execute(os.Stdout, ifdata)
		} else {
			netname := strings.Split(ifdata.NetworkName, ":")
			fmt.Fprintf(writer, "%.34s\t%-.28s\t%s\n",
				ifdata.InstanceName, netname[2], ifdata.IpAddress)
		}
	}

	if !interfaceStatusOpts.detail {
		writer.Flush()
	}
}