@Override public boolean apply(SpecParameter<?> input) { return input.getConfigKey().getName().equals(param.getConfigKey().getName()); }
@Override public boolean apply(SpecParameter<?> input) { return input.getConfigKey().getName().equals(name); }
/** gets all the keys in the given config bag which are applicable to the given list of parameters */ public static List<FlagConfigKeyAndValueRecord> findAllParameterConfigKeys(List<SpecParameter<?>> parameters, ConfigBag input) { List<FlagConfigKeyAndValueRecord> output = new ArrayList<FlagUtils.FlagConfigKeyAndValueRecord>(); for (SpecParameter<?> param : parameters) { FlagConfigKeyAndValueRecord record = getFlagConfigKeyRecord(null, param.getConfigKey(), input); if (record.isValuePresent()) output.add(record); } return output; }
public static EnricherConfigSummary enricherConfigSummary(SpecParameter<?> input) { Double priority = input.isPinned() ? Double.valueOf(1d) : null; return enricherConfigSummary(input.getConfigKey(), input.getLabel(), priority, null); } }
public static PolicyConfigSummary policyConfigSummary(SpecParameter<?> input) { Double priority = input.isPinned() ? Double.valueOf(1d) : null; return policyConfigSummary(input.getConfigKey(), input.getLabel(), priority, null); }
public static EntityConfigSummary entityConfigSummary(SpecParameter<?> input, AtomicInteger paramPriorityCnt) { // Increment the priority because the config container is a set. Server-side we are using an ordered set // which results in correctly ordered items on the wire (as a list). Clients which use the java bindings // though will push the items in an unordered set - so give them means to recover the correct order. Double priority = input.isPinned() ? Double.valueOf(paramPriorityCnt.incrementAndGet()) : null; return entityConfigSummary(input.getConfigKey(), input.getLabel(), priority, input.isPinned(), null); }
/** merge parameters against other parameters and known and type-inherited config keys */ private static Collection<SpecParameter<?>> resolveParameters(Collection<? extends SpecParameter<?>> newParams, AbstractBrooklynObjectSpec<?,?> spec) { Collection<? extends SpecParameter<?>> existingReferenceParams = spec.getParameters(); Map<String,SpecParameter<?>> existingToKeep = MutableMap.of(); if (existingReferenceParams!=null) { for (SpecParameter<?> p: existingReferenceParams) { if (ConfigInheritances.isKeyReinheritable(p.getConfigKey(), InheritanceContext.TYPE_DEFINITION)) { existingToKeep.put(p.getConfigKey().getName(), p); } } } List<SpecParameter<?>> result = MutableList.<SpecParameter<?>>of(); if (newParams!=null) { for (SpecParameter<?> p: newParams) { final SpecParameter<?> existingP = existingToKeep.remove(p.getConfigKey().getName()); if (p instanceof SpecParameterIncludingDefinitionForInheritance) { // config keys should be transformed to parameters and so should be found; // so the code below is correct whether existingP is set or is null p = ((SpecParameterIncludingDefinitionForInheritance<?>)p).resolveWithAncestor(existingP); } else { // shouldn't happen; all calling logic should get SpecParameterForInheritance; log.warn("Found non-definitional spec parameter: "+p+" adding to "+spec); } result.add(p); } } result.addAll(existingToKeep.values()); return result; }
@Test public void testJavaType() { String name = "minRam"; SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.of( "name", name, "type", BasicSpecParameterFromListTest.class.getName())); assertEquals(input.getConfigKey().getTypeToken(), TypeToken.of(BasicSpecParameterFromListTest.class)); }
@Test public void testOnlyName() { String name = "minRam"; SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.of("name", name)); assertEquals(input.getLabel(), name); assertEquals(input.getConfigKey().getName(), name); assertEquals(input.getConfigKey().getTypeToken(), TypeToken.of(String.class)); }
private void assertInput(SpecParameter<?> input, String label, boolean pinned, ConfigKey<?> type) { assertEquals(input.getLabel(), label); assertEquals(input.isPinned(), pinned); assertEquals(input.getConfigKey(), type); }
@Test public void testConstraintAsArray() { String name = "minRam"; String constraint = "required"; SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.of( "name", name, "constraints", ImmutableList.of(constraint))); ConfigKey<?> type = input.getConfigKey(); assertConstraint(type.getConstraint(), StringPredicates.isNonBlank()); }
EntityConfigSummary entityConfigSummary = EntityTransformer.entityConfigSummary(param.getConfigKey(), param.getLabel(), priority, param.isPinned(), MutableMap.<String,URI>of()); config.add(entityConfigSummary);
@Test public void testConfigInImplVisible() { Map<String, ConfigKey<?>> expectedKeys = ImmutableMap.<String, ConfigKey<?>>of( ConfigInImplParameterTestEntityImpl.SUGGESTED_VERSION.getName(), ConfigInImplParameterTestEntityImpl.SUGGESTED_VERSION, AbstractEntity.DEFAULT_DISPLAY_NAME.getName(), AbstractEntity.DEFAULT_DISPLAY_NAME); List<SpecParameter<?>> inputs = BasicSpecParameter.fromClass(mgmt, ConfigInImplParameterTestEntity.class); assertEquals(inputs.size(), expectedKeys.size()); for (SpecParameter<?> in : inputs) { ConfigKey<?> key = expectedKeys.get(in.getConfigKey().getName()); assertNotNull(key); assertInput(in, key.getName(), false, key); } }
@Test public void testInlineName() { String name = "minRam"; SpecParameter<?> input = parseSpecParameterDefinition(name); assertEquals(input.getLabel(), name); assertTrue(input.isPinned()); ConfigKey<?> type = input.getConfigKey(); assertEquals(type.getName(), name); assertEquals(type.getTypeToken(), TypeToken.of(String.class)); assertNull(type.getDefaultValue()); assertNull(type.getDescription()); assertTrue(type.getInheritanceByContext().values().isEmpty(), "Unexpected inheritance: "+type.getInheritanceByContext()); assertConstraint(type.getConstraint(), Predicates.alwaysTrue()); }
@Test public void testUnexpectedType() { String name = "1234"; String label = "1234"; String description = "5678.56"; String defaultValue = "444.12"; SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.of( "name", name, "label", label, "description", description, "default", defaultValue)); assertEquals(input.getLabel(), name); assertTrue(input.isPinned()); ConfigKey<?> type = input.getConfigKey(); assertEquals(type.getName(), name); assertEquals(type.getDefaultValue(), defaultValue); assertEquals(type.getDescription(), description); assertTrue(type.getInheritanceByContext().values().isEmpty(), "Unexpected inheritance: "+type.getInheritanceByContext()); }
@Test public void testOsgiType() { TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH); String itemId = ver("test.inputs", "0.0.1"); addCatalogItems( "brooklyn.catalog:", " id: test.inputs", " version: 0.0.1", " itemType: entity", " libraries:", " - classpath://" + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH, " item: ", " type: "+ BasicApplication.class.getName(), " brooklyn.parameters:", " - name: simple", " type: " + OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY); AbstractBrooklynObjectSpec<?,?> spec = createSpec(itemId); List<SpecParameter<?>> inputs = spec.getParameters(); assertEquals(inputs.size(), NUM_APP_DEFAULT_CONFIG_KEYS + 1, "inputs="+inputs); SpecParameter<?> firstInput = inputs.get(0); assertEquals(firstInput.getLabel(), "simple"); assertTrue(firstInput.isPinned()); assertEquals(firstInput.getConfigKey().getName(), "simple"); assertEquals(firstInput.getConfigKey().getTypeToken().getRawType().getName(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY); }
@Test public void testFullDefinition() { String name = "minRam"; String label = "Minimum Ram"; String description = "Some description"; String inputType = "string"; String defaultValue = "VALUE"; Boolean pinned = false; String constraint = "required"; SpecParameter<?> input = parseSpecParameterDefinition(ImmutableMap.builder() .put("name", name) .put("label", label) .put("description", description) .put("type", inputType) .put("default", defaultValue) .put("pinned", pinned) .put("constraints", constraint) .build()); assertEquals(input.getLabel(), label); assertFalse(input.isPinned()); ConfigKey<?> type = input.getConfigKey(); assertEquals(type.getName(), name); assertEquals(type.getTypeToken(), TypeToken.of(String.class)); assertEquals(type.getDefaultValue(), defaultValue); assertEquals(type.getDescription(), description); assertTrue(type.getInheritanceByContext().values().isEmpty(), "Unexpected inheritance: "+type.getInheritanceByContext()); assertConstraint(type.getConstraint(), StringPredicates.isNonBlank()); }
assertEquals(firstInput.getLabel(), "simple"); assertEquals(firstInput.isPinned(), true); assertEquals(firstInput.getConfigKey().getName(), "simple"); assertEquals(firstInput.getConfigKey().getTypeToken(), TypeToken.of(String.class)); assertEquals(secondInput.getConfigKey().getName(), "explicit_name"); assertEquals(secondInput.getConfigKey().getTypeToken(), TypeToken.of(String.class)); assertEquals(thirdInput.getConfigKey().getName(), "third_input"); assertEquals(thirdInput.getConfigKey().getTypeToken(), TypeToken.of(Integer.class));
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()); } }
/** used if yaml specifies a parameter, but possibly incomplete, and a spec supertype has a parameter */ @SuppressWarnings("unchecked") SpecParameter<?> resolveWithAncestor(SpecParameter<?> ancestor) { if (ancestor==null) return new BasicSpecParameter<>(getLabel(), isPinned(), getConfigKey(), getSensor()); return new BasicSpecParameter( hasLabelSet ? getLabel() : ancestor.getLabel(), hasPinnedSet ? isPinned() : ancestor.isPinned(), resolveWithAncestorConfigKey(ancestor.getConfigKey()), hasType ? getSensor() : ancestor.getSensor()); }