• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang log.Error函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/starkandwayne/rdpgd/log.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: BackupHandler

/* Should contain a form value dbname which equals the database name
   e.g. curl www.hostname.com/backup/now -X POST -d "dbname=nameofdatabase"
   The {how} should be either "now" or "enqueue" */
func BackupHandler(w http.ResponseWriter, request *http.Request) {
	vars := mux.Vars(request)
	dbname := request.FormValue("dbname")
	t := tasks.NewTask()
	t.Action = "BackupDatabase"
	t.Data = dbname
	t.Node = globals.MyIP
	t.Role = globals.ServiceRole
	t.TTL = 3600
	t.ClusterService = globals.ClusterService
	t.NodeType = "read"
	if rdpgconsul.IsWriteNode(globals.MyIP) {
		t.NodeType = "write"
	}

	var err error
	if dbname != "rdpg" {
		//Using FindByDatabase to determine if the database actually exists to be backed up.
		inst, err := instances.FindByDatabase(dbname)
		if err != nil {
			log.Error(fmt.Sprintf("admin.BackupHandler() instances.FindByDatabase(%s) Error occurred when searching for database.", dbname))
			w.WriteHeader(http.StatusInternalServerError)
			w.Write([]byte("Error encountered while searching for database"))
			return
		}
		if inst == nil {
			//...then the database doesn't exist on this cluster.
			log.Debug(fmt.Sprintf("admin.BackupHandler() Attempt to initiate backup on non-existant database with name: %s", dbname))
			w.WriteHeader(http.StatusNotFound)
			w.Write([]byte("Database not found"))
			return
		}
	}

	switch vars[`how`] {
	//Immediately calls Backup() and performs the backup
	case "now":
		err = t.BackupDatabase()
		if err != nil {
			log.Error(fmt.Sprintf(`api.BackupHandler() Task.BackupDatabase() %+v ! %s`, t, err))
			w.WriteHeader(http.StatusInternalServerError)
			w.Write([]byte("Error encountered while trying to perform backup"))
			return
		}
		w.Write([]byte("Backup completed."))
	case "enqueue":
		// Queues up a backup to be done with a worker thread gets around to it.
		// This call returns after the queuing process is done; not after the backup is done.
		err = t.Enqueue()
		if err != nil {
			log.Error(fmt.Sprintf(`api.BackupHandler() Task.Enqueue() %+v ! %s`, t, err))
			w.WriteHeader(http.StatusInternalServerError)
			w.Write([]byte("Error while trying to queue"))
			return
		}
		w.Write([]byte("Backup successfully queued."))
	default:
		w.WriteHeader(http.StatusNotFound)
	}
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:63,代码来源:backup.go


示例2: getMasterIP

func getMasterIP(clusterName string) (masterIp string, err error) {

	log.Trace(fmt.Sprintf("gpb#consul.getMasterIP() Calling out to Consul at address %s", mcConsulIP))

	consulConfig := consulapi.DefaultConfig()
	consulConfig.Address = mcConsulIP
	consulClient, err := consulapi.NewClient(consulConfig)
	if err != nil {
		log.Error(fmt.Sprintf(`gpb#consul.getMasterIP() Consul IP: %s ! %s`, mcConsulIP, err))
		return
	}

	masterNode, _, err := consulClient.Catalog().Service(fmt.Sprintf(`%s-master`, clusterName), "", nil)
	if err != nil {
		log.Error(fmt.Sprintf("gpb#consul.getMasterIP() Cluster Name: %s ! %s", clusterName, err))
		return
	}

	if len(masterNode) == 0 {
		masterIp = "0.0.0.0"
		return masterIp, errors.New("Could not find the consul master ip")
	}

	masterIp = masterNode[0].Address
	log.Trace(fmt.Sprintf("gpb#consul.getMasterIP() Found master ip for %s = %s", clusterName, masterIp))
	return masterIp, err

}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:28,代码来源:consul.go


示例3: httpAuth

func httpAuth(h http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, request *http.Request) {
		if len(request.Header["Authorization"]) == 0 {
			log.Trace(fmt.Sprintf("httpAuth(): 'Authorization' Header Required"))
			http.Error(w, "Authorization Required", http.StatusUnauthorized)
			return
		}

		auth := strings.SplitN(request.Header["Authorization"][0], " ", 2)
		if len(auth) != 2 || auth[0] != "Basic" {
			log.Error(fmt.Sprintf("httpAuth(): Unhandled Authorization Type, Expected Basic"))
			http.Error(w, "Unhandled Authorization Type, Expected Basic\n", http.StatusBadRequest)
			return
		}
		payload, err := base64.StdEncoding.DecodeString(auth[1])
		if err != nil {
			log.Error(fmt.Sprintf("httpAuth(): Authorization base64.StdEncoding.DecodeString() Failed"))
			http.Error(w, "Authorization Failed\n", http.StatusUnauthorized)
			return
		}
		nv := strings.SplitN(string(payload), ":", 2)
		if (len(nv) != 2) || !isAuthorized(nv[0], nv[1]) {
			log.Error(fmt.Sprintf("httpAuth(): Authorization Failed: !isAuthorized() nv: %+v", nv))
			http.Error(w, "Authorization Failed\n", http.StatusUnauthorized)
			return
		}
		h(w, request)
	}
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:29,代码来源:api.go


示例4: Register

// This is called on the management cluster when the service cluster has created
// a new database and is registering it's avialabilityh with the management cluster.
func (i *Instance) Register() (err error) {
	p := pg.NewPG(`127.0.0.1`, pbPort, `rdpg`, `rdpg`, pgPass)
	db, err := p.Connect()
	if err != nil {
		log.Error(fmt.Sprintf("instances.Register() p.Connect(%s) ! %s", p.URI, err))
		return err
	}
	defer db.Close()

	err = i.Lock()
	if err != nil {
		log.Error(fmt.Sprintf("instances.Instance#Register(%s) Failed Locking instance %s ! %s", i.Database, i.Database, err))
		return
	}
	sq := fmt.Sprintf(`INSERT INTO cfsb.instances (cluster_id,dbname, dbuser, dbpass,effective_at) VALUES ('%s','%s','%s','%s',CURRENT_TIMESTAMP)`, i.ClusterID, i.Database, i.User, i.Pass)
	log.Trace(fmt.Sprintf(`instances.Instance#Register(%s) > %s`, i.Database, sq))
	_, err = db.Exec(sq)
	if err != nil {
		log.Error(fmt.Sprintf("instances.Instance#Register(%s) ! %s", i.Database, err))
	}
	err = i.Unlock()
	if err != nil {
		log.Error(fmt.Sprintf(`instances.Instance#Register(%s) Unlocking ! %s`, i.InstanceID, err))
	}

	return
}
开发者ID:subhankarc,项目名称:rdpg-boshrelease,代码行数:29,代码来源:register.go


示例5: MoveRemoteBackupFiles

func MoveRemoteBackupFiles(oldPath, newPath string) (err error) {
	log.Trace("tasks.MoveRemoteBackupFiles ! Beginning to move remote backup files")
	if !rdpgs3.Configured {
		errorMessage := "tasks.MoveRemoteBackupFiles !  s3 storage is not configured; exiting"
		log.Error(errorMessage)
		return errors.New(errorMessage)
	}
	//Helper functions rely on pointing to a specific place for globals.LocalBackupLocation...
	// so, I'm going to hack that for the duration of this function
	storedPath := globals.LocalBackupPath
	globals.LocalBackupPath = oldPath
	defer func() { globals.LocalBackupPath = storedPath }() //mmmm lambdas
	//Get all of the old files...
	backupList, err := RemoteListing("", true)
	if err != nil {
		log.Error(fmt.Sprintf("tasks.MoveRemoteBackupFiles ! backup.RemoteListing erred : %s", err.Error()))
		return err
	}
	//Move them over to the new location...
	err = moveS3(backupList, oldPath, newPath)
	if err != nil {
		log.Error(fmt.Sprintf("tasks.MoveRemoteBackupFiles ! tasks.moveS3 erred : %s", err.Error()))
		return err
	}
	return nil
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:26,代码来源:upgrade.go


示例6: bdrBootstrap

func (r *RDPG) bdrBootstrap() (err error) {
	_, err = r.bootstrapLock()
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() r.bootstrapLock() ! %s`, ClusterID, err))
		return
	}

	leader := false
	key := fmt.Sprintf(`rdpg/%s/bdr/join/ip`, ClusterID)
	bdrJoinIP, err = r.getValue(key)
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() kv.getValue(%s) ! %s ...`, ClusterID, key, err))
		return err
	}
	if len(bdrJoinIP) == 0 || bdrJoinIP == globals.MyIP {
		log.Trace(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() kv.getValue(%s) BDR Join IP has not been set`, ClusterID, key))
		leader = true
	} else {
		log.Trace(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() kv.getValue(%s) BDR Join Node IP has been set to %s`, ClusterID, key, bdrJoinIP))
		leader = false
	}

	if leader {
		err = r.bdrLeaderBootstrap()
		if err != nil {
			log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() r.bdrLeaderBootstrap() ! %s`, ClusterID, err))
		}
	} else {
		err = r.bdrNonLeaderBootstrap()
		if err != nil {
			log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#Bootstrap() r.bdrNonLeaderBootstrap() ! %s`, ClusterID, err))
		}
	}
	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:35,代码来源:bootstrap.go


