/** as {@link #put(Object, Object)} but excluding null keys and values, and fluent style */ public MutableMap<K,V> addIfNotNull(K key, V value) { if (key!=null && value!=null) add(key, value); return this; }
public Builder<K, V> putAll(Map<? extends K, ? extends V> map) { result.add(map); return this; }
@Override protected Map<String, Object> merge(Map<String, Object> base, Map<String, Object> subkeys, boolean unmodifiable) { Map<String, Object> result = MutableMap.copyOf(base).add(subkeys); if (unmodifiable) result = Collections.unmodifiableMap(result); return result; }
public static MutableMap<String, Object> minimalMemoryConfig() { // http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html return MutableMap.<String, Object>of() .add("skip-name-resolve","") .add("performance_schema","0") .add("innodb_buffer_pool_size","5M") .add("innodb_log_buffer_size","256K") .add("query_cache_size","0") .add("max_connections","10") .add("key_buffer_size","8") .add("thread_cache_size","0") .add("host_cache_size","0") .add("innodb_ft_cache_size","1600000") .add("innodb_ft_total_cache_size","32000000") // per thread or per operation settings .add("thread_stack","131072") .add("sort_buffer_size","32K") .add("read_buffer_size","8200") .add("read_rnd_buffer_size","8200") .add("max_heap_table_size","16K") .add("tmp_table_size","1K") .add("bulk_insert_buffer_size","0") .add("join_buffer_size","128") .add("net_buffer_length","1K") .add("innodb_sort_buffer_size","64K") // settings that relate to the binary log (if enabled) .add("binlog_cache_size","4K") .add("binlog_stmt_cache_size","4K"); }
@Override public Map<String, String> getShellEnvironment() { return MutableMap.copyOf(super.getShellEnvironment()).add("PID_FILE", getPidFile()); }
public static HttpToolResponse requestTokenWithExplicitLifetime(URL url, String user, String key, Duration expiration) throws URISyntaxException { HttpClient client = HttpTool.httpClientBuilder().build(); HttpToolResponse response = HttpTool.httpGet(client, url.toURI(), MutableMap.<String,String>of() .add(AuthHeaders.AUTH_USER, user) .add(AuthHeaders.AUTH_KEY, key) .add("Host", url.getHost()) .add("X-Auth-New-Token", "" + true) .add("X-Auth-Token-Lifetime", "" + expiration.toSeconds()) ); // curl -v https://ams01.objectstorage.softlayer.net/auth/v1.0/v1.0 -H "X-Auth-User: IBMOS12345-2:username" -H "X-Auth-Key: <API KEY>" -H "Host: ams01.objectstorage.softlayer.net" -H "X-Auth-New-Token: true" -H "X-Auth-Token-Lifetime: 15" log.info("Requested token with explicit lifetime: "+expiration+" at "+url+"\n"+response+"\n"+response.getHeaderLists()); return response; } }
protected String execCommands(ConfigBag config, List<String> cmds, Map<String,?> env) { ByteArrayOutputStream out = new ByteArrayOutputStream(); MutableMap<String,Object> flags = MutableMap.<String,Object>of("out", out); if (config!=null) flags.add(config.getAllConfig()); tool.execCommands(flags, cmds, env); return new String(out.toByteArray()); }
@Override public void init() { super.init(); ChefConfigs.addToLaunchRunList(this, "mysql::server"); ChefConfigs.addToCookbooksFromGithub(this, "mysql", "build-essential", "openssl"); ChefConfigs.setLaunchAttribute(this, "mysql", MutableMap.of() .add("server_root_password", "MyPassword") .add("server_debian_password", "MyPassword") .add("server_repl_password", "MyPassword") ); // TODO other attributes, eg: // node['mysql']['port'] }
@Override public void init() { super.init(); ChefConfigs.addToLaunchRunList(this, "mysql::server"); ChefConfigs.addToCookbooksFromGithub(this, "mysql", "build-essential", "openssl"); ChefConfigs.setLaunchAttribute(this, "mysql", MutableMap.of() .add("server_root_password", "MyPassword") .add("server_debian_password", "MyPassword") .add("server_repl_password", "MyPassword") ); // TODO other attributes, eg: // node['mysql']['port'] }
if ( m.containsKey("brooklyn.config") ) { Map<?,?> cfg1 = (Map<?,?>) m.get("brooklyn.config"); Map<Object,Object> cfgMergeFlat = MutableMap.<Object,Object>copyOf(cfg1).add(params.getAllConfig()); if (cfgMergeFlat.size() < cfg1.size() + params.size()) {
@Test public void testPrimitivedAndLiteralledMap() { Object foo = new Object() { @Override public String toString() { return "FOO"; } }; MutableMap<Object, Object> map = MutableMap.<Object,Object>of("a", 1, 2, Arrays.<Object>asList(true, 8, "8"), 'C', foo); Map<Object, Object> mapL = Jsonya.newInstanceLiteral().put(map).getRootMap(); Assert.assertEquals(mapL, map); Assert.assertEquals(mapL.get('C'), foo); Map<Object, Object> mapP = Jsonya.newInstancePrimitive().put(map).getRootMap(); Assert.assertNotEquals(mapP, map); Assert.assertEquals(mapP.get('C'), foo.toString()); Assert.assertEquals(MutableMap.copyOf(mapP).add('C', null), MutableMap.copyOf(map).add('C', null)); }
.add(TEMPLATE_BUILDER, tb); if (portForwardingMode) flags.put(WAIT_FOR_SSHABLE, false);
/** * Constructs an instance (e.g. of entity, location, enricher or policy. * Checks if special instructions on the spec, if supplied; * else if new-style class, calls no-arg constructor (ignoring spec); * else if old-style, uses flags if avail as args or as spec and passes to constructor. */ protected <T> T construct(Class<? extends T> clazz, AbstractBrooklynObjectSpec<?,?> optionalSpec, Map<String,?> optionalOldStyleConstructorFlags) { try { if (optionalSpec!=null) { ConfigBag bag = ConfigBag.newInstance(optionalSpec.getConfig()); Class<? extends SpecialBrooklynObjectConstructor> special = bag.get(SpecialBrooklynObjectConstructor.Config.SPECIAL_CONSTRUCTOR); if (special!=null) { // special construction requested; beta and very limited scope; see SpecialBrooklynObjectConstructor return constructWithSpecial(special, clazz, optionalSpec); } } if (isNewStyle(clazz)) { return constructNewStyle(clazz); } else { MutableMap<String,Object> constructorFlags = MutableMap.of(); if (optionalOldStyleConstructorFlags!=null) constructorFlags.add(optionalOldStyleConstructorFlags); else constructorFlags.add(optionalSpec.getFlags()); return constructOldStyle(clazz, MutableMap.copyOf(constructorFlags)); } } catch (Exception e) { throw Exceptions.propagate(e); } }
protected static EntitySpec<? extends Entity> specBase() { EntitySpec<ChefEntity> spec = EntitySpec.create(ChefEntity.class); ChefConfigs.addToLaunchRunList(spec, "mysql::server"); spec.configure(PID_FILE, "/var/run/mysqld/mysql*.pid"); // init.d service name is sometimes mysql, sometimes mysqld, depending ubuntu/centos // we use pid file above instead, but this (with the right name) could be used: // spec.configure(SERVICE_NAME, "mysql"); // chef mysql fails on first run but works on second if switching between server and solo modes spec.configure(ChefConfig.CHEF_RUN_CONVERGE_TWICE, true); // only used for solo, but safely ignored for knife ChefConfigs.addToCookbooksFromGithub(spec, "mysql", "build-essential", "openssl"); // we always need dependent cookbooks set, and mysql requires password set // (TODO for knife we might wish to prefer things from the server) ChefConfigs.addLaunchAttributes(spec, MutableMap.of("mysql", MutableMap.of() .add("server_root_password", "MyPassword") .add("server_debian_password", "MyPassword") .add("server_repl_password", "MyPassword") )); return spec; }
protected static EntitySpec<? extends Entity> specBase() { EntitySpec<ChefEntity> spec = EntitySpec.create(ChefEntity.class); ChefConfigs.addToLaunchRunList(spec, "mysql::server"); spec.configure(PID_FILE, "/var/run/mysqld/mysql*.pid"); // init.d service name is sometimes mysql, sometimes mysqld, depending ubuntu/centos // we use pid file above instead, but this (with the right name) could be used: // spec.configure(SERVICE_NAME, "mysql"); // chef mysql fails on first run but works on second if switching between server and solo modes spec.configure(ChefConfig.CHEF_RUN_CONVERGE_TWICE, true); // only used for solo, but safely ignored for knife ChefConfigs.addToCookbooksFromGithub(spec, "mysql", "build-essential", "openssl"); // we always need dependent cookbooks set, and mysql requires password set // (TODO for knife we might wish to prefer things from the server) ChefConfigs.addLaunchAttributes(spec, MutableMap.of("mysql", MutableMap.of() .add("server_root_password", "MyPassword") .add("server_debian_password", "MyPassword") .add("server_repl_password", "MyPassword") )); return spec; }
environment.add(config().get(DockerContainer.DOCKER_CONTAINER_ENVIRONMENT)); environment.add(entity.config().get(DockerContainer.DOCKER_CONTAINER_ENVIRONMENT)); Map<String, Entity> links = entity.config().get(DockerAttributes.DOCKER_LINKS); if (links != null && links.size() > 0) { for (Map.Entry<String, Entity> linked : links.entrySet()) { Map<String, Object> linkVars = DockerUtils.generateLinks(getRunningEntity(), linked.getValue(), linked.getKey()); environment.add(linkVars); String targetAddress = DockerUtils.getTargetAddress(getRunningEntity(), linked.getValue()); extraHosts.put(linked.getKey(), targetAddress);