Esempio n. 1
0
func (e *AddDependerEnvDataForDependerAppExecutor) Execute(t *Task) error {
	if e.arg.App == "" {
		return errors.New("Please specify an app")
	}
	if e.arg.Depender == "" {
		return errors.New("Please specify a depender app")
	}
	if e.arg.DependerEnvData == nil {
		return errors.New("Please specify data for the env")
	} else if e.arg.DependerEnvData.Name == "" {
		return errors.New("Please specify name for the env")
	}
	// verify SecurityGroups are valid
	for ipGroup, _ := range e.arg.DependerEnvData.SecurityGroup {
		if _, err := datamodel.GetIPGroup(ipGroup); err != nil {
			return errors.New("Invalid IP Group in Security Group: " + ipGroup)
		}
	}
	zkApp, err := datamodel.GetApp(e.arg.App)
	if err != nil {
		e.reply.Status = StatusError
		return err
	}
	err = zkApp.AddDependerEnvDataForDependerApp(e.arg.Depender, e.arg.DependerEnvData)
	if err != nil {
		e.reply.Status = StatusError
		return err
	}
	e.reply.Status = StatusOk
	castedApp := App(*zkApp)
	e.reply.App = &castedApp
	return err
}
Esempio n. 2
0
func RemoveIPFromGroup(name, ip string) error {
	lock.Lock()
	defer lock.Unlock()
	log.Printf("[RemoveIPFromGroup] Removing " + ip + " from " + name)
	group, err := datamodel.GetIPGroup(name)
	if err != nil {
		// no group exists, create it
		group = &datamodel.ZkIPGroup{Name: name, IPs: []string{}}
	} else {
		// dedup
		ipsMap := map[string]bool{}
		for _, theIP := range group.IPs {
			ipsMap[theIP] = true
		}
		delete(ipsMap, ip) // delete the ip we want to remove
		group.IPs = []string{}
		for theIP, _ := range ipsMap {
			group.IPs = append(group.IPs, theIP)
		}
	}

	if err := group.Save(); err != nil {
		return err
	}
	return updateSupervisors(name, group.IPs)
}
Esempio n. 3
0
func AddIPToGroup(name, ip string) error {
	lock.Lock()
	defer lock.Unlock()
	log.Printf("[AddIPToGroup] Adding " + ip + " to " + name)
	group, err := datamodel.GetIPGroup(name)
	if err != nil {
		// no group exists, create it
		group = &datamodel.ZkIPGroup{Name: name, IPs: []string{ip}}
	} else {
		// dedup
		ipsMap := map[string]bool{}
		for _, theIP := range group.IPs {
			ipsMap[theIP] = true
		}
		ipsMap[ip] = true
		group.IPs = []string{}
		for theIP, _ := range ipsMap {
			group.IPs = append(group.IPs, theIP)
		}
	}

	if err := group.Save(); err != nil {
		return err
	}
	return updateSupervisors(name, group.IPs)
}
Esempio n. 4
0
func GetIPGroup(name string) (*IPGroup, error) {
	lock.RLock()
	defer lock.RUnlock()
	// get the IP group
	group, err := datamodel.GetIPGroup(name)
	if err != nil {
		return nil, err
	}
	typedGroup := IPGroup(*group)
	return &typedGroup, nil
}
Esempio n. 5
0
func UpdateSupervisor(host string) error {
	lock.RLock()
	defer lock.RUnlock()
	groups, err := datamodel.ListIPGroups()
	if err != nil {
		return err
	}
	for _, name := range groups {
		group, err := datamodel.GetIPGroup(name)
		if err != nil {
			return err
		}
		if _, err := supervisor.UpdateIPGroup(host, group.Name, group.IPs); err != nil {
			return err
		}
	}
	return nil
}
Esempio n. 6
0
func DeleteIPGroup(name string) error {
	lock.Lock()
	defer lock.Unlock()
	log.Printf("[DeleteIPGroup] Deleting " + name)
	// delete the IP group
	group, err := datamodel.GetIPGroup(name)
	if err != nil {
		return err
	}
	if err := group.Delete(); err != nil {
		return err
	}
	// update all supervisors
	supers, err := datamodel.ListSupervisors()
	if err != nil {
		return err
	}
	for _, host := range supers {
		if _, err := supervisor.DeleteIPGroup(host, name); err != nil {
			return err
		}
	}
	return nil
}