mirror of https://github.com/apache/jclouds.git
change to use vm -> node mapping
This commit is contained in:
parent
401d2f675f
commit
ef79f94e1d
|
@ -29,23 +29,19 @@ import org.jclouds.compute.predicates.ImagePredicates;
|
||||||
import org.jclouds.domain.Location;
|
import org.jclouds.domain.Location;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Link;
|
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Vm;
|
import org.jclouds.vcloud.director.v1_5.domain.Vm;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.section.VirtualHardwareSection;
|
import org.jclouds.vcloud.director.v1_5.domain.section.VirtualHardwareSection;
|
||||||
import org.jclouds.vcloud.director.v1_5.functions.SectionForVApp;
|
import org.jclouds.vcloud.director.v1_5.functions.SectionForVApp;
|
||||||
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
|
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Predicate;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.inject.name.Named;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class HardwareForVApp implements Function<VApp, Hardware> {
|
public class HardwareForVm implements Function<Vm, Hardware> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
@ -55,7 +51,7 @@ public class HardwareForVApp implements Function<VApp, Hardware> {
|
||||||
private final SectionForVApp<VirtualHardwareSection> findVirtualHardwareSectionForVm;
|
private final SectionForVApp<VirtualHardwareSection> findVirtualHardwareSectionForVm;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected HardwareForVApp(Function<Reference, Location> findLocationForResource,
|
protected HardwareForVm(Function<Reference, Location> findLocationForResource,
|
||||||
VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder,
|
VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder,
|
||||||
SectionForVApp<VirtualHardwareSection> findVirtualHardwareSectionForVm) {
|
SectionForVApp<VirtualHardwareSection> findVirtualHardwareSectionForVm) {
|
||||||
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
|
this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
|
||||||
|
@ -64,14 +60,13 @@ public class HardwareForVApp implements Function<VApp, Hardware> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Hardware apply(VApp from) {
|
public Hardware apply(Vm from) {
|
||||||
checkNotNull(from, "VApp");
|
checkNotNull(from, "VApp");
|
||||||
// TODO make this work with composite vApps
|
// TODO make this work with composite vApps
|
||||||
Vm vm = from.getChildren().getVms().size() == 0 ? null : Iterables.get(from.getChildren().getVms(), 0);
|
if (from == null)
|
||||||
if (vm == null)
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
VirtualHardwareSection hardware = findVirtualHardwareSectionForVm.apply(vm);
|
VirtualHardwareSection hardware = findVirtualHardwareSectionForVm.apply(from);
|
||||||
HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems());
|
HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems());
|
||||||
builder.location(findLocationForResource.apply(Iterables.find(checkNotNull(from, "from").getLinks(),
|
builder.location(findLocationForResource.apply(Iterables.find(checkNotNull(from, "from").getLinks(),
|
||||||
LinkPredicates.typeEquals(VCloudDirectorMediaType.VDC))));
|
LinkPredicates.typeEquals(VCloudDirectorMediaType.VDC))));
|
|
@ -21,9 +21,9 @@ package org.jclouds.vcloud.director.v1_5.compute.functions;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.google.common.base.Predicates.not;
|
import static com.google.common.base.Predicates.not;
|
||||||
import static com.google.common.collect.Iterables.filter;
|
import static com.google.common.collect.Iterables.filter;
|
||||||
import static org.jclouds.vcloud.director.v1_5.compute.util.VCloudComputeUtils.getCredentialsFrom;
|
import static org.jclouds.vcloud.director.v1_5.compute.util.VCloudDirectorComputeUtils.getCredentialsFrom;
|
||||||
import static org.jclouds.vcloud.director.v1_5.compute.util.VCloudComputeUtils.getIpsFromVApp;
|
import static org.jclouds.vcloud.director.v1_5.compute.util.VCloudDirectorComputeUtils.getIpsFromVm;
|
||||||
import static org.jclouds.vcloud.director.v1_5.compute.util.VCloudComputeUtils.toComputeOs;
|
import static org.jclouds.vcloud.director.v1_5.compute.util.VCloudDirectorComputeUtils.toComputeOs;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -42,7 +42,7 @@ import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
|
import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
|
||||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
|
import org.jclouds.vcloud.director.v1_5.domain.ResourceEntity.Status;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
import org.jclouds.vcloud.director.v1_5.domain.Vm;
|
||||||
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
|
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
|
||||||
|
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
|
@ -52,28 +52,28 @@ import com.google.common.collect.Iterables;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
|
public class VmToNodeMetadata implements Function<Vm, NodeMetadata> {
|
||||||
@Resource
|
@Resource
|
||||||
protected static Logger logger = Logger.NULL;
|
protected static Logger logger = Logger.NULL;
|
||||||
|
|
||||||
protected final FindLocationForResource findLocationForResourceInVDC;
|
protected final FindLocationForResource findLocationForResourceInVDC;
|
||||||
protected final Function<VApp, Hardware> hardwareForVApp;
|
protected final Function<Vm, Hardware> hardwareForVm;
|
||||||
protected final Map<Status, NodeState> vAppStatusToNodeState;
|
protected final Map<Status, NodeState> vAppStatusToNodeState;
|
||||||
protected final Map<String, Credentials> credentialStore;
|
protected final Map<String, Credentials> credentialStore;
|
||||||
protected final GroupNamingConvention nodeNamingConvention;
|
protected final GroupNamingConvention nodeNamingConvention;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
protected VAppToNodeMetadata(Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore,
|
protected VmToNodeMetadata(Map<Status, NodeState> vAppStatusToNodeState, Map<String, Credentials> credentialStore,
|
||||||
FindLocationForResource findLocationForResourceInVDC, Function<VApp, Hardware> hardwareForVApp,
|
FindLocationForResource findLocationForResourceInVDC, Function<Vm, Hardware> hardwareForVm,
|
||||||
GroupNamingConvention.Factory namingConvention) {
|
GroupNamingConvention.Factory namingConvention) {
|
||||||
this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
|
this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
|
||||||
this.hardwareForVApp = checkNotNull(hardwareForVApp, "hardwareForVApp");
|
this.hardwareForVm = checkNotNull(hardwareForVm, "hardwareForVm");
|
||||||
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
|
this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
|
||||||
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
this.credentialStore = checkNotNull(credentialStore, "credentialStore");
|
||||||
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
|
this.vAppStatusToNodeState = checkNotNull(vAppStatusToNodeState, "vAppStatusToNodeState");
|
||||||
}
|
}
|
||||||
|
|
||||||
public NodeMetadata apply(VApp from) {
|
public NodeMetadata apply(Vm from) {
|
||||||
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
NodeMetadataBuilder builder = new NodeMetadataBuilder();
|
||||||
builder.ids(from.getHref().toASCIIString());
|
builder.ids(from.getHref().toASCIIString());
|
||||||
builder.uri(from.getHref());
|
builder.uri(from.getHref());
|
||||||
|
@ -82,10 +82,10 @@ public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
|
||||||
builder.location(findLocationForResourceInVDC.apply(
|
builder.location(findLocationForResourceInVDC.apply(
|
||||||
Iterables.find(from.getLinks(), LinkPredicates.typeEquals(VCloudDirectorMediaType.VDC))));
|
Iterables.find(from.getLinks(), LinkPredicates.typeEquals(VCloudDirectorMediaType.VDC))));
|
||||||
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
|
builder.group(nodeNamingConvention.groupInUniqueNameOrNull(from.getName()));
|
||||||
builder.operatingSystem(toComputeOs(from, null));
|
builder.operatingSystem(toComputeOs(from));
|
||||||
builder.hardware(hardwareForVApp.apply(from));
|
builder.hardware(hardwareForVm.apply(from));
|
||||||
builder.state(vAppStatusToNodeState.get(from.getStatus()));
|
builder.state(vAppStatusToNodeState.get(from.getStatus()));
|
||||||
Set<String> addresses = getIpsFromVApp(from);
|
Set<String> addresses = getIpsFromVm(from);
|
||||||
builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
|
builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
|
||||||
builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
|
builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
|
||||||
|
|
|
@ -48,7 +48,7 @@ import com.google.inject.Inject;
|
||||||
*
|
*
|
||||||
* @author danikov
|
* @author danikov
|
||||||
*/
|
*/
|
||||||
public class VCloudComputeUtils {
|
public class VCloudDirectorComputeUtils {
|
||||||
|
|
||||||
public static OperatingSystem toComputeOs(VApp vApp, OperatingSystem defaultOs) {
|
public static OperatingSystem toComputeOs(VApp vApp, OperatingSystem defaultOs) {
|
||||||
CIMOperatingSystem cimOs = toComputeOs(vApp);
|
CIMOperatingSystem cimOs = toComputeOs(vApp);
|
||||||
|
@ -109,8 +109,11 @@ public class VCloudComputeUtils {
|
||||||
// TODO make this work with composite vApps
|
// TODO make this work with composite vApps
|
||||||
if (vApp.getChildren().getVms().size() == 0)
|
if (vApp.getChildren().getVms().size() == 0)
|
||||||
return ImmutableSet.of();
|
return ImmutableSet.of();
|
||||||
|
return getIpsFromVm(Iterables.get(vApp.getChildren().getVms(), 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Set<String> getIpsFromVm(Vm vm) {
|
||||||
Builder<String> ips = ImmutableSet.builder();
|
Builder<String> ips = ImmutableSet.builder();
|
||||||
Vm vm = Iterables.get(vApp.getChildren().getVms(), 0);
|
|
||||||
// TODO: figure out how to differentiate public from private ip addresses
|
// TODO: figure out how to differentiate public from private ip addresses
|
||||||
// assumption is that we'll do this from the network object, which may
|
// assumption is that we'll do this from the network object, which may
|
||||||
// have
|
// have
|
||||||
|
@ -119,7 +122,7 @@ public class VCloudComputeUtils {
|
||||||
// parsing. At worst, we could have properties set per cloud provider to
|
// parsing. At worst, we could have properties set per cloud provider to
|
||||||
// declare the networks which are public, then check against these in
|
// declare the networks which are public, then check against these in
|
||||||
// networkconnection.getNetwork
|
// networkconnection.getNetwork
|
||||||
NetworkConnectionSection networkConnectionSection = findNetworkConnectionSectionForVApp.apply(vApp);
|
NetworkConnectionSection networkConnectionSection = findNetworkConnectionSectionForVApp.apply(vm);
|
||||||
if (networkConnectionSection != null) {
|
if (networkConnectionSection != null) {
|
||||||
for (NetworkConnection connection : networkConnectionSection.getNetworkConnections()) {
|
for (NetworkConnection connection : networkConnectionSection.getNetworkConnections()) {
|
||||||
if (connection.getIpAddress() != null)
|
if (connection.getIpAddress() != null)
|
||||||
|
@ -128,7 +131,7 @@ public class VCloudComputeUtils {
|
||||||
ips.add(connection.getExternalIpAddress());
|
ips.add(connection.getExternalIpAddress());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (ResourceAllocationSettingData net : filter(findVirtualHardwareSectionForVApp.apply(vApp).getItems(),
|
for (ResourceAllocationSettingData net : filter(findVirtualHardwareSectionForVApp.apply(vm).getItems(),
|
||||||
CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) {
|
CIMPredicates.resourceTypeIn(ResourceType.ETHERNET_ADAPTER))) {
|
||||||
// FIXME: not yet implemented
|
// FIXME: not yet implemented
|
||||||
// if (net instanceof VCloudNetworkAdapter) {
|
// if (net instanceof VCloudNetworkAdapter) {
|
|
@ -43,7 +43,7 @@ import org.jclouds.rest.internal.RestContextImpl;
|
||||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient;
|
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient;
|
||||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient;
|
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient;
|
||||||
import org.jclouds.vcloud.director.v1_5.annotations.Login;
|
import org.jclouds.vcloud.director.v1_5.annotations.Login;
|
||||||
import org.jclouds.vcloud.director.v1_5.compute.util.VCloudComputeUtils;
|
import org.jclouds.vcloud.director.v1_5.compute.util.VCloudDirectorComputeUtils;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.Session;
|
import org.jclouds.vcloud.director.v1_5.domain.Session;
|
||||||
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
|
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
|
||||||
import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncClient;
|
import org.jclouds.vcloud.director.v1_5.features.CatalogAsyncClient;
|
||||||
|
@ -174,7 +174,7 @@ public class VCloudDirectorRestClientModule extends RestClientModule<VCloudDirec
|
||||||
|
|
||||||
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(InvalidateSessionAndRetryOn401AndLogoutOnClose.class);
|
bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(InvalidateSessionAndRetryOn401AndLogoutOnClose.class);
|
||||||
|
|
||||||
requestStaticInjection(VCloudComputeUtils.class);
|
requestStaticInjection(VCloudDirectorComputeUtils.class);
|
||||||
|
|
||||||
super.configure();
|
super.configure();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue