Beispiel #1
0
func (sr *ServiceRegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
	srv := obj.(api.Service)
	if srv.ID == "" {
		return nil, fmt.Errorf("ID should not be empty: %#v", srv)
	}
	return apiserver.MakeAsync(func() (interface{}, error) {
		// TODO: Consider moving this to a rectification loop, so that we make/remove external load balancers
		// correctly no matter what http operations happen.
		if srv.CreateExternalLoadBalancer {
			var balancer cloudprovider.TCPLoadBalancer
			var ok bool
			if sr.cloud != nil {
				balancer, ok = sr.cloud.TCPLoadBalancer()
			}
			if ok && balancer != nil {
				hosts, err := sr.machines.List()
				if err != nil {
					return nil, err
				}
				err = balancer.CreateTCPLoadBalancer(srv.ID, "us-central1", srv.Port, hosts)
				if err != nil {
					return nil, err
				}
			} else {
				return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.")
			}
		}
		// TODO actually wait for the object to be fully created here.
		err := sr.registry.CreateService(srv)
		if err != nil {
			return nil, err
		}
		return sr.registry.GetService(srv.ID)
	}), nil
}
Beispiel #2
0
func (sr *ServiceRegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
	srv := obj.(api.Service)
	if errs := api.ValidateService(&srv); len(errs) > 0 {
		return nil, fmt.Errorf("Validation errors: %v", errs)
	}
	return apiserver.MakeAsync(func() (interface{}, error) {
		// TODO: Consider moving this to a rectification loop, so that we make/remove external load balancers
		// correctly no matter what http operations happen.
		if srv.CreateExternalLoadBalancer {
			var balancer cloudprovider.TCPLoadBalancer
			var zones cloudprovider.Zones
			var ok bool
			if sr.cloud != nil {
				balancer, ok = sr.cloud.TCPLoadBalancer()
				if ok {
					zones, ok = sr.cloud.Zones()
				}
			}
			if ok && balancer != nil && zones != nil {
				hosts, err := sr.machines.List()
				if err != nil {
					return nil, err
				}
				zone, err := zones.GetZone()
				if err != nil {
					return nil, err
				}
				err = balancer.CreateTCPLoadBalancer(srv.ID, zone, srv.Port, hosts)
				if err != nil {
					return nil, err
				}
			} else {
				return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.")
			}
		}
		// TODO actually wait for the object to be fully created here.
		err := sr.registry.CreateService(srv)
		if err != nil {
			return nil, err
		}
		return sr.registry.GetService(srv.ID)
	}), nil
}
func (sr *ServiceRegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
	srv := obj.(api.Service)
	if srv.CreateExternalLoadBalancer {
		var balancer cloudprovider.TCPLoadBalancer
		var ok bool
		if sr.cloud != nil {
			balancer, ok = sr.cloud.TCPLoadBalancer()
		}
		if ok && balancer != nil {
			err := balancer.CreateTCPLoadBalancer(srv.ID, "us-central1", srv.Port, sr.hosts)
			if err != nil {
				return nil, err
			}
		} else {
			return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.")
		}
	}
	// TODO actually wait for the object to be fully created here.
	return apiserver.MakeAsync(func() interface{} { return obj }), sr.registry.CreateService(srv)
}
Beispiel #4
0
func (sr *ServiceRegistryStorage) Create(obj interface{}) error {
	srv := obj.(api.Service)
	if srv.CreateExternalLoadBalancer {
		var balancer cloudprovider.TCPLoadBalancer
		if sr.cloud != nil {
			var err error
			balancer, err = sr.cloud.TCPLoadBalancer()
			if err != nil {
				return err
			}
		}
		if balancer != nil {
			err := balancer.CreateTCPLoadBalancer(srv.ID, "us-central1", srv.Port, sr.hosts)
			if err != nil {
				return err
			}
		} else {
			return fmt.Errorf("requested an external service, but no cloud provider supplied.")
		}
	}
	return sr.registry.CreateService(srv)
}