示例7: GetWriteMasterIP

/*
GetWriteMasterIP returns the write master IP for the service cluster.
*/
func (s *Service) GetWriteMasterIP() (ip string, err error) {
	log.Trace(fmt.Sprintf(`services.Service<%s>#GetWriteMaster()`, s.Name))
	client, err := consulapi.NewClient(consulapi.DefaultConfig())
	if err != nil {
		log.Error(fmt.Sprintf("services.Service<%s>#GetWriteMaster() ! %s", s.Name, err))
		return
	}
	catalog := client.Catalog()

	clusterID := os.Getenv("RDPGD_CLUSTER")
	if clusterID == "" {
		matrixName := os.Getenv(`RDPGD_MATRIX`)
		matrixNameSplit := strings.SplitAfterN(matrixName, `-`, -1)
		matrixColumn := os.Getenv(`RDPGD_MATRIX_COLUMN`)
		for i := 0; i < len(matrixNameSplit)-1; i++ {
			clusterID = clusterID + matrixNameSplit[i]
		}
		clusterID = clusterID + "c" + matrixColumn
	}
	svcs, _, err := catalog.Service(fmt.Sprintf(`%s-master`, clusterID), "", nil)

	if err != nil {
		log.Error(fmt.Sprintf(`services.Service<%s>#GetWriteMaster() ! %s`, s.Name, err))
		return
	}

	if len(svcs) == 0 {
		return "", nil
	}
	ip = svcs[0].Address
	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:35,代码来源:services.go


示例8: DropDatabase

func (p *PG) DropDatabase(dbname string) (err error) {
	log.Trace(fmt.Sprintf(`pg.PG<%s>#DropDatabase(%s) Dropping postgres database...`, p.IP, dbname))
	p.Set(`database`, `postgres`)
	db, err := p.Connect()
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#DropDatabase(%s) ! %s", p.IP, dbname, err))
		return
	}
	defer db.Close()

	exists, err := p.DatabaseExists(dbname)
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#DropDatabase(%s) ! %s", p.IP, dbname, err))
		return
	}
	if !exists {
		log.Error(fmt.Sprintf("pg.PG<%s>#DropDatabase(%s) Database %s already does not exist.", p.IP, dbname, err))
		return
	}

	// TODO: How do we drop a database in bdr properly?
	sq := fmt.Sprintf(`DROP DATABASE IF EXISTS %s`, dbname)
	log.Trace(fmt.Sprintf(`pg.PG<%s>#DropDatabase(%s) > %s`, p.IP, dbname, sq))
	_, err = db.Exec(sq)
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#DropDatabase(%s) ! %s", p.IP, dbname, err))
		return
	}
	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:30,代码来源:pg.go


