Skip to content

Commit

Permalink
Modify NodeEntryImpl to use attributes map for all data
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Jun 10, 2011
1 parent d05e924 commit 33986d3
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class NodeBaseImpl implements INodeBase {

}
NodeBaseImpl(final String nodename) {
this.nodename = nodename;
setNodename(nodename);
}

public String getNodename() {
Expand Down
108 changes: 57 additions & 51 deletions core/src/java/com/dtolabs/rundeck/core/common/NodeEntryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
*/
package com.dtolabs.rundeck.core.common;

import java.util.*;
import java.lang.reflect.InvocationTargetException;
import com.dtolabs.rundeck.core.utils.StringArrayUtil;

import org.apache.commons.beanutils.BeanUtils;
import java.util.*;


/**
Expand All @@ -39,34 +38,31 @@ public class NodeEntryImpl extends NodeBaseImpl implements INodeEntry, INodeDesc

protected static final String USER_AT_HOSTNAME_REGEX = "([^@])+@([^@:])+";
protected static final String PORT_REGEX = "([^:]+):([0-9]+)";
public static final String OS_NAME = "os-name";
public static final String OS_FAMILY = "os-family";
public static final String OS_VERSION = "os-version";
public static final String HOSTNAME = "hostname";
public static final String OS_ARCH = "os-arch";
public static final String USERNAME = "username";
public static final String DESCRIPTION = "description";
public static final String NAME = "name";
public static final String TAGS = "tags";

private Set tags;
private String osName;
private String osArch;
private String osFamily;
private String osVersion;
private String hostname;
private String description;

private Map<String, String> attributes;

public NodeEntryImpl() {
super();
this.tags = new HashSet();
this.attributes = new HashMap<String, String>();
}

public NodeEntryImpl(String nodename) {
super(nodename);
this.tags = new HashSet();
}

private static String notNull(String in) {
if (null == in) {
return "";
}
return in;
public NodeEntryImpl(final String nodename) {
this();
setNodename(nodename);
}


/**
* Create a NodeEntryImpl with hostname and nodename
*
Expand All @@ -75,7 +71,7 @@ private static String notNull(String in) {
*/
public NodeEntryImpl(final String hostname, final String nodename) {
this(nodename);
this.hostname = hostname;
setHostname(hostname);
}

public static INodeEntry create(final String hostname, final String nodename) {
Expand All @@ -86,78 +82,87 @@ public static INodeEntry create(final INodeDesc node) {
return new NodeEntryImpl(node.getHostname(), node.getNodename());
}

@Override
public void setNodename(final String nodename) {
super.setNodename(nodename);
getAttributes().put(NAME, nodename);
}

public Set getTags() {
return tags;
}

public void setTags(final Set tags) {
this.tags = tags;
final Object[] objects = tags.toArray();
Arrays.sort(objects);
getAttributes().put(TAGS, StringArrayUtil.asString(objects, ","));
}

public String getOsName() {
return osName;
return getAttributes().get(OS_NAME);
}


public void setOsName(final String osName) {
this.osName = osName;
getAttributes().put(OS_NAME, osName);
}

public String getOsFamily() {
return osFamily;
return getAttributes().get(OS_FAMILY);
}

public void setOsFamily(final String osFamily) {
this.osFamily = osFamily;
getAttributes().put(OS_FAMILY, osFamily);
}

public String getOsVersion() {
return osVersion;
return getAttributes().get(OS_VERSION);
}

public void setOsVersion(final String osVersion) {
this.osVersion = osVersion;
getAttributes().put(OS_VERSION, osVersion);
}

public String getHostname() {
return hostname;
return getAttributes().get(HOSTNAME);
}

public void setHostname(String hostname) {
this.hostname = hostname;
public void setHostname(final String hostname) {
getAttributes().put(HOSTNAME, hostname);
}

public String getOsArch() {
return osArch;
return getAttributes().get(OS_ARCH);
}

public void setOsArch(final String osArch) {
this.osArch = osArch;
getAttributes().put(OS_ARCH, osArch);
}

private String username;

public String getUsername() {
return username;
return getAttributes().get(USERNAME);
}

public void setUsername(final String username) {
this.username = username;
getAttributes().put(USERNAME, username);
}


public boolean equals(final INodeDesc node) {
return nodename.equals(node.getNodename());
return getNodename().equals(node.getNodename());
}


public String toString() {
return "NodeEntryImpl{" +
"nodename=" + nodename +
",hostname=" + hostname +
",osName=" + osName +
",osArch=" + osArch +
",osFamily=" + osFamily +
",osVersion=" + osVersion +
",username=" + username +
"nodename=" + getNodename() +
",hostname=" + getHostname() +
",osName=" + getOsName() +
",osArch=" + getOsArch() +
",osFamily=" + getOsFamily() +
",osVersion=" + getOsVersion() +
",username=" + getUsername() +
",tags=" + tags +
",attributes=" + attributes +
"}";
Expand Down Expand Up @@ -198,10 +203,11 @@ public String extractUserName(final String hostname) {
* @return Gets the username for remote connections
*/
public String extractUserName() {
final String username = getUsername();
if (null != username && !"".equals(username)) {
return username;
}
return extractUserName(hostname);
return extractUserName(getHostname());
}

public static String extractHostname(final String host) {
Expand All @@ -218,11 +224,11 @@ public static String extractHostname(final String host) {
}

public String extractHostname() {
return extractHostname(hostname);
return extractHostname(getHostname());
}

public String extractPort() {
return extractPort(hostname);
return extractPort(getHostname());
}

public static String extractPort(final String host) {
Expand All @@ -234,7 +240,7 @@ public static String extractPort(final String host) {
}

public boolean containsPort() {
return containsPort(hostname);
return containsPort(getHostname());
}

/**
Expand Down Expand Up @@ -271,15 +277,15 @@ public Map<String, String> getAttributes() {
return attributes;
}

public void setAttributes(Map<String, String> attributes) {
public void setAttributes(final Map<String, String> attributes) {
this.attributes = attributes;
}

public void setDescription(final String description) {
this.description = description;
getAttributes().put(DESCRIPTION, description);
}

public String getDescription() {
return description;
return getAttributes().get(DESCRIPTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ public void testShouldOutputEditUrl() throws Exception{
final NodeEntryImpl nodeEntry = new NodeEntryImpl();
nodeEntry.setNodename("strongbad");
nodeEntry.setHostname("strongbad");
nodeEntry.setAttributes(new HashMap<String, String>());
nodeEntry.getAttributes().put("editUrl","http://some.com/test/url");

nodesYamlGenerator.addNode(nodeEntry);
Expand All @@ -275,7 +274,7 @@ public void testShouldOutputRemoteUrl() throws Exception{
final NodeEntryImpl nodeEntry = new NodeEntryImpl();
nodeEntry.setNodename("strongbad");
nodeEntry.setHostname("strongbad");
nodeEntry.setAttributes(new HashMap<String, String>());

nodeEntry.getAttributes().put("remoteUrl", "http://somez.com/test/other/url");

nodesYamlGenerator.addNode(nodeEntry);
Expand All @@ -300,7 +299,7 @@ public void testShouldOutputAnyAttribtue() throws Exception{
final NodeEntryImpl nodeEntry = new NodeEntryImpl();
nodeEntry.setNodename("strongbad");
nodeEntry.setHostname("strongbad");
nodeEntry.setAttributes(new HashMap<String, String>());

nodeEntry.getAttributes().put("test-attribute", "some value");

nodesYamlGenerator.addNode(nodeEntry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,7 @@ public void testRoundtripObjToObj() throws Exception {
//set properties that should not be serialized: type, frameworkProject, settings, attributes
node.setFrameworkProject("my project");

final HashMap<String, String> dummy = new HashMap<String, String>();
dummy.put("a", "b");
node.setAttributes(dummy);
node.getAttributes().put("a", "b");



Expand Down
16 changes: 6 additions & 10 deletions core/src/test/com/dtolabs/rundeck/core/utils/TestNodeSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,9 @@ protected void setUp() throws Exception {
tags2.add("devenv");
tags2.add("workstation");
nodeimp2.setTags(tags2);
HashMap<String, String> attrs2 = new HashMap<String, String>();
attrs2.put("testattribute1", "testvalue1");
attrs2.put("testattribute2", "testvalue2");
attrs2.put("testattribute3", "testvalue3");
nodeimp2.setAttributes(attrs2);
nodeimp2.getAttributes().put("testattribute1", "testvalue1");
nodeimp2.getAttributes().put("testattribute2", "testvalue2");
nodeimp2.getAttributes().put("testattribute3", "testvalue3");

nodeimp3 = new NodeEntryImpl("testnode3.local", "testnode3");
nodeimp3.setOsArch("intel");
Expand All @@ -87,11 +85,9 @@ protected void setUp() throws Exception {
tags3.add("priority1");
tags3.add("workstation");
nodeimp3.setTags(tags3);
HashMap<String, String> attrs3 = new HashMap<String, String>();
attrs3.put("testattribute1", "testvalue1");
attrs3.put("testattribute2", "testvalue2redux");
attrs3.put("testattribute4", "testvalue5");
nodeimp3.setAttributes(attrs3);
nodeimp3.getAttributes().put("testattribute1", "testvalue1");
nodeimp3.getAttributes().put("testattribute2", "testvalue2redux");
nodeimp3.getAttributes().put("testattribute4", "testvalue5");
}

protected void tearDown() throws Exception {
Expand Down

0 comments on commit 33986d3

Please sign in to comment.