def add_worker(self, instance_type):
        ''' table of instance_type -> available ram. '''
        AVAILABLE_RAM = {
            'm1.large': 7500,
            'm1.xlarge' : 15000,
            'm2.xlarge' : 17000,
            'm2.2xlarge' : 34000,
            'm2.4xlarge' : 68000,
        }
        if not instance_type in AVAILABLE_RAM:
            logger.error("instance type %s is not on AVAILABLE_RAM table. Choose another type or update the table.")
            return WorkerManager.WORKER_CREATION_FAILED

        logger.info("Creating new worker using image %s, using a %s instance", IMAGE_ID, instance_type)
        conn = self.ec2_connection()
        res = conn.run_instances(image_id=IMAGE_ID, security_groups=['indextank-worker'], instance_type=instance_type, placement='us-east-1a')
        if len(res.instances) == 0:
            logger.error("New instance failed")
            return WorkerManager.WORKER_CREATION_FAILED
        else:
            w = Worker()
            w.status = Worker.States.created
            w.instance_name = res.instances[0].id
            w.ram = AVAILABLE_RAM[instance_type]
            w.save()
            '''
            UNCOMMENT ME WHEN WE UPDATE BOTO'S VERSION
            conn.create_tags(res, {'Name': 'Worker:%i' % (w.id)})
            '''
            mail.report_new_worker(w)
            return WorkerManager.WORKER_CREATED
Exemple #2
0
    def update_status(self, instance_name):
        worker = Worker.objects.filter(instance_name=instance_name)[0]
        if worker.status == Worker.States.created:
            conn = self.ec2_connection()
            reservations = conn.get_all_instances([instance_name])
            instance = reservations[0].instances[0]
            if instance.state == 'running':
                logger.info('Worker %s is now initializing: %s',
                            worker.instance_name, instance.public_dns_name)
                worker.status = Worker.States.initializing
                worker.lan_dns = instance.private_dns_name
                worker.wan_dns = instance.public_dns_name
                worker.save()
                mail.report_new_worker(worker)
            else:
                logger.debug('Worker %s is still reporting as %s',
                             worker.instance_name, instance.state)
                return WorkerManager.WORKER_NOT_READY

        if worker.status == Worker.States.initializing:
            logger.debug('Trying to update controller on %s',
                         worker.instance_name)
            if self.update_worker(worker.lan_dns):
                worker.status = Worker.States.updating
                worker.save()
                logger.info('Worker %s is now updating', worker.instance_name)
                return WorkerManager.WORKER_UPDATING
            else:
                return WorkerManager.WORKER_INITIALIZING

        if worker.status == Worker.States.updating:
            logger.debug('Checking if controller is up on %s',
                         worker.instance_name)
            try:
                controller = rpc.getThriftControllerClient(worker.lan_dns)
                controller.get_worker_load_stats()
                worker.status = Worker.States.controllable
                worker.save()
                logger.info('Worker %s is now controllable',
                            worker.instance_name)
                return WorkerManager.WORKER_CONTROLLABLE
            except Exception, e:
                if isinstance(
                        e, TTransport.TTransportException
                ) and e.type == TTransport.TTransportException.NOT_OPEN:
                    logger.info('Controller on worker %s not responding yet.',
                                worker.lan_dns)
                else:
                    logger.exception(
                        'Unexpected exception while checking worker %s',
                        worker.lan_dns)
                return WorkerManager.WORKER_UPDATING
    def update_status(self, instance_name):
        worker = Worker.objects.filter(instance_name=instance_name)[0]
        if worker.status == Worker.States.created:
            conn = self.ec2_connection()
            reservations = conn.get_all_instances([instance_name])
            instance = reservations[0].instances[0]
            if instance.state == 'running':
                logger.info('Worker %s is now initializing: %s', worker.instance_name, instance.public_dns_name)
                worker.status = Worker.States.initializing
                worker.lan_dns = instance.private_dns_name
                worker.wan_dns = instance.public_dns_name
                worker.save()
                mail.report_new_worker(worker)
            else:
                logger.debug('Worker %s is still reporting as %s', worker.instance_name, instance.state)
                return WorkerManager.WORKER_NOT_READY
    
        if worker.status == Worker.States.initializing:
            logger.debug('Trying to update controller on %s', worker.instance_name)
            if self.update_worker(worker.lan_dns):
                worker.status = Worker.States.updating
                worker.save()
                logger.info('Worker %s is now updating', worker.instance_name)
                return WorkerManager.WORKER_UPDATING
            else:
                return WorkerManager.WORKER_INITIALIZING

        if worker.status == Worker.States.updating:
            logger.debug('Checking if controller is up on %s', worker.instance_name)
            try:
                controller = rpc.getThriftControllerClient(worker.lan_dns)
                controller.get_worker_load_stats()
                worker.status = Worker.States.controllable
                worker.save()
                logger.info('Worker %s is now controllable', worker.instance_name)
                return WorkerManager.WORKER_CONTROLLABLE
            except Exception, e:
                if isinstance(e, TTransport.TTransportException) and e.type == TTransport.TTransportException.NOT_OPEN:
                    logger.info('Controller on worker %s not responding yet.', worker.lan_dns)
                else:
                    logger.exception('Unexpected exception while checking worker %s', worker.lan_dns)
                return WorkerManager.WORKER_UPDATING
Exemple #4
0
    def add_worker(self, instance_type):
        ''' table of instance_type -> available ram. '''
        AVAILABLE_RAM = {
            'm1.large': 7500,
            'm1.xlarge': 15000,
            'm2.xlarge': 17000,
            'm2.2xlarge': 34000,
            'm2.4xlarge': 68000,
        }
        if not instance_type in AVAILABLE_RAM:
            logger.error(
                "instance type %s is not on AVAILABLE_RAM table. Choose another type or update the table."
            )
            return WorkerManager.WORKER_CREATION_FAILED

        logger.info("Creating new worker using image %s, using a %s instance",
                    IMAGE_ID, instance_type)
        conn = self.ec2_connection()
        res = conn.run_instances(image_id=IMAGE_ID,
                                 security_groups=['indextank-worker'],
                                 instance_type=instance_type,
                                 placement='us-east-1a')
        if len(res.instances) == 0:
            logger.error("New instance failed")
            return WorkerManager.WORKER_CREATION_FAILED
        else:
            w = Worker()
            w.status = Worker.States.created
            w.instance_name = res.instances[0].id
            w.ram = AVAILABLE_RAM[instance_type]
            w.save()
            '''
            UNCOMMENT ME WHEN WE UPDATE BOTO'S VERSION
            conn.create_tags(res, {'Name': 'Worker:%i' % (w.id)})
            '''
            mail.report_new_worker(w)
            return WorkerManager.WORKER_CREATED