View Javadoc

1   package org.kuali.common.deploy.env.spring;
2   
3   import org.kuali.common.deploy.dns.model.DnsContext;
4   import org.kuali.common.deploy.dns.model.DnsUtils;
5   import org.kuali.common.deploy.env.model.DeployEnvironment;
6   import org.kuali.common.util.Assert;
7   import org.kuali.common.util.project.model.Project;
8   import org.kuali.common.util.project.spring.AutowiredProjectConfig;
9   import org.kuali.common.util.spring.env.EnvironmentService;
10  import org.kuali.common.util.spring.service.SpringServiceConfig;
11  import org.springframework.beans.factory.annotation.Autowired;
12  import org.springframework.context.annotation.Configuration;
13  import org.springframework.context.annotation.Import;
14  
15  @Configuration
16  @Import({ SpringServiceConfig.class, AutowiredProjectConfig.class })
17  public class DefaultDeployEnvironmentConfig implements DeployEnvironmentConfig {
18  
19  	public static final String KUALI_DOMAIN = "kuali.org";
20  
21  	private final String DOMAIN_KEY = "dns.domain";
22  	private final String PREFIX_KEY = "dns.prefix";
23  	private final String SUBDOMAIN_KEY = "dns.subdomain";
24  	private final String HOSTNAME_KEY = "dns.hostname";
25  
26  	private final String GROUP_ID_CODE_KEY = "project.groupId.code";
27  	private final String SEQUENCE_KEY = "deploy.env";
28  	private final String NAME_KEY = "deploy.env.name";
29  
30  	private final String DEFAULT_ENV_PREFIX = "env";
31  
32  	@Autowired
33  	EnvironmentService env;
34  
35  	@Autowired
36  	Project project;
37  
38  	@Override
39  	public DeployEnvironment deployEnvironment() {
40  		int sequence = env.getInteger(SEQUENCE_KEY); // No default value, they must supply "deploy.env"
41  		String defaultName = DEFAULT_ENV_PREFIX + sequence;
42  		String name = env.getString(NAME_KEY, defaultName);
43  		DnsContext dns = getDnsContext(name);
44  		return new DeployEnvironment(project.getGroupId(), sequence, name, dns);
45  	}
46  
47  	protected DnsContext getDnsContext(String name) {
48  		String prefix = env.getString(PREFIX_KEY, name);
49  		String defaultSubdomain = project.getProperties().getProperty(GROUP_ID_CODE_KEY);
50  		Assert.noBlanks(defaultSubdomain);
51  		String subdomain = env.getString(SUBDOMAIN_KEY, defaultSubdomain);
52  		String domain = env.getString(DOMAIN_KEY, KUALI_DOMAIN);
53  		String defaultHostname = DnsUtils.getHostname(prefix, subdomain, domain);
54  		String hostname = env.getString(HOSTNAME_KEY, defaultHostname);
55  		return new DnsContext.Builder(prefix, subdomain, domain).hostname(hostname).build();
56  	}
57  }