You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2013/11/27 19:55:10 UTC
[13/26] CC refactoring, API cleaning r1
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
index ec0e198..34b652a 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
@@ -1,23 +1,24 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
+ * 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
+ * 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
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * 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
+ * "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.deployers;
+import org.apache.axiom.om.OMElement;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.deployment.AbstractDeployer;
import org.apache.axis2.deployment.DeploymentException;
@@ -25,6 +26,8 @@ import org.apache.axis2.deployment.repository.util.DeploymentFileData;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.axiom.AxiomXpathParser;
+import org.apache.stratos.cloud.controller.axiom.AxiomXpathParserUtil;
+import org.apache.stratos.cloud.controller.axiom.parser.CloudControllerConfigParser;
import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
import org.apache.stratos.cloud.controller.util.IaasProvider;
@@ -34,79 +37,74 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
- * All the {@link IaasProvider}s will get deployed / undeployed / updated via this class.
+ * All the {@link IaasProvider}s will get deployed / undeployed / updated via this class.
*/
-public class CloudControllerDeployer extends AbstractDeployer{
-
+public class CloudControllerDeployer extends AbstractDeployer {
+
private static final Log log = LogFactory.getLog(CloudControllerDeployer.class);
private static final String FILE_NAME = "cloud-controller";
private Map<String, List<IaasProvider>> fileToIaasProviderListMap;
@Override
public void init(ConfigurationContext arg0) {
- fileToIaasProviderListMap = new ConcurrentHashMap<String, List<IaasProvider>>();
+ fileToIaasProviderListMap = new ConcurrentHashMap<String, List<IaasProvider>>();
}
@Override
public void setDirectory(String arg0) {
// component xml handles this
-
+
}
@Override
public void setExtension(String arg0) {
// component xml handles this
}
-
+
public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
-
- log.debug("Started to deploy the deployment artifact: "+deploymentFileData.getFile());
-
+
+ log.debug("Started to deploy the deployment artifact: " + deploymentFileData.getFile());
+
// since cloud-controller.xml resides in repository/conf
- if (deploymentFileData.getName().contains(FILE_NAME)) {
+ if (deploymentFileData.getName().contains(FILE_NAME)) {
- AxiomXpathParser parser = new AxiomXpathParser(deploymentFileData.getFile());
+ OMElement docElt = AxiomXpathParserUtil.parse(deploymentFileData.getFile());
- // parse the file
- parser.parse();
+ CloudControllerConfigParser.parse(docElt);
- // load iaases
- parser.setIaasProvidersList();
- parser.setPartitionsList();
- parser.setDataPublisherRelatedData();
- parser.setTopologySyncRelatedData();
+ // update map
+ fileToIaasProviderListMap.put(deploymentFileData.getAbsolutePath(),
+ new ArrayList<IaasProvider>(
+ FasterLookUpDataHolder.getInstance()
+ .getIaasProviders()));
- // update map
- fileToIaasProviderListMap.put(deploymentFileData.getAbsolutePath(),
- new ArrayList<IaasProvider>(
- FasterLookUpDataHolder.getInstance()
- .getIaasProviders()));
+ log.info("Successfully deployed the cloud-controller XML file located at " +
+ deploymentFileData.getAbsolutePath());
+ }
- log.info("Successfully deployed the cloud-controller XML file specified at " +
- deploymentFileData.getAbsolutePath());
- }
-
}
-
public void undeploy(String file) throws DeploymentException {
-
+
if (file.contains(FILE_NAME)) {
// reset
- FasterLookUpDataHolder.getInstance().setSerializationDir("");
-
+ FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
+ dataHolder.setSerializationDir("");
+
// grab the entry from Map
- if(fileToIaasProviderListMap.containsKey(file)){
+ if (fileToIaasProviderListMap.containsKey(file)) {
// remove 'em
- FasterLookUpDataHolder.getInstance().getIaasProviders().removeAll(fileToIaasProviderListMap.get(file));
-
- log.info("Successfully undeployed the cloud-controller XML file specified at "+file);
+ dataHolder.getIaasProviders().removeAll(fileToIaasProviderListMap.get(file));
+
+ log.info("Successfully undeployed the cloud-controller XML file specified at " +
+ file);
}
- // only one cloud-controller file, hence delete 'em all
-// FasterLookUpDataHolder.getInstance().setIaasProviders(new ArrayList<IaasProvider>());
-
+
+ dataHolder.setDataPubConfig(null);
+ dataHolder.setTopologyConfig(null);
+
}
-
+
}
}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
index fcf2a61..a0418ae 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
@@ -18,6 +18,7 @@
*/
package org.apache.stratos.cloud.controller.deployers;
+import org.apache.axiom.om.OMElement;
import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.deployment.AbstractDeployer;
import org.apache.axis2.deployment.DeploymentException;
@@ -25,6 +26,9 @@ import org.apache.axis2.deployment.repository.util.DeploymentFileData;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.cloud.controller.axiom.AxiomXpathParser;
+import org.apache.stratos.cloud.controller.axiom.AxiomXpathParserUtil;
+import org.apache.stratos.cloud.controller.axiom.parser.ServiceConfigParser;
+import org.apache.stratos.cloud.controller.exception.MalformedConfigurationFileException;
import org.apache.stratos.cloud.controller.topology.TopologyBuilder;
import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
import org.apache.stratos.cloud.controller.util.ServiceContext;
@@ -39,110 +43,110 @@ import java.util.concurrent.ConcurrentHashMap;
/**
* All the {@link org.apache.stratos.cloud.controller.util.Cartridge}s will get deployed / undeployed / updated via this class.
*/
-public class ServiceDeployer extends AbstractDeployer{
+//public class ServiceDeployer extends AbstractDeployer{
- private static final Log log = LogFactory.getLog(ServiceDeployer.class);
-
- private FasterLookUpDataHolder serviceContextLookUpStructure;
- private Map<String, List<ServiceContext>> fileToServiceContextListMap;
- private File servicesSchema, serviceSchema;
-
- @Override
- public void init(ConfigurationContext arg0) {
- fileToServiceContextListMap = new ConcurrentHashMap<String, List<ServiceContext>>();
- String etcDir = CarbonUtils.getCarbonConfigDirPath() + File.separator + "etc" + File.separator;
- servicesSchema = new File(etcDir+"services.xsd");
- serviceSchema = new File(etcDir+"service.xsd");
- }
-
- @Override
- public void setDirectory(String arg0) {
- // component xml handles this
- }
-
- @Override
- public void setExtension(String arg0) {
- // component xml handles this
- }
-
- public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
-
- log.debug("Started to deploy the deployment artefact: "+deploymentFileData.getFile());
- serviceContextLookUpStructure = FasterLookUpDataHolder.getInstance();
-
- AxiomXpathParser parser = new AxiomXpathParser(deploymentFileData.getFile());
- parser.parse();
-
- // validate
- try {
- validateService(parser);
-
- } catch (Exception e) {
- String msg = "Invalid deployment artefact at "+deploymentFileData.getAbsolutePath();
- // back up the file
- File f = deploymentFileData.getFile();
- f.renameTo(new File(deploymentFileData.getAbsolutePath()+".back"));
- log.error(msg, e);
- throw new DeploymentException(msg, e);
- }
-
- // deploy
- List<ServiceContext> services = parser.getServiceContexts();
-
-
-
- // update map
- fileToServiceContextListMap.put(deploymentFileData.getAbsolutePath(), new ArrayList<ServiceContext>(services));
-
- log.info("Successfully deployed the Service definition specified at "+deploymentFileData.getAbsolutePath());
- }
-
- private void validateService(AxiomXpathParser parser) throws Exception {
- boolean validated = false;
- Exception firstException = null;
-
- try{
- // first try to validate using services schema
- parser.validate(servicesSchema);
- validated = true;
- log.debug("Service validation was successful.");
-
- }catch (Exception e) {
- firstException = e;
- }
-
- if(!validated){
- try{
- // Now try to validate using service schema
- parser.validate(serviceSchema);
- validated = true;
- log.debug("Service validation was successful.");
-
- }catch (Exception e) {
- String msg = "Service XML validation failed. Invalid Service XML: "+parser.getXmlSource().getAbsolutePath();
- log.error(msg, firstException);
- throw firstException;
- }
- }
-
-
- }
-
- public void undeploy(String file) throws DeploymentException {
-
- serviceContextLookUpStructure = FasterLookUpDataHolder.getInstance();
-
- // grab the entry from Map
- if(fileToServiceContextListMap.containsKey(file)){
- // remove 'em all
- for (ServiceContext ctxt : fileToServiceContextListMap.get(file)) {
- serviceContextLookUpStructure.removeServiceContext(ctxt);
- TopologyBuilder.handleClusterRemoved(ctxt);
- // remove from the topology
- }
- log.info("Successfully undeployed the Service definition specified at "+file);
- }
-
- }
+// private static final Log log = LogFactory.getLog(ServiceDeployer.class);
+//
+// private FasterLookUpDataHolder serviceContextLookUpStructure;
+// private Map<String, List<ServiceContext>> fileToServiceContextListMap;
+// private File servicesSchema, serviceSchema;
+//
+// @Override
+// public void init(ConfigurationContext arg0) {
+// fileToServiceContextListMap = new ConcurrentHashMap<String, List<ServiceContext>>();
+// String etcDir = CarbonUtils.getCarbonConfigDirPath() + File.separator + "etc" + File.separator;
+// servicesSchema = new File(etcDir+"services.xsd");
+// serviceSchema = new File(etcDir+"service.xsd");
+// }
+//
+// @Override
+// public void setDirectory(String arg0) {
+// // component xml handles this
+// }
+//
+// @Override
+// public void setExtension(String arg0) {
+// // component xml handles this
+// }
+//
+// public void deploy(DeploymentFileData deploymentFileData) throws DeploymentException {
+//
+// File file = deploymentFileData.getFile();
+// log.debug("Started to deploy the deployment artefact: " + file);
+// serviceContextLookUpStructure = FasterLookUpDataHolder.getInstance();
+//
+// try {
+// OMElement docElt = AxiomXpathParserUtil.parse(file);
+// String fileName = file.getAbsolutePath();
+//
+// // validate
+// validateService(docElt, fileName);
+//
+// // deploy
+// List<ServiceContext> services = ServiceConfigParser.extractServiceContexts(file, docElt);
+//
+// // update map
+// fileToServiceContextListMap.put(deploymentFileData.getAbsolutePath(),
+// new ArrayList<ServiceContext>(services));
+//
+// log.info("Successfully deployed the Service definition specified at " +
+// deploymentFileData.getAbsolutePath());
+// } catch (Exception e) {
+// String msg = "Invalid deployment artefact at " + deploymentFileData.getAbsolutePath();
+// // back up the file
+// File f = file;
+// f.renameTo(new File(deploymentFileData.getAbsolutePath() + ".back"));
+// log.error(msg, e);
+// throw new DeploymentException(msg, e);
+// }
+// }
+//
+// private void validateService(final OMElement elt, final String fileName) throws Exception {
+// boolean validated = false;
+// Exception firstException = null;
+//
+// try{
+// // first try to validate using services schema
+// AxiomXpathParserUtil.validate(elt, servicesSchema);
+// validated = true;
+// log.debug("Service validation was successful.");
+//
+// }catch (Exception e) {
+// firstException = e;
+// }
+//
+// if(!validated){
+// try{
+// // Now try to validate using service schema
+// AxiomXpathParserUtil.validate(elt, serviceSchema);
+// validated = true;
+// log.debug("Service validation was successful.");
+//
+// }catch (Exception e) {
+// String msg = "Service XML validation failed. Invalid Service XML: "+fileName;
+// log.error(msg, firstException);
+// throw new MalformedConfigurationFileException(msg, firstException);
+// }
+// }
+//
+//
+// }
+//
+// public void undeploy(String file) throws DeploymentException {
+//
+// serviceContextLookUpStructure = FasterLookUpDataHolder.getInstance();
+//
+// // grab the entry from Map
+// if(fileToServiceContextListMap.containsKey(file)){
+// // remove 'em all
+// for (ServiceContext ctxt : fileToServiceContextListMap.get(file)) {
+// serviceContextLookUpStructure.removeServiceContext(ctxt);
+// TopologyBuilder.handleClusterRemoved(ctxt);
+// // remove from the topology
+// }
+// log.info("Successfully undeployed the Service definition specified at "+file);
+// }
+//
+// }
-}
+//}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeTypeException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeTypeException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeTypeException.java
new file mode 100644
index 0000000..47b004a
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeTypeException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.exception;
+
+
+/**
+ * Throws when a {@link Partition} is evaluated to be invalid.
+ * @author nirmal
+ *
+ */
+public class InvalidCartridgeTypeException extends Exception {
+
+ private static final long serialVersionUID = 8060893118810908075L;
+
+ public InvalidCartridgeTypeException(String msg) {
+ super(msg);
+ }
+
+ public InvalidCartridgeTypeException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidClusterException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidClusterException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidClusterException.java
new file mode 100644
index 0000000..c003fd0
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidClusterException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.exception;
+
+
+/**
+ * Throws when a {@link Partition} is evaluated to be invalid.
+ * @author nirmal
+ *
+ */
+public class InvalidClusterException extends Exception {
+
+ private static final long serialVersionUID = -7883324379272628566L;
+
+ public InvalidClusterException(String msg) {
+ super(msg);
+ }
+
+ public InvalidClusterException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidHostException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidHostException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidHostException.java
new file mode 100644
index 0000000..83dfba0
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidHostException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.exception;
+
+
+/**
+ * Throws when a {@link Partition} is evaluated to be invalid.
+ * @author nirmal
+ *
+ */
+public class InvalidHostException extends Exception {
+
+ private static final long serialVersionUID = 9125466293508957338L;
+
+ public InvalidHostException(String msg) {
+ super(msg);
+ }
+
+ public InvalidHostException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidIaasProviderException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidIaasProviderException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidIaasProviderException.java
new file mode 100644
index 0000000..ee98f0e
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidIaasProviderException.java
@@ -0,0 +1,39 @@
+/*
+ * 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.exception;
+
+import org.apache.stratos.cloud.controller.util.IaasProvider;
+
+/**
+ * Throws when a {@link IaasProvider} is evaluated to be invalid.
+ * @author nirmal
+ *
+ */
+public class InvalidIaasProviderException extends Exception {
+
+ private static final long serialVersionUID = 2453133690565031869L;
+
+ public InvalidIaasProviderException(String msg) {
+ super(msg);
+ }
+
+ public InvalidIaasProviderException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidMemberException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidMemberException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidMemberException.java
new file mode 100644
index 0000000..3b6677c
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidMemberException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.exception;
+
+
+/**
+ * Throws when a {@link Partition} is evaluated to be invalid.
+ * @author nirmal
+ *
+ */
+public class InvalidMemberException extends Exception {
+
+ private static final long serialVersionUID = -7883324379272628566L;
+
+ public InvalidMemberException(String msg) {
+ super(msg);
+ }
+
+ public InvalidMemberException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidPartitionException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidPartitionException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidPartitionException.java
new file mode 100644
index 0000000..e842ad9
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidPartitionException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.exception;
+
+
+/**
+ * Throws when a {@link Partition} is evaluated to be invalid.
+ * @author nirmal
+ *
+ */
+public class InvalidPartitionException extends Exception {
+
+ private static final long serialVersionUID = 5403224496111965638L;
+
+ public InvalidPartitionException(String msg) {
+ super(msg);
+ }
+
+ public InvalidPartitionException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidRegionException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidRegionException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidRegionException.java
new file mode 100644
index 0000000..c85502a
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidRegionException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.exception;
+
+
+/**
+ * Throws when a {@link Partition} is evaluated to be invalid.
+ * @author nirmal
+ *
+ */
+public class InvalidRegionException extends Exception {
+
+ private static final long serialVersionUID = -7883324379272628566L;
+
+ public InvalidRegionException(String msg) {
+ super(msg);
+ }
+
+ public InvalidRegionException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidZoneException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidZoneException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidZoneException.java
new file mode 100644
index 0000000..435587b
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidZoneException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.stratos.cloud.controller.exception;
+
+
+/**
+ * Throws when a {@link Partition} is evaluated to be invalid.
+ * @author nirmal
+ *
+ */
+public class InvalidZoneException extends Exception {
+
+ private static final long serialVersionUID = 1830765777991647319L;
+
+ public InvalidZoneException(String msg) {
+ super(msg);
+ }
+
+ public InvalidZoneException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredClusterException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredClusterException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredClusterException.java
new file mode 100644
index 0000000..0a17376
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredClusterException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.exception;
+
+public class UnregisteredClusterException extends Exception {
+
+ private static final long serialVersionUID = -6326227079367867222L;
+
+ public UnregisteredClusterException(String msg) {
+ super(msg);
+ }
+
+ public UnregisteredClusterException(String msg, Exception ex) {
+ super(msg, ex);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java
deleted file mode 100644
index d7bba93..0000000
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java
+++ /dev/null
@@ -1,33 +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.apache.stratos.cloud.controller.exception;
-
-public class UnregisteredServiceException extends Exception {
-
- private static final long serialVersionUID = -6326227079367867222L;
-
- public UnregisteredServiceException(String msg) {
- super(msg);
- }
-
- public UnregisteredServiceException(String msg, Exception ex) {
- super(msg, ex);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
index debaea5..a754e2f 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
@@ -145,12 +145,12 @@ public class CassandraDataRetriever {
private static void getCassandraKeyspace() {
if (cluster == null) {
Map<String, String> credentials = new HashMap<String, String>();
- credentials.put("username", dataHolder.getCassandraUser());
- credentials.put("password", dataHolder.getCassandraPassword());
+ credentials.put("username", dataHolder.getDataPubConfig().getCassandraUser());
+ credentials.put("password", dataHolder.getDataPubConfig().getCassandraPassword());
cluster =
retrieveCassandraCluster(CloudControllerConstants.DEFAULT_CASSANDRA_CLUSTER_NAME,
- dataHolder.getCassandraConnUrl(), credentials);
+ dataHolder.getDataPubConfig().getCassandraConnUrl(), credentials);
keyspace =
HFactory.createKeyspace(CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE,
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
index 2cda0a7..31bbf4e 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
@@ -57,8 +57,8 @@ public class HiveQueryExecutor {
// admin service authentication
authenticator = new HttpTransportProperties.Authenticator();
- authenticator.setUsername(dataHolder.getBamUsername());
- authenticator.setPassword(dataHolder.getBamPassword());
+ authenticator.setUsername(dataHolder.getDataPubConfig().getBamUsername());
+ authenticator.setPassword(dataHolder.getDataPubConfig().getBamPassword());
authenticator.setPreemptiveAuthentication(true);
ServiceClient client = hiveService._getServiceClient();
@@ -101,11 +101,11 @@ public class HiveQueryExecutor {
payloadPrefix+CloudControllerConstants.STATUS_COL+" STRING," +
payloadPrefix+CloudControllerConstants.SUB_DOMAIN_COL+" STRING" +
") STORED BY 'org.apache.hadoop.hive.cassandra.CassandraStorageHandler' " +
- "WITH SERDEPROPERTIES ( \"cassandra.host\" = \""+dataHolder.getCassandraConnUrl().split(":")[0]+"\"," +
- "\"cassandra.port\" = \""+dataHolder.getCassandraConnUrl().split(":")[1]+
+ "WITH SERDEPROPERTIES ( \"cassandra.host\" = \""+dataHolder.getDataPubConfig().getCassandraConnUrl().split(":")[0]+"\"," +
+ "\"cassandra.port\" = \""+dataHolder.getDataPubConfig().getCassandraConnUrl().split(":")[1]+
"\",\"cassandra.ks.name\" = \""+CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE+"\"," +
- "\"cassandra.ks.username\" = \""+dataHolder.getCassandraUser()+
- "\", \"cassandra.ks.password\" = \""+dataHolder.getCassandraPassword()+"\"," +
+ "\"cassandra.ks.username\" = \""+dataHolder.getDataPubConfig().getCassandraUser()+
+ "\", \"cassandra.ks.password\" = \""+dataHolder.getDataPubConfig().getCassandraPassword()+"\"," +
"\"cassandra.cf.name\" = \""+CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY+"\"," +
"\"cassandra.columns.mapping\" = \"" +
payloadPrefix+CloudControllerConstants.NODE_ID_COL+"," +
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
index 36bcdd3..a591607 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
@@ -25,6 +25,9 @@ import com.google.common.collect.Lists;
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.exception.InvalidHostException;
+import org.apache.stratos.cloud.controller.exception.InvalidRegionException;
+import org.apache.stratos.cloud.controller.exception.InvalidZoneException;
import org.apache.stratos.cloud.controller.interfaces.Iaas;
import org.apache.stratos.cloud.controller.jcloud.ComputeServiceBuilderUtil;
import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
@@ -43,6 +46,8 @@ import org.jclouds.compute.domain.Template;
import org.jclouds.compute.domain.TemplateBuilder;
import org.jclouds.compute.options.TemplateOptions;
import org.jclouds.ec2.EC2Api;
+import org.jclouds.ec2.EC2ApiMetadata;
+import org.jclouds.ec2.EC2Client;
import org.jclouds.ec2.domain.AvailabilityZoneInfo;
import org.jclouds.ec2.domain.KeyPair;
import org.jclouds.ec2.domain.PublicIpInstanceIdPair;
@@ -87,9 +92,9 @@ public class AWSEC2Iaas extends Iaas {
templateBuilder.locationId(iaas.getType());
}
- if (iaas.getProperty("instanceType") != null) {
+ if (iaas.getProperty(CloudControllerConstants.INSTANCE_TYPE) != null) {
// set instance type eg: m1.large
- templateBuilder.hardwareId(iaas.getProperty("instanceType"));
+ templateBuilder.hardwareId(iaas.getProperty(CloudControllerConstants.INSTANCE_TYPE));
}
// build the Template
@@ -100,7 +105,7 @@ public class AWSEC2Iaas extends Iaas {
// wish to assign IPs manually, it can be non-blocking.
// is auto-assign-ip mode or manual-assign-ip mode?
boolean blockUntilRunning = Boolean.parseBoolean(iaas
- .getProperty("autoAssignIp"));
+ .getProperty(CloudControllerConstants.AUTO_ASSIGN_IP));
template.getOptions().as(TemplateOptions.class)
.blockUntilRunning(blockUntilRunning);
@@ -110,31 +115,31 @@ public class AWSEC2Iaas extends Iaas {
.inboundPorts(new int[] {});
// set EC2 specific options
- if (iaas.getProperty("subnetId") != null) {
+ if (iaas.getProperty(CloudControllerConstants.SUBNET_ID) != null) {
template.getOptions().as(AWSEC2TemplateOptions.class)
- .subnetId(iaas.getProperty("subnetId"));
+ .subnetId(iaas.getProperty(CloudControllerConstants.SUBNET_ID));
}
- if (iaas.getProperty("availabilityZone") != null) {
+ if (iaas.getProperty(CloudControllerConstants.AVAILABILITY_ZONE) != null) {
template.getOptions().as(AWSEC2TemplateOptions.class)
- .placementGroup(iaas.getProperty("availabilityZone"));
+ .placementGroup(iaas.getProperty(CloudControllerConstants.AVAILABILITY_ZONE));
}
// security group names
- if (iaas.getProperty("securityGroups") != null) {
+ if (iaas.getProperty(CloudControllerConstants.SECURITY_GROUPS) != null) {
template.getOptions()
.as(AWSEC2TemplateOptions.class)
.securityGroups(
- iaas.getProperty("securityGroups").split(
+ iaas.getProperty(CloudControllerConstants.SECURITY_GROUPS).split(
CloudControllerConstants.ENTRY_SEPARATOR));
}
// security group ids
- if (iaas.getProperty("securityGroupIds") != null) {
+ if (iaas.getProperty(CloudControllerConstants.SECURITY_GROUP_IDS) != null) {
template.getOptions()
.as(AWSEC2TemplateOptions.class)
- .securityGroupIds(iaas.getProperty("securityGroupIds")
+ .securityGroupIds(iaas.getProperty(CloudControllerConstants.SECURITY_GROUP_IDS)
.split(CloudControllerConstants.ENTRY_SEPARATOR));
}
@@ -150,9 +155,9 @@ public class AWSEC2Iaas extends Iaas {
+ iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER)));
}*/
- if (iaas.getProperty("keyPair") != null) {
+ if (iaas.getProperty(CloudControllerConstants.KEY_PAIR) != null) {
template.getOptions().as(AWSEC2TemplateOptions.class)
- .keyPair(iaas.getProperty("keyPair"));
+ .keyPair(iaas.getProperty(CloudControllerConstants.KEY_PAIR));
}
// set Template
@@ -307,9 +312,18 @@ public class AWSEC2Iaas extends Iaas {
}
@Override
- public boolean isValidRegion(IaasProvider iaasInfo, String region) {
+ public boolean isValidRegion(IaasProvider iaasInfo, String region) throws InvalidRegionException {
+
+ if (region == null || iaasInfo == null) {
+ String msg =
+ "Region or IaaSProvider is null: region: " + region + " - IaaSProvider: " +
+ iaasInfo;
+ log.error(msg);
+ throw new InvalidRegionException(msg);
+ }
+
ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- EC2Api api = context.unwrap();
+ EC2Client api = EC2Client.class.cast(context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi());
for (String configuredRegion : api.getConfiguredRegions()) {
if (region.equalsIgnoreCase(configuredRegion)) {
if (log.isDebugEnabled()) {
@@ -318,16 +332,22 @@ public class AWSEC2Iaas extends Iaas {
return true;
}
}
- if (log.isDebugEnabled()) {
- log.debug("Did not find a matching region: " + region);
- }
- return false;
+ String msg = "Invalid region: " + region +" in the iaas: "+iaasInfo.getType();
+ log.error(msg);
+ throw new InvalidRegionException(msg);
}
@Override
- public boolean isValidZone(IaasProvider iaasInfo, String region, String zone) {
+ public boolean isValidZone(IaasProvider iaasInfo, String region, String zone) throws InvalidZoneException {
+ if (zone == null || iaasInfo == null) {
+ String msg =
+ "Zone or IaaSProvider is null: zone: " + zone + " - IaaSProvider: " +
+ iaasInfo;
+ log.error(msg);
+ throw new InvalidZoneException(msg);
+ }
ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- EC2Api api = context.unwrap();
+ EC2Client api = EC2Client.class.cast(context.unwrap(EC2ApiMetadata.CONTEXT_TOKEN).getApi());
AvailabilityZoneAndRegionApi zoneRegionApi =
api.getAvailabilityZoneAndRegionApiForRegion(region)
.get();
@@ -343,16 +363,19 @@ public class AWSEC2Iaas extends Iaas {
return true;
}
}
- if (log.isDebugEnabled()) {
- log.debug("Did not find a matching zone: " + zone);
- }
- return false;
+
+ String msg = "Invalid zone: " + zone +" in the region: "+region+ " and of the iaas: "+iaasInfo.getType();
+ log.error(msg);
+ throw new InvalidZoneException(msg);
+
}
@Override
- public boolean isValidHost(IaasProvider iaasInfo, String zone, String host) {
+ public boolean isValidHost(IaasProvider iaasInfo, String zone, String host) throws InvalidHostException {
// there's no such concept in EC2
- return false;
+ String msg = "Invalid host: " + host +" in the zone: "+zone+ " and of the iaas: "+iaasInfo.getType();
+ log.error(msg);
+ throw new InvalidHostException(msg);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/1654262f/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
index 7e6f961..07f7aff 100644
--- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
@@ -26,6 +26,9 @@ import com.google.common.collect.Lists;
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.exception.InvalidHostException;
+import org.apache.stratos.cloud.controller.exception.InvalidRegionException;
+import org.apache.stratos.cloud.controller.exception.InvalidZoneException;
import org.apache.stratos.cloud.controller.interfaces.Iaas;
import org.apache.stratos.cloud.controller.jcloud.ComputeServiceBuilderUtil;
import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
@@ -99,7 +102,7 @@ public class OpenstackNovaIaas extends Iaas {
String instanceType;
// set instance type
- if (((instanceType = iaas.getProperty("instanceType")) != null)) {
+ if (((instanceType = iaas.getProperty(CloudControllerConstants.INSTANCE_TYPE)) != null)) {
templateBuilder.hardwareId(instanceType);
}
@@ -111,7 +114,7 @@ public class OpenstackNovaIaas extends Iaas {
// wish to assign IPs manually, it can be non-blocking.
// is auto-assign-ip mode or manual-assign-ip mode?
boolean blockUntilRunning = Boolean.parseBoolean(iaas
- .getProperty("autoAssignIp"));
+ .getProperty(CloudControllerConstants.AUTO_ASSIGN_IP));
template.getOptions().as(TemplateOptions.class)
.blockUntilRunning(blockUntilRunning);
@@ -120,11 +123,11 @@ public class OpenstackNovaIaas extends Iaas {
template.getOptions().as(TemplateOptions.class)
.inboundPorts(new int[] {});
- if (iaas.getProperty("securityGroups") != null) {
+ if (iaas.getProperty(CloudControllerConstants.SECURITY_GROUPS) != null) {
template.getOptions()
.as(NovaTemplateOptions.class)
.securityGroupNames(
- iaas.getProperty("securityGroups").split(
+ iaas.getProperty(CloudControllerConstants.SECURITY_GROUPS).split(
CloudControllerConstants.ENTRY_SEPARATOR));
}
@@ -138,10 +141,16 @@ public class OpenstackNovaIaas extends Iaas {
+ iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER)));
}
*/
- if (iaas.getProperty("keyPair") != null) {
+ if (iaas.getProperty(CloudControllerConstants.KEY_PAIR) != null) {
template.getOptions().as(NovaTemplateOptions.class)
- .keyPairName(iaas.getProperty("keyPair"));
+ .keyPairName(CloudControllerConstants.KEY_PAIR);
}
+
+ //TODO
+// if (iaas.getProperty(CloudControllerConstants.HOST) != null) {
+// template.getOptions().as(NovaTemplateOptions.class)
+// .(CloudControllerConstants.HOST);
+// }
// set Template
iaas.setTemplate(template);
@@ -289,47 +298,51 @@ public class OpenstackNovaIaas extends Iaas {
}
@Override
- public boolean isValidRegion(IaasProvider iaasInfo, String region) {
- // jclouds doesn't support regions in Openstack-Nova API
- return false;
- }
-
- @Override
- public boolean isValidZone(IaasProvider iaasInfo, String region, String zone) {
- if (zone == null || iaasInfo == null) {
- if (log.isDebugEnabled()) {
- log.debug("Zone or IaaSProvider is null: zone: " + zone + " - IaaSProvider: " +
- iaasInfo);
- }
- return false;
+ public boolean isValidRegion(IaasProvider iaasInfo, String region) throws InvalidRegionException {
+ // jclouds' zone = region in openstack
+ if (region == null || iaasInfo == null) {
+ String msg =
+ "Region or IaaSProvider is null: region: " + region + " - IaaSProvider: " +
+ iaasInfo;
+ log.error(msg);
+ throw new InvalidRegionException(msg);
}
+
ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- NovaApi api = context.unwrap();
+ NovaApi api = context.unwrap(NovaApiMetadata.CONTEXT_TOKEN).getApi();
for (String configuredZone : api.getConfiguredZones()) {
- if (zone.equalsIgnoreCase(configuredZone)) {
+ if (region.equalsIgnoreCase(configuredZone)) {
if (log.isDebugEnabled()) {
- log.debug("Found a matching zone: " + zone);
+ log.debug("Found a matching region: " + region);
}
return true;
}
}
- if (log.isDebugEnabled()) {
- log.debug("Did not find a matching zone: " + zone);
- }
- return false;
+
+ String msg = "Invalid region: " + region +" in the iaas: "+iaasInfo.getType();
+ log.error(msg);
+ throw new InvalidRegionException(msg);
}
@Override
- public boolean isValidHost(IaasProvider iaasInfo, String zone, String host) {
+ public boolean isValidZone(IaasProvider iaasInfo, String region, String zone) throws InvalidZoneException {
+ // jclouds doesn't support zone in Openstack-Nova API
+ String msg = "Invalid zone: " + zone +" in the region: "+region+ " and of the iaas: "+iaasInfo.getType();
+ log.error(msg);
+ throw new InvalidZoneException(msg);
+
+ }
+
+ @Override
+ public boolean isValidHost(IaasProvider iaasInfo, String zone, String host) throws InvalidHostException {
if (host == null || zone == null || iaasInfo == null) {
- if (log.isDebugEnabled()) {
- log.debug("Host or Zone or IaaSProvider is null: host: " + host + " - zone: " +
- zone + " - IaaSProvider: " + iaasInfo);
- }
- return false;
+ String msg = "Host or Zone or IaaSProvider is null: host: " + host + " - zone: " +
+ zone + " - IaaSProvider: " + iaasInfo;
+ log.error(msg);
+ throw new InvalidHostException(msg);
}
ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- NovaApi api = context.unwrap();
+ NovaApi api = context.unwrap(NovaApiMetadata.CONTEXT_TOKEN).getApi();
HostAggregateApi hostApi = api.getHostAggregateExtensionForZone(zone).get();
for (HostAggregate hostAggregate : hostApi.list()) {
for (String configuredHost : hostAggregate.getHosts()) {
@@ -341,10 +354,10 @@ public class OpenstackNovaIaas extends Iaas {
}
}
}
- if (log.isDebugEnabled()) {
- log.debug("Did not find a matching host: " + host);
- }
- return false;
+
+ String msg = "Invalid host: " + host +" in the zone: "+zone+ " and of the iaas: "+iaasInfo.getType();
+ log.error(msg);
+ throw new InvalidHostException(msg);
}
@Override