Change class member once it is loaded in puppet - manifest

Here's the scenario: I'm using the same 3rd party parameterized class in 2 different places in my manifests.
I don't know where the 3rd party class will be included first and in both places, I need to pass a different parameter to the class.
Right now, I only include the class in both places since I don't know how to resolve my situation.
Any help appreciated :)
Thanks

You can only declare a class once when you are using the syntax with Parameters.
include classname
can be used multiple times, but
class { 'classname':
parameter => 'yada',
}
only once.

Related

Grails: Where do I handle a domain class property that can have two different representations?

I am programming a way of displaying products that I get from a MySQL database based on user input. My products have a property (size) that can either be represented by a string, by an object of the type Size (another domain class holding three float-values) or be missing alltogether.
Currently my Product-Class has one property for each representation, both of which are nullable. In my view I have one specific place where this property should be displayed.
Now my question is, where do I handle the problem of determining which representation I have for a specific object?
I would be able to include an if-condition in my gsp-template but that seems to be bad practice.
I would be able to have the service that does the query handle the results and build a single size-property to pass to the template but that doesn't seem right either.
Is the problem in my database design?
Do I have to change my domain-model?
I am sorry for the very general question, I can definitely change that once I know where exactly I need to change something. Thanks a lot already!
One way to solve your problem would be to use an additional transient field that would be used in your views, but would not be persisted in your database.
class Product {
String sizeString
Size sizeSize
getSize() { sizeString ?: sizeSize.toString() }
static transients = ['size']
}

Why #PetiteInject cannot inject service in DecoraManager?

I have a DecoraManager implementation : AppDecoraManager, and want to inject a service e.g.: FooService as:
#PetiteInject
FooService fooService;
When resolveDecorator() is called I want to use fooService to determine some parameters, but it has null value.
What could be the reason for this, and how could I resolve it?
DecoraManager is created by the servlet container, in DecoraServletFilter.
At the moment, there is no integration with existing Petite IOC, so you have to do the following:
First, you need to have a public static reference to PetiteContainer. Store it during the creation of container, for example.
Override createDecoraManager() in your implementation
Use PetiteContainer.wire(this) in your implementation of DecoraManager.
That is the only way to do so, so far.
The alternative would be this:
Register DecoraManager as #PetiteBean.
Again, get the static reference to PetiteContainer
In createDecoraManager use PetiteContainer.get() to get the instance.
In the first example, DecoraManager gets just wired; in the second example, it gets stored in Petite container, too.

How to write a wrapper class / Override configuration in pre existing Puppet Class

I would like to override the values of another class in another Puppet Modules. Please help me by suggesting ways.
Existing Class : ( Module Name : MySQL )
class mysql::server (
$config_file = $mysql::params::config_file,
$includedir = $mysql::params::includedir)
{
My Code Logics
}
My Current Class : ( Module Name : Profiles )
Class profiles::mysql () {
class { '::mysql::server':
config_file => '/opt/arunraj',
includedir => true
}
}
When i am doing like above, I am getting duplicate class declaration error. Which is a best way to override a values between two classes
In the first place, your example code is incomplete. You present the definitions of classes mysql::server and profiles::mysql, and the latter contains a resource-style declaration of class mysql::server, but you say nothing about the one or more other declarations of class mysql::server that the given one collides with. What you actually presented is not enough to produce the error you describe.
Note also that using resource-style class declarations is usually poor form, especially for declaring public classes of any module, and most especially for declaring classes belonging to a different module than the one in which the declaration appears. The reasons are a bit technical, but to a large extent they boil down to the risk of eliciting exactly the kind of error you encountered. That happens whenever Puppet evaluates a resource-style declaration of a class for which a declaration (in any style) has already been evaluated, because class parameter values are bound as part of evaluating the first-encountered declaration.
The best way to customize class parameter values is to rely on automatic data binding (Hiera) to bind values to those parameters in the first place. If you have an oddball machine that needs different parameter values then you set them at a higher-priority level of your data hierarchy than the one from which the ordinary values come, and which is scoped narrowly enough to avoid affecting machines that should have the ordinary parameters.
Moreover, to avoid the kind of error you describe, you should also be certain everywhere to use only include-like declarations for any class that might be declared more than once (i.e. any public one, and some private ones). That goes hand in hand with automatic binding because if you don't use resource-like declarations then automatic data binding is your best available means for customizing class parameter values. The classical include-style declaration is via the include function itself, but the require, contain, and hiera_include functions also provide include-style declarations (with various differences in semantics). If you're using an ENC to declare classes then it might produce either style.

Adding generator functionality to a Python/C class

I have built a class in C with the Python/C API. I now have a requirement to iterate over the data items in the C blob. Returning a PyList is undesirable as length is >50K. Is there a way to provide generator-like functionality?
My one solution is to wrap the class in another pure python class and write the generator function at that level. Is there another way?
According to PEP 234, all you need to do is implement the tp_iternext slot in your python C class.

Actionscript 3 - passing custom class as parameter to custom class where parameter class not constructed

Hi and thanks in advance,
I have a custom class being constructed from my main class. In the custom class it has another custom class that is passed in as a parameter. I would like to strictly type the parameter variable but when I do, 'the type is not a compile type constant etc'.
This, I understand, is because the custom class used as a parameter has not yet been constructed.
It all works when I use the variable type ( * ) to type the parameter.
I suspect this is a design flaw, in that I am using an incorrect design pattern. It is actually hand-me-down code, having received a large project from someone else who is not entirely familiar with oop concepts and design patterns.
I have considered using a dummy constructor for the parametered class in my main class but the passed in class also takes a custom class (itself with a parametered constructor). I am considering using ... (rest) so that the custom classes' parameters are optional.
Is there any other way to control the order of construction of classes? Would the rest variables work?
Thanks
(edit)
in main.as within the constructor or another function
var parameter1:customclass2;
customclass1(parameter1);
in customclass1 constructor:
public function customclass1(parameter1:customclass2)
{
....
Flash complains that the compiled type cannot be found when I use the data type customclass 2 in the paramater. It does not complain when I use the variable data type * or leave out the data type (which then defaults to * anyway). I reason that this is because customclass2 has not yet been constructed and is therefore not available to the compiler.
Alternatively, I have not added the path of customclass2 to the compiler but I am fairly certain I have ruled this out.
There are over 10,000 lines of code and the whole thing works very well. I am rewriting simply to optimise for the compiler - strict data typing, error handling, etc. If I find a situation where inheritance etc is available as an option then I'll use it but it is already divided into classes (at least in the main part). It is simply for my own peace of mind and to maintain a policy of strict data typing so that compiler optimization works more efficiently.
thnx
I have not added the path of customclass2 to the compiler but I am fairly certain I have ruled this out.
So if you don't have the class written anywhere what can the compiler do ? It is going to choke of course. You either have to write the CustomClass class file or just use "thing:Object" or "thing:Asteriks". It's not going to complain when you use the "*" class type because it could be anything an array, string, a previously declared class. But when you specify something that doesn't exists it will just choke, regardless of the order the parameters are declared in.