GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( 31696d...d014e0 )
by Stuart
05:40
created

FromSupervisor::getProgramIsRunning()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 40
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 40
rs 8.5806
cc 4
eloc 19
nc 4
nop 1
1
<?php
2
3
/**
4
 * Copyright (c) 2011-present Mediasift Ltd
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 *
11
 *   * Redistributions of source code must retain the above copyright
12
 *     notice, this list of conditions and the following disclaimer.
13
 *
14
 *   * Redistributions in binary form must reproduce the above copyright
15
 *     notice, this list of conditions and the following disclaimer in
16
 *     the documentation and/or other materials provided with the
17
 *     distribution.
18
 *
19
 *   * Neither the names of the copyright holders nor the names of his
20
 *     contributors may be used to endorse or promote products derived
21
 *     from this software without specific prior written permission.
22
 *
23
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34
 * POSSIBILITY OF SUCH DAMAGE.
35
 *
36
 * @category  Libraries
37
 * @package   Storyplayer/Modules/Supervisor
38
 * @author    Shweta Saikumar <[email protected]>
39
 * @copyright 2011-present Mediasift Ltd www.datasift.com
40
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
41
 * @link      http://datasift.github.io/storyplayer
42
 */
43
44
namespace Storyplayer\SPv2\Modules\Supervisor;
45
46
use DataSift\Storyplayer\HostLib;
47
use DataSift\Storyplayer\OsLib;
48
use DataSift\Storyplayer\PlayerLib\StoryTeller;
49
use DataSift\Stone\ObjectLib\BaseObject;
50
51
use GanbaroDigital\TextTools\Filters\FilterColumns;
52
use GanbaroDigital\TextTools\Filters\FilterForMatchingRegex;
53
54
use Storyplayer\SPv2\Modules\Exceptions;
55
use Storyplayer\SPv2\Modules\Host;
56
use Storyplayer\SPv2\Modules\Host\HostAwareModule;
57
use Storyplayer\SPv2\Modules\Log;
58
59
/**
60
 * get information about a program running under supervisor
61
 *
62
 * @category  Libraries
63
 * @package   Storyplayer/Modules/Supervisor
64
 * @author    Shweta Saikumar <[email protected]>
65
 * @copyright 2011-present Mediasift Ltd www.datasift.com
66
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
67
 * @link      http://datasift.github.io/storyplayer
68
 */
69
class FromSupervisor extends HostAwareModule
70
{
71
    public function getProgramIsRunning($programName)
72
    {
73
        // what are we doing?
74
        $log = Log::usingLog()->startAction("is program '{$programName}' running under supervisor on host '{$this->args[0]}'?");
75
76
        // get the host details
77
        $hostDetails = $this->getHostDetails();
78
79
        //run the supervisorctl command
80
        $result = Host::onHost($hostDetails->hostId)->runCommandAndIgnoreErrors("sudo supervisorctl status");
0 ignored issues
show
Deprecated Code introduced by
The method Storyplayer\SPv2\Modules...ommandAndIgnoreErrors() has been deprecated with message: since v2.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
81
        // |egrep '^$programName' | awk '{print \\$2}'");
82
83
        // did the command succeed?
84
        if ($result->didCommandFail()) {
85
            $msg = "command failed with return code '{$result->returnCode}' and output '{$result->output}'";
86
            $log->endAction($msg);
87
            throw Exceptions::newActionFailedException(__METHOD__);
88
        }
89
90
        // reduce the output down
91
        $lines = explode("\n", $result->output);
92
        $lines = FilterForMatchingRegex::against($lines, "/^$programName /");
93
        $lines = FilterColumns::from($lines, "1", ' ');
94
95
        if (empty($lines)) {
96
            $log->endAction("supervisor does not know about '{$programName}'");
97
            return false;
98
        }
99
100
        // what happened?
101
        if ($lines[0] == 'RUNNING') {
102
            $log->endAction('current status is RUNNING');
103
            return true;
104
        }
105
106
        // if we get here, then the program is not RUNNING, and we
107
        // treat that as a failure
108
        $log->endAction('current status is ' . $lines[0]);
109
        return false;
110
    }
111
}
112