<commit_before><?php
namespace Peazie\BuildDeliveryBundle\Controller;

use Aws\Common\Aws;
use Aws\Ec2\Ec2Client;
use Aws\ElasticLoadBalancing\ElasticLoadBalancingClient;

use Guzzle\Http\Client;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
 * @Route("/deploy")
 * @Template()
 */
class DeployController extends Controller
{
    /**
     * @Route("/{strategy}/{elb}", name="deploy_form", defaults={ "strategy":null, "elb":null })
     * @Template()
     */
    public function deployAction($strategy, $elb) 
    {
        if( is_null($strategy) || is_null($elb) ) {
            throw new \Exception('Required parameters cannot be null');
        }

        $cache  = $this->get('delivery.cache');
        $params = $this->container->getParameter('jenkins');
        $client = new Client($params['base_url']);

        $builds = null;
        if( !$builds = $cache->get('build-list') ) {

            $request = $client->get( '/job/PeazieCM-Staging-Deploy/api/json', array(), array( 
                    'auth' => array( 'auth' => $params['user'], $params['password'] )
                )
            );

            $response = $request->send();
            $builds = $response->json();

            $cache->set( 'build-list', $builds, 3*60 );
        }

        if( !$lastBuildResults = $cache->get('build-list-' . $builds['lastStableBuild']['number'] ) ) {

            $lastBuildRequest = $client->get( $builds['lastStableBuild']['url'] . 'api/json', array(), array( 
                    'auth' => array( 'auth' => $params['user'], $params['password'] )
                )
            );

            $lastBuildResponse = $lastBuildRequest->send();
            $lastBuildResults  = $lastBuildResponse->json();

            $cache->set( 'build-list-' . $builds['lastStableBuild']['number'], $lastBuildResults, 3*60 );
        }

        $data['LoadBalancerName' ] = $elb;
        $data['DeployStrategy']    = $strategy;
        $data['JenkinsBuild']      = $lastBuildResults['number'];
        $data['HgRevision']        = $lastBuildResults['actions'][1]['mercurialNodeName'];

        return array( 'data' => $data );

    }//deploy


