Author: adietish
Date: 2010-12-08 11:43:42 -0500 (Wed, 08 Dec 2010)
New Revision: 27239
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
Log:
[JBIDE-7834] implemented #getLastImage(id) that queries the local cache and the server
(fallback), removed #getImage(String id), #loadImage(String imageId), removed
#findInstanceById
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-08 16:26:00
UTC (rev 27238)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-08 16:43:42
UTC (rev 27239)
@@ -1,3 +1,9 @@
+2010-12-08 André Dietisheim <adietish(a)redhat.com>
+
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java (getImage):
+ [JBIDE-7834] implemented #getLastImage(id) that queries the local cache and the server
(fallback),
+ removed #getImage(String id), #loadImage(String imageId), removed #findInstanceById
+
2010-12-06 André Dietisheim <adietish(a)redhat.com>
* src/org/jboss/tools/deltacloud/core/InstanceFilter.java (InstanceFilter):
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-12-08
16:26:00 UTC (rev 27238)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-12-08
16:43:42 UTC (rev 27239)
@@ -138,6 +138,10 @@
return lastImageId;
}
+ public DeltaCloudImage getLastImage() throws DeltaCloudException {
+ return getImage(lastImageId);
+ }
+
public void setLastImageId(String lastImageId) {
this.lastImageId = lastImageId;
}
@@ -310,7 +314,7 @@
public DeltaCloudInstance waitForState(String instanceId, IInstanceStateMatcher
stateMatcher, IProgressMonitor pm)
throws InterruptedException, DeltaCloudException {
- DeltaCloudInstance instance = findInstanceById(instanceId);
+ DeltaCloudInstance instance = instances.getById(instanceId);
if (instance != null) {
while (!pm.isCanceled()) {
if (stateMatcher.matchesState(instance, instance.getState())
@@ -399,15 +403,27 @@
notifyImageListListeners(getImagesRepository().get());
}
+ /**
+ * Gets an image for the given image id. In a first step, the local cache is
+ * queried and if no image is found, the server is queried.
+ *
+ * @param id
+ * the image id to match
+ * @return the image that has the given id
+ * @throws DeltaCloudException
+ */
public DeltaCloudImage getImage(String id) throws DeltaCloudException {
- DeltaCloudImage matchingImage = null;
- for (DeltaCloudImage image : getImagesRepository().get()) {
- if (id.equals(image.getId())) {
- matchingImage = image;
- break;
+ DeltaCloudImage deltaCloudImage = getImagesRepository().getById(id);
+ if (deltaCloudImage == null) {
+ try {
+ Image image = client.listImages(id);
+ deltaCloudImage = images.add(image, this);
+ } catch (DeltaCloudClientException e) {
+ throw new DeltaCloudException(MessageFormat.format("Cloud not find image with id
\"{0}\"", id), e);
}
}
- return matchingImage;
+
+ return deltaCloudImage;
}
public void createKey(String keyname, String keystoreLocation) throws
DeltaCloudException {
@@ -436,7 +452,7 @@
public void replaceInstance(DeltaCloudInstance instance) {
String instanceId = instance.getId();
if (instance != null) {
- DeltaCloudInstance instanceToReplace = findInstanceById(instanceId);
+ DeltaCloudInstance instanceToReplace = instances.getById(instanceId);
replaceInstance(instance, instanceToReplace);
// TODO: remove notification with all instances, replace by
// notifying the changed instance
@@ -444,17 +460,13 @@
}
}
- private DeltaCloudInstance findInstanceById(String instanceId) {
- return getInstancesRepository().getById(instanceId);
- }
-
// TODO: remove duplicate code with #replaceInstance
public DeltaCloudInstance refreshInstance(String instanceId) throws DeltaCloudException
{
DeltaCloudInstance deltaCloudInstance = null;
try {
Instance instance = client.listInstances(instanceId);
deltaCloudInstance = new DeltaCloudInstance(this, instance);
- DeltaCloudInstance currentInstance = findInstanceById(instanceId);
+ DeltaCloudInstance currentInstance = instances.getById(instanceId);
// FIXME: remove BOGUS state when server fixes state
// problems
if (!(deltaCloudInstance.getState().equals(DeltaCloudInstance.BOGUS))
@@ -476,7 +488,7 @@
}
public boolean performInstanceAction(String instanceId, String actionId) throws
DeltaCloudException {
- return performInstanceAction(findInstanceById(instanceId), actionId);
+ return performInstanceAction(instances.getById(instanceId), actionId);
}
protected boolean performInstanceAction(DeltaCloudInstance instance, String actionId)
throws DeltaCloudException {
@@ -533,15 +545,6 @@
}
- public DeltaCloudImage loadImage(String imageId) throws DeltaCloudException {
- try {
- Image image = client.listImages(imageId);
- return getImagesRepository().add(image, this);
- } catch (DeltaCloudClientException e) {
- throw new DeltaCloudException(e);
- }
- }
-
public boolean testConnection() throws DeltaCloudException {
String instanceId = "nonexistingInstance"; //$NON-NLS-1$
try {
Show replies by date