func getProviderName(host string) (*global.PredefClouds, error) { pdc := &global.PredefClouds{} conn, err := db.Conn(PREDEFCLOUDSBUCKET) if err != nil { return pdc, err } ferr := conn.FetchStruct(host, pdc) if ferr != nil { return pdc, ferr } sshkeyerr := downloadSshFiles(pdc, "key", 0600) if sshkeyerr != nil { return pdc, sshkeyerr } sshpuberr := downloadSshFiles(pdc, "pub", 0644) if sshpuberr != nil { return pdc, sshpuberr } return pdc, nil }
func (self *Server) Checker() { log.Info("verifying rabbitmq") factor, err := amqp.Factory() if err != nil { log.Error("Error: %v\nFailed to get the queue", err) } _, connerr := factor.Dial() if connerr != nil { fmt.Fprintf(os.Stderr, "Error: %v\n Please start rabbitmq service.\n", connerr) os.Exit(1) } log.Info("rabbitmq connected [ok]") log.Info("verifying riak") rconn, rerr := db.Conn("connection") if rerr != nil { fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", rerr) os.Exit(1) } data := "sampledata" ferr := rconn.StoreObject("sampleobject", data) if ferr != nil { fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", ferr) os.Exit(1) } defer rconn.Close() log.Info("riak connected [ok]") }
func updateIndex(ip string, pos uint) error { index := global.IPIndex{} res, err := index.Get(global.IPINDEXKEY) if err != nil { log.Error("Error: Riak didn't cooperate:\n%s.", err) return err } update := global.IPIndex{ Ip: ip, Subnet: res.Subnet, Index: pos, } conn, connerr := db.Conn("ipindex") if connerr != nil { log.Error("Failed to riak connection : %s", connerr) return connerr } serr := conn.StoreStruct(global.IPINDEXKEY, &update) if serr != nil { log.Error("Failed to store the update index value : %s", serr) return serr } log.Info("Docker network index update was successfully.") return nil }
func getProviderName(host string) (*global.PredefClouds, error) { pdc := &global.PredefClouds{} predefBucket, perr := config.GetString("riak:predefclouds") if perr != nil { return pdc, perr } conn, err := db.Conn(predefBucket) if err != nil { return pdc, err } ferr := conn.FetchStruct(host, pdc) if ferr != nil { return pdc, ferr } sshkeyerr := downloadSshFiles(pdc, "key", 0600) if sshkeyerr != nil { return pdc, sshkeyerr } sshpuberr := downloadSshFiles(pdc, "pub", 0644) if sshpuberr != nil { return pdc, sshpuberr } return pdc, nil }
/* * * UpdateComponent updates the ipaddress that is bound to the container * It talks to riakdb and updates the respective component(s) */ func updatecomponent(assembly *global.AssemblyWithComponents, ipaddress string, id string, port string) { log.Debug("Update process for component with ip and container id") mySlice := make([]*global.KeyValuePair, 3) mySlice[0] = &global.KeyValuePair{Key: "ip", Value: ipaddress} mySlice[1] = &global.KeyValuePair{Key: "id", Value: id} mySlice[2] = &global.KeyValuePair{Key: "port", Value: port} update := global.Component{ Id: assembly.Components[0].Id, Name: assembly.Components[0].Name, ToscaType: assembly.Components[0].ToscaType, Inputs: assembly.Components[0].Inputs, Outputs: mySlice, Artifacts: assembly.Components[0].Artifacts, RelatedComponents: assembly.Components[0].RelatedComponents, Operations: assembly.Components[0].Operations, Status: assembly.Components[0].Status, CreatedAt: assembly.Components[0].CreatedAt, } conn, connerr := db.Conn("components") if connerr != nil { log.Error("Failed to riak connection : %s", connerr) } err := conn.StoreStruct(assembly.Components[0].Id, &update) if err != nil { log.Error("Failed to store the update component data : %s", err) } log.Info("Container component update was successfully.") }
func (asm *Assembly) GetAssemblyWithComponents(asmId string) (*AssemblyWithComponents, error) { log.Info("Get Assembly message %v", asmId) var j = -1 asmresult := &AssemblyWithComponents{} conn, err := db.Conn("assembly") if err != nil { return asmresult, err } //appout := &Requests{} ferr := conn.FetchStruct(asmId, asm) if ferr != nil { return asmresult, ferr } var arraycomponent = make([]*Component, len(asm.Components)) for i := range asm.Components { t := strings.TrimSpace(asm.Components[i]) if len(t) > 1 { componentID := asm.Components[i] component := Component{Id: componentID} com, err := component.Get(componentID) if err != nil { log.Error("Error: Riak didn't cooperate:\n%s.", err) return asmresult, err } j++ arraycomponent[j] = com } } result := &AssemblyWithComponents{Id: asm.Id, Name: asm.Name, ToscaType: asm.ToscaType, Components: arraycomponent, Requirements: asm.Requirements, Policies: asm.Policies, Inputs: asm.Inputs, Outputs: asm.Outputs, Operations: asm.Operations, Status: asm.Status, CreatedAt: asm.CreatedAt} defer conn.Close() return result, nil }
func downloadSshFiles(pdc *global.PredefClouds, keyvalue string, permission os.FileMode) error { sa := make([]string, 2) sa = strings.Split(pdc.Access.IdentityFile, "_") email, name := sa[0], sa[1] ssh := &db.SshObject{} sshBucket, serr := config.GetString("riak:ssh_files") if serr != nil { return serr } conn, err := db.Conn(sshBucket) if err != nil { return err } ferr := conn.FetchObject(pdc.Access.IdentityFile+"_"+keyvalue, ssh) if ferr != nil { return ferr } cloudkeysBucket, ckberr := config.GetString("riak:cloud_keys") if ckberr != nil { return ckberr } megam_home, ckberr := config.GetString("megam_home") if ckberr != nil { return ckberr } basePath := megam_home + cloudkeysBucket dir := path.Join(basePath, email) filePath := path.Join(dir, name+"."+keyvalue) if _, err := os.Stat(dir); os.IsNotExist(err) { fmt.Printf("no such file or directory: %s", dir) if errm := os.MkdirAll(dir, 0777); errm != nil { return errm } // open output file _, err := os.Create(filePath) if err != nil { return err } } errf := ioutil.WriteFile(filePath, []byte(ssh.Data), permission) if errf != nil { return errf } return nil }
/** **fetch the ip index data from riak and parse the json to struct **/ func (req *IPIndex) Get(key string) (*IPIndex, error) { log.Info("Get IPIndex value %v", key) conn, err := db.Conn("ipindex") if err != nil { return req, err } ferr := conn.FetchStruct(key, req) if ferr != nil { return req, ferr } defer conn.Close() return req, nil }
func GetAccessKeys(pdc *global.PredefClouds) (*AccessKeys, error) { keys := &AccessKeys{} conn, err := db.Conn(CLOUDACCESSKEYSBUCKET) if err != nil { return keys, err } ferr := conn.FetchStruct(pdc.Access.VaultLocation, keys) if ferr != nil { return keys, ferr } return keys, nil }
func GetPredefClouds(host string) (*global.PredefClouds, error) { pdc := &global.PredefClouds{} conn, err := db.Conn(PREDEFCLOUDSBUCKET) if err != nil { return pdc, err } ferr := conn.FetchStruct(host, pdc) if ferr != nil { return pdc, ferr } return pdc, nil }
/** **fetch the request json from riak and parse the json to struct **/ func (req *Request) Get(reqId string) (*Request, error) { log.Info("Get Request message %v", reqId) conn, err := db.Conn("requests") if err != nil { return req, err } //appout := &Requests{} ferr := conn.FetchStruct(reqId, req) if ferr != nil { return req, ferr } defer conn.Close() return req, nil }
/** **fetch the component json from riak and parse the json to struct **/ func (asm *Component) Get(asmId string) (*Component, error) { log.Info("Get Component message %v", asmId) conn, err := db.Conn("components") if err != nil { return asm, err } //appout := &Requests{} ferr := conn.FetchStruct(asmId, asm) if ferr != nil { return asm, ferr } defer conn.Close() return asm, nil }
func (asm *Assemblies) Get(asmId string) (*Assemblies, error) { log.Info("Get Assemblies message %v", asmId) conn, err := db.Conn("assemblies") if err != nil { return asm, err } //appout := &Requests{} ferr := conn.FetchStruct(asmId, asm) if ferr != nil { return asm, ferr } defer conn.Close() log.Debug(asm) log.Debug("----------ASSEMBLIES--------") return asm, nil }
func GetAccessKeys(pdc *global.PredefClouds) (*AccessKeys, error) { keys := &AccessKeys{} cakbBucket, cakberr := config.GetString("riak:cloud_access_keys") if cakberr != nil { return keys, cakberr } conn, err := db.Conn(cakbBucket) if err != nil { return keys, err } ferr := conn.FetchStruct(pdc.Access.VaultLocation, keys) if ferr != nil { return keys, ferr } return keys, nil }
func GetPredefClouds(host string) (*global.PredefClouds, error) { pdc := &global.PredefClouds{} predefBucket, perr := config.GetString("riak:predefclouds") if perr != nil { return pdc, perr } conn, err := db.Conn(predefBucket) if err != nil { return pdc, err } ferr := conn.FetchStruct(host, pdc) if ferr != nil { return pdc, ferr } return pdc, nil }
func (self *Server) IPInit() { rconn, rerr := db.Conn("ipindex") if rerr != nil { fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", rerr) os.Exit(1) } index := global.IPIndex{} subnet, _ := config.GetString("swarm:subnet") _, err := index.Get(global.IPINDEXKEY) if err != nil { data := &global.IPIndex{Ip: subnet, Subnet: subnet, Index: 1} res2B, _ := json.Marshal(data) ferr := rconn.StoreObject(global.IPINDEXKEY, string(res2B)) if ferr != nil { fmt.Fprintf(os.Stderr, "Error: %v\n Please start Riak service.\n", ferr) os.Exit(1) } } defer rconn.Close() }
} var updateStatus = action.Action{ Name: "updatestatus", Forward: func(ctx action.FWContext) (action.Result, error) { var app global.AssemblyWithComponents switch ctx.Params[0].(type) { case global.AssemblyWithComponents: app = ctx.Params[0].(global.AssemblyWithComponents) case *global.AssemblyWithComponents: app = *ctx.Params[0].(*global.AssemblyWithComponents) default: return nil, errors.New("First parameter must be App or *global.AssemblyWithComponents.") } asm := &global.Assembly{} conn, err := db.Conn("assembly") if err != nil { return nil, err } ferr := conn.FetchStruct(app.Id, asm) if ferr != nil { return nil, ferr } update := global.Assembly{ Id: asm.Id, JsonClaz: asm.JsonClaz, Name: asm.Name, Components: asm.Components, ToscaType: asm.ToscaType,
func uploadENVVariables(asm *global.AssemblyWithComponents, com *global.Component) error { megam_home, ckberr := config.GetString("megam_home") if ckberr != nil { return ckberr } conn, err := db.Conn("assemblies") if err != nil { return err } act_id, actberr := config.GetString("account_id") if actberr != nil { return actberr } arr, ferr := conn.FetchObjectByIndex("assemblies", ASSEMBLIESINDEX, act_id, "", "") if ferr != nil { return ferr } for i := range arr { s := global.BytesToString(arr[i]) rassemblies := &global.Assemblies{} rams, ramserr := rassemblies.Get(s) if ramserr != nil { return ramserr } for l := range rams.Assemblies { if len(rams.Assemblies[l]) > 0 { assembly := global.Assembly{Id: rams.Assemblies[l]} rasm, rasmerr := assembly.GetAssemblyWithComponents(rams.Assemblies[l]) if rasmerr != nil { log.Error("Error: Riak didn't cooperate:\n%s.", rasmerr) return rasmerr } for j := range com.RelatedComponents { if len(com.RelatedComponents[j]) > 0 { rasmname := strings.Split(com.RelatedComponents[j], "/") assemblyname := strings.Split(rasmname[0], ".")[0] if rasm.Name == assemblyname { for rc := range rasm.Components { if rasm.Components[rc] != nil { if rasmname[1] == rasm.Components[rc].Name { basePath := megam_home dir := path.Join(basePath, com.Name) filePath := path.Join(dir, "env.sh") if _, err := os.Stat(dir); os.IsNotExist(err) { fmt.Printf("no such file or directory: %s", dir) if errm := os.MkdirAll(dir, 0777); errm != nil { return errm } // open output file _, err := os.Create(filePath) if err != nil { return err } } str := "BINDED_HOST_NAME=" + rasm.Components[rc].Name + "\n" + "HOST=" + rasm.Name + "." + GetParsedValue(rasm.Inputs, "domain") + "\n" + "\nDBNAME=" + com.Name + "\n" + "PORT=" + GetParsedValue(rasm.Components[rc].Inputs, "port") + "\nUSERNAME="******"username") + "\nPASSWORD="******"password") + "\nDBUSER="******"username") + "\nDBPASSWORD="******"dbpassword") + "\n" errf := ioutil.WriteFile(filePath, []byte(str), 0644) if errf != nil { return errf } //return nil } } } } } } } } } return nil }