Beispiel #1
0
 def POST( self, request):
     """
     Insert/update
     """
     self.app.logger.info("POST")
     req_d = self._req_to_dict( request )
     if(self.cluster_type == 'None'):
         self.app.logger.info( req_d )
         self.app.logger.error( "Got a none")
         status = 404
         msg = { 'status': 'error',
                 'message': 'Received a None',
                 'data': req_d }
         return ( msg, status )
     #create/update'
     if self.cluster_type is None or self.aws_region is None:
         #missing information
         msg =  {'status': 'error',
                 'message': 'Invalid URI for insert/update',
                 'data': {
                           'cluster_type': str(self.cluster_type),
                           'aws_region': str(self.aws_region)
                         } 
                 }
         return ( msg, 400 )
     result_clean = self._clean_result( req_d )
     wkr.insert_ANWorkerBase( self.cluster_type, self.aws_region, **result_clean )
     result = wkr.get_ANWorkerBase( self.cluster_type, self.aws_region )
     msg = {'status': 'complete',
             'data' : result }
     return ( msg, 200 )
Beispiel #2
0
 def _init_worker( self, req_d):
     msg = {'status': 'error',
             'data' : '',
             'message': 'Unable to initialize worker'}
     status = 404
     result = None
     if( req_d['master_name'] and req_d['master_name'] != "None"):
         result = wkr.get_ANWorkerBase( req_d['cluster_type'], req_d['aws_region'] )
     if result:
         new_worker_settings = {
                 'master_name': req_d['master_name'],
                 'cluster_type': result['cluster_type'],
                 'aws_region' : result['aws_region'],
                 'cluster_name' : self._gen_name( req_d['master_name'],
                     result['prefix'] ),
                 'num_nodes': 0,
                 'status':wkr.CONFIG,
         }
         starcluster_config = {
                 'cluster_name': new_worker_settings['cluster_name'],
                 'spot_bid': result['spot_bid'],
                 'key_name' : 'SET BY MASTER',
                 'key_location': 'SET BY MASTER',
                 'iam_profile': result['iam_profile'],
                 'force_spot_master': result['force_spot_master'],
                 'cluster_size': result['cluster_size'],
                 'plugins': result['plugins'],
                 'node_instance_type': result['instance_type'],
                 'node_image_id': result['image_id'],
                 'aws_region': result['aws_region']
                 }
         new_worker = None
         try:
             new_worker = wkr.insert_ANWorker(starcluster_config=starcluster_config,
                 **new_worker_settings)
         except Exception as e:
             self.app.logger.error("Attempted to create [%r] [%r]" % (
                 new_worker_settings, starcluster_config ))
             self.app.logger.error("Received exception [%r]" % (e))
             pass
         if new_worker:
             msg = {'status' : 'complete',
                     'data' : json_prep( new_worker )}
             status=200
     return (msg, status)
Beispiel #3
0
 def GET( self, request):
     """
     Read
     The request is only used if region is not given in constructor
     If cluster_type and aws_region are given, returns a single record
     otherwise a list.
     May return an empty list
     """
     self.app.logger.info("GET")
     result = None
     if self.aws_region is None and 'aws_region' in request.args:
         self.aws_region = request.args['aws_region']
     result = wkr.get_ANWorkerBase( self.cluster_type, self.aws_region )
     if result:
         status = 200
     else:
         status = 404
     msg = {'status':'complete',
             'data': result }
     return (msg, status)