示例9: DropUser

func (p *PG) DropUser(dbuser string) (err error) {
	log.Trace(fmt.Sprintf(`pg.PG<%s>#DropUser(%s) Dropping postgres user...`, p.IP, dbuser))
	p.Set(`database`, `postgres`)
	db, err := p.Connect()
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#DropUser(%s) %s ! %s", p.IP, dbuser, p.URI, err))
		return
	}
	defer db.Close()

	exists, err := p.UserExists(dbuser)
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#DropUser(%s) ! %s", p.IP, dbuser, err))
		return
	}
	if !exists {
		log.Error(fmt.Sprintf("pg.PG<%s>#DropUser(%s) User already does not exist, skipping.", p.IP, dbuser))
		return
	}
	// TODO: How do we drop a database in bdr properly?
	sq := fmt.Sprintf(`DROP USER %s`, dbuser)
	log.Trace(fmt.Sprintf(`pg.PG<%s>#DropDatabase(%s) > %s`, p.IP, dbuser, sq))
	_, err = db.Exec(sq)
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#DropDatabase(%s) ! %s", p.IP, dbuser, err))
		return
	}
	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:29,代码来源:pg.go


示例10: CreateExtensions

// Create given extensions on a single target host.
func (p *PG) CreateExtensions(dbname string, exts []string) (err error) {
	log.Trace(fmt.Sprintf(`pg.PG<%s>#CreateExtensions(%s) Creating postgres extensions %+v on database...`, p.IP, dbname, exts))
	p.Set(`database`, dbname)
	db, err := p.Connect()
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#CreateExtensions(%s) %s ! %s", p.IP, dbname, p.URI, err))
		return
	}

	ddlLockRE := regexp.MustCompile(`cannot acquire DDL lock|Database is locked against DDL operations`)
	// TODO: Only create extension if it doesn't already exist.
	for _, ext := range exts {
		sq := fmt.Sprintf(`CREATE EXTENSION IF NOT EXISTS "%s";`, ext)
		log.Trace(fmt.Sprintf(`pg.PG<%s>#CreateExtensions() > %s`, p.IP, sq))
		for { // Retry loop for acquiring DDL schema lock.
			_, err = db.Exec(sq)
			if err != nil {
				if ddlLockRE.MatchString(err.Error()) {
					log.Trace("pg.PG#CreateExtensions() DDL Lock not available, waiting...")
					time.Sleep(1 * time.Second)
					continue
				}
				db.Close()
				log.Error(fmt.Sprintf("pg.PG<%s>#CreateExtensions() %s ! %s", p.IP, ext, err))
				return
			}
			break
		}
	}
	db.Close()
	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:33,代码来源:pg.go


