Uploaded image for project: 'Brooklyn'
  1. Brooklyn
  2. BROOKLYN-565

brooklyn:object with nested DSL inside list is not resolved

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • None

    Description

      When using $brooklyn:object with a nested DSL expression that is contained within a list, it does not resolve the nested DSL expression.

      This is because it thinks that deferred-evaluation is not necessary. It constructs the object immediately - we end up with a DSL object in the list rather than the resolved value.

      The workaround is to include deferred: true inside the brooklyn object.

      The problem does not happen if there are any other top-level values in brooklyn.fields that are DSL expressions (it realises then that it must defer the evaluation).

      This is demonstrated by adding the following tests to ObjectsYamlTest:

          @Test
          public void testFieldOfTypeListAsDeferredSuppliersExplicitlyDeferred() throws Exception {
              // Using explicit `deferred: true`
              Entity testEntity = setupAndCheckTestEntityInBasicYamlWith(
                  "  brooklyn.config:",
                  "    mystring: myval",
                  "    myint: 123",
                  "    test.confObject:",
                  "      $brooklyn:object:",
                  "        type: "+ObjectsYamlTest.class.getName()+"$TestObject",
                  "        deferred: true",
                  "        object.fields:",
                  "          list: ",
                  "          - $brooklyn:config(\"mystring\")");
      
              TestObject testObject = (TestObject) testEntity.getConfig(TestEntity.CONF_OBJECT);
              Assert.assertEquals(testObject.getList(), ImmutableList.of("myval"));
          }
          
          // Fails if don't include `deferred: true`
          // see {@link #testFieldOfTypeListAsDeferredSuppliersExplicitlyDeferred()}
          @Test(groups="Broken")
          public void testFieldOfTypeListAsDeferredSuppliers() throws Exception {
              // should defer evaluation automatically, and resolve config
              Entity testEntity = setupAndCheckTestEntityInBasicYamlWith(
                  "  brooklyn.config:",
                  "    mystring: myval",
                  "    myint: 123",
                  "    test.confObject:",
                  "      $brooklyn:object:",
                  "        type: "+ObjectsYamlTest.class.getName()+"$TestObject",
                  "        object.fields:",
                  "          list: ",
                  "          - $brooklyn:config(\"mystring\")");
      
              TestObject testObject = (TestObject) testEntity.getConfig(TestEntity.CONF_OBJECT);
              Assert.assertEquals(testObject.getList(), ImmutableList.of("myval"));
          }
      

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              aled.sage Aled Sage
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: