示例#1
0
    def run(self):
        self.running = True
        pid = self.get_pid()
        proc = None
        # check pid file and lookup process
        if pid and self.process_exist(pid):
            servo.log.debug('Existing SWF worker process is found (%d)' % pid)
            self.kill_pid(pid)
        try:
            # if no process, start a new process
            # prepare arguments to the process
            swf_url = config.get_swf_service_url()
            if not swf_url:
                raise Exception('Simple workflow service url is not found')
            swf_url = 'http://%s:%d/' % (swf_url, config.get_webservice_port())
            instance_id = config.get_servo_id()
            if not instance_id:
                raise Exception('Instance ID is not found')

            cmdline = 'load-balancer-servo-workflow --logdir %s --loglevel %s -e %s -d %s -l %s' % (
                LOG_DIR, LOG_LEVEL, swf_url, SWF_DOMAIN, instance_id)
            servo.log.debug('Running SWF worker: %s' % cmdline)
            proc = self.execute_with_popen(cmdline)
            pid = proc.pid
            self.write_pid(pid)
        except Exception, err:
            servo.log.error('Failed to run SWF worker: %s' % err)
    def run(self):
        self.running = True
        pid = self.get_pid()
        proc = None
        # check pid file and lookup process
        if pid and self.process_exist(pid):
            servo.log.debug('Existing SWF worker process is found (%d)' % pid)
            self.kill_pid(pid)
        try:
            # if no process, start a new Java process
            # prepare arguments to the process
            swf_url = config.get_swf_service_url()
            if not swf_url:
                raise Exception('Simple workflow service url is not found')
            swf_url = 'http://%s:%d/' % (swf_url, config.get_webservice_port())
            instance_id = config.get_servo_id()
            if not instance_id:
                raise Exception('Instance ID is not found')
            worker_jar = self.lookup_worker_jar()
            if not worker_jar:
                raise Exception('No worker jar is found')

            cmdline = 'java -cp .:%s/* %s --logdir %s --logappender cloud-debug-file --loglevel %s -d %s -e %s --jar %s --classes %s -l %s' % (DIR_LIBRARIES, CLIENT_CLASS, LOG_DIR, LOG_LEVEL, SWF_DOMAIN, swf_url, worker_jar, WORKER_CLASSES, instance_id)
            servo.log.debug('Running SWF worker: %s' % cmdline)
            proc = self.execute_with_popen(cmdline)
            pid = proc.pid
            self.write_pid(pid)
        except Exception, err:
            servo.log.error('Failed to run SWF worker: %s' % err)
示例#3
0
    def run(self):
        self.running = True
        pid = self.get_pid()
        proc = None
        # check pid file and lookup process
        if pid and self.process_exist(pid):
            servo.log.debug('Existing SWF worker process is found (%d)' % pid)
            self.kill_pid(pid)
        try:
            # if no process, start a new Java process
            # prepare arguments to the process
            swf_url = config.get_swf_service_url()
            if not swf_url:
                raise Exception('Simple workflow service url is not found')
            swf_url = 'http://%s:%d/' % (swf_url, config.get_webservice_port())
            instance_id = config.get_servo_id()
            if not instance_id:
                raise Exception('Instance ID is not found')
            worker_jar = self.lookup_worker_jar()
            if not worker_jar:
                raise Exception('No worker jar is found')

            cmdline = 'java -cp .:%s/* %s --logdir %s --logappender cloud-debug-file --loglevel %s -d %s -e %s --jar %s --classes %s -l %s' % (
                DIR_LIBRARIES, CLIENT_CLASS, LOG_DIR, LOG_LEVEL, SWF_DOMAIN,
                swf_url, worker_jar, WORKER_CLASSES, instance_id)
            servo.log.debug('Running SWF worker: %s' % cmdline)
            proc = self.execute_with_popen(cmdline)
            pid = proc.pid
            self.write_pid(pid)
        except Exception, err:
            servo.log.error('Failed to run SWF worker: %s' % err)
示例#4
0
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error(
                    'could not find the ipaddress of the instance %s' %
                    self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()
            con = servo.ws.connect_elb(
                host_name=elb_host,
                aws_access_key_id=aws_access_key_id,
                aws_secret_access_key=aws_secret_access_key,
                security_token=security_token)

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)
            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:
                healthy_count += 1
                unhealthy_count = 0
                if healthy_count >= health_check_config.healthy_threshold:
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('Reported %s InService' % self.instance_id)
                    try:
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' %
                                        err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id,
                                                'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('Reported %s OutOfService' %
                                    self.instance_id)
                    try:
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' %
                                        err)
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        last_inservice_reported = dt.min
        last_outofservice_reported = dt.min
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error(
                    'could not find the ipaddress of the instance %s' %
                    self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)

            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:  # passed one check
                healthy_count += 1
                unhealthy_count = 0
                if not self.initially_reported or healthy_count >= health_check_config.healthy_threshold:
                    self.initially_reported = True
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('%s: InService' % self.instance_id)
                    elapsed = dt.now() - last_inservice_reported
                    if self.report_elb and elapsed.seconds > config.PUT_BACKEND_INSTANCE_HEALTH_PERIOD_SEC:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token)
                            con.put_instance_health(servo_instance_id,
                                                    [instance])
                            servo.log.debug('%s: InService status reported' %
                                            self.instance_id)
                            last_inservice_reported = dt.now()
                            last_outofservice_reported = dt.min
                        except Exception, err:
                            servo.log.error('failed to post servo states: %s' %
                                            err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    self.initially_reported = True
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id,
                                                'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('%s: OutOfService' % self.instance_id)
                    elapsed = dt.now() - last_outofservice_reported
                    if self.report_elb and elapsed.seconds > config.PUT_BACKEND_INSTANCE_HEALTH_PERIOD_SEC:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token)
                            con.put_instance_health(servo_instance_id,
                                                    [instance])
                            servo.log.debug(
                                '%s: OutOfService status reported' %
                                self.instance_id)
                            last_outofservice_reported = dt.now()
                            last_inservice_reported = dt.min
                        except Exception, err:
                            servo.log.error('failed to post servo states: %s' %
                                            err)
    def run(self):
        if health_check_config is None:
            servo.log.error("health check config is not set")
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        while self.running:
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error("could not find the ipaddress of the instance %s" % self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith("HTTPS"):
                result = self.check_https(target)
            elif target.upper().startswith("TCP"):
                result = self.check_tcp(target)
            elif target.upper().startswith("HTTP"):
                result = self.check_http(target)
            elif target.upper().startswith("SSL"):
                result = self.check_ssl(target)
            else:
                servo.log.error("unknown target: %s" % target)
            # print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:
                healthy_count += 1
                unhealthy_count = 0
                if healthy_count >= health_check_config.healthy_threshold:
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, "InService")
                    self.inst_status = "InService"
                    servo.log.debug("%s: InService" % self.instance_id)
                    if self.report_elb:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token,
                            )
                            con.put_instance_health(servo_instance_id, [instance])
                            servo.log.debug("%s: InService status reported" % self.instance_id)
                        except Exception, err:
                            servo.log.error("failed to post servo states: %s" % err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id, "OutOfService")
                    self.inst_status = "OutOfService"
                    servo.log.debug("%s: OutOfService" % self.instance_id)
                    if self.report_elb:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token,
                            )
                            con.put_instance_health(servo_instance_id, [instance])
                            servo.log.debug("%s: OutOfService status reported" % self.instance_id)
                        except Exception, err:
                            servo.log.error("failed to post servo states: %s" % err)
示例#7
0
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        last_inservice_reported = dt.min
        last_outofservice_reported = dt.min
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error(
                    'could not find the ipaddress of the instance %s' %
                    self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)

            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:  # passed one check
                healthy_count += 1
                unhealthy_count = 0
                if not self.initially_reported or healthy_count >= health_check_config.healthy_threshold:
                    self.initially_reported = True
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('%s: InService' % self.instance_id)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    self.initially_reported = True
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id,
                                                'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('%s: OutOfService' % self.instance_id)

            if healthy_count > health_check_config.healthy_threshold:
                healthy_count = 0
            if unhealthy_count > health_check_config.unhealthy_threshold:
                unhealthy_count = 0
            health_check_delay = health_check_config.interval
            while health_check_delay > 0 and self.running:
                time.sleep(1)
                health_check_delay -= 1
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None 
        healthy_count = 0
        unhealthy_count = 0
        last_inservice_reported = dt.min
        last_outofservice_reported = dt.min
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error('could not find the ipaddress of the instance %s' % self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)

            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result: # passed one check
                healthy_count += 1
                unhealthy_count = 0
                if not self.initially_reported or healthy_count >= health_check_config.healthy_threshold:
                    self.initially_reported = True
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('%s: InService' % self.instance_id)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    self.initially_reported = True
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('%s: OutOfService' % self.instance_id)

            if healthy_count > health_check_config.healthy_threshold:
                healthy_count = 0
            if unhealthy_count > health_check_config.unhealthy_threshold:
                unhealthy_count = 0
            health_check_delay = health_check_config.interval
            while health_check_delay > 0 and self.running:
                time.sleep(1)
                health_check_delay -= 1
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None 
        healthy_count = 0
        unhealthy_count = 0
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error('could not find the ipaddress of the instance %s' % self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)
            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:
                healthy_count += 1
                unhealthy_count = 0
                if healthy_count >= health_check_config.healthy_threshold:
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('Reported %s InService' % self.instance_id)
                    try:
                        con = servo.ws.connect_elb(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token)
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' % err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('Reported %s OutOfService' % self.instance_id)
                    try:
                        con = servo.ws.connect_elb(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token)
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' % err)