Exemplo n.º 1
0
func (s *FusisStore) AddDestination(svc *types.Service, dst *types.Destination) error {
	dstKey := s.key("destinations", svc.GetId(), dst.GetId())
	ipvsKey := s.key("ipvs-ids", "destinations", dst.IpvsId())

	// Validating destination
	if err := s.validateDestination(dst); err != nil {
		return err
	}
	if err := s.validateDestinationNameUniqueness(dstKey); err != nil {
		return err
	}
	if err := s.validateDestinationIpvsUniqueness(ipvsKey); err != nil {
		return err
	}

	// Persisting destination
	value, err := json.Marshal(dst)
	if err != nil {
		return errors.Wrapf(err, "error marshaling destination: %v", dst)
	}
	err = s.kv.Put(dstKey, value, nil)
	if err != nil {
		return errors.Wrapf(err, "error sending destination to store: %v", dst)
	}
	log.Debugf("[store] Added destination: %s with key: %s", value, dstKey)

	// Persisting IPVS key. So it can be validated.
	err = s.kv.Put(ipvsKey, []byte("true"), nil)
	if err != nil {
		return errors.Wrapf(err, "error sending destination ipvs id to store: %v", dst.IpvsId())
	}

	return nil
}
Exemplo n.º 2
0
func (s *FusisStore) DeleteDestination(svc *types.Service, dst *types.Destination) error {
	key := s.key("destinations", svc.GetId(), dst.GetId())

	err := s.kv.DeleteTree(key)
	if err != nil {
		return errors.Wrapf(err, "error trying to delete destination: %v", dst)
	}
	log.Debugf("[store] Deleted destination: %s", key)

	ipvsKey := s.key("ipvs-ids", "destinations", dst.IpvsId())
	err = s.kv.Delete(ipvsKey)
	if err != nil {
		return errors.Wrapf(err, "error trying to delete destination ipvs id: %s", ipvsKey)
	}

	return nil
}