JBoss Tools SVN: r26256 - trunk/build/aggregate/site.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2010-11-04 10:41:32 -0400 (Thu, 04 Nov 2010)
New Revision: 26256
Modified:
trunk/build/aggregate/site/site.xml
Log:
reorder to match JBDS agg update site
Modified: trunk/build/aggregate/site/site.xml
===================================================================
--- trunk/build/aggregate/site/site.xml 2010-11-04 14:02:46 UTC (rev 26255)
+++ trunk/build/aggregate/site/site.xml 2010-11-04 14:41:32 UTC (rev 26256)
@@ -116,27 +116,25 @@
<feature url="features/org.jboss.tools.maven.portlet.feature_0.0.0.jar" id="org.jboss.tools.maven.portlet.feature" version="0.0.0">
<category name="MavenTools" />
</feature>
+ <feature url="features/org.jboss.tools.jbpm4.feature_0.0.0.jar" id="org.jboss.tools.jbpm4.feature" version="0.0.0">
+ <category name="AllTools" />
+ <category name="SOATools" />
+ </feature>
+ <feature url="features/org.jboss.tools.bpel.feature_0.0.0.jar" id="org.jboss.tools.bpel.feature" version="0.0.0">
+ <category name="SOATools" />
+ </feature>
+ <feature url="features/org.jboss.tools.gwt.feature_0.0.0.jar" id="org.jboss.tools.gwt.feature" version="0.0.0">
+ <category name="GeneralTools" />
+ </feature>
+ <feature url="features/org.jboss.tools.deltacloud.feature_0.0.0.jar" id="org.jboss.tools.deltacloud.feature" version="0.0.0">
+ <category name="CloudTools" />
+ </feature>
<feature url="features/org.jboss.tools.xulrunner.feature_0.0.0.jar" id="org.jboss.tools.xulrunner.feature" version="0.0.0">
<category name="AllTools" />
<category name="WebTools" />
</feature>
- <!-- TODO: enable SDK features once we can build source plugins w/ Tycho -->
- <!-- <feature url="features/org.jboss.tools.jmx.sdk.feature_0.0.0.jar" id="org.jboss.tools.jmx.sdk.feature"
- version="0.0.0"> <category name="SDKTools"/> </feature> <feature url="features/org.jboss.ide.eclipse.freemarker.sdk.feature_0.0.0.jar"
- id="org.jboss.ide.eclipse.freemarker.sdk.feature" version="0.0.0"> <category
- name="SDKTools"/> </feature> -->
- <!-- TODO: enable SDK features once we can build source plugins w/ Tycho -->
- <!-- Only in JBT -->
- <!--
- <feature url="features/org.jboss.tools.bpel.sdk.feature_0.0.0.jar"
- id="org.jboss.tools.bpel.sdk.feature" version="0.0.0"> <category name="AllTools"/>
- <category name="SOATools"/> </feature> <feature url="features/org.jboss.tools.maven.sdk.feature_0.0.0.jar"
- id="org.jboss.tools.maven.sdk.feature" version="0.0.0"> <category name="SDKTools"/>
- </feature>
- -->
-
<!-- jBPM Tools & Flow features -->
<feature url="features/org.jboss.tools.jbpm.convert.feature_0.0.0.jar" id="org.jboss.tools.jbpm.convert.feature" version="0.0.0">
<category name="AllTools" />
@@ -150,15 +148,7 @@
<category name="AllTools" />
<category name="SOATools" />
</feature>
- <feature url="features/org.jboss.tools.jbpm4.feature_0.0.0.jar" id="org.jboss.tools.jbpm4.feature" version="0.0.0">
- <category name="AllTools" />
- <category name="SOATools" />
- </feature>
- <feature url="features/org.jboss.tools.bpel.feature_0.0.0.jar" id="org.jboss.tools.bpel.feature" version="0.0.0">
- <category name="SOATools" />
- </feature>
-
<feature url="features/org.jboss.tools.modeshape.rest.feature_0.0.0.jar" id="org.jboss.tools.modeshape.rest.feature" version="0.0.0">
<category name="AllTools" />
<category name="GeneralTools" />
@@ -168,15 +158,6 @@
<category name="AllTools" />
</feature>
- <!-- JBIDE- 6836 DO NOT PUT IN AllTools CATEGORY -->
- <feature url="features/org.jboss.tools.gwt.feature_0.0.0.jar" id="org.jboss.tools.gwt.feature" version="0.0.0">
- <category name="GeneralTools" />
- </feature>
-
- <feature url="features/org.jboss.tools.deltacloud.feature_0.0.0.jar" id="org.jboss.tools.deltacloud.feature" version="0.0.0">
- <category name="CloudTools" />
- </feature>
-
<feature url="features/org.jboss.tools.usage.feature_0.0.0.jar" id="org.jboss.tools.usage.feature" version="0.0.0">
<category name="AllTools" />
</feature>
@@ -226,29 +207,36 @@
transformation.</description>
</category-def>
+ <category-def name="TestPerfTools" label="Test and Performance">
+ <description>Tools used to improve testing and performance.
+ </description>
+ </category-def>
+
<!-- Only in JBT -->
<category-def name="MavenTools" label="Maven Support">
<description>Plugins related to Maven and m2eclipse support. Use these
to enable use of Maven.</description>
</category-def>
-
- <!-- Only in JBT -->
<category-def name="ReportTools" label="Business Intelligence, Reporting and Charting">
<description>Business Intelligence, Reporting and Charting. Use these
if you plan to integrate Hibernate or Seam with Eclipse BIRT.
</description>
</category-def>
-
- <category-def name="TestPerfTools" label="Test and Performance">
- <description>Tools used to improve testing and performance.
- </description>
- </category-def>
-
<category-def name="CloudTools" label="Cloud">
<description>Tools for Cloud Development.
</description>
</category-def>
+ <!-- aggregated from other sources; only in JBT -->
+ <feature url="features/org.pi4soa.core.feature_0.0.0.jar" id="org.pi4soa.core.feature" version="0.0.0">
+ <category name="SOATools" />
+ </feature>
+ <feature url="features/org.jboss.savara.tools.feature_0.0.0.jar" id="org.jboss.savara.tools.feature" version="0.0.0">
+ <category name="SOATools" />
+ </feature>
+ <feature url="features/org.scribble.protocol.feature_0.0.0.jar" id="org.scribble.protocol.feature" version="0.0.0">
+ </feature>
+
<!-- aggregated from other sources -->
<feature url="features/org.drools.eclipse.feature_0.0.0.jar" id="org.drools.eclipse.feature" version="0.0.0">
<category name="AllTools" />
@@ -263,9 +251,6 @@
<category name="AllTools" />
<category name="SOATools" />
</feature>
- <feature url="features/org.pi4soa.core.feature_0.0.0.jar" id="org.pi4soa.core.feature" version="0.0.0">
- <category name="SOATools" />
- </feature>
<feature url="features/org.teiid.datatools.connectivity.feature_0.0.0.jar" id="org.teiid.datatools.connectivity.feature" version="0.0.0">
<category name="DataTools" />
@@ -276,10 +261,4 @@
<feature url="features/org.teiid.designer.runtime.feature_0.0.0.jar" id="org.teiid.designer.runtime.feature" version="0.0.0">
<category name="DataTools" />
</feature>
- <feature url="features/org.jboss.savara.tools.feature_0.0.0.jar" id="org.jboss.savara.tools.feature" version="0.0.0">
- <category name="SOATools" />
- </feature>
- <feature url="features/org.scribble.protocol.feature_0.0.0.jar" id="org.scribble.protocol.feature" version="0.0.0">
- </feature>
-
</site>
15 years, 5 months
JBoss Tools SVN: r26255 - trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/util.
by jbosstools-commits@lists.jboss.org
Author: bbrodt
Date: 2010-11-04 10:02:46 -0400 (Thu, 04 Nov 2010)
New Revision: 26255
Modified:
trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/util/XSDComparer.java
Log:
CODING IN PROGRESS - issue JBIDE-7351: General issues with Variable Initialization, Assign, and Copy
https://jira.jboss.org/browse/JBIDE-7351
Modified: trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/util/XSDComparer.java
===================================================================
--- trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/util/XSDComparer.java 2010-11-04 13:53:00 UTC (rev 26254)
+++ trunk/bpel/plugins/org.eclipse.bpel.model/src/org/eclipse/bpel/model/util/XSDComparer.java 2010-11-04 14:02:46 UTC (rev 26255)
@@ -26,6 +26,8 @@
import java.util.List;
import java.util.Stack;
+import javax.xml.namespace.QName;
+
import org.eclipse.emf.common.util.EList;
import org.eclipse.xsd.*;
import org.eclipse.xsd.util.XSDConstants;
@@ -125,6 +127,10 @@
if (type1 instanceof XSDSimpleTypeDefinition && type2 instanceof XSDSimpleTypeDefinition) {
dump("Comparing ", elem1, type1, level);
dump(" to ", elem2, type2, level);
+ if (!compareQNames(elem1, elem2)) {
+ addError("different QNames: " + elem1.getQName() + " vs " + elem2.getQName(), term1,term2);
+ return false;
+ }
String s1 = getTypeNameHierarchy(elem1);
String s2 = getTypeNameHierarchy(elem2);
if (!s1.equals(s2)) {
@@ -132,23 +138,27 @@
return false;
}
} else if (type1 instanceof XSDComplexTypeDefinition && type2 instanceof XSDComplexTypeDefinition) {
- int min1 = getMinOccurs(term1);
- int min2 = getMinOccurs(term2);
- int max1 = getMaxOccurs(term1);
- int max2 = getMaxOccurs(term2);
+ dump("Comparing ", elem1, type1, level);
+ dump(" to ", elem2, type2, level);
+ if (!compareQNames(elem1, elem2)) {
+ addError("different QNames: " + elem1.getQName() + " vs " + elem2.getQName(), term1,term2);
+ return false;
+ }
+ int min1 = getMinOccurs(term1);
+ int min2 = getMinOccurs(term2);
+ int max1 = getMaxOccurs(term1);
+ int max2 = getMaxOccurs(term2);
if (strict) {
if (min1 != min2 || max1 != max2) {
addError("different cardinality: " + min1 + " to " + max1 + " vs " + min2 + " to " + max2, term1,term2);
return false;
}
} else {
- if (min1 > max2 || min2 > max1) {
+ if ((max2>0 && min1 > max2) || (max1>0 && min2 > max1)) {
addError("incompatible cardinality: " + min1 + " to " + max1 + " vs " + min2 + " to " + max2, term1,term2);
return false;
}
}
- dump("Comparing ", elem1, type1, level);
- dump(" to ", elem2, type2, level);
boolean result = compare(getChildTerms(elem1), getChildTerms(elem2), level + 1);
if (!result) {
addError("different complex element structures",elem1,elem2);
@@ -194,18 +204,24 @@
List<XSDAttributeDeclaration> attrs1 = getAttributeDeclarations(elem1);
List<XSDAttributeDeclaration> attrs2 = getAttributeDeclarations(elem2);
if (attrs1.size() != attrs2.size()) {
- addError("differing number of attributes",elem1,elem2);
+ addError("different number of attributes",elem1,elem2);
return false;
}
for (int i = 0; i < attrs1.size(); ++i) {
XSDAttributeDeclaration attr1 = attrs1.get(i);
XSDAttributeDeclaration attr2 = attrs2.get(i);
if (!attr1.getQName().equals(attr2.getQName())) {
- addError("differing attribute names: "+attr1.getQName()+" vs "+attr2.getQName(),elem1,elem2);
+ addError("different attribute names: "+attr1.getQName()+" vs "+attr2.getQName(),elem1,elem2);
return false;
}
- if (!attr1.getLexicalValue().equals(attr2.getLexicalValue())) {
- addError("differing attribute values: "+attr1.getLexicalValue()+" vs "+attr2.getLexicalValue(),elem1,elem2);
+ String value1 = attr1.getLexicalValue();
+ String value2 = attr2.getLexicalValue();
+ if (value1==null)
+ value1 = "";
+ if (value2==null)
+ value2 = "";
+ if (!value1.equals(value2)) {
+ addError("different attribute values: "+attr1.getLexicalValue()+" vs "+attr2.getLexicalValue(),elem1,elem2);
return false;
}
}
@@ -308,9 +324,12 @@
} catch (Exception e) {
addError("caught exception: "+e.toString(),term1,term2);
+ e.printStackTrace();
return false;
}
- dump("*** Schemas are compatible");
+
+ if (level==0)
+ dump("*** Schemas are compatible");
return true;
}
@@ -339,7 +358,31 @@
}
return s;
}
+
+ private boolean compareQNames(XSDNamedComponent elem1, XSDNamedComponent elem2) {
+ String name1 = elem1.getName();
+ String name2 = elem2.getName();
+ if (name1==null || name2==null) {
+ if (name1==name2)
+ return true;
+ return false;
+ }
+ if (name1.equals(name2)) {
+ if (elem1.getTargetNamespace() == null || elem1.getTargetNamespace().isEmpty()
+ && elem2.getTargetNamespace() == null || elem2.getTargetNamespace().isEmpty())
+ return true;
+
+ if (elem1.getTargetNamespace().equals(elem2.getTargetNamespace()))
+ return true;
+
+ if ( elem1.getSchema().getTargetNamespace().equals(elem2.getSchema().getTargetNamespace()) )
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Returns a list of immediate children for the specified element.
*
@@ -670,6 +713,9 @@
diag.getComponents().add(comp2);
getDiagnostics().add(diag);
+ if (debug)
+ dump(getDiagnostic(getDiagnostics().size()-1));
+
return diag;
}
15 years, 5 months
JBoss Tools SVN: r26254 - trunk/build/target-platform.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2010-11-04 09:53:00 -0400 (Thu, 04 Nov 2010)
New Revision: 26254
Modified:
trunk/build/target-platform/e361-wtp322.target.p2mirror.xml
Log:
comment out SAVARA deps for now (SAVARA-141)
Modified: trunk/build/target-platform/e361-wtp322.target.p2mirror.xml
===================================================================
--- trunk/build/target-platform/e361-wtp322.target.p2mirror.xml 2010-11-04 13:45:31 UTC (rev 26253)
+++ trunk/build/target-platform/e361-wtp322.target.p2mirror.xml 2010-11-04 13:53:00 UTC (rev 26254)
@@ -134,19 +134,6 @@
<iu version="" id="org.eclipse.zest.feature.group"/>
<iu version="" id="org.eclipse.uml2.feature.group"/>
<iu version="" id="org.eclipse.rse.feature.group"/>
-<iu version="" id="org.eclipse.gmf.runtime.notation.feature.group"/>
-<iu version="" id="org.eclipse.gmf.feature.group"/>
-<iu version="" id="org.eclipse.gmf.tooling.feature.group"/>
-<iu version="" id="org.eclipse.gmf.runtime.thirdparty.feature.group"/>
-<iu version="" id="org.eclipse.m2m.qvt.oml.feature.group"/>
-<iu version="" id="org.eclipse.emf.workspace.feature.group"/>
-<iu version="" id="org.eclipse.emf.transaction.feature.group"/>
-<iu version="" id="org.eclipse.ocl.feature.group"/>
-<iu version="" id="org.eclipse.pde.junit.runtime.standalone.feature.group"/>
-<iu version="" id="org.eclipse.m2m.qvt.oml.common.feature.group"/>
-<iu version="" id="org.eclipse.emf.validation.feature.group"/>
-<iu version="" id="org.eclipse.emf.validation.ocl.feature.group"/>
-<iu version="" id="org.eclipse.m2m.qvt.oml.runtime.feature.group"/>
<iu version="" id="org.eclipse.jst.jee"/>
<iu version="" id="org.eclipse.wst.common.frameworks"/>
<iu version="" id="org.eclipse.wst.common.project.facet.ui"/>
15 years, 5 months
JBoss Tools SVN: r26253 - trunk/build/target-platform.
by jbosstools-commits@lists.jboss.org
Author: nickboldt
Date: 2010-11-04 09:45:31 -0400 (Thu, 04 Nov 2010)
New Revision: 26253
Modified:
trunk/build/target-platform/e361-wtp322.target
Log:
comment out SAVARA deps for now (SAVARA-141)
Modified: trunk/build/target-platform/e361-wtp322.target
===================================================================
--- trunk/build/target-platform/e361-wtp322.target 2010-11-04 13:37:05 UTC (rev 26252)
+++ trunk/build/target-platform/e361-wtp322.target 2010-11-04 13:45:31 UTC (rev 26253)
@@ -145,7 +145,8 @@
<unit version="1.2.0.v20100519-2050-67808yE5F-8HAH4HECF4242" id="org.eclipse.zest.feature.group"/>
<unit version="3.1.1.v201008191505" id="org.eclipse.uml2.feature.group"/>
<unit version="3.2.1.v201008191400-7L78FA-8wqbPcNj4qa8R0eViy7vZ" id="org.eclipse.rse.feature.group"/>
- <!-- <unit version="1.2.0.201006151053" id="org.eclipse.stp.bpmn.feature.feature.group"/> -->
+ <!-- SAVARA dependencies -->
+ <!-- <unit version="1.2.0.201006151053" id="org.eclipse.stp.bpmn.feature.feature.group"/>
<unit version="1.4.1.v20100909-1000-37708s73533F5C1479I" id="org.eclipse.gmf.runtime.notation.feature.group"/>
<unit version="1.4.1.v20100909-1300-7d9A78FYnmMD7VBZOqOghp2tsgXc" id="org.eclipse.gmf.feature.group"/>
<unit version="2.3.0.v20100421-2359-7c7MFO2FLWUl0im8BjQMa9f" id="org.eclipse.gmf.tooling.feature.group"/>
@@ -158,7 +159,7 @@
<unit version="2.1.0.v20100606-1530-7908_AkF7AG8KEM3CMFA" id="org.eclipse.m2m.qvt.oml.common.feature.group"/>
<unit version="1.4.0.v20100428-2315-479-9oB56N5BBR6LCA6" id="org.eclipse.emf.validation.feature.group"/>
<unit version="1.4.0.v20100428-2315-23-7w3121133502768" id="org.eclipse.emf.validation.ocl.feature.group"/>
- <unit version="2.1.0.v20100606-1530-7A2-AkF7AG8PBU3BRLA" id="org.eclipse.m2m.qvt.oml.runtime.feature.group"/>
+ <unit version="2.1.0.v20100606-1530-7A2-AkF7AG8PBU3BRLA" id="org.eclipse.m2m.qvt.oml.runtime.feature.group"/> -->
<repository location="http://download.eclipse.org/releases/helios/"/>
</location>
<location includeAllPlatforms="false" includeMode="planner" type="InstallableUnit">
15 years, 5 months
JBoss Tools SVN: r26252 - in trunk/deltacloud: plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core and 6 other directories.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-11-04 09:37:05 -0400 (Thu, 04 Nov 2010)
New Revision: 26252
Added:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.java
Removed:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/API.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.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/DeltaCloud.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java
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/Instance.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudTypeValidator.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/context/MockIntegrationTestContext.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ImageMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ProfileMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/RealmMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java
Log:
[JBIDE-7484] removed instance related methods from client, unified funtionality in #performAction and offered additional methods on Instance (#start, #stop, #destroy, #reboot). Furthermore update instance upon action responses from server.
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-11-04 13:37:05 UTC (rev 26252)
@@ -1,3 +1,12 @@
+2010-11-04 André Dietisheim <adietish(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java:
+ * src/org/jboss/tools/deltacloud/core/client/InstanceAction.java:
+ * src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java:
+ * src/org/jboss/tools/deltacloud/core/client/Instance.java (start), (stop), (destroy), (reboot):
+ [JBIDE-7484] removed instance related methods from client, unified funtionality in #performAction and offered additional methods on
+ Instance (#start, #stop, #destroy, #reboot). Furthermore update instance upon action responses from server.
+
2010-10-29 André Dietisheim <adietish(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/client/HttpStatusCode.java: extracted and put in a 2 enums:
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -25,9 +25,9 @@
import org.eclipse.equinox.security.storage.SecurePreferencesFactory;
import org.eclipse.equinox.security.storage.StorageException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudAuthException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundException;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundClientException;
import org.jboss.tools.deltacloud.core.client.HardwareProfile;
import org.jboss.tools.deltacloud.core.client.Image;
import org.jboss.tools.deltacloud.core.client.Instance;
@@ -44,7 +44,7 @@
private String type;
private String lastKeyname = "";
private String lastImageId = "";
- private DeltaCloudClient client;
+ private DeltaCloudClientImpl client;
private ArrayList<DeltaCloudInstance> instances;
private ArrayList<DeltaCloudImage> images;
private IImageFilter imageFilter;
@@ -69,7 +69,7 @@
public DeltaCloud(String name, String url, String username, String passwd,
String type, boolean persistent,
String imageFilterRules, String instanceFilterRules) throws MalformedURLException {
- this.client = new DeltaCloudClient(url, username, passwd); //$NON-NLS-1$
+ this.client = new DeltaCloudClientImpl(url, username, passwd); //$NON-NLS-1$
this.url = url;
this.name = name;
this.username = username;
@@ -93,7 +93,7 @@
public void editCloud(String name, String url, String username, String passwd, String type)
throws MalformedURLException {
- this.client = new DeltaCloudClient(url, username, passwd); //$NON-NLS-1$
+ this.client = new DeltaCloudClientImpl(url, username, passwd); //$NON-NLS-1$
this.url = url;
this.name = name;
this.username = username;
@@ -288,15 +288,10 @@
public DeltaCloudInstance[] destroyInstance(String instanceId) {
try {
- client.destroyInstance(instanceId);
- for (int i = 0; i < instances.size(); ++i) {
- DeltaCloudInstance instance = instances.get(i);
- if (instance.getId().equals(instanceId)) {
- instances.remove(i);
- break;
- }
- }
- } catch (DeltaCloudClientException e) {
+ DeltaCloudInstance instance = getInstance(instanceId);
+ performInstanceAction(instance, DeltaCloudInstance.DESTROY);
+ instances.remove(instance);
+ } catch (DeltaCloudException e) {
return null;
}
DeltaCloudInstance[] instanceArray = new DeltaCloudInstance[instances.size()];
@@ -367,14 +362,31 @@
return retVal;
}
- public boolean performInstanceAction(String instanceId, String action) throws DeltaCloudException {
+ public boolean performInstanceAction(String instanceId, String actionId) throws DeltaCloudException {
+ return performInstanceAction(getInstance(instanceId), actionId);
+ }
+
+ protected boolean performInstanceAction(DeltaCloudInstance instance, String actionId) throws DeltaCloudException {
try {
- return client.performInstanceAction(instanceId, action);
+ if (instance == null) {
+ return false;
+ }
+ return instance.performInstanceAction(actionId, client);
+
} catch (DeltaCloudClientException e) {
throw new DeltaCloudException(e);
}
}
+ private DeltaCloudInstance getInstance(String instanceId) {
+ for (DeltaCloudInstance instance : instances) {
+ if (instance.getId().equals(instanceId)) {
+ return instance;
+ }
+ }
+ return null;
+ }
+
public DeltaCloudHardwareProfile[] getProfiles() {
ArrayList<DeltaCloudHardwareProfile> profiles = new ArrayList<DeltaCloudHardwareProfile>();
try {
@@ -437,11 +449,11 @@
try {
client.listInstances(instanceId);
return true;
- } catch( DeltaCloudNotFoundException e) {
+ } catch (DeltaCloudNotFoundClientException e) {
return true;
} catch (DeltaCloudAuthException e) {
return false;
- }
+ }
}
public DeltaCloudRealm[] getRealms() {
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -12,6 +12,8 @@
import java.util.List;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.Instance;
import org.jboss.tools.deltacloud.core.client.InstanceAction;
@@ -90,4 +92,12 @@
return hostNames.get(0);
return null;
}
+
+ protected boolean performInstanceAction(String actionId, DeltaCloudClientImpl client) throws DeltaCloudClientException {
+ InstanceAction action = instance.getAction(actionId);
+ if (action == null) {
+ return false;
+ }
+ return client.performInstanceAction(action);
+ }
}
Deleted: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/API.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/API.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/API.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -1,119 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat Inc..
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat Incorporated - initial API and implementation
- *******************************************************************************/
-package org.jboss.tools.deltacloud.core.client;
-
-import java.util.List;
-
-public interface API
-{
- /**
- * Returns a list of Delta Cloud Realms
- * @return List of Delta Cloud Realms
- * @throws DeltaCloudClientException
- */
- public List<Realm> listRealms() throws DeltaCloudClientException;
-
- /**
- * Returns a single Delta Cloud Realm given its ID
- * @param realmId
- * @return Delta Cloud Realm
- * @throws DeltaCloudClientException
- */
- public Realm listRealms(String realmId) throws DeltaCloudClientException;
-
- public List<HardwareProfile> listProfiles() throws DeltaCloudClientException;
-
- /**
- * Returns a Delta Cloud Flavors
- * @param flavorId
- * @return Delta Cloud Flavor
- * @throws DeltaCloudClientException
- */
- public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException;
-
- /**
- * Returns a List of Delta Cloud Images
- * @return List of Delta Cloud Images
- * @throws DeltaCloudClientException
- */
- public List<Image> listImages() throws DeltaCloudClientException;
-
- /**
- * Returns a Delta Cloud Image given its ID
- * @param imageId
- * @return
- * @throws DeltaCloudClientException
- */
- public Image listImages(String imageId) throws DeltaCloudClientException;
-
- /**
- * Returns a list of all Instances from the Delta Cloud Provider
- * @return
- * @throws DeltaCloudClientException
- */
- public List<Instance> listInstances() throws DeltaCloudClientException;
-
- /**
- * Returns an Instance from the Delta Cloud Provider given on the Instances ID
- * @param instanceId
- * @return
- * @throws DeltaCloudClientException
- */
- public Instance listInstances(String instanceId) throws DeltaCloudClientException;
-
- /**
- * Creates a new Delta Cloud Instance based on the Image specified by the Image ID. Default parameters are used for the
- * Flavor, Realm and Name. These are specified by the Delta Cloud Provider
- * @param imageId
- * @return The newly created Delta Cloud Instance
- * @throws DeltaCloudClientException
- */
- public Instance createInstance(String imageId) throws DeltaCloudClientException;
-
- /**
- * Creates a new Delta Cloud Instance, the instance will be based on the Image specified by the instance ID. It will be of
- * type flavor and in the location realm
- * @param imageId
- * @param flavor
- * @param realm
- * @param name
- * @return
- * @throws DeltaCloudClientException
- */
- public Instance createInstance(String imageId, String flavor, String realm, String name) throws DeltaCloudClientException;
-
- /**
- * Starts a previously stopped Instance given the Instance ID
- * @param instanceId
- * @throws DeltaCloudClientException
- */
- public void startInstance(String instanceId) throws DeltaCloudClientException;
-
- /**
- * Reboots a running Instance
- * @param instanceId
- * @throws DeltaCloudClientException
- */
- public void rebootInstance(String instanceId) throws DeltaCloudClientException;
-
- /** Shuts down a running instance
- * @param instanceId
- * @throws DeltaCloudClientException
- */
- public void shutdownInstance(String instanceId) throws DeltaCloudClientException;
-
- /** Destroys a previously Stopped Instance
- *
- * @param instanceId
- * @throws DeltaCloudClientException
- */
- public void destroyInstance(String instanceId) throws DeltaCloudClientException;
-}
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-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClient.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -10,706 +10,107 @@
*******************************************************************************/
package org.jboss.tools.deltacloud.core.client;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
-import javax.xml.bind.JAXB;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.methods.HttpDelete;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.client.methods.HttpUriRequest;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.log4j.Logger;
-import org.eclipse.core.runtime.Path;
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
+public interface DeltaCloudClient {
-public class DeltaCloudClient implements API {
+ /**
+ * Returns the server type this client is connected to.
+ *
+ * @return the server type
+ *
+ * @see DeltaCloudServerType
+ */
+ public DeltaCloudServerType getServerType();
- private static final String BASEURL_API = "/api";
- private static final String PEM_FILE_SUFFIX = "pem";
- private static final String DOCUMENT_ELEMENT_DRIVER = "driver";
- private static final String DOCUMENT_ELEMENT_API = "api";
+ /**
+ * Returns a list of Delta Cloud Realms
+ *
+ * @return List of Delta Cloud Realms
+ * @throws DeltaCloudClientException
+ */
+ public List<Realm> listRealms() throws DeltaCloudClientException;
- public static Logger logger = Logger.getLogger(DeltaCloudClient.class);
+ /**
+ * Returns a single Delta Cloud Realm given its ID
+ *
+ * @param realmId
+ * @return Delta Cloud Realm
+ * @throws DeltaCloudClientException
+ */
+ public Realm listRealms(String realmId) throws DeltaCloudClientException;
- public static enum DeltaCloudType {
- UNKNOWN, MOCK, EC2
- }
+ public List<HardwareProfile> listProfiles() throws DeltaCloudClientException;
- private static enum DCNS {
- TYPE {
- public String getResourceName() {
- return "";
- }
- }
- ,
- INSTANCES
- , REALMS
- , IMAGES
- , HARDWARE_PROFILES
- , KEYS
- , START
- , STOP
- , REBOOT
- , DESTROY;
+ /**
+ * Returns a Delta Cloud Flavors
+ *
+ * @param flavorId
+ * @return Delta Cloud Flavor
+ * @throws DeltaCloudClientException
+ */
+ public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException;
- @Override
- public String toString() {
- return "/" + getResourceName();
- }
-
- public String getResourceName() {
- return name().toLowerCase();
- }
- }
-
- private URL baseUrl;
- private String username;
- private String password;
-
- public DeltaCloudClient(String url) throws MalformedURLException {
- this(url, null, null);
- }
-
- public DeltaCloudClient(String url, String username, String password) throws MalformedURLException {
-
- logger.debug("Creating new Delta Cloud Client for Server: " + url);
-
- this.baseUrl = new URL(url + BASEURL_API);
- this.username = username;
- this.password = password;
- }
-
- private String sendRequest(String path, HttpMethod httpMethod) throws DeltaCloudClientException {
- DefaultHttpClient httpClient = addCredentials(new DefaultHttpClient());
- String requestUrl = baseUrl.toString() + path;
- logger.debug("Sending Request to: " + requestUrl);
-
- try {
- HttpUriRequest request = getRequest(httpMethod, requestUrl);
- HttpResponse httpResponse = httpClient.execute(request);
- throwOnHttpErrors(requestUrl, httpResponse);
- return getResponse(httpResponse.getEntity());
- } catch (DeltaCloudClientException e) {
- throw e;
- } catch (IOException e) {
- logger.error("Error processing request to: " + requestUrl, e);
- throw new DeltaCloudClientException("Error processing request to: " + requestUrl, e);
- } catch (Exception e) {
- throw new DeltaCloudClientException(e.getMessage());
- } finally {
- httpClient.getConnectionManager().shutdown();
- }
- }
-
- private void throwOnHttpErrors(String requestUrl, HttpResponse httpResponse) throws DeltaCloudClientException {
- int statusCode = httpResponse.getStatusLine().getStatusCode();
- if (HttpStatusCode.OK.isStatus(statusCode)) {
- return;
- } else if (HttpStatusCode.FORBIDDEN.isStatus(statusCode)) {
- throw new DeltaCloudAuthException(
- MessageFormat.format("The server reported an authorization error \"{0}\" on requesting \"{1}\"",
- httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
- } else if (HttpStatusCode.NOT_FOUND.isStatus(statusCode)) {
- throw new DeltaCloudNotFoundException(
- MessageFormat.format("The server could not find the resource \"{0}\"", requestUrl));
- } else if (HttpStatusRange.CLIENT_ERROR.isInRange(statusCode)
- || HttpStatusRange.SERVER_ERROR.isInRange(statusCode)) {
- throw new DeltaCloudClientException(
- MessageFormat.format("The server reported an error \"{0}\" on requesting \"{1}\"",
- httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
- }
- }
-
- private String getResponse(HttpEntity entity) throws IOException,
- DeltaCloudClientException {
- if (entity == null) {
- return null;
- }
- String xml = readInputStreamToString(entity.getContent());
- logger.debug("Response\n" + xml);
- return xml;
- }
-
/**
- * Returns a request instance for the given request type and url.
+ * Returns a List of Delta Cloud Images
*
- * @param httpMethod
- * the request type to use
- * @param requestUrl
- * the requested url
- * @return the request instance
+ * @return List of Delta Cloud Images
+ * @throws DeltaCloudClientException
*/
- protected HttpUriRequest getRequest(HttpMethod httpMethod, String requestUrl) {
- HttpUriRequest request = null;
- switch (httpMethod) {
- case POST:
- request = new HttpPost(requestUrl);
- break;
- case DELETE:
- request = new HttpDelete(requestUrl);
- break;
- case GET:
- default:
- request = new HttpGet(requestUrl);
- }
- request.setHeader("Accept", "application/xml;q=1");
- return request;
- }
+ public List<Image> listImages() throws DeltaCloudClientException;
/**
- * Adds the credentials to the given http client.
+ * Returns a Delta Cloud Image given its ID
*
- * @param httpClient
- * the http client
- * @return the default http client
+ * @param imageId
+ * @return
+ * @throws DeltaCloudClientException
*/
- private DefaultHttpClient addCredentials(DefaultHttpClient httpClient) {
- if (username != null && password != null) {
- httpClient.getCredentialsProvider().setCredentials(
- new AuthScope(baseUrl.getHost(), baseUrl.getPort()),
- new UsernamePasswordCredentials(username, password));
- }
- return httpClient;
- }
+ public Image listImages(String imageId) throws DeltaCloudClientException;
- private static String readInputStreamToString(InputStream is) throws DeltaCloudClientException {
- try {
- try {
- if (is != null) {
- StringBuilder sb = new StringBuilder();
- String line;
-
- BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
- while ((line = reader.readLine()) != null) {
- sb.append(line).append("\n");
- }
- return sb.toString();
- }
- } finally {
- is.close();
- }
- } catch (Exception e) {
- throw new DeltaCloudClientException("Error converting Response to String", e);
- }
- return "";
- }
-
- public DeltaCloudType getServerType() {
- DeltaCloudType serverType = DeltaCloudType.UNKNOWN;
- try {
- String query = "?format=xml";
- String apiResponse = sendRequest(DCNS.TYPE + query, HttpMethod.GET);
- DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
- Document document = db.parse(new InputSource(new StringReader(apiResponse)));
-
- NodeList elements = document.getElementsByTagName(DOCUMENT_ELEMENT_API);
- if (elements.getLength() > 0) {
- Node n = elements.item(0);
- Node driver = n.getAttributes().getNamedItem(DOCUMENT_ELEMENT_DRIVER);
- if (driver != null) {
- String driverValue = driver.getNodeValue();
- serverType = DeltaCloudType.valueOf(driverValue.toUpperCase());
- }
- }
- } catch (Exception e) {
- serverType = DeltaCloudType.UNKNOWN;
- }
- return serverType;
- }
-
- @Override
- public Instance createInstance(String imageId) throws DeltaCloudClientException {
- String query = "?image_id=" + imageId;
- return buildInstance(sendRequest(DCNS.INSTANCES + query, HttpMethod.POST));
- }
-
- @Override
- public Instance createInstance(String imageId, String profileId, String realmId, String name)
- throws DeltaCloudClientException {
- return createInstance(imageId, profileId, realmId, name, null, null, null);
- }
-
- public Instance createInstance(String imageId, String profileId, String realmId, String name, String memory,
- String storage) throws DeltaCloudClientException {
- return createInstance(imageId, profileId, realmId, name, null, memory, storage);
- }
-
- public Instance createInstance(String imageId, String profileId, String realmId, String name, String keyname,
- String memory, String storage) throws DeltaCloudClientException {
- String query = "?image_id=" + imageId + "&hwp_id=" + profileId + "&realm_id=" + realmId + "&name=" + name;
- if (memory != null)
- query += "&hwp_memory=" + memory;
- if (storage != null)
- query += "&hwp_storage=" + storage;
- if (keyname != null)
- query += "&keyname=" + keyname;
- query += "&commit=create";
- return buildInstance(sendRequest(DCNS.INSTANCES + query, HttpMethod.POST));
- }
-
- @Override
- public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException {
- String request = DCNS.HARDWARE_PROFILES + "/" + profileId;
- return buildDeltaCloudObject(HardwareProfile.class, sendRequest(request, HttpMethod.GET));
- }
-
- @Override
- public List<HardwareProfile> listProfiles() throws DeltaCloudClientException {
- return listDeltaCloudObjects(HardwareProfile.class, DCNS.HARDWARE_PROFILES.toString(), "hardware_profile");
- }
-
- @Override
- public List<Image> listImages() throws DeltaCloudClientException {
- return listDeltaCloudObjects(Image.class, DCNS.IMAGES.toString(), "image");
- }
-
- @Override
- public Image listImages(String imageId) throws DeltaCloudClientException {
- return JAXB.unmarshal(new StringReader(sendRequest(DCNS.IMAGES + "/" + imageId, HttpMethod.GET)), Image.class);
- }
-
- @Override
- public List<Instance> listInstances() throws DeltaCloudClientException {
- return listDeltaCloudObjects(Instance.class, DCNS.INSTANCES.toString(), "instance");
- }
-
- @Override
- public Instance listInstances(String instanceId) throws DeltaCloudClientException {
- return buildInstance(sendRequest(DCNS.INSTANCES + "/" + instanceId, HttpMethod.GET));
- }
-
- @Override
- public List<Realm> listRealms() throws DeltaCloudClientException {
- return listDeltaCloudObjects(Realm.class, DCNS.REALMS.toString(), "realm");
- }
-
- @Override
- public Realm listRealms(String realmId) throws DeltaCloudClientException {
- return JAXB.unmarshal(new StringReader(sendRequest(DCNS.REALMS + "/" + realmId, HttpMethod.GET)), Realm.class);
- }
-
/**
- * Retrieves a key for a given name on the deltacloud server and stores it
- * in the file at the given path. The file gets created if the file path
- * does not exist yet.
+ * Returns a list of all Instances from the Delta Cloud Provider
*
- * @param keyname
- * the name of the key to retrieve from the server
- * @param keyStoreLocation
- * the path to the file to store the key in
+ * @return
* @throws DeltaCloudClientException
- * the delta cloud client exception
*/
- public void createKey(String keyname, String keyStoreLocation) throws DeltaCloudClientException {
- String xml = sendRequest(DCNS.KEYS + "?name=" + keyname, HttpMethod.POST);
- try {
- String key = trimKey(getKey(xml));
- File keyFile = createKeyFile(keyname, keyStoreLocation);
- storeKey(key, keyFile);
- } catch (Exception e) {
- throw new DeltaCloudClientException(e);
- }
- }
+ public List<Instance> listInstances() throws DeltaCloudClientException;
- private void storeKey(String key, File keyFile) throws IOException {
- FileWriter w = new FileWriter(keyFile);
- w.write(key);
- w.close();
- }
-
- private String trimKey(List<String> keyText) throws IOException {
- StringBuffer sb = new StringBuffer();
- String line;
- BufferedReader reader = new BufferedReader(new StringReader(keyText.get(0)));
- while ((line = reader.readLine()) != null) {
- // We must trim off the white-space from the xml
- // Complete white-space lines are to be ignored.
- String trimmedLine = line.trim();
- if (trimmedLine.length() > 0) {
- sb.append(trimmedLine).append("\n");
- }
- }
- return sb.toString();
- }
-
- private List<String> getKey(String xml) throws ParserConfigurationException, SAXException, IOException {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document document = db.parse(new InputSource(new StringReader(xml)));
- List<String> keyText = getElementText(document, PEM_FILE_SUFFIX); //$NON-NLS-1$
- return keyText;
- }
-
- private File createKeyFile(String keyname, String keyStoreLocation) throws IOException {
- File keyFile = Path.fromOSString(keyStoreLocation).append(keyname + "." + PEM_FILE_SUFFIX).toFile(); //$NON-NLS-1$
- if (!keyFile.exists()) {
- keyFile.createNewFile();
- }
- keyFile.setReadable(false, false);
- keyFile.setWritable(true, true);
- keyFile.setReadable(true, true);
- return keyFile;
- }
-
- public void deleteKey(String keyname) throws DeltaCloudClientException {
- sendRequest(DCNS.KEYS + "/" + keyname, HttpMethod.DELETE);
- }
-
- @Override
- public void rebootInstance(String instanceId) throws DeltaCloudClientException {
- /**
- * shouldn't that be PUT? changing resource states == PUT!
- */
- sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.REBOOT, HttpMethod.GET);
- }
-
- @Override
- public void shutdownInstance(String instanceId) throws DeltaCloudClientException {
- /**
- * shouldn't that be PUT? changing resource states == PUT!
- */
- sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.STOP, HttpMethod.POST);
- }
-
- @Override
- public void startInstance(String instanceId) throws DeltaCloudClientException {
- /**
- * shouldn't that be PUT? changing resource states == PUT!
- */
- sendRequest(DCNS.INSTANCES + "/" + instanceId + DCNS.START, HttpMethod.POST);
- }
-
- @Override
- public void destroyInstance(String instanceId) throws DeltaCloudClientException {
- sendRequest(DCNS.INSTANCES + "/" + instanceId, HttpMethod.DELETE);
- }
-
- private Instance buildInstance(String xml) throws DeltaCloudClientException {
- try {
- Instance instance = JAXB.unmarshal(new StringReader(xml), Instance.class);
-
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document document = db.parse(new InputSource(new StringReader(xml)));
-
- instance.setImageId(getIdFromHref(getAttributeValues(document, "image", "href").get(0))); //$NON-NLS-1$ //$NON-NLS-2$
- instance.setProfileId(getIdFromHref(getAttributeValues(document, "hardware_profile", "href").get(0))); //$NON-NLS-1$ //$NON-NLS-2$
- getProfileProperties(instance, getPropertyNodes(document, "hardware_profile")); //$NON-NLS-1$
- instance.setRealmId(getIdFromHref(getAttributeValues(document, "realm", "href").get(0))); //$NON-NLS-1$ //$NON-NLS-2$
- instance.setState(getElementText(document, "state").get(0)); //$NON-NLS-1$
- getAuthentication(document, instance);
- instance.setActions(createInstanceActions(instance, document));
-
- return instance;
- } catch (DeltaCloudClientException e) {
- throw e;
- } catch (Exception e) {
- DeltaCloudClientException newException = new DeltaCloudClientException(e.getLocalizedMessage());
- throw newException;
- }
- }
-
- private List<InstanceAction> createInstanceActions(Instance instance, Document document)
- throws DeltaCloudClientException {
- final List<InstanceAction> actions = new ArrayList<InstanceAction>();
- forEachNode(document, "link", new INodeVisitor() {
-
- @Override
- public void visit(Node node) throws Exception {
- NamedNodeMap attributes = node.getAttributes();
- String name = getAttributeTextContent("rel", attributes, node);
- String url = getAttributeTextContent("href", attributes, node);
- String method = getAttributeTextContent("method", attributes, node);
- actions.add(new InstanceAction(name, stripBaseUrl(url), method));
- }
- });
- return actions;
- }
-
- private String stripBaseUrl(String url) throws DeltaCloudClientException {
- String baseUrlString = baseUrl.toString();
- if (url.indexOf(baseUrlString) != 0) {
- throw new DeltaCloudClientException(MessageFormat.format(
- "Resource at {0} is not child resource of root resource at {1}", url, baseUrl));
- }
-
- return url.substring(baseUrlString.length());
- }
-
- private String getAttributeTextContent(String attributeName, NamedNodeMap namedNodeMap, Node node)
- throws DeltaCloudClientException {
- Node attributeNode = namedNodeMap.getNamedItem(attributeName);
- if (attributeNode == null) {
- throw new DeltaCloudClientException(MessageFormat.format("Could not find attribute {0} in node {1}",
- attributeName, node.getNodeName()));
- }
-
- return attributeNode.getTextContent();
- }
-
- private HardwareProfile buildHardwareProfile(String xml) throws DeltaCloudClientException {
- 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"); //$NON-NLS-1$
-
- for (Node n : nodes) {
- Property p = new Property();
- p.setName(n.getAttributes().getNamedItem("name").getNodeValue()); //$NON-NLS-1$
- p.setValue(n.getAttributes().getNamedItem("value").getNodeValue()); //$NON-NLS-1$
- p.setUnit(n.getAttributes().getNamedItem("unit").getNodeValue()); //$NON-NLS-1$
- p.setKind(n.getAttributes().getNamedItem("kind").getNodeValue()); //$NON-NLS-1$
- if (p.getKind().equals("range")) { //$NON-NLS-1$
- NodeList children = n.getChildNodes();
- for (int i = 0; i < children.getLength(); ++i) {
- Node child = children.item(i);
- if (child.getNodeName().equals("range")) { //$NON-NLS-1$
- String first = child.getAttributes().getNamedItem("first").getNodeValue(); //$NON-NLS-1$
- String last = child.getAttributes().getNamedItem("last").getNodeValue(); //$NON-NLS-1$
- p.setRange(first, last);
- }
- }
- } else if (p.getKind().equals("enum")) { //$NON-NLS-1$
- 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")) { //$NON-NLS-1$
- NodeList enumChildren = child.getChildNodes();
- for (int j = 0; j < enumChildren.getLength(); ++j) {
- Node enumChild = enumChildren.item(j);
- if (enumChild.getNodeName().equals("entry")) {
- enums.add(enumChild.getAttributes().getNamedItem("value").getNodeValue()); //$NON-NLS-1$
- }
- }
- }
- }
- p.setEnums(enums);
- }
- profile.getProperties().add(p);
- }
- return profile;
- } catch (Exception e) {
- e.printStackTrace();
- }
- return null;
- }
-
- private void forEachNode(Document document, String tagName, INodeVisitor visitor) throws DeltaCloudClientException {
- NodeList elements = document.getElementsByTagName(tagName);
- for (int i = 0; i < elements.getLength(); i++) {
- try {
- visitor.visit(elements.item(i));
- } catch (Exception e) {
- throw new DeltaCloudClientException(e.getMessage());
- }
- }
- }
-
- private List<String> getAttributeValues(Document document, String elementName, String attributeName) {
- NodeList elements = document.getElementsByTagName(elementName);
- ArrayList<String> values = new ArrayList<String>();
- for (int i = 0; i < elements.getLength(); i++) {
- values.add(elements.item(i).getAttributes().getNamedItem(attributeName).getTextContent());
- }
- return values;
- }
-
- private List<String> getElementText(Document document, String elementName) {
- NodeList elements = document.getElementsByTagName(elementName);
- ArrayList<String> values = new ArrayList<String>();
- for (int i = 0; i < elements.getLength(); i++) {
- values.add(elements.item(i).getTextContent());
- }
- return values;
- }
-
- private List<Node> getPropertyNodes(Document document, String elementName) {
- NodeList elements = document.getElementsByTagName(elementName);
- ArrayList<Node> values = new ArrayList<Node>();
- for (int i = 0; i < elements.getLength(); i++) {
- NodeList children = elements.item(i).getChildNodes();
- for (int j = 0; j < children.getLength(); ++j) {
- Node child = children.item(j);
- if (child.getNodeName().equals("property")) { //$NON-NLS-1$
- values.add(child);
- }
- }
- }
- return values;
- }
-
- private void getAuthentication(Document document, Instance instance) {
- NodeList elements = document.getElementsByTagName("authentication");
- for (int i = 0; i < elements.getLength(); i++) {
- Node element = elements.item(i);
- NamedNodeMap attrs = element.getAttributes();
- Node type = attrs.getNamedItem("type"); //$NON-NLS-1$
- if (type.getNodeValue().equals("key")) { //$NON-NLS-1$
- NodeList children = element.getChildNodes();
- for (int j = 0; j < children.getLength(); ++j) {
- Node child = children.item(j);
- if (child.getNodeName().equals("login")) { //$NON-NLS-1$
- NodeList loginChildren = child.getChildNodes();
- for (int k = 0; k < loginChildren.getLength(); ++k) {
- Node loginChild = loginChildren.item(k);
- if (loginChild.getNodeName().equals("keyname")) { //$NON-NLS-1$
- instance.setKey(loginChild.getTextContent());
- }
- }
- }
- }
- }
- }
- }
-
- private void getProfileProperties(Instance instance, List<Node> propertyNodes) {
- if (propertyNodes != null) {
- for (Iterator<Node> i = propertyNodes.iterator(); i.hasNext();) {
- Node n = i.next();
- NamedNodeMap attrs = n.getAttributes();
- String name = attrs.getNamedItem("name").getNodeValue(); //$NON-NLS-1$
- if (name.equals("memory")) { //$NON-NLS-1$
- String memory = attrs.getNamedItem("value").getNodeValue(); //$NON-NLS-1$
- if (attrs.getNamedItem("unit") != null) { //$NON-NLS-1$
- memory += " " + attrs.getNamedItem("unit").getNodeValue(); //$NON-NLS-1$
- }
- instance.setMemory(memory);
- } else if (name.equals("storage")) { //$NON-NLS-1$
- String storage = attrs.getNamedItem("value").getNodeValue(); //$NON-NLS-1$
- if (attrs.getNamedItem("unit") != null) { //$NON-NLS-1$
- 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);
- }
- }
- }
- }
-
- private String getIdFromHref(String href) {
- return href.substring(href.lastIndexOf("/") + 1, href.length());
- }
-
- private <T extends DeltaCloudObject> List<T> listDeltaCloudObjects(Class<T> clazz, String path, String elementName)
- throws DeltaCloudClientException {
- try {
- Document document = getDocument(path);
- ArrayList<T> dco = new ArrayList<T>();
- NodeList nodeList = document.getElementsByTagName(elementName);
- for (int i = 0; i < nodeList.getLength(); i++) {
- dco.add(buildDeltaCloudObject(clazz, nodeToString(nodeList.item(i))));
- }
- return dco;
- } catch (DeltaCloudClientException e) {
- throw e;
- } catch (Exception e) {
- throw new DeltaCloudClientException("Could not list object of type " + clazz, e);
- }
- }
-
- private Document getDocument(String path) throws DeltaCloudClientException, ParserConfigurationException,
- SAXException, IOException {
- InputSource is = new InputSource(new StringReader(sendRequest(path, HttpMethod.GET)));
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- DocumentBuilder db = dbf.newDocumentBuilder();
- Document document = db.parse(is);
- return document;
- }
-
- @SuppressWarnings("unchecked")
- private <T extends Object> T buildDeltaCloudObject(Class<T> clazz, String node) throws DeltaCloudClientException {
- if (clazz.equals(Instance.class)) {
- return (T) buildInstance(node);
- } else if (clazz.equals(HardwareProfile.class)) {
- return (T) buildHardwareProfile(node);
- } else {
- return JAXB.unmarshal(new StringReader(node), clazz);
- }
- }
-
/**
- * Performs an action, indicated by a given action id, on a instance with a
- * given instance id.
- * <p>
- * Retrieves the instance with the given id, checks for the actions that are
- * available to it and performs the given action only if it is available. It
- * is important to note that this method performs several REST calls to the
- * server.
+ * Returns an Instance from the Delta Cloud Provider given on the Instances
+ * ID
*
* @param instanceId
- * the id of the instance to perfom the action on
- * @param action
- * the action id to perform
- * @return true, if the action was performed successfully
+ * @return
* @throws DeltaCloudClientException
- * indicates that an error occured while performing the action
+ */
+ public Instance listInstances(String instanceId) throws DeltaCloudClientException;
+
+ /**
+ * Creates a new Delta Cloud Instance based on the Image specified by the
+ * Image ID. Default parameters are used for the Flavor, Realm and Name.
+ * These are specified by the Delta Cloud Provider
*
- * @see #startInstance(String)
- * @see #shutdownInstance(String)
- * @see #destroyInstance(String)
- * @see #rebootInstance(String)
+ * @param imageId
+ * @return The newly created Delta Cloud Instance
+ * @throws DeltaCloudClientException
*/
- public boolean performInstanceAction(String instanceId, String actionName) throws DeltaCloudClientException {
- Instance instance = listInstances(instanceId);
- InstanceAction action = instance.getAction(actionName);
- if (action != null) {
- sendRequest(action.getUrl(), action.getMethod());
- return true;
- }
- return false;
- }
+ public Instance createInstance(String imageId) throws DeltaCloudClientException;
- private String nodeToString(Node node) throws DeltaCloudClientException {
- try {
- StringWriter writer = new StringWriter();
- Transformer t = TransformerFactory.newInstance().newTransformer();
- t.transform(new DOMSource(node), new StreamResult(writer));
- return writer.toString();
- } catch (TransformerException e) {
- throw new DeltaCloudClientException("Error transforming node to string", e);
- }
- }
-
- private interface INodeVisitor {
- public void visit(Node node) throws Exception;
- }
-
+ /**
+ * Creates a new Delta Cloud Instance, the instance will be based on the
+ * Image specified by the instance ID. It will be of type flavor and in the
+ * location realm
+ *
+ * @param imageId
+ * @param flavor
+ * @param realm
+ * @param name
+ * @return
+ * @throws DeltaCloudClientException
+ */
+ public Instance createInstance(String imageId, String flavor, String realm, String name)
+ throws DeltaCloudClientException;
}
Copied: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java (from rev 26235, 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/DeltaCloudClientImpl.java (rev 0)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -0,0 +1,670 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.bind.JAXB;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.Path;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class DeltaCloudClientImpl implements InternalDeltaCloudClient {
+
+ private static final String BASEURL_API = "/api";
+ private static final String PEM_FILE_SUFFIX = "pem";
+ private static final String DOCUMENT_ELEMENT_DRIVER = "driver";
+ private static final String DOCUMENT_ELEMENT_API = "api";
+
+ public static Logger logger = Logger.getLogger(DeltaCloudClientImpl.class);
+
+ public static enum DeltaCloudServerType {
+ UNKNOWN, MOCK, EC2
+ }
+
+ private static enum DCNS {
+ TYPE {
+ public String getResourceName() {
+ return "";
+ }
+ }
+ ,
+ INSTANCES
+ , REALMS
+ , IMAGES
+ , HARDWARE_PROFILES
+ , KEYS
+ , START
+ , STOP
+ , REBOOT
+ , DESTROY;
+
+ @Override
+ public String toString() {
+ return "/" + getResourceName();
+ }
+
+ public String getResourceName() {
+ return name().toLowerCase();
+ }
+ }
+
+ private URL baseUrl;
+ private String username;
+ private String password;
+
+ public DeltaCloudClientImpl(String url) throws MalformedURLException {
+ this(url, null, null);
+ }
+
+ public DeltaCloudClientImpl(String url, String username, String password) throws MalformedURLException {
+
+ logger.debug("Creating new Delta Cloud Client for Server: " + url);
+
+ this.baseUrl = new URL(url + BASEURL_API);
+ this.username = username;
+ this.password = password;
+ }
+
+ private String sendRequest(String path, HttpMethod httpMethod) throws DeltaCloudClientException {
+ DefaultHttpClient httpClient = addCredentials(new DefaultHttpClient());
+ String requestUrl = baseUrl.toString() + path;
+ logger.debug("Sending Request to: " + requestUrl);
+
+ try {
+ HttpUriRequest request = getRequest(httpMethod, requestUrl);
+ HttpResponse httpResponse = httpClient.execute(request);
+ throwOnHttpErrors(requestUrl, httpResponse);
+ return getResponse(httpResponse.getEntity());
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (IOException e) {
+ logger.error("Error processing request to: " + requestUrl, e);
+ throw new DeltaCloudClientException("Error processing request to: " + requestUrl, e);
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e.getMessage());
+ } finally {
+ httpClient.getConnectionManager().shutdown();
+ }
+ }
+
+ private void throwOnHttpErrors(String requestUrl, HttpResponse httpResponse) throws DeltaCloudClientException {
+ int statusCode = httpResponse.getStatusLine().getStatusCode();
+ if (HttpStatusCode.OK.isStatus(statusCode)) {
+ return;
+ } else if (HttpStatusCode.FORBIDDEN.isStatus(statusCode)) {
+ throw new DeltaCloudAuthException(
+ MessageFormat.format("The server reported an authorization error \"{0}\" on requesting \"{1}\"",
+ httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
+ } else if (HttpStatusCode.NOT_FOUND.isStatus(statusCode)) {
+ throw new DeltaCloudNotFoundClientException(
+ MessageFormat.format("The server could not find the resource \"{0}\"", requestUrl));
+ } else if (HttpStatusRange.CLIENT_ERROR.isInRange(statusCode)
+ || HttpStatusRange.SERVER_ERROR.isInRange(statusCode)) {
+ throw new DeltaCloudClientException(
+ MessageFormat.format("The server reported an error \"{0}\" on requesting \"{1}\"",
+ httpResponse.getStatusLine().getReasonPhrase(), requestUrl));
+ }
+ }
+
+ private String getResponse(HttpEntity entity) throws IOException,
+ DeltaCloudClientException {
+ if (entity == null) {
+ return null;
+ }
+ String xml = readInputStreamToString(entity.getContent());
+ logger.debug("Response\n" + xml);
+ return xml;
+ }
+
+ /**
+ * Returns a request instance for the given request type and url.
+ *
+ * @param httpMethod
+ * the request type to use
+ * @param requestUrl
+ * the requested url
+ * @return the request instance
+ */
+ protected HttpUriRequest getRequest(HttpMethod httpMethod, String requestUrl) {
+ HttpUriRequest request = null;
+ switch (httpMethod) {
+ case POST:
+ request = new HttpPost(requestUrl);
+ break;
+ case DELETE:
+ request = new HttpDelete(requestUrl);
+ break;
+ case GET:
+ default:
+ request = new HttpGet(requestUrl);
+ }
+ request.setHeader("Accept", "application/xml;q=1");
+ return request;
+ }
+
+ /**
+ * Adds the credentials to the given http client.
+ *
+ * @param httpClient
+ * the http client
+ * @return the default http client
+ */
+ private DefaultHttpClient addCredentials(DefaultHttpClient httpClient) {
+ if (username != null && password != null) {
+ httpClient.getCredentialsProvider().setCredentials(
+ new AuthScope(baseUrl.getHost(), baseUrl.getPort()),
+ new UsernamePasswordCredentials(username, password));
+ }
+ return httpClient;
+ }
+
+ private static String readInputStreamToString(InputStream is) throws DeltaCloudClientException {
+ try {
+ try {
+ if (is != null) {
+ StringBuilder sb = new StringBuilder();
+ String line;
+
+ BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ while ((line = reader.readLine()) != null) {
+ sb.append(line).append("\n");
+ }
+ return sb.toString();
+ }
+ } finally {
+ is.close();
+ }
+ } catch (Exception e) {
+ throw new DeltaCloudClientException("Error converting Response to String", e);
+ }
+ return "";
+ }
+
+ public DeltaCloudServerType getServerType() {
+ DeltaCloudServerType serverType = DeltaCloudServerType.UNKNOWN;
+ try {
+ String query = "?format=xml";
+ String apiResponse = sendRequest(DCNS.TYPE + query, HttpMethod.GET);
+ DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ Document document = db.parse(new InputSource(new StringReader(apiResponse)));
+
+ NodeList elements = document.getElementsByTagName(DOCUMENT_ELEMENT_API);
+ if (elements.getLength() > 0) {
+ Node n = elements.item(0);
+ Node driver = n.getAttributes().getNamedItem(DOCUMENT_ELEMENT_DRIVER);
+ if (driver != null) {
+ String driverValue = driver.getNodeValue();
+ serverType = DeltaCloudServerType.valueOf(driverValue.toUpperCase());
+ }
+ }
+ } catch (Exception e) {
+ serverType = DeltaCloudServerType.UNKNOWN;
+ }
+ return serverType;
+ }
+
+ @Override
+ public Instance createInstance(String imageId) throws DeltaCloudClientException {
+ String query = "?image_id=" + imageId;
+ return buildInstance(sendRequest(DCNS.INSTANCES + query, HttpMethod.POST));
+ }
+
+ @Override
+ public Instance createInstance(String imageId, String profileId, String realmId, String name)
+ throws DeltaCloudClientException {
+ return createInstance(imageId, profileId, realmId, name, null, null, null);
+ }
+
+ public Instance createInstance(String imageId, String profileId, String realmId, String name, String memory,
+ String storage) throws DeltaCloudClientException {
+ return createInstance(imageId, profileId, realmId, name, null, memory, storage);
+ }
+
+ public Instance createInstance(String imageId, String profileId, String realmId, String name, String keyname,
+ String memory, String storage) throws DeltaCloudClientException {
+ String query = "?image_id=" + imageId + "&hwp_id=" + profileId + "&realm_id=" + realmId + "&name=" + name;
+ if (memory != null)
+ query += "&hwp_memory=" + memory;
+ if (storage != null)
+ query += "&hwp_storage=" + storage;
+ if (keyname != null)
+ query += "&keyname=" + keyname;
+ query += "&commit=create";
+ return buildInstance(sendRequest(DCNS.INSTANCES + query, HttpMethod.POST));
+ }
+
+ @Override
+ public HardwareProfile listProfile(String profileId) throws DeltaCloudClientException {
+ String request = DCNS.HARDWARE_PROFILES + "/" + profileId;
+ return buildDeltaCloudObject(HardwareProfile.class, sendRequest(request, HttpMethod.GET));
+ }
+
+ @Override
+ public List<HardwareProfile> listProfiles() throws DeltaCloudClientException {
+ return listDeltaCloudObjects(HardwareProfile.class, DCNS.HARDWARE_PROFILES.toString(), "hardware_profile");
+ }
+
+ @Override
+ public List<Image> listImages() throws DeltaCloudClientException {
+ return listDeltaCloudObjects(Image.class, DCNS.IMAGES.toString(), "image");
+ }
+
+ @Override
+ public Image listImages(String imageId) throws DeltaCloudClientException {
+ return JAXB.unmarshal(new StringReader(sendRequest(DCNS.IMAGES + "/" + imageId, HttpMethod.GET)), Image.class);
+ }
+
+ @Override
+ public List<Instance> listInstances() throws DeltaCloudClientException {
+ return listDeltaCloudObjects(Instance.class, DCNS.INSTANCES.toString(), "instance");
+ }
+
+ @Override
+ public Instance listInstances(String instanceId) throws DeltaCloudClientException {
+ return buildInstance(sendRequest(DCNS.INSTANCES + "/" + instanceId, HttpMethod.GET));
+ }
+
+ @Override
+ public List<Realm> listRealms() throws DeltaCloudClientException {
+ return listDeltaCloudObjects(Realm.class, DCNS.REALMS.toString(), "realm");
+ }
+
+ @Override
+ public Realm listRealms(String realmId) throws DeltaCloudClientException {
+ return JAXB.unmarshal(new StringReader(sendRequest(DCNS.REALMS + "/" + realmId, HttpMethod.GET)), Realm.class);
+ }
+
+ /**
+ * Retrieves a key for a given name on the deltacloud server and stores it
+ * in the file at the given path. The file gets created if the file path
+ * does not exist yet.
+ *
+ * @param keyname
+ * the name of the key to retrieve from the server
+ * @param keyStoreLocation
+ * the path to the file to store the key in
+ * @throws DeltaCloudClientException
+ * the delta cloud client exception
+ */
+ public void createKey(String keyname, String keyStoreLocation) throws DeltaCloudClientException {
+ String xml = sendRequest(DCNS.KEYS + "?name=" + keyname, HttpMethod.POST);
+ try {
+ String key = trimKey(getKey(xml));
+ File keyFile = createKeyFile(keyname, keyStoreLocation);
+ storeKey(key, keyFile);
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e);
+ }
+ }
+
+ private void storeKey(String key, File keyFile) throws IOException {
+ FileWriter w = new FileWriter(keyFile);
+ w.write(key);
+ w.close();
+ }
+
+ private String trimKey(List<String> keyText) throws IOException {
+ StringBuffer sb = new StringBuffer();
+ String line;
+ BufferedReader reader = new BufferedReader(new StringReader(keyText.get(0)));
+ while ((line = reader.readLine()) != null) {
+ // We must trim off the white-space from the xml
+ // Complete white-space lines are to be ignored.
+ String trimmedLine = line.trim();
+ if (trimmedLine.length() > 0) {
+ sb.append(trimmedLine).append("\n");
+ }
+ }
+ return sb.toString();
+ }
+
+ private List<String> getKey(String xml) throws ParserConfigurationException, SAXException, IOException {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document document = db.parse(new InputSource(new StringReader(xml)));
+ List<String> keyText = getElementText(document, PEM_FILE_SUFFIX); //$NON-NLS-1$
+ return keyText;
+ }
+
+ private File createKeyFile(String keyname, String keyStoreLocation) throws IOException {
+ File keyFile = Path.fromOSString(keyStoreLocation).append(keyname + "." + PEM_FILE_SUFFIX).toFile(); //$NON-NLS-1$
+ if (!keyFile.exists()) {
+ keyFile.createNewFile();
+ }
+ keyFile.setReadable(false, false);
+ keyFile.setWritable(true, true);
+ keyFile.setReadable(true, true);
+ return keyFile;
+ }
+
+ public void deleteKey(String keyname) throws DeltaCloudClientException {
+ sendRequest(DCNS.KEYS + "/" + keyname, HttpMethod.DELETE);
+ }
+
+ private Instance updateInstance(String xml, Instance instance) throws DeltaCloudClientException {
+ try {
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document document = db.parse(new InputSource(new StringReader(xml)));
+
+ instance.setImageId(getIdFromHref(getAttributeValues(document, "image", "href").get(0))); //$NON-NLS-1$ //$NON-NLS-2$
+ instance.setProfileId(getIdFromHref(getAttributeValues(document, "hardware_profile", "href").get(0))); //$NON-NLS-1$ //$NON-NLS-2$
+ getProfileProperties(instance, getPropertyNodes(document, "hardware_profile")); //$NON-NLS-1$
+ instance.setRealmId(getIdFromHref(getAttributeValues(document, "realm", "href").get(0))); //$NON-NLS-1$ //$NON-NLS-2$
+ instance.setState(getElementText(document, "state").get(0)); //$NON-NLS-1$
+ getAuthentication(document, instance);
+ instance.setActions(createInstanceActions(instance, document));
+
+ return instance;
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ DeltaCloudClientException newException = new DeltaCloudClientException(e.getLocalizedMessage());
+ throw newException;
+ }
+ }
+
+ private Instance buildInstance(String xml) throws DeltaCloudClientException {
+ Instance instance = JAXB.unmarshal(new StringReader(xml), Instance.class);
+ updateInstance(xml, instance);
+ return instance;
+ }
+
+ private List<InstanceAction> createInstanceActions(final Instance instance, Document document)
+ throws DeltaCloudClientException {
+ final List<InstanceAction> actions = new ArrayList<InstanceAction>();
+ forEachNode(document, "link", new INodeVisitor() {
+
+ @Override
+ public void visit(Node node) throws Exception {
+ NamedNodeMap attributes = node.getAttributes();
+ String name = getAttributeTextContent("rel", attributes, node);
+ String url = getAttributeTextContent("href", attributes, node);
+ String method = getAttributeTextContent("method", attributes, node);
+ actions.add(new InstanceAction(name, stripBaseUrl(url), method, instance));
+ }
+ });
+ return actions;
+ }
+
+ private String stripBaseUrl(String url) throws DeltaCloudClientException {
+ String baseUrlString = baseUrl.toString();
+ if (url.indexOf(baseUrlString) != 0) {
+ throw new DeltaCloudClientException(MessageFormat.format(
+ "Resource at {0} is not child resource of root resource at {1}", url, baseUrl));
+ }
+
+ return url.substring(baseUrlString.length());
+ }
+
+ private String getAttributeTextContent(String attributeName, NamedNodeMap namedNodeMap, Node node)
+ throws DeltaCloudClientException {
+ Node attributeNode = namedNodeMap.getNamedItem(attributeName);
+ if (attributeNode == null) {
+ throw new DeltaCloudClientException(MessageFormat.format("Could not find attribute {0} in node {1}",
+ attributeName, node.getNodeName()));
+ }
+
+ return attributeNode.getTextContent();
+ }
+
+ private HardwareProfile buildHardwareProfile(String xml) throws DeltaCloudClientException {
+ 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"); //$NON-NLS-1$
+
+ for (Node n : nodes) {
+ Property p = new Property();
+ p.setName(n.getAttributes().getNamedItem("name").getNodeValue()); //$NON-NLS-1$
+ p.setValue(n.getAttributes().getNamedItem("value").getNodeValue()); //$NON-NLS-1$
+ p.setUnit(n.getAttributes().getNamedItem("unit").getNodeValue()); //$NON-NLS-1$
+ p.setKind(n.getAttributes().getNamedItem("kind").getNodeValue()); //$NON-NLS-1$
+ if (p.getKind().equals("range")) { //$NON-NLS-1$
+ NodeList children = n.getChildNodes();
+ for (int i = 0; i < children.getLength(); ++i) {
+ Node child = children.item(i);
+ if (child.getNodeName().equals("range")) { //$NON-NLS-1$
+ String first = child.getAttributes().getNamedItem("first").getNodeValue(); //$NON-NLS-1$
+ String last = child.getAttributes().getNamedItem("last").getNodeValue(); //$NON-NLS-1$
+ p.setRange(first, last);
+ }
+ }
+ } else if (p.getKind().equals("enum")) { //$NON-NLS-1$
+ 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")) { //$NON-NLS-1$
+ NodeList enumChildren = child.getChildNodes();
+ for (int j = 0; j < enumChildren.getLength(); ++j) {
+ Node enumChild = enumChildren.item(j);
+ if (enumChild.getNodeName().equals("entry")) {
+ enums.add(enumChild.getAttributes().getNamedItem("value").getNodeValue()); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ p.setEnums(enums);
+ }
+ profile.getProperties().add(p);
+ }
+ return profile;
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ private void forEachNode(Document document, String tagName, INodeVisitor visitor) throws DeltaCloudClientException {
+ NodeList elements = document.getElementsByTagName(tagName);
+ for (int i = 0; i < elements.getLength(); i++) {
+ try {
+ visitor.visit(elements.item(i));
+ } catch (Exception e) {
+ throw new DeltaCloudClientException(e.getMessage());
+ }
+ }
+ }
+
+ private List<String> getAttributeValues(Document document, String elementName, String attributeName) {
+ NodeList elements = document.getElementsByTagName(elementName);
+ ArrayList<String> values = new ArrayList<String>();
+ for (int i = 0; i < elements.getLength(); i++) {
+ values.add(elements.item(i).getAttributes().getNamedItem(attributeName).getTextContent());
+ }
+ return values;
+ }
+
+ private List<String> getElementText(Document document, String elementName) {
+ NodeList elements = document.getElementsByTagName(elementName);
+ ArrayList<String> values = new ArrayList<String>();
+ for (int i = 0; i < elements.getLength(); i++) {
+ values.add(elements.item(i).getTextContent());
+ }
+ return values;
+ }
+
+ private List<Node> getPropertyNodes(Document document, String elementName) {
+ NodeList elements = document.getElementsByTagName(elementName);
+ ArrayList<Node> values = new ArrayList<Node>();
+ for (int i = 0; i < elements.getLength(); i++) {
+ NodeList children = elements.item(i).getChildNodes();
+ for (int j = 0; j < children.getLength(); ++j) {
+ Node child = children.item(j);
+ if (child.getNodeName().equals("property")) { //$NON-NLS-1$
+ values.add(child);
+ }
+ }
+ }
+ return values;
+ }
+
+ private void getAuthentication(Document document, Instance instance) {
+ NodeList elements = document.getElementsByTagName("authentication");
+ for (int i = 0; i < elements.getLength(); i++) {
+ Node element = elements.item(i);
+ NamedNodeMap attrs = element.getAttributes();
+ Node type = attrs.getNamedItem("type"); //$NON-NLS-1$
+ if (type.getNodeValue().equals("key")) { //$NON-NLS-1$
+ NodeList children = element.getChildNodes();
+ for (int j = 0; j < children.getLength(); ++j) {
+ Node child = children.item(j);
+ if (child.getNodeName().equals("login")) { //$NON-NLS-1$
+ NodeList loginChildren = child.getChildNodes();
+ for (int k = 0; k < loginChildren.getLength(); ++k) {
+ Node loginChild = loginChildren.item(k);
+ if (loginChild.getNodeName().equals("keyname")) { //$NON-NLS-1$
+ instance.setKey(loginChild.getTextContent());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void getProfileProperties(Instance instance, List<Node> propertyNodes) {
+ if (propertyNodes != null) {
+ for (Iterator<Node> i = propertyNodes.iterator(); i.hasNext();) {
+ Node n = i.next();
+ NamedNodeMap attrs = n.getAttributes();
+ String name = attrs.getNamedItem("name").getNodeValue(); //$NON-NLS-1$
+ if (name.equals("memory")) { //$NON-NLS-1$
+ String memory = attrs.getNamedItem("value").getNodeValue(); //$NON-NLS-1$
+ if (attrs.getNamedItem("unit") != null) { //$NON-NLS-1$
+ memory += " " + attrs.getNamedItem("unit").getNodeValue(); //$NON-NLS-1$
+ }
+ instance.setMemory(memory);
+ } else if (name.equals("storage")) { //$NON-NLS-1$
+ String storage = attrs.getNamedItem("value").getNodeValue(); //$NON-NLS-1$
+ if (attrs.getNamedItem("unit") != null) { //$NON-NLS-1$
+ 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);
+ }
+ }
+ }
+ }
+
+ private String getIdFromHref(String href) {
+ return href.substring(href.lastIndexOf("/") + 1, href.length());
+ }
+
+ private <T extends DeltaCloudObject> List<T> listDeltaCloudObjects(Class<T> clazz, String path, String elementName)
+ throws DeltaCloudClientException {
+ try {
+ Document document = getDocument(path);
+ ArrayList<T> dco = new ArrayList<T>();
+ NodeList nodeList = document.getElementsByTagName(elementName);
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ dco.add(buildDeltaCloudObject(clazz, nodeToString(nodeList.item(i))));
+ }
+ return dco;
+ } catch (DeltaCloudClientException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new DeltaCloudClientException("Could not list object of type " + clazz, e);
+ }
+ }
+
+ private Document getDocument(String path) throws DeltaCloudClientException, ParserConfigurationException,
+ SAXException, IOException {
+ InputSource is = new InputSource(new StringReader(sendRequest(path, HttpMethod.GET)));
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ DocumentBuilder db = dbf.newDocumentBuilder();
+ Document document = db.parse(is);
+ return document;
+ }
+
+ @SuppressWarnings("unchecked")
+ private <T extends Object> T buildDeltaCloudObject(Class<T> clazz, String node) throws DeltaCloudClientException {
+ if (clazz.equals(Instance.class)) {
+ return (T) buildInstance(node);
+ } else if (clazz.equals(HardwareProfile.class)) {
+ return (T) buildHardwareProfile(node);
+ } else {
+ return JAXB.unmarshal(new StringReader(node), clazz);
+ }
+ }
+
+ public boolean performInstanceAction(InstanceAction action) throws DeltaCloudClientException {
+ if (action != null) {
+ String response = sendRequest(action.getUrl(), action.getMethod());
+ if (!InstanceAction.DESTROY.equals(action.getName())) {
+ updateInstance(response, action.getInstance());
+ }
+ return true;
+ }
+ return false;
+ }
+
+ private String nodeToString(Node node) throws DeltaCloudClientException {
+ try {
+ StringWriter writer = new StringWriter();
+ Transformer t = TransformerFactory.newInstance().newTransformer();
+ t.transform(new DOMSource(node), new StreamResult(writer));
+ return writer.toString();
+ } catch (TransformerException e) {
+ throw new DeltaCloudClientException("Error transforming node to string", e);
+ }
+ }
+
+ private interface INodeVisitor {
+ public void visit(Node node) throws Exception;
+ }
+
+}
Copied: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java (from rev 26088, trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java)
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java (rev 0)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat Inc..
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat Incorporated - initial API and implementation
+ *******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+public class DeltaCloudNotFoundClientException extends DeltaCloudClientException {
+
+ private static final long serialVersionUID = 1L;
+
+ public DeltaCloudNotFoundClientException(String message, Throwable clause)
+ {
+ super(message, clause);
+ }
+
+ public DeltaCloudNotFoundClientException(Throwable clause)
+ {
+ super(clause);
+ }
+
+ public DeltaCloudNotFoundClientException(String message)
+ {
+ super(message);
+ }
+
+}
Property changes on: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundClientException.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudNotFoundException.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Red Hat Inc..
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Red Hat Incorporated - initial API and implementation
- *******************************************************************************/
-package org.jboss.tools.deltacloud.core.client;
-
-public class DeltaCloudNotFoundException extends DeltaCloudClientException {
-
- private static final long serialVersionUID = 1L;
-
- public DeltaCloudNotFoundException(String message, Throwable clause)
- {
- super(message, clause);
- }
-
- public DeltaCloudNotFoundException(Throwable clause)
- {
- super(clause);
- }
-
- public DeltaCloudNotFoundException(String message)
- {
- super(message);
- }
-
-}
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-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -15,73 +15,69 @@
import javax.xml.bind.annotation.XmlElement;
-public class Instance extends DeltaCloudObject
-{
+public class Instance extends DeltaCloudObject {
private static final long serialVersionUID = 1L;
-
- public static enum State { RUNNING, STOPPED, PENDING, TERMINATED, BOGUS };
-
- @XmlElement(name="owner_id")
+
+ public static enum State {
+ RUNNING, STOPPED, PENDING, TERMINATED, BOGUS
+ };
+
+ @XmlElement(name = "owner_id")
private String ownerId;
-
+
@XmlElement
private String name;
-
+
private String imageId;
private String profileId;
private String memory;
-
+
private String storage;
-
+
private String cpu;
-
+
private String realmId;
-
+
private String keyname;
-
+
@XmlElement
private State state;
-
+
private List<InstanceAction> actions;
-
- @XmlElement(name="public_addresses")
+
+ @XmlElement(name = "public_addresses")
private AddressList publicAddresses;
-
- @XmlElement(name="private_addresses")
+
+ @XmlElement(name = "private_addresses")
private AddressList privateAddresses;
-
- private Instance()
- {
+
+ private Instance() {
}
@SuppressWarnings("unused")
- private void setOwnerId(String ownerId)
- {
+ private void setOwnerId(String ownerId) {
this.ownerId = ownerId;
}
-
+
@SuppressWarnings("unused")
- private void setName(String name)
- {
+ private void setName(String name) {
this.name = name;
}
-
- protected void setImageId(String imageId)
- {
+
+ protected void setImageId(String imageId) {
this.imageId = imageId;
}
-
- protected void setProfileId(String profileId)
- {
+
+ protected void setProfileId(String profileId) {
this.profileId = profileId;
}
-
+
protected void setMemory(String memory) {
this.memory = memory;
}
-
+
protected void setStorage(String storage) {
this.storage = storage;
}
@@ -89,70 +85,61 @@
protected void setCPU(String cpu) {
this.cpu = cpu;
}
-
- protected void setRealmId(String realmId)
- {
+
+ protected void setRealmId(String realmId) {
this.realmId = realmId;
}
-
- protected void setActions(List<InstanceAction> actions)
- {
+
+ protected void setActions(List<InstanceAction> actions) {
this.actions = actions;
}
- protected void setState(String state)
- {
+ protected void setState(String state) {
try {
this.state = State.valueOf(state);
} catch (Exception e) {
this.state = State.BOGUS;
}
}
-
+
public void setKey(String keyname) {
this.keyname = keyname;
}
-
+
public String getKey() {
return keyname;
}
-
+
@SuppressWarnings("unused")
- private void setPrivateAddresses(AddressList privateAddresses)
- {
+ private void setPrivateAddresses(AddressList privateAddresses) {
this.privateAddresses = privateAddresses;
}
-
+
@SuppressWarnings("unused")
- private void setPublicAddresses(AddressList publicAddresses)
- {
+ private void setPublicAddresses(AddressList publicAddresses) {
this.publicAddresses = publicAddresses;
}
-
- public String getOwnerId()
- {
+
+ public String getOwnerId() {
return ownerId;
}
- public String getName()
- {
+ public String getName() {
return name;
}
- public String getImageId()
- {
+ public String getImageId() {
return imageId;
}
- public String getProfileId()
- {
+ public String getProfileId() {
return profileId;
}
public String getMemory() {
return memory;
}
-
+
public String getStorage() {
return storage;
}
@@ -161,57 +148,65 @@
return cpu;
}
- public String getRealmId()
- {
+ public String getRealmId() {
return realmId;
}
- public State getState()
- {
+ public State getState() {
return state;
}
-
- public List<InstanceAction> getActions()
- {
+
+ public List<InstanceAction> getActions() {
return actions;
}
-
- public List<String> getActionNames()
- {
- ArrayList<String>names = new ArrayList<String>();
- for (InstanceAction action : actions)
- {
+
+ public List<String> getActionNames() {
+ ArrayList<String> names = new ArrayList<String>();
+ for (InstanceAction action : actions) {
names.add(action.getName());
}
return names;
}
-
+
public InstanceAction getAction(String name) {
if (name == null) {
return null;
}
-
- for(InstanceAction action : actions) {
+
+ for (InstanceAction action : actions) {
if (name.equals(action.getName())) {
return action;
}
}
return null;
}
-
- public List<String> getPublicAddresses()
- {
+
+ public List<String> getPublicAddresses() {
return publicAddresses.getAddress();
}
- public List<String> getPrivateAddresses()
- {
+ public List<String> getPrivateAddresses() {
return privateAddresses.getAddress();
- }
-
+ }
+
+ public boolean start(DeltaCloudClient client) throws DeltaCloudClientException {
+ return ((InternalDeltaCloudClient) client).performInstanceAction(getAction(InstanceAction.START));
+ }
+
+ public boolean stop(DeltaCloudClient client) throws DeltaCloudClientException {
+ return ((InternalDeltaCloudClient) client).performInstanceAction(getAction(InstanceAction.STOP));
+ }
+
+ public boolean destroy(DeltaCloudClient client) throws DeltaCloudClientException {
+ return ((InternalDeltaCloudClient) client).performInstanceAction(getAction(InstanceAction.DESTROY));
+ }
+
+ public boolean reboot(DeltaCloudClient client) throws DeltaCloudClientException {
+ return ((InternalDeltaCloudClient) client).performInstanceAction(getAction(InstanceAction.REBOOT));
+ }
+
@Override
- public String toString()
- {
+ public String toString() {
String s = "";
s += "Instance:\t" + getId() + "\n";
s += "Owner:\t\t" + getOwnerId() + "\n";
@@ -219,7 +214,7 @@
s += "Realm:\t\t" + getRealmId() + "\n";
s += "Profile:\t\t" + getProfileId() + "\n";
if (getMemory() != null)
- s += "Memory:\t\t" + getMemory() + "\n";
+ s += "Memory:\t\t" + getMemory() + "\n";
if (getStorage() != null) {
s += "Storage:\t\t" + getStorage() + "\n";
}
@@ -227,45 +222,32 @@
s += "CPU:\t\t" + getCPU() + "\n";
}
s += "State:\t\t" + getState() + "\n";
-
-
- for(int i = 0; i < actions.size(); i ++)
- {
- if(i == 0)
- {
- s += "Actions:\t" + actions.get(i) + "\n";
- }
- else
- {
+
+ for (int i = 0; i < actions.size(); i++) {
+ if (i == 0) {
+ s += "Actions:\t" + actions.get(i) + "\n";
+ } else {
s += "\t\t" + actions.get(i) + "\n";
}
}
-
-
- for(int i = 0; i < publicAddresses.getAddress().size(); i ++)
- {
- if(i == 0)
- {
+
+ for (int i = 0; i < publicAddresses.getAddress().size(); i++) {
+ if (i == 0) {
s += "Public Addr:\t" + publicAddresses.getAddress().get(i) + "\n";
- }
- else
- {
+ } else {
s += "\t\t" + publicAddresses.getAddress().get(i) + "\n";
}
}
-
- for(int i = 0; i < publicAddresses.getAddress().size(); i ++)
- {
- if(i == 0)
- {
+
+ for (int i = 0; i < publicAddresses.getAddress().size(); i++) {
+ if (i == 0) {
s += "Private Addr:\t" + publicAddresses.getAddress().get(i) + "\n";
- }
- else
- {
+ } else {
s += "\t\t" + privateAddresses.getAddress().get(i) + "\n";
}
}
-
+
return s;
}
+
}
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InstanceAction.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -28,15 +28,17 @@
private String name;
private String url;
private HttpMethod method;
+ private Instance instance;
- public InstanceAction(String name, String url, String method) {
- this(name, url, HttpMethod.valueOf(method.toUpperCase()));
+ protected InstanceAction(String name, String url, String method, Instance instance) {
+ this(name, url, HttpMethod.valueOf(method.toUpperCase()), instance);
}
- public InstanceAction(String name, String url, HttpMethod method) {
+ protected InstanceAction(String name, String url, HttpMethod method, Instance instance) {
this.name = name;
this.url = url;
this.method = method;
+ this.instance = instance;
}
public String getName() {
@@ -55,4 +57,8 @@
public String toString() {
return "InstanceAction [name=" + name + ", url=" + url + ", method=" + method + "]";
}
+
+ public Instance getInstance() {
+ return instance;
+ }
}
Added: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.java (rev 0)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.deltacloud.core.client;
+
+public interface InternalDeltaCloudClient extends DeltaCloudClient {
+
+ /**
+ * Performs the given action on the given instance *.
+ *
+ * @param action
+ * the action to perform
+ * @param instance
+ * the instance to perform on
+ * @return true, if the action was performed successfully
+ * @throws DeltaCloudClientException
+ * indicates that an error occured while performing the action
+ * @see InstanceAction
+ * @see Instance
+ */
+ public boolean performInstanceAction(InstanceAction action) throws DeltaCloudClientException;
+
+}
Property changes on: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/InternalDeltaCloudClient.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 13:37:05 UTC (rev 26252)
@@ -1,5 +1,8 @@
2010-11-04 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java:
+ [JBIDE-7484] removed instance related methods from client, unified funtionality in #performAction and offered additional methods on
+ Instance (#start, #stop, #destroy, #reboot). Furthermore update instance upon action responses from server.
* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java (getKeyName):
avoid NullPointerExeption when fetching name of key and keyText is not instantiated (is null)
* src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java:
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/PerformInstanceActionThread.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -32,24 +32,25 @@
private String action;
private String taskName;
private String expectedState;
-
- public PerformInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance instance,
- String action, String title, String taskName, String expectedState) {
- super(title);
- this.cloud = cloud;
- this.instance = instance;
- this.action = action;
- this.taskName = taskName;
- this.expectedState = expectedState;
- }
-
+
+ public PerformInstanceActionThread(DeltaCloud cloud, DeltaCloudInstance instance,
+ String action, String title, String taskName, String expectedState) {
+ super(title);
+ this.cloud = cloud;
+ this.instance = instance;
+ this.action = action;
+ this.taskName = taskName;
+ this.expectedState = expectedState;
+ }
+
@Override
public IStatus run(IProgressMonitor pm) {
String id = instance.getId();
try {
pm.beginTask(taskName, IProgressMonitor.UNKNOWN);
pm.worked(1);
- // To handle the user starting a new action when we haven't confirmed the last one yet,
+ // To handle the user starting a new action when we haven't
+ // confirmed the last one yet,
// cancel the previous job and then go on performing this action
Job job = cloud.getActionJob(id);
if (job != null) {
@@ -61,7 +62,8 @@
}
}
cloud.performInstanceAction(id, action);
- while (instance != null && !(instance.getState().equals(expectedState))
+ while (instance != null && expectedState != null
+ && !(instance.getState().equals(expectedState))
&& !(instance.getState().equals(DeltaCloudInstance.TERMINATED))) {
instance = cloud.refreshInstance(id);
try {
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionModel.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -12,8 +12,8 @@
import java.net.MalformedURLException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient.DeltaCloudType;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
import org.jboss.tools.internal.deltacloud.ui.common.databinding.ObservablePojo;
/**
@@ -36,11 +36,11 @@
private String username;
private String password;
- private DeltaCloudClient.DeltaCloudType cloudType;
+ private DeltaCloudClientImpl.DeltaCloudServerType cloudType;
private String initialName;
public CloudConnectionModel() {
- this("", "", "", "", (DeltaCloudType) null);
+ this("", "", "", "", (DeltaCloudServerType) null);
}
public CloudConnectionModel(String name, String url, String username, String password, String cloudType) throws MalformedURLException {
@@ -51,7 +51,7 @@
this(name, url, username, password, getDeltaCloudTypeFromUrl(url));
}
- public CloudConnectionModel(String name, String url, String username, String password, DeltaCloudType deltaCloudType) {
+ public CloudConnectionModel(String name, String url, String username, String password, DeltaCloudServerType deltaCloudType) {
this.name = name;
this.initialName = name;
this.url = url;
@@ -60,17 +60,17 @@
this.cloudType = deltaCloudType;
}
- private static DeltaCloudType getDeltaCloudTypeFromUrl(String url) throws MalformedURLException {
- return new DeltaCloudClient(url, "", "").getServerType();
+ private static DeltaCloudServerType getDeltaCloudTypeFromUrl(String url) throws MalformedURLException {
+ return new DeltaCloudClientImpl(url, "", "").getServerType();
}
- private static DeltaCloudType getDeltaCloudType(String cloudType, String url) throws MalformedURLException {
+ private static DeltaCloudServerType getDeltaCloudType(String cloudType, String url) throws MalformedURLException {
if (cloudType == null) {
return null;
}
try {
- return DeltaCloudType.valueOf(cloudType);
+ return DeltaCloudServerType.valueOf(cloudType);
} catch (IllegalArgumentException e) {
return getDeltaCloudTypeFromUrl(url);
}
@@ -112,11 +112,11 @@
getPropertyChangeSupport().firePropertyChange(PROPERTY_URL, this.url, this.url = url);
}
- public DeltaCloudClient.DeltaCloudType getType() {
+ public DeltaCloudClientImpl.DeltaCloudServerType getType() {
return cloudType;
}
- public void setType(DeltaCloudClient.DeltaCloudType cloudType) {
+ public void setType(DeltaCloudClientImpl.DeltaCloudServerType cloudType) {
getPropertyChangeSupport().firePropertyChange(PROPERTY_TYPE, this.cloudType, this.cloudType = cloudType);
}
}
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudConnectionPage.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -55,7 +55,7 @@
import org.eclipse.ui.PlatformUI;
import org.jboss.tools.common.log.LogHelper;
import org.jboss.tools.deltacloud.core.DeltaCloudManager;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient.DeltaCloudType;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
import org.jboss.tools.deltacloud.ui.Activator;
import org.jboss.tools.deltacloud.ui.SWTImagesFactory;
import org.jboss.tools.internal.deltacloud.ui.common.databinding.validator.CompositeValidator;
@@ -114,30 +114,30 @@
* the label that shall display the delta cloud type
*
* @see IValueChangeListener
- * @see DeltaCloudType
+ * @see DeltaCloudServerType
*/
private class DeltaCloudTypeLabelAdapter implements IValueChangeListener {
private Label typeLabel;
- public DeltaCloudTypeLabelAdapter(DeltaCloudType cloudType, Label typeLabel) {
+ public DeltaCloudTypeLabelAdapter(DeltaCloudServerType cloudType, Label typeLabel) {
this.typeLabel = typeLabel;
init(cloudType);
}
- private void init(DeltaCloudType cloudType) {
+ private void init(DeltaCloudServerType cloudType) {
setLabelText(cloudType);
}
@Override
public void handleValueChange(ValueChangeEvent event) {
Object newValue = event.diff.getNewValue();
- Assert.isTrue(newValue instanceof DeltaCloudType);
- setLabelText((DeltaCloudType) newValue);
+ Assert.isTrue(newValue instanceof DeltaCloudServerType);
+ setLabelText((DeltaCloudServerType) newValue);
}
- private void setLabelText(DeltaCloudType cloudType) {
- if (cloudType != null && cloudType != DeltaCloudType.UNKNOWN) {
+ private void setLabelText(DeltaCloudServerType cloudType) {
+ if (cloudType != null && cloudType != DeltaCloudServerType.UNKNOWN) {
typeLabel.setText(cloudType.toString());
} else {
typeLabel.setText("?"); // $NON-NLS-1$
@@ -503,7 +503,7 @@
*/
IObservableValue cloudTypeObservable = urlToCloudTypeConverter.getCloudTypeObservable();
DeltaCloudTypeLabelAdapter cloudTypeAdapter =
- new DeltaCloudTypeLabelAdapter((DeltaCloudType) cloudTypeObservable.getValue(), typeLabel);
+ new DeltaCloudTypeLabelAdapter((DeltaCloudServerType) cloudTypeObservable.getValue(), typeLabel);
cloudTypeObservable.addValueChangeListener(cloudTypeAdapter);
ControlDecorationSupport.create(urlTypeBinding, SWT.LEFT | SWT.TOP);
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudTypeValidator.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudTypeValidator.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/CloudTypeValidator.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -13,14 +13,14 @@
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.databinding.validation.ValidationStatus;
import org.eclipse.core.runtime.IStatus;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
public class CloudTypeValidator implements IValidator {
@Override
public IStatus validate(Object value) {
if (value != null
- && !DeltaCloudClient.DeltaCloudType.UNKNOWN.equals(value)) {
+ && !DeltaCloudClientImpl.DeltaCloudServerType.UNKNOWN.equals(value)) {
return ValidationStatus.ok();
} else {
return ValidationStatus.warning(WizardMessages.getString("IllegalCloudUrl.msg")); //$NON-NLS-1$
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/Url2DeltaCloudTypeConverter.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -15,8 +15,8 @@
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.core.databinding.observable.value.WritableValue;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient.DeltaCloudType;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl.DeltaCloudServerType;
/**
* A class that converts an url (string) to a DeltaCloudType (enum). The state
@@ -40,20 +40,20 @@
@Override
public Object getToType() {
- return DeltaCloudClient.DeltaCloudType.class;
+ return DeltaCloudClientImpl.DeltaCloudServerType.class;
}
@Override
public Object convert(Object fromObject) {
String deltaCloudUrl = (String) fromObject;
- DeltaCloudType cloudType = getCloudType(deltaCloudUrl);
+ DeltaCloudServerType cloudType = getCloudType(deltaCloudUrl);
cloudTypeObservable.setValue(cloudType);
return cloudType;
}
- private DeltaCloudType getCloudType(String deltaCloudUrl) {
+ private DeltaCloudServerType getCloudType(String deltaCloudUrl) {
try {
- return new DeltaCloudClient(deltaCloudUrl, "", "").getServerType();
+ return new DeltaCloudClientImpl(deltaCloudUrl, "", "").getServerType();
} catch (MalformedURLException e) {
return null;
}
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/context/MockIntegrationTestContext.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/context/MockIntegrationTestContext.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/context/MockIntegrationTestContext.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -24,8 +24,9 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.Image;
import org.jboss.tools.deltacloud.core.client.Instance;
import org.jboss.tools.deltacloud.core.client.Instance.State;
@@ -50,7 +51,7 @@
public void setUp() throws IOException, DeltaCloudClientException {
ensureDeltaCloudIsRunning();
- this.client = new DeltaCloudClient(DELTACLOUD_URL, DELTACLOUD_USER, DELTACLOUD_PASSWORD);
+ this.client = new DeltaCloudClientImpl(DELTACLOUD_URL, DELTACLOUD_USER, DELTACLOUD_PASSWORD);
Image image = getFirstImage(client);
this.testInstance = createTestInstance(image);
}
@@ -102,7 +103,10 @@
public void quietlyDestroyInstance(Instance instance) {
if (instance != null) {
try {
- client.destroyInstance(instance.getId());
+ if (instance.getState() == Instance.State.RUNNING) {
+ instance.stop(client);
+ }
+ instance.destroy(client);
} catch (Exception e) {
// ignore
}
@@ -120,10 +124,11 @@
* the timeout to wait for
* @return <code>true</code>, if the state was reached while waiting for
* timeout, <code>false</code> otherwise
- * @throws ExecutionException
- * @throws InterruptedException
+ * @throws ExecutionException
+ * @throws InterruptedException
*/
- public boolean waitForInstanceState(final String instanceId, final State state, final long timeout) throws InterruptedException, ExecutionException {
+ public boolean waitForInstanceState(final String instanceId, final State state, final long timeout)
+ throws InterruptedException, ExecutionException {
final long startTime = System.currentTimeMillis();
Callable<Boolean> waitingCallable = new Callable<Boolean>() {
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ImageMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ImageMockIntegrationTest.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ImageMockIntegrationTest.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -16,7 +16,7 @@
import java.net.MalformedURLException;
import java.util.List;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.Image;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
@@ -29,8 +29,8 @@
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#listImages()
- * @see DeltaCloudClient#listImages(String)
+ * @see DeltaCloudClientImpl#listImages()
+ * @see DeltaCloudClientImpl#listImages(String)
*
*/
public class ImageMockIntegrationTest {
@@ -50,7 +50,7 @@
@Test(expected = DeltaCloudClientException.class)
public void cannotListIfNotAuthenticated() throws MalformedURLException, DeltaCloudClientException {
- DeltaCloudClient client = new DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL, "badUser", "badPassword");
+ DeltaCloudClientImpl client = new DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL, "badUser", "badPassword");
client.listImages();
}
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/InstanceMockIntegrationTest.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -17,31 +17,40 @@
import static org.junit.Assert.assertTrue;
import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundClientException;
+import org.jboss.tools.deltacloud.core.client.HttpMethod;
import org.jboss.tools.deltacloud.core.client.Image;
import org.jboss.tools.deltacloud.core.client.Instance;
import org.jboss.tools.deltacloud.core.client.Instance.State;
import org.jboss.tools.deltacloud.core.client.InstanceAction;
+import org.jboss.tools.deltacloud.core.client.InternalDeltaCloudClient;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
/**
- * Integration tests for instance related methods in {@link DeltaCloudClient}.
+ * Integration tests for instance related methods in
+ * {@link DeltaCloudClientImpl}.
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#listInstances()
- * @see DeltaCloudClient#createInstance(String)
- * @see DeltaCloudClient#destroyInstance(String)
- * @see DeltaCloudClient#startInstance(String)
- * @see DeltaCloudClient#shutdownInstance(String)
+ * @see DeltaCloudClientImpl#listInstances()
+ * @see DeltaCloudClientImpl#createInstance(String)
+ * @see DeltaCloudClientImpl#destroyInstance(String)
+ * @see DeltaCloudClientImpl#startInstance(String)
+ * @see DeltaCloudClientImpl#shutdownInstance(String)
*/
public class InstanceMockIntegrationTest {
@@ -92,7 +101,7 @@
, instance);
}
- @Test(expected = DeltaCloudClientException.class)
+ @Test(expected = DeltaCloudNotFoundClientException.class)
public void listDestroyedInstanceThrowsException() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
testSetup.quietlyDestroyInstance(testInstance);
@@ -113,7 +122,8 @@
@Test(expected = DeltaCloudClientException.class)
public void cannotDestroyIfNotAuthenticated() throws MalformedURLException, DeltaCloudClientException {
- DeltaCloudClient unauthenticatedClient = new DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL,
+ DeltaCloudClientImpl unauthenticatedClient = new DeltaCloudClientImpl(
+ MockIntegrationTestContext.DELTACLOUD_URL,
"badUser", "badPassword");
Image image = testSetup.getFirstImage(unauthenticatedClient);
unauthenticatedClient.createInstance(image.getId());
@@ -141,21 +151,67 @@
@Test
public void canDestroy() throws DeltaCloudClientException {
Image image = testSetup.getFirstImage(testSetup.getClient());
- Instance instance = testSetup.getClient().createInstance(image.getId());
- testSetup.getClient().destroyInstance(instance.getId());
+ DeltaCloudClient client = testSetup.getClient();
+ Instance instance = client.createInstance(image.getId());
+ instance.stop(client);
+ instance.destroy(client);
assertNull(testSetup.getInstanceById(instance.getId(), testSetup.getClient()));
}
@Test(expected = DeltaCloudClientException.class)
- public void destroyThrowExceptionOnUnknowInstanceId() throws DeltaCloudClientException {
- testSetup.getClient().destroyInstance("dummy");
+ public void destroyThrowExceptionOnUnknowInstanceId() throws DeltaCloudClientException, IllegalArgumentException,
+ InstantiationException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
+ DeltaCloudClient client = testSetup.getClient();
+ ((InternalDeltaCloudClient) testSetup.getClient()).performInstanceAction(
+ createInstanceAction(
+ InstanceAction.DESTROY,
+ MockIntegrationTestContext.DELTACLOUD_URL,
+ HttpMethod.POST,
+ createInstance()));
}
+ private Instance createInstance() throws IllegalArgumentException, InstantiationException, IllegalAccessException,
+ InvocationTargetException, SecurityException, NoSuchMethodException {
+ Constructor<Instance> constructor = (Constructor<Instance>) Instance.class
+ .getDeclaredConstructor(null);
+ constructor.setAccessible(true);
+ return constructor.newInstance();
+ }
+
+ private InstanceAction createInstanceAction(String name, String url, HttpMethod method, Instance instance)
+ throws IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
+ Constructor<InstanceAction> constructor = (Constructor<InstanceAction>) InstanceAction.class
+ .getDeclaredConstructor(String.class, String.class, HttpMethod.class, Instance.class);
+ constructor.setAccessible(true);
+ InstanceAction instanceAction = constructor.newInstance(
+ name,
+ url,
+ method,
+ instance
+ );
+ return instanceAction;
+ }
+
+ private class InstanceActionProxy implements InvocationHandler {
+
+ @Override
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (method.getName().equals("getUrl")) {
+ return MockIntegrationTestContext.DELTACLOUD_URL;
+ } else if (method.getName().equals("getMethod")) {
+ return HttpMethod.POST;
+ } else {
+ return null;
+ }
+ }
+
+ }
+
@Test
public void canShutdownInstance() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
- client.shutdownInstance(testInstance.getId());
+ testInstance.stop(client);
testInstance = client.listInstances(testInstance.getId()); // reload!
assertEquals(State.STOPPED, testInstance.getState());
}
@@ -165,9 +221,9 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
if (testInstance.getState() == State.RUNNING) {
- client.shutdownInstance(testInstance.getId());
+ testInstance.stop(client);
}
- client.startInstance(testInstance.getId());
+ testInstance.start(client);
testInstance = client.listInstances(testInstance.getId()); // reload!
assertEquals(State.RUNNING, testInstance.getState());
}
@@ -177,9 +233,9 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
if (testInstance.getState() == State.RUNNING) {
- client.performInstanceAction(testInstance.getId(), InstanceAction.STOP);
+ testInstance.stop(client);
}
- assertTrue(client.performInstanceAction(testInstance.getId(), InstanceAction.START));
+ assertTrue(testInstance.start(client));
testInstance = client.listInstances(testInstance.getId()); // reload!
assertEquals(State.RUNNING, testInstance.getState());
}
@@ -188,8 +244,8 @@
public void cannotStartRunningInstance() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
- client.startInstance(testInstance.getId());
- assertFalse(client.performInstanceAction(testInstance.getId(), InstanceAction.START));
+ testInstance.start(client);
+ assertFalse(testInstance.start(client));
}
@Test
@@ -197,10 +253,10 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
try {
- client.shutdownInstance(testInstance.getId());
- assertFalse(client.performInstanceAction(testInstance.getId(), InstanceAction.STOP));
+ testInstance.stop(client);
+ assertFalse(testInstance.stop(client));
} finally {
- client.startInstance(testInstance.getId());
+ testInstance.start(client);
}
}
@@ -210,7 +266,7 @@
DeltaCloudClient client = testSetup.getClient();
testInstance = client.listInstances(testInstance.getId()); // reload
assertTrue(testInstance.getState() == State.RUNNING);
- assertFalse(client.performInstanceAction(testInstance.getId(), InstanceAction.DESTROY));
+ assertFalse(testInstance.destroy(client));
}
@Test
@@ -219,12 +275,12 @@
Instance testInstance = testSetup.getTestInstance();
DeltaCloudClient client = testSetup.getClient();
try {
- client.shutdownInstance(testInstance.getId());
+ testInstance.stop(client);
testInstance = client.listInstances(testInstance.getId()); // reload
assertTrue(testInstance.getState() == State.STOPPED);
- assertFalse(client.performInstanceAction(testInstance.getId(), InstanceAction.REBOOT));
+ assertFalse(testInstance.reboot(client));
} finally {
- client.startInstance(testInstance.getId());
+ testInstance.start(client);
client.listInstances(testInstance.getId()); // reload
}
}
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/KeyMockIntegrationTest.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -12,7 +12,7 @@
import java.io.IOException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.junit.After;
@@ -23,8 +23,8 @@
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#createKey(String, String)
- * @see DeltaCloudClient#deleteKey(String)
+ * @see DeltaCloudClientImpl#createKey(String, String)
+ * @see DeltaCloudClientImpl#deleteKey(String)
*/
public class KeyMockIntegrationTest {
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ProfileMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ProfileMockIntegrationTest.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ProfileMockIntegrationTest.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -17,7 +17,7 @@
import java.io.IOException;
import java.util.List;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.HardwareProfile;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
@@ -30,8 +30,8 @@
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#listProfiles()
- * @see DeltaCloudClient#listProfie(String)
+ * @see DeltaCloudClientImpl#listProfiles()
+ * @see DeltaCloudClientImpl#listProfie(String)
*/
public class ProfileMockIntegrationTest {
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/RealmMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/RealmMockIntegrationTest.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/RealmMockIntegrationTest.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -17,7 +17,7 @@
import java.io.IOException;
import java.util.List;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
import org.jboss.tools.deltacloud.core.client.Realm;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
@@ -30,8 +30,8 @@
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#listRealms()
- * @see DeltaCloudClient#listRealm(String)
+ * @see DeltaCloudClientImpl#listRealms()
+ * @see DeltaCloudClientImpl#listRealm(String)
*/
public class RealmMockIntegrationTest {
Modified: trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java
===================================================================
--- trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java 2010-11-04 13:35:05 UTC (rev 26251)
+++ trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/core/client/ServerTypeMockIntegrationTest.java 2010-11-04 13:37:05 UTC (rev 26252)
@@ -19,9 +19,9 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudClient;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudClientImpl;
import org.jboss.tools.deltacloud.core.client.DeltaCloudClientException;
-import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundException;
+import org.jboss.tools.deltacloud.core.client.DeltaCloudNotFoundClientException;
import org.jboss.tools.deltacloud.core.client.HttpMethod;
import org.jboss.tools.internal.deltacloud.test.context.MockIntegrationTestContext;
import org.jboss.tools.internal.deltacloud.test.fakes.ServerFake;
@@ -30,11 +30,11 @@
import org.junit.Test;
/**
- * Integration tests for {@link DeltaCloudClient#getServerType()}.
+ * Integration tests for {@link DeltaCloudClientImpl#getServerType()}.
*
* @author Andre Dietisheim
*
- * @see DeltaCloudClient#getServerType()
+ * @see DeltaCloudClientImpl#getServerType()
*/
public class ServerTypeMockIntegrationTest {
@@ -53,7 +53,7 @@
@Test
public void recognizesDeltaCloud() throws IOException {
- assertEquals(DeltaCloudClient.DeltaCloudType.MOCK,testSetup.getClient().getServerType());
+ assertEquals(DeltaCloudClientImpl.DeltaCloudServerType.MOCK,testSetup.getClient().getServerType());
}
/**
@@ -68,7 +68,7 @@
ServerFake serverFake = new ServerFake(new URL(MockIntegrationTestContext.SERVERFAKE_URL).getPort(), "<dummy></dummy>");
serverFake.start();
try {
- assertEquals(DeltaCloudClient.DeltaCloudType.UNKNOWN, new DeltaCloudClient(MockIntegrationTestContext.SERVERFAKE_URL, MockIntegrationTestContext.DELTACLOUD_USER,
+ assertEquals(DeltaCloudClientImpl.DeltaCloudServerType.UNKNOWN, new DeltaCloudClientImpl(MockIntegrationTestContext.SERVERFAKE_URL, MockIntegrationTestContext.DELTACLOUD_USER,
MockIntegrationTestContext.DELTACLOUD_PASSWORD).getServerType());
} finally {
serverFake.stop();
@@ -77,14 +77,14 @@
@Test(expected = DeltaCloudClientException.class)
public void listImages_cannotListIfNotAuthenticated() throws MalformedURLException, DeltaCloudClientException {
- DeltaCloudClient client = new DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL, "badUser", "badPassword");
+ DeltaCloudClientImpl client = new DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL, "badUser", "badPassword");
client.listImages();
}
@Test
public void throwsDeltaCloudClientExceptionOnUnknownResource() {
try {
- DeltaCloudClient errorClient = new DeltaCloudClient(MockIntegrationTestContext.DELTACLOUD_URL) {
+ DeltaCloudClientImpl errorClient = new DeltaCloudClientImpl(MockIntegrationTestContext.DELTACLOUD_URL) {
@Override
protected HttpUriRequest getRequest(HttpMethod httpMethod, String requestUrl) {
return new HttpGet(MockIntegrationTestContext.DELTACLOUD_URL + "/DUMMY");
@@ -93,7 +93,7 @@
errorClient.listImages();
fail("no exception catched");
} catch (Exception e) {
- assertEquals(DeltaCloudNotFoundException.class, e.getClass());
+ assertEquals(DeltaCloudNotFoundClientException.class, e.getClass());
}
}
}
15 years, 5 months
JBoss Tools SVN: r26251 - trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test.
by jbosstools-commits@lists.jboss.org
Author: jlukas(a)redhat.com
Date: 2010-11-04 09:35:05 -0400 (Thu, 04 Nov 2010)
New Revision: 26251
Modified:
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SampleWebService.java
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSClient.java
Log:
minor tweaks, unused imports, logging
Modified: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SampleWebService.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SampleWebService.java 2010-11-04 13:23:40 UTC (rev 26250)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SampleWebService.java 2010-11-04 13:35:05 UTC (rev 26251)
@@ -34,7 +34,6 @@
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.jboss.tools.ui.bot.ext.config.Annotations.SWTBotTestRequires;
import org.jboss.tools.ui.bot.ext.config.Annotations.Server;
-import org.jboss.tools.ui.bot.ext.config.Annotations.ServerType;
import org.jboss.tools.ui.bot.ext.gen.ActionItem;
import org.jboss.tools.ws.ui.bot.test.uiutils.actions.NewSampleWSWizardAction;
import org.jboss.tools.ws.ui.bot.test.uiutils.actions.TreeItemAction;
@@ -86,7 +85,7 @@
}
assertTrue(dd.exists());
createSampleRESTWS(project, "RESTSample", "rest.sample", "Sample", "RESTApp");
- checkRESTService(project, "RESTSample", "rest.sample", "Sample", "You", "RESTApp");
+ checkRESTService(project, "RESTSample", "rest.sample", "Sample", "Hello World!", "RESTApp");
}
private void createDD(String project) {
@@ -132,7 +131,6 @@
}
private void checkService(Type type, String project, String svcName, String svcPkg, String svcClass, String msgContent, String appCls) {
- //"RESTSample", "rest.sample", "Sample", "RESTApp"
SWTBotEditor ed = bot.activeEditor();
assertEquals(svcClass + ".java", ed.getTitle());
String code = ed.toTextEditor().getText();
@@ -156,7 +154,7 @@
try {
URL u = new URL("http://" + SERVER_URL + "/" + project + "/" + svcName);
String s = readStream(u.openConnection().getInputStream());
- assertEquals("Hello World!", s);
+ assertEquals(msgContent, s);
} catch (MalformedURLException e) {
L.log(Level.WARNING, e.getMessage(), e);
} catch (IOException e) {
Modified: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSClient.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSClient.java 2010-11-04 13:23:40 UTC (rev 26250)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSClient.java 2010-11-04 13:35:05 UTC (rev 26251)
@@ -13,26 +13,21 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.StringWriter;
-import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import javax.xml.namespace.QName;
-import javax.xml.soap.AttachmentPart;
import javax.xml.soap.MessageFactory;
-import javax.xml.soap.MimeHeaders;
-import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;
-import javax.xml.soap.SOAPPart;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.Service.Mode;
public class WSClient {
+ private static final Logger L = Logger.getLogger(WSClient.class.getName());
private Dispatch<SOAPMessage> d;
public WSClient(URL location, QName serviceName, QName portName) {
@@ -42,23 +37,40 @@
public String callService(String message) {
SOAPMessage result = null;
- ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
SOAPMessage msg = MessageFactory.newInstance().createMessage( null, new ByteArrayInputStream(message.getBytes()));
msg.saveChanges();
result = d.invoke(msg);
- result.writeTo(out);
+ } catch (SOAPException e) {
+ L.log(Level.WARNING, e.getMessage(), e);
} catch (IOException e) {
- e.printStackTrace(System.err);
+ L.log(Level.WARNING, e.getMessage(), e);
+ }
+ String s = msgToString(result);
+ L.fine("SOAP Request :\n" + message);
+ L.fine("SOAP Response:\n" + s);
+ return s;
+ }
+
+ private String msgToString(SOAPMessage msg) {
+ if (msg == null) {
+ return "";
+ }
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ msg.writeTo(out);
} catch (SOAPException e) {
- e.printStackTrace(System.err);
+ L.log(Level.WARNING, e.getMessage(), e);
+ } catch (IOException e) {
+ L.log(Level.WARNING, e.getMessage(), e);
} finally {
try {
out.close();
} catch (IOException e) {
//ignore
+ L.log(Level.WARNING, e.getMessage(), e);
}
}
return out.toString();
- }
+ }
}
15 years, 5 months
JBoss Tools SVN: r26250 - in trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui: src/org/jboss/tools/internal/deltacloud/ui/wizards and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-11-04 09:23:40 -0400 (Thu, 04 Nov 2010)
New Revision: 26250
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
Log:
avoid NullPointerExeption when fetching name of key and keyText is not instantiated (is null)
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 13:19:02 UTC (rev 26249)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 13:23:40 UTC (rev 26250)
@@ -1,5 +1,7 @@
2010-11-04 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java (getKeyName):
+ avoid NullPointerExeption when fetching name of key and keyText is not instantiated (is null)
* src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java:
* src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java:
[JBIDE-7495] changed dialog and handler to climb up the hierarchy to the connection and offer to disconnect the cloud connection
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java 2010-11-04 13:19:02 UTC (rev 26249)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java 2010-11-04 13:23:40 UTC (rev 26250)
@@ -153,7 +153,11 @@
}
public String getKeyName() {
- return keyText.getText();
+ if (keyText == null) {
+ return null;
+ } else {
+ return keyText.getText();
+ }
}
private void validate() {
15 years, 5 months
JBoss Tools SVN: r26249 - in trunk/ws/tests/org.jboss.tools.ws.ui.bot.test: .settings and 5 other directories.
by jbosstools-commits@lists.jboss.org
Author: jlukas(a)redhat.com
Date: 2010-11-04 09:19:02 -0400 (Thu, 04 Nov 2010)
New Revision: 26249
Added:
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSClient.java
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/Action.java
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/NewFileWizardAction.java
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/NewSampleWSWizardAction.java
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/TreeItemAction.java
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/DynamicWebProjectWizard.java
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/SampleWSWizard.java
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/Wizard.java
Modified:
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/.classpath
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/.settings/org.eclipse.jdt.core.prefs
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/META-INF/MANIFEST.MF
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/JbossWSTest.java
trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SampleWebService.java
Log:
updated test for sample ws wizards
Modified: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/.classpath
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/.classpath 2010-11-04 13:09:57 UTC (rev 26248)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/.classpath 2010-11-04 13:19:02 UTC (rev 26249)
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="resources"/>
Modified: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/.settings/org.eclipse.jdt.core.prefs 2010-11-04 13:09:57 UTC (rev 26248)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/.settings/org.eclipse.jdt.core.prefs 2010-11-04 13:19:02 UTC (rev 26249)
@@ -1,8 +1,8 @@
-#Mon Aug 31 15:12:26 CEST 2009
+#Wed Nov 03 12:20:34 CET 2010
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
-org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.compiler.source=1.6
Modified: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/META-INF/MANIFEST.MF 2010-11-04 13:09:57 UTC (rev 26248)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/META-INF/MANIFEST.MF 2010-11-04 13:19:02 UTC (rev 26249)
@@ -22,7 +22,7 @@
org.jboss.tools.tests,
org.eclipse.wst.common.project.facet.core
Bundle-ActivationPolicy: lazy
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Eclipse-RegisterBuddy: org.apache.log4j
Bundle-ClassPath: .
Export-Package: org.jboss.tools.ws.ui.bot.test
Modified: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/JbossWSTest.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/JbossWSTest.java 2010-11-04 13:09:57 UTC (rev 26248)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/JbossWSTest.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -1,5 +1,16 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.ws.ui.bot.test;
+import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
@@ -10,7 +21,6 @@
import org.jboss.tools.ui.bot.ext.gen.ActionItem;
import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.Class;
import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.JavaEEEnterpriseApplicationProject;
-import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.WebDynamicWebProject;
import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.WebServicesWebService;
import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.WebServicesWebServiceClient;
import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.WebServlet;
@@ -18,6 +28,8 @@
import org.jboss.tools.ui.bot.ext.parts.SWTBotHyperlinkExt;
import org.jboss.tools.ui.bot.ext.parts.SWTBotScaleExt;
import org.jboss.tools.ui.bot.ext.types.IDELabel;
+import org.jboss.tools.ws.ui.bot.test.uiutils.actions.NewFileWizardAction;
+import org.jboss.tools.ws.ui.bot.test.uiutils.wizards.DynamicWebProjectWizard;
import org.junit.runner.RunWith;
@RunWith(SWTBotJunit4ClassRunner.class)
@@ -26,12 +38,6 @@
public static final String EAR_PROJECT_NAME="EAR";
public static final String PKG_NAME="jbossws";
- public static final String SAMPLE_WS_PROJ_NAME="SampleWS";
- public static final String SAMPLE_WS_SERVICE_NAME="HelloWorld";
- public static final String SAMPLE_WS_WSDL_URL="http://localhost:8080/"+SAMPLE_WS_PROJ_NAME+"/"+SAMPLE_WS_SERVICE_NAME+"?wsdl";
- public static final String SAMPLE_WSCLIENT_PROJ_NAME = "SampleWSClient";
- public static final String SAMPLE_WSCLIENT_SERVLET_NAME = "SampleWStest";
- public static final String SAMPLE_WSCLIENT_SERVLET_URL = "http://localhost:8080/"+SAMPLE_WSCLIENT_PROJ_NAME+"/"+SAMPLE_WSCLIENT_SERVLET_NAME;
public static final String CLASS_A="ClassA";
public static final String CLASS_B="ClassB";
public static final String CLASS_C="ClassC";
@@ -63,6 +69,12 @@
public static final int SERVICE_SCALE_TEST=0;
protected static Map<Integer,String> wizardConfigTexts = new HashMap<Integer, String>();
+ private static final String SOAP_REQUEST_TEMPLATE = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>" +
+ "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"" +
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
+ "<soap:Body>{0}</soap:Body>" +
+ "</soap:Envelope>";;
public JbossWSTest() {
@@ -144,9 +156,9 @@
}
protected void createProject(String name) {
- SWTBot wiz = open.newObject(WebDynamicWebProject.LABEL);
- wiz.textWithLabel(WebDynamicWebProject.TEXT_PROJECT_NAME).setText(name);
- open.finish(wiz);
+ new NewFileWizardAction().run().selectTemplate("Web", "Dynamic Web Project").next();
+ new DynamicWebProjectWizard().setProjectName(name).finish();
+ util.waitForNonIgnoredJobs();
assertTrue(projectExplorer.existsResource(name));
projectExplorer.selectProject(name);
}
@@ -198,4 +210,9 @@
+ servletReturned, servletRetOK);
}
+
+ public static String getSoapRequest(String body) {
+ return MessageFormat.format(SOAP_REQUEST_TEMPLATE, body);
+ }
+
}
Modified: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SampleWebService.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SampleWebService.java 2010-11-04 13:09:57 UTC (rev 26248)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/SampleWebService.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -1,49 +1,229 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
package org.jboss.tools.ws.ui.bot.test;
-import org.eclipse.swtbot.swt.finder.SWTBot;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.text.MessageFormat;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.jboss.tools.ui.bot.ext.config.Annotations.SWTBotTestRequires;
import org.jboss.tools.ui.bot.ext.config.Annotations.Server;
+import org.jboss.tools.ui.bot.ext.config.Annotations.ServerType;
import org.jboss.tools.ui.bot.ext.gen.ActionItem;
-import org.jboss.tools.ui.bot.ext.gen.ActionItem.NewObject.JBossToolsCreateaSampleWebService;
+import org.jboss.tools.ws.ui.bot.test.uiutils.actions.NewSampleWSWizardAction;
+import org.jboss.tools.ws.ui.bot.test.uiutils.actions.TreeItemAction;
+import org.jboss.tools.ws.ui.bot.test.uiutils.wizards.SampleWSWizard;
+import org.jboss.tools.ws.ui.bot.test.uiutils.wizards.SampleWSWizard.Type;
+import org.junit.AfterClass;
import org.junit.Test;
@SWTBotTestRequires(server=@Server(),perspective="Java EE")
public class SampleWebService extends JbossWSTest {
+ private static final String SOAP_REQUEST = getSoapRequest("<ns1:sayHello xmlns:ns1=\"http://{0}/\"><arg0>{1}</arg0></ns1:sayHello>");
+ private static final String SERVER_URL = "localhost:8080";
+ private static final Logger L = Logger.getLogger(SampleWebService.class.getName());
+
+ @AfterClass
+ public static void cleanup() {
+ servers.removeAllProjectsFromServer();
+ projectExplorer.deleteAllProjects();
+ }
+
+ @Test
+ public void testSampleSoapWS() {
+ String project = "SampleSOAPWS";
+ createProject(project);
+ IFile dd = getDD(project);
+ if (!dd.exists()) {
+ createDD(project);
+ }
+ assertTrue(dd.exists());
+ createSampleSOAPWS(project, "HelloService", "sample", "SampleService");
+ checkSOAPService(project, "HelloService", "sample", "SampleService", "You");
+ createSampleSOAPWS(project, "GreetService", "greeter", "Greeter");
+ checkSOAPService(project, "GreetService", "greeter", "Greeter", "Tester");
+ }
+
@Test
- public void sampleWebService() {
- console.show().toolbarToggleButton("Show Console When Standard Out Changes").deselect();
- console.show().toolbarToggleButton("Show Console When Standard Error Changes").deselect();
- int testlevel = 3;
- for (int i=0;i<testlevel;i++) {
- sampleWebService(i);
+ public void testSampleRestWS() {
+ if ("JBOSS_AS".equals(configuredState.getServer().type)) {
+ fail("This test requires RESTEasy jars in the server");
}
+ String project = "SampleRESTWS";
+ createProject(project);
+ IFile dd = getDD(project);
+ if (!dd.exists()) {
+ createDD(project);
+ }
+ assertTrue(dd.exists());
+ createSampleRESTWS(project, "RESTSample", "rest.sample", "Sample", "RESTApp");
+ checkRESTService(project, "RESTSample", "rest.sample", "Sample", "You", "RESTApp");
}
+
+ private void createDD(String project) {
+ SWTBotTree tree = projectExplorer.tree();
+ SWTBotTreeItem ti = tree.expandNode(project);
+ bot.sleep(500);
+ ti = ti.getNode("Deployment Descriptor: " + project);
+ new TreeItemAction(ti, "Generate Deployment Descriptor Stub").run();
+ util.waitForNonIgnoredJobs();
+ }
+
+ private void createSampleSOAPWS(String project, String name, String pkg, String cls) {
+ createSampleService(Type.SOAP, project, name, pkg, cls, null);
+ }
- private void sampleWebService(int clientType) {
- log.info(" * Running test with ClientType: '"+wizardConfigTexts.get(clientType)+"'");
- createEARProject(EAR_PROJECT_NAME);
- createProject(SAMPLE_WS_PROJ_NAME);
- SWTBot wiz = open.newObject(JBossToolsCreateaSampleWebService.LABEL);
- wiz.comboBox().setText(SAMPLE_WS_PROJ_NAME);
- open.finish(wiz);
+ private void checkSOAPService(String project, String svcName, String svcPkg, String svcClass, String msgContent) {
+ checkService(Type.SOAP, project, svcName, svcPkg, svcClass, msgContent, null);
+ }
+
+ private void checkRESTService(String project, String svcName, String svcPkg, String svcClass, String msgContent, String appCls) {
+ checkService(Type.REST, project, svcName, svcPkg, svcClass, msgContent, appCls);
+ }
+
+ private void createSampleRESTWS(String project, String name, String pkg, String cls, String appCls) {
+ createSampleService(Type.REST, project, name, pkg, cls, appCls);
+ }
+
+ private void createSampleService(Type type, String project, String name, String pkg, String cls, String appCls) {
+ SampleWSWizard w = new NewSampleWSWizardAction(type).run();
+ w.setProjectName(project).setServiceName(name);
+ w.setPackageName(pkg).setClassName(cls);
+ if (type == Type.REST) {
+ w.setApplicationClassName(appCls);
+ }
+ w.finish();
+ util.waitForNonIgnoredJobs();
+ }
+
+ private void runProject(String project) {
open.viewOpen(ActionItem.View.ServerServers.LABEL);
- projectExplorer.runOnServer(SAMPLE_WS_PROJ_NAME);
- // browse WSDL
- assertServiceDeployed(SAMPLE_WS_WSDL_URL);
- // create and run WS Sample Client
- createClient(SAMPLE_WSCLIENT_PROJ_NAME, SAMPLE_WSCLIENT_SERVLET_NAME, SAMPLE_WS_WSDL_URL, clientType);
- // re run project
- if (clientType<=CLIENT_SCALE_DEPLOY) {
- servers.removeProjectFromServers(EAR_PROJECT_NAME);
+ projectExplorer.runOnServer(project);
+ bot.sleep(5000);
+ }
+
+ private void checkService(Type type, String project, String svcName, String svcPkg, String svcClass, String msgContent, String appCls) {
+ //"RESTSample", "rest.sample", "Sample", "RESTApp"
+ SWTBotEditor ed = bot.activeEditor();
+ assertEquals(svcClass + ".java", ed.getTitle());
+ String code = ed.toTextEditor().getText();
+ assertContains("package " + svcPkg + ";", code);
+ String dd = readFile(getDD(project));
+ switch (type) {
+ case REST:
+ assertContains("@Path(\"/" + svcName + "\")", code);
+ assertContains("@GET()", code);
+ assertContains("@Produces(\"text/plain\")", code);
+ assertContains("<servlet-name>Resteasy</servlet-name>", dd);
+ assertContains("<param-value>" + svcPkg + "." + appCls + "</param-value>", dd);
+ break;
+ case SOAP:
+ assertContains("<servlet-name>" + svcName + "</servlet-name>", dd);
+ break;
}
- projectExplorer.runOnServer(SAMPLE_WSCLIENT_PROJ_NAME);
- assertServiceResponseToClient(SAMPLE_WSCLIENT_SERVLET_URL, "abcdefg");
- servers.removeAllProjectsFromServer(configuredState.getServer().name);
- assertServiceNotDeployed(SAMPLE_WS_WSDL_URL);
- servers.removeAllProjectsFromServer();
- projectExplorer.deleteAllProjects();
+ runProject(project);
+ switch (type) {
+ case REST:
+ try {
+ URL u = new URL("http://" + SERVER_URL + "/" + project + "/" + svcName);
+ String s = readStream(u.openConnection().getInputStream());
+ assertEquals("Hello World!", s);
+ } catch (MalformedURLException e) {
+ L.log(Level.WARNING, e.getMessage(), e);
+ } catch (IOException e) {
+ L.log(Level.WARNING, e.getMessage(), e);
+ }
+ break;
+ case SOAP:
+ try {
+ WSClient c = new WSClient(new URL("http://" + SERVER_URL + "/" + project + "/" + svcName),
+ new QName("http://" + svcPkg + "/", svcClass + "Service"),
+ new QName("http://" + svcPkg + "/", svcClass + "Port"));
+ assertContains("Hello " + msgContent + "!", c.callService(MessageFormat.format(SOAP_REQUEST, svcPkg, msgContent)));
+ } catch (MalformedURLException e) {
+ L.log(Level.WARNING, e.getMessage(), e);
+ }
+ break;
+ }
}
+
+ private IProject getProject(String project) {
+ return ResourcesPlugin.getWorkspace().getRoot().getProject(project);
+ }
+
+ private IFile getDD(String project) {
+ return getProject(project).getFile("WebContent/WEB-INF/web.xml");
+ }
+
+ private String readFile(IFile file) {
+ try {
+ return readStream(file.getContents());
+ } catch (CoreException e) {
+ L.log(Level.WARNING, e.getMessage(), e);
+ }
+ return "";
+ }
+
+ private String readStream(InputStream is) {
+ Reader r = null;
+ Writer w = null;
+ try {
+ char[] buffer = new char[1024];
+ r = new BufferedReader(new InputStreamReader(is, "UTF-8"));
+ w = new StringWriter();
+ int n;
+ while ((n = r.read(buffer)) != -1) {
+ w.write(buffer, 0, n);
+ }
+ } catch (IOException e) {
+ L.log(Level.WARNING, e.getMessage(), e);
+ } finally {
+ if (r != null) {
+ try {
+ r.close();
+ } catch (IOException e) {
+ //ignore
+ L.log(Level.WARNING, e.getMessage(), e);
+ }
+ }
+ if (w != null) {
+ try {
+ w.close();
+ } catch (IOException e) {
+ //ignore
+ L.log(Level.WARNING, e.getMessage(), e);
+ }
+ }
+ }
+ return w != null ? w.toString() : "";
+ }
}
Added: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSClient.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSClient.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/WSClient.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.bot.test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+import javax.xml.soap.AttachmentPart;
+import javax.xml.soap.MessageFactory;
+import javax.xml.soap.MimeHeaders;
+import javax.xml.soap.SOAPElement;
+import javax.xml.soap.SOAPException;
+import javax.xml.soap.SOAPMessage;
+import javax.xml.soap.SOAPPart;
+import javax.xml.ws.Dispatch;
+import javax.xml.ws.Service;
+import javax.xml.ws.Service.Mode;
+
+public class WSClient {
+
+ private Dispatch<SOAPMessage> d;
+
+ public WSClient(URL location, QName serviceName, QName portName) {
+ Service s = Service.create(location, serviceName);
+ d = s.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE);
+ }
+
+ public String callService(String message) {
+ SOAPMessage result = null;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try {
+ SOAPMessage msg = MessageFactory.newInstance().createMessage( null, new ByteArrayInputStream(message.getBytes()));
+ msg.saveChanges();
+ result = d.invoke(msg);
+ result.writeTo(out);
+ } catch (IOException e) {
+ e.printStackTrace(System.err);
+ } catch (SOAPException e) {
+ e.printStackTrace(System.err);
+ } finally {
+ try {
+ out.close();
+ } catch (IOException e) {
+ //ignore
+ }
+ }
+ return out.toString();
+ }
+}
Added: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/Action.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/Action.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/Action.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.bot.test.uiutils.actions;
+
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+
+public abstract class Action<T> {
+
+ private final SWTBotExt bot = new SWTBotExt();
+ private final String[] actionPath;
+
+ public Action(String... path) {
+ assert path.length > 0;
+ this.actionPath = path;
+ }
+
+ public abstract T run();
+
+ protected SWTBot performMenu() {
+ SWTBotMenu m = bot.menu(actionPath[0]);
+ for (int i = 1; i < actionPath.length; i++) {
+ m = m.menu(actionPath[i]);
+ }
+ m.click();
+ return new SWTBot();
+ }
+
+ public String[] getActionPath() {
+ return actionPath;
+ }
+}
Added: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/NewFileWizardAction.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/NewFileWizardAction.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/NewFileWizardAction.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -0,0 +1,28 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.bot.test.uiutils.actions;
+
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.jboss.tools.ui.bot.ext.types.IDELabel;
+import org.jboss.tools.ws.ui.bot.test.uiutils.wizards.Wizard;
+
+public class NewFileWizardAction extends Action<Wizard> {
+
+ public NewFileWizardAction() {
+ super(IDELabel.Menu.FILE, IDELabel.Menu.NEW, IDELabel.Menu.OTHER);
+ }
+
+ @Override
+ public Wizard run() {
+ SWTBot b = performMenu();
+ return new Wizard(b.activeShell().widget);
+ }
+}
Added: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/NewSampleWSWizardAction.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/NewSampleWSWizardAction.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/NewSampleWSWizardAction.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.bot.test.uiutils.actions;
+
+import org.jboss.tools.ws.ui.bot.test.uiutils.wizards.SampleWSWizard;
+import org.jboss.tools.ws.ui.bot.test.uiutils.wizards.SampleWSWizard.Type;
+import org.jboss.tools.ws.ui.bot.test.uiutils.wizards.Wizard;
+
+public class NewSampleWSWizardAction extends NewFileWizardAction {
+
+ private final Type type;
+
+ public NewSampleWSWizardAction(Type type) {
+ super();
+ this.type = type;
+ }
+
+ @Override
+ public SampleWSWizard run() {
+ Wizard w = super.run();
+ w.selectTemplate("Web Services", type.getLabel());
+ w.next();
+ return new SampleWSWizard(type);
+ }
+
+}
Added: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/TreeItemAction.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/TreeItemAction.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/actions/TreeItemAction.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.bot.test.uiutils.actions;
+
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
+import org.eclipse.swtbot.swt.finder.results.Result;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.jboss.tools.ui.bot.ext.helper.ContextMenuHelper;
+
+public class TreeItemAction extends Action<SWTBot> {
+
+ private final SWTBotTreeItem item;
+
+ public TreeItemAction(SWTBotTreeItem tree, String... actionPath) {
+ super(actionPath);
+ this.item = tree;
+ }
+
+ @Override
+ public SWTBot run() {
+ return performMenu();
+ }
+
+ @Override
+ protected SWTBot performMenu() {
+ assert item != null : "TreeItem cannot be null!";
+ Tree tree = UIThreadRunnable.syncExec(new Result<Tree>() {
+
+ public Tree run() {
+ return item.widget.getParent();
+ }
+
+ });
+ final SWTBotTree t = new SWTBotTree(tree);
+ final String[] actionPath = super.getActionPath();
+ ContextMenuHelper.prepareTreeItemForContextMenu(t, item);
+ UIThreadRunnable.syncExec(new Result<SWTBotMenu>() {
+
+ public SWTBotMenu run() {
+ SWTBotMenu m = new SWTBotMenu(ContextMenuHelper.getContextMenu(
+ t, actionPath[0], false));
+ for (int i = 1; i < actionPath.length; i++) {
+ m = m.menu(actionPath[i]);
+ }
+ return m;
+ }
+ }).click();
+ return new SWTBot();
+ }
+
+}
Added: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/DynamicWebProjectWizard.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/DynamicWebProjectWizard.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/DynamicWebProjectWizard.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.bot.test.uiutils.wizards;
+
+import org.eclipse.swtbot.swt.finder.SWTBot;
+
+public class DynamicWebProjectWizard extends Wizard {
+
+ public DynamicWebProjectWizard() {
+ super(new SWTBot().activeShell().widget);
+ assert "New Dynamic Web Project".equals(getText());
+ }
+
+ public DynamicWebProjectWizard setProjectName(String name) {
+ setText("Project name:", name);
+ return this;
+ }
+
+}
Added: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/SampleWSWizard.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/SampleWSWizard.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/SampleWSWizard.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.bot.test.uiutils.wizards;
+
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
+import org.jboss.tools.ui.bot.ext.SWTBotExt;
+import org.jboss.tools.ws.ui.messages.JBossWSUIMessages;
+import org.osgi.framework.Bundle;
+
+public class SampleWSWizard extends Wizard {
+
+ private static final Bundle WSUI_BUNDLE = Platform.getBundle("org.jboss.tools.ws.ui");
+
+ public enum Type {
+ SOAP, REST;
+
+ public String getLabel() {
+ switch (this) {
+ case SOAP:
+ return getStringFromBundle("%JBOSSWS_GENERATEACTION_LABEL");
+ case REST:
+ return getStringFromBundle("%restful.wizard.name");
+ default:
+ throw new IllegalArgumentException("Unknown type: " + this);
+ }
+ }
+ }
+
+ private Type type;
+
+ public SampleWSWizard(Type type) throws WidgetNotFoundException {
+ super(new SWTBotExt().activeShell().widget);
+ this.type = type;
+ }
+
+ public SampleWSWizard setProjectName(String name) {
+ SWTBotCombo c = bot().comboBoxInGroup(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWizardPage_Project_Group);
+ c.setSelection(name);
+ return this;
+ }
+
+ public SampleWSWizard setServiceName(String name) {
+ setText(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWizardPage_ServiceName_Label, name);
+ return this;
+ }
+
+ public SampleWSWizard setPackageName(String name) {
+ setText(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWizardPage_Package_Label, name);
+ return this;
+ }
+
+ public SampleWSWizard setClassName(String name) {
+ setText(JBossWSUIMessages.JBossWS_GenerateWizard_GenerateWizardPage_ClassName_Label, name);
+ return this;
+ }
+
+ public SampleWSWizard setApplicationClassName(String name) {
+ assert type == Type.REST;
+ setText(JBossWSUIMessages.JBossRSGenerateWizardPage_Label_Application_Class_Name, name);
+ return this;
+ }
+
+ private static String getStringFromBundle(String key) {
+ return Platform.getResourceString(WSUI_BUNDLE, key);
+ }
+}
Added: trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/Wizard.java
===================================================================
--- trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/Wizard.java (rev 0)
+++ trunk/ws/tests/org.jboss.tools.ws.ui.bot.test/src/org/jboss/tools/ws/ui/bot/test/uiutils/wizards/Wizard.java 2010-11-04 13:19:02 UTC (rev 26249)
@@ -0,0 +1,69 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.ws.ui.bot.test.uiutils.wizards;
+
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+
+public class Wizard extends SWTBotShell {
+
+ public Wizard(Shell shell) {
+ super(shell);
+ assert getText().contains("New ");
+ }
+
+ public Wizard selectTemplate(String... item) {
+ assert item.length > 0;
+ SWTBotTree tree = bot().tree();
+ SWTBotTreeItem ti = null;
+ for (int i = 0; i < item.length - 1; i++) {
+ ti = ti != null ? ti.expandNode(item[i]).select() : tree.expandNode(item[i]).select();
+ }
+ if (ti != null) {
+ ti.select(item[item.length - 1]);
+ } else {
+ tree.select(item[item.length - 1]);
+ }
+ return this;
+ }
+
+ public Wizard back() {
+ clickButton("< Back");
+ return this;
+ }
+
+ public Wizard next() {
+ clickButton("Next >");
+ return this;
+ }
+
+ public void cancel() {
+ clickButton("Cancel");
+ }
+
+ public void finish() {
+ clickButton("Finish");
+ }
+
+ protected void clickButton(String text) {
+ bot().button(text).click();
+ bot().sleep(500);
+ }
+
+ protected void setText(String label, String text) {
+ SWTBotText t = bot().textWithLabel(label);
+ t.setFocus();
+ t.setText(text);
+ }
+}
15 years, 5 months
JBoss Tools SVN: r26248 - trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-11-04 09:09:57 -0400 (Thu, 04 Nov 2010)
New Revision: 26248
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
Log:
[JBIDE-7495] changed dialog and handler to climb up the hierarchy to the connection and offer to disconnect the cloud connection
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 13:08:28 UTC (rev 26247)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-11-04 13:09:57 UTC (rev 26248)
@@ -1,3 +1,9 @@
+2010-11-04 André Dietisheim <adietish(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java:
+ * src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java:
+ [JBIDE-7495] changed dialog and handler to climb up the hierarchy to the connection and offer to disconnect the cloud connection
+
2010-11-02 André Dietisheim <adietish(a)redhat.com>
* src/org/jboss/tools/deltacloud/ui/views/CVMessages.properties: [JBIDE-7482] fixed missing label
15 years, 5 months
JBoss Tools SVN: r26247 - in trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui: views and 1 other directory.
by jbosstools-commits@lists.jboss.org
Author: adietish
Date: 2010-11-04 09:08:28 -0400 (Thu, 04 Nov 2010)
New Revision: 26247
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java
Log:
[JBIDE-7495] changed dialog and handler to climb up the hierarchy to the connection and offer to disconnect the cloud connection
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java 2010-11-04 13:01:26 UTC (rev 26246)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/commands/DisconnectCloudHandler.java 2010-11-04 13:08:28 UTC (rev 26247)
@@ -10,6 +10,11 @@
******************************************************************************/
package org.jboss.tools.deltacloud.ui.commands;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
@@ -38,7 +43,7 @@
if (selection instanceof IStructuredSelection) {
DisconnectCloudsDialog dialog = new DisconnectCloudsDialog(
shell
- , ((IStructuredSelection) selection).toList());
+ , getSelectedClouds(selection));
if (Dialog.OK == dialog.open()) {
removeCloudViewElements(dialog.getResult());
}
@@ -47,12 +52,46 @@
return Status.OK_STATUS;
}
- private void removeCloudViewElements(Object[] cloudViewerElements) {
- for (Object cloudViewElement : cloudViewerElements) {
- if (cloudViewElement instanceof CloudViewElement) {
- DeltaCloud deltaCloud = (DeltaCloud) ((CloudViewElement) cloudViewElement).getElement();
- DeltaCloudManager.getDefault().removeCloud(deltaCloud);
+ private Collection<DeltaCloud> getSelectedClouds(ISelection selection) {
+ Set<DeltaCloud> selectedClouds = new HashSet<DeltaCloud>();
+ List<?> selectedElements = ((IStructuredSelection) selection).toList();
+ for (Object element : selectedElements) {
+ DeltaCloud deltaCloud = getDeltaCloud(element);
+ if (deltaCloud != null) {
+ selectedClouds.add(deltaCloud);
}
}
+ return selectedClouds;
}
+
+ private DeltaCloud getDeltaCloud(Object item) {
+ if (!(item instanceof CloudViewElement)) {
+ return null;
+ }
+
+ DeltaCloud cloud = getDeltaCloud((CloudViewElement) item);
+
+ if (cloud == null) {
+ return null;
+ }
+ return cloud;
+ }
+
+ private DeltaCloud getDeltaCloud(CloudViewElement element) {
+ if (element == null) {
+ return null;
+ }
+ Object cloud = element.getElement();
+ if (cloud instanceof DeltaCloud) {
+ return (DeltaCloud) cloud;
+ }
+
+ return getDeltaCloud((CloudViewElement) element.getParent());
+ }
+
+ private void removeCloudViewElements(Object[] deltaClouds) {
+ for (Object deltaCloud : deltaClouds) {
+ DeltaCloudManager.getDefault().removeCloud((DeltaCloud) deltaCloud);
+ }
+ }
}
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java 2010-11-04 13:01:26 UTC (rev 26246)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/DisconnectCloudsDialog.java 2010-11-04 13:08:28 UTC (rev 26247)
@@ -10,32 +10,29 @@
******************************************************************************/
package org.jboss.tools.deltacloud.ui.views;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
+import org.eclipse.core.runtime.Assert;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.dialogs.ListSelectionDialog;
+import org.jboss.tools.deltacloud.core.DeltaCloud;
public class DisconnectCloudsDialog extends ListSelectionDialog {
private static final String CONFIRM_CLOUD_DELETE_TITLE = "ConfirmCloudDelete.title"; //$NON-NLS-1$
private static final String CONFIRM_CLOUD_DELETE_MSG = "ConfirmCloudDelete.msg"; //$NON-NLS-1$
- private static class CloudViewElementsParentContentProvider implements IStructuredContentProvider {
+ private static class DeltaCloudItemProvider implements IStructuredContentProvider {
@SuppressWarnings("unchecked")
@Override
public Object[] getElements(Object cloudViewElements) {
- List<CloudViewElement> cloudViewElementParents = new ArrayList<CloudViewElement>();
- for (Object cloudViewElement : (List<CloudViewElement>) cloudViewElements) {
- if (cloudViewElement instanceof CloudViewElement && ((CloudViewElement) cloudViewElement).getParent() != null) {
- cloudViewElementParents.add((CloudViewElement) cloudViewElement);
- }
- }
- return cloudViewElementParents.toArray(new CloudViewElement[cloudViewElementParents.size()]);
+ Assert.isTrue(cloudViewElements instanceof Collection);
+ Collection<DeltaCloud> deltaClouds = (Collection<DeltaCloud>) cloudViewElements;
+ return deltaClouds.toArray(new DeltaCloud[deltaClouds.size()]);
}
@Override
@@ -49,14 +46,14 @@
private static class CloudElementNameProvider extends LabelProvider {
public String getText(Object element) {
- return ((CloudViewElement) element).getName();
+ return ((DeltaCloud) element).getName();
}
};
- public DisconnectCloudsDialog(Shell parentShell, List<?> cloudViewElements) {
+ public DisconnectCloudsDialog(Shell parentShell, Collection<?> cloudViewElements) {
super(parentShell
, cloudViewElements
- , new CloudViewElementsParentContentProvider()
+ , new DeltaCloudItemProvider()
, new CloudElementNameProvider(), CVMessages.getString(CONFIRM_CLOUD_DELETE_MSG));
setTitle(CVMessages.getString(CONFIRM_CLOUD_DELETE_TITLE));
}
15 years, 5 months