func formatAgentTaskCompletePayload(log log.T,
	pluginId string,
	pluginResults map[string]*contracts.PluginResult,
	sessionId string,
	instanceId string,
	topic string) mgsContracts.AgentTaskCompletePayload {

	if len(pluginResults) < 1 {
		log.Error("Error in FormatAgentTaskCompletePayload, the outputs map is empty!")
		return mgsContracts.AgentTaskCompletePayload{}
	}

	// get plugin result
	if pluginId == "" {
		// for instance reboot scenarios, it only contains document level result which does not contain pluginId.
		for key := range pluginResults {
			pluginId = key
			break
		}
	}
	pluginResult := pluginResults[pluginId]

	if pluginResult == nil {
		log.Error("Error in FormatAgentTaskCompletePayload, the pluginOutput is nil!")
		return mgsContracts.AgentTaskCompletePayload{}
	}

	sessionPluginResultOutput := mgsContracts.SessionPluginResultOutput{}
	if pluginResult.Error != "" {
		sessionPluginResultOutput.Output = pluginResult.Error
	} else if pluginResult.Output != nil {
		if err := jsonutil.Remarshal(pluginResult.Output, &sessionPluginResultOutput); err != nil {
			sessionPluginResultOutput.Output = fmt.Sprintf("%v", pluginResult.Output)
		}
	}

	payload := mgsContracts.AgentTaskCompletePayload{
		SchemaVersion:    1,
		TaskId:           sessionId,
		Topic:            topic,
		FinalTaskStatus:  string(pluginResult.Status),
		IsRoutingFailure: false,
		AwsAccountId:     "",
		InstanceId:       instanceId,
		Output:           sessionPluginResultOutput.Output,
		S3Bucket:         sessionPluginResultOutput.S3Bucket,
		S3UrlSuffix:      sessionPluginResultOutput.S3UrlSuffix,
		CwlGroup:         sessionPluginResultOutput.CwlGroup,
		CwlStream:        sessionPluginResultOutput.CwlStream,
	}
	return payload
}
// formatAgentTaskCompletePayload builds AgentTaskComplete message Payload from the total task result.
formatAgentTaskCompletePayload builds AgentTaskComplete message Payload from the total task result.
// formatAgentTaskCompletePayload builds AgentTaskComplete message Payload from the total task result .
func formatAgentTaskCompletePayload(log log.T,
	pluginId string,
	pluginResults map[string]*contracts.PluginResult,
	sessionId string,
	instanceId string,
	topic string) mgsContracts.AgentTaskCompletePayload {
	if len(pluginResults) < 1 {
		log.Error("Error in FormatAgentTaskCompletePayload, the outputs map is empty!")
		return mgsContracts.AgentTaskCompletePayload{}
	}
	if pluginId == "" {
		for key := range pluginResults {
			pluginId = key
			break
		}
	}
	pluginResult := pluginResults[pluginId]
	if pluginResult == nil {
		log.Error("Error in FormatAgentTaskCompletePayload, the pluginOutput is nil!")
		return mgsContracts.AgentTaskCompletePayload{}
	}
	sessionPluginResultOutput := mgsContracts.SessionPluginResultOutput{}
	if pluginResult.Error != "" {
		sessionPluginResultOutput.Output = pluginResult.Error
	} else if pluginResult.Output != nil {
		if err := jsonutil.Remarshal(pluginResult.Output, &sessionPluginResultOutput); err != nil {
			sessionPluginResultOutput.Output = fmt.Sprintf("%v", pluginResult.Output)
		}
	}
	payload := mgsContracts.AgentTaskCompletePayload{
		SchemaVersion:    1,
		TaskId:           sessionId,
		Topic:            topic,
		FinalTaskStatus:  string(pluginResult.Status),
		IsRoutingFailure: false,
		AwsAccountId:     "",
		InstanceId:       instanceId,
		Output:           sessionPluginResultOutput.Output,
		S3Bucket:         sessionPluginResultOutput.S3Bucket,
		S3UrlSuffix:      sessionPluginResultOutput.S3UrlSuffix,
		CwlGroup:         sessionPluginResultOutput.CwlGroup,
		CwlStream:        sessionPluginResultOutput.CwlStream,
	}
	return payload
}
func formatAgentTaskCompletePayload ( log log . T , pluginId string , pluginResults map [ string ] * contracts . PluginResult , sessionId string , instanceId string , topic string ) mgsContracts . AgentTaskCompletePayload { if len ( pluginResults ) < 1 { log . Error ( " " ) return mgsContracts . AgentTaskCompletePayload { } } if pluginId == " " { for key := range pluginResults { pluginId = key break } } pluginResult := pluginResults [ pluginId ] if pluginResult == nil { log . Error ( " " ) return mgsContracts . AgentTaskCompletePayload { } } sessionPluginResultOutput := mgsContracts . SessionPluginResultOutput { } if pluginResult . Error != " " { sessionPluginResultOutput . Output = pluginResult . Error } else if pluginResult . Output != nil { if err := jsonutil . Remarshal ( pluginResult . Output , & sessionPluginResultOutput ) ; err != nil { sessionPluginResultOutput . Output = fmt . Sprintf ( " " , pluginResult . Output ) } } payload := mgsContracts . AgentTaskCompletePayload { SchemaVersion : 1 , TaskId : sessionId , Topic : topic , FinalTaskStatus : string ( pluginResult . Status ) , IsRoutingFailure : false , AwsAccountId : " " , InstanceId : instanceId , Output : sessionPluginResultOutput . Output , S3Bucket : sessionPluginResultOutput . S3Bucket , S3UrlSuffix : sessionPluginResultOutput . S3UrlSuffix , CwlGroup : sessionPluginResultOutput . CwlGroup , CwlStream : sessionPluginResultOutput . CwlStream , } return payload }
formatAgentTaskCompletePayload builds AgentTaskComplete message Payload from the total task result.
formatAgentTaskCompletePayload builds AgentTaskComplete message Payload from the total task result .
// get plugin result // for instance reboot scenarios, it only contains document level result which does not contain pluginId.