mirror of https://github.com/apache/jclouds.git
modify yaml format: list of nodes
This commit is contained in:
parent
89d201854b
commit
22b1b89e6a
|
@ -35,9 +35,10 @@ public class Node {
|
|||
public Node() {
|
||||
}
|
||||
|
||||
public Node(String id, String description, String hostname, String osArch, String osFamily, String osName,
|
||||
public Node(String id, String name, String description, String hostname, String osArch, String osFamily, String osName,
|
||||
String osVersion, String group, List<String> tags, String username, String credential, String sudo_password) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.hostname = hostname;
|
||||
this.os_arch = osArch;
|
||||
|
@ -53,6 +54,7 @@ public class Node {
|
|||
|
||||
// public due to snakeyaml
|
||||
public String id;
|
||||
public String name;
|
||||
public String description;
|
||||
public String hostname;
|
||||
public String os_arch;
|
||||
|
@ -69,6 +71,10 @@ public class Node {
|
|||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
@ -130,10 +136,10 @@ public class Node {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).add("id", id).add("description", description).add("hostname", hostname).add(
|
||||
"osArch", os_arch).add("osFamily", os_family).add("osName", os_name).add("osVersion", os_version).add(
|
||||
"group", group).add("tags", tags).add("username", username).add("hasCredential", credential != null)
|
||||
.add("hasSudoPassword", sudo_password != null).toString();
|
||||
return Objects.toStringHelper(this).add("id", id).add("name", name).add("description", description).add(
|
||||
"hostname", hostname).add("osArch", os_arch).add("osFamily", os_family).add("osName", os_name).add(
|
||||
"osVersion", os_version).add("group", group).add("tags", tags).add("username", username).add(
|
||||
"hasCredential", credential != null).add("hasSudoPassword", sudo_password != null).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ public class NodeToNodeMetadata implements Function<Node, NodeMetadata> {
|
|||
public NodeMetadata apply(Node from) {
|
||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||
builder.ids(from.getId());
|
||||
builder.name(from.getDescription());
|
||||
builder.name(from.getName());
|
||||
builder.location(location.get());
|
||||
builder.tag(from.getGroup());
|
||||
// TODO add tags!
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.jclouds.byon.functions;
|
|||
import static com.google.common.base.Preconditions.checkState;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Singleton;
|
||||
|
@ -33,26 +34,27 @@ import org.yaml.snakeyaml.Yaml;
|
|||
import org.yaml.snakeyaml.constructor.Constructor;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
/**
|
||||
* Parses the following syntax.
|
||||
*
|
||||
* <pre>
|
||||
* nodes:
|
||||
* cluster-1:
|
||||
* id: cluster-1
|
||||
* description: xyz
|
||||
* hostname: cluster-1.mydomain.com
|
||||
* os_arch: x86
|
||||
* os_family: linux
|
||||
* os_name: redhat
|
||||
* os_version: 5.3
|
||||
* group: hadoop
|
||||
* tags:
|
||||
* - vanilla
|
||||
* username: kelvin
|
||||
* credential: password_or_rsa_in_base64
|
||||
* sudo_password: password_in_base64
|
||||
* - id: cluster-1:
|
||||
* name: cluster-1
|
||||
* description: xyz
|
||||
* hostname: cluster-1.mydomain.com
|
||||
* os_arch: x86
|
||||
* os_family: linux
|
||||
* os_name: redhat
|
||||
* os_version: 5.3
|
||||
* group: hadoop
|
||||
* tags:
|
||||
* - vanilla
|
||||
* username: kelvin
|
||||
* credential: password_or_rsa_in_base64
|
||||
* sudo_password: password_in_base64
|
||||
* </pre>
|
||||
*
|
||||
* @author Kelvin Kakugawa
|
||||
|
@ -65,7 +67,7 @@ public class NodesFromYaml implements Function<InputStream, Map<String, Node>> {
|
|||
*
|
||||
*/
|
||||
public static class Config {
|
||||
public Map<String, Node> nodes;
|
||||
public List<Node> nodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,12 +79,16 @@ public class NodesFromYaml implements Function<InputStream, Map<String, Node>> {
|
|||
constructor.addTypeDescription(nodeDesc);
|
||||
|
||||
TypeDescription configDesc = new TypeDescription(Config.class);
|
||||
configDesc.putMapPropertyType("nodes", String.class, Node.class);
|
||||
configDesc.putListPropertyType("nodes", Node.class);
|
||||
constructor.addTypeDescription(configDesc);
|
||||
|
||||
Yaml yaml = new Yaml(new Loader(constructor));
|
||||
Config config = (Config) yaml.load(source);
|
||||
checkState(config != null, "missing nodes: collection");
|
||||
return config.nodes;
|
||||
checkState(config != null, "missing config: class");
|
||||
checkState(config.nodes != null, "missing nodes: collection");
|
||||
|
||||
return Maps.uniqueIndex(config.nodes, new Function<Node, String>(){
|
||||
public String apply(Node node) { return node.getId(); }
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,19 +60,19 @@ public class BYONComputeServiceLiveTest {
|
|||
|
||||
StringBuilder nodes = new StringBuilder();
|
||||
nodes.append("nodes:\n");
|
||||
nodes.append(" mymachine:\n");
|
||||
nodes.append(" id: mymachine\n");
|
||||
nodes.append(" description: my local machine\n");
|
||||
nodes.append(" hostname: localhost\n");
|
||||
nodes.append(" os_arch: ").append(System.getProperty("os.arch")).append("\n");
|
||||
nodes.append(" os_family: ").append(OsFamily.UNIX).append("\n");
|
||||
nodes.append(" os_name: ").append(System.getProperty("os.name")).append("\n");
|
||||
nodes.append(" os_version: ").append(System.getProperty("os.version")).append("\n");
|
||||
nodes.append(" group: ").append("ssh").append("\n");
|
||||
nodes.append(" tags:\n");
|
||||
nodes.append(" - local\n");
|
||||
nodes.append(" username: ").append(System.getProperty("user.name")).append("\n");
|
||||
nodes.append(" credential: ").append(base64(ComputeTestUtils.setupKeyPair().get("private").getBytes()))
|
||||
nodes.append(" - id: mymachine\n");
|
||||
nodes.append(" name: mymachine\n");
|
||||
nodes.append(" description: my local machine\n");
|
||||
nodes.append(" hostname: localhost\n");
|
||||
nodes.append(" os_arch: ").append(System.getProperty("os.arch")).append("\n");
|
||||
nodes.append(" os_family: ").append(OsFamily.UNIX).append("\n");
|
||||
nodes.append(" os_name: ").append(System.getProperty("os.name")).append("\n");
|
||||
nodes.append(" os_version: ").append(System.getProperty("os.version")).append("\n");
|
||||
nodes.append(" group: ").append("ssh").append("\n");
|
||||
nodes.append(" tags:\n");
|
||||
nodes.append(" - local\n");
|
||||
nodes.append(" username: ").append(System.getProperty("user.name")).append("\n");
|
||||
nodes.append(" credential: ").append(base64(ComputeTestUtils.setupKeyPair().get("private").getBytes()))
|
||||
.append("\n");
|
||||
|
||||
contextProperties.setProperty("byon.nodes", nodes.toString());
|
||||
|
|
|
@ -46,7 +46,7 @@ import com.google.common.collect.Maps;
|
|||
public class NodeToNodeMetadataTest {
|
||||
public static final Location location = new LocationImpl(LocationScope.PROVIDER, "byon", "byon", null);
|
||||
|
||||
public static final NodeMetadata TEST1 = new NodeMetadataBuilder().ids("cluster-1").tag("hadoop").name("xyz").location(
|
||||
public static final NodeMetadata TEST1 = new NodeMetadataBuilder().ids("cluster-1").tag("hadoop").name("cluster-1").location(
|
||||
location).state(NodeState.RUNNING).operatingSystem(
|
||||
new OperatingSystemBuilder().name("redhat").family(OsFamily.RHEL).arch("x86").version("5.3").description(
|
||||
"xyz").build()).publicAddresses(ImmutableSet.of("cluster-1.mydomain.com")).credentials(
|
||||
|
|
|
@ -37,7 +37,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
*/
|
||||
public class NodesFromYamlTest {
|
||||
|
||||
public static final Node TEST1 = new Node("cluster-1", "xyz", "cluster-1.mydomain.com", "x86", "rhel", "redhat",
|
||||
public static final Node TEST1 = new Node("cluster-1", "cluster-1", "xyz", "cluster-1.mydomain.com", "x86", "rhel", "redhat",
|
||||
"5.3", "hadoop", ImmutableList.of("vanilla"), "myUser", CryptoStreams.base64("fancyfoot".getBytes()),
|
||||
CryptoStreams.base64("sudo".getBytes()));
|
||||
|
||||
|
|
|
@ -37,11 +37,4 @@ public class NodesParsedFromSupplierTest {
|
|||
new NodesParsedFromSupplier(Suppliers.ofInstance(Strings2.toInputStream("nodes:\n")), new NodesFromYaml()).get();
|
||||
|
||||
}
|
||||
|
||||
public void testCanParseSomething() throws Exception {
|
||||
|
||||
new NodesParsedFromSupplier(Suppliers.ofInstance(Strings2.toInputStream("nodes:\n first:\n")),
|
||||
new NodesFromYaml()).get();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
nodes:
|
||||
cluster-1:
|
||||
id: cluster-1
|
||||
description: xyz
|
||||
hostname: cluster-1.mydomain.com
|
||||
os_arch: x86
|
||||
os_family: rhel
|
||||
os_name: redhat
|
||||
os_version: 5.3
|
||||
group: hadoop
|
||||
tags:
|
||||
- vanilla
|
||||
username: myUser
|
||||
credential: ZmFuY3lmb290
|
||||
sudo_password: c3Vkbw==
|
||||
- id: cluster-1
|
||||
name: cluster-1
|
||||
description: xyz
|
||||
hostname: cluster-1.mydomain.com
|
||||
os_arch: x86
|
||||
os_family: rhel
|
||||
os_name: redhat
|
||||
os_version: 5.3
|
||||
group: hadoop
|
||||
tags:
|
||||
- vanilla
|
||||
username: myUser
|
||||
credential: ZmFuY3lmb290
|
||||
sudo_password: c3Vkbw==
|
||||
|
|
Loading…
Reference in New Issue