Sfoglia il codice sorgente

Merge branch 'master' of bitbucket.org:ikflowdat/stats into FD3-241

Luciano Andrade 7 anni fa
parent
commit
fe49c2f658

+ 26 - 2
.drone.yml

@@ -11,6 +11,14 @@ services:
 pipeline:
  build:
   image: docker.infra.flowdat.com/fd3/sf-php:latest
+  environment:
+    HOST_FTTH: ftth.test.fd3.flowdat.com
+    HOST_STATS: stats.test.fd3.flowdat.com
+    HOST_MAPAS: mapas.test.fd3.flowdat.com
+    HOST_BASE: base.test.fd3.flowdat.com
+    OAUTH_CLIENT_ID: ""
+    OAUTH_CLIENT_SECRET: ""
+ 
   commands:
       - command -v mysqladmin >/dev/null 2>&1 || { echo "I require mysqladmin but it's not installed.  Aborting." >&2; exit 1; }
       - while ! mysqladmin ping -h 127.0.0.1 --silent; do :; done
@@ -21,6 +29,8 @@ pipeline:
       
       - echo 'client = Flowdat3-Stats-Drone-Test' | tee /etc/flowdat.conf
       - echo 'date.timezone="America/Argentina/Buenos_Aires"' >> /etc/php/7.0/cli/php.ini
+
+      - cp app/config/bundles/ik/base-admin-bundle/parameters.yml.dist app/config/bundles/ik/base-admin-bundle/parameters.yml
       - chmod 0400 keys/bitbucket.id_rsa
       - eval $(ssh-agent); ssh-add keys/bitbucket.id_rsa
       - composer install --no-interaction --no-progress
@@ -35,7 +45,21 @@ pipeline:
    registry: docker.infra.flowdat.com
    username: drone
    password: 6hd2dLfL
-   tag: latest
+   tag: 
+     - latest
+   when:
+     event: [pull_request, push, tag]
+     branch: [master]
+
+ tag_docker:
+   repo : docker.infra.flowdat.com/fd3/stats
+   image: plugins/docker
+   email: luciano@interlink.com.ar
+   registry: docker.infra.flowdat.com
+   username: drone
+   password: 6hd2dLfL
+   tag: 
+     - ${DRONE_TAG##v}
    when:
      event: [pull_request, push, tag]
-     branch: master
+     branch: [v*]

+ 1 - 0
.gitignore

@@ -16,4 +16,5 @@
 /vendor/
 /web/bundles/
 /app/config/bundles/ik/webservice-bundle/parameters.yml
+/app/config/bundles/ik/base-admin-bundle/parameters.yml
 /app/config/bundles/hwi/oauth-bundle/parameters.yml

+ 14 - 0
Dockerfile

@@ -4,17 +4,31 @@ EXPOSE 8000
 ADD . /opt/stats
 
 RUN rm /opt/stats/var/cache/* -rf
+RUN cp /opt/stats/app/config/bundles/ik/base-admin-bundle/parameters.yml.dist /opt/stats/app/config/bundles/ik/base-admin-bundle/parameters.yml
 
 WORKDIR /opt/stats
 
+RUN rm -rf /opt/ftth/vendor/*
+RUN rm -rf app/config/parameters.yml 
+RUN rm -rf app/config/bundles/hwi/oauth-bundle/parameters.yml 
+RUN rm -rf app/config/bundles/ik/webservice-bundle/parameters.yml 
+ 
+RUN cp app/config/parameters.yml.docker app/config/parameters.yml 
+RUN cp app/config/bundles/hwi/oauth-bundle/parameters.yml.docker app/config/bundles/hwi/oauth-bundle/parameters.yml 
+RUN cp app/config/bundles/ik/webservice-bundle/parameters.yml.docker app/config/bundles/ik/webservice-bundle/parameters.yml 
+ 
+
 RUN cp -r keys /opt/keys/
 RUN chmod 0600 /opt/keys/*
 
+RUN eval $(ssh-agent) ; ssh-add /opt/keys/bitbucket.id_rsa ; composer install --no-scripts --no-interaction 
+
 CMD  eval $(ssh-agent) ; ssh-add /opt/keys/bitbucket.id_rsa ; composer install --no-scripts --no-interaction ;\
      rm var/cache/* -rf ;\
      cp app/config/parameters.yml.docker app/config/parameters.yml ;\
      cp app/config/bundles/hwi/oauth-bundle/parameters.yml.docker app/config/bundles/hwi/oauth-bundle/parameters.yml ;\
      cp app/config/bundles/ik/webservice-bundle/parameters.yml.docker app/config/bundles/ik/webservice-bundle/parameters.yml ;\
+     cp app/config/bundles/ik/base-admin-bundle/parameters.yml.dist app/config/bundles/ik/base-admin-bundle/parameters.yml ;\
      composer dump-autoload ;\
      composer run-script symfony-scripts --no-interaction ;\
      bin/console server:run 0.0.0.0

+ 3 - 0
app/AppKernel.php

@@ -48,6 +48,9 @@ class AppKernel extends Kernel
             new SimpleThings\EntityAudit\SimpleThingsEntityAuditBundle(),
             new AuditBundle\AuditBundle(),
             new AuthBundle\AuthBundle(),
+
+            new OldSound\RabbitMqBundle\OldSoundRabbitMqBundle(),
+            new WorkflowBundle\WorkflowBundle(),
         ];
 
         if (in_array($this->getEnvironment(), ['dev', 'test'], true)) {

+ 3 - 0
app/config/bundles/ik/base-admin-bundle/parameters.yml.dist

@@ -0,0 +1,3 @@
+parameters:
+    # el valor esta en segundos
+    app.checked_is_user_logged_in: 600

+ 2 - 0
app/config/config.yml

@@ -5,6 +5,7 @@ imports:
     
     - { resource: "bundles/friendsofsymfony/rest-bundle/config.yml" }
     - { resource: "bundles/ik/webservice-bundle/parameters.yml" }
+    - { resource: "bundles/ik/base-admin-bundle/parameters.yml" }
     - { resource: "bundles/hwi/oauth-bundle/parameters.yml" }
     - { resource: "@BaseOAuthClientBundle/Resources/config/services.yml" }
     - { resource: "@BaseOAuthClientBundle/Resources/config/hwioauthbundle/services.yml" }
@@ -60,6 +61,7 @@ twig:
     strict_variables: '%kernel.debug%'
     globals:
         fd_alerts: '@base_admin.alert_service'
+        checked_is_user_logged_in: '%app.checked_is_user_logged_in%'
 
 # Doctrine Configuration
 doctrine:

+ 5 - 0
app/config/parameters.yml.dist

@@ -35,3 +35,8 @@ parameters:
     geoserver_user: admin
     geoserver_pass: geoserver
     geoserver_path_shapes: '/var/flowdat/geoserver-shapes'
+
+    # Url del webservice de crontab para crear los archivos
+    url_crontab: http://127.0.0.1/cron.php?wsdl
+
+    env(HOST_BASE): base

+ 2 - 0
app/config/parameters.yml.docker

@@ -44,3 +44,5 @@ parameters:
     geoserver_user: admin
     geoserver_pass: geoserver
     geoserver_path_shapes: '/var/flowdat/geoserver-shapes'
+
+    url_crontab: http://supervisord/cron.php?wsdl

+ 4 - 5
app/config/routing.yml

@@ -51,10 +51,6 @@ base_oauth_client:
 base_hwioauthbundle_oauth_client:
     resource: "@BaseOAuthClientBundle/Resources/config/hwioauthbundle/routing.yml"    
 
-admin_tenancy_change_tenancy_global_ajax:
-    path: changeTenancyAjaxAction
-    defaults: { _controller: BaseAdminBundle:RedirectionAjax:changeTenancyAjax }
-
 baseadmin_alert:
     resource: "@BaseAdminBundle/Controller"
     type:     annotation
@@ -62,4 +58,7 @@ baseadmin_alert:
 audit:
     resource: "@AuditBundle/Controller/"
     type:     annotation
-    prefix:   /
+    prefix:   /
+
+base_admin:
+    resource: "@BaseAdminBundle/Resources/config/routing.yml"

+ 12 - 0
composer.json

@@ -130,6 +130,13 @@
             "type": "vcs",
             "url": "ssh://git@gogs.infra.flowdat.com:222/3erPartyFlowdat3/SonataAdminBundle.git",
             "name": "ik-sonata"
+        },
+        {
+            "type": "vcs",
+            "url": "ssh://git@200.50.168.30:222/VendorSoftwareFlowdat3/WorkflowBundle.git",
+            "options": {
+                "local_pk": "./keys/bitbucket.id_rsa"
+            }
         }
     ],
     "require": {
@@ -153,6 +160,8 @@
         "ik/stats/huawei-bundle": "dev-master",
         "ik/statsd-bundle": "dev-master",
         "ik/webservice-bundle": "dev-workflow_update",
+        "ik/workflow-bundle": "dev-workflow_update",
+        "ik/auth-bundle": "dev-master",
         "incenteev/composer-parameter-handler": "^2.0",
         "jms/serializer": "^1.9.0",
         "jms/serializer-bundle": "^1.5.0",
@@ -230,6 +239,9 @@
             },
             {
                 "file": "app/config/bundles/ik/audit-bundle/parameters.yml"
+            },
+            {
+                "file": "app/config/bundles/ik/base-admin-bundle/parameters.yml"
             }
         ]
     }

File diff suppressed because it is too large
+ 622 - 962
composer.lock


+ 169 - 0
src/StatsBundle/Command/GenerateRemoteCrontabCommand.php

@@ -0,0 +1,169 @@
+<?php
+
+namespace StatsBundle\Command;
+
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputOption;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class GenerateRemoteCrontabCommand extends ContainerAwareCommand
+{
+
+    protected function configure()
+    {
+        $this
+            ->setName('stats:crontab:remote')
+            ->setDescription('Generate Remote Stats Crontab File')
+            ->setHelp('El comando genera/actualiza el archivo crontab de manera remota para realizar consultas a dispositivos')
+            ->setDefinition(array(
+                new InputOption('file-crontab', false, InputOption::VALUE_OPTIONAL, "File Crontab","/etc/cron.d/fd3_stats"),
+                new InputOption('path-app', false, InputOption::VALUE_OPTIONAL, "Path App"),
+                new InputOption('url', false, InputOption::VALUE_OPTIONAL, "Crontab webservice url"),
+                new InputOption('amqp', false, InputOption::VALUE_OPTIONAL, "Execute the commands via amqp", true),
+                new InputOption('routing_key', false, InputOption::VALUE_OPTIONAL, "AMQP Routing key"),
+            ))
+        ;
+    }
+
+    /**
+     * @param InputInterface $input
+     * @param OutputInterface $output
+     */
+    protected function execute(InputInterface $input, OutputInterface $output)
+    {
+        $this->output = $output;
+        $fileCrontab = $input->getOption('file-crontab');
+        $pathApp = $input->getOption('path-app');
+        $url = $input->getOption('url');
+        if (is_null($url)) {
+            if ($this->getContainer()->hasParameter('url_crontab')) {
+                $url = $this->getContainer()->getParameter('url_crontab');
+            } else {
+                $output->writeln('<error>ERROR:</error> Debe definir una url para generar el crontab.');
+                $output->writeln($this->getSynopsis());
+
+                return;
+            }
+        }
+
+        $times = array();
+        $now = date("d-m-Y H:i:s");
+        $content = PHP_EOL."# NO EDITAR este archivo, se autogenera con el comando stats:crontab:remote. Generado {$now}.".PHP_EOL;
+
+        $doctrine = $this->getContainer()->get('doctrine.orm.entity_manager');
+        
+        if(is_null($pathApp)) {
+            $pathApp = $this->getContainer()->getParameter('app_path');
+        }
+        $pathConsole = "root $(wich php) {$pathApp}/bin/console"; 
+        
+        $serverDevices = $doctrine->getRepository('\StatsBundle\Entity\DeviceServer')->findAll();
+        
+        $oltMarks = array('FiberHome','FiberLink','Huawei');
+        $oltLibraries = array('OIDSFiberHomeV1','OIDSHuaweiV1');
+
+        $amqp = $input->getOption('amqp');
+        $amqpRemote = '';
+        $routing_key = '';
+        if ($amqp) {
+            $amqpRemote = 'amqp:remote';
+            
+            // Verifico la routing key si se pasa como parametro o variable de entorno
+            // default routing_key = stats
+            $routing_key = $input->getOption('routing_key');
+            if (!$routing_key) {
+                $routing_key = getenv('AMQP_KEY') !== false ? getenv('AMQP_KEY') : 'stats';
+            }
+            $routing_key = "--route={$routing_key}";
+        }
+        
+        $content .= "*/5 * * * * {$pathConsole} {$amqpRemote} {$routing_key} generate:crontab".PHP_EOL;
+
+        foreach($serverDevices as $server) {
+
+            $content .= PHP_EOL.PHP_EOL."# SERVER {$server->getName()} / {$server->getUrl()}".PHP_EOL;
+        
+            // APARTADO OLT
+            $oltDevices = $doctrine->getRepository('\StatsBundle\Entity\Device')->findBy(array('deviceType' => 'FTTHBundle\Entity\OLT','deviceServer' => $server));
+
+            $serverId = $server->getId();
+
+            foreach($oltDevices as $device) {
+                $commands = array();
+                $data = $device->jsonExtraData();
+                
+                if($data['executeSnmp'] == 0) continue;
+
+                if(!in_array($data['mark'],$oltMarks)) continue;
+                
+                if(!in_array($data['library'],$oltLibraries)) continue;
+
+                $oltName = $data['name'];
+                $mark = strtolower($data['mark']);
+                $library = $data['library'];
+                $snmpCommunity = $data['snmpCommunity'];
+                $deviceIp = $device->getIp();
+                $deviceId = $device->getDeviceId();
+
+                $timeScan = $data['timeScan'];
+                $timeOnuStats = $data['timeOnuStats'];
+                $timePonStats = $data['timePonStats'];
+                $timeOltOctets = $data['timeOltOctets'];
+
+                $params = "--olt-ip={$deviceIp} --olt-community={$snmpCommunity} --olt-snmp-library={$library} --olt-device-id={$deviceId} --olt-server-id={$serverId}";
+                if ($amqp) {
+                    $params = "--args=--olt-ip:{$deviceIp} --args=--olt-community:{$snmpCommunity} --args=--olt-snmp-library:{$library} --args=--olt-device-id:{$deviceId} --args=--olt-server-id:{$serverId}";
+                }
+
+                $commands[] = "*/{$timeScan} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:pon:scan {$params}";
+                $commands[] = "*/{$timeScan} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:onu:scan {$params}";
+                
+                $commands[] = "*/{$timeOnuStats} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:onu:stats {$params}";
+                $commands[] = "*/{$timePonStats} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:pon:stats {$params}";
+                $commands[] = "*/{$timeOltOctets} * * * * {$pathConsole} {$amqpRemote} {$routing_key} {$mark}:pon:octets {$params}";
+                
+                $params = '--olt-device-id={$deviceId} --olt-server-id={$serverId}';
+                if ($amqp) {
+                    $params = '--args=--olt-device-id:{$deviceId} --args=--olt-server-id:{$serverId}';
+                }
+                $commands[] = "*/{$timeOnuStats} * * * * {$pathConsole} {$amqpRemote} {$routing_key} stats:onu {$params}";
+                $commands[] = "*/{$timeOnuStats} * * * * {$pathConsole} {$amqpRemote} {$routing_key} stats:ponport {$params}";
+                
+                $content .= PHP_EOL."# OLT {$oltName} ({$deviceIp})".PHP_EOL;
+                
+                $content .= implode(PHP_EOL, $commands);
+            }
+            
+            if($this->getContainer()->getParameter('geoserver_service')) {
+                $content .= PHP_EOL.PHP_EOL."# MAPAS".PHP_EOL;
+                
+                $params = '--olt-server-id={$serverId}';
+                if ($amqp) {
+                    $params = '--args=--olt-server-id:{$serverId}';
+                }
+                
+                $commands = array();
+                $commands[] = "*/5 * * * * {$pathConsole} {$amqpRemote} {$routing_key} stats:onu:geo {$params}";
+                $commands[] = "*/10 * * * * {$pathConsole} {$amqpRemote} {$routing_key} stats:ponport:geo {$params}";
+                
+                $content .= implode(PHP_EOL, $commands);
+                $content .= PHP_EOL;
+            }
+        }
+        $this->soap($url, $fileCrontab, $content);
+    }
+
+    /**
+    * @param string $url
+    * @param string $filename
+    * @param string $content
+    */
+    protected function soap($url, $filename, $content)
+    {
+        $client = new \SoapClient($url);
+        $result = $client->__soapCall('crontab', compact('filename', 'content'));
+        $this->output->writeln($result); 
+    }
+
+}