Permalink
Browse files

added support for grizzly latest changes in compute core, now logging…

… is disabled by default and must be enabled per client using enableLogging() method
  • Loading branch information...
1 parent 485589c commit fc68b83b41eff7291fadf100fa4f15ba4936ad3e @woorea committed Mar 3, 2013
Showing with 150 additions and 193 deletions.
  1. +1 −1 ceilometer-client/src/main/java/org/openstack/ceilometer/v2/api/MeterShow.java
  2. +1 −8 keystone-client/src/main/java/org/openstack/keystone/KeystoneClient.java
  3. +1 −8 nova-client/src/main/java/org/openstack/nova/NovaClient.java
  4. +13 −2 nova-model/src/main/java/org/openstack/nova/model/Image.java
  5. +22 −2 nova-model/src/main/java/org/openstack/nova/model/Server.java
  6. +0 −1 openstack-client/src/main/java/org/openstack/OpenStack.java
  7. +0 −52 openstack-client/src/main/java/org/openstack/ceilometer/client/CeilometerClient.java
  8. +23 −0 openstack-client/src/main/java/org/openstack/common/client/AbstractOpenStackClient.java
  9. +13 −0 openstack-examples/src/main/java/org/openstack/examples/ExamplesConfiguration.java
  10. +28 −27 openstack-examples/src/main/java/org/openstack/examples/compute/NovaCreateServer.java
  11. +10 −12 openstack-examples/src/main/java/org/openstack/examples/compute/NovaListFlavors.java
  12. +10 −11 openstack-examples/src/main/java/org/openstack/examples/compute/NovaListImages.java
  13. +10 −12 openstack-examples/src/main/java/org/openstack/examples/compute/NovaListServers.java
  14. +3 −9 openstack-examples/src/main/java/org/openstack/examples/keystone/KeystoneCreateTenant.java
  15. +4 −9 openstack-examples/src/main/java/org/openstack/examples/metering/TestAll.java
  16. +3 −10 openstack-examples/src/main/java/org/openstack/examples/network/QuantumListNetworks.java
  17. +3 −13 openstack-examples/src/main/java/org/openstack/examples/network/QuantumQueryNetworks.java
  18. +3 −9 openstack-examples/src/main/java/org/openstack/examples/objectstore/SwiftExample.java
  19. +2 −7 openstack-examples/src/main/java/org/openstack/examples/simple/OpenStackSimpleClient.java
