Properties-default-sources construct 编辑
Properties-default-sources construct
The properties-default-sources construct is analogous to the parameters-default-sources construct. While the parameters-default-sources construct allows the reuse of existing parameters (from other StyleBooks) in a StyleBook, properties-default-sources construct allows the user to specify properties of a component based on existing sources.
The properties of a component may be distributed across various sections of the StyleBook. For example, the properties may come from object parameters, substitutions that return an object, properties of other components, or outputs of other components. In such cases, you need to redefine the properties that occur in other sections of the StyleBook in the definition of the component. Clearly, this is redundant and can lead to errors. To deal with this problem, properties-default-sources construct can be used. The properties-default-sources construct is a list where each item identifies a source for some properties of the component.
For example, consider a component that creates an lbvserver
configuration. This component defines the properties of the lbvserver
as follows.
parameters:
-
name: lb
type: ns::lbvserver
components:
-
name: lb-comp
type: ns::lbvserver
properties:
name: $parameters.lb.name
ipv46: $parameters.lb.ipv46
port: $parameters.lb.port
servicetype: $parameters.lb.servicetype
lbmethod: $parameters.lb.lbmethod
<!--NeedCopy-->
In the above example, observe that the values for all properties defined in the components section are taken from $parameters.lb object. Though they are taken from a single source, the properties are again defined in the StyleBook. In addition, if a new sub-parameter to $parameters.lb object that is relevant to the configuration of the lbvserver
is added, you need to update the lb-comp component to add the new property that corresponds to the new sub-parameter.
To avoid redefining properties and to fetch all relevant properties of a component without explicitly list them in the properties section, properties-default-sources construct can be used. The above example can be written as follows.
parameters:
-
name: lb
type: ns::lbvserver
components:
-
name: lb-comp
type: ns::lbvserver
properties-default-sources:
- $parameters.lb
<!--NeedCopy-->
In the above example, the use of properties-default-sources construct leads to a reduction in the size of the component definition, and this allows you to concisely define a component. In addition, each time the source of the properties of the component changes, the changes are reflected automatically. For example, when a new property, say persistencetype
, is added in the $parameters.lb object, this property is added to the configuration of lb-comp by default since persistencetype
is a property of lbvserver
. Thus, properties-default-sources construct provides a dynamic interface to define the components without worrying about changes happening to the sources of the properties of the component.
Computation of the Properties of the Component
This section discusses on how the properties are fetched if properties-default-sources construct is used in a component. First, the StyleBooks compiler identifies the list of properties for a component based on its type (in the above example, lbvserver
.) Next, the compiler fetches these properties from the multiple sources in the order that they are defined (in properties-default-sources section of the component). If a property exists in multiple sources then the property appearing in the last source takes precedence over others. Finally, a property fetched by using properties-default-sources construct can be overridden in the properties section of the component. It is important to note that the definition of a component section at least have a properties-default-sources section or a properties section. It may have both.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论