App-Oozie

 view release on metacpan or  search on metacpan

lib/App/Oozie/Deploy/Validate/Oozie.pm  view on Meta::CPAN

package App::Oozie::Deploy::Validate::Oozie;

use 5.014;
use strict;
use warnings;

our $VERSION = '0.020'; # VERSION

use namespace::autoclean -except => [qw/_options_data _options_config/];

use App::Oozie::Types::Common qw( IsExecutable );
use IPC::Cmd ();
use Moo;
use MooX::Options;
use Types::Standard qw( Num );

with qw(
    App::Oozie::Role::Log
    App::Oozie::Role::Fields::Generic
);

has oozie_cli => (
    is       => 'rw',
    isa      => IsExecutable,
    required => 1,
);

has oozie_uri => (
    is       => 'rw',
    required => 1,
);

sub validate {
    my $self = shift;
    my $oozie_xmlfile = shift || die 'No xml specified!';

    if ( ! -e $oozie_xmlfile ) {
        die "Not a file: $oozie_xmlfile";
    }

    my($validation_errors, $total_errors);

    $self->logger->info(
        sprintf 'Oozie validate for %s',
                $oozie_xmlfile,
    );

    my $oozie_uri = $self->oozie_uri;
    my $command   = [
        $self->oozie_cli,
        validate => $oozie_xmlfile,
    ];

    my($ok, $err, $full_buf, $stdout_buff, $stderr_buff);
    EXEC_VALIDATE: {
        # At least Oozie v4.1 does not seem to support an `-oozie` parameter
        # In the validate sub command args, hence the need to set the env var.
        #
        local $ENV{OOZIE_URL} = $oozie_uri if $oozie_uri;
        if ( $self->verbose && $oozie_uri ) {
            $self->logger->debug(
                sprintf 'Overriding the env var OOZIE_URL for validation only: %s',
                        $oozie_uri,
            );
        }
        ( $ok, $err, $full_buf, $stdout_buff, $stderr_buff ) = IPC::Cmd::run(
            command => $command,
            verbose => $self->verbose,
            timeout => $self->timeout,



( run in 0.595 second using v1.01-cache-2.11-cpan-56fb94df46f )