Example #1
0
func rollBackVolumeCreate(c transaction.TxnCtx) error {
	var vol volume.Volinfo
	e := c.Get("volinfo", &vol)
	if e != nil {
		return errors.New("failed to get volinfo from context")
	}

	_ = volume.RemoveBrickPaths(vol.Bricks)

	return nil
}
Example #2
0
func aggregateVolumeStatus(ctx transaction.TxnCtx, nodes []uuid.UUID) (*volume.VolStatus, error) {
	var brickStatuses []brick.Brickstatus

	// Loop over each node on which txn was run.
	// Fetch brick statuses stored by each node in transaction context.
	for _, node := range nodes {
		var tmp []brick.Brickstatus
		err := ctx.GetNodeResult(node, brickStatusTxnKey, &tmp)
		if err != nil {
			return nil, goerrors.New("aggregateVolumeStatus: Could not fetch results from transaction context.")
		}
		brickStatuses = append(brickStatuses, tmp...)
	}
	v := &volume.VolStatus{Brickstatuses: brickStatuses}
	return v, nil
}
Example #3
0
func generateVolfiles(c transaction.TxnCtx) error {
	var vol volume.Volinfo
	e := c.Get("volinfo", &vol)
	if e != nil {
		return errors.New("failed to get volinfo from context")
	}

	// Creating client and server volfile
	e = volgen.GenerateVolfileFunc(&vol)
	if e != nil {
		c.Logger().WithFields(log.Fields{"error": e.Error(),
			"volume": vol.Name,
		}).Error("failed to generate volfile")
		return e
	}
	return nil
}
Example #4
0
func storeVolume(c transaction.TxnCtx) error {
	var vol volume.Volinfo
	e := c.Get("volinfo", &vol)
	if e != nil {
		return errors.New("failed to get volinfo from context")
	}

	e = volume.AddOrUpdateVolumeFunc(&vol)
	if e != nil {
		c.Logger().WithFields(log.Fields{"error": e.Error(),
			"volume": vol.Name,
		}).Error("Failed to create volume")
		return e
	}

	log.WithField("volume", vol.Name).Debug("new volume added")
	return nil
}
Example #5
0
func validateVolumeCreate(c transaction.TxnCtx) error {

	var req volume.VolCreateRequest
	err := c.Get("req", &req)
	if err != nil {
		return err
	}

	var vol volume.Volinfo
	err = c.Get("volinfo", &vol)
	if err != nil {
		return err
	}

	// FIXME: Return values of this function are inconsistent and unused
	_, err = volume.ValidateBrickEntriesFunc(vol.Bricks, vol.ID, req.Force)
	if err != nil {
		return err
	}

	return nil
}
Example #6
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
}
Example #7
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
}
Example #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
}