Workaround for aws:runDocument bookkeeping bug
cr:
@@ -22,7 +22,6 @@ import (
"github.com/aws/amazon-ssm-agent/agent/appconfig"
"github.com/aws/amazon-ssm-agent/agent/context"
"github.com/aws/amazon-ssm-agent/agent/contracts"
- "github.com/aws/amazon-ssm-agent/agent/framework/docmanager"
"github.com/aws/amazon-ssm-agent/agent/framework/docparser"
"github.com/aws/amazon-ssm-agent/agent/framework/processor/executer"
"github.com/aws/amazon-ssm-agent/agent/task"
@@ -92,10 +91,53 @@ func (exec ExecDocumentImpl) ExecuteDocument(config contracts.Configuration, con
InstancePluginsInformation: pluginInput,
}
- docStore := executer.NewDocumentFileStore(documentID, appconfig.DefaultLocationOfCurrent,
- &docState, docmanager.NewDocumentFileMgr(context, appconfig.DefaultDataStorePath, appconfig.DefaultDocumentRootDirName, appconfig.DefaultLocationOfState))
+ docStore := executer.NewDocumentFileStore(documentID, appconfig.DefaultLocationOfCurrent, &docState,
+ NewNoOpDocumentMgr(context))
cancelFlag := task.NewChanneledCancelFlag()
resultChannels = exec.DocExecutor.Run(cancelFlag, &docStore)
return resultChannels, nil
}
+
+// Workaround to keep this plugin from overwriting the DocumentState of the top-level document.
+//
+// Up until version 3.0.732.0, this plugin always failed to write the DocumentState to file due to a
+// path calculation bug. In 3.0.732.0, the path calculation bug was fixed, and the plugin
+// started overwriting the top-level document's DocumentState, which sometimes interfered with
+// plugins in the top-level document that executed after this one. NoOpDocumentMgr is meant
+// to keep this plugin from overwriting the state of the top-level document. However, it does
+// not persist the DocumentState over a reboot, and it does not track the status (e.g. "pending",
+// "current", "corrupt") of the document. Longer-term, we may want to implement proper DocumentState
+// bookkeeping for the documents executed by this plugin.
+type NoOpDocumentMgr struct {
+ context context.T
+ state contracts.DocumentState
+}
+
+func NewNoOpDocumentMgr(ctx context.T) *NoOpDocumentMgr {
+ return &NoOpDocumentMgr{
+ ctx,
+ contracts.DocumentState{},
+ }
+}
+
+func (m *NoOpDocumentMgr) MoveDocumentState(fileName, srcLocationFolder, dstLocationFolder string) {
+ // No-op
+ m.context.Log().Debugf("NoOpDocumentMgr.MoveDocumentState(%s, %s, %s)", fileName, srcLocationFolder, dstLocationFolder)
+}
+
+func (m *NoOpDocumentMgr) PersistDocumentState(fileName, locationFolder string, state contracts.DocumentState) {
+ m.context.Log().Debugf("NoOpDocumentMgr.PersistDocumentState(%s, %s, %+v)", fileName, locationFolder, state)
+ m.state = state
+}
+
+func (m *NoOpDocumentMgr) GetDocumentState(fileName, locationFolder string) contracts.DocumentState {
+ m.context.Log().Debugf("NoOpDocumentMgr.GetDocumentState(%s, %s)", fileName, locationFolder)
+ m.context.Log().Warn("NoOpDocumentMgr.GetDocumentState() called, consider using a persistent DocumentMgr")
+ return m.state
+}
+
+func (m *NoOpDocumentMgr) RemoveDocumentState(fileName, locationFolder string) {
+ // No-op
+ m.context.Log().Debugf("NoOpDocumentMgr.RemoveDocumentState(%s, %s)", fileName, locationFolder)
+}