@@ -14,7 +14,7 @@
private String name;
- public MeterShow id(String name) {
+ public MeterShow name(String name) {
this.name = name;
return this;
}
@@ -1,8 +1,5 @@
package org.openstack.keystone;
-import javax.ws.rs.client.WebTarget;
-
-import org.openstack.OpenStack;
import org.openstack.common.client.AbstractOpenStackClient;
public class KeystoneClient extends AbstractOpenStackClient {
@@ -16,11 +13,7 @@ public KeystoneClient(String endpointURL) {
}
public <R> R execute(KeystoneCommand<R> command) {
- WebTarget endpoint = OpenStack.CLIENT.target(endpointURL);
- if(token != null) {
- endpoint.register(tokenFilter);
- }
- return command.execute(endpoint);
+ return command.execute(create(endpointURL));
}
}
@@ -1,8 +1,5 @@
package org.openstack.nova;
-import javax.ws.rs.client.WebTarget;
-
-import org.openstack.OpenStack;
import org.openstack.common.client.AbstractOpenStackClient;
public class NovaClient extends AbstractOpenStackClient {
@@ -12,11 +9,7 @@ public NovaClient(String endpointURL, String token) {
}
public <R> R execute(NovaCommand<R> command) {
- WebTarget endpoint = OpenStack.CLIENT.target(endpointURL);
- if(token != null) {
- endpoint.register(tokenFilter);
- }
- return command.execute(endpoint);
+ return command.execute(create(endpointURL));
}
}
@@ -5,6 +5,7 @@
import java.util.List;
import java.util.Map;
+import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.map.annotate.JsonRootName;
@JsonRootName("image")
@@ -26,6 +27,9 @@
private Calendar updated;
+ @JsonProperty("OS-EXT-IMG-SIZE:size")
+ private Integer size;
+
private Map<String, String> metadata;
private List<Link> links;
@@ -150,6 +154,13 @@ public void setUpdated(Calendar updated) {
}
/**
+ * @return the size
+ */
+ public Integer getSize() {
+ return size;
+ }
+
+ /**
* @param metadata the metadata to set
*/
public void setMetadata(Map<String, String> metadata) {
@@ -178,8 +189,8 @@ public String toString() {
return "Image [id=" + id + ", status=" + status + ", name=" + name
+ ", progress=" + progress + ", minRam=" + minRam
+ ", minDisk=" + minDisk + ", created=" + created
- + ", updated=" + updated + ", metadata=" + metadata
- + ", links=" + links + "]";
+ + ", updated=" + updated + ", size=" + size + ", metadata="
+ + metadata + ", links=" + links + "]";
}
}
@@ -74,6 +74,8 @@ public String toString() {
private String message;
+ private String details;
+
private Calendar created;
/**
@@ -91,6 +93,13 @@ public String getMessage() {
}
/**
+ * @return the details
+ */
+ public String getDetails() {
+ return details;
+ }
+
+ /**
* @return the created
*/
public Calendar getCreated() {
@@ -166,6 +175,9 @@ public Calendar getCreated() {
@JsonProperty("OS-DCF:diskConfig")
private String diskConfig;
+ @JsonProperty("OS-EXT-AZ:availability_zone")
+ private String availabilityZone;
+
private String uuid;
private String adminPass;
@@ -374,6 +386,13 @@ public String getDiskConfig() {
}
/**
+ * @return the availabilityZone
+ */
+ public String getAvailabilityZone() {
+ return availabilityZone;
+ }
+
+ /**
* @return the uuid
*/
public String getUuid() {
@@ -404,8 +423,9 @@ public String toString() {
+ taskState + ", powerState=" + powerState + ", vmState="
+ vmState + ", host=" + host + ", instanceName=" + instanceName
+ ", hypervisorHostname=" + hypervisorHostname
- + ", diskConfig=" + diskConfig + ", uuid=" + uuid
- + ", adminPass=" + adminPass + "]";
+ + ", diskConfig=" + diskConfig + ", availabilityZone="
+ + availabilityZone + ", uuid=" + uuid + ", adminPass="
+ + adminPass + "]";
}
}
@@ -91,7 +91,6 @@ public void filter(ClientRequestContext requestContext) throws IOException {
}
});
- CLIENT.register(new LoggingFilter(Logger.getLogger("openstack"), true));
} catch(Exception e) {
throw new RuntimeException(e.getMessage(), e);
}
@@ -1,52 +0,0 @@
-//package org.openstack.ceilometer.client;
-//
-//import java.util.logging.Logger;
-//
-//import javax.ws.rs.client.Client;
-//import javax.ws.rs.client.ClientFactory;
-//import javax.ws.rs.client.WebTarget;
-//import javax.ws.rs.core.MediaType;
-//
-//import org.glassfish.jersey.filter.LoggingFilter;
-//import org.glassfish.jersey.media.json.JsonJacksonFeature;
-//import org.openstack.ceilometer.model.Extension;
-//import org.openstack.ceilometer.model.Extensions;
-//import org.openstack.ceilometer.model.MeterEvents;
-//import org.openstack.ceilometer.model.Projects;
-//import org.openstack.ceilometer.model.ResourceAggregations;
-//import org.openstack.ceilometer.model.Resources;
-//import org.openstack.ceilometer.model.Sources;
-//import org.openstack.ceilometer.model.Users;
-//import org.openstack.ceilometer.model.Version;
-//
-//public class CeilometerClient {
-//
-// public static void main(String[] args) {
-// Client client = ClientFactory.newClient();
-// client.configuration().register(new JsonJacksonFeature());
-// WebTarget endpoint = client.target("http://localhost:8989/v1");
-// endpoint.configuration().register(new LoggingFilter(Logger.getLogger("ceilometer"), true));
-//
-// //version
-// endpoint.request(MediaType.APPLICATION_XML).get(Version.class);
-// endpoint.path("extensions").request(MediaType.APPLICATION_XML).get(Extensions.class);
-// endpoint.path("extensions/alias").request(MediaType.APPLICATION_XML).get(Extension.class);
-// endpoint.path("sources").request(MediaType.APPLICATION_JSON).get(Sources.class);
-// endpoint.path("sources/source/list/resources").request(MediaType.APPLICATION_JSON).get(Resources.class);
-// endpoint.path("sources/source/users").request(MediaType.APPLICATION_JSON).get(Users.class);
-// endpoint.path("sources/source/users/2").request(MediaType.APPLICATION_JSON).get(MeterEvents.class);
-// endpoint.path("sources/source/users/2/meter").request(MediaType.APPLICATION_JSON).get(MeterEvents.class);
-// endpoint.path("sources/source/users/2/meter/volume").request(MediaType.APPLICATION_JSON).get(ResourceAggregations.class);
-// endpoint.path("sources/source/users/2/meter/duration").request(MediaType.APPLICATION_JSON).get(ResourceAggregations.class);
-// endpoint.path("sources/source/users/2/resources").request(MediaType.APPLICATION_JSON).get(Resources.class);
-// endpoint.path("sources/source/projects").request(MediaType.APPLICATION_JSON).get(Projects.class);
-// endpoint.path("sources/source/projects/1").request(MediaType.APPLICATION_JSON).get(MeterEvents.class);
-// endpoint.path("sources/source/projects/1/meter").request(MediaType.APPLICATION_JSON).get(MeterEvents.class);
-// endpoint.path("sources/source/projects/1/meter/volume").request(MediaType.APPLICATION_JSON).get(ResourceAggregations.class);
-// endpoint.path("sources/source/projects/1/meter/duration").request(MediaType.APPLICATION_JSON).get(ResourceAggregations.class);
-//
-// System.exit(0);
-//
-// }
-//
-//}
@@ -1,6 +1,7 @@
package org.openstack.common.client;
import java.io.IOException;
+import java.util.logging.Logger;
import javax.ws.rs.client.ClientRequestContext;
import javax.ws.rs.client.ClientRequestFilter;
@@ -9,6 +10,7 @@
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
+import org.glassfish.jersey.filter.LoggingFilter;
import org.openstack.OpenStack;
public class AbstractOpenStackClient {
@@ -17,6 +19,8 @@
protected String token;
+ protected LoggingFilter loggingFilter;
+
protected ClientRequestFilter tokenFilter = new ClientRequestFilter() {
@Override
@@ -53,6 +57,25 @@ public OpenStackRequest request(String uri) {
return request(uri, MediaType.APPLICATION_JSON);
}
+ protected WebTarget create(String endpoint) {
+ WebTarget target = OpenStack.CLIENT.target(endpoint);
+ if(loggingFilter != null) {
+ target.register(loggingFilter);
+ }
+ if(token != null) {
+ target.register(tokenFilter);
+ }
+ return target;
+ }
+
+ public void enableLogging(Logger logger, int entitySize) {
+ loggingFilter = new LoggingFilter(logger, entitySize);
+ }
+
+ public void disableLogging() {
+ loggingFilter = null;
+ }
+
public static class OpenStackRequest {
private Builder builder;
@@ -0,0 +1,13 @@
+package org.openstack.examples;
+
+public class ExamplesConfiguration {
+
+ public static final String KEYSTONE_AUTH_URL = "";
+
+ public static final String KEYSTONE_USERNAME = "admin";
+
+ public static final String KEYSTONE_PASSWORD = "secret0";
+
+ public static final String NOVA_ENDPOINT = "";
+
+}
@@ -1,39 +1,33 @@
package org.openstack.examples.compute;
+import java.util.logging.Logger;
+
+import org.openstack.examples.ExamplesConfiguration;
import org.openstack.keystone.KeystoneClient;
import org.openstack.keystone.api.Authenticate;
import org.openstack.keystone.api.ListTenants;
import org.openstack.keystone.model.Access;
-import org.openstack.keystone.model.Authentication;
-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.FlavorsCore;
+import org.openstack.nova.api.ImagesCore;
import org.openstack.nova.api.ServersCore;
import org.openstack.nova.api.extensions.KeyPairsExtension;
-import org.openstack.nova.api.extensions.SecurityGroupsExtension;
-import org.openstack.nova.model.KeyPair;
-import org.openstack.nova.model.SecurityGroup;
+import org.openstack.nova.model.Flavors;
+import org.openstack.nova.model.Images;
+import org.openstack.nova.model.KeyPairs;
import org.openstack.nova.model.Server;
import org.openstack.nova.model.ServerForCreate;
public class NovaCreateServer {
- private static final String KEYSTONE_AUTH_URL = "";
-
- private static final String KEYSTONE_USERNAME = "";
-
- private static final String KEYSTONE_PASSWORD = "";
-
-
/**
* @param args
*/
public static void main(String[] args) {
- KeystoneClient keystone = new KeystoneClient(KEYSTONE_AUTH_URL);
+ KeystoneClient keystone = new KeystoneClient(ExamplesConfiguration.KEYSTONE_AUTH_URL);
//access with unscoped token
- Access access = keystone.execute(Authenticate.withPasswordCredentials(KEYSTONE_USERNAME, KEYSTONE_PASSWORD));
+ Access access = keystone.execute(Authenticate.withPasswordCredentials(ExamplesConfiguration.KEYSTONE_USERNAME, ExamplesConfiguration.KEYSTONE_PASSWORD));
//use the token in the following requests
keystone.setToken(access.getToken().getId());
@@ -45,25 +39,32 @@ public static void main(String[] args) {
access = keystone.execute(Authenticate.withToken(access.getToken().getId()).withTenantId(tenants.getList().get(0).getId()));
- NovaClient novaClient = new NovaClient(KeystoneUtils.findEndpointURL(access.getServiceCatalog(), "compute", null, "public"), 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);
//create a new keypair
- KeyPair keyPair = novaClient.execute(KeyPairsExtension.createKeyPair("mykeypair"));
- System.out.println(keyPair.getPrivateKey());
+ //KeyPair keyPair = novaClient.execute(KeyPairsExtension.createKeyPair("mykeypair"));
+ //System.out.println(keyPair.getPrivateKey());
//create security group
- SecurityGroup securityGroup = novaClient.execute(SecurityGroupsExtension.createSecurityGroup("mysecuritygroup", "description"));
+ //SecurityGroup securityGroup = novaClient.execute(SecurityGroupsExtension.createSecurityGroup("mysecuritygroup", "description"));
+
+ //novaClient.execute(SecurityGroupsExtension.createSecurityGroupRule(securityGroup.getId(), "UDP", 9090, 9092, "0.0.0.0/0"));
+ //novaClient.execute(SecurityGroupsExtension.createSecurityGroupRule(securityGroup.getId(), "TCP", 8080, 8080, "0.0.0.0/0"));
+
+ KeyPairs keysPairs = novaClient.execute(KeyPairsExtension.listKeyPairs());
+
+ Images images = novaClient.execute(ImagesCore.listImages());
- novaClient.execute(SecurityGroupsExtension.createSecurityGroupRule(securityGroup.getId(), "UDP", 9090, 9092, "0.0.0.0/0"));
- novaClient.execute(SecurityGroupsExtension.createSecurityGroupRule(securityGroup.getId(), "TCP", 8080, 8080, "0.0.0.0/0"));
+ Flavors flavors = novaClient.execute(FlavorsCore.listFlavors());
ServerForCreate serverForCreate = new ServerForCreate();
serverForCreate.setName("woorea");
- serverForCreate.setFlavorRef("100");
- serverForCreate.setImageRef("120");
- serverForCreate.setKeyName("woorea");
+ serverForCreate.setFlavorRef(flavors.getList().get(0).getId());
+ serverForCreate.setImageRef(images.getList().get(1).getId());
+ serverForCreate.setKeyName(keysPairs.getList().get(0).getName());
serverForCreate.getSecurityGroups().add(new ServerForCreate.SecurityGroup("default"));
- serverForCreate.getSecurityGroups().add(new ServerForCreate.SecurityGroup(securityGroup.getName()));
+ //serverForCreate.getSecurityGroups().add(new ServerForCreate.SecurityGroup(securityGroup.getName()));
Server server = novaClient.execute(ServersCore.createServer(serverForCreate));
System.out.println(server);
Oops, something went wrong.

0 comments on commit fc68b83

Please sign in to comment.