Example #1
0
func (m *FusisMonitor) newCheck(spec types.CheckSpec, dst types.Destination) Check {
	switch spec.Type {
	default:
		check := CheckTCP{Spec: spec, DestinationID: dst.GetId(), Status: BAD}
		check.Init(m.changesCh, dst)
		return &check
	}
}
Example #2
0
func (b *FusisBalancer) DeleteDestination(dst *types.Destination) error {
	svc, err := b.state.GetService(dst.ServiceId)
	if err != nil {
		return err
	}

	_, err = b.state.GetDestination(dst.GetId())
	if err != nil {
		return err
	}

	return b.store.DeleteDestination(svc, dst)
}
Example #3
0
func (b *FusisBalancer) AddDestination(svc *types.Service, dst *types.Destination) error {
	// Set defaults
	if dst.Weight == 0 {
		dst.Weight = 1
	}
	if dst.Mode == "" {
		dst.Mode = "nat"
	}

	//TODO: Configurate destination
	// if err := b.setupDestination(svc, dst); err != nil {
	// 	return errors.Wrap(err, "setup destination failed")
	// }

	return b.store.AddDestination(svc, dst)
}
Example #4
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
}
Example #5
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
}
Example #6
0
func (s *FusisState) DeleteDestination(dst *types.Destination) {
	s.Lock()
	defer s.Unlock()

	delete(s.destinations, dst.GetId())
}
Example #7
0
func (s *FusisState) AddDestination(dst types.Destination) {
	s.Lock()
	defer s.Unlock()

	s.destinations[dst.GetId()] = dst
}