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

Add Heat Functionality #133

Merged
merged 4 commits into from
Mar 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions heat-client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.woorea</groupId>
<artifactId>openstack-java-sdk</artifactId>
<version>3.2.2-SNAPSHOT</version>
</parent>
<artifactId>heat-client</artifactId>
<name>OpenStack Heat Client</name>
<description>OpenStack Heat Client</description>
<dependencies>
<dependency>
<groupId>com.woorea</groupId>
<artifactId>openstack-client</artifactId>
<version>3.2.2-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.woorea</groupId>
<artifactId>heat-model</artifactId>
<version>3.2.2-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
31 changes: 31 additions & 0 deletions heat-client/src/main/java/com/woorea/openstack/heat/Heat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.woorea.openstack.heat;

import com.woorea.openstack.base.client.OpenStackClient;
import com.woorea.openstack.base.client.OpenStackClientConnector;

/**
* Reference: http://api.openstack.org/api-ref-orchestration.html
*/
public class Heat extends OpenStackClient {

private final StackResource stacks;
private final ResourcesResource resources;

public Heat(String endpoint, OpenStackClientConnector connector) {
super(endpoint, connector);
stacks = new StackResource(this);
resources = new ResourcesResource(this);
}

public Heat(String endpoint) {
this(endpoint, null);
}

public StackResource getStacks() {
return stacks;
}

public ResourcesResource getResources() {
return resources;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.woorea.openstack.heat;

import com.woorea.openstack.base.client.HttpMethod;
import com.woorea.openstack.base.client.OpenStackClient;
import com.woorea.openstack.base.client.OpenStackRequest;
import com.woorea.openstack.heat.model.Resources;


/**
* v1/​{tenant_id}​/stacks/​{stack_name}​/resources
*/
public class ResourcesResource {
private final OpenStackClient client;

public ResourcesResource(OpenStackClient client) {
this.client = client;
}

public ListResources listResources(String name) {
return new ListResources(name);
}

/**
* v1/​{tenant_id}​/stacks/​{stack_name}​/resources
*/
public class ListResources extends OpenStackRequest<Resources> {
public ListResources(String name) {
super(client, HttpMethod.GET, "/stacks/" + name + "/resources", null, Resources.class);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.woorea.openstack.heat;

import com.woorea.openstack.base.client.Entity;
import com.woorea.openstack.base.client.HttpMethod;
import com.woorea.openstack.base.client.OpenStackClient;
import com.woorea.openstack.base.client.OpenStackRequest;
import com.woorea.openstack.heat.model.CreateStackParam;
import com.woorea.openstack.heat.model.Stack;
import com.woorea.openstack.heat.model.Stacks;

public class StackResource {

private final OpenStackClient client;

public StackResource(OpenStackClient client) {
this.client = client;
}

public CreateStack create(CreateStackParam param) {
return new CreateStack(param);
}

public List list() {
return new List();
}

public GetStack byName(String name) {
return new GetStack(name);
}

public DeleteStack deleteByName(String name) {
return new DeleteStack(name);
}

public class CreateStack extends OpenStackRequest<Stack> {
public CreateStack(CreateStackParam params) {
super(client, HttpMethod.POST, "/stacks", Entity.json(params), Stack.class);
}
}

public class DeleteStack extends OpenStackRequest<Void> {
public DeleteStack(String name) {
super(client, HttpMethod.DELETE, "/stacks/" + name, null, Void.class);
}
}


public class GetStack extends OpenStackRequest<Stack> {
public GetStack(String name) {
super(client, HttpMethod.GET, "/stacks/" + name, null, Stack.class);
}
}

public class List extends OpenStackRequest<Stacks> {
public List() {
super(client, HttpMethod.GET, "/stacks", null, Stacks.class);
}
}


}
11 changes: 11 additions & 0 deletions heat-model/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.woorea</groupId>
<artifactId>openstack-java-sdk</artifactId>
<version>3.2.2-SNAPSHOT</version>
</parent>
<artifactId>heat-model</artifactId>
<name>OpenStack Heat Model</name>
<description>OpenStack Heat Model</description>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.woorea.openstack.heat.model;

import org.codehaus.jackson.annotate.JsonProperty;

import java.util.Map;

public class CreateStackParam {
@JsonProperty("stack_name")
private String stackName;

@JsonProperty("template_url")
private String templateUrl;

@JsonProperty
private String template;

@JsonProperty("parameters")
private Map<String, String> parameters;

@JsonProperty("timeout_mins")
private int timeoutMinutes;

@JsonProperty("environment")
private String environment;

public String getStackName() {
return stackName;
}

public void setStackName(String stackName) {
this.stackName = stackName;
}

public String getTemplateUrl() {
return templateUrl;
}

/**
* The URL of the template to instantiate. This value is ignored if the template is supplied inline.
*
* @param templateUrl a template url.
*/
public void setTemplateUrl(String templateUrl) {
this.templateUrl = templateUrl;
}

public Map<String, String> getParameters() {
return parameters;
}

public String getTemplate() {
return template;
}

/**
* A JSON template to instantiate. This value takes precedence over the template URL if both are supplied.
*
* @param template a template json.
*/
public void setTemplate(String template) {
this.template = template;
}

public void setParameters(Map<String, String> parameters) {
this.parameters = parameters;
}

public int getTimeoutMinutes() {
return timeoutMinutes;
}

public void setTimeoutMinutes(int timeoutMinutes) {
this.timeoutMinutes = timeoutMinutes;
}

public String getEnvironment() {
return environment;
}

/**
* A JSON environment for the stack.
*
* @param environment a environment.
*/
public void setEnvironment(String environment) {
this.environment = environment;
}

@Override
public String toString() {
return "CreateStackParam{" +
"stackName='" + stackName + '\'' +
", templateUrl='" + templateUrl + '\'' +
", template='" + template + '\'' +
", parameters=" + parameters +
", timeoutMinutes=" + timeoutMinutes +
", environment='" + environment + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.woorea.openstack.heat.model;

import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonRootName;

@JsonRootName("error")
public class Explanation {
@JsonProperty("explanation")
private String explanation;

@JsonProperty("code")
private int code;

@JsonRootName("error")
public static class Error {
@JsonProperty("message")
private String message;

@JsonProperty("traceback")
private String traceback;

@JsonProperty("type")
private String type;

@JsonProperty("title")
private String title;
}
}
35 changes: 35 additions & 0 deletions heat-model/src/main/java/com/woorea/openstack/heat/model/Link.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.woorea.openstack.heat.model;

import org.codehaus.jackson.annotate.JsonProperty;

public class Link {
@JsonProperty("href")
private String href;

@JsonProperty("rel")
private String rel;

public String getHref() {
return href;
}

public void setHref(String href) {
this.href = href;
}

public String getRel() {
return rel;
}

public void setRel(String rel) {
this.rel = rel;
}

@Override
public String toString() {
return "Link{" +
"href='" + href + '\'' +
", rel='" + rel + '\'' +
'}';
}
}
Loading