gpt4 book ai didi

alien4cloud.utils.YamlParserUtil类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 00:23:31 26 4
gpt4 key购买 nike

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

YamlParserUtil介绍

[英]Utility to help parsing YAML files.
[中]帮助解析YAML文件的实用程序。

代码示例

代码示例来源:origin: alien4cloud/alien4cloud

private DefaultDeclarativeWorkflows loadDefaultDeclarativeWorkflow(String configName) throws IOException {
  return YamlParserUtil.parse(DefaultDeclarativeWorkflows.class.getClassLoader().getResourceAsStream(configName), DefaultDeclarativeWorkflows.class);
}

代码示例来源:origin: alien4cloud/alien4cloud

public static String dump(Object object) {
  return object == null ? null : (object instanceof Map ? dumpAsMap(object) : snakeYaml.dump(object));
}

代码示例来源:origin: alien4cloud/alien4cloud

/**
 * Parses a file to get a clazz parameter class
 * 
 * @param filePath The path of the file to load an parse.
 * @param clazz The return instance class
 * @return An instance of T.
 * @throws IOException In case jackson fails to read the json input stream to create an instance of T.
 */
public static <T> T parseFromUTF8File(String filePath, Class<T> clazz) throws IOException {
  Path path = Paths.get(filePath);
  return parseFromUTF8File(path, clazz);
}

代码示例来源:origin: alien4cloud/alien4cloud

@Override
@SneakyThrows
public void process(Csar csar, Topology topology, T operation) {
  // load if exists the corresponding variables file
  operation.setPath(getRelativeVariablesFilePath(operation));
  Map<String, Object> variables = loadVariables(EditionContextManager.get().getCsar().getId(), operation);
  // if the expression is empty, remove the var
  if (StringUtils.isBlank(operation.getExpression())) {
    // stop processing if the input is not yet preconfigured
    if (!variables.containsKey(operation.getName())) {
      return;
    }
    variables.remove(operation.getName());
  } else {
    // update the value of the variable
    variables.put(operation.getName(), YamlParserUtil.load(operation.getExpression()));
  }
  if (operation.getTempFileId() == null) {
    operation.setArtifactStream(new ByteArrayInputStream(YamlParserUtil.dumpAsMap(variables).getBytes(StandardCharsets.UTF_8)));
  }
  super.process(csar, topology, operation);
}

代码示例来源:origin: alien4cloud/alien4cloud

/**
 * Creates YAML object mapper
 * 
 * @return YAML object mapper
 */
public static ObjectMapper createYamlObjectMapper() {
  return newObjectMapper(new YAMLFactory());
}

代码示例来源:origin: alien4cloud/alien4cloud

