-
Notifications
You must be signed in to change notification settings - Fork 180
/
wizard.go
142 lines (122 loc) · 5.01 KB
/
wizard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT
package main
import (
"bufio"
"flag"
"fmt"
"os"
"github.com/aws/amazon-cloudwatch-agent/tool/data"
"github.com/aws/amazon-cloudwatch-agent/tool/processors"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/basicInfo"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/migration/linux"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/migration/windows"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/serialization"
"github.com/aws/amazon-cloudwatch-agent/tool/processors/tracesconfig"
"github.com/aws/amazon-cloudwatch-agent/tool/runtime"
"github.com/aws/amazon-cloudwatch-agent/tool/stdin"
"github.com/aws/amazon-cloudwatch-agent/tool/testutil"
"github.com/aws/amazon-cloudwatch-agent/tool/util"
)
type IMainProcessor interface {
VerifyProcessor(processor interface{})
}
type MainProcessorStruct struct{}
var MainProcessorGlobal IMainProcessor = &MainProcessorStruct{}
var isNonInteractiveWindowsMigration *bool
var configOutputPath *string
var isNonInteractiveXrayMigration *bool
func main() {
// Parse command line args for non-interactive Windows migration
isNonInteractiveWindowsMigration = flag.Bool("isNonInteractiveWindowsMigration", false,
"If true, it will use command line args to bypass the wizard. Default value is false.")
isNonInteractiveLinuxMigration := flag.Bool("isNonInteractiveLinuxMigration", false,
"If true, it will do the linux config migration. Default value is false.")
tracesOnly := flag.Bool("tracesOnly", false, "If true, only trace configuration will be generated")
useParameterStore := flag.Bool("useParameterStore", false,
"If true, it will use the parameter store for the migrated config storage.")
isNonInteractiveXrayMigration = flag.Bool("nonInteractiveXrayMigration", false, "If true, then this is part of non Interactive xray migration tool.")
configFilePath := flag.String("configFilePath", "",
fmt.Sprintf("The path of the old config file. Default is %s on Windows or %s on Linux", windows.DefaultFilePathWindowsConfiguration, linux.DefaultFilePathLinuxConfiguration))
configOutputPath = flag.String("configOutputPath", "", "Specifies where to write the configuration file generated by the wizard")
parameterStoreName := flag.String("parameterStoreName", "", "The parameter store name. Default is AmazonCloudWatch-windows")
parameterStoreRegion := flag.String("parameterStoreRegion", "", "The parameter store region. Default is us-east-1")
flag.Parse()
if *isNonInteractiveWindowsMigration {
addWindowsMigrationInputs(*configFilePath, *parameterStoreName, *parameterStoreRegion, *useParameterStore)
} else if *isNonInteractiveLinuxMigration {
ctx := new(runtime.Context)
config := new(data.Config)
ctx.HasExistingLinuxConfig = true
ctx.ConfigFilePath = *configFilePath
if ctx.ConfigFilePath == "" {
ctx.ConfigFilePath = linux.DefaultFilePathLinuxConfiguration
}
process(ctx, config, linux.Processor, serialization.Processor)
return
} else if *tracesOnly {
ctx := new(runtime.Context)
config := new(data.Config)
ctx.TracesOnly = true
ctx.ConfigOutputPath = *configOutputPath
if *isNonInteractiveXrayMigration {
ctx.NonInteractiveXrayMigration = true
}
process(ctx, config, tracesconfig.Processor, serialization.Processor)
return
}
startProcessing()
}
func init() {
stdin.Scanln = func(a ...interface{}) (n int, err error) {
scanner := bufio.NewScanner(os.Stdin)
scanner.Scan()
if len(a) > 0 {
*a[0].(*string) = scanner.Text()
n = len(*a[0].(*string))
}
err = scanner.Err()
return
}
processors.StartProcessor = basicInfo.Processor
}
func addWindowsMigrationInputs(configFilePath string, parameterStoreName string, parameterStoreRegion string, useParameterStore bool) {
inputChan := testutil.SetUpTestInputStream()
if useParameterStore {
testutil.Type(inputChan, "2", "1", "2", "1", configFilePath, "1", parameterStoreName, parameterStoreRegion, "1")
} else {
testutil.Type(inputChan, "2", "1", "2", "1", configFilePath, "2")
}
}
func process(ctx *runtime.Context, config *data.Config, processors ...processors.Processor) {
for _, processor := range processors {
processor.Process(ctx, config)
}
}
func startProcessing() {
ctx := new(runtime.Context)
config := new(data.Config)
ctx.ConfigOutputPath = *configOutputPath
var processor interface{}
processor = processors.StartProcessor
if *isNonInteractiveWindowsMigration {
ctx.WindowsNonInteractiveMigration = true
}
if *isNonInteractiveXrayMigration {
ctx.NonInteractiveXrayMigration = true
}
for {
if processor == nil {
if util.CurOS() == util.OsTypeWindows && !*isNonInteractiveWindowsMigration {
util.EnterToExit()
}
fmt.Println("Program exits now.")
break
}
MainProcessorGlobal.VerifyProcessor(processor) // For testing purposes
processor.(processors.Processor).Process(ctx, config)
processor = processor.(processors.Processor).NextProcessor(ctx, config)
}
}
func (p *MainProcessorStruct) VerifyProcessor(processor interface{}) {
}