Author: kve
Date: Tue Oct 4 14:04:22 2011
New Revision: 1178800
URL: http://svn.apache.org/viewvc?rev=1178800&view=rev
Log:
fix for WHIRR-376: Launching a BYON cluster doesn't produce an instances file.
This also fixes whirr list-cluster and whirr run-script on BYON clusters.
Modified:
whirr/trunk/CHANGES.txt
whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/ListClusterCommand.java
whirr/trunk/core/src/main/java/org/apache/whirr/ByonClusterController.java
whirr/trunk/core/src/main/java/org/apache/whirr/Cluster.java
whirr/trunk/core/src/main/java/org/apache/whirr/ClusterController.java
Modified: whirr/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/whirr/trunk/CHANGES.txt?rev=1178800&r1=1178799&r2=1178800&view=diff
==============================================================================
--- whirr/trunk/CHANGES.txt (original)
+++ whirr/trunk/CHANGES.txt Tue Oct 4 14:04:22 2011
@@ -18,6 +18,8 @@ Trunk (unreleased changes)
WHIRR-371. Allow defining additional firewall rules (kve)
+ WHIRR-376. Launching a BYON cluster doesn't produce an instances file.
(kve)
+
BUG FIXES
WHIRR-377. Fix broken CLI logging config. (asavu via tomwhite)
Modified:
whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/ListClusterCommand.java
URL:
http://svn.apache.org/viewvc/whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/ListClusterCommand.java?rev=1178800&r1=1178799&r2=1178800&view=diff
==============================================================================
---
whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/ListClusterCommand.java
(original)
+++
whirr/trunk/cli/src/main/java/org/apache/whirr/cli/command/ListClusterCommand.java
Tue Oct 4 14:04:22 2011
@@ -70,7 +70,7 @@ public class ListClusterCommand extends
ClusterController controller =
createClusterController(clusterSpec.getServiceName());
for (Cluster.Instance instance : controller.getInstances(clusterSpec,
stateStore)) {
- out.println(Joiner.on('\t').join(
+ out.println(Joiner.on('\t').useForNull("-").join(
instance.getId(),
instance.getNodeMetadata().getImageId(),
instance.getPublicIp(),
Modified:
whirr/trunk/core/src/main/java/org/apache/whirr/ByonClusterController.java
URL:
http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/ByonClusterController.java?rev=1178800&r1=1178799&r2=1178800&view=diff
==============================================================================
--- whirr/trunk/core/src/main/java/org/apache/whirr/ByonClusterController.java
(original)
+++ whirr/trunk/core/src/main/java/org/apache/whirr/ByonClusterController.java
Tue Oct 4 14:04:22 2011
@@ -23,19 +23,37 @@ import static org.apache.whirr.service.C
import static org.apache.whirr.service.ClusterActionHandler.DESTROY_ACTION;
import java.io.IOException;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.whirr.Cluster.Instance;
import org.apache.whirr.actions.ByonClusterAction;
import org.apache.whirr.service.ClusterActionHandler;
+import org.jclouds.compute.ComputeService;
+import org.jclouds.compute.ComputeServiceContext;
+import org.jclouds.compute.RunScriptOnNodesException;
+import org.jclouds.compute.domain.ExecResponse;
import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.NodeState;
+import org.jclouds.compute.options.RunScriptOptions;
+import org.jclouds.scriptbuilder.domain.Statement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.common.base.Function;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
/**
* Equivalent of {@link ClusterController}, but for execution in BYON mode
* ("bring your own nodes").
*/
public class ByonClusterController extends ClusterController {
-
+
+ private static final Logger LOG =
LoggerFactory.getLogger(ClusterController.class);
+
@Override
public String getName() {
return "byon";
@@ -53,6 +71,8 @@ public class ByonClusterController exten
ClusterAction configurer = new ByonClusterAction(CONFIGURE_ACTION,
getCompute(), handlerMap);
cluster = configurer.execute(clusterSpec, cluster);
+ getClusterStateStore(clusterSpec).save(cluster);
+
return cluster;
}
@@ -65,6 +85,32 @@ public class ByonClusterController exten
destroyer.execute(clusterSpec, null);
}
+ public Map<? extends NodeMetadata, ExecResponse>
runScriptOnNodesMatching(final ClusterSpec spec,
+ Predicate<NodeMetadata> condition, final Statement statement) throws
IOException, RunScriptOnNodesException {
+
+ ComputeServiceContext computeServiceContext = getCompute().apply(spec);
+ ComputeService computeService = computeServiceContext.getComputeService();
+ Cluster cluster = getClusterStateStore(spec).load();
+
+ RunScriptOptions options =
RunScriptOptions.Builder.runAsRoot(false).wrapInInitScript(false);
+ return
computeService.runScriptOnNodesMatching(Predicates.<NodeMetadata>and(condition,
runningIn(cluster)), statement, options);
+ }
+
+ private Predicate<NodeMetadata> runningIn(Cluster cluster) {
+ final Set<String> instanceIds = new
HashSet<String>(Collections2.transform(cluster.getInstances(), new
Function<Instance, String>() {
+ @Override
+ public String apply(Instance instance) {
+ return instance.getId();
+ }
+ }));
+ return new Predicate<NodeMetadata>() {
+ @Override
+ public boolean apply(final NodeMetadata nodeMetadata) {
+ return instanceIds.contains(nodeMetadata.getId()) &&
nodeMetadata.getState().equals(NodeState.RUNNING);
+ }
+ };
+ }
+
@Override
public void destroyInstance(ClusterSpec clusterSpec, String instanceId)
throws IOException {
@@ -74,7 +120,8 @@ public class ByonClusterController exten
@Override
public Set<? extends NodeMetadata> getNodes(ClusterSpec clusterSpec)
throws IOException, InterruptedException {
- // TODO return singleton with trivial NodeMetadata for localhost?
- return null;
+ ComputeServiceContext computeServiceContext =
getCompute().apply(clusterSpec);
+ ComputeService computeService = computeServiceContext.getComputeService();
+ return
computeService.listNodesDetailsMatching(Predicates.in(computeService.listNodes()));
}
}
Modified: whirr/trunk/core/src/main/java/org/apache/whirr/Cluster.java
URL:
http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/Cluster.java?rev=1178800&r1=1178799&r2=1178800&view=diff
==============================================================================
--- whirr/trunk/core/src/main/java/org/apache/whirr/Cluster.java (original)
+++ whirr/trunk/core/src/main/java/org/apache/whirr/Cluster.java Tue Oct 4
14:04:22 2011
@@ -65,9 +65,11 @@ public class Cluster {
this.publicIp = checkNotNull(publicIp, "publicIp");
checkArgument(InetAddresses.isInetAddress(publicIp),
"invalid IP address: %s", publicIp);
- this.privateIp = checkNotNull(privateIp, "privateIp");
- checkArgument(InetAddresses.isInetAddress(privateIp),
- "invalid IP address: %s", privateIp);
+ this.privateIp = privateIp;
+ if (privateIp != null) {
+ checkArgument(InetAddresses.isInetAddress(privateIp),
+ "invalid IP address: %s", privateIp);
+ }
this.id = checkNotNull(id, "id");
this.nodeMetadata = nodeMetadata;
}
Modified: whirr/trunk/core/src/main/java/org/apache/whirr/ClusterController.java
URL:
http://svn.apache.org/viewvc/whirr/trunk/core/src/main/java/org/apache/whirr/ClusterController.java?rev=1178800&r1=1178799&r2=1178800&view=diff
==============================================================================
--- whirr/trunk/core/src/main/java/org/apache/whirr/ClusterController.java
(original)
+++ whirr/trunk/core/src/main/java/org/apache/whirr/ClusterController.java Tue
Oct 4 14:04:22 2011
@@ -108,7 +108,7 @@ public class ClusterController {
ConfigureClusterAction configurer = new
ConfigureClusterAction(getCompute(), handlerMap);
cluster = configurer.execute(clusterSpec, cluster);
- stateStoreFactory.create(clusterSpec).save(cluster);
+ getClusterStateStore(clusterSpec).save(cluster);
return cluster;
}
@@ -126,7 +126,7 @@ public class ClusterController {
DestroyClusterAction destroyer = new DestroyClusterAction(getCompute());
destroyer.execute(clusterSpec, null);
- stateStoreFactory.create(clusterSpec).destroy();
+ getClusterStateStore(clusterSpec).destroy();
}
public void destroyInstance(ClusterSpec clusterSpec, String instanceId)
throws IOException {
@@ -137,13 +137,17 @@ public class ClusterController {
computeService.destroyNode(instanceId);
/* .. and update the cluster state storage */
- ClusterStateStore store = stateStoreFactory.create(clusterSpec);
+ ClusterStateStore store = getClusterStateStore(clusterSpec);
Cluster cluster = store.load();
cluster.removeInstancesMatching(withIds(instanceId));
store.save(cluster);
LOG.info("Instance {} destroyed", instanceId);
}
+
+ public ClusterStateStore getClusterStateStore(ClusterSpec clusterSpec) {
+ return stateStoreFactory.create(clusterSpec);
+ }
public Map<? extends NodeMetadata, ExecResponse>
runScriptOnNodesMatching(ClusterSpec spec,
Predicate<NodeMetadata> condition, Statement statement) throws
IOException, RunScriptOnNodesException {