@SneakyThrows
public <T extends AbstractDeploymentConfig> void save(T deploymentInputs) {
  Date now = new Date();
  if (deploymentInputs.getCreationDate() == null) {
    deploymentInputs.setCreationDate(now);
  }
  deploymentInputs.setLastUpdateDate(now);
  Path path = localGitRepositoryPathResolver.resolve(deploymentInputs.getClass(), deploymentInputs.getId());
  String yaml = YamlParserUtil.toYaml(deploymentInputs);
  Files.createDirectories(path.getParent());
  Files.write(path, yaml.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
}

代码示例来源:origin: alien4cloud/alien4cloud

private ScopeVariableExpressionDTO getScopeVariableExpressionDTO(String varName, String scopeId, String scopeName, Map<String, Object> variables) {
  ScopeVariableExpressionDTO dto = new ScopeVariableExpressionDTO();
  dto.setScopeId(scopeId);
  dto.setScopeName(scopeName);
  dto.setVariable(new Variable(varName, YamlParserUtil.dump(variables.get(varName))));
  return dto;
}

代码示例来源:origin: alien4cloud/alien4cloud

/**
 * Load the file from the given path and parse it's content into an instance of T.
 * 
 * @param filePath The path of the file to load an parse.
 * @param clazz The return instance class
 * @return An instance of T.
 * @throws IOException In case jackson fails to read the json input stream to create an instance of T.
 */
public static <T> T parseFromUTF8File(Path filePath, Class<T> clazz) throws IOException {
  InputStream input = Files.newInputStream(filePath);
  try {
    return parse(input, clazz);
  } finally {
    Closeables.close(input, true);
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

try {
  try {
    descriptor = YamlParserUtil.parseFromUTF8File(fs.getPath(PLUGIN_DESCRIPTOR_FILE), PluginDescriptor.class);
  } catch (IOException e) {
    if (e instanceof NoSuchFileException) {

代码示例来源:origin: alien4cloud/alien4cloud

/**
 * Rename the preconfigured input entry in the inputs file
 *
 * @param csar
 * @param topology
 * @param operation
 */
private void renamePreconfiguredInput(Csar csar, Topology topology, RenameInputOperation operation) {
  Map<String, Object> variables = editorFileService.loadInputsVariables(csar.getId());
  if (!variables.containsKey(operation.getInputName())) {
    return;
  }
  Object value = variables.remove(operation.getInputName());
  variables.put(operation.getNewInputName(), value);
  UpdateFileOperation updateFileOperation = new UpdateFileOperation(quickFileStorageService.getRelativeInputsFilePath(),
      new ByteArrayInputStream(YamlParserUtil.dumpAsMap(variables).getBytes(StandardCharsets.UTF_8)));
  updateFileProcessor.process(csar, topology, updateFileOperation);
}

代码示例来源:origin: alien4cloud/alien4cloud

@Override
public Date parse(String text) throws InvalidPropertyValueException {
  try {
    return YamlParserUtil.parse(text, Date.class);
  } catch (Exception e) {
    throw new InvalidPropertyValueException("Could not parse timestamp from value " + text, e);
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

try {
  try {
    descriptor = YamlParserUtil.parseFromUTF8File(fs.getPath(PLUGIN_DESCRIPTOR_FILE), PluginDescriptor.class);
  } catch (IOException e) {
    if (e instanceof NoSuchFileException) {

代码示例来源:origin: alien4cloud/alien4cloud

/**
 * This method load the defaults suggestions to ES.
 * 
 * @throws IOException
 */
@PostConstruct
public void loadDefaultSuggestions() throws IOException {
  try (InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream("suggestion-configuration.yml")) {
    SuggestionEntry[] suggestions = YamlParserUtil.parse(input, SuggestionEntry[].class);
    for (SuggestionEntry suggestionEntry : suggestions) {
      if (!isSuggestionExist(suggestionEntry)) {
        alienDAO.save(suggestionEntry);
        try {
          setSuggestionIdOnPropertyDefinition(suggestionEntry);
        } catch (Exception e) {
          log.warn(e.getClass().getName() + " : " + e.getMessage());
        }
      }
    }
  }
}

代码示例来源:origin: alien4cloud/alien4cloud

@SneakyThrows
public <T extends AbstractDeploymentConfig> T findById(Class<T> clazz, String id) {
  Path path = localGitRepositoryPathResolver.resolve(clazz, id);
  T config = null;
  if (Files.exists(path)) {
    byte[] bytes = Files.readAllBytes(path);
    if (ArrayUtils.isNotEmpty(bytes)) {
      config = YamlParserUtil.parse(new String(bytes, StandardCharsets.UTF_8), clazz);
    }
  } else {
    // Any data to migrate?
    config = alienDao.findById(clazz, id);
    if (config != null) {
      // migrating data from ES to Git
      save(config);
      alienDao.delete(clazz, id);
    }
  }
  return config;
}

代码示例来源:origin: alien4cloud/alien4cloud

@Test
  public void default_declarative_workflow_could_be_parsed_from_configuration() throws IOException {
    DefaultDeclarativeWorkflows defaultDeclarativeWorkflows = YamlParserUtil.parse(
        DefaultDeclarativeWorkflows.class.getClassLoader().getResourceAsStream("declarative-workflows-2.0.0.yml"), DefaultDeclarativeWorkflows.class);

    Assert.assertNotNull(defaultDeclarativeWorkflows.getNodeWorkflows());
    Assert.assertNotNull(defaultDeclarativeWorkflows.getRelationshipWorkflows());
    Assert.assertNotNull(defaultDeclarativeWorkflows.getRelationshipsWeaving());

    Assert.assertTrue(defaultDeclarativeWorkflows.getNodeWorkflows().containsKey(NormativeWorkflowNameConstants.INSTALL));
    Assert.assertTrue(defaultDeclarativeWorkflows.getRelationshipWorkflows().containsKey(NormativeWorkflowNameConstants.INSTALL));
    Assert.assertTrue(defaultDeclarativeWorkflows.getRelationshipsWeaving().containsKey(NormativeTypesConstant.ROOT_RELATIONSHIP_TYPE));
  }
}

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