/** includes the given attributes in the attributes to be passed to chef; * when combining with other attributes, this uses {@link Jsonya} semantics to add * (a deep add, combining lists and maps) */ public KnifeConvergeTaskFactory<RET> knifeAddAttributes(Map<? extends Object, ? extends Object> attributes) { if (attributes!=null && !attributes.isEmpty()) { Jsonya.of(knifeAttributes).add(attributes); } return self(); }
/** includes the given attributes in the attributes to be passed to chef; * when combining with other attributes, this uses {@link Jsonya} semantics to add * (a deep add, combining lists and maps) */ public KnifeConvergeTaskFactory<RET> knifeAddAttributes(Map<? extends Object, ? extends Object> attributes) { if (attributes!=null && !attributes.isEmpty()) { Jsonya.of(knifeAttributes).add(attributes); } return self(); }
@SuppressWarnings("rawtypes") @Override public Object applyToKeyInMap(MapConfigKey<V> key, Map target) { return key.applyValueToMap(Jsonya.of(key.rawValue(target)).add(this).getRootMap(), target); } };
@SuppressWarnings("unchecked") @Test public void testJsonyaMapNew() { MutableMap<Object, Object> m = europeMap().getRootMap(); Assert.assertEquals(Jsonya.of(m).get("europe", "uk", "edinburgh", "population"), 500*1000); Assert.assertEquals(Jsonya.of(m).at("europe", "uk", "edinburgh", "population").get(), 500*1000); Assert.assertEquals(((Map<Object,Object>)Jsonya.of(m).get("europe")).keySet(), ImmutableSet.of("uk", "france")); Assert.assertEquals(Jsonya.of(m).at("europe").getFocusMap().keySet(), ImmutableSet.of("uk", "france")); }
@Override public T call(ConfigBag parameters) { MutableMap<String, String> headers = MutableMap.of(com.google.common.net.HttpHeaders.CONTENT_TYPE, MediaType.JSON_UTF_8.toString()); byte[] httpBody = Jsonya.of(parameters.getAllConfig()).toString().getBytes(); String effectorUrl = Urls.mergePaths("effectors", Urls.encode(remoteEffectorName)); HttpToolResponse result = ((BrooklynEntityMirror)entity()).http().post(effectorUrl, headers, httpBody); if (resultParser!=null) return resultParser.apply(result); else return null; } }
protected String extractPlanYamlString(ConfigBag parameters) { Object planRaw = parameters.getStringKey(BLUEPRINT_CAMP_PLAN.getName()); if (planRaw instanceof String && Strings.isBlank((String)planRaw)) planRaw = null; String url = parameters.get(BLUEPRINT_TYPE); if (url!=null && planRaw!=null) throw new IllegalArgumentException("Cannot supply both plan and url"); if (url==null && planRaw==null) throw new IllegalArgumentException("Must supply plan or url"); Map<String, Object> config = asMap(parameters, BLUEPRINT_CONFIG); if (planRaw==null) { planRaw = Jsonya.at("services").list().put("serviceType", url).putIfNotNull("brooklyn.config", config).getRootMap(); } else { if (config!=null) throw new IllegalArgumentException("Cannot supply plan with config"); } // planRaw might be a yaml string, or a map; if a map, convert to string if (planRaw instanceof Map) planRaw = Jsonya.of((Map<?,?>)planRaw).toString(); if (!(planRaw instanceof String)) throw new IllegalArgumentException("Invalid "+JavaClassNames.simpleClassName(planRaw)+" value for CAMP plan: "+planRaw); // now *all* the data is in planRaw; that is what will be submitted return (String)planRaw; }
@Test public void testJsonyaDeepSimpleFailure() { try { Jsonya.of(europeMap()).atExisting("euroope"); Asserts.shouldHaveFailedPreviously(); } catch (Exception e) { Asserts.expectedFailureContainsIgnoreCase(e, "euroope", "no", "found"); } }
@SuppressWarnings("rawtypes") @Test public void testJsonyaMapExistingAndRootModification() { Navigator<MutableMap<Object, Object>> n = Jsonya.of(europeMap().getRootMap()).at("asia") .put(MutableMap.of("china", null)) .put(MutableMap.of("japan", null)); Assert.assertTrue( n.root().at("asia").get(Map.class).containsKey("china") ); Assert.assertTrue( ((Map)n.root().get("asia")).containsKey("japan") ); }
@Test public void testJsonyaDeepSimple() { Navigator<MutableMap<Object, Object>> n = Jsonya.of(europeMap()) .at("europe").add("spain", "plains"); Assert.assertEquals( n.root().get("europe", "spain"), "plains" ); Assert.assertEquals( n.getRootMap().size(), 1 ); Assert.assertEquals( n.root().at("europe").getFocusMap().size(), 3 ); }
@Test public void testJsonyaDeepMoreComplicated() { Navigator<MutableMap<Object, Object>> n = Jsonya.of(europeMap()).at("asia") .list().add("china", "japan") .root().add( Jsonya.newInstance().at("europe", "uk", "glasgow").put("weather", "even wetter").getRootMap() ); Assert.assertEquals( n.getRootMap().size(), 2 ); Assert.assertTrue( n.root().at("asia").get(List.class).contains("china") ); Assert.assertTrue( ((List<?>)n.root().get("asia")).contains("japan") ); Assert.assertEquals(n.root().at("europe", "uk").get(Map.class).size(), 2); Assert.assertEquals(n.root().at("europe", "uk", "edinburgh", "weather").get(), "wet"); Assert.assertEquals(n.root().at("europe", "uk", "glasgow", "weather").get(), "even wetter"); }