Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modify properties file to yaml file. #255

Merged
merged 18 commits into from
Mar 22, 2022
Merged

Conversation

HessTina-YuI
Copy link
Contributor

No description provided.

Copy link
Contributor

@Oseenix Oseenix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

final HashMap<String, String> propsMap = extractPropsMap(inputStream);
try (InputStream in = classLoader.getResourceAsStream(CONFIG_FILE)) {
if (in != null) {
final Map<String, String> propsMap = extractPropsMap(in);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. for CONFIG_FILE has been changed to 'agent.yaml', maybe the parse method should not be the extractPropsMap which is used to parse property file.
  2. the agent.yaml is not exist, could you help to generate it.

Oseenix and others added 3 commits March 21, 2022 16:49
# Conflicts:
#	build/src/main/resources/agent.yaml
#	config/src/main/java/com/megaease/easeagent/config/ConfigFactory.java
return new GlobalConfigs(map);
try (FileInputStream in = new FileInputStream(file)) {
Map<String, String> map;
if (file.getName().contains(".properties")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better as follows:

if (file.getName().endsWith(".properties")) {
    ////
} else if (file.getName().endsWith(".yaml") || file.getName().endsWith(".yml")) {
    ///
} else {
    LOGGER.warn("can not load config file: {}", file.getAbsolutePath());
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    private static boolean checkYaml(String filename) {
        return filename.endsWith(".yaml") || filename.endsWith(".yml");
    }

    private static GlobalConfigs loadFromClasspath(ClassLoader classLoader, String file) {
        try (InputStream in = classLoader.getResourceAsStream(file)) {
            if (in != null) {
                Map<String, String> map;
                if (checkYaml(file)) {
                    try {
                        map = new YamlReader().load(in).compress();
                    } catch (ParserException e) {
                        LOGGER.warn("Wrong Yaml format, load config file failure: {}", file);
                        map = Collections.emptyMap();
                    }
                } else {
                    map = extractPropsMap(in);
                }
                return new GlobalConfigs(map);
            }
        } catch (IOException e) {
            LOGGER.warn("Load config file:{} by classloader:{} failure: {}", file, classLoader.toString(), e);
        }

        return new GlobalConfigs(Collections.emptyMap());
    }

@Oseenix Oseenix merged commit 89855aa into megaease:master Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants