@@ -206,6 +206,8 @@ def startCluster():
206206 requestInfo = ec2client .request_spot_fleet (SpotFleetRequestConfig = spotfleetConfig )
207207 print 'Request in process. Wait until your machines are available in the cluster.'
208208 print 'SpotFleetRequestId' ,requestInfo ['SpotFleetRequestId' ]
209+
210+ # Step 3: Make the monitor
209211 starttime = str (int (time .time ()* 1000 ))
210212 createMonitor = open ('files/' + APP_NAME + 'SpotFleetRequestId.json' ,'w' )
211213 createMonitor .write ('{"MONITOR_FLEET_ID" : "' + requestInfo ['SpotFleetRequestId' ]+ '",\n ' )
@@ -217,10 +219,26 @@ def startCluster():
217219 createMonitor .write ('"MONITOR_START_TIME" : "' + starttime + '"}\n ' )
218220 createMonitor .close ()
219221
220-
221-
222+ # Step 4: Create a log group for this app and date if one does not already exist
223+ logclient = boto3 .client ('logs' )
224+ loggroupinfo = logclient .describe_log_groups (logGroupNamePrefix = LOG_GROUP_NAME )
225+ groupnames = [d ['logGroupName' ] for d in loggroupinfo ['logGroups' ]]
226+ if LOG_GROUP_NAME not in groupnames :
227+ logclient .create_log_group (logGroupName = LOG_GROUP_NAME )
228+ logclient .put_retention_policy (logGroupName = LOG_GROUP_NAME , retentionInDays = 60 )
229+ if LOG_GROUP_NAME + '_perInstance' not in groupnames :
230+ logclient .create_log_group (logGroupName = LOG_GROUP_NAME + '_perInstance' )
231+ logclient .put_retention_policy (logGroupName = LOG_GROUP_NAME + '_perInstance' , retentionInDays = 60 )
232+
233+ # Step 5: update the ECS service to be ready to inject docker containers in EC2 instances
234+ print 'Updating service'
235+ cmd = 'aws ecs update-service --cluster ' + ECS_CLUSTER + \
236+ ' --service ' + APP_NAME + 'Service' + \
237+ ' --desired-count ' + str (CLUSTER_MACHINES * TASKS_PER_MACHINE )
238+ update = getAWSJsonOutput (cmd )
239+ print 'Service updated.'
222240
223- # Step 2: wait until instances in the cluster are available
241+ # Step 6: Monitor the creation of the instances until all are present
224242 cmd = 'aws ec2 describe-spot-fleet-instances --spot-fleet-request-id ' + requestInfo ['SpotFleetRequestId' ]
225243 cmd_tbl = 'aws ec2 describe-spot-fleet-request-history --spot-fleet-request-id ' + requestInfo ['SpotFleetRequestId' ] + \
226244 ' --event-type error --start-time ' + datetime .date .isoformat (datetime .date .today ())
@@ -239,26 +257,7 @@ def startCluster():
239257 time .sleep (20 )
240258 print '.' ,
241259 status = getAWSJsonOutput (cmd )
242- print '\n Cluster ready'
243-
244- # Step 3: Create a log group for this app and date if one does not already exist
245- logclient = boto3 .client ('logs' )
246- loggroupinfo = logclient .describe_log_groups (logGroupNamePrefix = LOG_GROUP_NAME )
247- groupnames = [d ['logGroupName' ] for d in loggroupinfo ['logGroups' ]]
248- if LOG_GROUP_NAME not in groupnames :
249- logclient .create_log_group (logGroupName = LOG_GROUP_NAME )
250- logclient .put_retention_policy (logGroupName = LOG_GROUP_NAME , retentionInDays = 60 )
251- if LOG_GROUP_NAME + '_perInstance' not in groupnames :
252- logclient .create_log_group (logGroupName = LOG_GROUP_NAME + '_perInstance' )
253- logclient .put_retention_policy (logGroupName = LOG_GROUP_NAME + '_perInstance' , retentionInDays = 60 )
254-
255- # Step 4: update the ECS service to inject docker containers in EC2 instances
256- print 'Updating service'
257- cmd = 'aws ecs update-service --cluster ' + ECS_CLUSTER + \
258- ' --service ' + APP_NAME + 'Service' + \
259- ' --desired-count ' + str (CLUSTER_MACHINES * TASKS_PER_MACHINE )
260- update = getAWSJsonOutput (cmd )
261- print 'Service updated. Your job should start in a few minutes.'
260+ print 'Spot fleet successfully created. Your job should start in a few minutes.'
262261
263262#################################
264263# SERVICE 3: MONITOR JOB
0 commit comments