Skip to content

Commit

Permalink
Strip out all references to derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
jrha committed Sep 16, 2024
1 parent f544f15 commit c553c02
Show file tree
Hide file tree
Showing 11 changed files with 105 additions and 145 deletions.
20 changes: 2 additions & 18 deletions src/main/perl/CacheManager/Element.pm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ EDG::WP4::CCM::CacheManager::Element - Element class
$name = $element->getName();
$path = $element->getPath()
$type = $element->getType();
$derivation = $element->getDerivation();
$checksum = $element->getChecksum();
$description = $element->getDescription();
$value = $element->getValue();
Expand Down Expand Up @@ -86,7 +85,6 @@ sub new
$self->{EID} = undef;
$self->{PATH} = undef; # should be a Path object
$self->{TYPE} = undef; # should a valid TYPE constant)
$self->{DERIVATION} = undef;
$self->{CHECKSUM} = undef;
$self->{DESCRIPTION} = undef;
$self->{VALUE} = undef;
Expand Down Expand Up @@ -333,18 +331,6 @@ sub getType
return $self->{TYPE};
}

=item getDerivation()
Returns the element's derivation
=cut

sub getDerivation
{
my $self = shift;
return $self->{DERIVATION};
}

=item getChecksum()
Returns the element's checksum (that is, MD5 digest)
Expand Down Expand Up @@ -660,14 +646,12 @@ sub _read_metadata
return;
}