示例11: BDRDisableDatabase

// First break replication within the specified database
// Then disables the specific database from the postgres database
func (p *PG) BDRDisableDatabase(dbname string) (err error) {
	log.Trace(fmt.Sprintf(`pg.PG<%s>#BDRDisableDatabase(%s) Disabling postgres database...`, p.IP, dbname))
	p.Set(`database`, dbname)
	db, err := p.Connect()
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#BDRDisableDatabase(%s) %s ! %s", p.IP, dbname, p.URI, err))
		return
	}

	nodes := []string{}
	sq := `SELECT node_name FROM bdr.bdr_nodes;`
	err = db.Select(&nodes, sq)
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#BDRDisableDatabase(%s) %s ! %s", p.IP, dbname, sq, err))
	}
	for index, _ := range nodes {
		sq := fmt.Sprintf(`SELECT bdr.bdr_part_by_node_names(ARRAY['%s']);`, nodes[index])
		_, err = db.Exec(sq)
		if err != nil {
			log.Error(fmt.Sprintf("pg.PG<%s>#BDRDisableDatabase(%s) %s ! %s", p.IP, dbname, sq, err))
		}
	}
	db.Close()

	p.DisableDatabase(dbname) // Call the non-BDR disabling function.
	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:29,代码来源:pg.go


示例12: GrantUserPrivileges

