You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by im...@apache.org on 2015/08/20 11:36:03 UTC
[17/51] [abbrv] [partial] stratos git commit: Revert "Upgrading to
jclouds 1.9.1"
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudMediaType.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudMediaType.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudMediaType.java
new file mode 100644
index 0000000..7126701
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudMediaType.java
@@ -0,0 +1,226 @@
+/*
+ * 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;
+
+import javax.ws.rs.core.MediaType;
+
+/**
+ * Resource Types used in VCloud
+ *
+ * @see MediaType
+ */
+public interface VCloudMediaType {
+ /**
+ * "application/vnd.vmware.vcloud.error+xml"
+ */
+ public static final String ERROR_XML = "application/vnd.vmware.vcloud.error+xml";
+
+ /**
+ * "application/vnd.vmware.vcloud.error+xml"
+ */
+ public static final MediaType ERROR_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.error+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.vcloud+xml"
+ */
+ public static final String VCLOUD_XML = "application/vnd.vmware.vcloud.vcloud+xml";
+
+ /**
+ * "application/vnd.vmware.vcloud.vcloud+xml"
+ */
+ public static final MediaType VCLOUD_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vcloud+xml");
+ /**
+ * "application/vnd.vmware.vcloud.orgList+xml"
+ */
+ public static final String ORGLIST_XML = "application/vnd.vmware.vcloud.orgList+xml";
+
+ /**
+ * "application/vnd.vmware.vcloud.orgList+xml"
+ */
+ public static final MediaType ORGLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.orgList+xml");
+ /**
+ * "application/vnd.vmware.vcloud.org+xml"
+ */
+ public static final String ORG_XML = "application/vnd.vmware.vcloud.org+xml";
+ /**
+ * "application/vnd.vmware.vcloud.org+xml"
+ */
+ public static final MediaType ORG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.org+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.vdc+xml"
+ */
+ public static final String VDC_XML = "application/vnd.vmware.vcloud.vdc+xml";
+ /**
+ * "application/vnd.vmware.vcloud.vdc+xml"
+ */
+ public static final MediaType VDC_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vdc+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.catalog+xml"
+ */
+ public static final String CATALOG_XML = "application/vnd.vmware.vcloud.catalog+xml";
+ /**
+ * "application/vnd.vmware.vcloud.catalog+xml"
+ */
+ public static final MediaType CATALOG_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.catalog+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.tasksList+xml"
+ */
+ public static final String TASKSLIST_XML = "application/vnd.vmware.vcloud.tasksList+xml";
+ /**
+ * "application/vnd.vmware.vcloud.tasksList+xml"
+ */
+ public static final MediaType TASKSLIST_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.tasksList+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.catalogItem+xml"
+ */
+ public static final String CATALOGITEM_XML = "application/vnd.vmware.vcloud.catalogItem+xml";
+ /**
+ * "application/vnd.vmware.vcloud.catalogItem+xml"
+ */
+ public static final MediaType CATALOGITEM_XML_TYPE = new MediaType("application",
+ "vnd.vmware.vcloud.catalogItem+xml");
+ /**
+ * "application/vnd.vmware.vcloud.networkConnectionSection+xml"
+ */
+ public static final String NETWORKCONNECTIONSECTION_XML = "application/vnd.vmware.vcloud.networkConnectionSection+xml";
+ /**
+ * "application/vnd.vmware.vcloud.networkConnectionSection+xml"
+ */
+ public static final MediaType NETWORKCONNECTIONSECTION_XML_TYPE = new MediaType("application",
+ "vnd.vmware.vcloud.networkConnectionSection+xml");
+ /**
+ * "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
+ */
+ public static final String VIRTUALHARDWARESECTION_XML = "application/vnd.vmware.vcloud.virtualHardwareSection+xml";
+ /**
+ * "application/vnd.vmware.vcloud.virtualHardwareSection+xml"
+ */
+ public static final MediaType VIRTUALHARDWARESECTION_XML_TYPE = new MediaType("application",
+ "vnd.vmware.vcloud.virtualHardwareSection+xml");
+ /**
+ * "application/vnd.vmware.vcloud.guestCustomizationSection+xml"
+ */
+ public static final String GUESTCUSTOMIZATIONSECTION_XML = "application/vnd.vmware.vcloud.guestCustomizationSection+xml";
+ /**
+ * "application/vnd.vmware.vcloud.guestCustomizationSection+xml"
+ */
+ public static final MediaType GUESTCUSTOMIZATIONSECTION_XML_TYPE = new MediaType("application",
+ "vnd.vmware.vcloud.guestCustomizationSection+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.networkSection+xml"
+ */
+ public static final String NETWORKSECTION_XML = "application/vnd.vmware.vcloud.networkSection+xml";
+ /**
+ * "application/vnd.vmware.vcloud.networkSection+xml"
+ */
+ public static final MediaType NETWORKSECTION_XML_TYPE = new MediaType("application",
+ "vnd.vmware.vcloud.networkSection+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.task+xml"
+ */
+ public static final String TASK_XML = "application/vnd.vmware.vcloud.task+xml";
+ /**
+ * "application/vnd.vmware.vcloud.task+xml"
+ */
+ public static final MediaType TASK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.task+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.undeployVAppParams+xml"
+ */
+ public static final String UNDEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.undeployVAppParams+xml";
+ /**
+ * "application/vnd.vmware.vcloud.undeployVAppParams+xml"
+ */
+ public static final MediaType UNDEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application",
+ "vnd.vmware.vcloud.undeployVAppParams+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.deployVAppParams+xml"
+ */
+ public static final String DEPLOYVAPPPARAMS_XML = "application/vnd.vmware.vcloud.deployVAppParams+xml";
+ /**
+ * "application/vnd.vmware.vcloud.deployVAppParams+xml"
+ */
+ public static final MediaType DEPLOYVAPPPARAMS_XML_TYPE = new MediaType("application",
+ "vnd.vmware.vcloud.deployVAppParams+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.vApp+xml"
+ */
+ public static final String VAPP_XML = "application/vnd.vmware.vcloud.vApp+xml";
+ /**
+ * "application/vnd.vmware.vcloud.vApp+xml"
+ */
+ public static final MediaType VAPP_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vApp+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.vm+xml"
+ */
+ public static final String VM_XML = "application/vnd.vmware.vcloud.vm+xml";
+ /**
+ * "application/vnd.vmware.vcloud.vm+xml"
+ */
+ public static final MediaType VM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.vm+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.vAppTemplate+xml"
+ */
+ public static final String VAPPTEMPLATE_XML = "application/vnd.vmware.vcloud.vAppTemplate+xml";
+ /**
+ * "application/vnd.vmware.vcloud.vAppTemplate+xml"
+ */
+ public static final MediaType VAPPTEMPLATE_XML_TYPE = new MediaType("application",
+ "vnd.vmware.vcloud.vAppTemplate+xml");
+ /**
+ * "application/vnd.vmware.vcloud.network+xml"
+ */
+ public static final String NETWORK_XML = "application/vnd.vmware.vcloud.network+xml";
+ /**
+ * "application/vnd.vmware.vcloud.network+xml"
+ */
+ public static final MediaType NETWORK_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.network+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.rasdItem+xml"
+ */
+ public static final String RASDITEM_XML = "application/vnd.vmware.vcloud.rasdItem+xml";
+ /**
+ * "application/vnd.vmware.vcloud.rasdItemsList+xml"
+ */
+ public static final String RASDITEMLIST_XML = "application/vnd.vmware.vcloud.rasdItemsList+xml";
+ /**
+ * "application/vnd.vmware.vcloud.rasdItem+xml"
+ */
+ public static final MediaType RASDITEM_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.rasdItem+xml");
+
+ /**
+ * "application/vnd.vmware.vcloud.session+xml"
+ */
+ public static final String SESSION_XML = "application/vnd.vmware.vcloud.session+xml";
+
+ /**
+ * "application/vnd.vmware.vcloud.session+xml"
+ */
+ public static final MediaType SESSION_XML_TYPE = new MediaType("application", "vnd.vmware.vcloud.session+xml");
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudResponseException.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudResponseException.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudResponseException.java
new file mode 100644
index 0000000..ea8d7f8
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudResponseException.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;
+
+import org.jclouds.http.HttpCommand;
+import org.jclouds.http.HttpResponse;
+import org.jclouds.http.HttpResponseException;
+import org.jclouds.vcloud.domain.VCloudError;
+
+/**
+ * Encapsulates an VCloud Error.
+ */
+public class VCloudResponseException extends HttpResponseException {
+
+ private org.jclouds.vcloud.domain.VCloudError error;
+
+ public VCloudResponseException(HttpCommand command, HttpResponse response, VCloudError error) {
+ super(String.format("request %s failed with code %s, error: %s", command.getCurrentRequest().getRequestLine(), response
+ .getStatusCode(), error.toString()), command, response);
+ this.setError(error);
+
+ }
+
+ public VCloudResponseException(HttpCommand command, HttpResponse response, VCloudError error, Throwable cause) {
+ super(String.format("request %1$s failed with error: %2$s", command.getCurrentRequest().getRequestLine(), error
+ .toString()), command, response, cause);
+ this.setError(error);
+
+ }
+
+ public VCloudResponseException(String message, HttpCommand command, HttpResponse response, VCloudError error) {
+ super(message, command, response);
+ this.setError(error);
+
+ }
+
+ public VCloudResponseException(String message, HttpCommand command, HttpResponse response, VCloudError error,
+ Throwable cause) {
+ super(message, command, response, cause);
+ this.setError(error);
+
+ }
+
+ public void setError(VCloudError error) {
+ this.error = error;
+ }
+
+ public VCloudError getError() {
+ return error;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudToken.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudToken.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudToken.java
new file mode 100644
index 0000000..2aca7bd
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudToken.java
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+/**
+ * A VCloud Session Token
+ */
+@Retention(value = RetentionPolicy.RUNTIME)
+@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD })
+@Qualifier
+public @interface VCloudToken {
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudVersionsApi.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudVersionsApi.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudVersionsApi.java
new file mode 100644
index 0000000..b6c46f9
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/VCloudVersionsApi.java
@@ -0,0 +1,38 @@
+/*
+ * 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;
+
+import java.io.Closeable;
+import java.net.URI;
+import java.util.SortedMap;
+
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+
+import org.jclouds.rest.annotations.RequestFilters;
+import org.jclouds.rest.annotations.XMLResponseParser;
+import org.jclouds.vcloud.http.filters.VCloudSupportedVersions;
+import org.jclouds.vcloud.xml.SupportedVersionsHandler;
+
+@RequestFilters(VCloudSupportedVersions.class)
+public interface VCloudVersionsApi extends Closeable {
+
+ @GET
+ @XMLResponseParser(SupportedVersionsHandler.class)
+ @Path("/versions")
+ SortedMap<String, URI> getSupportedVersions();
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCPUCountToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCPUCountToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCPUCountToXmlPayload.java
new file mode 100644
index 0000000..fc757a1
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCPUCountToXmlPayload.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.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 BindCPUCountToXmlPayload extends BindToStringPayload {
+ protected final String ns;
+ protected final String schema;
+
+ @Inject
+ public BindCPUCountToXmlPayload(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, "cpuCount") instanceof Integer, "this binder is only valid for Integers!");
+ Integer cpuCount = 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("hertz * 10^6");
+ cpuItem.e("rasd:Description").t("Number of Virtual CPUs");
+ cpuItem.e("rasd:ElementName").t(cpuCount.toString() + " virtual CPU(s)");
+ cpuItem.e("rasd:InstanceID").t("4");
+ cpuItem.e("rasd:ResourceType").t(ResourceType.PROCESSOR.value());
+ cpuItem.e("rasd:VirtualQuantity").t(cpuCount.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/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCaptureVAppParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCaptureVAppParamsToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCaptureVAppParamsToXmlPayload.java
new file mode 100644
index 0000000..8a556be
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCaptureVAppParamsToXmlPayload.java
@@ -0,0 +1,119 @@
+/*
+ * 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.Map;
+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 org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.jclouds.vcloud.VCloudMediaType;
+import org.jclouds.vcloud.options.CaptureVAppOptions;
+
+import com.google.inject.Inject;
+import com.jamesmurty.utils.XMLBuilder;
+
+@Singleton
+public class BindCaptureVAppParamsToXmlPayload implements MapBinder {
+
+ protected final String ns;
+ protected final String schema;
+ private final BindToStringPayload stringBinder;
+
+ @Inject
+ public BindCaptureVAppParamsToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
+ this.ns = ns;
+ this.schema = schema;
+ this.stringBinder = stringBinder;
+ }
+
+ @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 templateName = checkNotNull(postParams.remove("templateName"), "templateName").toString();
+ String vApp = checkNotNull(postParams.remove("vApp"), "vApp").toString();
+
+ CaptureVAppOptions options = findOptionsInArgsOrNull(gRequest);
+ if (options == null) {
+ options = new CaptureVAppOptions();
+ }
+ try {
+ return stringBinder.bindToRequest(request, generateXml(templateName, vApp, options));
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ } catch (FactoryConfigurationError e) {
+ throw new RuntimeException(e);
+ } catch (TransformerException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ protected String generateXml(String templateName, String vApp, CaptureVAppOptions options)
+ throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
+ XMLBuilder rootBuilder = buildRoot(templateName);
+ if (options.getDescription() != null)
+ rootBuilder.e("Description").text(options.getDescription());
+ rootBuilder.e("Source").a("href", vApp).a("type", VCloudMediaType.VAPP_XML);
+ Properties outputProperties = new Properties();
+ outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
+ return rootBuilder.asString(outputProperties);
+ }
+
+ protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
+ XMLBuilder rootBuilder = XMLBuilder.create("CaptureVAppParams").a("name", name).a("xmlns", ns)
+ .a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema);
+ return rootBuilder;
+ }
+
+ protected CaptureVAppOptions findOptionsInArgsOrNull(GeneratedHttpRequest gRequest) {
+ for (Object arg : gRequest.getInvocation().getArgs()) {
+ if (arg instanceof CaptureVAppOptions) {
+ return (CaptureVAppOptions) arg;
+ } else if (arg instanceof CaptureVAppOptions[]) {
+ CaptureVAppOptions[] options = (CaptureVAppOptions[]) arg;
+ return (options.length > 0) ? options[0] : null;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalStateException("CaptureVAppParams is needs parameters");
+ }
+
+ protected String ifNullDefaultTo(String value, String defaultValue) {
+ return value != null ? value : checkNotNull(defaultValue, "defaultValue");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayload.java
new file mode 100644
index 0000000..98c4e3a
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCatalogItemToXmlPayload.java
@@ -0,0 +1,121 @@
+/*
+ * 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.net.URI;
+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 org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.jclouds.vcloud.options.CatalogItemOptions;
+
+import com.google.inject.Inject;
+import com.jamesmurty.utils.XMLBuilder;
+
+@Singleton
+public class BindCatalogItemToXmlPayload implements MapBinder {
+
+ protected final String ns;
+ protected final String schema;
+ private final BindToStringPayload stringBinder;
+
+ @Inject
+ public BindCatalogItemToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
+ this.ns = ns;
+ this.schema = schema;
+ this.stringBinder = stringBinder;
+ }
+
+ @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.get("name"), "name").toString();
+ URI entity = URI.create(checkNotNull(postParams.get("Entity"), "Entity").toString());
+
+ CatalogItemOptions options = findOptionsInArgsOrNew(gRequest);
+ try {
+ return stringBinder.bindToRequest(request, generateXml(name, entity, options));
+ } catch (ParserConfigurationException e) {
+ throw new RuntimeException(e);
+ } catch (FactoryConfigurationError e) {
+ throw new RuntimeException(e);
+ } catch (TransformerException e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ protected String generateXml(String templateName, URI entity, CatalogItemOptions options)
+ throws ParserConfigurationException, FactoryConfigurationError, TransformerException {
+ XMLBuilder rootBuilder = buildRoot(templateName);
+ if (options.getDescription() != null)
+ rootBuilder.e("Description").t(options.getDescription());
+ rootBuilder.e("Entity").a("href", entity.toASCIIString());
+ for (Entry<String, String> entry : options.getProperties().entrySet()) {
+ rootBuilder.e("Property").a("key", entry.getKey()).t(entry.getValue());
+ }
+ Properties outputProperties = new Properties();
+ outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
+ return rootBuilder.asString(outputProperties);
+ }
+
+ protected XMLBuilder buildRoot(String name) throws ParserConfigurationException, FactoryConfigurationError {
+ XMLBuilder rootBuilder = XMLBuilder.create("CatalogItem").a("name", name).a("xmlns", ns).a("xmlns:xsi",
+ "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema);
+ return rootBuilder;
+ }
+
+ protected CatalogItemOptions findOptionsInArgsOrNew(GeneratedHttpRequest gRequest) {
+ for (Object arg : gRequest.getInvocation().getArgs()) {
+ if (arg instanceof CatalogItemOptions) {
+ return CatalogItemOptions.class.cast(arg);
+ } else if (arg.getClass().isArray()) {
+ Object[] array = (Object[]) arg;
+ if (array.length > 0 && array[0] instanceof CatalogItemOptions)
+ return CatalogItemOptions.class.cast(array[0]);
+ }
+ }
+ return new CatalogItemOptions();
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalStateException("CatalogItem is needs parameters");
+ }
+
+ protected String ifNullDefaultTo(String value, String defaultValue) {
+ return value != null ? value : checkNotNull(defaultValue, "defaultValue");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneParamsToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneParamsToXmlPayload.java
new file mode 100644
index 0000000..71617bc
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneParamsToXmlPayload.java
@@ -0,0 +1,128 @@
+/*
+ * 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.Map;
+import java.util.Properties;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.rest.binders.BindToStringPayload;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.jclouds.vcloud.options.CloneOptions;
+
+import com.google.common.base.Throwables;
+import com.google.inject.Inject;
+import com.jamesmurty.utils.XMLBuilder;
+
+@Singleton
+public abstract class BindCloneParamsToXmlPayload<O extends CloneOptions> implements MapBinder {
+
+ protected final String ns;
+ protected final String schema;
+ private final BindToStringPayload stringBinder;
+
+ protected abstract String getRootElement();
+ protected abstract String getSourceMediaType();
+ protected abstract Class<O> getOptionClass();
+
+ @Inject
+ public BindCloneParamsToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
+ this.ns = ns;
+ this.schema = schema;
+ this.stringBinder = stringBinder;
+ }
+
+ @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.get("name"), "name").toString();
+ String source = checkNotNull(postParams.get("Source"), "Source").toString();
+ boolean isSourceDelete = Boolean.parseBoolean((String) postParams.get("IsSourceDelete"));
+
+ O options = findOptionsInArgsOrNew(gRequest);
+ return stringBinder.bindToRequest(request, generateXml(name, source, isSourceDelete, options));
+ }
+
+ protected String generateXml(String name, String source, boolean isSourceDelete, O options) {
+ XMLBuilder rootBuilder = buildRoot(name, options);
+ addElementsUnderRoot(rootBuilder, source, options, isSourceDelete);
+ Properties outputProperties = new Properties();
+ outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
+ try {
+ return rootBuilder.asString(outputProperties);
+ } catch (Exception e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+ protected void addElementsUnderRoot(XMLBuilder rootBuilder, String source, O options, boolean isSourceDelete) {
+ if (options.getDescription() != null)
+ rootBuilder.e("Description").text(options.getDescription());
+ rootBuilder.e("Source").a("href", source).a("type", getSourceMediaType());
+ if (isSourceDelete)
+ rootBuilder.e("IsSourceDelete").t("true");
+ }
+
+ protected XMLBuilder buildRoot(String name, O options) {
+ try {
+ return XMLBuilder.create(getRootElement()).a("xmlns", ns).a("xmlns:xsi",
+ "http://www.w3.org/2001/XMLSchema-instance").a("xsi:schemaLocation", ns + " " + schema).a("name",
+ name);
+ } catch (Exception e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected O findOptionsInArgsOrNew(GeneratedHttpRequest gRequest) {
+ for (Object arg : gRequest.getInvocation().getArgs()) {
+ if (getOptionClass().isInstance(arg)) {
+ return (O) arg;
+ } else if (arg.getClass().isArray()) {
+ Object[] array = (Object[]) arg;
+ if (array.length > 0 && getOptionClass().isInstance(array[0]))
+ return (O) array[0];
+ }
+ }
+ try {
+ return getOptionClass().newInstance();
+ } catch (Exception e) {
+ throw Throwables.propagate(e);
+ }
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object input) {
+ throw new IllegalStateException("CloneParams is needs parameters");
+ }
+
+ protected String ifNullDefaultTo(String value, String defaultValue) {
+ return value != null ? value : checkNotNull(defaultValue, "defaultValue");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayload.java
new file mode 100644
index 0000000..50c3b83
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppParamsToXmlPayload.java
@@ -0,0 +1,60 @@
+/*
+ * 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 static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.rest.binders.BindToStringPayload;
+import org.jclouds.vcloud.VCloudMediaType;
+import org.jclouds.vcloud.options.CloneVAppOptions;
+
+import com.google.inject.Inject;
+import com.jamesmurty.utils.XMLBuilder;
+
+@Singleton
+public class BindCloneVAppParamsToXmlPayload extends BindCloneParamsToXmlPayload<CloneVAppOptions> {
+
+ @Inject
+ public BindCloneVAppParamsToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
+ super(stringBinder, ns, schema);
+ }
+
+ @Override
+ protected Class<CloneVAppOptions> getOptionClass() {
+ return CloneVAppOptions.class;
+ }
+
+ @Override
+ protected String getRootElement() {
+ return "CloneVAppParams";
+ }
+
+ @Override
+ protected String getSourceMediaType() {
+ return VCloudMediaType.VAPP_XML;
+ }
+
+ protected XMLBuilder buildRoot(String name, CloneVAppOptions options) {
+ return super.buildRoot(name, options).a("deploy", options.isDeploy() + "").a("powerOn", options.isPowerOn() + "");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppTemplateParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppTemplateParamsToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppTemplateParamsToXmlPayload.java
new file mode 100644
index 0000000..2323c94
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindCloneVAppTemplateParamsToXmlPayload.java
@@ -0,0 +1,55 @@
+/*
+ * 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 static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+
+import org.jclouds.rest.binders.BindToStringPayload;
+import org.jclouds.vcloud.VCloudMediaType;
+import org.jclouds.vcloud.options.CloneVAppTemplateOptions;
+
+import com.google.inject.Inject;
+
+@Singleton
+public class BindCloneVAppTemplateParamsToXmlPayload extends BindCloneParamsToXmlPayload<CloneVAppTemplateOptions> {
+
+ @Inject
+ public BindCloneVAppTemplateParamsToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
+ super(stringBinder, schema, schema);
+ }
+
+ @Override
+ protected Class<CloneVAppTemplateOptions> getOptionClass() {
+ return CloneVAppTemplateOptions.class;
+ }
+
+ @Override
+ protected String getRootElement() {
+ return "CloneVAppTemplateParams";
+ }
+
+ @Override
+ protected String getSourceMediaType() {
+ return VCloudMediaType.VAPPTEMPLATE_XML;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayload.java
new file mode 100644
index 0000000..d376222
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindDeployVAppParamsToXmlPayload.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 BindDeployVAppParamsToXmlPayload extends BindParamsToXmlPayload {
+
+ @Inject
+ public BindDeployVAppParamsToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns) {
+ super("DeployVAppParams", stringBinder, ns);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindDiskAttachOrDetachParamsToXmlPayload.java
----------------------------------------------------------------------
diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindDiskAttachOrDetachParamsToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindDiskAttachOrDetachParamsToXmlPayload.java
new file mode 100644
index 0000000..7e198aa
--- /dev/null
+++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindDiskAttachOrDetachParamsToXmlPayload.java
@@ -0,0 +1,100 @@
+/*
+ * 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 com.google.common.base.Throwables;
+import com.google.inject.Inject;
+import com.jamesmurty.utils.XMLBuilder;
+import org.jclouds.http.HttpRequest;
+import org.jclouds.rest.MapBinder;
+import org.jclouds.rest.binders.BindToStringPayload;
+import org.jclouds.rest.internal.GeneratedHttpRequest;
+import org.jclouds.vcloud.domain.DiskAttachOrDetachParams;
+
+import javax.inject.Named;
+import javax.inject.Singleton;
+import javax.xml.parsers.FactoryConfigurationError;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+import java.util.Map;
+import java.util.Properties;
+
+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;
+
+/**
+ * Created by mblokzij on 29/10/2014.
+ */
+@Singleton
+public class BindDiskAttachOrDetachParamsToXmlPayload implements MapBinder {
+
+ protected final String ns;
+ protected final String schema;
+
+ protected final BindToStringPayload stringBinder;
+
+ @Inject
+ public BindDiskAttachOrDetachParamsToXmlPayload(BindToStringPayload stringBinder,
+ @Named(PROPERTY_VCLOUD_XML_NAMESPACE) String ns, @Named(PROPERTY_VCLOUD_XML_SCHEMA) String schema) {
+ this.ns = ns;
+ this.schema = schema;
+ this.stringBinder = stringBinder;
+ }
+
+ @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!");
+ DiskAttachOrDetachParams params = (DiskAttachOrDetachParams) checkNotNull(postParams.remove("params"), "params");
+ XMLBuilder diskAttachOrDetachParams;
+ String xml = null;
+ try {
+ diskAttachOrDetachParams = XMLBuilder.create("DiskAttachOrDetachParams").a("xmlns", ns);
+ XMLBuilder disk = diskAttachOrDetachParams.e("Disk");
+ if (params.getHref() != null) {
+ disk.a("href", params.getHref().toString());
+ }
+ if (params.getId() != null) {
+ disk.a("id", params.getId().toString());
+ }
+ if (params.getName() != null) {
+ disk.a("name", params.getName());
+ }
+ if (params.getType() != null) {
+ disk.a("type", params.getType());
+ }
+ if (params.getBusNumber() != null) {
+ diskAttachOrDetachParams.e("BusNumber").t(params.getBusNumber().toString());
+ }
+ if (params.getUnitNumber() != null) {
+ diskAttachOrDetachParams.e("UnitNumber").t(params.getUnitNumber().toString());
+ }
+
+ xml = diskAttachOrDetachParams.asString();
+ } catch (Exception e) {
+ Throwables.propagate(e);
+ }
+ return stringBinder.bindToRequest(request, xml);
+ }
+
+ @Override
+ public <R extends HttpRequest> R bindToRequest(R request, Object postParams) {
+ throw new IllegalStateException("BindDiskAttachOrDetachParamsToXmlPayload needs parameters");
+ }
+}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/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/b45ae00e/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/b45ae00e/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/b45ae00e/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/b45ae00e/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/b45ae00e/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);
+ }
+
+}