Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

best practices to managing and loading properties

I am looking forward to know some best approaches to manage properties files.

We have a set of devices (say N). Each of these devices has certain properties. e.g. Device A has properties

A.a11=valuea11

A.a12=valuea12

.

Device B has properties

B.b11=valueb11

B.b12=valueb12 .

Apart from this they have some common properties applicable for all devices.

X.x11=valuex11

X.x12=valuex12

I am writing an automation for running some test suites on these devices. At a time, test script on run on a single device. The device name will be passed as a argument. Based on the device name, code will grab the respective properties and common properties and update the device with these properties. e.g. for device A, code will grab the A.a11, A.a12 (device A specific) and X.x11, X.x12 (common) properties and upload it to the device before running test script.

So, in code, I need to manage these properties so that only device specific and common properties will be uploaded to the device, ignoring the rest one. I am managing it like this

if ($device eq 'A') then
    upload A's properties
elsif ($device eq 'B') then
    upload B's properties
endif

upload Common (X) properties.

Managing device in this way is becoming little bit difficult as the number of devices are keep on increasing.

So I am looking forward for some other best approach to manage these properties.

like image 780
rpg Avatar asked Aug 16 '11 07:08

rpg


People also ask

What are configuration management techniques?

Configuration management is the process of monitoring the hardware and software configuration of computers and changing configurations when necessary to ensure they stay in line with IT policies. Not surprisingly, those policies typically include guidelines for security and regulatory compliance.

How do you externalize properties in mule 4?

Some people that want to externalize properties files just references properties files by absolute path in a directory outside the Mule installation directory. Another option in Mule 4 you can create a custom properties provider and implement in Java any access to Zuul or some other way to collect the properties.


1 Answers

This is a good case where v (aka traits in generalized OOP literature) will be useful.

Instead of the classical object is a class, with roles an object *does a * role.

Check out the appropriate Moose docs for way more information.

Example:

package Device::ActLikeA;
use Moose::Role;

has 'attribute' => (
    isa => string,
    is  => 'rw',
    default => 'Apple',
);

sub an_a_like_method {
    my $self = shift;

    # foo
}

1;

So now I have a role called Device::ActLikeA, what do I do with it?

Well, I can apply the role to a class, and the code and attributes defined in ActLikeA will be available in the class:

package Device::USBButterChurn;
use Moose;

does 'Device::ActLikeA';

# now has an attribute 'attribute' and a method 'an_a_like_method'
1;

You can also apply roles to individual instances of a class.

package Device;
use Moose;

has 'part_no' => (
  isa => 'Str',
  is  => 'ro',
  required => 1,
);

has 'serial' => {
  isa  => 'Str',
  is   => 'ro',
  lazy => 1,
  build => '_build_serial',
);

1;

And then main code that looks at the part and applies appropriate roles:

my @PART_MATCH = (
    [ qr/Foo/,              'Device::MetaSyntacticVariable' ],
    [ qr/^...-[^_]*[A][^-], 'Device::ActLikeA; ],
    [ qr/^...-[^_]*[B][^-], 'Device::ActLikeB; ],
# etc
);

my $parts = load_parts($config_file);

for my $part ( @$parts ) {

    my $part_no = $part->part_number();

    for my $_ (@PART_MATCH) {
        my ($match, $role) = @$_;
        $part->apply_role($role)
           if $part_no =~ /$match/;
    }

}
like image 80
daotoad Avatar answered Oct 22 '22 02:10

daotoad