.putIfNotNull("user", user) .put("address", InetAddress.getByName(address)) .build());
public static Map<String,Object> getBasicEntitySubstitutions(EntityDriver driver) { Entity entity = driver.getEntity(); String type = entity.getEntityType().getName(); String simpleType = type.substring(type.lastIndexOf(".")+1); String version = entity.getConfig(BrooklynConfigKeys.SUGGESTED_VERSION); return MutableMap.<String,Object>builder() .put("entity", entity) .put("driver", driver) .put("type", type) .put("simpletype", simpleType) .putIfNotNull("version", version) .build(); }
builder.putIfNotNull("command", command); List<String> args = MutableList.copyOf(config().get(ARGS)); builder.putIfNotNull("args", args); } else {
.put("useSsh", useSsh) .put("entity", entity) .putIfNotNull("imageId", imageId) .putIfNotNull("imageName", imageId == null ? imageName : null) .putIfNotNull("imageTag", imageId == null ? imageTag : null) .putIfNotNull("hardwareId", hardwareId) .build(); Group cluster = dockerHost.getDockerContainerCluster();
@Override public String generateConfigFile(NginxDriver driver, NginxController nginx) { // Check template URL exists String templateUrl = driver.getEntity().getConfig(NginxController.SERVER_CONF_TEMPLATE_URL); ResourceUtils.create(this).checkUrlExists(templateUrl); // Check SSL configuration ProxySslConfig ssl = driver.getEntity().getConfig(NginxController.SSL_CONFIG); if (ssl != null && Strings.isEmpty(ssl.getCertificateDestination()) && Strings.isEmpty(ssl.getCertificateSourceUrl())) { throw new IllegalStateException("ProxySslConfig can't have a null certificateDestination and null certificateSourceUrl. One or both need to be set"); } // For mapping by URL Iterable<UrlMapping> mappings = ((NginxController) driver.getEntity()).getUrlMappings(); Multimap<String, UrlMapping> mappingsByDomain = LinkedHashMultimap.create(); for (UrlMapping mapping : mappings) { Collection<String> addrs = mapping.getAttribute(UrlMapping.TARGET_ADDRESSES); if (addrs != null && addrs.size() > 0) { mappingsByDomain.put(mapping.getDomain(), mapping); } } Map<String, Object> substitutions = MutableMap.<String, Object>builder() .putIfNotNull("ssl", ssl) .put("urlMappings", mappings) .put("domainMappings", mappingsByDomain) .build(); // Get template contents and process String contents = ResourceUtils.create(driver.getEntity()).getResourceAsString(templateUrl); return TemplateProcessor.processTemplateContents(contents, driver, substitutions); }
private Map<String,?> toFlags() { return MutableMap.<String,Object>builder() .putIfNotNull("id", id) .putIfNotNull("name", name) .putIfNotNull("metric", metric) .putIfNotNull("entityWithMetric", entityWithMetric) .putIfNotNull("metricUpperBound", metricUpperBound) .putIfNotNull("metricLowerBound", metricLowerBound) .putIfNotNull("minPoolSize", minPoolSize) .putIfNotNull("maxPoolSize", maxPoolSize) .putIfNotNull("resizeUpIterationMax", resizeUpIterationMax) .putIfNotNull("resizeUpIterationIncrement", resizeUpIterationIncrement) .putIfNotNull("resizeDownIterationMax", resizeDownIterationMax) .putIfNotNull("resizeDownIterationIncrement", resizeDownIterationIncrement) .putIfNotNull("minPeriodBetweenExecs", minPeriodBetweenExecs) .putIfNotNull("resizeUpStabilizationDelay", resizeUpStabilizationDelay) .putIfNotNull("resizeDownStabilizationDelay", resizeDownStabilizationDelay) .putIfNotNull("resizeOperator", resizeOperator) .putIfNotNull("currentSizeOperator", currentSizeOperator) .putIfNotNull("poolHotSensor", poolHotSensor) .putIfNotNull("poolColdSensor", poolColdSensor) .putIfNotNull("poolOkSensor", poolOkSensor) .putIfNotNull("maxSizeReachedSensor", maxSizeReachedSensor) .putIfNotNull("maxReachedNotificationDelay", maxReachedNotificationDelay) .build(); } }
@Override public EnricherSpec<?> build() { return super.build().configure(MutableMap.builder() .putIfNotNull(Aggregator.PRODUCER, fromEntity) .put(Aggregator.TARGET_SENSOR, publishing) .putIfNotNull(Aggregator.SOURCE_SENSOR, aggregating) .putIfNotNull(MapAggregator.KEY_SENSOR, keySensor) .putIfNotNull(MapAggregator.VALUE_SENSOR, valueSensor) .putIfNotNull(Aggregator.FROM_CHILDREN, fromChildren) .putIfNotNull(Aggregator.FROM_MEMBERS, fromMembers) .putIfNotNull(Aggregator.TRANSFORMATION, computingSupplier.get()) .putIfNotNull(Aggregator.FROM_HARDCODED_PRODUCERS, fromHardcodedProducers) .putIfNotNull(Aggregator.EXCLUDE_BLANK, excludingBlank) .putIfNotNull(Aggregator.ENTITY_FILTER, entityFilter) .putIfNotNull(Aggregator.VALUE_FILTER, valueFilter) .putIfNotNull(Aggregator.DEFAULT_MEMBER_VALUE, defaultValueForUnreportedSensors) .build()); }
@Override public void doStart(Collection<? extends Location> locs) { addLocations(locs); List<Location> locations = MutableList.copyOf(Locations.getLocationsCheckingAncestors(locs, this)); sensors().set(SERVICE_UP, Boolean.FALSE); ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); // TODO support multiple provisioners Location provisioner = Iterables.getOnlyElement(locations); LOG.info("Creating new DockerLocation wrapping {}", provisioner); Map<String, ?> flags = MutableMap.<String, Object>builder() .putAll(config().get(LOCATION_FLAGS)) .put("provisioner", provisioner) .putIfNotNull("strategies", config().get(PLACEMENT_STRATEGIES)) .build(); createLocation(flags); super.doStart(locations); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); sensors().set(SERVICE_UP, Boolean.TRUE); }
@Test public void testEnricherSpecPropagatesSpecificSensorAndMapsOthers() throws Exception { final AttributeSensor<String> ANOTHER_ATTRIBUTE = Sensors.newStringSensor("another.attribute", ""); app.enrichers().add(EnricherSpec.create(Propagator.class) .configure(MutableMap.builder() .putIfNotNull(Propagator.PRODUCER, entity) .putIfNotNull(Propagator.SENSOR_MAPPING, ImmutableMap.of(TestEntity.NAME, ANOTHER_ATTRIBUTE)) .putIfNotNull(Propagator.PROPAGATING, ImmutableList.of(TestEntity.SEQUENCE)) .build())); // name propagated as alternative sensor entity.sensors().set(TestEntity.NAME, "foo"); EntityAsserts.assertAttributeEqualsEventually(app, ANOTHER_ATTRIBUTE, "foo"); // sequence also propagated entity.sensors().set(TestEntity.SEQUENCE, 2); EntityAsserts.assertAttributeEqualsEventually(app, TestEntity.SEQUENCE, 2); // name not propagated as original sensor EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.NAME, null); }
/** * Returns the detector. note that callers should then add this to the entity, * typically using {@link Entity#addEnricher(Enricher)}. * * @deprecated since 0.12.0; instead use {@link #buildSpec()} or directly use {@link EnricherSpec} */ @Deprecated public HttpLatencyDetector build() { return new HttpLatencyDetector(MutableMap.builder() .putIfNotNull(PERIOD, period) .putIfNotNull(ROLLUP_WINDOW_SIZE, rollupWindowSize) .putIfNotNull(REQUIRE_SERVICE_UP, requireServiceUp) .putIfNotNull(URL, url) .putIfNotNull(URL_SENSOR, urlSensor) .putIfNotNull(URL_POST_PROCESSING, urlPostProcessing) .build()); }
@SuppressWarnings("unchecked") public FixedListMachineProvisioningLocation<SshMachineLocation> build() { if (lm==null) return new FixedListMachineProvisioningLocation<SshMachineLocation>(MutableMap.builder() .putIfNotNull("machines", machines) .putIfNotNull("user", user) .putIfNotNull("privateKeyPassphrase", privateKeyPassphrase) .putIfNotNull("privateKeyFile", privateKeyFile) .putIfNotNull("privateKeyData", privateKeyData) .putIfNotNull("localTempDir", localTempDir) .build()); else return lm.createLocation(MutableMap.builder() .putIfNotNull("machines", machines) .putIfNotNull("user", user) .putIfNotNull("privateKeyPassphrase", privateKeyPassphrase) .putIfNotNull("privateKeyFile", privateKeyFile) .putIfNotNull("privateKeyData", privateKeyData) .putIfNotNull("localTempDir", localTempDir) .build(), FixedListMachineProvisioningLocation.class); } }
@Override public EnricherSpec<?> build() { return super.build().configure(MutableMap.builder() .putIfNotNull(Joiner.PRODUCER, fromEntity) .put(Joiner.TARGET_SENSOR, publishing) .put(Joiner.SOURCE_SENSOR, transforming) .putIfNotNull(Joiner.SEPARATOR, separator) .putIfNotNull(Joiner.KEY_VALUE_SEPARATOR, keyValueSeparator) .putIfNotNull(Joiner.JOIN_MAP_ENTRIES, joinMapEntries) .putIfNotNull(Joiner.QUOTE, quote) .putIfNotNull(Joiner.MINIMUM, minimum) .putIfNotNull(Joiner.MAXIMUM, maximum) .build()); }
@Test public void testEnricherSpecPropagatesSpecificSensor() throws Exception { app.enrichers().add(EnricherSpec.create(Propagator.class) .configure(MutableMap.builder() .putIfNotNull(Propagator.PRODUCER, entity) .putIfNotNull(Propagator.PROPAGATING, ImmutableList.of(TestEntity.NAME)) .build())); // name propagated entity.sensors().set(TestEntity.NAME, "foo"); EntityAsserts.assertAttributeEqualsEventually(app, TestEntity.NAME, "foo"); // sequence not propagated entity.sensors().set(TestEntity.SEQUENCE, 2); EntityAsserts.assertAttributeEqualsContinually(MutableMap.of("timeout", 100), app, TestEntity.SEQUENCE, null); }
@Override public Map<String, Object> getCustomJavaSystemProperties() { return MutableMap.<String, Object>builder() .putAll(super.getCustomJavaSystemProperties()) .put("connector.port", getAmqpPort()) .put("management.enabled", "true") .put("management.jmxport.registryServer", getRmiRegistryPort()) .put("management.jmxport.connectorServer", getJmxPort()) .put("management.http.enabled", Boolean.toString(getHttpManagementPort() != null)) .putIfNotNull("management.http.port", getHttpManagementPort()) .build(); }
@Override public EnricherSpec<?> build() { return super.build().configure(MutableMap.builder() .put(Reducer.SOURCE_SENSORS, reducing) .put(Reducer.PRODUCER, fromEntity) .put(Reducer.TARGET_SENSOR, publishing) .putIfNotNull(Reducer.REDUCER_FUNCTION, computing) .putIfNotNull(Reducer.REDUCER_FUNCTION_TRANSFORMATION, functionName) .putIfNotNull(Reducer.PARAMETERS, parameters) .build() ); }
@Override public EnricherSpec<?> build() { return super.build().configure(MutableMap.builder() .put(UpdatingMap.TARGET_SENSOR, targetSensor) .put(UpdatingMap.SOURCE_SENSOR, fromSensor) .putIfNotNull(UpdatingMap.KEY_IN_TARGET_SENSOR, key) .put(UpdatingMap.COMPUTING, computing) .putIfNotNull(UpdatingMap.REMOVING_IF_RESULT_IS_NULL, removingIfResultIsNull) .build()); }
@Override public EnricherSpec<? extends Enricher> build() { return super.build().configure(MutableMap.builder() .putIfNotNull(Propagator.PRODUCER, fromEntity) .putIfNotNull(Propagator.PRODUCER, fromEntitySupplier) .putIfNotNull(Propagator.SENSOR_MAPPING, propagating) .putIfNotNull(Propagator.PROPAGATING_ALL, propagatingAll) .putIfNotNull(Propagator.PROPAGATING_ALL_BUT, propagatingAllBut) .build()); }
@Override public EnricherSpec<?> build() { return super.build().configure(MutableMap.builder() .putIfNotNull(Transformer.PRODUCER, fromEntity) .put(Transformer.TARGET_SENSOR, publishing) .put(Transformer.SOURCE_SENSOR, transforming) .putIfNotNull(Transformer.TRANSFORMATION_FROM_VALUE, computing) .putIfNotNull(Transformer.TRANSFORMATION_FROM_EVENT, computingFromEvent) .build()); }
@Override public EnricherSpec<?> build() { return super.build().configure(MutableMap.builder() .putIfNotNull(Combiner.PRODUCER, fromEntity) .put(Combiner.TARGET_SENSOR, publishing) .put(Combiner.SOURCE_SENSORS, combining) .putIfNotNull(Combiner.TRANSFORMATION, computing) .putIfNotNull(Combiner.VALUE_FILTER, valueFilter) .build()); }
@Override public Map<String,String> getShellEnvironment() { return MutableMap.<String,String>builder() .putAll(super.getShellEnvironment()) .putIfNotNull("CLASSPATH", getClasspath()) .build(); } }