当前位置: 首页>>代码示例>>Golang>>正文


Golang Service.IpvsId方法代码示例

本文整理汇总了Golang中github.com/luizbafilho/fusis/types.Service.IpvsId方法的典型用法代码示例。如果您正苦于以下问题:Golang Service.IpvsId方法的具体用法?Golang Service.IpvsId怎么用?Golang Service.IpvsId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/luizbafilho/fusis/types.Service的用法示例。


在下文中一共展示了Service.IpvsId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: AddService

// AddService adds a new services to store. It validates the name
// uniqueness and the IPVS uniqueness by saving the IPVS key
// in the store, which consists in a combination of address, port
// and protocol.
func (s *FusisStore) AddService(svc *types.Service) error {
	svcKey := s.key("services", svc.GetId(), "config")
	ipvsKey := s.key("ipvs-ids", "services", svc.IpvsId())
	// Validating service
	if err := s.validateService(svc); err != nil {
		return err
	}
	if err := s.validateServiceNameUniqueness(svcKey); err != nil {
		return err
	}
	if err := s.validateServiceIpvsUniqueness(ipvsKey); err != nil {
		return err
	}

	// TODO: Make the persistence of service and ipvs id atomic.
	// Pesisting service
	value, err := json.Marshal(svc)
	if err != nil {
		return errors.Wrapf(err, "error marshaling service: %v", svc)
	}
	err = s.kv.Put(svcKey, value, nil)
	if err != nil {
		return errors.Wrapf(err, "error sending service to store: %v", svc)
	}

	// 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 service ipvs id to store: %v", svc.IpvsId())
	}

	return nil
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:37,代码来源:store.go

示例2: DeleteService

func (s *FusisStore) DeleteService(svc *types.Service) error {
	// TODO: Make all these actions atomic

	key := s.key("services", svc.GetId())
	err := s.kv.DeleteTree(key)
	if err != nil {
		return errors.Wrapf(err, "error trying to delete service: %v", svc)
	}

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

	// Deleting dependent destionations
	dsts, err := s.GetDestinations()
	if err != nil {
		return errors.Wrapf(err, "get destinations from deleted service failed: %#v", svc)
	}

	for _, dst := range dsts {
		if dst.ServiceId == svc.GetId() {
			if err := s.DeleteDestination(svc, &dst); err != nil {
				return errors.Wrap(err, "deleting dependent destination failed")
			}
		}
	}

	// Deleting checks
	exists, err := s.kv.Exists(s.key("checks", svc.GetId()))
	if err != nil {
		return errors.Wrapf(err, "verifying health check to service: %s failed", svc.GetId())
	}

	if exists {
		if err := s.DeleteCheck(types.CheckSpec{ServiceID: svc.GetId()}); err != nil {
			return errors.Wrap(err, "deleting dependent check failed")
		}
	}

	return nil
}
开发者ID:luizbafilho,项目名称:fusis,代码行数:43,代码来源:store.go


注:本文中的github.com/luizbafilho/fusis/types.Service.IpvsId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。