foreach my $md (qw(TYPE DERIVATION CHECKSUM DESCRIPTION)) {
foreach my $md (qw(TYPE CHECKSUM DESCRIPTION)) {
my $val = $hashref->{$keys->{$md}};
if (defined($val)) {
$self->{$md} = $val;
} elsif ($md eq 'DESCRIPTION' || $md eq 'DERIVATION') {
} elsif ($md eq 'DESCRIPTION') {
# metadata attribute "description" is optional
# TODO: metadata attribute "derivation" should not be optional
# but eg none of the JSONProfile have it
$self->{$md} = "";
} else {
throw_error("failed to read element's $md eid $self->{EID}");
Expand Down
4 changes: 2 additions & 2 deletions src/main/perl/CacheManager/Encode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Readonly::Hash our %NAME_TYPE_MAP => {

# sorted names to compute pack'ed values for
# using offset based on index in this array
Readonly::Array our @EIDS_PACK => qw(VALUE TYPE DERIVATION CHECKSUM DESCRIPTION);
Readonly::Array our @EIDS_PACK => qw(VALUE TYPE CHECKSUM DESCRIPTION);

# DB filenames (typically in profilepath)
Readonly our $PATH2EID => 'path2eid';
Expand Down Expand Up @@ -144,7 +144,7 @@ sub decode_eid
=item encode_eids
Given C<eid>, return the keys of the tie'ed DB hashref
for C<VALUE>, C<TYPE>, C<DERIVATION>, C<CHECKSUM> and C<DESCRIPTION>
for C<VALUE>, C<TYPE>, C<CHECKSUM> and C<DESCRIPTION>
as used in the C<eid2data> DB.
=cut
Expand Down
2 changes: 1 addition & 1 deletion src/main/perl/CacheManager/Resource.pm
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ sub new
my $self = $class->SUPER::new(@_);

# check that element it is really a resource
if (!$self->isResource()) {
if (defined $self && !$self->isResource()) {
throw_error("element is not of type Resource");
return ();
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/perl/Fetch/ProfileCache.pm
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ sub AddPath
# store attributes
my $t = defined $tree->{USERTYPE} ? $tree->{USERTYPE} : $type;
$eid2data->{$eids->{TYPE}} = $t;
foreach my $md (qw(DERIVATION CHECKSUM DECRIPTION)) {
foreach my $md (qw(CHECKSUM DECRIPTION)) {
$eid2data->{$eids->{$md}} = $tree->{$md} if (defined $tree->{$md});
}
}
Expand Down
1 change: 0 additions & 1 deletion src/main/perl/Fetch/XMLPanProfile.pm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use constant INTERPRETERS => {

use constant VALID_ATTRIBUTES => {
NAME => 1,
DERIVATION => 1,
CHECKSUM => 1,
ACL => 1,
ENCODING => 1,
Expand Down
4 changes: 2 additions & 2 deletions src/test/perl/cli.t
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ like($txt,
"dumpdb output path2eid");
# \0 separated list of subpaths
like($txt,
qr{eid2data:\n0 => a\0c\0e\n10000000 => nlist\n30000000 => 1740877ebcb53b5132e75cff986cd705\n1 => b}m,
qr{eid2data:\n0 => a\0c\0e\n10000000 => nlist\n20000000 => 1740877ebcb53b5132e75cff986cd705\n1 => b}m,
"dumpdb output eid2data");
like($txt,
qr{path2eid and eid2data combined:\n/ \(0\) =>\n V: a\0c\0e\n T: nlist\n D: <undef>\n C: 1740877ebcb53b5132e75cff986cd705\n D: <undef>\n/a \(1\) =>\n},
qr{path2eid and eid2data combined:\n/ \(0\) =>\n V: a\0c\0e\n T: nlist\n C: 1740877ebcb53b5132e75cff986cd705\n D: <undef>\n/a \(1\) =>\n},
"dumpdb ouptut combined path2eid eid2data");
diag $txt;

Expand Down
47 changes: 17 additions & 30 deletions src/test/perl/element.t
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ sub gen_dbm ($$) {

my ($cache_dir, $profile) = @_;
my (%hash);
my ($key, $val, $active);
my ($derivation);
my ($key, $val, $type, $active);

# remove previous cache dir

Expand Down Expand Up @@ -62,46 +61,39 @@ sub gen_dbm ($$) {
&O_RDWR|&O_CREAT, 0644) or return();
# value
$key = 0x00000001;
$hash{pack("L", $key)} = "a string";
$val = "a string";
$hash{pack("L", $key)} = $val;
# type
$key = 0x10000001;
$hash{pack("L", $key)} = "string";
# derivation
$key = 0x20000001;
$derivation = "lxplus.tpl,hardware.tpl,lxplust_025.tpl";
$hash{pack("L", $key)} = $derivation;
$type = "string";
$hash{pack("L", $key)} = $type;
# checksum
$key = 0x30000001;
$hash{pack("L", $key)} = md5_hex($derivation);
$key = 0x20000001;
$hash{pack("L", $key)} = md5_hex("$val|$type");
# description
$key = 0x40000001;
$key = 0x30000001;
$hash{pack("L", $key)} = "an example of string";

# value
$key = 0x00000002;
$hash{pack("L", $key)} = "a list";
$val = "a list";
$hash{pack("L", $key)} = $val;
# type
$key = 0x10000002;
$hash{pack("L", $key)} = "list";
# derivation
$key = 0x20000002;
$derivation = "lxplus.tpl,hardware.tpl,lxplust_025.tpl";
$hash{pack("L", $key)} = $derivation;
$type = "list";
$hash{pack("L", $key)} = $type;
# checksum
$key = 0x30000002;
$hash{pack("L", $key)} = md5_hex($derivation);
$key = 0x20000002;
$hash{pack("L", $key)} = md5_hex("$val|$type");
# description
$key = 0x40000002;
$key = 0x30000002;
$hash{pack("L", $key)} = "an example of list";

untie(%hash);

return (1);

}

my ($element, $property, $resource, $path);
my ($type, $derivation, $checksum, $description, $value);
my ($type, $checksum, $description, $value);
my ($string);

my ($cm, $config, $cache_dir, $profile);
Expand Down Expand Up @@ -161,14 +153,9 @@ is($string, "/path/to/property", "Element->getPath()");
$type = $element->getType();
is($type, EDG::WP4::CCM::CacheManager::Element->STRING, "Element->getType()" );

# test getDerivation()
$derivation = $element->getDerivation();
is($derivation, "lxplus.tpl,hardware.tpl,lxplust_025.tpl",
"Element->getDerivation()");

# test getChecksum()
$checksum = $element->getChecksum();
is($checksum, md5_hex($derivation), "Element->getChecksum()");
is($checksum, md5_hex("a string|string"), "Element->getChecksum()");

# test getDescription()
$description = $element->getDescription();
Expand Down
7 changes: 3 additions & 4 deletions src/test/perl/encode.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ foreach my $name (sort keys %map) {
is(type_from_name('something'), UNDEFINED, "type_from_name returns UNDEFINED");

is_deeply(\@EIDS_PACK,
[qw(VALUE TYPE DERIVATION CHECKSUM DESCRIPTION)],
[qw(VALUE TYPE CHECKSUM DESCRIPTION)],
"EIDS_PACK array");

is_deeply(encode_eids(123), {
VALUE => pack('L', 123),
TYPE => pack('L', 1 << 28 | 123),
DERIVATION => pack('L', 2 << 28 | 123),
CHECKSUM => pack('L', 3 << 28 | 123),
DESCRIPTION => pack('L', 4 << 28 | 123),
CHECKSUM => pack('L', 2 << 28 | 123),
DESCRIPTION => pack('L', 3 << 28 | 123),
}, "encode_eids for id 123");

is(decode_eid(encode_eids(123)->{VALUE}), 123, "decode encoded eid returns original");
Expand Down
30 changes: 13 additions & 17 deletions src/test/perl/property.t
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ sub gen_dbm
{
my ($cache_dir, $profile) = @_;
my (%hash);
my ($key, $val, $active);
my ($derivation);
my ($key, $val, $type, $active);

# create new profile
mkdir("$cache_dir");
Expand All @@ -52,21 +51,23 @@ sub gen_dbm

tie(%hash, "DB_File", "${cache_dir}/${profile}/eid2data.db",
&O_RDWR|&O_CREAT, 0644) or return();

# value
$key = 0x00000001;
$hash{pack("L", $key)} = "a string";
$val = "a string";
$hash{pack("L", $key)} = $val;

# type
$key = 0x10000001;
$hash{pack("L", $key)} = "string";
# derivation
$key = 0x20000001;
$derivation = "lxplus.tpl,hardware.tpl,lxplust_025.tpl";
$hash{pack("L", $key)} = $derivation;
$type = "string";
$hash{pack("L", $key)} = $type;

# checksum
$key = 0x30000001;
$hash{pack("L", $key)} = md5_hex($derivation);
$key = 0x20000001;
$hash{pack("L", $key)} = md5_hex("$val|$type");

# description
$key = 0x40000001;
$key = 0x30000001;
$hash{pack("L", $key)} = "an example of string";
untie(%hash);

Expand Down Expand Up @@ -102,13 +103,8 @@ is($getpath->toString(), "/path/to/element", "property Element->getPath()");
# test getType()
is($property->getType(), EDG::WP4::CCM::CacheManager::Element->STRING, "property Element->getType() is STRING");

# test getDerivation()
my $derivation = $property->getDerivation();
is($derivation, "lxplus.tpl,hardware.tpl,lxplust_025.tpl",
"property Element->getDerivation()");

# test getChecksum()
is($property->getChecksum(), md5_hex($derivation), "property Element->getChecksum()");
is($property->getChecksum(), md5_hex("a string|string"), "property Element->getChecksum()");

# test getDescription()
is($property->getDescription(), "an example of string", "property Element->getDescription()");
Expand Down
Loading

0 comments on commit c553c02

Please sign in to comment.