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