# Test a simple dynamic bundlesequnece pattern
# Classification Bundles listed in bundlesequence
# Bundle list built from array
# Bundles policy defined in separate file
# include only app files neaded based on list built from array
# Lexicly sorted bundles activated with methods promise
body common control
{
    bundlesequence => { "classify", "map_role_bundles", "go" };
}

bundle common classify
{
  vars:
      "variable" string => "vmware";

  classes:
      "group_one"
        expression => strcmp($(variable), "vmware"),
        comment => "Highest level classification, other classes depend on this.";
}

bundle common map_role_bundles
{
  vars:
    # Define bundles
    any::
      "role[app00_zero]"
        string => "$(this.promise_dirname)/apps/app00_zero.cf.sub",
        comment =>
          "Roles are based on groups. Roles
                    map to bundles. Bundles are defined in a specific file.";

      "role[app_zero]"
        string => "$(this.promise_dirname)/apps/app_zero.cf.sub",
        comment =>
          "Roles are based on groups. Roles
                    map to bundles. Bundles are defined in a specific file.";
    group_one::
      "role[app_one]"
        string => "$(this.promise_dirname)/apps/app_one.cf.sub",
        comment =>
          "Roles are based on groups. Roles
                    map to bundles. Bundles are defined in a specific file.";
    group_none::
      "role[app_two]"
        string => "$(this.promise_dirname)/apps/app_two.cf.sub";

    any::
      "inputs" slist => getvalues(role);
      "bundles" slist => getindices(role);
}

bundle agent go
{
  vars:
      "bundles" slist => { @(map_role_bundles.bundles) };
      "sorted_bundles" slist => sort(bundles, "lex");

  methods:
      "$(sorted_bundles)" usebundle => $(sorted_bundles);
}

body file control
{
    inputs => { @(map_role_bundles.inputs) };
}
