func (s *DeployHelperSuite) TestResolveDepValues(c *C) {
	datamodel.Zk.RecursiveDelete(helper.GetBaseEnvPath())
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPath(true))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPath(false))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPortsPath(true))
	datamodel.Zk.RecursiveDelete(helper.GetBaseRouterPortsPath(false))
	datamodel.CreateEnvPath()
	datamodel.CreateRouterPaths()
	datamodel.Router(true, "dev", "somehost", "1.2.3.4").Save()
	zkEnv := datamodel.Env("root")
	err := zkEnv.Save()
	c.Assert(err, IsNil)
	deps, err := ResolveDepValues("app", zkEnv, []string{"hello-go"}, false, &Task{})
	c.Assert(err, Not(IsNil))
	_, err = datamodel.CreateInstance("hello-go", "1234567890", "root", "myhost")
	c.Assert(err, IsNil)
	_, err = datamodel.CreateOrUpdateApp(false, false, "app", "ssh://github.com/ooyala/apo", "/", "*****@*****.**")
	c.Assert(err, IsNil)
	zkApp, err := datamodel.CreateOrUpdateApp(false, true, "hello-go", "ssh://github.com/ooyala/hello-go", "/", "*****@*****.**")
	c.Assert(err, IsNil)
	c.Assert(zkApp.AddDependerAppData(&DependerAppData{Name: "app", DependerEnvData: map[string]*DependerEnvData{"root": &DependerEnvData{Name: "root"}}}), IsNil)
	deps, err = ResolveDepValues("app", zkEnv, []string{"hello-go"}, false, &Task{})
	c.Assert(err, IsNil)
	c.Assert(deps["dev1"]["hello-go"].DataMap["address"], Equals, fmt.Sprintf("internal-router.1.%s.suffix.com:%d", Region, datamodel.MinRouterPort))
	deps, err = ResolveDepValues("app", zkEnv, []string{"hello-go"}, true, &Task{})
	c.Assert(err, IsNil)
	c.Assert(deps["dev1"]["hello-go"].EncryptedData, Not(Equals), "")
	c.Assert(deps["dev1"]["hello-go"].DataMap, IsNil)
	scrypto.DecryptAppDep(deps["dev1"]["hello-go"])
	c.Assert(deps["dev1"]["hello-go"].DataMap, Not(IsNil))
	c.Assert(deps["dev1"]["hello-go"].DataMap["address"], Equals, fmt.Sprintf("internal-router.1.%s.suffix.com:%d", Region, datamodel.MinRouterPort))
}
func (e *UpdateEnvExecutor) Execute(t *Task) error {
	// error checking
	if e.arg.Name == "" {
		return errors.New("Please specify a name")
	}
	if IsEnvInUse(e.arg.Name) {
		return errors.New(fmt.Sprintf("%s is in use and cannot be updated", e.arg.Name))
	}
	env := datamodel.Env(e.arg.Name)
	if err := env.Save(); err != nil {
		return err
	}
	e.reply.Status = StatusOk
	return nil
}
Example #3
0
func (e *DeleteEnvExecutor) Execute(t *Task) (err error) {
	// error checking
	if e.arg.Name == "" {
		return errors.New("Please specify a name")
	}
	if IsEnvInUse(e.arg.Name) {
		return errors.New(fmt.Sprintf("%s is in use and cannot be deleted", e.arg.Name))
	}
	env := datamodel.Env(e.arg.Name)
	if err := env.Delete(); err != nil {
		e.reply.Status = StatusError
	} else {
		DeleteEnv(e.arg.Name)
		e.reply.Status = StatusOk
	}
	return err
}
Example #4
0
func (e *UpdateEnvExecutor) Execute(t *Task) error {
	// error checking
	if e.arg.Name == "" {
		return errors.New("Please specify a name")
	}
	if !EnvRegexp.MatchString(e.arg.Name) {
		return errors.New("Env name must be ^[A-Za-z0-9-]+$")
	}
	if IsEnvInUse(e.arg.Name) {
		return errors.New(fmt.Sprintf("%s already exits", e.arg.Name))
	}
	env := datamodel.Env(e.arg.Name)
	if err := env.Save(); err != nil {
		return err
	}
	e.reply.Status = StatusOk
	return nil
}