// Create a given user on a single target host.
func (p *PG) GrantUserPrivileges(dbuser string, priviliges []string) (err error) {
	log.Trace(fmt.Sprintf(`pg.PG<%s>#GrantUserPrivileges(%s) Granting postgres user priviliges %+v...`, p.IP, dbuser, priviliges))
	p.Set(`database`, `postgres`)
	db, err := p.Connect()
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#UserGrantPrivileges(%s) %s ! %s", p.IP, dbuser, p.URI, err))
		return
	}
	defer db.Close()

	for _, priv := range priviliges {
		sq := fmt.Sprintf(`ALTER USER %s WITH %s;`, dbuser, priv)
		log.Trace(fmt.Sprintf(`pg.PG<%s>#UserGrantPrivileges(%s) > %s`, p.IP, dbuser, sq))
		result, err := db.Exec(sq)
		rows, _ := result.RowsAffected()
		if rows > 0 {
			log.Trace(fmt.Sprintf(`pg.PG<%s>#CreateUser(%s) Successfully Created.`, p.IP, dbuser))
		}
		if err != nil {
			log.Error(fmt.Sprintf(`pg.PG<%s>#CreateUser(%s) ! %s`, p.IP, dbuser, err))
			return err
		}
	}
	return nil
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:26,代码来源:pg.go


示例13: Find

