Search in sources :

Example 1 with OutputListWriter

use of com.thoughtworks.go.api.base.OutputListWriter in project gocd by gocd.

the class EnvironmentsRepresenter method toJSON.

public static void toJSON(OutputListWriter writer, Collection<EnvironmentConfig> environments, AgentInstance agentInstance) {
    EnvironmentsConfig envConfigs = new EnvironmentsConfig();
    envConfigs.addAll(environments);
    Set<String> agentEnvAssociationFromDB = new HashSet<>(agentInstance.getAgent().getEnvironmentsAsList());
    Set<String> agentEnvAssociationFromConfigRepo = envConfigs.stream().filter(environmentConfig -> !environmentConfig.isLocal()).map(environmentConfig -> environmentConfig.name().toString()).collect(Collectors.toSet());
    Set<String> allAgentEnvAssociations = Sets.union(agentEnvAssociationFromDB, agentEnvAssociationFromConfigRepo);
    List<String> sortedEnvNames = allAgentEnvAssociations.stream().sorted().collect(toList());
    for (String envName : sortedEnvNames) {
        EnvironmentConfig envConfig = envConfigs.find(new CaseInsensitiveString(envName));
        if (envConfig != null) {
            writer.addChild((childWriter) -> {
                childWriter.add("name", envName);
                childWriter.addChild("origin", (originWriter) -> origin(originWriter, envConfig, agentInstance.getUuid()));
            });
        } else {
            writer.addChild((childWriter) -> {
                childWriter.add("name", envName);
                childWriter.addChild("origin", (originWriter) -> originWriter.add("type", "unknown"));
            });
        }
    }
}
Also used : OutputListWriter(com.thoughtworks.go.api.base.OutputListWriter) java.util(java.util) AgentInstance(com.thoughtworks.go.domain.AgentInstance) ConfigOrigin(com.thoughtworks.go.config.remote.ConfigOrigin) ExceptionUtils.bomb(com.thoughtworks.go.util.ExceptionUtils.bomb) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) OutputWriter(com.thoughtworks.go.api.base.OutputWriter) Collectors.toList(java.util.stream.Collectors.toList) EnvironmentsConfig(com.thoughtworks.go.config.EnvironmentsConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Routes(com.thoughtworks.go.spark.Routes) CurrentGoCDVersion.apiDocsUrl(com.thoughtworks.go.CurrentGoCDVersion.apiDocsUrl) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) EnvironmentConfig(com.thoughtworks.go.config.EnvironmentConfig) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentsConfig(com.thoughtworks.go.config.EnvironmentsConfig)

Aggregations

Sets (com.google.common.collect.Sets)1 CurrentGoCDVersion.apiDocsUrl (com.thoughtworks.go.CurrentGoCDVersion.apiDocsUrl)1 OutputListWriter (com.thoughtworks.go.api.base.OutputListWriter)1 OutputWriter (com.thoughtworks.go.api.base.OutputWriter)1 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 EnvironmentConfig (com.thoughtworks.go.config.EnvironmentConfig)1 EnvironmentsConfig (com.thoughtworks.go.config.EnvironmentsConfig)1 ConfigOrigin (com.thoughtworks.go.config.remote.ConfigOrigin)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 Routes (com.thoughtworks.go.spark.Routes)1 ExceptionUtils.bomb (com.thoughtworks.go.util.ExceptionUtils.bomb)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1