本文整理汇总了Golang中github.com/outbrain/orchestrator/go/db.OpenOrchestrator函数的典型用法代码示例。如果您正苦于以下问题:Golang OpenOrchestrator函数的具体用法?Golang OpenOrchestrator怎么用?Golang OpenOrchestrator使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了OpenOrchestrator函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: readMissingKeysToResolve
// readMissingHostnamesToResolve gets those (unresolved, e.g. VIP) hostnames that *should* be present in
// the hostname_resolve table, but aren't.
func readMissingKeysToResolve() (result InstanceKeyMap, err error) {
query := `
select
hostname_unresolve.unresolved_hostname,
database_instance.port
from
database_instance
join hostname_unresolve on (database_instance.hostname = hostname_unresolve.hostname)
left join hostname_resolve on (database_instance.hostname = hostname_resolve.resolved_hostname)
where
hostname_resolve.hostname is null
`
db, err := db.OpenOrchestrator()
if err != nil {
goto Cleanup
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
instanceKey := InstanceKey{Hostname: m.GetString("unresolved_hostname"), Port: m.GetInt("port")}
result.AddKey(instanceKey)
return nil
})
Cleanup:
if err != nil {
log.Errore(err)
}
return result, err
}
示例2: ReadOutdatedAgentsHosts
// ReadOutdatedAgentsHosts returns agents that need to be updated
func ReadOutdatedAgentsHosts() ([]string, error) {
res := []string{}
query := fmt.Sprintf(`
select
hostname
from
host_agent
where
IFNULL(last_checked < now() - interval %d minute, true)
`,
config.Config.AgentPollMinutes)
db, err := db.OpenOrchestrator()
if err != nil {
goto Cleanup
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
hostname := m.GetString("hostname")
res = append(res, hostname)
return nil
})
Cleanup:
if err != nil {
log.Errore(err)
}
return res, err
}
示例3: readAgentBasicInfo
// readAgentBasicInfo returns the basic data for an agent directly from backend table (no agent access)
func readAgentBasicInfo(hostname string) (Agent, string, error) {
agent := Agent{}
token := ""
query := fmt.Sprintf(`
select
hostname,
port,
token,
last_submitted,
mysql_port
from
host_agent
where
hostname = '%s'
`, hostname)
db, err := db.OpenOrchestrator()
if err != nil {
return agent, "", err
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
agent.Hostname = m.GetString("hostname")
agent.Port = m.GetInt("port")
agent.LastSubmitted = m.GetString("last_submitted")
agent.MySQLPort = m.GetInt64("mysql_port")
token = m.GetString("token")
return nil
})
if token == "" {
return agent, "", log.Errorf("Cannot get agent/token: %s", hostname)
}
return agent, token, nil
}
示例4: ReadClusterByAlias
// ReadClusterAliases reads the entrie cluster name aliases mapping
func ReadClusterByAlias(alias string) (string, error) {
clusterName := ""
query := fmt.Sprintf(`
select
cluster_name
from
cluster_alias
where
alias = '%s'
`, alias)
db, err := db.OpenOrchestrator()
if err != nil {
goto Cleanup
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
clusterName = m.GetString("cluster_name")
return nil
})
Cleanup:
if err != nil {
return "", err
}
if clusterName == "" {
err = fmt.Errorf("No cluster found for alias %s", alias)
}
return clusterName, err
}
示例5: EndMaintenance
// EndMaintenance will terminate an active maintenance via maintenanceToken
func EndMaintenance(maintenanceToken int64) error {
db, err := db.OpenOrchestrator()
if err != nil {
return log.Errore(err)
}
res, err := sqlutils.Exec(db, `
update
database_instance_maintenance
set
maintenance_active = NULL,
end_timestamp = NOW()
where
database_instance_maintenance_id = ?
`,
maintenanceToken,
)
if err != nil {
return log.Errore(err)
}
if affected, _ := res.RowsAffected(); affected == 0 {
err = fmt.Errorf("Instance is not in maintenance mode; token = %+v", maintenanceToken)
} else {
// success
instanceKey, _ := ReadMaintenanceInstanceKey(maintenanceToken)
AuditOperation("end-maintenance", instanceKey, fmt.Sprintf("maintenanceToken: %d", maintenanceToken))
}
return err
}
示例6: ReadMaintenanceInstanceKey
// ReadMaintenanceInstanceKey will return the instanceKey for active maintenance by maintenanceToken
func ReadMaintenanceInstanceKey(maintenanceToken int64) (*InstanceKey, error) {
var res *InstanceKey
query := fmt.Sprintf(`
select
hostname, port
from
database_instance_maintenance
where
database_instance_maintenance_id = %d `,
maintenanceToken)
db, err := db.OpenOrchestrator()
if err != nil {
goto Cleanup
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
instanceKey, merr := NewInstanceKeyFromStrings(m.GetString("hostname"), m.GetString("port"))
if merr != nil {
return merr
}
res = instanceKey
return nil
})
Cleanup:
if err != nil {
log.Errore(err)
}
return res, err
}
示例7: writePoolInstances
// writePoolInstances will write (and override) a single cluster name mapping
func writePoolInstances(pool string, instanceKeys [](*InstanceKey)) error {
writeFunc := func() error {
db, err := db.OpenOrchestrator()
if err != nil {
return log.Errore(err)
}
tx, err := db.Begin()
stmt, err := tx.Prepare(`delete from database_instance_pool where pool = ?`)
_, err = stmt.Exec(pool)
if err != nil {
tx.Rollback()
return log.Errore(err)
}
stmt, err = tx.Prepare(`insert into database_instance_pool values (?, ?, ?)`)
for _, instanceKey := range instanceKeys {
_, err := stmt.Exec(instanceKey.Hostname, instanceKey.Port, pool)
if err != nil {
tx.Rollback()
return log.Errore(err)
}
}
if err != nil {
tx.Rollback()
return log.Errore(err)
}
tx.Commit()
return nil
}
return ExecDBWriteFunc(writeFunc)
}
示例8: IsElected
// IsElected checks whether this node is the elected active node
func IsElected() (bool, error) {
isElected := false
query := fmt.Sprintf(`
select
count(*) as is_elected
from
active_node
where
anchor = 1
and hostname = '%s'
and token = '%s'
`,
ThisHostname, ProcessToken.Hash)
db, err := db.OpenOrchestrator()
if err != nil {
goto Cleanup
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
isElected = m.GetBool("is_elected")
return nil
})
Cleanup:
if err != nil {
log.Errore(err)
}
return isElected, err
}
示例9: ElectedNode
// ElectedNode returns the hostname of the elected node
func ElectedNode() (string, string, bool, error) {
hostname := ""
token := ""
isElected := false
query := fmt.Sprintf(`
select
ifnull(max(hostname), '') as hostname,
ifnull(max(token), '') as token,
(ifnull(max(hostname), '') = '%s') and (ifnull(max(token), '') = '%s') as is_elected
from
active_node
where
anchor = 1
`,
ThisHostname, ProcessToken.Hash)
db, err := db.OpenOrchestrator()
if err != nil {
goto Cleanup
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
hostname = m.GetString("hostname")
token = m.GetString("token")
isElected = m.GetBool("is_elected")
return nil
})
Cleanup:
if err != nil {
log.Errore(err)
}
return hostname, token, isElected, err
}
示例10: GetEquivalentMasterCoordinates
func GetEquivalentMasterCoordinates(instanceCoordinates *InstanceBinlogCoordinates) (result [](*InstanceBinlogCoordinates), err error) {
query := fmt.Sprintf(`
select
master1_hostname as hostname,
master1_port as port,
master1_binary_log_file as binlog_file,
master1_binary_log_pos as binlog_pos
from
master_position_equivalence
where
master2_hostname = '%s'
and master2_port = '%d'
and master2_binary_log_file = '%s'
and master2_binary_log_pos = '%d'
union
select
master2_hostname as hostname,
master2_port as port,
master2_binary_log_file as binlog_file,
master2_binary_log_pos as binlog_pos
from
master_position_equivalence
where
master1_hostname = '%s'
and master1_port = '%d'
and master1_binary_log_file = '%s'
and master1_binary_log_pos = '%d'
`,
instanceCoordinates.Key.Hostname,
instanceCoordinates.Key.Port,
instanceCoordinates.Coordinates.LogFile,
instanceCoordinates.Coordinates.LogPos,
instanceCoordinates.Key.Hostname,
instanceCoordinates.Key.Port,
instanceCoordinates.Coordinates.LogFile,
instanceCoordinates.Coordinates.LogPos)
db, err := db.OpenOrchestrator()
if err != nil {
goto Cleanup
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
equivalentCoordinates := InstanceBinlogCoordinates{}
equivalentCoordinates.Key.Hostname = m.GetString("hostname")
equivalentCoordinates.Key.Port = m.GetInt("port")
equivalentCoordinates.Coordinates.LogFile = m.GetString("binlog_file")
equivalentCoordinates.Coordinates.LogPos = m.GetInt64("binlog_pos")
result = append(result, &equivalentCoordinates)
return nil
})
Cleanup:
if err != nil {
return nil, err
}
return result, nil
}
示例11: EndDowntime
// EndDowntime will remove downtime flag from an instance
func EndDowntime(instanceKey *InstanceKey) error {
db, err := db.OpenOrchestrator()
if err != nil {
return log.Errore(err)
}
res, err := sqlutils.Exec(db, `
update
database_instance_downtime
set
downtime_active = NULL,
end_timestamp = NOW()
where
hostname = ?
and port = ?
and downtime_active = 1
`,
instanceKey.Hostname,
instanceKey.Port,
)
if err != nil {
return log.Errore(err)
}
if affected, _ := res.RowsAffected(); affected == 0 {
err = fmt.Errorf("Instance is not in downtime mode: %+v", instanceKey)
} else {
// success
AuditOperation("end-downtime", instanceKey, "")
}
return err
}
示例12: WriteClusterDomainName
// WriteClusterDomainName will write (and override) the domain name of a cluster
func WriteClusterDomainName(clusterName string, domainName string) error {
writeFunc := func() error {
db, err := db.OpenOrchestrator()
if err != nil {
return log.Errore(err)
}
_, err = sqlutils.Exec(db, `
insert into
cluster_domain_name (cluster_name, domain_name, last_registered)
values
(?, ?, NOW())
on duplicate key update
domain_name=values(domain_name),
last_registered=values(last_registered)
`,
clusterName,
domainName)
if err != nil {
return log.Errore(err)
}
return nil
}
return ExecDBWriteFunc(writeFunc)
}
示例13: ReadClusterDomainName
// ReadClusterDomainName reads the domain name associated with a cluster, if any
func ReadClusterDomainName(clusterName string) (string, error) {
domainName := ""
query := fmt.Sprintf(`
select
domain_name
from
cluster_domain_name
where
cluster_name = '%s'
`, clusterName)
db, err := db.OpenOrchestrator()
if err != nil {
goto Cleanup
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
domainName = m.GetString("domain_name")
return nil
})
Cleanup:
if err != nil {
return "", err
}
if domainName == "" {
err = fmt.Errorf("No domain name found for cluster %s", clusterName)
}
return domainName, err
}
示例14: ElectedNode
// ElectedNode returns the details of the elected node, as well as answering the question "is this process the elected one"?
func ElectedNode() (hostname string, token string, isElected bool, err error) {
query := `
select
hostname,
token
from
active_node
where
anchor = 1
`
db, err := db.OpenOrchestrator()
if err != nil {
goto Cleanup
}
err = sqlutils.QueryRowsMap(db, query, func(m sqlutils.RowMap) error {
hostname = m.GetString("hostname")
token = m.GetString("token")
return nil
})
Cleanup:
if err != nil {
log.Errore(err)
}
isElected = (hostname == ThisHostname && token == ProcessToken.Hash)
return hostname, token, isElected, err
}
示例15: submitSeedStateEntry
// submitSeedStateEntry submits a seed state: a single step in the overall seed process
func submitSeedStateEntry(seedId int64, action string, errorMessage string) (int64, error) {
db, err := db.OpenOrchestrator()
if err != nil {
return 0, log.Errore(err)
}
res, err := sqlutils.Exec(db, `
insert
into agent_seed_state (
agent_seed_id, state_timestamp, state_action, error_message
) VALUES (
?, NOW(), ?, ?
)
`,
seedId,
action,
errorMessage,
)
if err != nil {
return 0, log.Errore(err)
}
id, err := res.LastInsertId()
return id, err
}