http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindVCloudNetworkAdapterToXmlPayload.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindVCloudNetworkAdapterToXmlPayload.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindVCloudNetworkAdapterToXmlPayload.java deleted file mode 100644 index b3fe262..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/BindVCloudNetworkAdapterToXmlPayload.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * 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.google.inject.name.Named; -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.ovf.VCloudNetworkAdapter; - -import javax.inject.Singleton; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.transform.TransformerException; -import java.util.Map; - -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 michiel on 17/11/2014. - */ -@Singleton -public class BindVCloudNetworkAdapterToXmlPayload implements MapBinder { - - protected final String ns; - protected final String schema; - - protected final BindToStringPayload stringBinder; - - @Inject - public BindVCloudNetworkAdapterToXmlPayload(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!"); - - Iterable<VCloudNetworkAdapter> networkCards = (Iterable<VCloudNetworkAdapter>) checkNotNull(postParams.remove("params"), "params"); - - /* - * The Iterable<VCloudNetworkAdapter> needs to be turned into a RasdItemList. - */ - XMLBuilder rasdItemListBuilder; - String xml = null; - try { - rasdItemListBuilder = XMLBuilder.create("RasdItemsList").a("xmlns", ns); - //all sorts of other crazy XML attributes - rasdItemListBuilder.a("xmlns:rasd", "http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData"); - rasdItemListBuilder.a("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - rasdItemListBuilder.a("type", "application/vnd.vmware.vcloud.rasdItemsList+xml"); - //rasdItemListBuilder.a("href", "https://<vcloud>/api/vApp/vm-<UUID>/virtualHardwareSection/networkCards"); - //rasdItemListBuilder.a("xsi:schemaLocation", "http://www.vmware.com/vcloud/v1.5 http://172.28.44.90/api/v1.5/schema/master.xsd http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_ResourceAllocationSettingData http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2.22.0/CIM_ResourceAllocationSettingData.xsd"); - - for (VCloudNetworkAdapter nic: networkCards) { - /* - * NOTE: the order of these items IS important. - */ - XMLBuilder rasdItem = rasdItemListBuilder.elem("Item"); - if (nic.getAddress() != null) - rasdItem.elem("rasd:Address").text(nic.getAddress()); - if (nic.getAddressOnParent() != null) - rasdItem.elem("rasd:AddressOnParent").text(nic.getAddressOnParent()); - if (nic.isAutomaticAllocation() != null) - rasdItem.elem("rasd:AutomaticAllocation").text(String.valueOf(nic.isAutomaticAllocation())); - - //the connection handling is a little bit more involved. - if (nic.getConnections().size() > 1) { - /* - * The IP address is an attribute of the <rasd:Connection /> element, and we only store - * 1 IP address for the whole NIC. It's not clear to me why the nic.getConnections() returns - * a list anyway. - */ - throw new UnsupportedOperationException("Currently we only support 1 connection per NIC."); - } - if (nic.getConnections() != null) { - for (String connection: nic.getConnections()) { - XMLBuilder c = rasdItem.elem("rasd:Connection").a("xmlns:vcloud", ns); - if (nic.getIpAddress() != null) - c.a("vcloud:ipAddress", nic.getIpAddress()); - - c.a("vcloud:primaryNetworkConnection", String.valueOf(nic.isPrimaryNetworkConnection())); - if (nic.getIpAddressingMode() != null) - c.a("vcloud:ipAddressingMode", nic.getIpAddressingMode()); - c.text(connection); - } - } - - if (nic.getDescription() != null) - rasdItem.elem("rasd:Description").text(nic.getDescription()); - if (nic.getElementName() != null) - rasdItem.elem("rasd:ElementName").text(nic.getElementName()); - if (nic.getInstanceID() != null) - rasdItem.elem("rasd:InstanceID").text(nic.getInstanceID()); - if (nic.getResourceSubType() != null) - rasdItem.elem("rasd:ResourceSubType").text(nic.getResourceSubType()); - if (nic.getResourceType() != null) - rasdItem.elem("rasd:ResourceType").text(nic.getResourceType().value()); - - //TODO: remaining items - } - xml = rasdItemListBuilder.asString(); - } catch (ParserConfigurationException e) { - Throwables.propagate(e); - } catch (TransformerException e) { - Throwables.propagate(e); - } - - return stringBinder.bindToRequest(request, xml); - } - - @Override - public <R extends HttpRequest> R bindToRequest(R request, Object postParams) { - throw new IllegalStateException("BindVCloudNetworkAdapterToXmlPayload needs parameters"); - } -}
http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/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 deleted file mode 100644 index 09c81e5..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndCatalogNameToEndpoint.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index b4bc580..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameAndVDCNameToEndpoint.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index 2d9f762..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameItemNameToEndpoint.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index a8b798d..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameCatalogNameVAppTemplateNameToEndpoint.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index 11bfeac..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameNetworkNameToEndpoint.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index effcc49..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceEntityNameToEndpoint.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index 99ac848..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/binders/OrgNameVDCNameResourceNameToEndpoint.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index d3538c0..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceContextModule.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index 8b53c90..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/config/VCloudComputeServiceDependenciesModule.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index f7e2cdf..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/FindLocationForResource.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index ebfb010..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVApp.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index 46d1627..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/HardwareForVAppTemplate.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index eb70f28..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/ImageForVAppTemplate.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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/897edde8/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 deleted file mode 100644 index 0947c78..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/VAppToNodeMetadata.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * 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(); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/VCloudHardwareBuilderFromResourceAllocations.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/VCloudHardwareBuilderFromResourceAllocations.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/VCloudHardwareBuilderFromResourceAllocations.java deleted file mode 100644 index 2f3bd42..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/VCloudHardwareBuilderFromResourceAllocations.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 javax.inject.Singleton; - -import org.jclouds.cim.ResourceAllocationSettingData; -import org.jclouds.cim.functions.HardwareBuilderFromResourceAllocations; -import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.domain.internal.VolumeImpl; -import org.jclouds.vcloud.domain.ovf.VCloudHardDisk; - -@Singleton -public class VCloudHardwareBuilderFromResourceAllocations extends HardwareBuilderFromResourceAllocations { - @Override - public Volume apply(ResourceAllocationSettingData from) { - if (from instanceof VCloudHardDisk) { - VCloudHardDisk vDisk = VCloudHardDisk.class.cast(from); - return new VolumeImpl(from.getAddressOnParent() + "", Volume.Type.LOCAL, vDisk.getCapacity() / 1024f, null, - "0".equals(from.getAddressOnParent()), true); - } else { - return super.apply(from); - } - - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException.java deleted file mode 100644 index c08a622..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/functions/ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.net.URI; -import java.util.concurrent.ExecutionException; - -import javax.annotation.Resource; -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.logging.Logger; -import org.jclouds.ovf.Envelope; -import org.jclouds.vcloud.domain.VAppTemplate; - -import com.google.common.base.Function; -import com.google.common.cache.LoadingCache; - -@Singleton -public class ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException implements - Function<VAppTemplate, Envelope> { - - @Resource - protected Logger logger = Logger.NULL; - - private final LoadingCache<URI, Envelope> envelopes; - - @Inject - protected ValidateVAppTemplateAndReturnEnvelopeOrThrowIllegalArgumentException(LoadingCache<URI, Envelope> envelopes) { - this.envelopes = checkNotNull(envelopes, "envelopes"); - } - - @Override - public Envelope apply(VAppTemplate from) { - checkArgument(from.getChildren().size() == 1, "multiple vms are not supported: %s", from); - - checkArgument(from.isOvfDescriptorUploaded(), "ovf descriptor is not uploaded: %s", from); - Envelope ovf = getOVFForVAppTemplateAndValidate(from); - return ovf; - } - - private Envelope getOVFForVAppTemplateAndValidate(VAppTemplate from) throws IllegalArgumentException { - Envelope ovf; - try { - ovf = envelopes.get(from.getHref()); - checkArgument(ovf.getVirtualSystem().getVirtualHardwareSections().size() > 0, - "no hardware sections exist in ovf %s", ovf); - } catch (ExecutionException e) { - throw new IllegalArgumentException("no ovf envelope found for: " + from, e); - } - return ovf; - } -} - http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/internal/VCloudTemplateBuilderImpl.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/internal/VCloudTemplateBuilderImpl.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/internal/VCloudTemplateBuilderImpl.java deleted file mode 100644 index 8304466..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/internal/VCloudTemplateBuilderImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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.internal; - -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Provider; - -import org.jclouds.collect.Memoized; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.TemplateBuilder; -import org.jclouds.compute.domain.internal.TemplateBuilderImpl; -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.compute.strategy.GetImageStrategy; -import org.jclouds.compute.suppliers.ImageCacheSupplier; -import org.jclouds.domain.Location; - -import com.google.common.base.Supplier; - -public class VCloudTemplateBuilderImpl extends TemplateBuilderImpl { - - @Inject - protected VCloudTemplateBuilderImpl(@Memoized Supplier<Set<? extends Location>> locations, - ImageCacheSupplier images, @Memoized Supplier<Set<? extends Hardware>> sizes, - Supplier<Location> defaultLocation, @Named("DEFAULT") Provider<TemplateOptions> optionsProvider, - @Named("DEFAULT") Provider<TemplateBuilder> defaultTemplateProvider, GetImageStrategy getImageStrategy) { - super(locations, images, sizes, defaultLocation, optionsProvider, defaultTemplateProvider, getImageStrategy); - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/897edde8/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/options/VCloudTemplateOptions.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/options/VCloudTemplateOptions.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/options/VCloudTemplateOptions.java deleted file mode 100644 index 0910db4..0000000 --- a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/main/java/org/jclouds/vcloud/compute/options/VCloudTemplateOptions.java +++ /dev/null @@ -1,349 +0,0 @@ -/* - * 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.options; - -import static com.google.common.base.Objects.equal; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Strings.emptyToNull; - -import java.net.URI; -import java.util.Hashtable; -import java.util.Map; - -import org.jclouds.compute.options.TemplateOptions; -import org.jclouds.vcloud.domain.NetworkConnection; -import org.jclouds.vcloud.domain.network.FenceMode; -import org.jclouds.vcloud.domain.network.IpAddressAllocationMode; - -import com.google.common.base.Objects; -import com.google.common.base.Objects.ToStringHelper; - -/** - * Contains options supported in the {@code ComputeService#runNode} operation on - * the "vcloud" provider. <h2> - * Usage</h2> The recommended way to instantiate a VCloudTemplateOptions object - * is to statically import VCloudTemplateOptions.* and invoke a static creation - * method followed by an instance mutator (if needed): - * <p/> - * <code> - * import static org.jclouds.compute.options.VCloudTemplateOptions.Builder.*; - * <p/> - * ComputeService client = // get connection - * templateBuilder.options(inboundPorts(22, 80, 8080, 443)); - * Set<NodeMetadata> set = client.createNodesInGroup(tag, 2, templateBuilder.build()); - * <code> - */ -public class VCloudTemplateOptions extends TemplateOptions implements Cloneable { - @Override - public VCloudTemplateOptions clone() { - VCloudTemplateOptions options = new VCloudTemplateOptions(); - copyTo(options); - return options; - } - - @Override - public void copyTo(TemplateOptions to) { - super.copyTo(to); - if (to instanceof VCloudTemplateOptions) { - VCloudTemplateOptions eTo = VCloudTemplateOptions.class.cast(to); - if (getCustomizationScript() != null) - eTo.customizationScript(getCustomizationScript()); - if (getDescription() != null) - eTo.description(getDescription()); - if (getNetworkConnections() != null) - eTo.networkConnections(getNetworkConnections()); - if (getParentNetwork() != null) - eTo.parentNetwork(getParentNetwork()); - if (getFenceMode() != null) - eTo.fenceMode(getFenceMode()); - } - } - - private String description = null; - private String customizationScript = null; - // This Hashtable maps TemplateOptions.networks[i] to each networks' specific vCloud options - // We index by network 'name' (href in vCloud) - private Hashtable<String, NetworkConnection> networkConnections = null; - private URI parentNetwork = null; - private FenceMode fenceMode = null; - - @Override - public boolean equals(Object o) { - if (this == o) - return true; - if (o == null || getClass() != o.getClass()) - return false; - VCloudTemplateOptions that = VCloudTemplateOptions.class.cast(o); - return super.equals(that) && equal(this.description, that.description) - && equal(this.customizationScript, that.customizationScript) - && equal(this.networkConnections, that.networkConnections) - && equal(this.parentNetwork, that.parentNetwork); - } - - @Override - public int hashCode() { - return Objects.hashCode(super.hashCode(), description, customizationScript, networkConnections, - parentNetwork); - } - - @Override - public ToStringHelper string() { - return super.string().add("description", description).add("customizationScript", customizationScript) - .add("networkConnections", networkConnections).add("parentNetwork", parentNetwork); - } - - /** - * Optional description. Used for the Description of the vApp created by this - * instantiation. - */ - public VCloudTemplateOptions description(String description) { - this.description = description; - return this; - } - - /** - * Specifies the customizationScript used to run instances with - */ - public VCloudTemplateOptions customizationScript(String customizationScript) { - this.customizationScript = checkNotNull(emptyToNull(customizationScript), "customizationScript must be defined"); - return this; - } - - /** - * Specifies the networkConnections settings used to for network interfaces on - * the VMs. This lets you specify things like ip address allocation mode, - * the actual IP (in case of fixed IP) etc. - */ - public VCloudTemplateOptions networkConnections(Hashtable<String, NetworkConnection> networkConnections) { - this.networkConnections = networkConnections; - return this; - } - - /** - * Specifies the parentNetwork to connect the the network interfaces on the - * VMs to. - * - * @see InstantiateVAppTemplateOptions#addNetworkConfig - */ - public VCloudTemplateOptions parentNetwork(URI parentNetwork) { - this.parentNetwork = parentNetwork; - return this; - } - - /** - * How to connect to the parent network - * - * @see InstantiateVAppTemplateOptions#addNetworkConfig - */ - public VCloudTemplateOptions fenceMode(FenceMode fenceMode) { - this.fenceMode = fenceMode; - return this; - } - - public static class Builder { - /** - * @see VCloudTemplateOptions#description - */ - public static VCloudTemplateOptions description(String description) { - return new VCloudTemplateOptions().description(description); - } - - /** - * @see VCloudTemplateOptions#customizationScript - */ - public static VCloudTemplateOptions customizationScript(String customizationScript) { - return new VCloudTemplateOptions().customizationScript(customizationScript); - } - - /** - * @see VCloudTemplateOptions#networkConnections - */ - public static VCloudTemplateOptions networkConnections(Hashtable<String, NetworkConnection> networkConnections) { - return new VCloudTemplateOptions().networkConnections(networkConnections); - } - - /** - * @see VCloudTemplateOptions#parentNetwork(URI parentNetwork) - */ - public static VCloudTemplateOptions parentNetwork(URI parentNetwork) { - return new VCloudTemplateOptions().parentNetwork(parentNetwork); - } - - /** - * @see VCloudTemplateOptions#fenceMode(FenceMode) - */ - public static VCloudTemplateOptions fenceMode(FenceMode fenceMode) { - return new VCloudTemplateOptions().fenceMode(fenceMode); - } - - // methods that only facilitate returning the correct object type - /** - * @see TemplateOptions#inboundPorts - */ - public static VCloudTemplateOptions inboundPorts(int... ports) { - VCloudTemplateOptions options = new VCloudTemplateOptions(); - return VCloudTemplateOptions.class.cast(options.inboundPorts(ports)); - } - - /** - * @see TemplateOptions#port - */ - public static VCloudTemplateOptions blockOnPort(int port, int seconds) { - VCloudTemplateOptions options = new VCloudTemplateOptions(); - return VCloudTemplateOptions.class.cast(options.blockOnPort(port, seconds)); - } - - /** - * @see TemplateOptions#userMetadata(Map) - */ - public static VCloudTemplateOptions userMetadata(Map<String, String> userMetadata) { - VCloudTemplateOptions options = new VCloudTemplateOptions(); - return VCloudTemplateOptions.class.cast(options.userMetadata(userMetadata)); - } - - /** - * @see TemplateOptions#userMetadata(String, String) - */ - public static VCloudTemplateOptions userMetadata(String key, String value) { - VCloudTemplateOptions options = new VCloudTemplateOptions(); - return VCloudTemplateOptions.class.cast(options.userMetadata(key, value)); - } - - /** - * @see TemplateOptions#nodeNames(Iterable) - */ - public static VCloudTemplateOptions nodeNames(Iterable<String> nodeNames) { - VCloudTemplateOptions options = new VCloudTemplateOptions(); - return VCloudTemplateOptions.class.cast(options.nodeNames(nodeNames)); - } - - /** - * @see TemplateOptions#networks(Iterable) - */ - public static VCloudTemplateOptions networks(Iterable<String> networks) { - VCloudTemplateOptions options = new VCloudTemplateOptions(); - return VCloudTemplateOptions.class.cast(options.networks(networks)); - } - - } - - /** - * @return description of the vApp - */ - public String getDescription() { - return description; - } - - /** - * @return customizationScript on the vms - */ - public String getCustomizationScript() { - return customizationScript; - } - - /** - * @return ipAddressAllocationMode on the vms - */ - public Hashtable<String, NetworkConnection> getNetworkConnections() { return networkConnections; } - - /** - * @return parentNetwork to connect to the vms - */ - public URI getParentNetwork() { - return parentNetwork; - } - - /** - * @return FenceMode to connect the parent network with - */ - public FenceMode getFenceMode() { - return fenceMode; - } - - // methods that only facilitate returning the correct object type - - /** - * @see TemplateOptions#blockOnPort - */ - @Override - public VCloudTemplateOptions blockOnPort(int port, int seconds) { - return VCloudTemplateOptions.class.cast(super.blockOnPort(port, seconds)); - } - - /** - * - * special thing is that we do assume if you are passing groups that you have - * everything you need already defined. for example, our option inboundPorts - * normally creates ingress rules accordingly but if we notice you've - * specified securityGroups, we do not mess with rules at all - * - * @see TemplateOptions#inboundPorts - */ - @Override - public VCloudTemplateOptions inboundPorts(int... ports) { - return VCloudTemplateOptions.class.cast(super.inboundPorts(ports)); - } - - /** - * @see TemplateOptions#authorizePublicKey(String) - */ - @Override - public VCloudTemplateOptions authorizePublicKey(String publicKey) { - return VCloudTemplateOptions.class.cast(super.authorizePublicKey(publicKey)); - } - - /** - * @see TemplateOptions#installPrivateKey(String) - */ - @Override - public VCloudTemplateOptions installPrivateKey(String privateKey) { - return VCloudTemplateOptions.class.cast(super.installPrivateKey(privateKey)); - } - - /** - * {@inheritDoc} - */ - @Override - public VCloudTemplateOptions userMetadata(Map<String, String> userMetadata) { - return VCloudTemplateOptions.class.cast(super.userMetadata(userMetadata)); - } - - /** - * {@inheritDoc} - */ - @Override - public VCloudTemplateOptions userMetadata(String key, String value) { - return VCloudTemplateOptions.class.cast(super.userMetadata(key, value)); - } - - /** - * {@inheritDoc} - */ - @Override - public VCloudTemplateOptions nodeNames(Iterable<String> nodeNames) { - return VCloudTemplateOptions.class.cast(super.nodeNames(nodeNames)); - } - - /** - * {@inheritDoc} - */ - @Override - public VCloudTemplateOptions networks(Iterable<String> networks) { - return VCloudTemplateOptions.class.cast(super.networks(networks)); - } - -}
