Author: adietish
Date: 2010-12-13 07:19:18 -0500 (Mon, 13 Dec 2010)
New Revision: 27406
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
Log:
[JBIDE-7877] replaced state- and action-strings in DeltaCloudInstace by enums
Modified: trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog
===================================================================
--- trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-13 12:18:42
UTC (rev 27405)
+++ trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/ChangeLog 2010-12-13 12:19:18
UTC (rev 27406)
@@ -4,6 +4,13 @@
(PROP_INSTANCES_ADDED):
(createInstance):
[JBIDE-7877] added notification for instances being added
+ * src/org/jboss/tools/deltacloud/core/DeltaCloud.java
+ (IInstanceStateMatcher.matchesState):
+ * src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java (State):
+ (Action):
+ (getState):
+ (performInstanceAction):
+ [JBIDE-7877] replaced state- and action-strings in DeltaCloudInstace by enums
2010-12-10 André Dietisheim <adietish(a)redhat.com>
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-13
12:18:42 UTC (rev 27405)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloud.java 2010-12-13
12:19:18 UTC (rev 27406)
@@ -69,7 +69,7 @@
private SecurePasswordStore passwordStore;
public static interface IInstanceStateMatcher {
- public boolean matchesState(DeltaCloudInstance instance, String instanceState);
+ public boolean matchesState(DeltaCloudInstance instance, DeltaCloudInstance.State
instanceState);
}
public DeltaCloud(String name, String url, String username, String passwd) throws
DeltaCloudException {
@@ -314,20 +314,20 @@
IInstanceStateMatcher differsFromPending = new IInstanceStateMatcher() {
@Override
- public boolean matchesState(DeltaCloudInstance instance, String instanceState) {
- return !DeltaCloudInstance.PENDING.equals(instanceState);
+ public boolean matchesState(DeltaCloudInstance instance, DeltaCloudInstance.State
instanceState) {
+ return !DeltaCloudInstance.State.PENDING.equals(instanceState);
}
};
return waitForState(instanceId, differsFromPending, pm);
}
- public DeltaCloudInstance waitForState(String instanceId, final String expectedState,
IProgressMonitor pm)
+ public DeltaCloudInstance waitForState(String instanceId, final DeltaCloudInstance.State
expectedState, IProgressMonitor pm)
throws InterruptedException, DeltaCloudException {
IInstanceStateMatcher stateMatcher = new IInstanceStateMatcher() {
@Override
- public boolean matchesState(DeltaCloudInstance instance, String instanceState) {
- return expectedState != null && expectedState.equals(instanceState);
+ public boolean matchesState(DeltaCloudInstance instance, DeltaCloudInstance.State
instanceState) {
+ return expectedState != null &&
expectedState.equals(instanceState.getName());
}
};
return waitForState(instanceId, stateMatcher, pm);
@@ -339,7 +339,7 @@
if (instance != null) {
while (!pm.isCanceled()) {
if (stateMatcher.matchesState(instance, instance.getState())
- || instance.getState().equals(DeltaCloudInstance.TERMINATED)) {
+ || instance.getState().equals(DeltaCloudInstance.State.TERMINATED)) {
return instance;
}
Thread.sleep(400);
@@ -488,9 +488,9 @@
Instance instance = client.listInstances(instanceId);
deltaCloudInstance = new DeltaCloudInstance(this, instance);
DeltaCloudInstance currentInstance = instanceRepo.getById(instanceId);
- // FIXME: remove BOGUS state when server fixes state
+ // FIXME: remove STATE_BOGUS state when server fixes state
// problems
- if (!(deltaCloudInstance.getState().equals(DeltaCloudInstance.BOGUS))
+ if (!(deltaCloudInstance.getState().equals(DeltaCloudInstance.State.BOGUS))
&& !(currentInstance.getState().equals(deltaCloudInstance.getState()))) {
replaceInstance(deltaCloudInstance, currentInstance);
}
@@ -512,19 +512,23 @@
firePropertyChange(PROP_INSTANCES, instances, repo.get());
}
- public boolean performInstanceAction(String instanceId, String actionId) throws
DeltaCloudException {
- return performInstanceAction(instanceRepo.getById(instanceId), actionId);
+ public boolean performInstanceAction(String instanceId, DeltaCloudInstance.Action
action) throws DeltaCloudException {
+ return performInstanceAction(instanceRepo.getById(instanceId), action);
}
- protected boolean performInstanceAction(DeltaCloudInstance instance, String actionId)
throws DeltaCloudException {
+ protected boolean performInstanceAction(DeltaCloudInstance instance,
DeltaCloudInstance.Action action) throws DeltaCloudException {
try {
if (instance == null) {
return false;
}
DeltaCloudInstancesRepository repo = getInstancesRepository();
DeltaCloudInstance[] instances = repo.get();
- boolean result = instance.performInstanceAction(actionId, client);
+ boolean result = instance.performInstanceAction(action, client);
if (result) {
+ if (DeltaCloudInstance.Action.DESTROY.equals(action)) {
+ repo.remove(instance);
+ firePropertyChange(PROP_INSTANCES_REMOVED, null, instance);
+ }
// TODO: remove notification with all instanceRepo, replace by
// notifying the changed instance
firePropertyChange(PROP_INSTANCES, instances, repo.get());
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-13
12:18:42 UTC (rev 27405)
+++
trunk/deltacloud/plugins/org.jboss.tools.deltacloud.core/src/org/jboss/tools/deltacloud/core/DeltaCloudInstance.java 2010-12-13
12:19:18 UTC (rev 27406)
@@ -19,7 +19,8 @@
import org.jboss.tools.deltacloud.core.client.InternalDeltaCloudClient;
/**
- * An instance that may be reached on a DeltaCloud instance. Wraps Instance from upper
layers.
+ * An instance that may be reached on a DeltaCloud instance. Wraps Instance from
+ * upper layers.
*
* @see Instance
* @see DeltaCloud
@@ -29,17 +30,47 @@
*/
public class DeltaCloudInstance extends AbstractDeltaCloudElement {
- public final static String PENDING = Instance.InstanceState.PENDING.toString();
- public final static String RUNNING = Instance.InstanceState.RUNNING.toString();
- public final static String STOPPED = Instance.InstanceState.STOPPED.toString();
- public final static String TERMINATED = Instance.InstanceState.TERMINATED.toString();
- public final static String BOGUS = Instance.InstanceState.BOGUS.toString();
+ public enum State {
- public final static String START = InstanceAction.START;
- public final static String STOP = InstanceAction.STOP;
- public final static String REBOOT = InstanceAction.REBOOT;
- public final static String DESTROY = InstanceAction.DESTROY;
+ PENDING(Instance.InstanceState.PENDING.name()),
+ RUNNING(Instance.InstanceState.RUNNING.name()),
+ STOPPED(Instance.InstanceState.STOPPED.name()),
+ TERMINATED(Instance.InstanceState.TERMINATED.name()),
+ BOGUS(Instance.InstanceState.BOGUS.name());
+ private String name;
+
+ private State(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean equals(String state) {
+ return name.equals(state);
+ }
+ }
+
+ public enum Action {
+
+ START(InstanceAction.START),
+ STOP(InstanceAction.STOP),
+ REBOOT(InstanceAction.REBOOT),
+ DESTROY(InstanceAction.DESTROY);
+
+ private String name;
+
+ private Action(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+
private Instance instance;
private String givenName;
@@ -68,8 +99,8 @@
return instance.getOwnerId();
}
- public String getState() {
- return instance.getState().toString();
+ public State getState() {
+ return State.valueOf(instance.getState().name());
}
public String getKey() {
@@ -99,7 +130,7 @@
public boolean isStopped() {
return instance.getState() == InstanceState.STOPPED;
}
-
+
public boolean canStart() {
return instance.canStart();
}
@@ -116,7 +147,6 @@
return instance.canDestroy();
}
-
public boolean isRunning() {
return instance.isRunning();
}
@@ -127,13 +157,13 @@
return hostNames.get(0);
return null;
}
-
- protected boolean performInstanceAction(String actionId, InternalDeltaCloudClient
client)
+
+ protected boolean performInstanceAction(Action action, InternalDeltaCloudClient client)
throws DeltaCloudClientException {
- InstanceAction action = instance.getAction(actionId);
- if (action == null) {
+ InstanceAction instanceAction = instance.getAction(action.getName());
+ if (instanceAction == null) {
return false;
}
- return client.performInstanceAction(action);
+ return client.performInstanceAction(instanceAction);
}
}