Repository: stratos
Updated Branches:
  refs/heads/master e4ec3ee4a -> 0984bcef2


http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
new file mode 100644
index 0000000..6e10628
--- /dev/null
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/VCloudIaas.java
@@ -0,0 +1,262 @@
+/*
+ * 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.apache.stratos.cloud.controller.iaases;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.exception.CloudControllerException;
+import org.apache.stratos.cloud.controller.util.ComputeServiceBuilderUtil;
+import org.apache.stratos.cloud.controller.domain.IaasProvider;
+import 
org.apache.stratos.cloud.controller.iaases.validators.PartitionValidator;
+import 
org.apache.stratos.cloud.controller.iaases.validators.VCloudPartitionValidator;
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.compute.domain.TemplateBuilder;
+import org.jclouds.compute.options.TemplateOptions;
+import org.jclouds.vcloud.compute.options.VCloudTemplateOptions;
+import org.jclouds.vcloud.domain.network.IpAddressAllocationMode;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import java.io.File;
+import java.io.IOException;
+
+public class VCloudIaas extends Iaas {
+
+
+       private static final Log log = LogFactory.getLog(VCloudIaas.class);
+       
+       private static final String SHELL_TYPE = "shellType";
+       private static final String SCRIPTS_PATH = "scripts";
+       private static final String CUSTOMIZATION_SCRIPT = "customization";
+       private static final String PAYLOAD = "PAYLOAD";
+       
+       public VCloudIaas(IaasProvider iaasProvider) {
+               super(iaasProvider);
+       }
+
+       @Override
+       public void buildComputeServiceAndTemplate() {
+
+               IaasProvider iaasInfo = getIaasProvider();
+               
+               // builds and sets Compute Service
+               ComputeServiceBuilderUtil.buildDefaultComputeService(iaasInfo);
+
+               // builds and sets Template
+               buildTemplate();
+
+       }
+
+       public void buildTemplate() {
+               IaasProvider iaasInfo = getIaasProvider();
+               
+               if (iaasInfo.getComputeService() == null) {
+                       String msg = "Compute service is null for IaaS 
provider: "
+                                       + iaasInfo.getName();
+                       log.fatal(msg);
+                       throw new CloudControllerException(msg);
+               }
+
+               TemplateBuilder templateBuilder = iaasInfo.getComputeService()
+                               .templateBuilder();
+
+               // set image id specified
+               templateBuilder.imageId(iaasInfo.getImage());
+
+               // build the Template
+               Template template = templateBuilder.build();
+
+               // if you wish to auto assign IPs, instance spawning call 
should be
+               // blocking, but if you
+               // wish to assign IPs manually, it can be non-blocking.
+               // is auto-assign-ip mode or manual-assign-ip mode? - default 
mode is
+               // non-blocking
+               boolean blockUntilRunning = Boolean.parseBoolean(iaasInfo
+                               .getProperty("autoAssignIp"));
+               template.getOptions().as(TemplateOptions.class)
+                               .blockUntilRunning(blockUntilRunning);
+
+               // this is required in order to avoid creation of additional 
security
+               // groups by Jclouds.
+               template.getOptions().as(TemplateOptions.class)
+                               .inboundPorts(22, 80, 8080, 443, 8243);
+
+               template.getOptions().as(VCloudTemplateOptions.class)
+                               
.ipAddressAllocationMode(IpAddressAllocationMode.POOL);
+
+               // set Template
+               iaasInfo.setTemplate(template);
+       }
+
+       @Override
+       public void setDynamicPayload() {
+               // in vCloud case we need to run a script
+               IaasProvider iaasInfo = getIaasProvider();
+
+               if (iaasInfo.getTemplate() == null || iaasInfo.getPayload() == 
null) {
+                       if (log.isDebugEnabled()) {
+                               log.debug("Payload for vCloud not found");
+                       }
+                       return;
+               }
+
+               String shellType = iaasInfo.getProperty(SHELL_TYPE);
+
+               if (shellType == null || shellType.isEmpty()) {
+                       if (log.isDebugEnabled()) {
+                               log.debug("Shell Type for vCloud Customization 
script not found from properties");
+                       }
+                       return;
+               }
+
+               if (log.isDebugEnabled()) {
+                       log.debug(String.format("Shell Type '%s' will be used 
for vCloud Customization script", shellType));
+               }
+
+               // Payload is a String value
+               String payload = new String(iaasInfo.getPayload());
+
+               if (log.isDebugEnabled()) {
+                       log.debug(String.format("Payload '%s' will be used for 
vCloud Customization script", payload));
+               }
+
+               Template template = iaasInfo.getTemplate();
+
+               File scriptPath = new 
File(CarbonUtils.getCarbonConfigDirPath(), SCRIPTS_PATH);
+
+               File customizationScriptFile = new File(new File(scriptPath, 
shellType), CUSTOMIZATION_SCRIPT);
+
+               if (!customizationScriptFile.exists()) {
+                       if (log.isWarnEnabled()) {
+                               log.warn(String.format("The vCloud 
Customization script '%s' does not exist",
+                                               
customizationScriptFile.getAbsolutePath()));
+                       }
+                       return;
+               }
+
+               String customizationScript = null;
+
+               try {
+                       customizationScript = 
FileUtils.readFileToString(customizationScriptFile);
+               } catch (IOException e) {
+                       if (log.isErrorEnabled()) {
+                               log.error(
+                                               String.format("Error reading 
the vCloud Customization script '%s'",
+                                                               
customizationScriptFile.getAbsolutePath()), e);
+                       }
+               }
+
+               if (StringUtils.isEmpty(customizationScript)) {
+                       if (log.isDebugEnabled()) {
+                               log.debug("No content vCloud Customization 
script not found from properties");
+                       }
+                       return;
+               }
+
+               // Set payload
+               customizationScript = customizationScript.replaceAll(PAYLOAD, 
payload);
+
+               if (log.isDebugEnabled()) {
+                       log.debug(String.format("The vCloud Customization 
script\n%s", customizationScript));
+               }
+
+               // Run the script
+               template.getOptions().runScript(customizationScript);
+       }
+
+       @Override
+       public boolean createKeyPairFromPublicKey(String region, String 
keyPairName, String publicKey) {
+
+               // TODO
+               return false;
+       }
+
+       @Override
+       public String associateAddress(NodeMetadata node) {
+
+               // TODO
+               return "";
+
+       }
+
+       @Override
+       public String associatePredefinedAddress(NodeMetadata node, String ip) {
+       return "";
+    }
+
+       @Override
+       public void releaseAddress(String ip) {
+               // TODO
+       }
+
+    @Override
+    public boolean isValidRegion(String region) {
+        // TODO Auto-generated method stub
+        return false;
+    }
+
+    @Override
+    public boolean isValidZone(String region, String zone) {
+        // TODO Auto-generated method stub
+        return true;
+    }
+
+    @Override
+    public boolean isValidHost(String zone, String host) {
+        // TODO Auto-generated method stub
+        return true;
+    }
+
+    @Override
+    public PartitionValidator getPartitionValidator() {
+        return new VCloudPartitionValidator();
+    }
+
+       @Override
+       public String createVolume(int sizeGB, String snapshotId) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public String attachVolume(String instanceId, String volumeId, String 
deviceName) {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       @Override
+       public void detachVolume(String instanceId, String volumeId) {
+               // TODO Auto-generated method stub
+               
+       }
+
+       @Override
+       public void deleteVolume(String volumeId) {
+               // TODO Auto-generated method stub
+               
+       }
+
+    @Override
+    public String getIaasDevice(String device) {
+        return device;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/AWSEC2PartitionValidator.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/AWSEC2PartitionValidator.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/AWSEC2PartitionValidator.java
new file mode 100644
index 0000000..b8ecfdb
--- /dev/null
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/AWSEC2PartitionValidator.java
@@ -0,0 +1,122 @@
+/*
+ * 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.apache.stratos.cloud.controller.iaases.validators;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import 
org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
+import org.apache.stratos.cloud.controller.domain.IaasProvider;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
+import org.apache.stratos.messaging.domain.topology.Scope;
+
+import java.util.Properties;
+
+
+/**
+ * AWS-EC2 {@link PartitionValidator} implementation.
+ *
+ *
+ */
+public class AWSEC2PartitionValidator implements PartitionValidator {
+    
+    private static final Log log = 
LogFactory.getLog(AWSEC2PartitionValidator.class);
+    private IaasProvider iaasProvider;
+    private Iaas iaas;
+
+    @Override
+    public IaasProvider validate(String partitionId, Properties properties) 
throws InvalidPartitionException {
+        // validate the existence of the region and zone properties.
+        try {
+            if (properties.containsKey(Scope.region.toString())) {
+                String region = 
properties.getProperty(Scope.region.toString());
+                
+                if (iaasProvider.getImage() != null && 
!iaasProvider.getImage().contains(region)) {
+
+                    String msg =
+                                 "Invalid Partition Detected : " + partitionId 
+
+                                         " - Cause: Invalid Region: " + region;
+                    log.error(msg);
+                    throw new InvalidPartitionException(msg);
+                } 
+                
+                iaas.isValidRegion(region);
+                
+                IaasProvider updatedIaasProvider = new 
IaasProvider(iaasProvider);
+                
+                Iaas updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+                updatedIaas.setIaasProvider(updatedIaasProvider);
+                
+                if (properties.containsKey(Scope.zone.toString())) {
+                    String zone = 
properties.getProperty(Scope.zone.toString());
+                    iaas.isValidZone(region, zone);
+                    
updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, 
zone);
+                    updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+                    updatedIaas.setIaasProvider(updatedIaasProvider);
+                } 
+                
+                updateOtherProperties(updatedIaasProvider, properties);
+                
+                return updatedIaasProvider;
+                
+            } else {
+                
+                return iaasProvider;
+            }
+        } catch (Exception ex) {
+            String msg = "Invalid Partition Detected : "+partitionId+". Cause: 
"+ex.getMessage();
+            log.error(msg, ex);
+            throw new InvalidPartitionException(msg, ex);
+        }
+        
+    }
+
+    private void updateOtherProperties(IaasProvider updatedIaasProvider,
+                       Properties properties) {
+       Iaas updatedIaas;
+               try {
+                       updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+
+                       for (Object property : properties.keySet()) {
+                               if (property instanceof String) {
+                                       String key = (String) property;
+                                       updatedIaasProvider.setProperty(key,
+                                                       
properties.getProperty(key));
+                                       if (log.isDebugEnabled()) {
+                                               log.debug("Added property " + 
key
+                                                               + " to the 
IaasProvider.");
+                                       }
+                               }
+                       }
+                       updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+                       updatedIaas.setIaasProvider(updatedIaasProvider);
+               } catch (InvalidIaasProviderException ignore) {
+               }
+       
+       }
+
+       @Override
+    public void setIaasProvider(IaasProvider iaas) {
+        this.iaasProvider = iaas;
+        this.iaas = iaas.getIaas();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/CloudstackPartitionValidator.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/CloudstackPartitionValidator.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/CloudstackPartitionValidator.java
new file mode 100644
index 0000000..9b3d159
--- /dev/null
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/CloudstackPartitionValidator.java
@@ -0,0 +1,52 @@
+package org.apache.stratos.cloud.controller.iaases.validators;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
+import org.apache.stratos.cloud.controller.domain.IaasProvider;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
+import org.apache.stratos.messaging.domain.topology.Scope;
+
+import java.util.Properties;
+
+
+public class CloudstackPartitionValidator implements PartitionValidator {
+
+
+    private static final Log log = 
LogFactory.getLog(AWSEC2PartitionValidator.class);
+    private IaasProvider iaasProvider;
+    private Iaas iaas;
+
+
+    @Override
+    public void setIaasProvider(IaasProvider iaas) {
+        this.iaasProvider = iaas;
+        this.iaas = iaas.getIaas();
+    }
+
+    @Override
+    public IaasProvider validate(String partitionId, Properties properties) 
throws InvalidPartitionException {
+
+        try {
+            IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider);
+            Iaas updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+            updatedIaas.setIaasProvider(updatedIaasProvider);
+
+            if (properties.containsKey(Scope.zone.toString())) {
+                String zone = properties.getProperty(Scope.zone.toString());
+                iaas.isValidZone(null, zone);
+                
updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, 
zone);
+                updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider);
+                updatedIaas.setIaasProvider(updatedIaasProvider);
+            }
+
+        } catch (Exception ex) {
+            String msg = "Invalid Partition Detected : "+partitionId+". Cause: 
"+ex.getMessage();
+            log.error(msg, ex);
+            throw new InvalidPartitionException(msg, ex);
+        }
+        return iaasProvider;
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/DockerPartitionValidator.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/DockerPartitionValidator.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/DockerPartitionValidator.java
new file mode 100644
index 0000000..5c00c4c
--- /dev/null
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/DockerPartitionValidator.java
@@ -0,0 +1,78 @@
+/*
+ * 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.apache.stratos.cloud.controller.iaases.validators;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import 
org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
+import org.apache.stratos.cloud.controller.iaases.AWSEC2Iaas;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
+import org.apache.stratos.cloud.controller.domain.IaasProvider;
+import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
+
+import java.util.Properties;
+
+/**
+ * Docker partition validator definition.
+ */
+public class DockerPartitionValidator implements PartitionValidator {
+    private static final Log log = LogFactory.getLog(AWSEC2Iaas.class);
+
+    private IaasProvider iaasProvider;
+
+    @Override
+    public void setIaasProvider(IaasProvider iaasProvider) {
+        this.iaasProvider = iaasProvider;
+    }
+
+    @Override
+    public IaasProvider validate(String partitionId, Properties properties) 
throws InvalidPartitionException {
+       // in Docker case currently we only update the custom properties passed 
via Partitions, and
+       // no validation done as of now.
+       IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider);
+       updateOtherProperties(updatedIaasProvider, properties);
+        return updatedIaasProvider;
+    }
+    
+    private void updateOtherProperties(IaasProvider updatedIaasProvider,
+                       Properties properties) {
+       Iaas updatedIaas;
+               try {
+                       updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+
+                       for (Object property : properties.keySet()) {
+                               if (property instanceof String) {
+                                       String key = (String) property;
+                                       updatedIaasProvider.setProperty(key,
+                                                       
properties.getProperty(key));
+                                       if (log.isDebugEnabled()) {
+                                               log.debug("Added property " + 
key
+                                                               + " to the 
IaasProvider.");
+                                       }
+                               }
+                       }
+                       updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+                       updatedIaas.setIaasProvider(updatedIaasProvider);
+               } catch (InvalidIaasProviderException ignore) {
+               }
+       
+       }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/GCEPartitionValidator.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/GCEPartitionValidator.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/GCEPartitionValidator.java
new file mode 100644
index 0000000..f1b4556
--- /dev/null
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/GCEPartitionValidator.java
@@ -0,0 +1,53 @@
+/*
+ * 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.apache.stratos.cloud.controller.iaases.validators;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
+import org.apache.stratos.cloud.controller.domain.IaasProvider;
+
+
+/**
+ * The VCloud {@link PartitionValidator} implementation.
+ *
+ */
+public class GCEPartitionValidator implements PartitionValidator {
+    
+    private static final Log log = 
LogFactory.getLog(VCloudPartitionValidator.class);
+    private IaasProvider iaasProvider;
+    private Iaas iaas;
+
+    @Override
+    public IaasProvider validate(String partitionId, Properties properties) 
throws InvalidPartitionException {
+        //TODO: implement real validation logic 
+        return iaasProvider;
+       
+    }
+
+    @Override
+    public void setIaasProvider(IaasProvider iaas) {
+        this.iaasProvider = iaas;
+        this.iaas = iaas.getIaas();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/OpenstackNovaPartitionValidator.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/OpenstackNovaPartitionValidator.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/OpenstackNovaPartitionValidator.java
new file mode 100644
index 0000000..1983e08
--- /dev/null
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/OpenstackNovaPartitionValidator.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.apache.stratos.cloud.controller.iaases.validators;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import 
org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
+import org.apache.stratos.cloud.controller.domain.IaasProvider;
+import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
+import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
+import org.apache.stratos.messaging.domain.topology.Scope;
+
+import java.util.Properties;
+
+
+/**
+ * The Openstack Nova {@link PartitionValidator} implementation.
+ *
+ *
+ */
+public class OpenstackNovaPartitionValidator implements PartitionValidator {
+    
+    private static final Log log = 
LogFactory.getLog(OpenstackNovaPartitionValidator.class);
+    private IaasProvider iaasProvider;
+    private Iaas iaas;
+
+    @Override
+    public IaasProvider validate(String partitionId, Properties properties) 
throws InvalidPartitionException {
+        try {
+            // validate the existence of the zone and hosts properties.
+            if (properties.containsKey(Scope.region.toString())) {
+                String region = 
properties.getProperty(Scope.region.toString());
+                
+                if (iaasProvider.getImage() != null && 
!iaasProvider.getImage().contains(region)) {
+
+                    String msg =
+                                 "Invalid Partition Detected : " + partitionId 
+
+                                         " - Cause: Invalid Region: " + region;
+                    log.error(msg);
+                    throw new InvalidPartitionException(msg);
+                } 
+                
+                iaas.isValidRegion(region);
+                
+                IaasProvider updatedIaasProvider = new 
IaasProvider(iaasProvider);
+                Iaas updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+                updatedIaas.setIaasProvider(updatedIaasProvider);
+                
+                if (properties.containsKey(Scope.zone.toString())) {
+                    String zone = 
properties.getProperty(Scope.zone.toString());
+                    iaas.isValidZone(region, zone);
+                    
+                    
updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, 
zone);
+                    updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+                    updatedIaas.setIaasProvider(updatedIaasProvider);
+                } 
+                
+                updateOtherProperties(updatedIaasProvider, properties);
+                
+                return updatedIaasProvider;
+                
+            } else {
+
+                return iaasProvider;
+            }
+        } catch (Exception ex) {
+            String msg = "Invalid Partition Detected : "+partitionId+". Cause: 
"+ex.getMessage();
+            log.error(msg, ex);
+            throw new InvalidPartitionException(msg, ex);
+        }
+    }
+    
+    private void updateOtherProperties(IaasProvider updatedIaasProvider,
+                       Properties properties) {
+       Iaas updatedIaas;
+               try {
+                       updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+
+                       for (Object property : properties.keySet()) {
+                               if (property instanceof String) {
+                                       String key = (String) property;
+                                       updatedIaasProvider.setProperty(key,
+                                                       
properties.getProperty(key));
+                                       if (log.isDebugEnabled()) {
+                                               log.debug("Added property " + 
key
+                                                               + " to the 
IaasProvider.");
+                                       }
+                               }
+                       }
+                       updatedIaas = 
CloudControllerUtil.getIaas(updatedIaasProvider);
+                       updatedIaas.setIaasProvider(updatedIaasProvider);
+               } catch (InvalidIaasProviderException ignore) {
+               }
+       
+       }
+
+    @Override
+    public void setIaasProvider(IaasProvider iaas) {
+        this.iaasProvider = iaas;
+        this.iaas = iaas.getIaas();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/PartitionValidator.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/PartitionValidator.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/PartitionValidator.java
new file mode 100644
index 0000000..162713a
--- /dev/null
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/PartitionValidator.java
@@ -0,0 +1,47 @@
+/*
+ * 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.apache.stratos.cloud.controller.iaases.validators;
+
+import java.util.Properties;
+
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
+import org.apache.stratos.cloud.controller.domain.IaasProvider;
+
+/**
+ * All the Partition Validators should implement this interface.
+ *
+ *
+ */
+public interface PartitionValidator {
+    
+    /**
+     * set the IaasProvider reference.
+     * @param iaas {@link IaasProvider}
+     */
+    public void setIaasProvider(IaasProvider iaas);
+
+    /**
+     * Validate the given properties for its existent in this partition.
+     * @param partitionId partition id.
+     * @param properties set of properties to be validated.
+     * @return cloned and modified {@link IaasProvider} which maps to the 
given partition. 
+     * @throws InvalidPartitionException if at least one property is evaluated 
to be invalid.
+     */
+    public IaasProvider validate(String partitionId, Properties properties) 
throws InvalidPartitionException;
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/VCloudPartitionValidator.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/VCloudPartitionValidator.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/VCloudPartitionValidator.java
new file mode 100644
index 0000000..8af42d7
--- /dev/null
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/validators/VCloudPartitionValidator.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.apache.stratos.cloud.controller.iaases.validators;
+
+import java.util.Properties;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.cloud.controller.exception.InvalidPartitionException;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
+import org.apache.stratos.cloud.controller.domain.IaasProvider;
+
+
+/**
+ * The VCloud {@link PartitionValidator} implementation.
+ *
+ */
+public class VCloudPartitionValidator implements PartitionValidator {
+    
+    @SuppressWarnings("unused")
+       private static final Log log = 
LogFactory.getLog(VCloudPartitionValidator.class);
+    private IaasProvider iaasProvider;
+    @SuppressWarnings("unused")
+       private Iaas iaas;
+
+    @Override
+    public IaasProvider validate(String partitionId, Properties properties) 
throws InvalidPartitionException {
+        //TODO: implement real validation logic 
+        return iaasProvider;
+       
+    }
+
+    @Override
+    public void setIaasProvider(IaasProvider iaas) {
+        this.iaasProvider = iaas;
+        this.iaas = iaas.getIaas();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
index ae3a7ae..8bddbfc 100644
--- 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java
@@ -37,7 +37,6 @@ import org.apache.stratos.cloud.controller.exception.*;
 import 
org.apache.stratos.cloud.controller.functions.ContainerClusterContextToKubernetesService;
 import 
org.apache.stratos.cloud.controller.functions.ContainerClusterContextToReplicationController;
 import org.apache.stratos.cloud.controller.functions.PodToMemberContext;
-import org.apache.stratos.cloud.controller.iaas.Iaas;
 import 
org.apache.stratos.cloud.controller.messaging.publisher.CartridgeInstanceDataPublisher;
 import org.apache.stratos.cloud.controller.services.CloudControllerService;
 import org.apache.stratos.cloud.controller.messaging.topology.TopologyBuilder;
@@ -46,7 +45,8 @@ import 
org.apache.stratos.cloud.controller.messaging.topology.TopologyManager;
 import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
 import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
 import org.apache.stratos.cloud.controller.util.PodActivationWatcher;
-import org.apache.stratos.cloud.controller.iaas.validators.PartitionValidator;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
+import 
org.apache.stratos.cloud.controller.iaases.validators.PartitionValidator;
 import org.apache.stratos.common.*;
 import org.apache.stratos.common.constants.StratosConstants;
 import org.apache.stratos.kubernetes.client.KubernetesApiClient;

http://git-wip-us.apache.org/repos/asf/stratos/blob/0984bcef/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
index 40b2459..89131e3 100644
--- 
a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
+++ 
b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/CloudControllerUtil.java
@@ -24,10 +24,9 @@ import org.apache.commons.logging.LogFactory;
 import org.apache.stratos.cloud.controller.config.CloudControllerConfig;
 import org.apache.stratos.cloud.controller.context.CloudControllerContext;
 import org.apache.stratos.cloud.controller.domain.*;
-import org.apache.stratos.cloud.controller.domain.Partition;
 import org.apache.stratos.cloud.controller.exception.CloudControllerException;
 import 
org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException;
-import org.apache.stratos.cloud.controller.iaas.Iaas;
+import org.apache.stratos.cloud.controller.iaases.Iaas;
 import org.apache.stratos.cloud.controller.registry.Deserializer;
 import org.apache.stratos.cloud.controller.registry.RegistryManager;
 import org.apache.stratos.common.Property;

Reply via email to