Author: adietish
Date: 2010-12-14 10:23:25 -0500 (Tue, 14 Dec 2010)
New Revision: 27448
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/AddressList.java
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/Instance.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/cloud/property/InstancePropertySource.java
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java
Log:
[JBIDE-7889]
* DeltaCloudClientImpl#updateInstance: now also sets pulic_adresses and private_adresses
when updating instances
* DeltaCloud#replaceInstance: removed code that replaced instances in the local cache.
* DeltaCloudInstance#setInstance: I now set a new instance to the DeltaCloudInstance
(DeltaCloudInstance#setInstance)
* InstancePropertySource#getKey: added #setInstance to be able to refresh instances
* NewInstanceWizard#WatchCreateJob#run: removed DeltaCloud#replaceInstance since
DeltaCloud now handles this
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-14 14:36:21
UTC (rev 27447)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-14 15:23:25
UTC (rev 27448)
@@ -1,5 +1,12 @@
2010-12-14 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java (updateInstance):
+ [JBIDE-7889] now also set pulic_adresses and private_adresses when updating instances
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java (refreshInstance):
+ [JBIDE-7889] removed code that replaced instances in the local cache.
+ I now set a new instance to the DeltaCloudInstance (DeltaCloudInstance#setInstance)
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java (setInstance):
+ [JBIDE-7889] added #setInstance to be able to refresh instances
* src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java (toString):
[JBIDE-7889] added #toString to facilitate debuggin
* src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java (getActions):
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-14
14:36:21 UTC (rev 27447)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-12-14
15:23:25 UTC (rev 27448)
@@ -103,8 +103,8 @@
this.type = type;
boolean nameChanged = updateName(name);
- boolean connectionPropertiesChanged = updateConnectionProperties(url, username,
password);
-
+ boolean connectionPropertiesChanged = updateConnectionProperties(url, username,
password);
+
if (nameChanged || connectionPropertiesChanged) {
this.passwordStore.update(new DeltaCloudPasswordStorageKey(name, username),
password);
}
@@ -114,7 +114,7 @@
loadChildren();
}
}
-
+
private boolean updateName(String name) {
if (equals(this.name, name)) {
return false;
@@ -123,7 +123,7 @@
setName(name);
return true;
}
-
+
private boolean updateConnectionProperties(String url, String username, String
password)
throws DeltaCloudException {
boolean changed = false;
@@ -321,7 +321,8 @@
return waitForState(instanceId, differsFromPending, pm);
}
- public DeltaCloudInstance waitForState(String instanceId, final DeltaCloudInstance.State
expectedState, IProgressMonitor pm)
+ public DeltaCloudInstance waitForState(String instanceId, final DeltaCloudInstance.State
expectedState,
+ IProgressMonitor pm)
throws InterruptedException, DeltaCloudException {
IInstanceStateMatcher stateMatcher = new IInstanceStateMatcher() {
@@ -343,7 +344,7 @@
return instance;
}
Thread.sleep(400);
- instance = refreshInstance(instance.getId());
+ instance = refreshInstance(instance);
}
}
return instance;
@@ -469,55 +470,25 @@
}
}
- /**
- * Replaces the current instance with the given one. The instanceRepo are
- * matched against identical id
- *
- * @param instance
- * the instance that shall replace the current one
- */
- public void replaceInstance(DeltaCloudInstance instance) {
- String instanceId = instance.getId();
- if (instance != null) {
- replaceInstance(instance, instanceRepo.getById(instanceId));
- }
- }
-
- public DeltaCloudInstance refreshInstance(String instanceId) throws DeltaCloudException
{
- DeltaCloudInstance deltaCloudInstance = null;
+ private DeltaCloudInstance refreshInstance(DeltaCloudInstance deltaCloudInstance) throws
DeltaCloudException {
try {
- Instance instance = client.listInstances(instanceId);
- deltaCloudInstance = new DeltaCloudInstance(this, instance);
- DeltaCloudInstance currentInstance = instanceRepo.getById(instanceId);
- // FIXME: remove STATE_BOGUS state when server fixes state
- // problems
- if (!(deltaCloudInstance.getState().equals(DeltaCloudInstance.State.BOGUS))
- && !(currentInstance.getState().equals(deltaCloudInstance.getState()))) {
- replaceInstance(deltaCloudInstance, currentInstance);
- }
+ Instance newInstance = client.listInstances(deltaCloudInstance.getId());
+ deltaCloudInstance.setInstance(newInstance);
+ return deltaCloudInstance;
} catch (DeltaCloudClientException e) {
- // TODO: is this correct?
- e.printStackTrace();
- // will get here when a pending instance is being checked
+ // TODO : internationalize strings
+ throw new DeltaCloudException(MessageFormat.format("Coud not refresh instance
\"{0}\"",
+ deltaCloudInstance.getId()), e);
}
- return deltaCloudInstance;
}
- private void replaceInstance(DeltaCloudInstance deltaCloudInstance, DeltaCloudInstance
currentInstance) {
- DeltaCloudInstancesRepository repo = getInstancesRepository();
- DeltaCloudInstance[] instances = repo.get();
- repo.remove(currentInstance);
- repo.add(deltaCloudInstance);
- // TODO: remove notification with all instanceRepo, replace by
- // notifying the changed instance
- firePropertyChange(PROP_INSTANCES, instances, repo.get());
- }
-
- public boolean performInstanceAction(String instanceId, DeltaCloudInstance.Action
action) throws DeltaCloudException {
+ public boolean performInstanceAction(String instanceId, DeltaCloudInstance.Action
action)
+ throws DeltaCloudException {
return performInstanceAction(instanceRepo.getById(instanceId), action);
}
- protected boolean performInstanceAction(DeltaCloudInstance instance,
DeltaCloudInstance.Action action) throws DeltaCloudException {
+ protected boolean performInstanceAction(DeltaCloudInstance instance,
DeltaCloudInstance.Action action)
+ throws DeltaCloudException {
try {
if (instance == null) {
return false;
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-12-14
14:36:21 UTC (rev 27447)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-12-14
15:23:25 UTC (rev 27448)
@@ -155,6 +155,10 @@
public boolean isRunning() {
return instance.isRunning();
}
+
+ protected void setInstance(Instance instance) {
+ this.instance = instance;
+ }
public String getHostName() {
List<String> hostNames = getHostNames();
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/AddressList.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/AddressList.java 2010-12-14
14:36:21 UTC (rev 27447)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/AddressList.java 2010-12-14
15:23:25 UTC (rev 27448)
@@ -17,28 +17,33 @@
/**
* @author Martyn Taylor
+ * @author André Dietisheim
*/
@XmlType
public class AddressList
{
private static final long serialVersionUID = 1L;
-
- private AddressList()
+
+ @XmlElement
+ @XmlList
+ private List<String> addresses;
+
+ protected AddressList()
{
}
- @XmlElement
- @XmlList
- private List<String> address;
-
- @SuppressWarnings("unused")
- private void setAddress(List<String> address)
+ protected AddressList(List<String> addresses)
{
- this.address = address;
+ setAddress(addresses);
}
+ protected void setAddress(List<String> addresses)
+ {
+ this.addresses = addresses;
+ }
+
public List<String> getAddress()
{
- return address;
+ return addresses;
}
}
Modified:
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/DeltaCloudClientImpl.java 2010-12-14
14:36:21 UTC (rev 27447)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/DeltaCloudClientImpl.java 2010-12-14
15:23:25 UTC (rev 27448)
@@ -25,6 +25,8 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import javax.xml.bind.JAXB;
import javax.xml.parsers.DocumentBuilder;
@@ -79,6 +81,8 @@
private static final String DOCUMENT_ELEMENT_DRIVER = "driver";
private static final String DOCUMENT_ELEMENT_API = "api";
+ private static final Pattern ELEMENT_TEXTVALUE_REGEX = Pattern.compile("[^\n\t
]+[^\n]+");
+
public static Logger logger = Logger.getLogger(DeltaCloudClientImpl.class);
public static enum DeltaCloudServerType {
@@ -290,6 +294,7 @@
@Override
public Instance listInstances(String instanceId) throws DeltaCloudClientException {
+// return JAXB.unmarshal(new StringReader(sendRequest(new ListInstanceRequest(baseUrl,
instanceId))), Instance.class);
return buildInstance(sendRequest(new ListInstanceRequest(baseUrl, instanceId)));
}
@@ -351,7 +356,7 @@
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$
+ List<String> keyText = getElementTextValues(document, PEM_FILE_SUFFIX);
//$NON-NLS-1$
return keyText;
}
@@ -381,10 +386,11 @@
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$
+ instance.setState(getElementTextValues(document, "state").get(0));
//$NON-NLS-1$
getAuthentication(document, instance);
instance.setActions(createInstanceActions(instance, document));
-
+ instance.setPublicAddresses(new AddressList(getElementTextValues(document,
"public_addresses")));
+ instance.setPrivateAddresses(new AddressList(getElementTextValues(document,
"private_addresses")));
return instance;
} catch (DeltaCloudClientException e) {
throw e;
@@ -396,8 +402,7 @@
private Instance buildInstance(String xml) throws DeltaCloudClientException {
Instance instance = JAXB.unmarshal(new StringReader(xml), Instance.class);
- updateInstance(xml, instance);
- return instance;
+ return updateInstance(xml, instance);
}
private List<InstanceAction> createInstanceActions(final Instance instance,
Document document)
@@ -500,11 +505,16 @@
return values;
}
- private List<String> getElementText(Document document, String elementName) {
+ private List<String> getElementTextValues(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());
+ String textValue = elements.item(i).getTextContent();
+ Matcher matcher = ELEMENT_TEXTVALUE_REGEX.matcher(textValue);
+ if (matcher.find()) {
+ String group = matcher.group();
+ values.add(group);
+ }
}
return values;
}
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-12-14
14:36:21 UTC (rev 27447)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/client/Instance.java 2010-12-14
15:23:25 UTC (rev 27448)
@@ -115,13 +115,11 @@
return keyname;
}
- @SuppressWarnings("unused")
- private void setPrivateAddresses(AddressList privateAddresses) {
+ protected void setPrivateAddresses(AddressList privateAddresses) {
this.privateAddresses = privateAddresses;
}
- @SuppressWarnings("unused")
- private void setPublicAddresses(AddressList publicAddresses) {
+ protected void setPublicAddresses(AddressList publicAddresses) {
this.publicAddresses = publicAddresses;
}
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-14 14:36:21
UTC (rev 27447)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/ChangeLog 2010-12-14 15:23:25
UTC (rev 27448)
@@ -1,5 +1,9 @@
2010-12-14 André Dietisheim <adietish(a)redhat.com>
+ * src/org/jboss/tools/deltacloud/ui/views/cloud/property/InstancePropertySource.java
(getKey):
+ [JBIDE-7789] removed DeltaCloud#replaceInstance code since DeltaCloud now handles this
+ * src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java
(WatchCreateJob.run):
+ [JBIDE-7789] removed DeltaCloud#replaceInstance since DeltaCloud now handles this
* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java
(WatchCreateJob):
[JBIDE-7594] switched WatchCreateJob to InstanceStateJob to have consistent blocking
with all other jobs
* src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstancePage.java
(asyncGetProfiles):
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/InstancePropertySource.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/InstancePropertySource.java 2010-12-14
14:36:21 UTC (rev 27447)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/deltacloud/ui/views/cloud/property/InstancePropertySource.java 2010-12-14
15:23:25 UTC (rev 27448)
@@ -12,14 +12,11 @@
import java.util.List;
-import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import org.jboss.tools.deltacloud.core.DeltaCloud;
-import org.jboss.tools.deltacloud.core.DeltaCloudException;
import org.jboss.tools.deltacloud.core.DeltaCloudInstance;
-import org.jboss.tools.deltacloud.ui.ErrorUtils;
import org.jboss.tools.deltacloud.ui.views.CVMessages;
import org.jboss.tools.deltacloud.ui.views.cloud.InstanceItem;
import org.jboss.tools.internal.deltacloud.ui.utils.CloudViewElementUtils;
@@ -133,23 +130,29 @@
// it will be complete for future requests until a refresh gets the
// entire list again.
String key = null;
- try {
- key = instance.getKey();
- if (!cloud.getType().equals(DeltaCloud.MOCK_TYPE)) {
- if (instance.getState().equals(DeltaCloudInstance.State.RUNNING) && (key ==
null || key.length() == 0)) {
- instance = cloud.refreshInstance(instance.getId());
- if (instance != null) {
- key = instance.getKey();
- if (key != null && key.length() > 0)
- cloud.replaceInstance(instance);
- }
- }
- }
- } catch (DeltaCloudException e) {
- ErrorUtils.handleError(
- "Error", "Could not get key for instance " +
instance.getName(),
- e, Display.getDefault().getActiveShell());
- }
+ // TODO: very weird stuff here. Why should we check for the server to be
+ // a mock and then refresh the instance? investigate what are the
+ // consequences of uncommenting this stuff here
+ // try {
+ key = instance.getKey();
+ // if (!cloud.getType().equals(DeltaCloud.MOCK_TYPE)) {
+ // if (instance.getState().equals(DeltaCloudInstance.State.RUNNING) &&
+ // (key == null || key.length() == 0)) {
+ // instance = cloud.refreshInstance(instance.getId());
+ // consequences
+ //
+ // if (instance != null) {
+ // key = instance.getKey();
+ // if (key != null && key.length() > 0)
+ // cloud.replaceInstance(instance);
+ // }
+ // }
+ // }
+ // } catch (DeltaCloudException e) {
+ // ErrorUtils.handleError(
+ // "Error", "Could not get key for instance " +
instance.getName(),
+ // e, Display.getDefault().getActiveShell());
+ // }
return key;
}
Modified:
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java
===================================================================
---
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java 2010-12-14
14:36:21 UTC (rev 27447)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.ui/src/org/jboss/tools/internal/deltacloud/ui/wizards/NewInstanceWizard.java 2010-12-14
15:23:25 UTC (rev 27448)
@@ -106,7 +106,7 @@
} catch (Exception e) {
// do nothing
} finally {
- cloud.replaceInstance(instance);
+// cloud.replaceInstance(instance);
cloud.removeInstanceJob(instanceId, this);
System.out.println(instance.getHostName());
pm.done();