<commit_before><?php
App::uses('VumiSupervisord','Lib');
App::uses('Component', 'Controller');


class VumiSupervisordComponent extends Component
{

    public function __construct(ComponentCollection $collection, $settings = array()) {
        //$this->_controller = $collection->getController();
        require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');        
        parent::__construct($collection, $settings);
    }

   
    function getState()
    {
        //require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');        
    
        $f=new xmlrpcmsg('supervisor.getState');
        $c=new xmlrpc_client("/RPC2", "localhost",9010);
        $r=&$c->send($f);
        if(!$r->faultCode())
        {
            $arr = php_xmlrpc_decode($r->value());
            return array(
                    'running' => true,
                    'msg' => $arr['statename']
                    );
        }
        else
        {
            return array(
                    'running' => false,
                    'code' => htmlspecialchars($r->faultCode()),
                    'msg' => htmlspecialchars($r->faultString())
                    );
        }
    }


    function getWorkerInfo($name)
    {
        require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');
   
        $val = array(new xmlrpcval('echo_worker:'.$name));     
        $f   = new xmlrpcmsg('supervisor.getProcessInfo', $val);
        $c   = new xmlrpc_client("/RPC2", "localhost",9010);
        
        $r=&$c->send($f);
        
        if(!$r->faultCode()) {
            $arr = php_xmlrpc_decode($r->value());
            return array(
                    'running' => true,
                    'msg' => $arr['statename']
                    );
        } else {
            return array(
                    'running' => false,
                    'msg' => 'Not registered'
                    );    
        }   
    }


    function startWorker($worker_name)
    {
        require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');
        
        $c = new xmlrpc_client("/RPC2", "localhost",9010);
        
        $val = array(
            new xmlrpcval('echo_worker'),
            new xmlrpcval($worker_name), 
            new xmlrpcval (
                array( 
                    'command' => new xmlrpcval("twistd 
                        --pidfile=./tmp/pids/%(program_name)s_%(process_num)s.pid 
                        -n start_worker 
                        --vhost=/develop 
                        --worker-class=vumi.workers.ttc.TtcGenericWorker 
                        --config=./config/ttc/ttc_generic_worker.yaml 
                        --set-option=control_name:".$worker_name),                    
                    //'command' => new xmlrpcval("ls -l"),
                    'autostart' => new xmlrpcval("true"),
                    'autorestart' => new xmlrpcval("true"),
                    'startsecs' => new xmlrpcval("0"),
                    'numprocs' => new xmlrpcval("1"),
                    'stdout_logfile' => new xmlrpcval("./logs/%(program_name)s_%(process_num)s.log"),
                    'stderr_logfile' => new xmlrpcval("./logs/%(program_name)s_%(process_num)s.err")
                ),"struct")
            );
        
        $f=new xmlrpcmsg('twiddler.addProgramToGroup', $val);
        
        $r=&$c->send($f);
        
        if(!$r->faultCode())
        {
            return array(
                    'running' => true,
                    );
                    
        } else {
            return array(
                    'running' => false,
                    'error_code' => htmlspecialchars($r->faultCode()),
                    'msg' => htmlspecialchars($r->faultString())
                    );
        }
    }


    function removeWorker($name)
    {
        require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');
        
        $c=new xmlrpc_client("/RPC2", "localhost",9010);
    
        $val = array(
            new xmlrpcval('echo_worker'),
            new xmlrpcval($name)
            );
                
        $f=new xmlrpcmsg('twiddler.removeProcessFromGroup', $val);
        
        $r=&$c->send($f);
        
        if(!$r->faultCode())
        {<commit_msg>removing xml useage<commit_after><?php
App::uses('VumiSupervisord','Lib');
App::uses('Component', 'Controller');


class VumiSupervisordComponent extends Component
{

    public function __construct(ComponentCollection $collection, $settings = array()) {
        //$this->_controller = $collection->getController();
        //require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');        
        parent::__construct($collection, $settings);
    }

   
    function getState()
    {
        //require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');        
    
        $f=new xmlrpcmsg('supervisor.getState');
        $c=new xmlrpc_client("/RPC2", "localhost",9010);
        $r=&$c->send($f);
        if(!$r->faultCode())
        {
            $arr = php_xmlrpc_decode($r->value());
            return array(
                    'running' => true,
                    'msg' => $arr['statename']
                    );
        }
        else
        {
            return array(
                    'running' => false,
                    'code' => htmlspecialchars($r->faultCode()),
                    'msg' => htmlspecialchars($r->faultString())
                    );
        }
    }


    function getWorkerInfo($name)
    {
        //require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');
   
        $val = array(new xmlrpcval('echo_worker:'.$name));     
        $f   = new xmlrpcmsg('supervisor.getProcessInfo', $val);
        $c   = new xmlrpc_client("/RPC2", "localhost",9010);
        
        $r=&$c->send($f);
        
        if(!$r->faultCode()) {
            $arr = php_xmlrpc_decode($r->value());
            return array(
                    'running' => true,
                    'msg' => $arr['statename']
                    );
        } else {
            return array(
                    'running' => false,
                    'msg' => 'Not registered'
                    );    
        }   
    }


    function startWorker($worker_name)
    {
      //  require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');
        
        $c = new xmlrpc_client("/RPC2", "localhost",9010);
        
        $val = array(
            new xmlrpcval('echo_worker'),
            new xmlrpcval($worker_name), 
            new xmlrpcval (
                array( 
                    'command' => new xmlrpcval("twistd 
                        --pidfile=./tmp/pids/%(program_name)s_%(process_num)s.pid 
                        -n start_worker 
                        --vhost=/develop 
                        --worker-class=vumi.workers.ttc.TtcGenericWorker 
                        --config=./config/ttc/ttc_generic_worker.yaml 
                        --set-option=control_name:".$worker_name),                    
                    //'command' => new xmlrpcval("ls -l"),
                    'autostart' => new xmlrpcval("true"),
                    'autorestart' => new xmlrpcval("true"),
                    'startsecs' => new xmlrpcval("0"),
                    'numprocs' => new xmlrpcval("1"),
                    'stdout_logfile' => new xmlrpcval("./logs/%(program_name)s_%(process_num)s.log"),
                    'stderr_logfile' => new xmlrpcval("./logs/%(program_name)s_%(process_num)s.err")
                ),"struct")
            );
        
        $f=new xmlrpcmsg('twiddler.addProgramToGroup', $val);
        
        $r=&$c->send($f);
        
        if(!$r->faultCode())
        {
            return array(
                    'running' => true,
                    );
                    
        } else {
            return array(
                    'running' => false,
                    'error_code' => htmlspecialchars($r->faultCode()),
                    'msg' => htmlspecialchars($r->faultString())
                    );
        }
    }


    function removeWorker($name)
    {
      //  require_once('xmlrpc-3.0.0.beta/xmlrpc.inc');
        
        $c=new xmlrpc_client("/RPC2", "localhost",9010);
    
        $val = array(
            new xmlrpcval('echo_worker'),
            new xmlrpcval($name)
            );
                
        $f=new xmlrpcmsg('twiddler.removeProcessFromGroup', $val);
        
        $r=&$c->send($f);
        
        if(!$r->faultCode())
        {
{'fraction_non_alphanumeric': 0.14952153110047847, 'fraction_numerical': 0.008851674641148326, 'mean_word_length': 1.3387412587412588, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 69}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2490822', 'n_tokens_mistral': 2485, 'n_tokens_neox': 2334, 'n_words': 326}