perfSONAR_PS::Services::MP::Config::Schedule - Configuration module for the


perfSONAR_PS-Services-PingER documentation Contained in the perfSONAR_PS-Services-PingER distribution.

Index


Code Index:

NAME

Top

perfSONAR_PS::Services::MP::Config::Schedule - Configuration module for the support of scheduled tests for MPs

DESCRIPTION

Top

The purpose of this module separate implementation of parsing configuration files for MPs so that they provide a consistent interface to allow the perfSONAR_PS::Services::MP::Scheduler class to determine the appropriate periodicity and offset times for running measurements by an MP.

SYNOPSIS

Top

  # create the configuration object
  my $schedule = perfSONAR_PS::Services::MP::Config::Schedule->new();

  # set the configuration file to use (note that the definitions of how to
  # parse for the appropriate test periods, and offset times etc for the 
  # individual tests should be defined in an inherited class.
  $schedule->configFile( 'some-config-file-path' ); 
  if ( $schedule->load() == 0 ) {

	# get a list of the test id's to run
	my @testids = $schedule->getAllTestIds();

	# determine the period of time from now until the next test should run
	# this will automatically determine the periodicity and conduct
	# a random on the offset to calculate the appropriate time.
	my $time = $schedule->getTestTimeFromNow( $testids[0] );

    print "The next test for '$testid' will run in $time seconds from now.";

  } else {

	print "Something went wrong with parsing file '" . $schedule->configFile() . "'\n";
    return -1;

  }

API

Top

This module exposes the following methods.

new

instantiate a new config object

configFile

accessor/mutator method for the configuration file

config

accessor/mutator method for the configuration

load( $file )

Load and parse the config file $file. Should be overridden by inheriting class.

Returns 0 = everythign okay -1 = something failed

store( $file )

Load and parse the config file $file. Should be overridden by inheriting class.

Returns 0 = everythign okay -1 = something failed

getAllTestIds()

Returns a list of all the testids that have been parsed.

getTestById( $testid )

Returns the test info hash of the test with id $testid (key of hash). The returned hash should be in a key/value format suitable for the configuration tool to use.

getTestPeriodById( $testid )

Returns the test period defined for test id '$testid'.

getTestOffsetById( $testid )

Returns the test offset defined for test id '$testid'.

getTestOffsetTypeById( $testid )

Returns the test offset type defined for test id '$testid'.

getTextNextTimeFromNow( $testid )

Determines the amonut of time from now until the next test for $testid should start.

Returns n = seconds til next test undef = testid does not exist

SEE ALSO

Top

perfSONAR_PS::Services::MP::Scheduler, perfSONAR_PS::Services::Config::PingER, perfSONAR_PS::Services::MP::Agent::Base,

To join the 'perfSONAR-PS' mailing list, please visit:

  https://mail.internet2.edu/wws/info/i2-perfsonar

The perfSONAR-PS subversion repository is located at:

  https://svn.internet2.edu/svn/perfSONAR-PS 

Questions and comments can be directed to the author, or the mailing list.

VERSION

Top

$Id: Base.pm 524 2007-09-05 17:35:50Z aaron $

AUTHOR

Top

Yee-Ting Li, ytl@slac.stanford.edu

LICENSE

Top

You should have received a copy of the Internet2 Intellectual Property Framework along with this software. If not, see <http://www.internet2.edu/membership/ip.html>

COPYRIGHT

Top


perfSONAR_PS-Services-PingER documentation Contained in the perfSONAR_PS-Services-PingER distribution.
package perfSONAR_PS::Services::MP::Config::Schedule;

use version; our $VERSION = 0.09; 

use Log::Log4perl qw(get_logger);
our $logger = Log::Log4perl::get_logger( 'perfSONAR_PS::Services::MP::Agent::Ping' );

use strict;

sub new
{
  my ( $package ) = @_; 
  my %hash = ();
  
  $hash{"CONFFILE"} = undef;	# config file path
  $hash{"CONF"} = undef;		# internal representation of schedule

  bless \%hash => $package;
}

sub configFile
{
	my $self = shift;
	my $file = shift;
	if ( $file ) {
		$self->{CONFFILE} = $file;
	}
	return $self->{CONFFILE};
}


sub config
{
	my $self = shift;
	my $conf = shift;
	if ( $conf ) {
		$self->{CONF} = $conf;
	}
	return $self->{CONF};
}


sub load
{
	my $self = shift;
	$logger->logdie( "load() should be overridden.");
	return -1;
}


sub store
{
	my $self = shift;
	$logger->logdie( "store() should be overridden.");
	return -1;
}


sub getAllTestIds
{
	my $self = shift;
	return keys %{$self->config()};
}


sub getTestById
{
	my $self = shift;
	my $testid = shift;
	
	if ( ! defined $testid || $testid eq '' ) {
		$logger->logdie( "Missing parameter 'testid'");
	} else {
		if( ! exists $self->config()->{$testid} ) {
			$logger->fatal( "unique test with id '$testid' does not exist in ". $self->configFile() );
			return undef;
		}
			
		return $self->config()->{$testid};
	}
	
}

sub getTestPeriodById
{
	my $self = shift;
	my $testid = shift;
	
	return undef
		unless defined $testid;

	$logger->fatal( "unique test with id '$testid' does not define a test period.")
		unless exists $self->config()->{$testid}->{'measurementPeriod'};

	return $self->config()->{$testid}->{'measurementPeriod'};
}

sub getTestOffsetById
{
	my $self = shift;
	my $testid = shift;
	
	return undef
		unless defined $testid;

	# return zero if there is no offset defined
	if( ! exists $self->config()->{$testid}->{'measurementOffset'} ) {
		return 0;
	}
	# otherwise return the value
	return $self->config()->{$testid}->{'measurementOffset'};
}

sub getTestOffsetTypeById
{
	my $self = shift;
	my $testid = shift;
	
	return undef
		unless defined $testid;

	# return zero if there is no offset defined
	if( ! exists $self->config()->{$testid}->{'measurementOffsetType'} ) {
		return 'Flat';
	}
	# otherwise return the value
	# TODO: Validate, enumerate types (Flat, Gaussian etc)
	return $self->config()->{$testid}->{'measurementOffsetType'};
}


sub getTestNextTimeFromNowById
{
	my $self = shift;
	my $testid = shift;

	return undef
		unless defined $testid && exists $self->config()->{$testid};
		
	# get the test period of the first testid in the array
	# don't bother doing the rest if it doesn't exist
	my $testing_period = $self->getTestPeriodById( $testid );
	return undef
		unless $testing_period;

    # get the test offset value of the first testid in the array
    my $testing_offset = $self->getTestOffsetById( $testid );
	return $testing_period
		unless $testing_offset;

    # get the test offset type of the first testid in the array
    my $testing_offset_type = $self->getTestOffsetTypeById( $testid );


    # to determine the next time that a testid should be run
    # $logger->debug( "OFFSET: " . $testing_offset_type . " " . $testing_offset );
    my $offset = undef;
    if ( $testing_offset_type eq 'Gausssian' ) {
	
	
	} else {
		
		# assume a flat random distro or plus or minus the offset
		$offset = rand( 2* $testing_offset ) - $testing_offset;

	}
	
	return $testing_period + $offset;
}


1;