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 VCloudExpressPropertiesBuilder extends PropertiesBuilder {
40     @Override
41     protected Properties defaultProperties() {
42        Properties properties = super.defaultProperties();
43        properties.setProperty(PROPERTY_API_VERSION, "0.8");
44        properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
45        properties.setProperty(PROPERTY_SESSION_INTERVAL, 8 * 60 + "");
46        properties.setProperty(PROPERTY_VCLOUD_XML_SCHEMA,
47                 "http://vcloud.safesecureweb.com/ns/vcloud.xsd");
48        properties.setProperty("jclouds.dns_name_length_min", "1");
49        properties.setProperty("jclouds.dns_name_length_max", "80");
50        properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 180l * 1000l + "");
51        return properties;
52     }
53  
54     public VCloudExpressPropertiesBuilder(Properties properties) {
55        super(properties);
56     }
57  
58     protected void setNs() {
59        if (properties.getProperty(PROPERTY_VCLOUD_XML_NAMESPACE) == null)
60           properties.setProperty(PROPERTY_VCLOUD_XML_NAMESPACE, "http://www.vmware.com/vcloud/v"
61                    + properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA));
62     }
63  
64     protected void setFenceMode() {
65        if (properties.getProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE) == null) {
66           if (properties.getProperty(PROPERTY_VCLOUD_VERSION_SCHEMA).startsWith("0.8"))
67              properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, "allowInOut");
68           else
69              properties.setProperty(PROPERTY_VCLOUD_DEFAULT_FENCEMODE, FenceMode.BRIDGED.toString());
70        }
71     }
72  
73     public VCloudExpressPropertiesBuilder withApiVersion(String version) {
74        properties.setProperty(PROPERTY_API_VERSION, "0.8");
75        return this;
76     }
77  
78     public VCloudExpressPropertiesBuilder withSchemaVersion(String version) {
79        properties.setProperty(PROPERTY_VCLOUD_VERSION_SCHEMA, "0.8");
80        return this;
81     }
82  
83     @Override
84     public Properties build() {
85        setNs();
86        setFenceMode();
87        return super.build();
88     }
89  }