You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ra...@apache.org on 2014/11/25 16:39:42 UTC
[17/18] stratos git commit: Jclouds vcloud api 1.8.1 clone with
custom changes
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindGuestCustomizationSectionToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindGuestCustomizationSectionToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindGuestCustomizationSectionToXmlPayload.java
new file mode 100644
index 0000000..3ba51d1
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindGuestCustomizationSectionToXmlPayload.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
+
+import java.util.Properties;
+
+import javax.annotation.Resource;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.logging.Logger;
+import org.jclouds.rest.binders.BindToStringPayload;
+import org.jclouds.vcloud.domain.GuestCustomizationSection;
+
+import com.google.common.base.Throwables;
+import com.google.inject.Inject;
+import com.jamesmurty.utils.XMLBuilder;
+
+@Singleton
+public class BindGuestCustomizationSectionToXmlPayload extends BindToStringPayload {
+ @Resource
+ protected Logger logger = Logger.NULL;
+
+ protected final String ns;
+ protected final String schema;
+
+ @Inject
+ public BindGuestCustomizationSectionToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
+ this.ns = ns;
+ this.schema = schema;
+ }
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
+ checkArgument(checkNotNull(payload, "GuestCustomizationSection") instanceof GuestCustomizationSection,
+ "this binder is only valid for GuestCustomizationSection!");
+ GuestCustomizationSection guest = GuestCustomizationSection.class.cast(payload);
+ XMLBuilder guestCustomizationSection;
+ try {
+ guestCustomizationSection = XMLBuilder.create("GuestCustomizationSection").a("xmlns", ns).a("xmlns:ovf",
+ "http://schemas.dmtf.org/ovf/envelope/1").a("type", guest.getType()).a("href",
+ guest.getHref().toASCIIString()).a("ovf:required", "false");
+ guestCustomizationSection.e("ovf:Info").t(guest.getInfo());
+
+ if (guest.isEnabled() != null)
+ guestCustomizationSection.e("Enabled").t(guest.isEnabled().toString());
+ if (guest.shouldChangeSid() != null)
+ guestCustomizationSection.e("ChangeSid").t(guest.shouldChangeSid().toString());
+ if (guest.getVirtualMachineId() != null)
+ guestCustomizationSection.e("VirtualMachineId").t(guest.getVirtualMachineId().toString());
+ if (guest.isJoinDomainEnabled() != null)
+ guestCustomizationSection.e("JoinDomainEnabled").t(guest.isJoinDomainEnabled().toString());
+ if (guest.shouldUseOrgSettings() != null)
+ guestCustomizationSection.e("UseOrgSettings").t(guest.shouldUseOrgSettings().toString());
+ if (guest.getDomainName() != null)
+ guestCustomizationSection.e("DomainName").t(guest.getDomainName().toString());
+ if (guest.getDomainUserName() != null)
+ guestCustomizationSection.e("DomainUserName").t(guest.getDomainUserName().toString());
+ if (guest.getDomainUserPassword() != null)
+ guestCustomizationSection.e("DomainUserPassword").t(guest.getDomainUserPassword().toString());
+ if (guest.isAdminPasswordEnabled() != null)
+ guestCustomizationSection.e("AdminPasswordEnabled").t(guest.isAdminPasswordEnabled().toString());
+ if (guest.isAdminPasswordAuto() != null)
+ guestCustomizationSection.e("AdminPasswordAuto").t(guest.isAdminPasswordAuto().toString());
+ // if (guest.getAdminPassword() != null)
+ // guestCustomizationSection.e("AdminPassword").t(guest.getAdminPassword().toString());
+ if (guest.isResetPasswordRequired() != null)
+ guestCustomizationSection.e("ResetPasswordRequired").t(guest.isResetPasswordRequired().toString());
+ if (guest.getCustomizationScript() != null)
+ guestCustomizationSection.e("CustomizationScript").t(guest.getCustomizationScript());
+ if (guest.getComputerName() != null)
+ guestCustomizationSection.e("ComputerName").t(guest.getComputerName().toString());
+ if (guest.getEdit() != null)
+ guestCustomizationSection.e("Link").a("rel", "edit").a("type", guest.getType()).a("href",
+ guest.getHref().toASCIIString());
+
+ Properties outputProperties = new Properties();
+ outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
+ request = super.bindToRequest(request, guestCustomizationSection.asString(outputProperties));
+ request.getPayload().getContentMetadata().setContentType(guest.getType());
+ } catch (Exception e) {
+ Throwables.propagate(e);
+ }
+ return request;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java
new file mode 100644
index 0000000..08e5443
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindInstantiateVAppTemplateParamsToXmlPayload.java
@@ -0,0 +1,216 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.collect.Iterables.transform;
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.rest.binders.BindToStringPayload;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.domain.VAppTemplate;
+import org.jclouds.vcloud.domain.Vm;
+import org.jclouds.vcloud.domain.network.FenceMode;
+import org.jclouds.vcloud.domain.network.NetworkConfig;
+import org.jclouds.vcloud.endpoints.Network;
+import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
+import com.google.common.base.Supplier;
+import com.google.common.cache.LoadingCache;
+import com.google.common.collect.ImmutableSet;
+import com.jamesmurty.utils.XMLBuilder;
+
+@Singleton
+public class BindInstantiateVAppTemplateParamsToXmlPayload implements MapBinder {
+
+ protected final String ns;
+ protected final String schema;
+ protected final BindToStringPayload stringBinder;
+ protected final Supplier<ReferenceType> defaultNetwork;
+ protected final FenceMode defaultFenceMode;
+ protected final LoadingCache<URI, VAppTemplate> templateCache;
+ protected final Function<VAppTemplate, String> defaultNetworkNameInTemplate;
+
+ @Inject
+ public BindInstantiateVAppTemplateParamsToXmlPayload(LoadingCache<URI, VAppTemplate> templateCache,
+ @Network Function<VAppTemplate, String> defaultNetworkNameInTemplate, BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema,
+ @Network Supplier<ReferenceType> network, FenceMode fenceMode) {
+ this.templateCache = templateCache;
+ this.defaultNetworkNameInTemplate = defaultNetworkNameInTemplate;
+ this.ns = ns;
+ this.schema = schema;
+ this.stringBinder = stringBinder;
+ this.defaultNetwork = network;
+ this.defaultFenceMode = fenceMode;
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
+ checkArgument(checkNotNull(request, "request") instanceof GeneratedHttpRequest,
+ "this binder is only valid for GeneratedHttpRequests!");
+ GeneratedHttpRequest gRequest = (GeneratedHttpRequest) request;
+ String name = checkNotNull(postParams.remove("name"), "name").toString();
+ URI template = URI.create(checkNotNull(postParams.remove("template"), "template").toString());
+
+ Set<NetworkConfig> networkConfig = null;
+
+ NetworkConfigDecorator networkConfigDecorator = new NetworkConfigDecorator(templateCache.getUnchecked(template),
+ defaultNetwork.get().getHref(), defaultFenceMode, defaultNetworkNameInTemplate);
+
+ InstantiateVAppTemplateOptions options = findOptionsInArgsOrNull(gRequest);
+
+ if (options != null) {
+ if (options.getNetworkConfig().size() > 0)
+ networkConfig = ImmutableSet
+ .copyOf(transform(options.getNetworkConfig(), networkConfigDecorator));
+ } else {
+ options = new InstantiateVAppTemplateOptions();
+ }
+
+ if (networkConfig == null)
+ networkConfig = ImmutableSet.of(networkConfigDecorator.apply(null));
+
+ try {
+ return stringBinder.bindToRequest(request, generateXml(name, options.getDescription(), options.shouldDeploy(),
+ options.shouldPowerOn(), template, networkConfig));
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ } catch (FactoryConfigurationError e) {
+ throw new RuntimeException(e);
+ } catch (TransformerException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ @VisibleForTesting
+ Set<Vm> ifCustomizationScriptIsSetGetVmsInTemplate(String customizationScript, final URI template) {
+ Set<Vm> vms = ImmutableSet.of();
+ if (customizationScript != null) {
+ VAppTemplate vAppTemplate = templateCache.getUnchecked(template);
+ checkArgument(vAppTemplate != null, "vAppTemplate %s not found!", template);
+ vms = vAppTemplate.getChildren();
+ checkArgument(vms.size() > 0, "no vms found in vAppTemplate %s", vAppTemplate);
+ }
+ return vms;
+ }
+
+ protected static final class NetworkConfigDecorator implements Function<NetworkConfig, NetworkConfig> {
+ private final VAppTemplate template;
+ private final URI defaultNetwork;
+ private final FenceMode defaultFenceMode;
+ private final Function<VAppTemplate, String> defaultNetworkNameInTemplate;
+
+ protected NetworkConfigDecorator(VAppTemplate template, URI defaultNetwork, FenceMode defaultFenceMode,
+ Function<VAppTemplate, String> defaultNetworkNameInTemplate) {
+ this.template = checkNotNull(template, "template");
+ this.defaultNetwork = checkNotNull(defaultNetwork, "defaultNetwork");
+ this.defaultFenceMode = checkNotNull(defaultFenceMode, "defaultFenceMode");
+ this.defaultNetworkNameInTemplate = checkNotNull(defaultNetworkNameInTemplate, "defaultNetworkNameInTemplate");
+ }
+
+ @Override
+ public NetworkConfig apply(NetworkConfig from) {
+ if (from == null)
+ return new NetworkConfig(defaultNetworkNameInTemplate.apply(template), defaultNetwork, defaultFenceMode);
+ URI network = ifNullDefaultTo(from.getParentNetwork(), defaultNetwork);
+ FenceMode fenceMode = ifNullDefaultTo(from.getFenceMode(), defaultFenceMode);
+ // using conditional statement instead of ifNullDefaultTo so that we lazy invoke the
+ // function, as it is an expensive one.
+ String networkName = from.getNetworkName() != null ? from.getNetworkName() : defaultNetworkNameInTemplate
+ .apply(template);
+ return new NetworkConfig(networkName, network, fenceMode);
+ }
+ }
+
+ protected String generateXml(String name, @Nullable String description, boolean deploy, boolean powerOn,
+ URI template, Iterable<NetworkConfig> networkConfig)
+ throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
+ XMLBuilder rootBuilder = buildRoot(name).a("deploy", deploy + "").a("powerOn", powerOn + "");
+ if (description != null)
+ rootBuilder.e("Description").t(description);
+ XMLBuilder instantiationParamsBuilder = rootBuilder.e("InstantiationParams");
+ addNetworkConfig(instantiationParamsBuilder, networkConfig);
+ rootBuilder.e("Source").a("href", template.toASCIIString());
+ rootBuilder.e("AllEULAsAccepted").t("true");
+
+ Properties outputProperties = new Properties();
+ outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
+ return rootBuilder.asString(outputProperties);
+ }
+
+ protected void addNetworkConfig(XMLBuilder instantiationParamsBuilder,
+ Iterable<NetworkConfig> networkConfig) {
+ XMLBuilder networkConfigBuilder = instantiationParamsBuilder.e("NetworkConfigSection");
+ networkConfigBuilder.e("ovf:Info").t("Configuration parameters for logical networks");
+ for (NetworkConfig n : networkConfig) {
+ XMLBuilder configurationBuilder = networkConfigBuilder.e("NetworkConfig").a("networkName", n.getNetworkName())
+ .e("Configuration");
+ configurationBuilder.e("ParentNetwork").a("href", n.getParentNetwork().toASCIIString());
+ if (n.getFenceMode() != null) {
+ configurationBuilder.e("FenceMode").t(n.getFenceMode().toString());
+ }
+ }
+ }
+
+ protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
+ return XMLBuilder.create("InstantiateVAppTemplateParams").a("name", name).a("xmlns", ns)
+ .a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1");
+ }
+
+ protected InstantiateVAppTemplateOptions findOptionsInArgsOrNull(GeneratedHttpRequest gRequest) {
+ for (Object arg : gRequest.getInvocation().getArgs()) {
+ if (arg instanceof InstantiateVAppTemplateOptions) {
+ return (InstantiateVAppTemplateOptions) arg;
+ } else if (arg instanceof InstantiateVAppTemplateOptions[]) {
+ InstantiateVAppTemplateOptions[] options = (InstantiateVAppTemplateOptions[]) arg;
+ return (options.length > 0) ? options[0] : null;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalStateException("InstantiateVAppTemplateParams is needs parameters");
+ }
+
+ public static <T> T ifNullDefaultTo(T value, T defaultValue) {
+ return value != null ? value : checkNotNull(defaultValue, "defaultValue");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindMemoryToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindMemoryToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindMemoryToXmlPayload.java
new file mode 100644
index 0000000..e6a1cd4
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindMemoryToXmlPayload.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
+
+import java.util.Properties;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.cim.ResourceAllocationSettingData.ResourceType;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.binders.BindToStringPayload;
+
+import com.google.common.base.Throwables;
+import com.google.inject.Inject;
+import com.jamesmurty.utils.XMLBuilder;
+
+@Singleton
+public class BindMemoryToXmlPayload extends BindToStringPayload {
+ protected final String ns;
+ protected final String schema;
+
+ @Inject
+ public BindMemoryToXmlPayload(BindToStringPayload stringBinder, @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns,
+ @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
+ this.ns = ns;
+ this.schema = schema;
+ }
+
+ private static final String RESOURCE_ALLOCATION_NS = "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData";
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
+ checkArgument(checkNotNull(payload, "memoryInMB") instanceof Integer, "this binder is only valid for Integers!");
+ Integer memoryInMB = Integer.class.cast(payload);
+ XMLBuilder cpuItem;
+ try {
+ cpuItem = XMLBuilder.create("Item").a("xmlns", ns).a("xmlns:rasd", RESOURCE_ALLOCATION_NS);
+ cpuItem.e("rasd:AllocationUnits").t("byte * 2^20");
+ cpuItem.e("rasd:Description").t("Memory Size");
+ cpuItem.e("rasd:ElementName").t(memoryInMB.toString() + " MB of memory");
+ cpuItem.e("rasd:InstanceID").t("5");
+ cpuItem.e("rasd:Reservation").t("0");
+ cpuItem.e("rasd:ResourceType").t(ResourceType.MEMORY.value());
+ cpuItem.e("rasd:VirtualQuantity").t(memoryInMB.toString());
+ cpuItem.e("rasd:Weight").t("0");
+ Properties outputProperties = new Properties();
+ outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
+ request = super.bindToRequest(request, cpuItem.asString(outputProperties));
+ } catch (Exception e) {
+ Throwables.propagate(e);
+ }
+ return request;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayload.java
new file mode 100644
index 0000000..6a27725
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindNetworkConnectionSectionToXmlPayload.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
+
+import java.util.Properties;
+
+import javax.annotation.Resource;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.logging.Logger;
+import org.jclouds.rest.binders.BindToStringPayload;
+import org.jclouds.vcloud.domain.NetworkConnection;
+import org.jclouds.vcloud.domain.NetworkConnectionSection;
+
+import com.google.common.base.Throwables;
+import com.google.inject.Inject;
+import com.jamesmurty.utils.XMLBuilder;
+
+@Singleton
+public class BindNetworkConnectionSectionToXmlPayload extends BindToStringPayload {
+ @Resource
+ protected Logger logger = Logger.NULL;
+
+ protected final String ns;
+ protected final String schema;
+
+ @Inject
+ public BindNetworkConnectionSectionToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
+ this.ns = ns;
+ this.schema = schema;
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object payload) {
+ checkArgument(checkNotNull(payload, "NetworkConnectionSection") instanceof NetworkConnectionSection,
+ "this binder is only valid for NetworkConnectionSection!");
+ NetworkConnectionSection net = NetworkConnectionSection.class.cast(payload);
+ XMLBuilder networkConnectionSection;
+ try {
+ networkConnectionSection = XMLBuilder.create("NetworkConnectionSection").a("xmlns", ns)
+ .a("xmlns:ovf", "http://schemas.dmtf.org/ovf/envelope/1").a("type", net.getType())
+ .a("href", net.getHref().toASCIIString()).a("ovf:required", "false");
+ networkConnectionSection.e("ovf:Info").t(net.getInfo());
+
+ if (net.getPrimaryNetworkConnectionIndex() != null)
+ networkConnectionSection.e("PrimaryNetworkConnectionIndex").t(
+ net.getPrimaryNetworkConnectionIndex().toString());
+ for (NetworkConnection networkConnection : net.getConnections()) {
+ XMLBuilder networkConnectionSectionChild = networkConnectionSection.e("NetworkConnection").a("network",
+ networkConnection.getNetwork());
+ networkConnectionSectionChild.e("NetworkConnectionIndex").t(
+ networkConnection.getNetworkConnectionIndex() + "");
+ if (networkConnection.getExternalIpAddress() != null)
+ networkConnectionSectionChild.e("ExternalIpAddress").t(networkConnection.getExternalIpAddress());
+ if (networkConnection.getIpAddress() != null)
+ networkConnectionSectionChild.e("IpAddress").t(networkConnection.getIpAddress());
+ networkConnectionSectionChild.e("IsConnected").t(networkConnection.isConnected() + "");
+ if (networkConnection.getMACAddress() != null)
+ networkConnectionSectionChild.e("MACAddress").t(networkConnection.getMACAddress());
+ if (networkConnection.getIpAddressAllocationMode() != null)
+ networkConnectionSectionChild.e("IpAddressAllocationMode").t(
+ networkConnection.getIpAddressAllocationMode().toString());
+ }
+
+ if (net.getEdit() != null)
+ networkConnectionSection.e("Link").a("rel", "edit").a("type", net.getType())
+ .a("href", net.getHref().toASCIIString());
+
+ Properties outputProperties = new Properties();
+ outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
+ request = super.bindToRequest(request, networkConnectionSection.asString(outputProperties));
+ request.getPayload().getContentMetadata().setContentType(net.getType());
+ } catch (Exception e) {
+ Throwables.propagate(e);
+ }
+ return request;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindParamsToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindParamsToXmlPayload.java
new file mode 100644
index 0000000..f613c1b
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindParamsToXmlPayload.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
+
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Properties;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.rest.binders.BindToStringPayload;
+
+import com.google.inject.Inject;
+import com.jamesmurty.utils.XMLBuilder;
+
+@Singleton
+public class BindParamsToXmlPayload implements MapBinder {
+
+ protected final String ns;
+ protected final BindToStringPayload stringBinder;
+ protected final String element;
+
+ @Inject
+ public BindParamsToXmlPayload(String element, BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns) {
+ this.element = element;
+ this.ns = ns;
+ this.stringBinder = stringBinder;
+ }
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
+ try {
+ return stringBinder.bindToRequest(request, generateXml(postParams));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ private String generateXml(Map<String, Object> postParams) throws ParserConfigurationException,
+ FactoryConfigurationError, TransformerException {
+ XMLBuilder rootBuilder = XMLBuilder.create(element);
+ for (Entry<String, Object> entry : postParams.entrySet())
+ rootBuilder.a(entry.getKey(), (String) entry.getValue());
+ rootBuilder.a("xmlns", ns);
+ Properties outputProperties = new Properties();
+ outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
+ return rootBuilder.asString(outputProperties);
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalArgumentException("incorrect usage");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayload.java
new file mode 100644
index 0000000..d95846e
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindUndeployVAppParamsToXmlPayload.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.rest.binders.BindToStringPayload;
+
+import com.google.inject.Inject;
+
+@Singleton
+public class BindUndeployVAppParamsToXmlPayload extends BindParamsToXmlPayload {
+
+ @Inject
+ public BindUndeployVAppParamsToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns) {
+ super("UndeployVAppParams", stringBinder, ns);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndCatalogNameToEndpoint.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndCatalogNameToEndpoint.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndCatalogNameToEndpoint.java
new file mode 100644
index 0000000..09c81e5
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndCatalogNameToEndpoint.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.vcloud.domain.Org;
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.endpoints.Catalog;
+
+import com.google.common.base.Supplier;
+import com.google.common.collect.Iterables;
+
+@Singleton
+public class OrgNameAndCatalogNameToEndpoint implements MapBinder {
+ private final Supplier<Map<String, Org>> orgMap;
+ private final Supplier<ReferenceType> defaultOrg;
+ private final Supplier<ReferenceType> defaultCatalog;
+
+ @Inject
+ public OrgNameAndCatalogNameToEndpoint(Supplier<Map<String, Org>> orgMap,
+ @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg,
+ @Catalog Supplier<ReferenceType> defaultCatalog) {
+ this.orgMap = orgMap;
+ this.defaultOrg = defaultOrg;
+ this.defaultCatalog = defaultCatalog;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
+ Object org = postParams.get("orgName");
+ Object catalog = postParams.get("catalogName");
+ if (org == null && catalog == null)
+ return (R) request.toBuilder().endpoint(defaultCatalog.get().getHref()).build();
+ else if (org == null)
+ org = defaultOrg.get().getName();
+
+ try {
+ Map<String, ReferenceType> catalogs = checkNotNull(orgMap.get().get(org)).getCatalogs();
+ URI endpoint = catalog == null ? Iterables.getLast(catalogs.values()).getHref() : catalogs.get(catalog).getHref();
+ return (R) request.toBuilder().endpoint(endpoint).build();
+ } catch (NullPointerException e) {
+ throw new NoSuchElementException(org + "/" + catalog + " not found in " + orgMap.get());
+ }
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalStateException(getClass() + " needs parameters");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndVDCNameToEndpoint.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndVDCNameToEndpoint.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndVDCNameToEndpoint.java
new file mode 100644
index 0000000..b4bc580
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndVDCNameToEndpoint.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.vcloud.domain.Org;
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.endpoints.VDC;
+
+import com.google.common.base.Supplier;
+import com.google.common.collect.Iterables;
+
+@Singleton
+public class OrgNameAndVDCNameToEndpoint implements MapBinder {
+ private final Supplier<Map<String, Org>> orgNameToVDCEndpoint;
+ private final Supplier<ReferenceType> defaultOrg;
+ private final Supplier<ReferenceType> defaultVDC;
+
+ @Inject
+ public OrgNameAndVDCNameToEndpoint(Supplier<Map<String, Org>> orgNameToVDCEndpoint,
+ @org.jclouds.vcloud.endpoints.Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
+ this.orgNameToVDCEndpoint = orgNameToVDCEndpoint;
+ this.defaultOrg = defaultOrg;
+ this.defaultVDC = defaultVDC;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
+ Object org = postParams.get("orgName");
+ Object vdc = postParams.get("vdcName");
+ if (org == null && vdc == null)
+ return (R) request.toBuilder().endpoint(defaultVDC.get().getHref()).build();
+ else if (org == null)
+ org = defaultOrg.get().getName();
+
+ try {
+ Map<String, ReferenceType> vdcs = checkNotNull(orgNameToVDCEndpoint.get().get(org)).getVDCs();
+ URI endpoint = vdc == null ? Iterables.getLast(vdcs.values()).getHref() : vdcs.get(vdc).getHref();
+ return (R) request.toBuilder().endpoint(endpoint).build();
+ } catch (NullPointerException e) {
+ throw new NoSuchElementException(org + "/" + vdc + " not found in " + orgNameToVDCEndpoint.get());
+ }
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalStateException(getClass() + " needs parameters");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameItemNameToEndpoint.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameItemNameToEndpoint.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameItemNameToEndpoint.java
new file mode 100644
index 0000000..2d9f762
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameItemNameToEndpoint.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.endpoints.Catalog;
+import org.jclouds.vcloud.endpoints.Org;
+
+import com.google.common.base.Supplier;
+
+@Singleton
+public class OrgNameCatalogNameItemNameToEndpoint implements MapBinder {
+ private final Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap;
+ private final Supplier<ReferenceType> defaultOrg;
+ private final Supplier<ReferenceType> defaultCatalog;
+
+ @Inject
+ public OrgNameCatalogNameItemNameToEndpoint(
+ Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.Catalog>>> orgCatalogMap,
+ @Org Supplier<ReferenceType> defaultOrg, @Catalog Supplier<ReferenceType> defaultCatalog) {
+ this.orgCatalogMap = orgCatalogMap;
+ this.defaultOrg = defaultOrg;
+ this.defaultCatalog = defaultCatalog;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
+ Object org = postParams.get("orgName");
+ Object catalog = postParams.get("catalogName");
+ Object catalogItem = postParams.get("itemName");
+ if (org == null)
+ org = defaultOrg.get().getName();
+ if (catalog == null)
+ catalog = defaultCatalog.get().getName();
+ try {
+ Map<String, org.jclouds.vcloud.domain.Catalog> catalogs = checkNotNull(orgCatalogMap.get().get(org));
+ return (R) request.toBuilder().endpoint(catalogs.get(catalog).get(catalogItem).getHref()).build();
+ } catch (NullPointerException e) {
+ throw new NoSuchElementException(org + "/" + catalog + "/" + catalogItem + " not found in "
+ + orgCatalogMap.get());
+ }
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalStateException(getClass() + " needs parameters");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameVAppTemplateNameToEndpoint.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameVAppTemplateNameToEndpoint.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameVAppTemplateNameToEndpoint.java
new file mode 100644
index 0000000..a8b798d
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameVAppTemplateNameToEndpoint.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.vcloud.domain.CatalogItem;
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.endpoints.Catalog;
+import org.jclouds.vcloud.endpoints.Org;
+
+import com.google.common.base.Supplier;
+
+@Singleton
+public class OrgNameCatalogNameVAppTemplateNameToEndpoint implements MapBinder {
+ private final Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> orgCatalogItemMap;
+ private final Supplier<ReferenceType> defaultOrg;
+ private final Supplier<ReferenceType> defaultCatalog;
+
+ @Inject
+ public OrgNameCatalogNameVAppTemplateNameToEndpoint(
+ Supplier<Map<String, Map<String, Map<String, CatalogItem>>>> orgCatalogItemMap,
+ @Org Supplier<ReferenceType> defaultOrg, @Catalog Supplier<ReferenceType> defaultCatalog) {
+ this.orgCatalogItemMap = orgCatalogItemMap;
+ this.defaultOrg = defaultOrg;
+ this.defaultCatalog = defaultCatalog;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
+ Object org = postParams.get("orgName");
+ Object catalog = postParams.get("catalogName");
+ Object catalogItem = postParams.get("itemName");
+ if (org == null)
+ org = defaultOrg.get().getName();
+ if (catalog == null)
+ catalog = defaultCatalog.get().getName();
+ Map<String, Map<String, Map<String, CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap.get();
+
+ if (!orgCatalogItemMap.containsKey(org))
+ throw new NoSuchElementException("org: " + org + " not found in " + orgCatalogItemMap.keySet());
+ Map<String, Map<String, CatalogItem>> catalogs = orgCatalogItemMap.get(org);
+
+ if (!catalogs.containsKey(catalog))
+ throw new NoSuchElementException("catalog: " + org + "/" + catalog + " not found in " + catalogs.keySet());
+ Map<String, CatalogItem> catalogMap = catalogs.get(catalog);
+
+ if (!catalogMap.containsKey(catalogItem))
+ throw new NoSuchElementException("item: " + org + "/" + catalog + "/" + catalogItem + " not found in "
+ + catalogMap.keySet());
+ CatalogItem item = catalogMap.get(catalogItem);
+
+ URI endpoint = checkNotNull(item.getEntity(),
+ "item: " + org + "/" + catalog + "/" + catalogItem + " has no entity").getHref();
+ return (R) request.toBuilder().endpoint(endpoint).build();
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalStateException(getClass() + " needs parameters");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameNetworkNameToEndpoint.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameNetworkNameToEndpoint.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameNetworkNameToEndpoint.java
new file mode 100644
index 0000000..11bfeac
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameNetworkNameToEndpoint.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.endpoints.Org;
+import org.jclouds.vcloud.endpoints.VDC;
+
+import com.google.common.base.Supplier;
+
+@Singleton
+public class OrgNameVDCNameNetworkNameToEndpoint extends OrgNameVDCNameResourceNameToEndpoint {
+ @Inject
+ public OrgNameVDCNameNetworkNameToEndpoint(
+ Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
+ @Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
+ super(orgVDCMap, defaultOrg, defaultVDC);
+ }
+
+ protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
+ org.jclouds.vcloud.domain.VDC vDCObject) {
+ ReferenceType resourceEntity = vDCObject.getAvailableNetworks().get(resource);
+ if (resourceEntity == null)
+ throw new NoSuchElementException("network " + resource + " in vdc " + vDC + ", org " + org + " not found in "
+ + vDCObject.getAvailableNetworks().keySet());
+ return resourceEntity.getHref();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceEntityNameToEndpoint.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceEntityNameToEndpoint.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceEntityNameToEndpoint.java
new file mode 100644
index 0000000..effcc49
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceEntityNameToEndpoint.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.endpoints.Org;
+import org.jclouds.vcloud.endpoints.VDC;
+
+import com.google.common.base.Supplier;
+
+@Singleton
+public class OrgNameVDCNameResourceEntityNameToEndpoint extends OrgNameVDCNameResourceNameToEndpoint {
+ @Inject
+ public OrgNameVDCNameResourceEntityNameToEndpoint(
+ Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
+ @Org Supplier<ReferenceType> defaultOrg, @VDC Supplier<ReferenceType> defaultVDC) {
+ super(orgVDCMap, defaultOrg, defaultVDC);
+ }
+
+ protected URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource,
+ org.jclouds.vcloud.domain.VDC vDCObject) {
+ ReferenceType resourceEntity = vDCObject.getResourceEntities().get(resource);
+ if (resourceEntity == null)
+ throw new NoSuchElementException("entity " + resource + " in vdc " + vDC + ", org " + org + " not found in "
+ + vDCObject.getResourceEntities().keySet());
+ return resourceEntity.getHref();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceNameToEndpoint.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceNameToEndpoint.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceNameToEndpoint.java
new file mode 100644
index 0000000..99ac848
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceNameToEndpoint.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.binders;
+
+import static com.google.common.base.Preconditions.checkState;
+
+import java.net.URI;
+import java.util.Map;
+import java.util.NoSuchElementException;
+
+import javax.inject.Inject;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.domain.VDC;
+import org.jclouds.vcloud.endpoints.Org;
+
+import com.google.common.base.Supplier;
+public abstract class OrgNameVDCNameResourceNameToEndpoint implements MapBinder {
+
+ protected final Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap;
+ protected final Supplier<ReferenceType> defaultOrg;
+ protected final Supplier<ReferenceType> defaultVDC;
+
+ @Inject
+ public OrgNameVDCNameResourceNameToEndpoint(
+ Supplier<Map<String, Map<String, org.jclouds.vcloud.domain.VDC>>> orgVDCMap,
+ @Org Supplier<ReferenceType> defaultOrg, @org.jclouds.vcloud.endpoints.VDC Supplier<ReferenceType> defaultVDC) {
+ this.orgVDCMap = orgVDCMap;
+ this.defaultOrg = defaultOrg;
+ this.defaultVDC = defaultVDC;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) {
+ Object org = postParams.get("orgName");
+ Object vDC = postParams.get("vdcName");
+ Object resource = postParams.get("resourceName");
+ if (org == null)
+ org = defaultOrg.get().getName();
+ if (vDC == null)
+ vDC = defaultVDC.get().getName();
+ Map<String, Map<String, org.jclouds.vcloud.domain.VDC>> orgToVDCs = orgVDCMap.get();
+ checkState(orgToVDCs != null, "could not get map of org name to vdcs!");
+ Map<String, org.jclouds.vcloud.domain.VDC> vDCs = orgToVDCs.get(org);
+ if (vDCs == null)
+ throw new NoSuchElementException("org " + org + " not found in " + orgToVDCs.keySet());
+ org.jclouds.vcloud.domain.VDC vDCObject = vDCs.get(vDC);
+ if (vDCObject == null)
+ throw new NoSuchElementException("vdc " + vDC + " in org " + org + " not found in " + vDCs.keySet());
+ URI endpoint = getEndpointOfResourceInVDC(org, vDC, resource, vDCObject);
+ return (R) request.toBuilder().endpoint(endpoint).build();
+ }
+
+ protected abstract URI getEndpointOfResourceInVDC(Object org, Object vDC, Object resource, VDC vDCObject);
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalStateException(getClass() + " needs parameters");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java
new file mode 100644
index 0000000..d3538c0
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.compute.config;
+
+import org.jclouds.compute.config.ComputeServiceAdapterContextModule;
+import org.jclouds.domain.Location;
+import org.jclouds.vcloud.domain.VApp;
+import org.jclouds.vcloud.domain.VAppTemplate;
+
+/**
+ * Configures the {@link VCloudComputeServiceContext}; requires {@link VCloudComputeClientImpl}
+ * bound.
+ */
+public class VCloudComputeServiceContextModule extends
+ ComputeServiceAdapterContextModule<VApp, VAppTemplate, VAppTemplate, Location> {
+
+ @Override
+ protected void configure() {
+ super.configure();
+ install(new VCloudComputeServiceDependenciesModule());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java
new file mode 100644
index 0000000..8b53c90
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java
@@ -0,0 +1,150 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.compute.config;
+
+
+import java.util.Map;
+
+import javax.inject.Singleton;
+
+import org.jclouds.compute.ComputeServiceAdapter;
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.TemplateBuilder;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.domain.Location;
+import org.jclouds.functions.IdentityFunction;
+import org.jclouds.vcloud.compute.functions.HardwareForVApp;
+import org.jclouds.vcloud.compute.functions.HardwareForVAppTemplate;
+import org.jclouds.vcloud.compute.functions.ImageForVAppTemplate;
+import org.jclouds.vcloud.compute.functions.VAppToNodeMetadata;
+import org.jclouds.vcloud.compute.internal.VCloudTemplateBuilderImpl;
+import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
+import org.jclouds.vcloud.compute.strategy.VCloudComputeServiceAdapter;
+import org.jclouds.vcloud.domain.Org;
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.domain.Status;
+import org.jclouds.vcloud.domain.VApp;
+import org.jclouds.vcloud.domain.VAppTemplate;
+import org.jclouds.vcloud.domain.network.FenceMode;
+import org.jclouds.vcloud.domain.network.NetworkConfig;
+import org.jclouds.vcloud.endpoints.Network;
+import org.jclouds.vcloud.functions.VAppTemplatesInOrg;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Function;
+import com.google.common.base.Supplier;
+import com.google.common.base.Suppliers;
+import com.google.common.collect.ImmutableMap;
+import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.TypeLiteral;
+
+public class VCloudComputeServiceDependenciesModule extends AbstractModule {
+
+ @VisibleForTesting
+ public static final Map<Status, NodeMetadata.Status> toPortableNodeStatus = ImmutableMap
+ .<Status, NodeMetadata.Status> builder()
+ .put(Status.OFF, NodeMetadata.Status.SUSPENDED)
+ .put(Status.ON, NodeMetadata.Status.RUNNING)
+ .put(Status.RESOLVED, NodeMetadata.Status.PENDING)
+ .put(Status.MIXED, NodeMetadata.Status.PENDING)
+ .put(Status.UNKNOWN, NodeMetadata.Status.UNRECOGNIZED)
+ .put(Status.UNRECOGNIZED, NodeMetadata.Status.UNRECOGNIZED)
+ .put(Status.DEPLOYED, NodeMetadata.Status.PENDING)
+ .put(Status.SUSPENDED, NodeMetadata.Status.SUSPENDED)
+ .put(Status.WAITING_FOR_INPUT, NodeMetadata.Status.PENDING)
+ .put(Status.INCONSISTENT, NodeMetadata.Status.PENDING)
+ .put(Status.ERROR, NodeMetadata.Status.ERROR)
+ .put(Status.UNRESOLVED, NodeMetadata.Status.PENDING).build();
+
+ @Singleton
+ @Provides
+ protected Map<Status, NodeMetadata.Status> toPortableNodeStatus() {
+ return toPortableNodeStatus;
+ }
+
+ @VisibleForTesting
+ public static final Map<Status, Image.Status> toPortableImageStatus = ImmutableMap
+ .<Status, Image.Status> builder()
+ .put(Status.RESOLVED, Image.Status.AVAILABLE)
+ .put(Status.OFF, Image.Status.AVAILABLE)
+ .put(Status.MIXED, Image.Status.PENDING)
+ .put(Status.UNKNOWN, Image.Status.UNRECOGNIZED)
+ .put(Status.UNRECOGNIZED, Image.Status.UNRECOGNIZED)
+ .put(Status.DEPLOYED, Image.Status.PENDING)
+ .put(Status.PENDING_DESCRIPTOR, Image.Status.PENDING)
+ .put(Status.COPYING, Image.Status.PENDING)
+ .put(Status.PENDING_CONTENTS, Image.Status.PENDING)
+ .put(Status.QUARANTINED, Image.Status.PENDING)
+ .put(Status.QUARANTINE_EXPIRED, Image.Status.ERROR)
+ .put(Status.REJECTED, Image.Status.ERROR)
+ .put(Status.TRANSFER_TIMEOUT, Image.Status.ERROR)
+ .put(Status.ERROR, Image.Status.ERROR)
+ .put(Status.UNRESOLVED, Image.Status.PENDING).build();
+
+ @Singleton
+ @Provides
+ protected Map<Status, Image.Status> toPortableImageStatus() {
+ return toPortableImageStatus;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void configure() {
+ bind(new TypeLiteral<ComputeServiceAdapter<VApp, VAppTemplate, VAppTemplate, Location>>() {
+ }).to(VCloudComputeServiceAdapter.class);
+
+ bind(new TypeLiteral<Function<VApp, NodeMetadata>>() {
+ }).to(VAppToNodeMetadata.class);
+
+ bind(TemplateOptions.class).to(VCloudTemplateOptions.class);
+ bind(TemplateBuilder.class).to(VCloudTemplateBuilderImpl.class);
+
+ bind(new TypeLiteral<Function<VApp, Hardware>>() {
+ }).to(new TypeLiteral<HardwareForVApp>() {
+ });
+
+ bind(new TypeLiteral<Function<Org, Iterable<VAppTemplate>>>() {
+ }).to(VAppTemplatesInOrg.class);
+ bind(new TypeLiteral<Function<VAppTemplate, Image>>() {
+ }).to(ImageForVAppTemplate.class);
+ bind(new TypeLiteral<Function<VAppTemplate, Hardware>>() {
+ }).to(HardwareForVAppTemplate.class);
+
+ // we aren't converting from a provider-specific type
+ bind(new TypeLiteral<Function<Location, Location>>() {
+ }).to(Class.class.cast(IdentityFunction.class));
+ }
+
+
+ @Provides
+ @Singleton
+ public Supplier<NetworkConfig> networkConfig(@Network Supplier<ReferenceType> network,
+ final FenceMode defaultFenceMode) {
+ return Suppliers.compose(new Function<ReferenceType, NetworkConfig>() {
+
+ @Override
+ public NetworkConfig apply(ReferenceType input) {
+ return new NetworkConfig(input.getName(), input.getHref(), defaultFenceMode);
+ }
+
+ }, network);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/FindLocationForResource.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/FindLocationForResource.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/FindLocationForResource.java
new file mode 100644
index 0000000..f7e2cdf
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/FindLocationForResource.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.compute.functions;
+
+import java.net.URI;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.collect.Memoized;
+import org.jclouds.domain.Location;
+import org.jclouds.logging.Logger;
+import org.jclouds.vcloud.domain.ReferenceType;
+
+import com.google.common.base.Function;
+import com.google.common.base.Supplier;
+
+@Singleton
+public class FindLocationForResource implements Function<ReferenceType, Location> {
+
+ @Resource
+ protected Logger logger = Logger.NULL;
+
+ final Supplier<Set<? extends Location>> locations;
+
+ @Inject
+ public FindLocationForResource(@Memoized Supplier<Set<? extends Location>> locations) {
+ this.locations = locations;
+ }
+
+ /**
+ * searches for a location associated with this resource.
+ *
+ * @throws NoSuchElementException
+ * if not found
+ */
+ public Location apply(ReferenceType resource) {
+ for (Location input : locations.get()) {
+ do {
+ // The "name" isn't always present, ex inside a vApp we have a rel
+ // link that only includes href and type.
+ if (URI.create(input.getId()).equals(resource.getHref()))
+ return input;
+ } while ((input = input.getParent()) != null);
+ }
+ throw new NoSuchElementException(String.format("resource: %s not found in locations: %s", resource,
+ locations.get()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVApp.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVApp.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVApp.java
new file mode 100644
index 0000000..ebfb010
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVApp.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.compute.functions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.HardwareBuilder;
+import org.jclouds.compute.predicates.ImagePredicates;
+import org.jclouds.domain.Location;
+import org.jclouds.logging.Logger;
+import org.jclouds.ovf.VirtualHardwareSection;
+import org.jclouds.vcloud.domain.ReferenceType;
+import org.jclouds.vcloud.domain.VApp;
+import org.jclouds.vcloud.domain.Vm;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+
+public class HardwareForVApp implements Function<VApp, Hardware> {
+
+ @Resource
+ protected Logger logger = Logger.NULL;
+
+ private final Function<ReferenceType, Location> findLocationForResource;
+ private final VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
+
+ @Inject
+ protected HardwareForVApp(Function<ReferenceType, Location> findLocationForResource,
+ VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
+ this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
+ this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");
+ }
+
+ @Override
+ public Hardware apply(VApp from) {
+ checkNotNull(from, "VApp");
+ // TODO make this work with composite vApps
+ Vm vm = from.getChildren().size() == 0 ? null : Iterables.get(from.getChildren(), 0);
+ if (vm == null)
+ return null;
+
+ VirtualHardwareSection hardware = vm.getVirtualHardwareSection();
+ HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems());
+ builder.location(findLocationForResource.apply(checkNotNull(from, "from").getVDC()));
+ builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(
+ ImagePredicates.idEquals(from.getHref().toASCIIString()));
+ builder.hypervisor("VMware");
+ return builder.build();
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java
new file mode 100644
index 0000000..46d1627
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.compute.functions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.HardwareBuilder;
+import org.jclouds.compute.predicates.ImagePredicates;
+import org.jclouds.logging.Logger;
+import org.jclouds.ovf.Envelope;
+import org.jclouds.ovf.VirtualHardwareSection;
+import org.jclouds.vcloud.domain.VAppTemplate;
+
+import com.google.common.base.Function;
+import com.google.common.collect.Iterables;
+
+@Singleton
+public class HardwareForVAppTemplate implements Function<VAppTemplate, Hardware> {
+
+ @Resource
+ protected Logger logger = Logger.NULL;
+
+ private final Function<VAppTemplate, Envelope> templateToEnvelope;
+ private final FindLocationForResource findLocationForResource;
+ private final VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder;
+
+ @Inject
+ protected HardwareForVAppTemplate(Function<VAppTemplate, Envelope> templateToEnvelope,
+ FindLocationForResource findLocationForResource,
+ VCloudHardwareBuilderFromResourceAllocations rasdToHardwareBuilder) {
+ this.templateToEnvelope = checkNotNull(templateToEnvelope, "templateToEnvelope");
+ this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
+ this.rasdToHardwareBuilder = checkNotNull(rasdToHardwareBuilder, "rasdToHardwareBuilder");
+ }
+
+ @Override
+ public Hardware apply(VAppTemplate from) {
+ checkNotNull(from, "VAppTemplate");
+
+ Envelope ovf = templateToEnvelope.apply(from);
+
+ if (ovf.getVirtualSystem().getVirtualHardwareSections().size() > 1) {
+ logger.warn("multiple hardware choices found. using first", ovf);
+ }
+ VirtualHardwareSection hardware = Iterables.get(ovf.getVirtualSystem().getVirtualHardwareSections(), 0);
+ HardwareBuilder builder = rasdToHardwareBuilder.apply(hardware.getItems());
+ if (from.getVDC() != null) {
+ builder.location(findLocationForResource.apply(from.getVDC()));
+ } else {
+ // otherwise, it could be in a public catalog, which is not assigned to a VDC
+ }
+ builder.ids(from.getHref().toASCIIString()).name(from.getName()).supportsImage(
+ ImagePredicates.idEquals(from.getHref().toASCIIString()));
+ builder.hypervisor("VMware");
+ return builder.build();
+
+ }
+
+ protected String getName(String name) {
+ return name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java
new file mode 100644
index 0000000..eb70f28
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.compute.functions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.compute.domain.CIMOperatingSystem;
+import org.jclouds.compute.domain.Image;
+import org.jclouds.compute.domain.ImageBuilder;
+import org.jclouds.compute.reference.ComputeServiceConstants;
+import org.jclouds.logging.Logger;
+import org.jclouds.ovf.Envelope;
+import org.jclouds.vcloud.domain.Status;
+import org.jclouds.vcloud.domain.VAppTemplate;
+
+import com.google.common.base.Function;
+
+@Singleton
+public class ImageForVAppTemplate implements Function<VAppTemplate, Image> {
+
+ @Resource
+ @Named(ComputeServiceConstants.COMPUTE_LOGGER)
+ public Logger logger = Logger.NULL;
+
+ private final Map<Status, Image.Status> toPortableImageStatus;
+ private final Function<VAppTemplate, Envelope> templateToEnvelope;
+ private final FindLocationForResource findLocationForResource;
+
+
+ @Inject
+ protected ImageForVAppTemplate(Map<Status, Image.Status> toPortableImageStatus, Function<VAppTemplate, Envelope> templateToEnvelope,
+ FindLocationForResource findLocationForResource) {
+ this.toPortableImageStatus = checkNotNull(toPortableImageStatus, "toPortableImageStatus");
+ this.templateToEnvelope = checkNotNull(templateToEnvelope, "templateToEnvelope");
+ this.findLocationForResource = checkNotNull(findLocationForResource, "findLocationForResource");
+ }
+
+ @Override
+ public Image apply(VAppTemplate from) {
+ checkNotNull(from, "VAppTemplate");
+ Envelope ovf = templateToEnvelope.apply(from);
+
+ ImageBuilder builder = new ImageBuilder();
+ builder.ids(from.getHref().toASCIIString());
+ builder.uri(from.getHref());
+ builder.name(from.getName());
+ if (from.getVDC() != null) {
+ builder.location(findLocationForResource.apply(from.getVDC()));
+ } else {
+ // otherwise, it could be in a public catalog, which is not assigned to a VDC
+ }
+ builder.description(from.getDescription() != null ? from.getDescription() : from.getName());
+ builder.operatingSystem(CIMOperatingSystem.toComputeOs(ovf));
+ builder.status(toPortableImageStatus.get(from.getStatus()));
+ return builder.build();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java
new file mode 100644
index 0000000..0947c78
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jclouds.vcloud.compute.functions;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static com.google.common.base.Predicates.not;
+import static com.google.common.base.Strings.isNullOrEmpty;
+import static com.google.common.collect.Iterables.filter;
+import static org.jclouds.compute.util.ComputeServiceUtils.addMetadataAndParseTagsFromCommaDelimitedValue;
+import static org.jclouds.compute.util.ComputeServiceUtils.groupFromMapOrName;
+import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getCredentialsFrom;
+import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.getIpsFromVApp;
+import static org.jclouds.vcloud.compute.util.VCloudComputeUtils.toComputeOs;
+
+import java.util.Map;
+import java.util.Set;
+
+import javax.annotation.Resource;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.jclouds.compute.domain.Hardware;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.NodeMetadataBuilder;
+import org.jclouds.compute.functions.GroupNamingConvention;
+import org.jclouds.domain.Credentials;
+import org.jclouds.logging.Logger;
+import org.jclouds.util.InetAddresses2.IsPrivateIPAddress;
+import org.jclouds.vcloud.domain.Status;
+import org.jclouds.vcloud.domain.VApp;
+
+import com.google.common.base.Function;
+import com.google.common.base.Splitter;
+import com.google.common.collect.ImmutableMap;
+
+@Singleton
+public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
+ @Resource
+ protected static Logger logger = Logger.NULL;
+
+ protected final FindLocationForResource findLocationForResourceInVDC;
+ protected final Function<VApp, Hardware> hardwareForVApp;
+ protected final Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus;
+ protected final Map<String, Credentials> credentialStore;
+ protected final GroupNamingConvention nodeNamingConvention;
+
+ @Inject
+ protected VAppToNodeMetadata(Map<Status, NodeMetadata.Status> vAppStatusToNodeStatus, Map<String, Credentials> credentialStore,
+ FindLocationForResource findLocationForResourceInVDC, Function<VApp, Hardware> hardwareForVApp,
+ GroupNamingConvention.Factory namingConvention) {
+ this.nodeNamingConvention = checkNotNull(namingConvention, "namingConvention").createWithoutPrefix();
+ this.hardwareForVApp = checkNotNull(hardwareForVApp, "hardwareForVApp");
+ this.findLocationForResourceInVDC = checkNotNull(findLocationForResourceInVDC, "findLocationForResourceInVDC");
+ this.credentialStore = checkNotNull(credentialStore, "credentialStore");
+ this.vAppStatusToNodeStatus = checkNotNull(vAppStatusToNodeStatus, "vAppStatusToNodeStatus");
+ }
+
+ public NodeMetadata apply(VApp from) {
+ NodeMetadataBuilder builder = new NodeMetadataBuilder();
+ builder.ids(from.getHref().toASCIIString());
+ builder.uri(from.getHref());
+ builder.name(from.getName());
+ String groupName = "";
+ Map<String, String> metadataMap;
+
+ if (!isNullOrEmpty(from.getDescription())
+ && from.getDescription().indexOf('=') != -1
+ && from.getDescription().indexOf('\n') != -1) {
+ try {
+ metadataMap = Splitter.on('\n').withKeyValueSeparator("=").split(from.getDescription());
+
+ addMetadataAndParseTagsFromCommaDelimitedValue(builder, metadataMap);
+ } catch (IllegalArgumentException iae) {
+ // no op
+ metadataMap = ImmutableMap.of();
+ }
+ } else {
+ metadataMap = ImmutableMap.of();
+ }
+ builder.hostname(from.getName());
+ builder.location(findLocationForResourceInVDC.apply(from.getVDC()));
+ builder.group(groupFromMapOrName(metadataMap, from.getName(), nodeNamingConvention));
+ builder.operatingSystem(toComputeOs(from, null));
+ builder.hardware(hardwareForVApp.apply(from));
+ builder.status(vAppStatusToNodeStatus.get(from.getStatus()));
+ Set<String> addresses = getIpsFromVApp(from);
+ builder.publicAddresses(filter(addresses, not(IsPrivateIPAddress.INSTANCE)));
+ builder.privateAddresses(filter(addresses, IsPrivateIPAddress.INSTANCE));
+
+ // normally, we don't affect the credential store when reading vApps.
+ // However, login user, etc, is actually in the metadata, so lets see
+ Credentials fromApi = getCredentialsFrom(from);
+ if (fromApi != null && !credentialStore.containsKey("node#" + from.getHref().toASCIIString()))
+ credentialStore.put("node#" + from.getHref().toASCIIString(), fromApi);
+ return builder.build();
+ }
+}