    /**
     * @Route("/", name="deploy_cf" )
     * @Template()
     */
    public function cfAction(Request $r)
    {
        if ($r->get('deploy_strategy') != 'build' ) {
            return $this->redirect( $this->generateUrl('prod_index') );
        }

        $jenkins_build = (int)    $r->get('jenkins_build');
        $hg_revision   = (string) $r->get('hg_rev');
        $instance_type = (string) $r->get('instance_type');
        $instance_num  = (int)    $r->get('instance_number');
        $access_key    = (string) $r->get('aws_key');
        $access_pass   = (string) $r->get('aws_pass');
        
        $stack_name    = 'peazie-web-' . $jenkins_build . '-' . substr( $hg_revision, 0, 6 );

        $stack_config = array(
            'StackName'   => $stack_name,
            'TemplateURL' => 'https://s3-us-west-1.amazonaws.com/deploy.peazie.io/cf/peazie_web_autoscale.json',
            'DisableRollback'  => true,

            'Parameters'  => array(
                array(
                    'ParameterKey'   => 'HgBuild',
                    'ParameterValue' => $jenkins_build,
                ),
                array(
                    'ParameterKey'   => 'HgRev',
                    'ParameterValue' => $hg_revision,
                ),
                array(
                    'ParameterKey'   => 'NumberOfInstances',
                    'ParameterValue' => $instance_num,
                ),
                array(
                    'ParameterKey'   => 'InstanceType',
                    'ParameterValue' => $instance_type,
                )
            ),
            'Tags' => array(
                array(
                    'Key'   => 'Name',
                    'Value' => 'autoscale prod ' . $jenkins_build . ' ' . substr( $hg_revision, 0, 4 ),
                ),
                array(
                    'Key'   => 'brand',
                    'Value' => 'peazie',
                ),
                array(<commit_msg>Make it first 6 of hash<commit_after><?php
namespace Peazie\BuildDeliveryBundle\Controller;

use Aws\Common\Aws;
use Aws\Ec2\Ec2Client;
use Aws\ElasticLoadBalancing\ElasticLoadBalancingClient;

use Guzzle\Http\Client;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;

/**
 * @Route("/deploy")
 * @Template()
 */
class DeployController extends Controller
{
    /**
     * @Route("/{strategy}/{elb}", name="deploy_form", defaults={ "strategy":null, "elb":null })
     * @Template()
     */
    public function deployAction($strategy, $elb) 
    {
        if( is_null($strategy) || is_null($elb) ) {
            throw new \Exception('Required parameters cannot be null');
        }

        $cache  = $this->get('delivery.cache');
        $params = $this->container->getParameter('jenkins');
        $client = new Client($params['base_url']);

        $builds = null;
        if( !$builds = $cache->get('build-list') ) {

            $request = $client->get( '/job/PeazieCM-Staging-Deploy/api/json', array(), array( 
                    'auth' => array( 'auth' => $params['user'], $params['password'] )
                )
            );

            $response = $request->send();
            $builds = $response->json();

            $cache->set( 'build-list', $builds, 3*60 );
        }

        if( !$lastBuildResults = $cache->get('build-list-' . $builds['lastStableBuild']['number'] ) ) {

            $lastBuildRequest = $client->get( $builds['lastStableBuild']['url'] . 'api/json', array(), array( 
                    'auth' => array( 'auth' => $params['user'], $params['password'] )
                )
            );

            $lastBuildResponse = $lastBuildRequest->send();
            $lastBuildResults  = $lastBuildResponse->json();

            $cache->set( 'build-list-' . $builds['lastStableBuild']['number'], $lastBuildResults, 3*60 );
        }

        $data['LoadBalancerName' ] = $elb;
        $data['DeployStrategy']    = $strategy;
        $data['JenkinsBuild']      = $lastBuildResults['number'];
        $data['HgRevision']        = $lastBuildResults['actions'][1]['mercurialNodeName'];

        return array( 'data' => $data );

    }//deploy


    /**
     * @Route("/", name="deploy_cf" )
     * @Template()
     */
    public function cfAction(Request $r)
    {
        if ($r->get('deploy_strategy') != 'build' ) {
            return $this->redirect( $this->generateUrl('prod_index') );
        }

        $jenkins_build = (int)    $r->get('jenkins_build');
        $hg_revision   = (string) $r->get('hg_rev');
        $instance_type = (string) $r->get('instance_type');
        $instance_num  = (int)    $r->get('instance_number');
        $access_key    = (string) $r->get('aws_key');
        $access_pass   = (string) $r->get('aws_pass');
        
        $stack_name    = 'peazie-web-' . $jenkins_build . '-' . substr( $hg_revision, 0, 6 );

        $stack_config = array(
            'StackName'   => $stack_name,
            'TemplateURL' => 'https://s3-us-west-1.amazonaws.com/deploy.peazie.io/cf/peazie_web_autoscale.json',
            'DisableRollback'  => true,

            'Parameters'  => array(
                array(
                    'ParameterKey'   => 'HgBuild',
                    'ParameterValue' => $jenkins_build,
                ),
                array(
                    'ParameterKey'   => 'HgRev',
                    'ParameterValue' => $hg_revision,
                ),
                array(
                    'ParameterKey'   => 'NumberOfInstances',
                    'ParameterValue' => $instance_num,
                ),
                array(
                    'ParameterKey'   => 'InstanceType',
                    'ParameterValue' => $instance_type,
                )
            ),
            'Tags' => array(
                array(
                    'Key'   => 'Name',
                    'Value' => 'autoscale prod ' . $jenkins_build . ' ' . substr( $hg_revision, 0, 6 ),
                ),
                array(
                    'Key'   => 'brand',
                    'Value' => 'peazie',
                ),
                array(
{'fraction_non_alphanumeric': 0.165383718217868, 'fraction_numerical': 0.003615581992069046, 'mean_word_length': 1.8775167785234899, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 91, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3955072', 'n_tokens_mistral': 2645, 'n_tokens_neox': 2490, 'n_words': 404}