All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.nosqlbench.engine.api.scenarios.WorkloadDesc Maven / Gradle / Ivy

Go to download

The engine API for nosqlbench; Provides the interfaces needed to build internal modules for the nosqlbench core engine

There is a newer version: 5.17.0
Show newest version
package io.nosqlbench.engine.api.scenarios;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Map;

public class WorkloadDesc implements Comparable {
    private final String yamlPath;
    private final List scenarioNames;
    private final Map templates;
    private final String description;

    public WorkloadDesc(String yamlPath,
                        List scenarioNames,
                        Map templates,
                        String description) {
        this.yamlPath = yamlPath;
        this.scenarioNames = scenarioNames;
        this.templates = templates;
        this.description = description;
    }

    public String getYamlPath() {
        return yamlPath;
    }

    public String getWorkloadName() {
        return getYamlPath().replaceAll("\\.yaml", "");
    }

    public List getScenarioNames() {
        return scenarioNames;
    }

    public Map getTemplates() {
        return templates;
    }

    public String getDescription() {
        return this.description != null ? this.description : "";
    }


    public String toString() {
        return toString(true);
    }

    public String toString(boolean includeScenarios) {

        StringBuilder sb = new StringBuilder();

        if (description.isEmpty()) {
            sb.append("# no description provided\n");
        }

        if (!description.isEmpty()) {
//            sb.append("# description:\n");
            String formttedDesc = "# " + String.join("\n# ",description.split("\n"));
            sb.append(formttedDesc).append("\n");
            while (sb.toString().endsWith("\n\n")) {
                sb.setLength(sb.length()-1);
            }
//            if (!description.endsWith("\n")) {
//                sb.append("\n");
//            }
        }

        if (includeScenarios) {
            sb.append("# workload found in in ");
        }
        sb.append(getYamlPath()).append("\n");


        if (includeScenarios) {
            sb.append("    # scenarios:\n");

            for (String scenario : getScenarioNames()) {
                sb.append("    nb ")
                    .append(this.getWorkloadName())
                    .append(" ").append(scenario).append("\n");
            }


            if (templates.size() > 0) {
                sb.append("        # defaults\n");
            }

            for (Map.Entry templateEntry : templates.entrySet()) {
                sb.append("        ")
                    .append(templateEntry.getKey()).append(" = ").append(templateEntry.getValue())
                    .append("\n");
            }
            sb.append("\n");
        }
        return sb.toString();

    }

    @Override
    public int compareTo(@NotNull WorkloadDesc o) {
        return this.yamlPath.compareTo(o.yamlPath);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy