mirror of https://github.com/apache/jclouds.git
Merge pull request #434 from mattstep/master
Changes to the nova compute service nodemetadata to server function
This commit is contained in:
commit
3ccea7282b
|
@ -22,12 +22,9 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.jclouds.compute.domain.NodeMetadata;
|
import org.jclouds.compute.domain.NodeMetadata;
|
||||||
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
import org.jclouds.compute.domain.NodeMetadataBuilder;
|
||||||
import org.jclouds.compute.domain.NodeState;
|
|
||||||
import org.jclouds.openstack.nova.v1_1.domain.Address;
|
import org.jclouds.openstack.nova.v1_1.domain.Address;
|
||||||
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
import org.jclouds.openstack.nova.v1_1.domain.Server;
|
||||||
import org.jclouds.openstack.nova.v1_1.domain.ServerStatus;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
@ -40,21 +37,6 @@ import com.google.common.collect.Iterables;
|
||||||
public class ServerToNodeMetadata implements Function<Server, NodeMetadata>
|
public class ServerToNodeMetadata implements Function<Server, NodeMetadata>
|
||||||
{
|
{
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
public static final Map<ServerStatus, NodeState> serverToNodeState = ImmutableMap.<ServerStatus, NodeState>builder()
|
|
||||||
.put(ServerStatus.ACTIVE, NodeState.RUNNING)
|
|
||||||
.put(ServerStatus.SUSPENDED, NodeState.SUSPENDED)
|
|
||||||
.put(ServerStatus.DELETED, NodeState.TERMINATED)
|
|
||||||
.put(ServerStatus.RESIZE, NodeState.PENDING)
|
|
||||||
.put(ServerStatus.VERIFY_RESIZE, NodeState.PENDING)
|
|
||||||
.put(ServerStatus.BUILD, NodeState.PENDING)
|
|
||||||
.put(ServerStatus.PASSWORD, NodeState.PENDING)
|
|
||||||
.put(ServerStatus.REBUILD, NodeState.PENDING)
|
|
||||||
.put(ServerStatus.REBOOT, NodeState.PENDING)
|
|
||||||
.put(ServerStatus.HARD_REBOOT, NodeState.PENDING)
|
|
||||||
.put(ServerStatus.UNKNOWN, NodeState.UNRECOGNIZED)
|
|
||||||
.put(ServerStatus.UNRECOGNIZED, NodeState.UNRECOGNIZED).build();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NodeMetadata apply(Server server)
|
public NodeMetadata apply(Server server)
|
||||||
{
|
{
|
||||||
|
@ -66,6 +48,7 @@ public class ServerToNodeMetadata implements Function<Server, NodeMetadata>
|
||||||
.publicAddresses(Iterables.transform(server.getPublicAddresses(), new AddressToStringTransformationFunction()))
|
.publicAddresses(Iterables.transform(server.getPublicAddresses(), new AddressToStringTransformationFunction()))
|
||||||
.privateAddresses(Iterables.transform(server.getPrivateAddresses(), new AddressToStringTransformationFunction()))
|
.privateAddresses(Iterables.transform(server.getPrivateAddresses(), new AddressToStringTransformationFunction()))
|
||||||
.state(server.getStatus().getNodeState())
|
.state(server.getStatus().getNodeState())
|
||||||
|
.userMetadata(ImmutableMap.copyOf(server.getMetadata()))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
package org.jclouds.openstack.nova.v1_1.compute.functions;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNotNull;
|
import static org.testng.Assert.assertNotNull;
|
||||||
|
|
||||||
|
@ -47,6 +49,7 @@ public class ServerToNodeMetadataTest
|
||||||
.privateAddresses(Address.createV4("10.0.0.1"))
|
.privateAddresses(Address.createV4("10.0.0.1"))
|
||||||
.publicAddresses(Address.createV4("1.0.1.1"))
|
.publicAddresses(Address.createV4("1.0.1.1"))
|
||||||
.status(ServerStatus.ACTIVE)
|
.status(ServerStatus.ACTIVE)
|
||||||
|
.metadata(ImmutableMap.of("test", "testing"))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
ServerToNodeMetadata converter = new ServerToNodeMetadata();
|
ServerToNodeMetadata converter = new ServerToNodeMetadata();
|
||||||
|
@ -65,5 +68,9 @@ public class ServerToNodeMetadataTest
|
||||||
assertNotNull(convertedNodeMetadata.getPublicAddresses());
|
assertNotNull(convertedNodeMetadata.getPublicAddresses());
|
||||||
assertEquals(convertedNodeMetadata.getPublicAddresses().size(), 1);
|
assertEquals(convertedNodeMetadata.getPublicAddresses().size(), 1);
|
||||||
assertEquals(convertedNodeMetadata.getPublicAddresses().iterator().next(), "1.0.1.1");
|
assertEquals(convertedNodeMetadata.getPublicAddresses().iterator().next(), "1.0.1.1");
|
||||||
|
|
||||||
|
assertNotNull(convertedNodeMetadata.getUserMetadata());
|
||||||
|
assertEquals(convertedNodeMetadata.getUserMetadata().size(), 1);
|
||||||
|
assertEquals(convertedNodeMetadata.getUserMetadata().get("test"),"testing");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue