}
function usage()
{
    global $help;
    echo "Usage: php " . basename(__FILE__) . " -c configFile [-h] [-k <key>] [-s <secret>] [-r <region>]\n";
    echo "-h: Print this help\n";
    echo "-d: Debug mode\n";
    echo "-c: configFile\n";
    echo "-k <AWS key>: Optional. Will use env variables by default\n";
    echo "-s <AWS secret>: Optional. Will use env variables by default\n";
    echo "-r <AWS region>: Optional. Will use env variables by default\n\n";
    echo $help;
    exit(0);
}
try {
    check_input_parameters();
} catch (Exception $e) {
    print "[ERROR] " . $e->getMessage() . "\n";
    exit(2);
}
// Instanciate ComSDK to communicate with the stack
try {
    $CpeClientSdk = new SA\CpeClientSdk($key, $secret, $region, $debug);
} catch (Exception $e) {
    exit($e->getMessage());
}
// Commands mapping
$commandMap = ["start_job" => "start_job"];
// Look for input commands
print $help;
while (42) {
    if (isset($options['l'])) {
        $logPath = $options['l'];
    }
    if (!isset($options['n'])) {
        print "[ERROR] You must provide a [-n client_name] parameter to provide your client application name.\n";
        exit(1);
    }
    $cpeLogger = new CpeSdk\CpeLogger($logPath, $options['n'], $debug);
    $config = new \stdClass();
    $config->clients = [(object) ['name' => $options['n'], 'queues' => (object) ['input' => getenv('INPUT_QUEUE'), 'output' => getenv('OUTPUT_QUEUE')]]];
    # Validate against JSON Schemas
    # if (($err = validate_json($config, "config/mainConfig.json")))
    # exit("JSON main configuration file invalid! Details:\n".$err);
    return $config;
}
$config = check_input_parameters();
$cpeLogger->log_out("INFO", basename(__FILE__), $config);
// Create InputPoller object
try {
    $inputPoller = new InputPoller($config);
} catch (CpeSdk\CpeException $e) {
    echo $e->getMessage();
    $cpeLogger->log_out("FATAL", basename(__FILE__), $e->getMessage());
    exit(1);
}
$cpeLogger->log_out("INFO", __DIR__, "Start Listening.");
print "Start polling ...\n";
// Start polling loop to get incoming commands from SQS input queues
while (42) {
    $inputPoller->poll_SQS_queues();
}
        $defaultConfigFile = $options['c'];
    }
    try {
        // Check config file
        if (!($config = json_decode(file_get_contents($defaultConfigFile)))) {
            print "\n[CONFIG ISSUE]\nConfiguration file '{$defaultConfigFile}' invalid or non-existant.\n\n[EASY FIX]\nGo to the directory mentioned in the error above and rename the template file 'cpeConfigTemplate.json' to 'cpeConfig.json'. Configure your Activities. As example you have Activities for CloudTranscode already setup in the template. You can declare your Activities and start executing tasks in an SWF workflow.\n";
            exit(1);
        }
    } catch (Exception $e) {
        print $e;
    }
    # Validate against JSON Schemas
    # if (($err = validate_json($config, "config/mainConfig.json")))
    # exit("JSON main configuration file invalid! Details:\n".$err);
    return $config;
}
// Get config file
$defaultConfigFile = realpath(dirname(__FILE__)) . "/../config/cpeConfig.json";
$config = check_input_parameters($defaultConfigFile);
// Instantiate ActivityPoller
try {
    $activityPoller = new ActivityPoller($config);
} catch (CpeSdk\CpeException $e) {
    $cpeLogger->log_out("FATAL", basename(__FILE__), $e->getMessage());
    exit(1);
}
$cpeLogger->log_out("INFO", basename(__FILE__), "Starting activity tasks polling");
// Start polling loop
while (42) {
    $activityPoller->poll_for_activities();
}
Esempio n. 4
0
    echo "--to <filepath>: Full path to file where to save. You can override original filename.\n";
    echo "--force: Force download even if file exists locally\n\n";
    exit(0);
}
function check_input_parameters($options)
{
    if (!count($options) || isset($options['h']) || isset($options['help'])) {
        usage();
    }
    if (!isset($options['bucket']) || !isset($options['file']) || !isset($options['to'])) {
        print "Error: Missing mandatory parameter !\n";
        usage();
    }
}
$options = getopt("h", array("bucket:", "file:", "to:", "force::", "help::"));
check_input_parameters($options);
// If local file already exists. We don't download unless --force
if (!isset($options['force']) && file_exists($options['to']) && filesize($options['to'])) {
    print json_encode(["status" => "SUCCESS", "msg" => "[" . __FILE__ . "] Using local copy: '" . $options['to'] . "'"]);
    exit(0);
}
try {
    // Get S3 client
    $s3 = S3Client::factory();
    // Download and Save object to a local file.
    $s3->getObject(array('Bucket' => $options['bucket'], 'Key' => $options['file'], 'SaveAs' => $options['to']));
    // Print JSON error output
    print json_encode(["status" => "SUCCESS", "msg" => "[" . __FILE__ . "] Download '" . $options['bucket'] . "/" . $options['file'] . "' successful !"]);
} catch (Exception $e) {
    $err = "Unable to get '" . $options['bucket'] . "/" . $options['file'] . "' file from S3 ! " . $e->getMessage();
    // Print JSON error output