Esempio n. 1
0
func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
	pod := obj.(*api.Pod)
	if errs := api.ValidatePod(pod); len(errs) > 0 {
		return nil, apiserver.NewInvalidErr("pod", pod.ID, errs)
	}
	return apiserver.MakeAsync(func() (interface{}, error) {
		if err := rs.registry.UpdatePod(*pod); err != nil {
			return nil, err
		}
		return rs.registry.GetPod(pod.ID)
	}), nil
}
Esempio n. 2
0
func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
	srv := obj.(*api.Service)
	if errs := api.ValidateService(srv); len(errs) > 0 {
		return nil, apiserver.NewInvalidErr("service", srv.ID, errs)
	}
	return apiserver.MakeAsync(func() (interface{}, error) {
		// TODO: check to see if external load balancer status changed
		err := rs.registry.UpdateService(*srv)
		if err != nil {
			return nil, err
		}
		return rs.registry.GetService(srv.ID)
	}), nil
}
Esempio n. 3
0
// Update replaces a given ReplicationController instance with an existing
// instance in storage.registry.
func (rs *RegistryStorage) Update(obj interface{}) (<-chan interface{}, error) {
	controller, ok := obj.(*api.ReplicationController)
	if !ok {
		return nil, fmt.Errorf("not a replication controller: %#v", obj)
	}
	if errs := api.ValidateReplicationController(controller); len(errs) > 0 {
		return nil, apiserver.NewInvalidErr("replicationController", controller.ID, errs)
	}
	return apiserver.MakeAsync(func() (interface{}, error) {
		err := rs.registry.UpdateController(*controller)
		if err != nil {
			return nil, err
		}
		return rs.registry.GetController(controller.ID)
	}), nil
}
Esempio n. 4
0
func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
	srv := obj.(*api.Service)
	if errs := api.ValidateService(srv); len(errs) > 0 {
		return nil, apiserver.NewInvalidErr("service", srv.ID, errs)
	}

	srv.CreationTimestamp = util.Now()

	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 {
			if rs.cloud == nil {
				return nil, fmt.Errorf("requested an external service, but no cloud provider supplied.")
			}
			balancer, ok := rs.cloud.TCPLoadBalancer()
			if !ok {
				return nil, fmt.Errorf("The cloud provider does not support external TCP load balancers.")
			}
			zones, ok := rs.cloud.Zones()
			if !ok {
				return nil, fmt.Errorf("The cloud provider does not support zone enumeration.")
			}
			hosts, err := rs.machines.List()
			if err != nil {
				return nil, err
			}
			zone, err := zones.GetZone()
			if err != nil {
				return nil, err
			}
			err = balancer.CreateTCPLoadBalancer(srv.ID, zone.Region, srv.Port, hosts)
			if err != nil {
				return nil, err
			}
		}
		err := rs.registry.CreateService(*srv)
		if err != nil {
			return nil, err
		}
		return rs.registry.GetService(srv.ID)
	}), nil
}
Esempio n. 5
0
func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
	pod := obj.(*api.Pod)
	if len(pod.ID) == 0 {
		pod.ID = uuid.NewUUID().String()
	}
	pod.DesiredState.Manifest.ID = pod.ID
	if errs := api.ValidatePod(pod); len(errs) > 0 {
		return nil, apiserver.NewInvalidErr("pod", pod.ID, errs)
	}

	pod.CreationTimestamp = util.Now()

	return apiserver.MakeAsync(func() (interface{}, error) {
		if err := rs.registry.CreatePod(*pod); err != nil {
			return nil, err
		}
		return rs.registry.GetPod(pod.ID)
	}), nil
}
Esempio n. 6
0
// Create registers the given ReplicationController.
func (rs *RegistryStorage) Create(obj interface{}) (<-chan interface{}, error) {
	controller, ok := obj.(*api.ReplicationController)
	if !ok {
		return nil, fmt.Errorf("not a replication controller: %#v", obj)
	}
	if len(controller.ID) == 0 {
		controller.ID = uuid.NewUUID().String()
	}
	// Pod Manifest ID should be assigned by the pod API
	controller.DesiredState.PodTemplate.DesiredState.Manifest.ID = ""
	if errs := api.ValidateReplicationController(controller); len(errs) > 0 {
		return nil, apiserver.NewInvalidErr("replicationController", controller.ID, errs)
	}

	controller.CreationTimestamp = util.Now()

	return apiserver.MakeAsync(func() (interface{}, error) {
		err := rs.registry.CreateController(*controller)
		if err != nil {
			return nil, err
		}
		return rs.registry.GetController(controller.ID)
	}), nil
}