gpt4 book ai didi

org.apache.brooklyn.util.yaml.Yamls.parseAll()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 13:22:40 27 4
gpt4 key购买 nike

本文整理了Java中org.apache.brooklyn.util.yaml.Yamls.parseAll()方法的一些代码示例,展示了Yamls.parseAll()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Yamls.parseAll()方法的具体详情如下:
包路径:org.apache.brooklyn.util.yaml.Yamls
类名称:Yamls
方法名:parseAll

Yamls.parseAll介绍

[英]as #parseAll(String)
[中]as#parseAll(字符串)

代码示例

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public static CompoundTransformer load(String contents) {
  CompoundTransformer.Builder builder = CompoundTransformer.builder();
  Iterable<Object> toplevel = Yamls.parseAll(contents);
  Collection<?> rules = (Collection<?>)Iterables.getOnlyElement(toplevel);
  for (Object obj : rules) {
    Map<?, ?> map = (Map<?, ?>)obj;
    Entry<?, ?> entry = Iterables.getOnlyElement(map.entrySet());
    addRule(builder, (String)entry.getKey(), (Map<?, ?>)entry.getValue());
  }
  LOG.info("Loaded " + rules.size() + " transforms");
  return builder.build();
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

Object input = Iterables.getOnlyElement( Yamls.parseAll(range) );
if (input instanceof Iterable) return LinearRangeQuorumCheck.of(name, (Iterable)input);
throw new IllegalArgumentException("Invalid input to linear range quorum check; should be a list of points (not '"+range+"')");

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

raw = Yamls.parseAll((String)raw).iterator().next();

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

public static QuorumCheck of(String nameOrRange) {
  if (nameOrRange==null) return null;
  for (QuorumCheck qc: NAMED_CHECKS) {
    if (qc instanceof NumericQuorumCheck) {
      if (Objects.equal(nameOrRange, ((NumericQuorumCheck)qc).getName()))
        return qc;
    }
  }
  // parse YAML
  Object input = Iterables.getOnlyElement( Yamls.parseAll(nameOrRange) );
  if (input instanceof Collection) return of((Collection<?>)input);
  if (input instanceof Integer || input instanceof Long) return of((int)((Number)input));
  // TODO also accept "50%", and "50%,1"
  throw new IllegalArgumentException("Unknown quorum check format '"+input+"'");
}

代码示例来源:origin: io.cloudsoft.brooklyn.tosca/brooklyn-tosca-transformer

public PlanTypeChecker(String plan) {
  try {
    obj = Yamls.parseAll(plan).iterator().next();
  } catch (Exception e) {
    Exceptions.propagateIfFatal(e);
    log.trace("Not YAML", e);
    return;
  }
  if (!(obj instanceof Map)) {
    log.trace("Not a map");
    // is it a one-line URL?
    plan = plan.trim();
    if (!plan.contains("\n") && Urls.isUrlWithProtocol(plan)) {
      csarLink = plan;
    }
    return;
  }
  if (isTosca((Map<?,?>)obj)) {
    isTosca = true;
    return;
  }
  if (((Map<?,?>)obj).size()==1) {
    csarLink = (String) ((Map<?,?>)obj).get("csar_link");
    return;
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-rest-resources

@Override
@Beta
public Response createFromUpload(byte[] item, boolean forceUpdate) {
  Throwable yamlException = null;
  try {
    MutableList.copyOf( Yamls.parseAll(new InputStreamReader(new ByteArrayInputStream(item))) );
  } catch (Exception e) {
    Exceptions.propagateIfFatal(e);
    yamlException = e;
  }
  
  if (yamlException==null) {
    // treat as yaml if it parsed
    return createFromYaml(new String(item), forceUpdate);
  }
  
  return createFromArchive(item, false, forceUpdate);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/**
   * As {@link LocationRegistry#getListOfLocationsManaged(Object)}, 
   * but using {@link #coerceToLocationManaged(ManagementContext, Object)}
   * for more forgiving interpretations.
   * <p>
   * The caller is responsible for ensuring the resulting {@link Location} is unmanaged. */
  public static Collection<? extends Location> coerceToCollectionOfLocationsManaged(ManagementContext mgmt, Object rawO) {
    if (rawO==null) return null;
    Object raw = rawO;
    if (raw instanceof Collection) {
      List<Location> result = MutableList.<Location>of();
      for (Object o: (Collection<?>)raw)
        result.add(coerceToLocationManaged(mgmt, o));
      return result;
    }
    if (raw instanceof String) {
      raw = Yamls.parseAll((String)raw).iterator().next();
      if (raw instanceof Collection)
        return Locations.coerceToCollectionOfLocationsManaged(mgmt, raw);
    }
    return Collections.singletonList( coerceToLocationManaged(mgmt, raw) );
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

public static Map<?,?> getCatalogMetadata(String yaml) {
  Map<?,?> itemDef = Yamls.getAs(Yamls.parseAll(yaml), Map.class);
  return getFirstAsMap(itemDef, "brooklyn.catalog").orNull();        
}

代码示例来源:origin: org.apache.brooklyn.camp/camp-base

@SuppressWarnings("unchecked")
public DeploymentPlan parseDeploymentPlan(String yaml) {
  Iterable<Object> template = Yamls.parseAll(yaml);
  
  Map<String, Object> dpRootUninterpreted = null;
  try {
    dpRootUninterpreted = Yamls.getAs(template, Map.class);
  } catch (Exception e) {
    Exceptions.propagateIfFatal(e);
    throw new YAMLException("Plan not in acceptable format: "+(e.getMessage()!=null ? e.getMessage() : ""+e), e);
  }
  Map<String, Object> dpRootInterpreted = applyInterpreters(dpRootUninterpreted);
  
  return DeploymentPlan.of(dpRootInterpreted, yaml);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base

private void assertTemplateValues(File template) throws IOException {
  String expectedHostname = BrooklynNetworkUtils.getLocalhostInetAddress().getHostName();
  String expectedIp = BrooklynNetworkUtils.getLocalhostInetAddress().getHostAddress();
  Map<?,?> data = (Map) Iterables.getOnlyElement(Yamls.parseAll(Files.toString(template, Charsets.UTF_8)));
  Assert.assertEquals(data.size(), 3);
  Assert.assertEquals(data.get("entity.hostname"), expectedHostname);
  Assert.assertEquals(data.get("entity.address"), expectedIp);
  Assert.assertEquals(data.get("frogs"), 12);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

return Yamls.getAs( Yamls.parseAll(input), Map.class );
} catch (Exception e) {
  Exceptions.propagateIfFatal(e);

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

/** Returns a wrapped map, if the object is YAML which parses as a map; 
 * otherwise returns absent capable of throwing an error with more details */
@SuppressWarnings("unchecked")
public static Maybe<Map<?,?>> getAsYamlMap(Object planData) {
  if (!(planData instanceof String)) return Maybe.absent("not a string");
  Iterable<Object> result;
  try {
    result = Yamls.parseAll((String)planData);
  } catch (Exception e) {
    Exceptions.propagateIfFatal(e);
    return Maybe.absent(e);
  }
  Iterator<Object> ri = result.iterator();
  if (!ri.hasNext()) return Maybe.absent("YAML has no elements in it");
  Object r1 = ri.next();
  if (ri.hasNext()) return Maybe.absent("YAML has multiple elements in it");
  if (r1 instanceof Map) return (Maybe<Map<?,?>>)(Maybe<?>) Maybe.of(r1);
  return Maybe.absent("YAML does not contain a map");
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

Map<?,?> m = ((Map<?,?>)Iterables.getOnlyElement( Yamls.parseAll(blueprint) ));
if ( m.containsKey("brooklyn.config") ) {
  Map<?,?> cfg1 = (Map<?,?>) m.get("brooklyn.config");

代码示例来源:origin: org.apache.brooklyn.camp/camp-base

@SuppressWarnings("unchecked")
public void testToyInterpreter() {
  @SuppressWarnings("rawtypes")
  Map y1 = Yamls.getAs( Yamls.parseAll( Streams.reader(getClass().getResourceAsStream("yaml-sample-toy-interpreter.yaml"))), Map.class );
  log.info("pre-interpreter have: "+y1);
  
  BasicCampPlatform p = new BasicCampPlatform();
  p.pdp().addInterpreter(new ToyInterpreter());
  Map<String, Object> y2 = p.pdp().applyInterpreters(y1);
  log.info("interpreter gives: "+y2);
  
  Map<String, Object> y3 = Yamls.getAs( Yamls.parseAll( Streams.reader(getClass().getResourceAsStream("yaml-sample-toy-interpreter-result.yaml"))), Map.class );
  Assert.assertEquals(y2, y3);
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-utils-common

@Test
public void testSafeYaml() throws Exception {
  assertFalse(BrooklynSystemProperties.YAML_TYPE_INSTANTIATION.isEnabled(),
      "Set property to false (or do not set at all): " + BrooklynSystemProperties.YAML_TYPE_INSTANTIATION.getPropertyName());
  try {
    Yamls.parseAll("!!java.util.Date\n" +
        "date: 25\n" +
        "month: 12\n" +
        "year: 2016");
    Asserts.shouldHaveFailedPreviously("Expected exception: " + ConstructorException.class.getCanonicalName());
  } catch(ConstructorException e) {
    Asserts.expectedFailureContains(e, "could not determine a constructor");
  }
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

List<CatalogItemDtoAbstract<?, ?>> resultLegacyFormat, Map<RegisteredType, RegisteredType> resultNewFormat, 
  boolean requireValidation, Map<?, ?> parentMeta, int depth, boolean force) {
Map<?,?> itemDef = Yamls.getAs(Yamls.parseAll(yaml), Map.class);
Map<?,?> catalogMetadata = getFirstAsMap(itemDef, "brooklyn.catalog").orNull();
if (catalogMetadata==null)

代码示例来源:origin: org.apache.brooklyn/brooklyn-camp

public Object parseDslExpression(String input) {
  String s1 = Yamls.getAs( Yamls.parseAll( Streams.reader(Streams.newInputStreamWithContents(input)) ), String.class );
  BasicCampPlatform p = new BasicCampPlatform();
  p.pdp().addInterpreter(new BrooklynDslInterpreter());
  Object out = p.pdp().applyInterpreters(MutableMap.of("key", s1)).get("key");
  log.debug("parsed "+input+" as "+out+" ("+(out==null ? "null" : out.getClass())+")");
  return out;
}

代码示例来源:origin: org.apache.brooklyn/brooklyn-core

PlanInterpreterGuessingType guesser = new PlanInterpreterGuessingType(typeToValidate.getSymbolicName(), Iterables.getOnlyElement( Yamls.parseAll(yaml) ), 
  yaml, null, CatalogItemDtoAbstract.parseLibraries( typeToValidate.getLibraries() ), null);
guesser.reconstruct();

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com