added loginPort to nodeMetadata, defaulting to port 22

This commit is contained in:
Adrian Cole 2010-10-26 10:24:49 -05:00
parent e5315d3348
commit 26eb27fdd0
3 changed files with 38 additions and 13 deletions

View File

@ -43,7 +43,7 @@ public interface NodeMetadata extends ComputeMetadata {
*
*/
String getTag();
/**
*
* The harware this node is running, if possible to determine.
@ -70,6 +70,17 @@ public interface NodeMetadata extends ComputeMetadata {
*/
NodeState getState();
/**
* @return the TCP port used for terminal connections. Generally, this is port 22 for ssh.
*/
int getLoginPort();
/**
* If possible, these are returned upon all detail requests. However, it is often the case that
* credentials are only available at "run" time.
*/
Credentials getCredentials();
/**
* All public IP addresses, potentially including shared ips.
*/
@ -80,10 +91,4 @@ public interface NodeMetadata extends ComputeMetadata {
*/
Set<String> getPrivateAddresses();
/**
* If possible, these are returned upon all detail requests. However, it is often the case that
* credentials are only available at "run" time.
*/
Credentials getCredentials();
}

View File

@ -45,6 +45,7 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder {
private Credentials credentials;
@Nullable
private String tag;
private int loginPort;
@Nullable
private String imageId;
@Nullable
@ -56,6 +57,11 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder {
super(ComputeType.NODE);
}
public NodeMetadataBuilder loginPort(int loginPort) {
this.loginPort = loginPort;
return this;
}
public NodeMetadataBuilder state(NodeState state) {
this.state = checkNotNull(state, "state");
return this;
@ -134,14 +140,14 @@ public class NodeMetadataBuilder extends ComputeMetadataBuilder {
@Override
public NodeMetadata build() {
return new NodeMetadataImpl(providerId, name, id, location, uri, userMetadata, tag, hardware, imageId, os, state,
publicAddresses, privateAddresses, credentials);
loginPort, publicAddresses, privateAddresses, credentials);
}
public static NodeMetadataBuilder fromNodeMetadata(NodeMetadata node) {
return new NodeMetadataBuilder().providerId(node.getProviderId()).name(node.getName()).id(node.getId())
.location(node.getLocation()).uri(node.getUri()).userMetadata(node.getUserMetadata()).tag(node.getTag())
.hardware(node.getHardware()).imageId(node.getImageId()).operatingSystem(node.getOperatingSystem())
.state(node.getState()).publicAddresses(node.getPublicAddresses())
.state(node.getState()).loginPort(node.getLoginPort()).publicAddresses(node.getPublicAddresses())
.privateAddresses(node.getPrivateAddresses()).credentials(node.getCredentials());
}

View File

@ -47,6 +47,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
private static final long serialVersionUID = 7924307572338157887L;
private final NodeState state;
private final int loginPort;
private final Set<String> publicAddresses;
private final Set<String> privateAddresses;
@Nullable
@ -62,7 +63,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
public NodeMetadataImpl(String providerId, String name, String id, Location location, URI uri,
Map<String, String> userMetadata, @Nullable String tag, @Nullable Hardware hardware, @Nullable String imageId,
@Nullable OperatingSystem os, NodeState state, Iterable<String> publicAddresses,
@Nullable OperatingSystem os, NodeState state, int loginPort, Iterable<String> publicAddresses,
Iterable<String> privateAddresses, @Nullable Credentials credentials) {
super(ComputeType.NODE, providerId, name, id, location, uri, userMetadata);
this.tag = tag;
@ -70,6 +71,7 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
this.imageId = imageId;
this.os = os;
this.state = checkNotNull(state, "state");
this.loginPort = loginPort;
this.publicAddresses = ImmutableSet.copyOf(checkNotNull(publicAddresses, "publicAddresses"));
this.privateAddresses = ImmutableSet.copyOf(checkNotNull(privateAddresses, "privateAddresses"));
this.credentials = credentials;
@ -123,6 +125,14 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
return state;
}
/**
* {@inheritDoc}
*/
@Override
public int getLoginPort() {
return this.loginPort;
}
/**
* {@inheritDoc}
*/
@ -143,15 +153,17 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
public String toString() {
return "[id=" + getId() + ", providerId=" + getProviderId() + ", tag=" + getTag() + ", name=" + getName()
+ ", location=" + getLocation() + ", uri=" + getUri() + ", imageId=" + getImageId() + ", os="
+ getOperatingSystem() + ", state=" + getState() + ", privateAddresses=" + privateAddresses
+ ", publicAddresses=" + publicAddresses + ", hardware=" + getHardware() + ", loginUser="
+ ((credentials != null) ? credentials.identity : null) + ", userMetadata=" + getUserMetadata() + "]";
+ getOperatingSystem() + ", state=" + getState() + ", loginPort=" + getLoginPort() + ", privateAddresses="
+ privateAddresses + ", publicAddresses=" + publicAddresses + ", hardware=" + getHardware()
+ ", loginUser=" + ((credentials != null) ? credentials.identity : null) + ", userMetadata="
+ getUserMetadata() + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + loginPort;
result = prime * result + ((privateAddresses == null) ? 0 : privateAddresses.hashCode());
result = prime * result + ((publicAddresses == null) ? 0 : publicAddresses.hashCode());
result = prime * result + ((tag == null) ? 0 : tag.hashCode());
@ -171,6 +183,8 @@ public class NodeMetadataImpl extends ComputeMetadataImpl implements NodeMetadat
if (getClass() != obj.getClass())
return false;
NodeMetadataImpl other = (NodeMetadataImpl) obj;
if (loginPort != other.loginPort)
return false;
if (privateAddresses == null) {
if (other.privateAddresses != null)
return false;