Java Code Examples for org.apache.brooklyn.api.entity.EntitySpec#getParameters()
The following examples show how to use
org.apache.brooklyn.api.entity.EntitySpec#getParameters() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BrooklynComponentTemplateResolver.java From brooklyn-server with Apache License 2.0 | 6 votes |
private Map<String, ConfigKey<?>> findAllConfigKeys(EntitySpec<?> spec) { // TODO use in BasicSpecParameter to resolve ancestor config keys ? Set<Class<?>> types = MutableSet.<Class<?>>builder() .add(spec.getImplementation()) .add(spec.getType()) .addAll(spec.getAdditionalInterfaces()) .remove(null) .build(); // order above is important, respected below to take the first one defined MutableMap<String, ConfigKey<?>> result = MutableMap.copyOf(FlagUtils.findAllConfigKeys(null, types)); // put parameters atop config keys // TODO currently at this point parameters have been merged with ancestor spec parameters, // but *not* with config keys defined on the java type // see comments in BasicSpecParameter; // one way to fix would be to record in BasicSpecParameter which type fields are explicitly set // and to do a further merge here with result.remove(param.getConfigKey().getName()); // another way, probably simpler, would be to do the above result computation in BasicSpecParameter for (SpecParameter<?> param : spec.getParameters()) { result.put(param.getConfigKey().getName(), param.getConfigKey()); } return result; }
Example 2
Source File: SpecParameterUnwrappingTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testChildEntitiyHasParameters() { addCatalogItems( "brooklyn.catalog:", " id: " + SYMBOLIC_NAME, " version: " + TEST_VERSION, " itemType: entity", " item:", " type: " + ConfigEntityForTest.class.getName(), " brooklyn.children:", " - type: " + ConfigEntityForTest.class.getName(), " brooklyn.parameters:", " - simple"); EntitySpec<?> parentSpec = (EntitySpec<?>) peekSpec(); EntitySpec<?> spec = parentSpec.getChildren().get(0); List<SpecParameter<?>> params = spec.getParameters(); assertEquals(params.size(), NUM_ENTITY_DEFAULT_CONFIG_KEYS + 2, "params="+params); assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent()); assertTrue(Iterables.tryFind(params, labelEqualTo("simple")).isPresent()); }
Example 3
Source File: SpecParameterUnwrappingTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testAppSpecInheritsCatalogParameters() { addCatalogItems( "brooklyn.catalog:", " version: " + TEST_VERSION, " id: " + SYMBOLIC_NAME, " itemType: entity", " item:", " type: " + BasicApplication.class.getName(), " brooklyn.parameters:", " - simple"); final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 1; EntitySpec<? extends Application> spec = createAppSpec( "services:", "- type: " + ver(SYMBOLIC_NAME)); List<SpecParameter<?>> params = spec.getParameters(); assertEquals(params.size(), NUM_APP_DEFAULT_CONFIG_KEYS + NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT, "params="+params); assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent()); assertTrue(Iterables.tryFind(params, labelEqualTo("simple")).isPresent()); }
Example 4
Source File: SpecParameterUnwrappingTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testAppSpecInheritsCatalogRootParameters() { addCatalogItems( "brooklyn.catalog:", " id: " + SYMBOLIC_NAME, " version: " + TEST_VERSION, " itemType: entity", " item:", " type: " + BasicApplication.class.getName(), " brooklyn.parameters:", " - simple"); final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 1; EntitySpec<? extends Application> spec = createAppSpec( "services:", "- type: " + ver(SYMBOLIC_NAME)); List<SpecParameter<?>> params = spec.getParameters(); assertEquals(params.size(), NUM_APP_DEFAULT_CONFIG_KEYS + NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT, "params="+params); assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent()); assertTrue(Iterables.tryFind(params, labelEqualTo("simple")).isPresent()); }
Example 5
Source File: SpecParameterUnwrappingTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testAppSpecInheritsCatalogRootParametersWithServices() { addCatalogItems( "brooklyn.catalog:", " id: " + SYMBOLIC_NAME, " version: " + TEST_VERSION, " itemType: entity", " item:", " brooklyn.parameters:", " - simple", " services:", " - type: " + BasicApplication.class.getName()); final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 1; EntitySpec<? extends Application> spec = createAppSpec( "services:", "- type: " + ver(SYMBOLIC_NAME)); List<SpecParameter<?>> params = spec.getParameters(); assertEquals(params.size(), NUM_APP_DEFAULT_CONFIG_KEYS + NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT, "params="+params); assertTrue(Iterables.tryFind(params, nameEqualTo("simple")).isPresent()); assertTrue(Iterables.tryFind(params, labelEqualTo("simple")).isPresent()); }
Example 6
Source File: SpecParameterUnwrappingTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testUnresolvedCatalogItemParameters() { // Insert template which is not instantiatable during catalog addition due to // missing dependencies, but the spec can be created (the // dependencies are already parsed). addCatalogItems( "brooklyn.catalog:", " version: " + TEST_VERSION, " items:", " - id: " + SYMBOLIC_NAME, " itemType: template", " item:", " services:", " - type: basic-app", " - id: basic-app", " itemType: entity", " item:", " type: " + ConfigAppForTest.class.getName()); EntitySpec<? extends Application> spec = createAppSpec( "services:", "- type: " + ver(SYMBOLIC_NAME)); List<SpecParameter<?>> params = spec.getParameters(); assertEquals(params.size(), NUM_APP_DEFAULT_CONFIG_KEYS + ConfigAppForTest.NUM_CONFIG_KEYS_DEFINED_HERE, "params="+params); assertEquals(ImmutableSet.copyOf(params), ImmutableSet.copyOf(BasicSpecParameter.fromClass(mgmt(), ConfigAppForTest.class))); }
Example 7
Source File: InternalEntityFactory.java From brooklyn-server with Apache License 2.0 | 6 votes |
private void addSpecParameters(EntitySpec<?> spec, EntityDynamicType edType) { // if coming from a catalog item, parsed by CAMP, then the spec list of parameters is canonical, // the parent item has had its config keys set as parameters here with those non-inheritable // via type definition removed, so wipe those on the EDT to make sure non-inheritable ones are removed; // OTOH if item is blank, it was set as a java type, not inheriting it, // and the config keys on the dynamic type are the correct ones to use, and usually there is nothing in spec.parameters, // except what is being added programmatically. // (this logic could get confused if catalog item ID referred to some runtime-inherited context, // but those semantics should no longer be used -- https://issues.apache.org/jira/browse/BROOKLYN-445) if (Strings.isNonBlank(spec.getCatalogItemId())) { edType.clearConfigKeys(); } for (SpecParameter<?> param : spec.getParameters()) { edType.addConfigKey(param.getConfigKey()); if (param.getSensor()!=null) edType.addSensor(param.getSensor()); } }
Example 8
Source File: SpecParameterParsingTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testYamlInputsParsed() { String itemId = ver("test.inputs", "0.0.1"); addCatalogItems( "brooklyn.catalog:", " id: test.inputs", " version: 0.0.1", " itemType: entity", " item: ", " type: "+ BasicApplication.class.getName(), " brooklyn.parameters:", " - simple", " - name: explicit_name", " - name: third_input", " type: integer", " pinned: false"); EntitySpec<?> item = mgmt().getTypeRegistry().createSpec(mgmt().getTypeRegistry().get(itemId), null, EntitySpec.class); List<SpecParameter<?>> inputs = item.getParameters(); assertEquals(inputs.size(), NUM_APP_DEFAULT_CONFIG_KEYS + 3, "inputs="+inputs); SpecParameter<?> firstInput = inputs.get(0); assertEquals(firstInput.getLabel(), "simple"); assertEquals(firstInput.isPinned(), true); assertEquals(firstInput.getConfigKey().getName(), "simple"); assertEquals(firstInput.getConfigKey().getTypeToken(), TypeToken.of(String.class)); SpecParameter<?> secondInput = inputs.get(1); assertEquals(secondInput.getLabel(), "explicit_name"); assertEquals(secondInput.isPinned(), true); assertEquals(secondInput.getConfigKey().getName(), "explicit_name"); assertEquals(secondInput.getConfigKey().getTypeToken(), TypeToken.of(String.class)); SpecParameter<?> thirdInput = inputs.get(2); assertEquals(thirdInput.getLabel(), "third_input"); assertEquals(thirdInput.isPinned(), false); assertEquals(thirdInput.getConfigKey().getName(), "third_input"); assertEquals(thirdInput.getConfigKey().getTypeToken(), TypeToken.of(Integer.class)); }
Example 9
Source File: SpecParameterUnwrappingTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testAppRootParameters() throws Exception { EntitySpec<? extends Application> spec = createAppSpec( "brooklyn.parameters:", "- simple", "services:", "- type: " + BasicApplication.class.getName()); final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 1; List<SpecParameter<?>> params = spec.getParameters(); assertEquals(params.size(), NUM_APP_DEFAULT_CONFIG_KEYS + NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT, "params="+params); SpecParameter<?> firstInput = params.get(0); assertEquals(firstInput.getLabel(), "simple"); }
Example 10
Source File: SpecParameterUnwrappingTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testAppServiceParameters() throws Exception { EntitySpec<? extends Application> spec = createAppSpec( "services:", "- type: " + BasicApplication.class.getName(), " brooklyn.parameters:", " - simple"); final int NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT = 1; List<SpecParameter<?>> params = spec.getParameters(); assertEquals(params.size(), NUM_APP_DEFAULT_CONFIG_KEYS + NUM_CONFIG_KEYS_FROM_TEST_BLUEPRINT, "params="+params); SpecParameter<?> firstInput = params.get(0); assertEquals(firstInput.getLabel(), "simple"); }