Skip to content

Commit e9a9f6c

Browse files
committed
Merge pull request #133 from chilicat/heat
Add Heat Functionality
2 parents f1763a1 + 447aa15 commit e9a9f6c

File tree

15 files changed

+682
-0
lines changed

15 files changed

+682
-0
lines changed

heat-client/pom.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.woorea</groupId>
5+
<artifactId>openstack-java-sdk</artifactId>
6+
<version>3.2.2-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>heat-client</artifactId>
9+
<name>OpenStack Heat Client</name>
10+
<description>OpenStack Heat Client</description>
11+
<dependencies>
12+
<dependency>
13+
<groupId>com.woorea</groupId>
14+
<artifactId>openstack-client</artifactId>
15+
<version>3.2.2-SNAPSHOT</version>
16+
</dependency>
17+
18+
<dependency>
19+
<groupId>com.woorea</groupId>
20+
<artifactId>heat-model</artifactId>
21+
<version>3.2.2-SNAPSHOT</version>
22+
</dependency>
23+
</dependencies>
24+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.woorea.openstack.heat;
2+
3+
import com.woorea.openstack.base.client.OpenStackClient;
4+
import com.woorea.openstack.base.client.OpenStackClientConnector;
5+
6+
/**
7+
* Reference: http://api.openstack.org/api-ref-orchestration.html
8+
*/
9+
public class Heat extends OpenStackClient {
10+
11+
private final StackResource stacks;
12+
private final ResourcesResource resources;
13+
14+
public Heat(String endpoint, OpenStackClientConnector connector) {
15+
super(endpoint, connector);
16+
stacks = new StackResource(this);
17+
resources = new ResourcesResource(this);
18+
}
19+
20+
public Heat(String endpoint) {
21+
this(endpoint, null);
22+
}
23+
24+
public StackResource getStacks() {
25+
return stacks;
26+
}
27+
28+
public ResourcesResource getResources() {
29+
return resources;
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.woorea.openstack.heat;
2+
3+
import com.woorea.openstack.base.client.HttpMethod;
4+
import com.woorea.openstack.base.client.OpenStackClient;
5+
import com.woorea.openstack.base.client.OpenStackRequest;
6+
import com.woorea.openstack.heat.model.Resources;
7+
8+
9+
/**
10+
* v1/​{tenant_id}​/stacks/​{stack_name}​/resources
11+
*/
12+
public class ResourcesResource {
13+
private final OpenStackClient client;
14+
15+
public ResourcesResource(OpenStackClient client) {
16+
this.client = client;
17+
}
18+
19+
public ListResources listResources(String name) {
20+
return new ListResources(name);
21+
}
22+
23+
/**
24+
* v1/​{tenant_id}​/stacks/​{stack_name}​/resources
25+
*/
26+
public class ListResources extends OpenStackRequest<Resources> {
27+
public ListResources(String name) {
28+
super(client, HttpMethod.GET, "/stacks/" + name + "/resources", null, Resources.class);
29+
}
30+
}
31+
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package com.woorea.openstack.heat;
2+
3+
import com.woorea.openstack.base.client.Entity;
4+
import com.woorea.openstack.base.client.HttpMethod;
5+
import com.woorea.openstack.base.client.OpenStackClient;
6+
import com.woorea.openstack.base.client.OpenStackRequest;
7+
import com.woorea.openstack.heat.model.CreateStackParam;
8+
import com.woorea.openstack.heat.model.Stack;
9+
import com.woorea.openstack.heat.model.Stacks;
10+
11+
public class StackResource {
12+
13+
private final OpenStackClient client;
14+
15+
public StackResource(OpenStackClient client) {
16+
this.client = client;
17+
}
18+
19+
public CreateStack create(CreateStackParam param) {
20+
return new CreateStack(param);
21+
}
22+
23+
public List list() {
24+
return new List();
25+
}
26+
27+
public GetStack byName(String name) {
28+
return new GetStack(name);
29+
}
30+
31+
public DeleteStack deleteByName(String name) {
32+
return new DeleteStack(name);
33+
}
34+
35+
public class CreateStack extends OpenStackRequest<Stack> {
36+
public CreateStack(CreateStackParam params) {
37+
super(client, HttpMethod.POST, "/stacks", Entity.json(params), Stack.class);
38+
}
39+
}
40+
41+
public class DeleteStack extends OpenStackRequest<Void> {
42+
public DeleteStack(String name) {
43+
super(client, HttpMethod.DELETE, "/stacks/" + name, null, Void.class);
44+
}
45+
}
46+
47+
48+
public class GetStack extends OpenStackRequest<Stack> {
49+
public GetStack(String name) {
50+
super(client, HttpMethod.GET, "/stacks/" + name, null, Stack.class);
51+
}
52+
}
53+
54+
public class List extends OpenStackRequest<Stacks> {
55+
public List() {
56+
super(client, HttpMethod.GET, "/stacks", null, Stacks.class);
57+
}
58+
}
59+
60+
61+
}

heat-model/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2+
<modelVersion>4.0.0</modelVersion>
3+
<parent>
4+
<groupId>com.woorea</groupId>
5+
<artifactId>openstack-java-sdk</artifactId>
6+
<version>3.2.2-SNAPSHOT</version>
7+
</parent>
8+
<artifactId>heat-model</artifactId>
9+
<name>OpenStack Heat Model</name>
10+
<description>OpenStack Heat Model</description>
11+
</project>
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package com.woorea.openstack.heat.model;
2+
3+
import org.codehaus.jackson.annotate.JsonProperty;
4+
5+
import java.util.Map;
6+
7+
public class CreateStackParam {
8+
@JsonProperty("stack_name")
9+
private String stackName;
10+
11+
@JsonProperty("template_url")
12+
private String templateUrl;
13+
14+
@JsonProperty
15+
private String template;
16+
17+
@JsonProperty("parameters")
18+
private Map<String, String> parameters;
19+
20+
@JsonProperty("timeout_mins")
21+
private int timeoutMinutes;
22+
23+
@JsonProperty("environment")
24+
private String environment;
25+
26+
public String getStackName() {
27+
return stackName;
28+
}
29+
30+
public void setStackName(String stackName) {
31+
this.stackName = stackName;
32+
}
33+
34+
public String getTemplateUrl() {
35+
return templateUrl;
36+
}
37+
38+
/**
39+
* The URL of the template to instantiate. This value is ignored if the template is supplied inline.
40+
*
41+
* @param templateUrl a template url.
42+
*/
43+
public void setTemplateUrl(String templateUrl) {
44+
this.templateUrl = templateUrl;
45+
}
46+
47+
public Map<String, String> getParameters() {
48+
return parameters;
49+
}
50+
51+
public String getTemplate() {
52+
return template;
53+
}
54+
55+
/**
56+
* A JSON template to instantiate. This value takes precedence over the template URL if both are supplied.
57+
*
58+
* @param template a template json.
59+
*/
60+
public void setTemplate(String template) {
61+
this.template = template;
62+
}
63+
64+
public void setParameters(Map<String, String> parameters) {
65+
this.parameters = parameters;
66+
}
67+
68+
public int getTimeoutMinutes() {
69+
return timeoutMinutes;
70+
}
71+
72+
public void setTimeoutMinutes(int timeoutMinutes) {
73+
this.timeoutMinutes = timeoutMinutes;
74+
}
75+
76+
public String getEnvironment() {
77+
return environment;
78+
}
79+
80+
/**
81+
* A JSON environment for the stack.
82+
*
83+
* @param environment a environment.
84+
*/
85+
public void setEnvironment(String environment) {
86+
this.environment = environment;
87+
}
88+
89+
@Override
90+
public String toString() {
91+
return "CreateStackParam{" +
92+
"stackName='" + stackName + '\'' +
93+
", templateUrl='" + templateUrl + '\'' +
94+
", template='" + template + '\'' +
95+
", parameters=" + parameters +
96+
", timeoutMinutes=" + timeoutMinutes +
97+
", environment='" + environment + '\'' +
98+
'}';
99+
}
100+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.woorea.openstack.heat.model;
2+
3+
import org.codehaus.jackson.annotate.JsonProperty;
4+
import org.codehaus.jackson.map.annotate.JsonRootName;
5+
6+
@JsonRootName("error")
7+
public class Explanation {
8+
@JsonProperty("explanation")
9+
private String explanation;
10+
11+
@JsonProperty("code")
12+
private int code;
13+
14+
@JsonRootName("error")
15+
public static class Error {
16+
@JsonProperty("message")
17+
private String message;
18+
19+
@JsonProperty("traceback")
20+
private String traceback;
21+
22+
@JsonProperty("type")
23+
private String type;
24+
25+
@JsonProperty("title")
26+
private String title;
27+
}
28+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.woorea.openstack.heat.model;
2+
3+
import org.codehaus.jackson.annotate.JsonProperty;
4+
5+
public class Link {
6+
@JsonProperty("href")
7+
private String href;
8+
9+
@JsonProperty("rel")
10+
private String rel;
11+
12+
public String getHref() {
13+
return href;
14+
}
15+
16+
public void setHref(String href) {
17+
this.href = href;
18+
}
19+
20+
public String getRel() {
21+
return rel;
22+
}
23+
24+
public void setRel(String rel) {
25+
this.rel = rel;
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return "Link{" +
31+
"href='" + href + '\'' +
32+
", rel='" + rel + '\'' +
33+
'}';
34+
}
35+
}

0 commit comments

Comments
 (0)