Author: jjohnstn
Date: 2010-07-27 15:50:41 -0400 (Tue, 27 Jul 2010)
New Revision: 23751
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Property.java
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java
Log:
2010-07-27 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/Property.java: New file.
* src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
(getProfileProperties): Renamed
from setProfileProperties and cpu support added.
(buildDeltaCloudObject): Add support for HardwareProfile.
(buildHardwareProfile): New method to build up a hardware profile.
(buildInstance): Add hardware profile support.
(createInstance): Change to use getProfileProperties which was renamed.
* src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java (getArchitecture): New
method.
(getNamedProperty): Ditto.
(getCPU): Ditto.
(toString): Ditto.
(getProperties): Ditto.
(getMemory): Change to get the memory property.
(getStorage): Change to get the storage property.
(HardwareProfile): Make private.
* src/org/jboss/tools/deltacloud/core/client/Instance.java (setCPU): New method.
(getCPU): Ditto.
(toString): Add cpu support.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-07-27 18:57:21
UTC (rev 23750)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-07-27 19:50:41
UTC (rev 23751)
@@ -1,3 +1,24 @@
+2010-07-27 Jeff Johnston <jjohnstn(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/client/Property.java: New file.
+ * src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
(getProfileProperties): Renamed
+ from setProfileProperties and cpu support added.
+ (buildDeltaCloudObject): Add support for HardwareProfile.
+ (buildHardwareProfile): New method to build up a hardware profile.
+ (buildInstance): Add hardware profile support.
+ (createInstance): Change to use getProfileProperties which was renamed.
+ * src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java (getArchitecture): New
method.
+ (getNamedProperty): Ditto.
+ (getCPU): Ditto.
+ (toString): Ditto.
+ (getProperties): Ditto.
+ (getMemory): Change to get the memory property.
+ (getStorage): Change to get the storage property.
+ (HardwareProfile): Make private.
+ * src/org/jboss/tools/deltacloud/core/client/Instance.java (setCPU): New method.
+ (getCPU): Ditto.
+ (toString): Add cpu support.
+
2010-07-26 Jeff Johnston <jjohnstn(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/AddressList.java: New file.
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-07-27
18:57:21 UTC (rev 23750)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-07-27
19:50:41 UTC (rev 23751)
@@ -154,9 +154,9 @@
}
@Override
- public Instance createInstance(String imageId, String flavorId, String realmId, String
name) throws DeltaCloudClientException
+ public Instance createInstance(String imageId, String profileId, String realmId, String
name) throws DeltaCloudClientException
{
- String query = "?image_id=" + imageId + "&flavor_id=" +
flavorId + "&realm_id=" + realmId + "&name=" + name +
"&commit=create";
+ String query = "?image_id=" + imageId + "&hardware_profile_id="
+ profileId + "&realm_id=" + realmId + "&name=" + name +
"&commit=create";
return buildInstance(sendRequest(DCNS.INSTANCES + query, RequestType.POST));
}
@@ -245,7 +245,7 @@
instance.setImageId(getIdFromHref(getAttributeValues(document, "image",
"href").get(0)));
instance.setProfileId(getIdFromHref(getAttributeValues(document,
"hardware-profile", "href").get(0)));
- setProfileProperties(instance, getPropertyNodes(document,
"hardware-profile"));
+ getProfileProperties(instance, getPropertyNodes(document,
"hardware-profile"));
instance.setRealmId(getIdFromHref(getAttributeValues(document, "realm",
"href").get(0)));
instance.setState(getElementText(document, "state").get(0));
@@ -264,7 +264,62 @@
}
return null;
}
-
+
+ private HardwareProfile buildHardwareProfile(String xml)
+ {
+ try
+ {
+ HardwareProfile profile = JAXB.unmarshal(new StringReader(xml),
HardwareProfile.class);
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document document = db.parse(new InputSource(new StringReader(xml)));
+
+ List<Node> nodes = getPropertyNodes(document, "hardware-profile");
+
+ for (Node n : nodes) {
+ Property p = new Property();
+ p.setName(n.getAttributes().getNamedItem("name").getNodeValue());
+ p.setValue(n.getAttributes().getNamedItem("value").getNodeValue());
+ p.setUnit(n.getAttributes().getNamedItem("unit").getNodeValue());
+ p.setKind(n.getAttributes().getNamedItem("kind").getNodeValue());
+ if (p.getKind().equals("range")) {
+ NodeList children = n.getChildNodes();
+ for (int i = 0; i < children.getLength(); ++i) {
+ Node child = children.item(i);
+ if (child.getNodeName().equals("range")) {
+ String first =
child.getAttributes().getNamedItem("first").getNodeValue();
+ String last =
child.getAttributes().getNamedItem("last").getNodeValue();
+ p.setRange(first, last);
+ }
+ }
+ }
+ else if (p.getKind().equals("enum")) {
+ ArrayList<String> enums = new ArrayList<String>();
+ NodeList children = n.getChildNodes();
+ for (int i = 0; i < children.getLength(); ++i) {
+ Node child = children.item(i);
+ if (child.getNodeName().equals("enum")) {
+ NodeList enumChildren = child.getChildNodes();
+ for (int j = 0; j < enumChildren.getLength(); ++j) {
+ Node enumChild = enumChildren.item(j);
+ enums.add(enumChild.getAttributes().getNamedItem("value").getNodeValue());
+ }
+ }
+ }
+ p.setEnums(enums);
+ }
+ profile.getProperties().add(p);
+ }
+ return profile;
+ }
+ catch(Exception e)
+ {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
private List<String> getAttributeValues(Document document, String elementName,
String attributeName)
{
NodeList elements = document.getElementsByTagName(elementName);
@@ -305,7 +360,7 @@
return values;
}
- private void setProfileProperties(Instance instance, List<Node> propertyNodes) {
+ private void getProfileProperties(Instance instance, List<Node> propertyNodes) {
if (propertyNodes != null) {
for (Iterator<Node> i = propertyNodes.iterator(); i.hasNext();) {
Node n = i.next();
@@ -323,6 +378,9 @@
storage += " " + attrs.getNamedItem("unit").getNodeValue();
//$NON-NLS-1$
}
instance.setStorage(storage);
+ } else if (name.equals("cpu")) { //$NON-NLS-1$
+ String cpu = attrs.getNamedItem("value").getNodeValue(); //$NON-NLS-1$
+ instance.setCPU(cpu);
}
}
}
@@ -366,6 +424,10 @@
{
return (T) buildInstance(nodeToString(node));
}
+ else if (clazz.equals(HardwareProfile.class))
+ {
+ return (T) buildHardwareProfile(nodeToString(node));
+ }
else
{
return JAXB.unmarshal(new StringReader(nodeToString(node)), clazz);
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java 2010-07-27
18:57:21 UTC (rev 23750)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/HardwareProfile.java 2010-07-27
19:50:41 UTC (rev 23751)
@@ -1,65 +1,73 @@
package org.jboss.tools.deltacloud.core.client;
-import javax.xml.bind.annotation.XmlElement;
+import java.util.ArrayList;
+import java.util.List;
public class HardwareProfile extends DeltaCloudObject
{
private static final long serialVersionUID = 1L;
- @XmlElement
- private String architecture;
+ private List<Property> properties;
- @XmlElement
- private String memory;
-
- @XmlElement
- private String storage;
-
private HardwareProfile()
{
}
- @SuppressWarnings("unused")
- private void setArchitecture(String architecture)
- {
- this.architecture = architecture;
+ public List<Property> getProperties() {
+ if (properties == null)
+ properties = new ArrayList<Property>();
+ return properties;
}
-
- @SuppressWarnings("unused")
- private void setMemory(String memory)
- {
- this.memory = memory;
+
+ private Property getNamedProperty(String name) {
+ for (Property p : properties) {
+ if (p.getName().equals(name))
+ return p;
+ }
+ return null;
}
-
- @SuppressWarnings("unused")
- private void setStorage(String storage)
- {
- this.storage = storage;
- }
-
+
public String getArchitecture()
{
- return architecture;
+ Property p = getNamedProperty("architecture");
+ if (p != null)
+ return p.toString();
+ return null;
}
public String getMemory()
{
- return memory;
+ Property p = getNamedProperty("memory");
+ if (p != null)
+ return p.toString();
+ return null;
}
-
+
public String getStorage()
{
- return storage;
+ Property p = getNamedProperty("storage");
+ if (p != null)
+ return p.toString();
+ return null;
}
+
+ public String getCPU()
+ {
+ Property p = getNamedProperty("cpu");
+ if (p != null)
+ return p.toString();
+ return null;
+ }
+
@Override
public String toString()
{
String s = "";
s += "Hardware-profile:\t\t" + getId() + "\n";
- s += "Arch:\t\t" + getArchitecture() + "\n";
- s += "Memory:\t\t" + getMemory() + "\n";
- s += "Storage:\t" + getStorage() + "\n";
+ for (Property p : properties) {
+ s += p.getName() + ":\t\t" + p.getValue() + "\n";
+ }
return s;
}
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-07-27
18:57:21 UTC (rev 23750)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-07-27
19:50:41 UTC (rev 23751)
@@ -20,13 +20,14 @@
private String imageId;
- @XmlElement(name="hardware-profile")
private String profileId;
private String memory;
private String storage;
+ private String cpu;
+
private String realmId;
@XmlElement
@@ -73,6 +74,10 @@
protected void setStorage(String storage) {
this.storage = storage;
}
+
+ protected void setCPU(String cpu) {
+ this.cpu = cpu;
+ }
protected void setRealmId(String realmId)
{
@@ -128,7 +133,11 @@
public String getStorage() {
return storage;
}
-
+
+ public String getCPU() {
+ return cpu;
+ }
+
public String getRealmId()
{
return realmId;
@@ -164,10 +173,13 @@
s += "Realm:\t\t" + getRealmId() + "\n";
s += "Profile:\t\t" + getProfileId() + "\n";
if (getMemory() != null)
- s += "Memory:\t\t\t" + getMemory() + "\n";
+ s += "Memory:\t\t" + getMemory() + "\n";
if (getStorage() != null) {
- s += "Storage:\t\t\t" + getStorage() + "\n";
+ s += "Storage:\t\t" + getStorage() + "\n";
}
+ if (getCPU() != null) {
+ s += "CPU:\t\t" + getCPU() + "\n";
+ }
s += "State:\t\t" + getState() + "\n";
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Property.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Property.java
(rev 0)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Property.java 2010-07-27
19:50:41 UTC (rev 23751)
@@ -0,0 +1,93 @@
+package org.jboss.tools.deltacloud.core.client;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+
+public class Property extends DeltaCloudObject {
+
+ private static final long serialVersionUID = 1L;
+
+ public static enum Kind {FIXED, RANGE, ENUM};
+
+ public Property()
+ {
+ }
+
+ @XmlElement
+ private String kind;
+
+ @XmlElement
+ private String unit;
+
+ @XmlElement
+ private String name;
+
+ @XmlElement
+ private String value;
+
+ // For range
+ private String first;
+ private String last;
+
+ // For enum
+ private List<String> enums;
+
+ public String getKind() {
+ return kind;
+ }
+
+ public String getUnit() {
+ return unit;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public void setUnit(String unit) {
+ this.unit = unit;
+ }
+
+ public void setKind(String kind) {
+ this.kind = kind;
+ }
+
+ public void setRange(String first, String last) {
+ this.first = first;
+ this.last = last;
+ }
+
+ public void setEnums(List<String> enums) {
+ this.enums = enums;
+ }
+
+ public String toString() {
+ if (kind.equals("range")) {
+ return first += "-" + last + "(default:" + value + ")";
+ }
+ else if (kind.equals("enum")) {
+ String s = enums.get(0);
+ for (int i = 1; i < enums.size(); ++i) {
+ s += ", " + enums.get(i);
+ }
+ s += " (default:" + value + ")";
+ return s;
+ }
+ // must be "fixed"
+ return value += " " + unit;
+ }
+
+}