本文整理汇总了Golang中github.com/aws/amazon-ssm-agent/agent/context.T.With方法的典型用法代码示例。如果您正苦于以下问题:Golang T.With方法的具体用法?Golang T.With怎么用?Golang T.With使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/aws/amazon-ssm-agent/agent/context.T
的用法示例。
在下文中一共展示了T.With方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewHealthCheck
// NewHealthCheck creates a new health check core plugin.
func NewHealthCheck(context context.T) *HealthCheck {
healthContext := context.With("[" + name + "]")
healthCheckStopPolicy := sdkutil.NewStopPolicy(name, 10)
svc := ssm.NewService()
return &HealthCheck{
context: healthContext,
healthCheckStopPolicy: healthCheckStopPolicy,
service: svc,
}
}
示例2: runPlugin
func runPlugin(
context context.T,
p plugin.T,
pluginID string,
config contracts.Configuration,
cancelFlag task.CancelFlag,
) (res contracts.PluginResult) {
// create a new context that includes plugin ID
context = context.With("[pluginID=" + pluginID + "]")
log := context.Log()
defer func() {
// recover in case the plugin panics
// this should handle some kind of seg fault errors.
if err := recover(); err != nil {
res.Status = contracts.ResultStatusFailed
res.Code = 1
res.Error = fmt.Errorf("Plugin crashed with message %v!", err)
log.Error(res.Error)
}
}()
log.Debug("Running plugin")
return p.Execute(context, config, cancelFlag)
}
示例3: NewProcessor
// NewProcessor initializes a new mds processor with the given parameters.
func NewProcessor(context context.T) *Processor {
messageContext := context.With("[" + name + "]")
log := messageContext.Log()
config := messageContext.AppConfig()
instanceID, err := platform.InstanceID()
if instanceID == "" {
log.Errorf("no instanceID provided, %v", err)
return nil
}
mdsService := newMdsService(config)
agentInfo := contracts.AgentInfo{
Lang: config.Os.Lang,
Name: config.Agent.Name,
Version: config.Agent.Version,
Os: config.Os.Name,
OsVersion: config.Os.Version,
}
agentConfig := contracts.AgentConfiguration{
AgentInfo: agentInfo,
InstanceID: instanceID,
}
// sendCommand and cancelCommand will be processed by separate worker pools
// so we can define the number of workers per each
cancelWaitDuration := 10000 * time.Millisecond
clock := times.DefaultClock
sendCommandTaskPool := task.NewPool(log, config.Mds.CommandWorkersLimit, cancelWaitDuration, clock)
cancelCommandTaskPool := task.NewPool(log, CancelWorkersLimit, cancelWaitDuration, clock)
// create new message processor
orchestrationRootDir := path.Join(appconfig.DefaultDataStorePath, instanceID, appconfig.DefaultCommandRootDirName, config.Agent.OrchestrationRootDir)
replyBuilder := func(pluginID string, results map[string]*contracts.PluginResult) messageContracts.SendReplyPayload {
runtimeStatuses := parser.PrepareRuntimeStatuses(log, results)
return parser.PrepareReplyPayload(pluginID, runtimeStatuses, clock.Now(), agentConfig.AgentInfo)
}
statusReplyBuilder := func(agentInfo contracts.AgentInfo, resultStatus contracts.ResultStatus, documentTraceOutput string) messageContracts.SendReplyPayload {
return parser.PrepareReplyPayloadToUpdateDocumentStatus(agentInfo, resultStatus, documentTraceOutput)
}
// create a stop policy where we will stop after 10 consecutive errors and if time period expires.
processorStopPolicy := newStopPolicy()
// SendResponse is used to send response on plugin completion.
// If pluginID is empty it will send responses of all plugins.
// If pluginID is specified, response will be sent of that particular plugin.
sendResponse := func(messageID string, pluginID string, results map[string]*contracts.PluginResult) {
payloadDoc := replyBuilder(pluginID, results)
processSendReply(log, messageID, mdsService, payloadDoc, processorStopPolicy)
}
// SendDocLevelResponse is used to send document level update
// Specify a new status of the document
sendDocLevelResponse := func(messageID string, resultStatus contracts.ResultStatus, documentTraceOutput string) {
payloadDoc := statusReplyBuilder(agentInfo, resultStatus, documentTraceOutput)
processSendReply(log, messageID, mdsService, payloadDoc, processorStopPolicy)
}
// PersistData is used to persist the data into a bookkeeping folder
persistData := func(msg *ssmmds.Message, bookkeeping string) {
commandStateHelper.PersistData(log, getCommandID(*msg.MessageId), *msg.Destination, bookkeeping, *msg)
}
return &Processor{
context: messageContext,
stopSignal: make(chan bool),
config: agentConfig,
service: mdsService,
pluginRunner: pluginRunner,
sendCommandPool: sendCommandTaskPool,
cancelCommandPool: cancelCommandTaskPool,
buildReply: replyBuilder,
sendResponse: sendResponse,
sendDocLevelResponse: sendDocLevelResponse,
orchestrationRootDir: orchestrationRootDir,
persistData: persistData,
processorStopPolicy: processorStopPolicy,
}
}