View Javadoc

1   /**
2    *
3    * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com>
4    *
5    * ====================================================================
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   * ====================================================================
18   */
19  package org.jclouds.vcloud;
20  
21  import static org.jclouds.Constants.PROPERTY_API_VERSION;
22  import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL;
23  import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_DEFAULT_FENCEMODE;
24  import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
25  import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_VERSION_SCHEMA;
26  import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_NAMESPACE;
27  import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_XML_SCHEMA;
28  
29  import java.util.Properties;
30  
31  import org.jclouds.PropertiesBuilder;
32  import org.jclouds.vcloud.domain.network.FenceMode;
33  
34  /**
35   * Builds properties used in VCloud Clients
36   * 
37   * @author Adrian Cole
38   */
39  public class VCloudPropertiesBuilder extends PropertiesBuilder {
40     @Override
41     protected Properties defaultProperties() {
42        Properties properties = super.defaultProperties();
43        properties.setProperty(PROPERTY_API_VERSION, "1.0");
44        properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1");
45        properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + "");
46        properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA, "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
47        properties.setProperty("jclouds.dns_name_length_min", "1");
48        properties.setProperty("jclouds.dns_name_length_max", "80");
49        properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString());
50        // TODO integrate this with the {@link ComputeTimeouts} instead of having a single timeout for
51        // everything.
52        properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 600l * 1000l + "");
53        return properties;
54     }
55  
56     public VCloudPropertiesBuilder(Properties properties) {
57        super(properties);
58     }
59  
60     protected void setNs() {
61        if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null)
62           properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v"
63                    + properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA));
64     }
65  
66     public VCloudPropertiesBuilder withApiVersion(String version) {
67        properties.setProperty(PROPERTY_API_VERSION, "1.0");
68        return this;
69     }
70  
71     public VCloudPropertiesBuilder withSchemaVersion(String version) {
72        properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "1.0");
73        return this;
74     }
75  
76     @Override
77     public Properties build() {
78        setNs();
79        return super.build();
80     }
81  }