20
20
21
21
import java .io .InputStream ;
22
22
import java .util .Arrays ;
23
- import java .util .Collection ;
24
23
import java .util .EnumSet ;
25
24
import java .util .LinkedList ;
26
25
import java .util .List ;
@@ -68,29 +67,29 @@ enum DB {
68
67
redis , dynomite , memory , redis_cluster , mysql
69
68
}
70
69
71
- private ServerModule sm ;
70
+ private ServerModule serverModule ;
72
71
73
72
private Server server ;
74
73
75
- private ConductorConfig cc ;
74
+ private ConductorConfig conductorConfig ;
76
75
77
- private DB db ;
76
+ private DB database ;
78
77
79
- public ConductorServer (ConductorConfig cc ) {
80
- this .cc = cc ;
81
- String dynoClusterName = cc .getProperty ("workflow.dynomite.cluster.name" , "" );
78
+ public ConductorServer (ConductorConfig conductorConfig ) {
79
+ this .conductorConfig = conductorConfig ;
80
+ String dynoClusterName = conductorConfig .getProperty ("workflow.dynomite.cluster.name" , "" );
82
81
83
82
List <Host > dynoHosts = new LinkedList <>();
84
- String dbstring = cc .getProperty ("db" , "memory" );
83
+ String dbstring = conductorConfig .getProperty ("db" , "memory" );
85
84
try {
86
- db = DB .valueOf (dbstring );
85
+ database = DB .valueOf (dbstring );
87
86
}catch (IllegalArgumentException ie ) {
88
87
logger .error ("Invalid db name: " + dbstring + ", supported values are: " + Arrays .toString (DB .values ()));
89
88
System .exit (1 );
90
89
}
91
90
92
- if (!(db .equals (DB .memory ) || db .equals (DB .mysql ))) {
93
- String hosts = cc .getProperty ("workflow.dynomite.cluster.hosts" , null );
91
+ if (!(database .equals (DB .memory ) || database .equals (DB .mysql ))) {
92
+ String hosts = conductorConfig .getProperty ("workflow.dynomite.cluster.hosts" , null );
94
93
if (hosts == null ) {
95
94
System .err .println ("Missing dynomite/redis hosts. Ensure 'workflow.dynomite.cluster.hosts' has been set in the supplied configuration." );
96
95
logger .error ("Missing dynomite/redis hosts. Ensure 'workflow.dynomite.cluster.hosts' has been set in the supplied configuration." );
@@ -109,59 +108,41 @@ public ConductorServer(ConductorConfig cc) {
109
108
110
109
}else {
111
110
//Create a single shard host supplier
112
- Host dynoHost = new Host ("localhost" , 0 , cc .getAvailabilityZone (), Status .Up );
111
+ Host dynoHost = new Host ("localhost" , 0 , conductorConfig .getAvailabilityZone (), Status .Up );
113
112
dynoHosts .add (dynoHost );
114
113
}
115
114
init (dynoClusterName , dynoHosts );
116
115
}
117
116
118
117
private void init (String dynoClusterName , List <Host > dynoHosts ) {
119
- HostSupplier hs = new HostSupplier () {
120
-
121
- @ Override
122
- public Collection <Host > getHosts () {
123
- return dynoHosts ;
124
- }
125
- };
118
+ HostSupplier hostSupplier = () -> dynoHosts ;
126
119
127
120
JedisCommands jedis = null ;
128
121
129
- switch (db ) {
122
+ switch (database ) {
130
123
case redis :
131
124
case dynomite :
132
- ConnectionPoolConfigurationImpl cp = new ConnectionPoolConfigurationImpl (dynoClusterName ).withTokenSupplier (new TokenMapSupplier () {
133
-
134
- HostToken token = new HostToken (1L , dynoHosts .get (0 ));
135
-
136
- @ Override
137
- public List <HostToken > getTokens (Set <Host > activeHosts ) {
138
- return Arrays .asList (token );
139
- }
140
-
141
- @ Override
142
- public HostToken getTokenForHost (Host host , Set <Host > activeHosts ) {
143
- return token ;
144
- }
145
-
146
-
147
- }).setLocalRack (cc .getAvailabilityZone ()).setLocalDataCenter (cc .getRegion ());
148
- cp .setSocketTimeout (0 );
149
- cp .setConnectTimeout (0 );
150
- cp .setMaxConnsPerHost (cc .getIntProperty ("workflow.dynomite.connection.maxConnsPerHost" , 10 ));
151
-
125
+ ConnectionPoolConfigurationImpl connectionPoolConfiguration = new ConnectionPoolConfigurationImpl (dynoClusterName )
126
+ .withTokenSupplier (getTokenMapSupplier (dynoHosts ))
127
+ .setLocalRack (conductorConfig .getAvailabilityZone ())
128
+ .setLocalDataCenter (conductorConfig .getRegion ())
129
+ .setSocketTimeout (0 )
130
+ .setConnectTimeout (0 )
131
+ .setMaxConnsPerHost (conductorConfig .getIntProperty ("workflow.dynomite.connection.maxConnsPerHost" , 10 ));
132
+
152
133
jedis = new DynoJedisClient .Builder ()
153
- .withHostSupplier (hs )
154
- .withApplicationName (cc .getAppId ())
155
- .withDynomiteClusterName (dynoClusterName )
156
- .withCPConfig (cp )
157
- .build ();
134
+ .withHostSupplier (hostSupplier )
135
+ .withApplicationName (conductorConfig .getAppId ())
136
+ .withDynomiteClusterName (dynoClusterName )
137
+ .withCPConfig (connectionPoolConfiguration )
138
+ .build ();
158
139
159
140
logger .info ("Starting conductor server using dynomite/redis cluster " + dynoClusterName );
160
141
161
142
break ;
162
143
163
144
case mysql :
164
- logger .info ("Starting conductor server using MySQL data store" , db );
145
+ logger .info ("Starting conductor server using MySQL data store" , database );
165
146
break ;
166
147
case memory :
167
148
jedis = new JedisMock ();
@@ -189,11 +170,28 @@ public HostToken getTokenForHost(Host host, Set<Host> activeHosts) {
189
170
break ;
190
171
}
191
172
192
- this .sm = new ServerModule (jedis , hs , cc , db );
173
+ this .serverModule = new ServerModule (jedis , hostSupplier , conductorConfig , database );
193
174
}
194
-
175
+
176
+ private TokenMapSupplier getTokenMapSupplier (List <Host > dynoHosts ) {
177
+ return new TokenMapSupplier () {
178
+
179
+ HostToken token = new HostToken (1L , dynoHosts .get (0 ));
180
+
181
+ @ Override
182
+ public List <HostToken > getTokens (Set <Host > activeHosts ) {
183
+ return Arrays .asList (token );
184
+ }
185
+
186
+ @ Override
187
+ public HostToken getTokenForHost (Host host , Set <Host > activeHosts ) {
188
+ return token ;
189
+ }
190
+ };
191
+ }
192
+
195
193
public ServerModule getGuiceModule () {
196
- return sm ;
194
+ return serverModule ;
197
195
}
198
196
199
197
public synchronized void start (int port , boolean join ) throws Exception {
@@ -202,7 +200,7 @@ public synchronized void start(int port, boolean join) throws Exception {
202
200
throw new IllegalStateException ("Server is already running" );
203
201
}
204
202
205
- Guice .createInjector (sm );
203
+ Guice .createInjector (serverModule );
206
204
207
205
//Swagger
208
206
String resourceBasePath = Main .class .getResource ("/swagger-ui" ).toExternalForm ();
0 commit comments