18
18
19
19
package org .apache .whirr .command ;
20
20
21
- import static org .apache .whirr .ClusterSpec .Property .CLUSTER_NAME ;
22
- import static org .apache .whirr .ClusterSpec .Property .IDENTITY ;
23
- import static org .apache .whirr .ClusterSpec .Property .INSTANCE_TEMPLATES ;
24
-
25
21
import com .google .common .collect .Maps ;
26
-
27
22
import java .io .IOException ;
28
23
import java .io .PrintStream ;
29
24
import java .util .EnumSet ;
30
25
import java .util .Map ;
31
-
32
26
import joptsimple .ArgumentAcceptingOptionSpec ;
33
27
import joptsimple .OptionParser ;
34
28
import joptsimple .OptionSet ;
35
29
import joptsimple .OptionSpec ;
36
-
37
30
import org .apache .commons .configuration .CompositeConfiguration ;
38
31
import org .apache .commons .configuration .Configuration ;
39
32
import org .apache .commons .configuration .ConfigurationException ;
43
36
import org .apache .whirr .ClusterControllerFactory ;
44
37
import org .apache .whirr .ClusterSpec ;
45
38
import org .apache .whirr .ClusterSpec .Property ;
39
+ import static org .apache .whirr .ClusterSpec .Property .CLUSTER_NAME ;
40
+ import static org .apache .whirr .ClusterSpec .Property .CREDENTIAL ;
41
+ import static org .apache .whirr .ClusterSpec .Property .IDENTITY ;
42
+ import static org .apache .whirr .ClusterSpec .Property .INSTANCE_TEMPLATES ;
43
+ import static org .apache .whirr .ClusterSpec .Property .PRIVATE_KEY_FILE ;
44
+ import static org .apache .whirr .ClusterSpec .Property .PROVIDER ;
46
45
import org .apache .whirr .state .ClusterStateStore ;
47
46
import org .apache .whirr .state .ClusterStateStoreFactory ;
48
47
import org .slf4j .Logger ;
@@ -100,12 +99,14 @@ protected ClusterSpec getClusterSpec(OptionSet optionSet) throws ConfigurationEx
100
99
for (Map .Entry <Property , OptionSpec <?>> entry : optionSpecs .entrySet ()) {
101
100
Property property = entry .getKey ();
102
101
OptionSpec <?> option = entry .getValue ();
102
+ Object value ;
103
103
if (property .hasMultipleArguments ()) {
104
- optionsConfig .setProperty (property .getConfigName (),
105
- optionSet .valuesOf (option ));
104
+ value = optionSet .valuesOf (option );
106
105
} else {
107
- optionsConfig .setProperty (property .getConfigName (),
108
- optionSet .valueOf (option ));
106
+ value = optionSet .valueOf (option );
107
+ }
108
+ if (value != null ) {
109
+ optionsConfig .setProperty (property .getConfigName (), value );
109
110
}
110
111
}
111
112
CompositeConfiguration config = new CompositeConfiguration ();
@@ -114,14 +115,17 @@ protected ClusterSpec getClusterSpec(OptionSet optionSet) throws ConfigurationEx
114
115
Configuration defaults = new PropertiesConfiguration (optionSet .valueOf (configOption ));
115
116
config .addConfiguration (defaults );
116
117
}
118
+ ClusterSpec clusterSpec = new ClusterSpec (config );
117
119
118
- for (Property required : EnumSet .of (CLUSTER_NAME , IDENTITY , INSTANCE_TEMPLATES )) {
119
- if (config .getString (required .getConfigName ()) == null ) {
120
+ for (Property required : EnumSet .of (CLUSTER_NAME , PROVIDER , IDENTITY , CREDENTIAL ,
121
+ INSTANCE_TEMPLATES , PRIVATE_KEY_FILE )) {
122
+ if (clusterSpec .getConfiguration ().getString (required .getConfigName ()) == null ) {
120
123
throw new IllegalArgumentException (String .format ("Option '%s' not set." ,
121
124
required .getSimpleName ()));
122
125
}
123
126
}
124
- return new ClusterSpec (config );
127
+
128
+ return clusterSpec ;
125
129
}
126
130
127
131
/**
0 commit comments