Home > Cloud Cruiser 3 > Setting Up Collection > Universal collectors > XML Collector > Mapping data to Cloud Cruiser

Mapping data to Cloud Cruiser

XML feed configuration

Elements from the XML document can be mapped to CC Record fields as output at any level in the document. Initial input is the document node or root element. A set of child elements can be mapped to output by providing an XPath expression for the nodes of interest. Each matching node is then processed according to output mappings specific to the expression results. By default, identifiers accumulate in the record, but resources do not.

Recursive processing

The parent output record is cloned and resources dropped before processing each child node. The recursive nature of the document is supported by XPathOutputMapping, which is also recursive and supports nesting expressions and mappings. In this way, identifiers can be accumulated for the context of a node containing usage data for one or more resources.

Variables

Input can be mapped to a mutable variable instead of an output field. These variables can then be specified in place of a literal input field where necessary. To specify a variable as input, set the input name to # followed by the variable name.

Mapping output

Outputs correspond to a CC Record field and typically name an element as the input. You can use a dot notation for input names to pull nested element data. For example, company.name as an input would pull the value of a name child element of a company child element of the current node.

When using expressions to match nodes, the inputs are relative to the matching nodes. This presents a special case where the value of the matching node is needed as input and there is no attribute or child element name to provide as input. In these cases, specify / as the input. This will pull the current node’s value. To specify an attribute value as input, prefix the attribute name with @. For example, company.@name as an input would pull the value of the attribute name from the child element company .

Mapping recursive elements

You can map most child elements of a collected entity with a single XPathOutputMapping bean at the entity level, with each element becoming a resource or identifier together in a single CC Record. But this approach breaks down when there are multiple instances of an element at the same level. In this case only the first such element is mapped to the output record.

For example, in the following data sample, the disks element contains two instances of its child element disk . The name and size of only the first disk are written to the output record for the node and the second is lost.

To capture multiple elements at the same level in your collector output, map that element to its own output record instead, as in Mapping sample. This code maps three identifiers and two resources to an output record for each subscription, plus an identifier and a resource to an output record for each disk. That produces the three CC Records in Output sample, capturing both disks.

Data sample

In the following example, the customer data can be mapped into identifiers that are included on all output records for the document. The service node and children can be mapped recursively so that the vmName identifier appears in all records having service resources.

<subscription>
  <customer>
    <name>ABC Corp</name>
  </customer>
  <service>
    <vmName>9283479</vmName>
    <compute>
      <osType>Windows 2008 R2</osType>
      <ramGB>4</ramGB>
      <cpuCount>2</cpuCount>
    </compute>
    <disks>
      <disk>
        <name>Disk‐1</name>
        <sizeGB>400</sizeGB>
      </disk>
      <disk>
        <name>Disk‐2</name>
        <sizeGB>2000</sizeGB>
      </disk>
    </disks>
  </service>
</subscription>

Mapping sample

<bean class="com.cloudcruiser.batch.collect.XPathOutputMapping">
  <property name="outputs">
    <list>
      <bean class="com.cloudcruiser.batch.collect.OutputField">
        <property name="cctype" value="IDENTIFIER"/>
        <property name="input" value="customer.name"/>
        <property name="label" value="customer"/>
      </bean>
      <bean class="com.cloudcruiser.batch.collect.OutputField">
        <property name="cctype" value="IDENTIFIER"/>
        <property name="input" value="service.vmName"/>
        <property name="label" value="vmName"/>
      </bean>
      <bean class="com.cloudcruiser.batch.collect.OutputField">
        <property name="cctype" value="IDENTIFIER"/>
        <property name="input" value="service.compute.osType"/>
        <property name="label" value="osType"/>
      </bean>
      <bean class="com.cloudcruiser.batch.collect.OutputField">
        <property name="cctype" value="RESOURCE"/>
        <property name="input" value="service.compute.ramGB"/>
        <property name="label" value="ramGB"/>
      </bean>
      <bean class="com.cloudcruiser.batch.collect.OutputField">
        <property name="cctype" value="RESOURCE"/>
        <property name="input" value="service.compute.cpuCount"/>
        <property name="label" value="cpuCount"/>
      </bean>
    </list>
  </property>
  <property name="xpathOutputs">
    <bean class="com.cloudcruiser.batch.collect.XPathOutputMapping">
      <property name="xpathExpression" value="/service/disks/disk"/>
      <property name="outputs">
        <list>
          <bean class="com.cloudcruiser.batch.collect.OutputField">
            <property name="cctype" value="IDENTIFIER"/>
            <property name="input" value="name"/>
            <property name="label" value="diskName"/>
          </bean>
          <bean class="com.cloudcruiser.batch.collect.OutputField">
            <property name="cctype" value="RESOURCE"/>
            <property name="input" value="sizeGB"/>
            <property name="label" value="diskGB"/>
          </bean>
        </list>
      </property>
    </bean>
  </property>
</bean>

Output sample

The following CSV, with dates and times omitted to save space, represents the output from the previous data sample with the previous mapping sample:

,,,,3,customer,ABC Corp,vmName,9283479,osType,Windows 2008 R2,2,ramGB,4,cpuCount,2
,,,,4,customer,ABC Corp,vmName,9283479,osType,Windows 2008 R2,diskName,Disk-1,1,diskGB,400
,,,,4,customer,ABC Corp,vmName,9283479,osType,Windows 2008 R2,diskName,Disk-2,1,diskGB,2000
Last modified

Tags

This page has no custom tags.

Classifications

This page has no classifications.
© Copyright 2018 Hewlett Packard Enterprise Development LP