func (b *Binding) Find() (err error) {
	log.Trace(fmt.Sprintf(`cfsb.Binding#Find(%s) ... `, b.BindingID))

	if b.BindingID == "" {
		return errors.New("Binding ID is empty, can not Binding#Find()")
	}
	p := pg.NewPG(`127.0.0.1`, pbPort, `rdpg`, `rdpg`, pgPass)
	db, err := p.Connect()
	if err != nil {
		log.Error(fmt.Sprintf("cfsb.Binding#Find(%s) ! %s", b.BindingID, err))
		return
	}
	defer db.Close()

	sq := fmt.Sprintf(`SELECT id,instance_id FROM cfsb.bindings WHERE binding_id=lower('%s') LIMIT 1`, b.BindingID)
	log.Trace(fmt.Sprintf(`cfsb.Binding#Find(%s) > %s`, b.BindingID, sq))
	err = db.Get(b, sq)
	if err != nil {
		if err == sql.ErrNoRows {
			log.Error(fmt.Sprintf("cfsb.Binding#Find(%s) ! Could not find binding with given Binding ID", b.BindingID))
		} else {
			log.Error(fmt.Sprintf("cfsb.Binding#Find(%s) ! %s", b.BindingID, err))
		}
	} else {
		// TODO: Load creds: b.Creds := Credentials{} ... b.Creds.Find()
	}
	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:28,代码来源:bindings.go


示例14: Remove

func (b *Binding) Remove() (err error) {
	log.Trace(fmt.Sprintf(`cfsb.Binding#Remove(%s) ... `, b.BindingID))
	err = b.Find()
	if err != nil {
		log.Error(fmt.Sprintf(`cfsb.Binding#Remove(%s) ! %s`, b.BindingID, err))
		return
	}
	p := pg.NewPG(`127.0.0.1`, pbPort, `rdpg`, `rdpg`, pgPass)
	db, err := p.Connect()
	if err != nil {
		log.Error(fmt.Sprintf("cfsb.Binding#Remove(%s) ! %s", b.BindingID, err))
		return
	}
	defer db.Close()

	// TODO: Scheduled background task that does any cleanup necessary for an
	// unbinding (remove credentials?)
	sq := fmt.Sprintf(`UPDATE cfsb.bindings SET ineffective_at=CURRENT_TIMESTAMP WHERE binding_id=lower('%s')`, b.BindingID)
	log.Trace(fmt.Sprintf(`cfsb.Binding#Remove(%s) SQL > %s`, b.BindingID, sq))
	_, err = db.Exec(sq)
	if err != nil {
		log.Error(fmt.Sprintf(`cfsb.Binding#Remove(%s) ! %s`, b.BindingID, err))
	}

	b.Creds = &Credentials{
		InstanceID: b.InstanceID,
		BindingID:  b.BindingID,
	}

	err = b.Creds.Remove()
	if err != nil {
		log.Error(fmt.Sprintf(`cfsb.Binding#Remove(%s) b.Creds.Remove() ! %s`, b.BindingID, err))
	}
	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:35,代码来源:bindings.go


示例15: serviceClusterCapacityStore

func (r *RDPG) serviceClusterCapacityStore() (err error) {
	if ClusterID == "rdpgmc" {
		return nil
	}
	instanceAllowed := os.Getenv(`RDPGD_INSTANCE_ALLOWED`)
	if instanceAllowed == "" {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#serviceClusterCapacityStore(): instanceAllowed is not configured or failed to export as environment variable! %s`, ClusterID))
	}
	instanceLimit := os.Getenv(`RDPGD_INSTANCE_LIMIT`)
	if instanceLimit == "" {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#serviceClusterCapacityStore(): instanceLimit is not configured or failed to export as environment variable! %s`, ClusterID))
	}
	kv := r.ConsulClient.KV()

	key := fmt.Sprintf(`rdpg/%s/capacity/instances/limit`, ClusterID)
	kvp := &consulapi.KVPair{Key: key, Value: []byte(instanceLimit)}
	_, err = kv.Put(kvp, &consulapi.WriteOptions{})
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#serviceClusterCapacityStore(): instanceLimit ! %s`, ClusterID, err))
	}

	key = fmt.Sprintf(`rdpg/%s/capacity/instances/allowed`, ClusterID)
	kvp.Key = key
	kvp.Value = []byte(instanceAllowed)
	_, err = kv.Put(kvp, &consulapi.WriteOptions{})
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#serviceClusterCapacityStore(): instanceAloowed ! %s`, ClusterID, err))
	}

	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:31,代码来源:bootstrap.go


示例16: DatabaseExists

// Check if the given PostgreSQL Database Exists on the host.
func (p *PG) DatabaseExists(dbname string) (exists bool, err error) {
	log.Trace(fmt.Sprintf(`pg.PG<%s>#DatabaseExists(%s) Checking if postgres database exists...`, p.IP, dbname))
	p.Set(`database`, `postgres`)
	db, err := p.Connect()
	if err != nil {
		log.Error(fmt.Sprintf("pg.PG<%s>#DatabaseExists(%s) %s ! %s", p.IP, dbname, p.URI, err))
		return
	}
	defer db.Close()

	type name struct {
		Name string `db:"name"`
	}
	var n name
	sq := fmt.Sprintf(`SELECT datname AS name FROM pg_database WHERE datname='%s' LIMIT 1;`, dbname)
	err = db.Get(&n, sq)
	if err != nil {
		if err == sql.ErrNoRows {
			exists = false
			err = nil
		} else {
			log.Error(fmt.Sprintf(`pg.PG<%s>#DatabaseExists(%s) ! %s`, p.IP, dbname, err))
			return
		}
	}
	if n.Name != "" {
		exists = true
	} else {
		exists = false
	}
	return
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:33,代码来源:pg.go


示例17: waitForClusterNodes

func (r *RDPG) waitForClusterNodes() (err error) {
	log.Trace(fmt.Sprintf(`rdpg.RDPG<%s>#waitForClusterNodes() waiting for all nodes to be registered as Consul services...`, ClusterID))
	cluster, err := NewCluster(ClusterID, r.ConsulClient)
	if err != nil {
		log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#waitForClusterNodes() NewCluster() ! %s`, ClusterID, err))
		return err
	}
	for {
		ips, err := cluster.ClusterIPs()
		if err != nil {
			log.Error(fmt.Sprintf(`rdpg.RDPG<%s>#waitForClusterNodes() cluster.ClusterIPs() ! %s`, ClusterID, err))
			return err
		}
		switch ClusterID {
		case `rdpgmc`:
			if len(ips) > 2 {
				return nil
			}
		default: // rdpgsc*
			if len(ips) > 1 {
				return nil
			}
		}
		time.Sleep(2 * time.Second)
	}
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:26,代码来源:bootstrap.go


示例18: createGlobalsFile

// createGlobalsFile - Create a pg backup file which contains only globals (roles/logins)
func createGlobalsFile(b backupParams) (f backupFileHistory, err error) {

	start := time.Now()
	f.duration = 0
	f.status = `ok`
	f.backupFile = b.baseFileName + ".globals"
	f.backupPathAndFile = b.basePath + "/" + b.databaseName + "/" + f.backupFile
	f.dbname = b.databaseName
	f.node = b.node

	pgDumpallPath := b.pgDumpPath + `all`

	out, err := exec.Command(pgDumpallPath, "-p", b.pgPort, "-U", "vcap", "--globals-only").CombinedOutput()
	if err != nil {
		log.Error(fmt.Sprintf(`tasks.createGlobalsFile() Error running pg_dumpall command for: %s out: %s ! %s`, b.databaseName, out, err))
		return
	}

	err = ioutil.WriteFile(f.backupPathAndFile, out, 0644)
	if err != nil {
		log.Error(fmt.Sprintf(`tasks.createGlobalsFile() Error running output to file: %s ! %s`, f.backupPathAndFile, err))
		return
	}

	f.duration = int(time.Since(start).Seconds())
	return

}
开发者ID:givett,项目名称:Databases-Unused-Cleanup,代码行数:29,代码来源:backups.go


示例19: EnvHandler

func EnvHandler(w http.ResponseWriter, request *http.Request) {
	vars := mux.Vars(request)
	envKey := vars["key"]
	envValue := os.Getenv(envKey)
	log.Trace(fmt.Sprintf(`%s /env/%s => %s`, request.Method, envKey, envValue))
	switch request.Method {
	case `GET`:
		w.Header().Set("Content-Type", "application/json; charset=UTF-8")
		w.WriteHeader(http.StatusOK)
		ev := EnvVar{Key: envKey, Value: envValue}
		msg, err := json.Marshal(ev)
		if err != nil {
			log.Error(fmt.Sprintf(`admin.EnvHandler() %s`, err))
		}
		w.Write(msg)
	default:
		resp := ResponseObject{Status: http.StatusMethodNotAllowed, Description: request.Method}
		msg, err := json.Marshal(resp)
		if err != nil {
			log.Error(fmt.Sprintf(`admin.EnvHandler() %s`, err))
		}
		log.Error(fmt.Sprintf(`admin.EnvHandler() %+v %s`, vars, string(msg)))
		http.Error(w, string(msg), http.StatusMethodNotAllowed)
	}
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:25,代码来源:env.go


示例20: CreateReplicationGroup

func (b *BDR) CreateReplicationGroup(dbname string) (err error) {
	nodes, err := b.PGNodes()
	if err != nil {
		log.Error(fmt.Sprintf(`bdr.BDR#CreateReplicationGroup(%s) b.PGNodes() ! %s`, dbname, err))
	}

	// TODO: Drop Database on all nodes if err != nil for any operation below
	for index, pg := range nodes {
		localNodeName := fmt.Sprintf(`%s_%d`, dbname, index)
		if index == 0 {
			err = pg.BDRGroupCreate(localNodeName, dbname)
			if err != nil {
				log.Error(fmt.Sprintf(`bdr.BDR<%s>#CreateReplicationGroup(%s) pg.BDRGroupCreate() ! %s`, pg.IP, dbname, err))
				break
			}
		} else {
			err = pg.BDRGroupJoin(localNodeName, dbname, nodes[0])
			if err != nil {
				log.Error(fmt.Sprintf(`bdr.BDR<%s>#CreateReplicationGroup(%s) pg.BDRGroupJoin() ! %s`, pg.IP, dbname, err))
				break
			}
		}
	}
	if err != nil {
		// Cleanup in BDR currently requires droping the database and trying again...
		err = b.DropDatabase(dbname)
		if err != nil {
			log.Error(fmt.Sprintf(`bdr.BDR#CreateReplicationGroup(%s) Dropping Database due to Create Error ! %s`, dbname, err))
		}
	}
	return err
}
开发者ID:predix,项目名称:rdpg-boshrelease,代码行数:32,代码来源:bdr.go



注:本文中的github.com/starkandwayne/rdpgd/log.Error函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang log.Trace函数代码示例发布时间:2022-05-28
下一篇:
Golang dropbox.Dropbox类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap