From 00529f4594fda3bf6cd440ec00b7cfb1dec7c253 Mon Sep 17 00:00:00 2001 From: AndyYang Date: Wed, 12 Jun 2013 16:54:27 +0800 Subject: [PATCH 1/3] add heat API support --- .../org/openstack/glance/model/Image.java | 3 +- .../java/org/openstack/nova/NovaClient.java | 1 - .../nova/model/SimpleTenantUsage.java | 20 +++++++---- openstack-examples/pom.xml | 10 ++++++ .../examples/ExamplesConfiguration.java | 4 +-- .../examples/compute/NovaListFlavors.java | 4 +-- .../examples/compute/NovaListImages.java | 34 ++++++++++++++----- pom.xml | 2 ++ 8 files changed, 56 insertions(+), 22 deletions(-) diff --git a/glance-model/src/main/java/org/openstack/glance/model/Image.java b/glance-model/src/main/java/org/openstack/glance/model/Image.java index a05f1f0de..8c5a8c118 100644 --- a/glance-model/src/main/java/org/openstack/glance/model/Image.java +++ b/glance-model/src/main/java/org/openstack/glance/model/Image.java @@ -10,10 +10,9 @@ @JsonRootName("image") public class Image implements Serializable { - private String id; - private String uri; + private String uri; // private String name; diff --git a/nova-client/src/main/java/org/openstack/nova/NovaClient.java b/nova-client/src/main/java/org/openstack/nova/NovaClient.java index 495c9b2c1..5199c0cf6 100644 --- a/nova-client/src/main/java/org/openstack/nova/NovaClient.java +++ b/nova-client/src/main/java/org/openstack/nova/NovaClient.java @@ -11,5 +11,4 @@ public NovaClient(String endpointURL, String token) { public R execute(NovaCommand command) { return command.execute(create(endpointURL)); } - } diff --git a/nova-model/src/main/java/org/openstack/nova/model/SimpleTenantUsage.java b/nova-model/src/main/java/org/openstack/nova/model/SimpleTenantUsage.java index 9914f3b40..bdea302d9 100644 --- a/nova-model/src/main/java/org/openstack/nova/model/SimpleTenantUsage.java +++ b/nova-model/src/main/java/org/openstack/nova/model/SimpleTenantUsage.java @@ -2,6 +2,7 @@ import java.io.Serializable; import java.math.BigDecimal; +import java.util.List; import org.codehaus.jackson.annotate.JsonProperty; import org.codehaus.jackson.map.annotate.JsonRootName; @@ -27,6 +28,9 @@ public class SimpleTenantUsage implements Serializable { @JsonProperty("total_hours") private String totalHours; + + @JsonProperty("server_usages") + private List serverUsages; /** * @return the totalMemoryMbUsage @@ -126,9 +130,15 @@ public void setTotalHours(String totalHours) { this.totalHours = totalHours; } - /* (non-Javadoc) - * @see java.lang.Object#toString() - */ + + public List getServerUsages() { + return serverUsages; + } + + public void setServerUsages(List serverUsages) { + this.serverUsages = serverUsages; + } + @Override public String toString() { return "SimpleTenantUsage [totalMemoryMbUsage=" + totalMemoryMbUsage @@ -136,7 +146,5 @@ public String toString() { + ", totalLocalGbUsage=" + totalLocalGbUsage + ", start=" + start + ", stop=" + stop + ", tenantId=" + tenantId + ", totalHours=" + totalHours + "]"; - } - - + } } diff --git a/openstack-examples/pom.xml b/openstack-examples/pom.xml index 6e1680f08..34492b928 100644 --- a/openstack-examples/pom.xml +++ b/openstack-examples/pom.xml @@ -19,6 +19,11 @@ nova-client 2.0.0-SNAPSHOT + + org.openstack + glance-client + 2.0.0-SNAPSHOT + org.openstack swift-client @@ -34,5 +39,10 @@ ceilometer-client 2.0.0-SNAPSHOT + + org.openstack + heat-client + 2.0.0-SNAPSHOT + \ No newline at end of file diff --git a/openstack-examples/src/main/java/org/openstack/examples/ExamplesConfiguration.java b/openstack-examples/src/main/java/org/openstack/examples/ExamplesConfiguration.java index 9b64a4c39..c00f68618 100644 --- a/openstack-examples/src/main/java/org/openstack/examples/ExamplesConfiguration.java +++ b/openstack-examples/src/main/java/org/openstack/examples/ExamplesConfiguration.java @@ -2,11 +2,11 @@ public class ExamplesConfiguration { - public static final String KEYSTONE_AUTH_URL = "http://keystone/v2.0"; + public static final String KEYSTONE_AUTH_URL = "http://10.214.25.186:5000/v2.0"; public static final String KEYSTONE_USERNAME = "admin"; - public static final String KEYSTONE_PASSWORD = "secret0"; + public static final String KEYSTONE_PASSWORD = "jtang"; public static final String NOVA_ENDPOINT = ""; diff --git a/openstack-examples/src/main/java/org/openstack/examples/compute/NovaListFlavors.java b/openstack-examples/src/main/java/org/openstack/examples/compute/NovaListFlavors.java index 6e76934bf..a62f89e7d 100644 --- a/openstack-examples/src/main/java/org/openstack/examples/compute/NovaListFlavors.java +++ b/openstack-examples/src/main/java/org/openstack/examples/compute/NovaListFlavors.java @@ -49,8 +49,8 @@ public static void main(String[] args) { access = keystone.execute(new Authenticate(authentication)); - //NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); - NovaClient novaClient = new NovaClient(ExamplesConfiguration.NOVA_ENDPOINT.concat(tenants.getList().get(0).getId()), access.getToken().getId()); + NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); + //NovaClient novaClient = new NovaClient(ExamplesConfiguration.NOVA_ENDPOINT.concat(tenants.getList().get(0).getId()), access.getToken().getId()); novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); Flavors flavors = novaClient.execute(FlavorsCore.listFlavors(true)); diff --git a/openstack-examples/src/main/java/org/openstack/examples/compute/NovaListImages.java b/openstack-examples/src/main/java/org/openstack/examples/compute/NovaListImages.java index c76704c9a..9c9eb4e83 100644 --- a/openstack-examples/src/main/java/org/openstack/examples/compute/NovaListImages.java +++ b/openstack-examples/src/main/java/org/openstack/examples/compute/NovaListImages.java @@ -1,8 +1,18 @@ package org.openstack.examples.compute; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.util.logging.Logger; import org.openstack.examples.ExamplesConfiguration; +import org.openstack.glance.GlanceClient; +import org.openstack.glance.api.ListImages; +import org.openstack.glance.api.ShowImage; +import org.openstack.glance.api.UploadImage; +import org.openstack.glance.model.Image; +import org.openstack.glance.model.ImageForUpload; +import org.openstack.glance.model.Images; import org.openstack.keystone.KeystoneClient; import org.openstack.keystone.api.Authenticate; import org.openstack.keystone.api.ListTenants; @@ -11,19 +21,15 @@ import org.openstack.keystone.model.Authentication.PasswordCredentials; import org.openstack.keystone.model.Authentication.Token; import org.openstack.keystone.model.Tenants; -import org.openstack.keystone.utils.KeystoneUtils; -import org.openstack.nova.NovaClient; -import org.openstack.nova.api.ImagesCore; -import org.openstack.nova.model.Image; -import org.openstack.nova.model.Images; public class NovaListImages { /** * @param args + * @throws FileNotFoundException */ - public static void main(String[] args) { + public static void main(String[] args) throws FileNotFoundException { KeystoneClient keystone = new KeystoneClient(ExamplesConfiguration.KEYSTONE_AUTH_URL); Authentication authentication = new Authentication(); PasswordCredentials passwordCredentials = new PasswordCredentials(); @@ -51,13 +57,23 @@ public static void main(String[] args) { access = keystone.execute(new Authenticate(authentication)); //NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), access.getToken().getId()); - NovaClient novaClient = new NovaClient(ExamplesConfiguration.NOVA_ENDPOINT.concat(tenants.getList().get(0).getId()), access.getToken().getId()); - novaClient.enableLogging(Logger.getLogger("nova"), 100 * 1024); + GlanceClient glanceClient = new GlanceClient("http://10.214.25.186:9292/v1", access.getToken().getId()); + glanceClient.enableLogging(Logger.getLogger("glance"), 100 * 1024); - Images images = novaClient.execute(ImagesCore.listImages(true)); + Images images = glanceClient.execute(new ListImages(true)); for(Image image : images) { System.out.println(image); } + Image image = glanceClient.execute(new ShowImage(images.getList().get(0).getId())); + System.out.println(image); + + ImageForUpload upload = new ImageForUpload(); + upload.setName("test-image"); + upload.setPublic(true); + upload.setContainerFormat("bare"); + upload.setDiskFormat("qcow2"); + upload.setInputStream(new FileInputStream(new File("/opt/devstack-stable-grizzly/files/F16-i386-cfntools.qcow2"))); + glanceClient.execute(new UploadImage(upload)); } else { System.out.println("No tenants found!"); diff --git a/pom.xml b/pom.xml index 71a68cfc9..bdcd3b7bb 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,8 @@ quantum-model ceilometer-model ceilometer-client + heat-client + heat-model openstack-examples From ddaec0bac2c823bd48a9b921e069e55f87a47784 Mon Sep 17 00:00:00 2001 From: AndyYang Date: Wed, 12 Jun 2013 18:55:29 +0800 Subject: [PATCH 2/3] add heat support --- .gitignore | 3 +- heat-client/pom.xml | 24 +++ .../org/openstack/heat/client/HeatClient.java | 21 +++ .../openstack/heat/client/HeatCommand.java | 8 + .../heat/client/HeatResourcesPath.java | 7 + .../openstack/heat/client/api/EventsCore.java | 88 ++++++++++ .../heat/client/api/ResourcesCore.java | 51 ++++++ .../openstack/heat/client/api/StacksCore.java | 112 +++++++++++++ heat-model/pom.xml | 12 ++ .../java/org/openstack/heat/model/Event.java | 91 ++++++++++ .../java/org/openstack/heat/model/Events.java | 26 +++ .../java/org/openstack/heat/model/Link.java | 42 +++++ .../org/openstack/heat/model/Resource.java | 80 +++++++++ .../org/openstack/heat/model/Resources.java | 25 +++ .../java/org/openstack/heat/model/Stack.java | 139 ++++++++++++++++ .../openstack/heat/model/StackForCreate.java | 88 ++++++++++ .../java/org/openstack/heat/model/Stacks.java | 28 ++++ .../org/openstack/heat/model/Template.java | 5 + .../org/openstack/heat/model/stackforecreate | 156 ++++++++++++++++++ 19 files changed, 1005 insertions(+), 1 deletion(-) create mode 100644 heat-client/pom.xml create mode 100644 heat-client/src/main/java/org/openstack/heat/client/HeatClient.java create mode 100644 heat-client/src/main/java/org/openstack/heat/client/HeatCommand.java create mode 100644 heat-client/src/main/java/org/openstack/heat/client/HeatResourcesPath.java create mode 100644 heat-client/src/main/java/org/openstack/heat/client/api/EventsCore.java create mode 100644 heat-client/src/main/java/org/openstack/heat/client/api/ResourcesCore.java create mode 100644 heat-client/src/main/java/org/openstack/heat/client/api/StacksCore.java create mode 100644 heat-model/pom.xml create mode 100644 heat-model/src/main/java/org/openstack/heat/model/Event.java create mode 100644 heat-model/src/main/java/org/openstack/heat/model/Events.java create mode 100644 heat-model/src/main/java/org/openstack/heat/model/Link.java create mode 100644 heat-model/src/main/java/org/openstack/heat/model/Resource.java create mode 100644 heat-model/src/main/java/org/openstack/heat/model/Resources.java create mode 100644 heat-model/src/main/java/org/openstack/heat/model/Stack.java create mode 100644 heat-model/src/main/java/org/openstack/heat/model/StackForCreate.java create mode 100644 heat-model/src/main/java/org/openstack/heat/model/Stacks.java create mode 100644 heat-model/src/main/java/org/openstack/heat/model/Template.java create mode 100644 heat-model/src/main/java/org/openstack/heat/model/stackforecreate diff --git a/.gitignore b/.gitignore index 3eaf4eebb..5a3aac784 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .classpath .project .settings/ +*.json target/ bin/logs/ @@ -17,4 +18,4 @@ openstack-ui/src/main/webapp/WEB-INF/lib/ openstack-ui/.gwt/ openstack-ui/deploy.sh test-output/ -bin \ No newline at end of file +bin diff --git a/heat-client/pom.xml b/heat-client/pom.xml new file mode 100644 index 000000000..fd04b7c5f --- /dev/null +++ b/heat-client/pom.xml @@ -0,0 +1,24 @@ + + 4.0.0 + + org.openstack + openstack-java-sdk + 2.0.0-SNAPSHOT + + heat-client + OpenStack Heat Client + OpenStack Heat Client + + + org.openstack + openstack-client + 2.0.0-SNAPSHOT + + + org.openstack + heat-model + 2.0.0-SNAPSHOT + + + \ No newline at end of file diff --git a/heat-client/src/main/java/org/openstack/heat/client/HeatClient.java b/heat-client/src/main/java/org/openstack/heat/client/HeatClient.java new file mode 100644 index 000000000..fd67ba3d6 --- /dev/null +++ b/heat-client/src/main/java/org/openstack/heat/client/HeatClient.java @@ -0,0 +1,21 @@ +package org.openstack.heat.client; + +import javax.ws.rs.client.WebTarget; + +import org.openstack.OpenStack; +import org.openstack.common.client.AbstractOpenStackClient; + +public class HeatClient extends AbstractOpenStackClient{ + + public HeatClient(String endpointURL, String token) { + super(endpointURL, token); + } + + public R execute(HeatCommand command) { + WebTarget endpoint = OpenStack.CLIENT.target(endpointURL); + if(token != null) { + endpoint.register(tokenFilter); + } + return command.execute(endpoint); + } +} diff --git a/heat-client/src/main/java/org/openstack/heat/client/HeatCommand.java b/heat-client/src/main/java/org/openstack/heat/client/HeatCommand.java new file mode 100644 index 000000000..928fa6619 --- /dev/null +++ b/heat-client/src/main/java/org/openstack/heat/client/HeatCommand.java @@ -0,0 +1,8 @@ +package org.openstack.heat.client; + +import javax.ws.rs.client.WebTarget; + +public interface HeatCommand{ + + R execute(WebTarget endpoint); +} diff --git a/heat-client/src/main/java/org/openstack/heat/client/HeatResourcesPath.java b/heat-client/src/main/java/org/openstack/heat/client/HeatResourcesPath.java new file mode 100644 index 000000000..a4fbc3b69 --- /dev/null +++ b/heat-client/src/main/java/org/openstack/heat/client/HeatResourcesPath.java @@ -0,0 +1,7 @@ +package org.openstack.heat.client; + +public interface HeatResourcesPath { + String stackPath = "stacks"; + String resourcePath = "resources"; + String eventPath = "events"; +} diff --git a/heat-client/src/main/java/org/openstack/heat/client/api/EventsCore.java b/heat-client/src/main/java/org/openstack/heat/client/api/EventsCore.java new file mode 100644 index 000000000..9de73a0e1 --- /dev/null +++ b/heat-client/src/main/java/org/openstack/heat/client/api/EventsCore.java @@ -0,0 +1,88 @@ +package org.openstack.heat.client.api; + +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import org.openstack.heat.client.HeatCommand; +import org.openstack.heat.client.HeatResourcesPath; +import org.openstack.heat.model.Event; +import org.openstack.heat.model.Events; + +public class EventsCore { + + private static class ListStackEvents implements HeatCommand{ + private String stackID; + private String stackName; + + public ListStackEvents(String stackID, String stackName) { + super(); + this.stackID = stackID; + this.stackName = stackName; + } + + @Override + public Events execute(WebTarget endpoint) { + return endpoint.path(HeatResourcesPath.stackPath).path(stackName).path(stackID).path(HeatResourcesPath.eventPath) + .request(MediaType.APPLICATION_JSON).get(Events.class); + } + + } + + private static class ListResourceEvents implements HeatCommand{ + private String stackID; + private String stackName; + private String resourceName; + + public ListResourceEvents(String stackID, String stackName, + String resourceName) { + super(); + this.stackID = stackID; + this.stackName = stackName; + this.resourceName = resourceName; + } + + @Override + public Events execute(WebTarget endpoint) { + return endpoint.path(HeatResourcesPath.stackPath).path(stackName).path(stackID). + path(HeatResourcesPath.resourcePath).path(resourceName).path(HeatResourcesPath.eventPath) + .request(MediaType.APPLICATION_JSON).get(Events.class); + } + + } + + private static class ShowEvent implements HeatCommand{ + private String stackID; + private String stackName; + private String resourceName; + private String eventID; + + public ShowEvent(String stackID, String stackName, + String resourceName, String eventID) { + super(); + this.stackID = stackID; + this.stackName = stackName; + this.resourceName = resourceName; + this.eventID = eventID; + } + + @Override + public Event execute(WebTarget endpoint) { + return endpoint.path(HeatResourcesPath.stackPath).path(stackName).path(stackID). + path(HeatResourcesPath.resourcePath).path(resourceName). + path(HeatResourcesPath.eventPath).path(eventID) + .request(MediaType.APPLICATION_JSON).get(Event.class); + } + } + + public static HeatCommand listStackEvents(String stackID, String stackName){ + return new ListStackEvents(stackID, stackName); + } + + public static HeatCommand listResourceEvents(String stackID, String stackName, String resourceName){ + return new ListResourceEvents(stackID, stackName ,resourceName); + } + + public static HeatCommand showEvent(String stackID, String stackName, String resourceName, String eventID){ + return new ShowEvent(stackID, stackName ,resourceName, eventID); + } +} diff --git a/heat-client/src/main/java/org/openstack/heat/client/api/ResourcesCore.java b/heat-client/src/main/java/org/openstack/heat/client/api/ResourcesCore.java new file mode 100644 index 000000000..1e75959e4 --- /dev/null +++ b/heat-client/src/main/java/org/openstack/heat/client/api/ResourcesCore.java @@ -0,0 +1,51 @@ +package org.openstack.heat.client.api; + +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; + +import org.openstack.heat.client.HeatCommand; +import org.openstack.heat.model.Resource; +import org.openstack.heat.model.Resources; + +public class ResourcesCore { + private static final String stackPath = "stacks"; + private static final String resourcePath = "resources"; + + private static class ListResources implements HeatCommand{ + private String stackID; + + public ListResources(String stackID){ + this.stackID = stackID; + } + @Override + public Resources execute(WebTarget endpoint) { + return endpoint.path(stackPath).path(stackID).path(resourcePath) + .request(MediaType.APPLICATION_JSON).get(Resources.class); + } + } + + private static class ShowResource implements HeatCommand{ + private String stackID; + private String stackName; + private String resourceName; + + public ShowResource(String stackID ,String stackName, String resourceName){ + this.stackID = stackID; + this.stackName = stackName; + this.resourceName = resourceName; + } + @Override + public Resource execute(WebTarget endpoint) { + return endpoint.path(stackPath).path(stackName).path(stackID).path(resourcePath).path(resourceName) + .request(MediaType.APPLICATION_JSON).get(Resource.class); + } + } + + public static HeatCommand listResources(String stackID){ + return new ListResources(stackID); + } + + public static HeatCommand showResource(String stackID , String stackName, String resourceName){ + return new ShowResource(stackID, stackName, resourceName); + } +} diff --git a/heat-client/src/main/java/org/openstack/heat/client/api/StacksCore.java b/heat-client/src/main/java/org/openstack/heat/client/api/StacksCore.java new file mode 100644 index 000000000..e630a2d81 --- /dev/null +++ b/heat-client/src/main/java/org/openstack/heat/client/api/StacksCore.java @@ -0,0 +1,112 @@ +package org.openstack.heat.client.api; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.openstack.heat.client.HeatCommand; +import org.openstack.heat.client.HeatResourcesPath; +import org.openstack.heat.model.Stack; +import org.openstack.heat.model.StackForCreate; +import org.openstack.heat.model.Stacks; + +public class StacksCore { + + private static class ListStacks implements HeatCommand{ + + @Override + public Stacks execute(WebTarget endpoint) { + return endpoint.path(HeatResourcesPath.stackPath).request(MediaType.APPLICATION_JSON).get(Stacks.class); + } + + } + + private static class ShowStack implements HeatCommand{ + private String id; + + public ShowStack(String id){ + this.id = id; + } + + @Override + public Stack execute(WebTarget endpoint) { + return endpoint.path(HeatResourcesPath.stackPath).path(id).request(MediaType.APPLICATION_JSON).get(Stack.class); + } + } + + private static class CreateStack implements HeatCommand{ + private StackForCreate stackForCreate; + + public CreateStack(StackForCreate stackForCreate) { + super(); + this.stackForCreate = stackForCreate; + } + + @Override + public Response execute(WebTarget endpoint) { + return endpoint.path(HeatResourcesPath.stackPath).request(MediaType.TEXT_PLAIN) + .post(Entity.json(stackForCreate)); + } + + } + + private static class UpdateStack implements HeatCommand{ + private String stackName; + private String stackID; + private StackForCreate stackForCreate; + + public UpdateStack(String stackName, String stackID, + StackForCreate stackForCreate) { + super(); + this.stackName = stackName; + this.stackID = stackID; + this.stackForCreate = stackForCreate; + } + + + + @Override + public Response execute(WebTarget endpoint) { + return endpoint.path(HeatResourcesPath.stackPath).path(stackName).path(stackID) + .request(MediaType.TEXT_PLAIN).put(Entity.json(stackForCreate)); + } + + } + + private static class DeleteStack implements HeatCommand{ + private String id; + + public DeleteStack(String id) { + super(); + this.id = id; + } + + @Override + public Response execute(WebTarget endpoint) { + return endpoint.path(HeatResourcesPath.stackPath).path(id).request(MediaType.TEXT_PLAIN).delete(); + } + + } + + public static HeatCommand listStacks(){ + return new ListStacks(); + } + + public static HeatCommand showStack(String id){ + return new ShowStack(id); + } + + public static HeatCommand createStack(StackForCreate stackForCreate){ + return new CreateStack(stackForCreate); + } + + public static HeatCommand updateStack(String stackName, String stackID, + StackForCreate stackForCreate){ + return new UpdateStack(stackName,stackID,stackForCreate); + } + + public static HeatCommand deleteStack(String id){ + return new DeleteStack(id); + } +} diff --git a/heat-model/pom.xml b/heat-model/pom.xml new file mode 100644 index 000000000..c59dda365 --- /dev/null +++ b/heat-model/pom.xml @@ -0,0 +1,12 @@ + + 4.0.0 + + org.openstack + openstack-java-sdk + 2.0.0-SNAPSHOT + + heat-model + OpenStack Heat Model + OpenStack Heat Model + diff --git a/heat-model/src/main/java/org/openstack/heat/model/Event.java b/heat-model/src/main/java/org/openstack/heat/model/Event.java new file mode 100644 index 000000000..57ad8514f --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/Event.java @@ -0,0 +1,91 @@ +package org.openstack.heat.model; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonRootName; +@JsonRootName("event") +public class Event implements Serializable{ + private static final long serialVersionUID = 7779947747496478239L; + private String id; + @JsonProperty("resource_type") + private String resourceType; + @JsonProperty("physical_resource_id") + private String resourceID; + @JsonProperty("logical_resource_id") + private String resourceName; + @JsonProperty("resource_status") + private String resourceStatus; + @JsonProperty("resource_status_reason") + private String resourceStatusReason; + private List links; + @JsonProperty("event_time") + private String time; + @JsonProperty("resource_properties") + private Map resourceProperties; + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getResourceType() { + return resourceType; + } + public void setResourceType(String resourceType) { + this.resourceType = resourceType; + } + public String getResourceID() { + return resourceID; + } + public void setResourceID(String resourceID) { + this.resourceID = resourceID; + } + public String getResourceName() { + return resourceName; + } + public void setResourceName(String resourceName) { + this.resourceName = resourceName; + } + public String getResourceStatus() { + return resourceStatus; + } + public void setResourceStatus(String resourceStatus) { + this.resourceStatus = resourceStatus; + } + public String getResourceStatusReason() { + return resourceStatusReason; + } + public void setResourceStatusReason(String resourceStatusReason) { + this.resourceStatusReason = resourceStatusReason; + } + public List getLinks() { + return links; + } + public void setLinks(List links) { + this.links = links; + } + public String getTime() { + return time; + } + public void setTime(String time) { + this.time = time; + } + public Map getResourceProperties() { + return resourceProperties; + } + public void setResourceProperties(Map resourceProperties) { + this.resourceProperties = resourceProperties; + } + @Override + public String toString() { + return "event:{id=" + id + ", resourceType=" + resourceType + + ", resourceID=" + resourceID + ", resourceName=" + + resourceName + ", resourceStatus=" + resourceStatus + + ", resourceStatusReason=" + resourceStatusReason + ", links=" + + links + ", time=" + time + ", resourceProperties=" + + resourceProperties + "}"; + } +} diff --git a/heat-model/src/main/java/org/openstack/heat/model/Events.java b/heat-model/src/main/java/org/openstack/heat/model/Events.java new file mode 100644 index 000000000..49f60e765 --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/Events.java @@ -0,0 +1,26 @@ +package org.openstack.heat.model; + +import java.io.Serializable; +import java.util.Iterator; +import java.util.List; + +public class Events implements Iterable, Serializable{ + private static final long serialVersionUID = 2292730044135837499L; + private List events; + + + public List getEvents() { + return events; + } + + @Override + public Iterator iterator() { + return events.iterator(); + } + + @Override + public String toString() { + return "events:[" + events + "]"; + } + +} diff --git a/heat-model/src/main/java/org/openstack/heat/model/Link.java b/heat-model/src/main/java/org/openstack/heat/model/Link.java new file mode 100644 index 000000000..5a3b72ab1 --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/Link.java @@ -0,0 +1,42 @@ +package org.openstack.heat.model; + +import java.io.Serializable; + +public class Link implements Serializable { + + private String rel; + + private String href; + + private String type; + + /** + * @return the rel + */ + public String getRel() { + return rel; + } + + /** + * @return the href + */ + public String getHref() { + return href; + } + + /** + * @return the type + */ + public String getType() { + return type; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "Link:{rel=" + rel + ", href=" + href + ", type=" + type + "}"; + } + +} diff --git a/heat-model/src/main/java/org/openstack/heat/model/Resource.java b/heat-model/src/main/java/org/openstack/heat/model/Resource.java new file mode 100644 index 000000000..913e23b3b --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/Resource.java @@ -0,0 +1,80 @@ +package org.openstack.heat.model; + +import java.io.Serializable; +import java.util.List; + +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonRootName; +@JsonRootName("resource") +public class Resource implements Serializable { + private static final long serialVersionUID = 2242093632995902190L; + @JsonProperty("physical_resource_id") + private String id; + @JsonProperty("logical_resource_id") + private String name; + @JsonProperty("resource_status") + private String status; + @JsonProperty("resource_status_reason") + private String statusReason; + @JsonProperty("resource_type") + private String type; + @JsonProperty("updated_time") + private String updatedAt; + private String description; + private List links; + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + public String getStatusReason() { + return statusReason; + } + public void setStatusReason(String statusReason) { + this.statusReason = statusReason; + } + public String getType() { + return type; + } + public void setType(String type) { + this.type = type; + } + public String getUpdatedAt() { + return updatedAt; + } + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + public List getLinks() { + return links; + } + public void setLinks(List links) { + this.links = links; + } + @Override + public String toString() { + return "resource:{" + id + ", name=" + name + ", status=" + status + + ", statusReason=" + statusReason + ", type=" + type + + ", updatedAt=" + updatedAt + ", description=" + description + + ", links=" + links + "}"; + } +} diff --git a/heat-model/src/main/java/org/openstack/heat/model/Resources.java b/heat-model/src/main/java/org/openstack/heat/model/Resources.java new file mode 100644 index 000000000..69d141776 --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/Resources.java @@ -0,0 +1,25 @@ +package org.openstack.heat.model; + +import java.io.Serializable; +import java.util.Iterator; +import java.util.List; + +public class Resources implements Iterable, Serializable{ + private static final long serialVersionUID = 8535374527228144691L; + private List resources; + + + public List getResources() { + return resources; + } + + @Override + public Iterator iterator() { + return resources.iterator(); + } + + @Override + public String toString() { + return "resources:" + resources; + } +} diff --git a/heat-model/src/main/java/org/openstack/heat/model/Stack.java b/heat-model/src/main/java/org/openstack/heat/model/Stack.java new file mode 100644 index 000000000..74d9ca917 --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/Stack.java @@ -0,0 +1,139 @@ +package org.openstack.heat.model; + +import java.util.List; +import java.util.Map; + +import org.codehaus.jackson.annotate.JsonProperty; +import org.codehaus.jackson.map.annotate.JsonRootName; +@JsonRootName("stack") +public class Stack { + private String id; + @JsonProperty("stack_name") + private String name; + @JsonProperty("creation_time") + private String createdAt; + @JsonProperty("updated_time") + private String updatedAt; + @JsonProperty("stack_status") + private String status; + private List links; + @JsonProperty("stack_status_reason") + private String statusReason; + private String description; + + @JsonProperty("disable_rollback") + private boolean disableRollback; + private Map parameters; + private List> outputs; + private List capabilities; + @JsonProperty("notification_topics") + private List topics; + @JsonProperty("timeout_mins") + private int timeoutInMinute; + @JsonProperty("template_description") + private String templateDescription; + + public String getId() { + return id; + } + public void setId(String id) { + this.id = id; + } + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getCreatedAt() { + return createdAt; + } + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + public String getUpdatedAt() { + return updatedAt; + } + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + public String getStatus() { + return status; + } + public void setStatus(String status) { + this.status = status; + } + public String getDescription() { + return description; + } + public void setDescription(String description) { + this.description = description; + } + + public List getLinks() { + return links; + } + public void setLinks(List links) { + this.links = links; + } + public String getStatusReason() { + return statusReason; + } + public void setStatusReason(String statusReason) { + this.statusReason = statusReason; + } + + public boolean isDisableRollback() { + return disableRollback; + } + public void setDisableRollback(boolean disableRollback) { + this.disableRollback = disableRollback; + } + public Map getParameters() { + return parameters; + } + public void setParameters(Map parameters) { + this.parameters = parameters; + } + public List> getOutputs() { + return outputs; + } + public void setOutputs(List> outputs) { + this.outputs = outputs; + } + public List getCapabilities() { + return capabilities; + } + public void setCapabilities(List capabilities) { + this.capabilities = capabilities; + } + public List getTopics() { + return topics; + } + public void setTopics(List topics) { + this.topics = topics; + } + public int getTimeoutInMinute() { + return timeoutInMinute; + } + public void setTimeoutInMinute(int timeoutInMinute) { + this.timeoutInMinute = timeoutInMinute; + } + public String isTemplateDescription() { + return templateDescription; + } + public void setTemplateDescription(String templateDescription) { + this.templateDescription = templateDescription; + } + @Override + public String toString() { + return "stack:{id=" + id + ", name=" + name + ", createdAt=" + + createdAt + ", updatedAt=" + updatedAt + ", status=" + status + + ", links=" + links + ", statusReason=" + statusReason + + ", description=" + description + ", disableRollback=" + + disableRollback + ", parameters=" + parameters + ", outputs=" + + outputs + ", capabilities=" + capabilities + ", topics=" + + topics + ", timeoutInMinute=" + timeoutInMinute + + ", templateDescription=" + templateDescription + "}"; + } +} diff --git a/heat-model/src/main/java/org/openstack/heat/model/StackForCreate.java b/heat-model/src/main/java/org/openstack/heat/model/StackForCreate.java new file mode 100644 index 000000000..de1132dfb --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/StackForCreate.java @@ -0,0 +1,88 @@ +package org.openstack.heat.model; + +import java.util.HashMap; +import java.util.Map; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class StackForCreate { + @JsonProperty("stack_name") + private String name; + @JsonProperty("timeout_mins") + private String timeout; + //@JsonProperty("disable_rollback") + //private boolean disableRollback; + private String template; + private Map parameters; + + + public StackForCreate(String name, Map parameters, String template ,String keyName) { + super(); + this.name = name; + this.timeout = "10"; + //this.disableRollback = true; + this.parameters = new HashMap(parameters); + this.parameters.put("KeyName", keyName); + this.template = template; + } + + public StackForCreate(String name, String timeout, boolean disableRollback, + Map parameters, String template ,String keyName) { + super(); + this.name = name; + this.timeout = timeout; + //this.disableRollback = disableRollback; + this.parameters = new HashMap(parameters); + this.parameters.put("KeyName", keyName); + this.template = template; + } + + public String getName() { + return name; + } + public void setName(String name) { + this.name = name; + } + public String getTimeout() { + return timeout; + } + public void setTimeout(String timeout) { + this.timeout = timeout; + } +// public boolean isDisableRollback() { +// return disableRollback; +// } +// public void setDisableRollback(boolean disableRollback) { +// this.disableRollback = disableRollback; +// } + public Map getParameters() { + return parameters; + } + public void setParameters(Map parameters) { + this.parameters = parameters; + } + public void setKeyName(String keyName){ + this.parameters.put("KeyName", keyName); + } + public String getKeyName(){ + return this.parameters.get("KeyName"); + } + public void setInstanceType(String instanceType){ + this.parameters.put("InstanceType", instanceType); + } + public String getInstanceType(){ + return this.parameters.get("InstanceType"); + } + public String getTemplate() { + return template; + } + public void setTemplate(String template) { + this.template = template; + } + /*@Override + public String toString() { + return "{name=" + name + ", timeout=" + timeout + + ", disableRollback=" + disableRollback + ", parameters=" + + parameters + ", template=" + template + "}"; + }*/ +} diff --git a/heat-model/src/main/java/org/openstack/heat/model/Stacks.java b/heat-model/src/main/java/org/openstack/heat/model/Stacks.java new file mode 100644 index 000000000..97045a517 --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/Stacks.java @@ -0,0 +1,28 @@ +package org.openstack.heat.model; + +import java.io.Serializable; +import java.util.Iterator; +import java.util.List; + +import org.codehaus.jackson.annotate.JsonProperty; + +public class Stacks implements Iterable, Serializable{ + private static final long serialVersionUID = 4326257588956065394L; + @JsonProperty("stacks") + private List stacks; + + + public List getStacks() { + return stacks; + } + + @Override + public Iterator iterator() { + return stacks.iterator(); + } + + @Override + public String toString() { + return "stacks:" + stacks; + } +} diff --git a/heat-model/src/main/java/org/openstack/heat/model/Template.java b/heat-model/src/main/java/org/openstack/heat/model/Template.java new file mode 100644 index 000000000..566bd76e2 --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/Template.java @@ -0,0 +1,5 @@ +package org.openstack.heat.model; + +public class Template { + +} diff --git a/heat-model/src/main/java/org/openstack/heat/model/stackforecreate b/heat-model/src/main/java/org/openstack/heat/model/stackforecreate new file mode 100644 index 000000000..3889ace32 --- /dev/null +++ b/heat-model/src/main/java/org/openstack/heat/model/stackforecreate @@ -0,0 +1,156 @@ +{ + "stack_name": "test_stack", + "template": { + "AWSTemplateFormatVersion" : "2010-09-09", + + "Description" : "AWS CloudFormation Sample Template WordPress_Single_Instance: WordPress is web software you can use to create a beautiful website or blog. This template installs a single-instance WordPress deployment using a local MySQL database to store the data.", + + "Parameters" : { + + "KeyName" : { + "Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances", + "Type" : "String" + }, + + "InstanceType" : { + "Description" : "WebServer EC2 instance type", + "Type" : "String", + "Default" : "m1.small", + "AllowedValues" : [ "t1.micro", "m1.small", "m1.large", "m1.xlarge", "m2.xlarge", "m2.2xlarge", "m2.4xlarge", "c1.medium", "c1.xlarge", "cc1.4xlarge" ], + "ConstraintDescription" : "must be a valid EC2 instance type." + }, + + "DBName": { + "Default": "wordpress", + "Description" : "The WordPress database name", + "Type": "String", + "MinLength": "1", + "MaxLength": "64", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBUsername": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account username", + "Type": "String", + "MinLength": "1", + "MaxLength": "16", + "AllowedPattern" : "[a-zA-Z][a-zA-Z0-9]*", + "ConstraintDescription" : "must begin with a letter and contain only alphanumeric characters." + }, + + "DBPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "The WordPress database admin account password", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + + "DBRootPassword": { + "Default": "admin", + "NoEcho": "true", + "Description" : "Root password for MySQL", + "Type": "String", + "MinLength": "1", + "MaxLength": "41", + "AllowedPattern" : "[a-zA-Z0-9]*", + "ConstraintDescription" : "must contain only alphanumeric characters." + }, + "LinuxDistribution": { + "Default": "F17", + "Description" : "Distribution of choice", + "Type": "String", + "AllowedValues" : [ "F16", "F17", "U10", "RHEL-6.1", "RHEL-6.2", "RHEL-6.3" ] + } + }, + + "Mappings" : { + "AWSInstanceType2Arch" : { + "t1.micro" : { "Arch" : "32" }, + "m1.small" : { "Arch" : "32" }, + "m1.large" : { "Arch" : "64" }, + "m1.xlarge" : { "Arch" : "64" }, + "m2.xlarge" : { "Arch" : "64" }, + "m2.2xlarge" : { "Arch" : "64" }, + "m2.4xlarge" : { "Arch" : "64" }, + "c1.medium" : { "Arch" : "32" }, + "c1.xlarge" : { "Arch" : "64" }, + "cc1.4xlarge" : { "Arch" : "64" } + }, + "DistroArch2AMI": { + "F16" : { "32" : "F16-i386-cfntools", "64" : "F16-x86_64-cfntools" }, + "F17" : { "32" : "F17-i386-cfntools", "64" : "F17-x86_64-cfntools" }, + "U10" : { "32" : "U10-i386-cfntools", "64" : "U10-x86_64-cfntools" }, + "RHEL-6.1" : { "32" : "rhel61-i386-cfntools", "64" : "rhel61-x86_64-cfntools" }, + "RHEL-6.2" : { "32" : "rhel62-i386-cfntools", "64" : "rhel62-x86_64-cfntools" }, + "RHEL-6.3" : { "32" : "rhel63-i386-cfntools", "64" : "rhel63-x86_64-cfntools" } + } + }, + + "Resources" : { + "WikiDatabase": { + "Type": "AWS::EC2::Instance", + "Metadata" : { + "AWS::CloudFormation::Init" : { + "config" : { + "packages" : { + "yum" : { + "mysql" : [], + "mysql-server" : [], + "httpd" : [], + "wordpress" : [] + } + }, + "services" : { + "systemd" : { + "mysqld" : { "enabled" : "true", "ensureRunning" : "true" }, + "httpd" : { "enabled" : "true", "ensureRunning" : "true" } + } + } + } + } + }, + "Properties": { + "ImageId" : { "Fn::FindInMap" : [ "DistroArch2AMI", { "Ref" : "LinuxDistribution" }, + { "Fn::FindInMap" : [ "AWSInstanceType2Arch", { "Ref" : "InstanceType" }, "Arch" ] } ] }, + "InstanceType" : { "Ref" : "InstanceType" }, + "KeyName" : { "Ref" : "KeyName" }, + "UserData" : { "Fn::Base64" : { "Fn::Join" : ["", [ + "#!/bin/bash -v\n", + "/opt/aws/bin/cfn-init\n", + "# Setup MySQL root password and create a user\n", + "mysqladmin -u root password '", { "Ref" : "DBRootPassword" }, "'\n", + "cat << EOF | mysql -u root --password='", { "Ref" : "DBRootPassword" }, "'\n", + "CREATE DATABASE ", { "Ref" : "DBName" }, ";\n", + "GRANT ALL PRIVILEGES ON ", { "Ref" : "DBName" }, ".* TO \"", { "Ref" : "DBUsername" }, "\"@\"localhost\"\n", + "IDENTIFIED BY \"", { "Ref" : "DBPassword" }, "\";\n", + "FLUSH PRIVILEGES;\n", + "EXIT\n", + "EOF\n", + "sed --in-place --e s/database_name_here/", { "Ref" : "DBName" }, "/ --e s/username_here/", { "Ref" : "DBUsername" }, "/ --e s/password_here/", { "Ref" : "DBPassword" }, "/ /usr/share/wordpress/wp-config.php\n" + ]]}} + } + } + }, + + "Outputs" : { + "WebsiteURL" : { + "Value" : { "Fn::Join" : ["", ["http://", { "Fn::GetAtt" : [ "WikiDatabase", "PublicIp" ]}, "/wordpress"]] }, + "Description" : "URL for Wordpress wiki" + } + } +}, + "parameters": { + "InstanceType": "m1.small", + "DBUsername": "jtang", + "DBPassword": "jtang", + "KeyName": "heatKey" + }, + "timeout_mins": 5 +} \ No newline at end of file From 455b005643d3cf76f1efecf72dabaf02bc415efd Mon Sep 17 00:00:00 2001 From: AndyYang Date: Wed, 12 Jun 2013 19:30:15 +0800 Subject: [PATCH 3/3] add tenant usage support --- .../src/main/java/org/openstack/glance/model/Image.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glance-model/src/main/java/org/openstack/glance/model/Image.java b/glance-model/src/main/java/org/openstack/glance/model/Image.java index 8c5a8c118..1915f0935 100644 --- a/glance-model/src/main/java/org/openstack/glance/model/Image.java +++ b/glance-model/src/main/java/org/openstack/glance/model/Image.java @@ -12,7 +12,7 @@ public class Image implements Serializable { private String id; - private String uri; // + private String uri; private String name;