You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by is...@apache.org on 2013/07/10 13:12:28 UTC
[13/14] committing components with version refactored to
3.0.0-SNAPSHOT
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/consumers/TopologyBuilder.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/consumers/TopologyBuilder.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/consumers/TopologyBuilder.java
deleted file mode 100644
index c6d191d..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/consumers/TopologyBuilder.java
+++ /dev/null
@@ -1,188 +0,0 @@
-package org.apache.stratos.cloud.controller.consumers;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.List;
-import java.util.concurrent.BlockingQueue;
-
-import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.commons.io.FileUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.lb.common.conf.structure.Node;
-import org.apache.stratos.lb.common.conf.structure.NodeBuilder;
-import org.apache.stratos.lb.common.conf.util.Constants;
-import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
-import org.apache.stratos.cloud.controller.util.DeclarativeServiceReferenceHolder;
-import org.apache.stratos.cloud.controller.util.ServiceContext;
-
-/**
- * This class is responsible for generating the service topology and
- * publishing it to a topic.
- */
-public class TopologyBuilder implements Runnable {
-
- private BlockingQueue<List<ServiceContext>> sharedQueue;
- private static File topologyFile, backup;
- private static final Log log = LogFactory.getLog(TopologyBuilder.class);
- private static DeclarativeServiceReferenceHolder data = DeclarativeServiceReferenceHolder.getInstance();
-
- public TopologyBuilder(BlockingQueue<List<ServiceContext>> queue){
-
- sharedQueue = queue;
- topologyFile = new File(CloudControllerConstants.TOPOLOGY_FILE_PATH);
- backup = new File(CloudControllerConstants.TOPOLOGY_FILE_PATH+".back");
-
- }
-
- @Override
- public void run() {
-
- while(true){
- try {
- Object obj = sharedQueue.take();
- boolean isAdded = false;
-
- if(obj instanceof List<?>){
- @SuppressWarnings("unchecked")
- List<ServiceContext> ctxts = (List<ServiceContext>) obj;
-
- for (ServiceContext serviceContext : ctxts) {
-
- Node newNode = serviceContext.toNode();
-
- if(!topologyFile.exists()){
- FileUtils.writeStringToFile(topologyFile, "services {\n}");
- }
-
- String currentContent = FileUtils.readFileToString(topologyFile);
- Node currentNode = NodeBuilder.buildNode(currentContent);
-
- for (Node aNode : currentNode.getChildNodes()) {
- // similar service element is present
- if(aNode.getName().equals(newNode.getName())){
- // hence, we should not override, but append
- Node domainsNode = aNode.findChildNodeByName(Constants.DOMAIN_ELEMENT);
-
- if(domainsNode == null){
- // existing node is useless
- currentNode.removeChildNode(aNode.getName());
- currentNode.appendChild(newNode);
- break;
- }
-
- // append the new node/s
- for (Node serNode : newNode.findChildNodeByName(Constants.DOMAIN_ELEMENT).getChildNodes()) {
-
- for (Node currentSerNode : domainsNode.getChildNodes()) {
- String prop = Constants.SUB_DOMAIN_ELEMENT;
- if(serNode.getName().equals(currentSerNode.getName()) &&
- serNode.getProperty(prop).equals(currentSerNode.getProperty(prop))){
- // if domain and sub domain, are not unique, we shouldn't append, but override
- domainsNode.removeChildNode(currentSerNode.getName());
- break;
- }
- }
-
- domainsNode.appendChild(serNode);
- }
- isAdded = true;
- break;
- }
- }
-
- if (!isAdded) {
- currentNode.appendChild(newNode);
- }
-
- if (topologyFile.exists()) {
- backup.delete();
- topologyFile.renameTo(backup);
- }
-
- // overwrite the topology file
- FileUtils.writeStringToFile(topologyFile, currentNode.toString());
-
- // publish to the topic - to sync immediately
- data.getConfigPub().publish(CloudControllerConstants.TOPIC_NAME, currentNode.toString());
-
- }
- }
-
- } catch (InterruptedException ignore) {
- } catch (IOException e) {
- log.error(e.getMessage(), e);
- throw new CloudControllerException(e.getMessage(), e);
- }
- }
-
- }
-
- public static void removeTopologyAndPublish(ServiceContext serviceContext){
-
- Node currentNodeToBeRemoved = null;
- Node nodeToBeRemoved = serviceContext.toNode();
-
- if(!topologyFile.exists()){
- return;
- }
- try{
- String currentContent = FileUtils.readFileToString(topologyFile);
- Node currentNode = NodeBuilder.buildNode(currentContent);
-
- for (Node aNode : currentNode.getChildNodes()) {
- // similar service element is present
- if(aNode.getName().equals(nodeToBeRemoved.getName())){
- // let's check whether the domain node exists
-
- Node domainsNode = aNode.findChildNodeByName(Constants.DOMAIN_ELEMENT);
-
- if(domainsNode == null){
- continue;
- }
-
- for (Node serNode : nodeToBeRemoved.findChildNodeByName(Constants.DOMAIN_ELEMENT).getChildNodes()) {
-
- for (Node currentSerNode : domainsNode.getChildNodes()) {
- String prop = Constants.SUB_DOMAIN_ELEMENT;
- if(serNode.getName().equals(currentSerNode.getName()) &&
- serNode.getProperty(prop).equals(currentSerNode.getProperty(prop))){
- // if domain and sub domain, are matching, we should remove the node.
- domainsNode.removeChildNode(currentSerNode.getName());
- if(domainsNode.getChildNodes().size() == 0){
- // if no cluster definitions remain, we shouldn't keep the node
- currentNodeToBeRemoved = aNode;
- }
- break;
- }
- }
-
- }
-
- }
- }
-
- if(currentNodeToBeRemoved != null){
- // remove the node with empty clusters
- currentNode.removeChildNode(currentNodeToBeRemoved);
- }
-
- if (topologyFile.exists()) {
- backup.delete();
- topologyFile.renameTo(backup);
- }
-
- // overwrite the topology file
- FileUtils.writeStringToFile(topologyFile, currentNode.toString());
-
- // publish to the topic - to sync immediately
- data.getConfigPub().publish(CloudControllerConstants.TOPIC_NAME, currentNode.toString());
-
- } catch (IOException e) {
- log.error(e.getMessage(), e);
- throw new CloudControllerException(e.getMessage(), e);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CartridgeDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CartridgeDeployer.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CartridgeDeployer.java
deleted file mode 100644
index a130f4e..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CartridgeDeployer.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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.deployers;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.deployment.AbstractDeployer;
-import org.apache.axis2.deployment.DeploymentException;
-import org.apache.axis2.deployment.repository.util.DeploymentFileData;
-import org.apache.stratos.cloud.controller.axiom.AxiomXpathParser;
-import org.apache.stratos.cloud.controller.concurrent.ThreadExecutor;
-import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.stratos.cloud.controller.interfaces.Iaas;
-import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
-import org.apache.stratos.cloud.controller.util.Cartridge;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.util.IaasProvider;
-import org.wso2.carbon.utils.CarbonUtils;
-
-/**
- * All the {@link org.apache.stratos.cloud.controller.util.Cartridge}s will get deployed / undeployed / updated via this class.
- */
-public class CartridgeDeployer extends AbstractDeployer{
-
- private static final Log log = LogFactory.getLog(CartridgeDeployer.class);
-
- private FasterLookUpDataHolder serviceContextLookUpStructure;
- private Map<String, List<Cartridge>> fileToCartridgeListMap;
- private File cartridgesSchema, cartridgeSchema;
-
- public void init(ConfigurationContext arg0) {
- fileToCartridgeListMap = new ConcurrentHashMap<String, List<Cartridge>>();
- String etcDir = CarbonUtils.getCarbonConfigDirPath() + File.separator + "etc" + File.separator;
- cartridgesSchema = new File(etcDir+"cartridges.xsd");
- cartridgeSchema = new File(etcDir+"cartridge.xsd");
- }
-
- public void setDirectory(String arg0) {
- // component xml handles this
- }
-
- 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());
-
- AxiomXpathParser parser = new AxiomXpathParser(deploymentFileData.getFile());
- parser.parse();
-
- try {
- // validate
- validateCartridge(parser);
-
- // deploy - grab cartridges
- List<Cartridge> cartridges = parser.getCartridgesList();
-
- ThreadExecutor exec = new ThreadExecutor(3);
- // create Jclouds objects, for each IaaS
- for (Cartridge cartridge : cartridges) {
- // jclouds object building is time consuming, hence I use Java executor framework
- exec.execute(new JcloudsObjectBuilder(cartridge, deploymentFileData));
- }
- exec.shutdown();
- // update map
- fileToCartridgeListMap.put(deploymentFileData.getAbsolutePath(),
- new ArrayList<Cartridge>(cartridges));
-
- log.info("Successfully deployed the Cartridge definition specified at "+deploymentFileData.getAbsolutePath());
-
- } 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);
- }
-
-
- }
-
- private void validateCartridge(AxiomXpathParser parser) throws Exception {
- boolean validated = false;
- Exception firstException = null;
-
- try{
- // first try to validate using cartridges schema
- parser.validate(cartridgesSchema);
- validated = true;
-
- }catch (Exception e) {
- firstException = e;
- }
-
- if(!validated){
- try{
- // Now try to validate using cartridge schema
- parser.validate(cartridgeSchema);
- validated = true;
- log.debug("Cartridge validation was successful.");
-
- }catch (Exception e) {
- String msg = "Cartridge XML validation failed. Invalid Cartridge 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(fileToCartridgeListMap.containsKey(file)){
- // remove 'em
- serviceContextLookUpStructure.removeCartridges(fileToCartridgeListMap.get(file));
-
- log.info("Successfully undeployed the Cartridge definition specified at "+file);
- }
-
- }
-
- private void handleException(String msg, Exception e) {
- log.fatal(msg, e);
- throw new CloudControllerException(msg, e);
- }
-
- /**
- * JcloudsObjectBuilder job
- *
- */
- class JcloudsObjectBuilder implements Runnable{
-
- private Cartridge cartridge;
- private DeploymentFileData file;
-
- public JcloudsObjectBuilder (Cartridge cartridge, DeploymentFileData file){
- this.cartridge = cartridge;
- this.file = file;
- }
-
- @Override
- public void run() {
-
- for (IaasProvider iaasProvider : cartridge.getIaases()) {
- try {
- Iaas iaas = (Iaas) Class.forName(iaasProvider.getClassName()).newInstance();
- iaas.buildComputeServiceAndTemplate(iaasProvider);
- iaasProvider.setIaas(iaas);
-
- } catch (Exception e) {
- rename();
- handleException(e.getMessage(), e);
- }
- }
-
- }
-
- private void rename(){
- // back up the file
- File f = file.getFile();
- f.renameTo(new File(file.getAbsolutePath()+".back"));
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
deleted file mode 100644
index 79987b0..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/CloudControllerDeployer.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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.deployers;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.deployment.AbstractDeployer;
-import org.apache.axis2.deployment.DeploymentException;
-import org.apache.axis2.deployment.repository.util.DeploymentFileData;
-import org.apache.stratos.cloud.controller.axiom.AxiomXpathParser;
-import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.util.IaasProvider;
-
-/**
- * All the {@link IaasProvider}s will get deployed / undeployed / updated via this class.
- */
-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>>();
- }
-
- @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());
-
- // since cloud-controller.xml resides in repository/conf
- if (deploymentFileData.getName().contains(FILE_NAME)) {
-
- AxiomXpathParser parser = new AxiomXpathParser(deploymentFileData.getFile());
-
- // parse the file
- parser.parse();
-
- // deploy iaases
- parser.setIaasProvidersList();
- parser.setDataPublisherRelatedData();
- parser.setTopologySyncRelatedData();
-
- // update map
- fileToIaasProviderListMap.put(deploymentFileData.getAbsolutePath(),
- new ArrayList<IaasProvider>(
- FasterLookUpDataHolder.getInstance()
- .getIaasProviders()));
-
- 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("");
-
- // grab the entry from Map
- 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);
- }
- // only one cloud-controller file, hence delete 'em all
-// FasterLookUpDataHolder.getInstance().setIaasProviders(new ArrayList<IaasProvider>());
-
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
deleted file mode 100644
index 2e37bef..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/deployers/ServiceDeployer.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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.deployers;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.deployment.AbstractDeployer;
-import org.apache.axis2.deployment.DeploymentException;
-import org.apache.axis2.deployment.repository.util.DeploymentFileData;
-import org.apache.stratos.cloud.controller.axiom.AxiomXpathParser;
-import org.apache.stratos.cloud.controller.consumers.TopologyBuilder;
-import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
-import org.apache.stratos.cloud.controller.util.ServiceContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.utils.CarbonUtils;
-
-/**
- * All the {@link org.apache.stratos.cloud.controller.util.Cartridge}s will get deployed / undeployed / updated via this class.
- */
-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();
-
- // notify consumer by adding the diff
- try {
- serviceContextLookUpStructure.getSharedTopologyDiffQueue().put(services);
- } catch (InterruptedException ignore) {
- }
-
- // 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);
- // remove from the topology
- TopologyBuilder.removeTopologyAndPublish(ctxt);
- }
-
- log.info("Successfully undeployed the Service definition specified at "+file);
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/CloudControllerException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/CloudControllerException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/CloudControllerException.java
deleted file mode 100644
index 08e57f5..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/CloudControllerException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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 CloudControllerException extends RuntimeException {
-
- private static final long serialVersionUID = -6326227079367867222L;
-
- public CloudControllerException(String msg) {
- super(msg);
- }
-
- public CloudControllerException(String msg, Exception ex) {
- super(msg, ex);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/DeserializationException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/DeserializationException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/DeserializationException.java
deleted file mode 100644
index 33ec80b..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/DeserializationException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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 DeserializationException extends RuntimeException {
-
- private static final long serialVersionUID = -2426068347954381831L;
-
- public DeserializationException(String msg) {
- super(msg);
- }
-
- public DeserializationException(String msg, Exception ex) {
- super(msg, ex);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeDefinitionException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeDefinitionException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeDefinitionException.java
deleted file mode 100644
index 363dc38..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidCartridgeDefinitionException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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 InvalidCartridgeDefinitionException extends Exception {
-
- private static final long serialVersionUID = -6326227079367867222L;
-
- public InvalidCartridgeDefinitionException(String msg) {
- super(msg);
- }
-
- public InvalidCartridgeDefinitionException(String msg, Exception ex) {
- super(msg, ex);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidXMLException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidXMLException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidXMLException.java
deleted file mode 100644
index d0bab7e..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/InvalidXMLException.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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 InvalidXMLException extends RuntimeException {
-
- private static final long serialVersionUID = -6326227079367867222L;
-
- public InvalidXMLException(String msg) {
- super(msg);
- }
-
- public InvalidXMLException(String msg, Exception ex) {
- super(msg, ex);
- }
-
- public InvalidXMLException(Exception ex) {
- super(ex);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java
deleted file mode 100644
index db268f2..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/MalformedConfigurationFileException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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 MalformedConfigurationFileException extends RuntimeException {
-
- private static final long serialVersionUID = -1662095377704279326L;
-
- public MalformedConfigurationFileException(String msg) {
- super(msg);
- }
-
- public MalformedConfigurationFileException(String msg, Exception ex) {
- super(msg, ex);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/NoInstanceFoundException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/NoInstanceFoundException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/NoInstanceFoundException.java
deleted file mode 100644
index c85d47a..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/NoInstanceFoundException.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
- *
- * WSO2 Inc. 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;
-
-/**
- * This will throw when no instance is found
- */
-public class NoInstanceFoundException extends Exception {
-
- /**
- * For serializing requirement
- */
- private static final long serialVersionUID = -435060299292679892L;
-
-
- public NoInstanceFoundException(String msg) {
- super(msg);
- }
-
- public NoInstanceFoundException(String msg, Exception ex) {
- super(msg, ex);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/SerializationException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/SerializationException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/SerializationException.java
deleted file mode 100644
index b2e2302..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/SerializationException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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 SerializationException extends RuntimeException {
-
- private static final long serialVersionUID = -3701458642228072331L;
-
- public SerializationException(String msg) {
- super(msg);
- }
-
- public SerializationException(String msg, Exception ex) {
- super(msg, ex);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredCartridgeException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredCartridgeException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredCartridgeException.java
deleted file mode 100644
index 96e2236..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredCartridgeException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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 UnregisteredCartridgeException extends Exception {
-
- private static final long serialVersionUID = -6326227079367867222L;
-
- public UnregisteredCartridgeException(String msg) {
- super(msg);
- }
-
- public UnregisteredCartridgeException(String msg, Exception ex) {
- super(msg, ex);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java
deleted file mode 100644
index 166be6d..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/exception/UnregisteredServiceException.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
deleted file mode 100644
index 71aa720..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hector/CassandraDataRetriever.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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.hector;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
-
-import me.prettyprint.cassandra.model.BasicColumnDefinition;
-import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
-import me.prettyprint.cassandra.model.CqlQuery;
-import me.prettyprint.cassandra.model.CqlRows;
-import me.prettyprint.cassandra.serializers.StringSerializer;
-import me.prettyprint.cassandra.service.CassandraHostConfigurator;
-import me.prettyprint.cassandra.service.ThriftCfDef;
-import me.prettyprint.hector.api.Cluster;
-import me.prettyprint.hector.api.Keyspace;
-import me.prettyprint.hector.api.beans.HColumn;
-import me.prettyprint.hector.api.beans.Row;
-import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
-import me.prettyprint.hector.api.ddl.ColumnIndexType;
-import me.prettyprint.hector.api.ddl.ComparatorType;
-import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
-import me.prettyprint.hector.api.factory.HFactory;
-import me.prettyprint.hector.api.query.QueryResult;
-
-public class CassandraDataRetriever {
-
- private static final Log log = LogFactory.getLog(CassandraDataRetriever.class);
- private static FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
- private final static StringSerializer se = StringSerializer.get();
- private static Cluster cluster;
- private static Keyspace keyspace;
- private static boolean isInit;
-
- public static void init() {
-
- if(isInit){
- return;
- }
- getCassandraKeyspace();
- indexCounterColumn("payload_status");
- isInit = true;
- }
-
- public static void connect() {
-
- if(keyspace == null){
- handleException("Cannot find the key space.");
- }
-
- String colFamily = CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY;
-
- CqlQuery<String,String,String> cqlQuery = new CqlQuery<String,String,String>(keyspace, se, se, se);
- cqlQuery.setQuery("select payload_nodeId from "+colFamily+" where payload_status='RUNNING'");
-// cqlQuery.setQuery("select * from "+colFamily+" where payload_domain='nirmal'");
- QueryResult<CqlRows<String,String,String>> result = cqlQuery.execute();
-
- if (result != null && result.get() != null) {
- List<Row<String, String, String>> list = result.get().getList();
- for (Row<?, ?, ?> row : list) {
- System.out.println(".");
- List<?> columns = row.getColumnSlice().getColumns();
- for (Iterator<?> iterator = columns.iterator(); iterator.hasNext();) {
- HColumn<?, ?> column = (HColumn<?, ?>) iterator.next();
- System.out.print(column.getName() + ":" + column.getValue()
- + "\t");
- }
- System.out.println("");
- }
- }
-
-// ColumnQuery<String, String, String> columnQuery =
-// HFactory.createStringColumnQuery(keyspace);
-// KeyIterator<String> keyIterator = new KeyIterator<String>(keyspace, colFamily, StringSerializer.get());
-// for ( String key : keyIterator ) {
-//
-// columnQuery.setColumnFamily(colFamily).setKey(key).setName("payload_nodeId");
-// QueryResult<HColumn<String, String>> result = columnQuery.execute();
-// HColumn<String, String> hColumn = result.get();
-// System.out.println("Column: " + hColumn.getName() + " Value : " + hColumn.getValue() + "\n");
-// }
-
-// //Read Data
-// for (String key : keyList) {
-// System.out.println("\nretrieving Key " + rowKey + "From Column Family " + columnFamily + "\n");
-// for (String columnName : columnList.split(":")) {
-// //sout data
-// }
-// }
-
-
- }
-
- private static void indexCounterColumn(String idxColumnName) {
-
- KeyspaceDefinition keyspaceDefinition = cluster.describeKeyspace(CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE);
-
- List<ColumnFamilyDefinition> cdfs = keyspaceDefinition.getCfDefs();
- ColumnFamilyDefinition cfd = null;
- for (ColumnFamilyDefinition c : cdfs) {
- if (c.getName().equals(CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY)) {
- System.out.println(c.getName());
- cfd = c;
- break;
- }
- }
-
- BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition(cfd);
-
- BasicColumnDefinition bcdf = new BasicColumnDefinition();
- bcdf.setName(StringSerializer.get().toByteBuffer(idxColumnName));
- bcdf.setIndexName(idxColumnName + "index");
- bcdf.setIndexType(ColumnIndexType.KEYS);
- bcdf.setValidationClass(ComparatorType.UTF8TYPE.getClassName());
-
- columnFamilyDefinition.addColumnDefinition(bcdf);
- cluster.updateColumnFamily(new ThriftCfDef(columnFamilyDefinition));
-
- }
-
- 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());
-
- cluster =
- retrieveCassandraCluster(CloudControllerConstants.DEFAULT_CASSANDRA_CLUSTER_NAME,
- dataHolder.getCassandraConnUrl(), credentials);
-
- keyspace =
- HFactory.createKeyspace(CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE,
- cluster);
- }
-
- }
-
- private static Cluster retrieveCassandraCluster(String clusterName, String connectionUrl,
- Map<String, String> credentials) {
-
- CassandraHostConfigurator hostConfigurator = new CassandraHostConfigurator(connectionUrl);
- hostConfigurator.setRetryDownedHosts(false);
- Cluster cluster = HFactory.createCluster(clusterName, hostConfigurator, credentials);
- return cluster;
- }
-
- private static void handleException(String msg) {
-
- log.error(msg);
- throw new CloudControllerException(msg);
- }
-
-// private void handleException(String msg, Exception e) {
-//
-// log.error(msg, e);
-// throw new AutoscalerServiceException(msg, e);
-// }
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
deleted file mode 100644
index fbbf940..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/hive/HiveQueryExecutor.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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.hive;
-
-import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.client.Options;
-import org.apache.axis2.client.ServiceClient;
-import org.apache.axis2.transport.http.HttpTransportProperties;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceHiveExecutionException;
-import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceStub;
-import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceStub.QueryResult;
-import org.wso2.carbon.analytics.hive.stub.HiveExecutionServiceStub.QueryResultRow;
-import org.wso2.carbon.base.ServerConfiguration;
-import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder;
-import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
-import org.wso2.carbon.utils.CarbonUtils;
-
-public class HiveQueryExecutor {
- private static final Log log = LogFactory.getLog(HiveQueryExecutor.class);
- private HiveExecutionServiceStub hiveService;
- private String payloadPrefix = CloudControllerConstants.PAYLOAD_PREFIX;
- private String hiveTable = "cloudController";
- private FasterLookUpDataHolder dataHolder = FasterLookUpDataHolder.getInstance();
-
- public HiveQueryExecutor() {
-
- ServerConfiguration serverConfig = CarbonUtils.getServerConfiguration();
- String bamServerUrl = serverConfig.getFirstProperty("BamServerURL");
- String serviceName = "HiveExecutionService";
- HttpTransportProperties.Authenticator authenticator;
-
- try {
- hiveService = new HiveExecutionServiceStub(bamServerUrl+"/services/"+serviceName);
-
- // admin service authentication
- authenticator = new HttpTransportProperties.Authenticator();
- authenticator.setUsername(dataHolder.getBamUsername());
- authenticator.setPassword(dataHolder.getBamPassword());
- authenticator.setPreemptiveAuthentication(true);
-
- ServiceClient client = hiveService._getServiceClient();
- Options option = client.getOptions();
- option.setManageSession(true);
- option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, authenticator);
- option.setTimeOutInMilliSeconds(120000);
-
- } catch (AxisFault e) {
- String msg = "Cannot get a connection to "+serviceName;
- handleException(msg, e);
- }
- }
-
- public QueryResult[] execute(String query){
- try {
- return hiveService.executeHiveScript(query);
- } catch (RemoteException e) {
- handleException("Query : '"+query+"' - "+e.getMessage(), e);
- } catch (HiveExecutionServiceHiveExecutionException e) {
- handleException("Query : '"+query+"' - "+e.getMessage(), e);
- }
-
- return new QueryResult[0];
- }
-
- public void createHiveTable(){
- String query =
- "CREATE EXTERNAL TABLE IF NOT EXISTS "+hiveTable+" (id STRING, " +
- payloadPrefix+CloudControllerConstants.NODE_ID_COL+" STRING," +
- payloadPrefix+CloudControllerConstants.CARTRIDGE_TYPE_COL+" STRING," +
- payloadPrefix+CloudControllerConstants.DOMAIN_COL+" STRING," +
- payloadPrefix+CloudControllerConstants.HOST_NAME_COL+" STRING," +
- payloadPrefix+CloudControllerConstants.HYPERVISOR_COL+" STRING," +
- payloadPrefix+CloudControllerConstants.IAAS_COL+" STRING," +
- payloadPrefix+CloudControllerConstants.IMAGE_ID_COL+" STRING," +
- payloadPrefix+CloudControllerConstants.LOGIN_PORT_COL+" STRING," +
- payloadPrefix+CloudControllerConstants.PRIV_IP_COL+" STRING," +
- payloadPrefix+CloudControllerConstants.PUB_IP_COL+" STRING," +
- 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]+
- "\",\"cassandra.ks.name\" = \""+CloudControllerConstants.DEFAULT_CASSANDRA_KEY_SPACE+"\"," +
- "\"cassandra.ks.username\" = \""+dataHolder.getCassandraUser()+
- "\", \"cassandra.ks.password\" = \""+dataHolder.getCassandraPassword()+"\"," +
- "\"cassandra.cf.name\" = \""+CloudControllerConstants.CLOUD_CONTROLLER_COL_FAMILY+"\"," +
- "\"cassandra.columns.mapping\" = \"" +
- payloadPrefix+CloudControllerConstants.NODE_ID_COL+"," +
- payloadPrefix+CloudControllerConstants.CARTRIDGE_TYPE_COL+"," +
- payloadPrefix+CloudControllerConstants.DOMAIN_COL+"," +
- payloadPrefix+CloudControllerConstants.HOST_NAME_COL+"," +
- payloadPrefix+CloudControllerConstants.HYPERVISOR_COL+"," +
- payloadPrefix+CloudControllerConstants.IAAS_COL+"," +
- payloadPrefix+CloudControllerConstants.IMAGE_ID_COL+"," +
- payloadPrefix+CloudControllerConstants.LOGIN_PORT_COL+"," +
- payloadPrefix+CloudControllerConstants.PRIV_IP_COL+"," +
- payloadPrefix+CloudControllerConstants.PUB_IP_COL+"," +
- payloadPrefix+CloudControllerConstants.STATUS_COL+"," +
- payloadPrefix+CloudControllerConstants.SUB_DOMAIN_COL +
- "\");";
-
- execute(query);
- }
-
- public List<String> getRunningNodeIds() {
- List<String> nodeIds = new ArrayList<String>();
- String query =
-// "select " + payloadPrefix + AutoscalerConstant.NODE_ID_COL + " from " +
-// hiveTable + " where payload_status='RUNNING' OR payload_status='PENDING' ;";
-
-// "select id1 from (select distinct payload_nodeId from cloud1 where payload_status='RUNNING' OR payload_status='PENDING') table1
-//LEFT OUTER JOIN
-//(select distinct payload_nodeId as nodeId from cloud1 where payload_status='TERMINATED') table2
-//ON(table2.nodeId = table1.payload_nodeId)
-//where table2.nodeId is null;";
- "select table1.id1 from (select distinct "+payloadPrefix+CloudControllerConstants.NODE_ID_COL+
- " as id1 from "+ hiveTable +" where "+payloadPrefix+CloudControllerConstants.STATUS_COL+
- "='RUNNING' OR "+payloadPrefix+CloudControllerConstants.STATUS_COL+"='PENDING') table1 " +
- "LEFT OUTER JOIN " +"(select distinct "+payloadPrefix+CloudControllerConstants.NODE_ID_COL+
- " as id2 from "+hiveTable+" where "+payloadPrefix+CloudControllerConstants.STATUS_COL+"='TERMINATED') table2 " +
- "ON(table1.id1 = table2.id2) where table2.id2 is null;";
-
- QueryResult[] result = execute(query);
-
- for (QueryResult queryResult : result) {
- if(queryResult == null || queryResult.getResultRows() == null){
- continue;
- }
- for (QueryResultRow row : queryResult.getResultRows()) {
- if (row != null && row.getColumnValues() != null && row.getColumnValues().length != 0) {
- nodeIds.add(row.getColumnValues()[0]);
- }
- }
- }
-
- return nodeIds;
-
- }
-
- private void handleException(String msg, Exception e){
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
deleted file mode 100644
index 3dee581..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/AWSEC2Iaas.java
+++ /dev/null
@@ -1,275 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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 java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jclouds.aws.ec2.AWSEC2AsyncClient;
-import org.jclouds.aws.ec2.AWSEC2Client;
-import org.jclouds.aws.ec2.compute.AWSEC2TemplateOptions;
-import org.jclouds.aws.ec2.domain.RegionNameAndPublicKeyMaterial;
-import org.jclouds.aws.ec2.functions.ImportOrReturnExistingKeypair;
-import org.jclouds.compute.ComputeServiceContext;
-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.ec2.domain.KeyPair;
-import org.jclouds.ec2.domain.PublicIpInstanceIdPair;
-import org.jclouds.rest.RestContext;
-import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.stratos.cloud.controller.interfaces.Iaas;
-import org.apache.stratos.cloud.controller.jcloud.ComputeServiceBuilderUtil;
-import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
-import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
-import org.apache.stratos.cloud.controller.util.IaasProvider;
-import org.wso2.carbon.utils.CarbonUtils;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-public class AWSEC2Iaas extends Iaas{
-
- private static final Log log = LogFactory.getLog(AWSEC2Iaas.class);
- private static final String SUCCESSFUL_LOG_LINE = "A key-pair is created successfully in ";
- private static final String FAILED_LOG_LINE = "Key-pair is unable to create in ";
-
- @Override
- public void buildComputeServiceAndTemplate(IaasProvider iaasInfo) {
-
- // builds and sets Compute Service
- ComputeServiceBuilderUtil.buildDefaultComputeService(iaasInfo);
-
- // builds and sets Template
- buildTemplate(iaasInfo);
-
- }
-
- private void buildTemplate(IaasProvider iaas) {
- if (iaas.getComputeService() == null) {
- String msg = "Compute service is null for IaaS provider: " + iaas.getName();
- log.fatal(msg);
- throw new CloudControllerException(msg);
- }
-
- TemplateBuilder templateBuilder = iaas.getComputeService().templateBuilder();
-
- // set image id specified
- templateBuilder.imageId(iaas.getImage());
-
- if (iaas.getProperty("instanceType") != null) {
- // set instance type eg: m1.large
- templateBuilder.hardwareId(iaas.getProperty("instanceType"));
- }
-
- // 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?
- boolean blockUntilRunning = Boolean.parseBoolean(iaas.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(new int[]{});
-
- // set EC2 specific options
- if (iaas.getProperty("subnetId") != null) {
- template.getOptions().as(AWSEC2TemplateOptions.class).subnetId(iaas.getProperty("subnetId"));
- }
-
- if (iaas.getProperty("availabilityZone") != null) {
- template.getOptions().as(AWSEC2TemplateOptions.class)
- .placementGroup(iaas.getProperty("availabilityZone"));
- }
-
- if (iaas.getProperty("securityGroups") != null) {
- template.getOptions()
- .as(AWSEC2TemplateOptions.class)
- .securityGroups(iaas.getProperty("securityGroups")
- .split(CloudControllerConstants.ENTRY_SEPARATOR));
-
- }
-
- if (iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER) != null) {
- template.getOptions()
- .as(AWSEC2TemplateOptions.class)
- .userData(ComputeServiceBuilderUtil.getUserData(CarbonUtils.getCarbonHome() +
- File.separator +
- iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER)));
- }
-
- if (iaas.getProperty("keyPair") != null) {
- template.getOptions().as(AWSEC2TemplateOptions.class)
- .keyPair(iaas.getProperty("keyPair"));
- }
-
- // set Template
- iaas.setTemplate(template);
- }
-
- @Override
- public void setDynamicPayload(IaasProvider iaasInfo) {
-
- if (iaasInfo.getTemplate() != null && iaasInfo.getPayload() != null) {
-
- iaasInfo.getTemplate().getOptions().as(AWSEC2TemplateOptions.class)
- .userData(iaasInfo.getPayload());
- }
-
- }
-
- @Override
- public synchronized boolean createKeyPairFromPublicKey(IaasProvider iaasInfo, String region, String keyPairName,
- String publicKey) {
-
- String ec2Msg = " ec2. Region: "+region+" - Key Pair Name: ";
-
- ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- @SuppressWarnings("unchecked")
- RestContext<AWSEC2Client, AWSEC2AsyncClient> restContext = context.unwrap(RestContext.class);
- AWSEC2Client ec2Client = restContext.getApi();
-
- ImportOrReturnExistingKeypair importer = new ImportOrReturnExistingKeypair(ec2Client);
-
- RegionNameAndPublicKeyMaterial regionNameAndKey = new RegionNameAndPublicKeyMaterial(region, keyPairName, publicKey);
- KeyPair keyPair = importer.apply(regionNameAndKey);
-
- if (keyPair != null) {
-
- iaasInfo.getTemplate().getOptions().as(AWSEC2TemplateOptions.class)
- .keyPair(keyPair.getKeyName());
-
- log.info(SUCCESSFUL_LOG_LINE + ec2Msg + keyPair.getKeyName());
- return true;
- }
-
- log.error(FAILED_LOG_LINE+ec2Msg);
-
- return false;
- }
-
- @Override
- public synchronized String associateAddress(IaasProvider iaasInfo, NodeMetadata node) {
-
- ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- @SuppressWarnings("unchecked")
- RestContext<AWSEC2Client, AWSEC2AsyncClient> restContext =
- context.unwrap(RestContext.class);
- AWSEC2Client ec2Client = restContext.getApi();
- String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
-
- String ip = null;
-
- // first try to find an unassigned IP.
- ArrayList<PublicIpInstanceIdPair> unassignedIps =
- Lists.newArrayList(Iterables.filter(ec2Client.getElasticIPAddressServices()
- .describeAddressesInRegion(region,
- new String[0]),
- new Predicate<PublicIpInstanceIdPair>() {
-
- @Override
- public boolean apply(PublicIpInstanceIdPair arg0) {
- return arg0.getInstanceId() == null;
- }
-
- }));
-
-
- if (!unassignedIps.isEmpty()) {
- // try to prevent multiple parallel launches from choosing the same
- // ip.
- Collections.shuffle(unassignedIps);
- ip = Iterables.getLast(unassignedIps).getPublicIp();
- }
-
- // if no unassigned IP is available, we'll try to allocate an IP.
- if (ip == null || ip.isEmpty()) {
- try {
- ip = ec2Client.getElasticIPAddressServices().allocateAddressInRegion(region);
- log.info("Assigned ip [" + ip +"]");
-
- } catch (Exception e) {
- String msg = "Failed to allocate an IP address. All IP addresses are in use.";
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
- }
-
- String id = node.getProviderId();
-
- // wait till the fixed IP address gets assigned - this is needed before we associate a
- // public IP
-
- while (node.getPrivateAddresses() == null) {
- CloudControllerUtil.sleep(1000);
- }
-
- int retries = 0;
- while (retries < 12 && !associatePublicIp(ec2Client, region, ip, id)) {
-
- // wait for 5s
- CloudControllerUtil.sleep(5000);
- retries++;
- }
-
- // FIXME make this debug
- log.info("Successfully associated an IP address " + ip + " for node with id: " +
- node.getId());
-
- return ip;
-
- }
-
- /**
- * @param ec2Client
- * @param region
- * @param ip
- * @param id
- */
- private boolean associatePublicIp(AWSEC2Client ec2Client, String region, String ip, String id) {
- try {
- ec2Client.getElasticIPAddressServices().associateAddressInRegion(region, ip, id);
- log.info("Successfully associated public IP ");
- return true;
- } catch (Exception e) {
- log.error("Exception in associating public IP " + e.getMessage());
- return false;
- }
- }
-
- @Override
- public synchronized void releaseAddress(IaasProvider iaasInfo, String ip) {
-
- ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- @SuppressWarnings("unchecked")
- RestContext<AWSEC2Client, AWSEC2AsyncClient> restContext =
- context.unwrap(RestContext.class);
- AWSEC2Client ec2Client = restContext.getApi();
- String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
-
- ec2Client.getElasticIPAddressServices().disassociateAddressInRegion(region, ip);
- ec2Client.getElasticIPAddressServices().releaseAddressInRegion(region, ip);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/a95bcac0/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java b/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
deleted file mode 100644
index 1db370a..0000000
--- a/components/org.apache.stratos.cloud.controller/2.1.3/src/main/java/org/apache/stratos/cloud/controller/iaases/OpenstackNovaIaas.java
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
-* Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
-*
-* WSO2 Inc. 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 java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-
-import org.apache.stratos.cloud.controller.exception.CloudControllerException;
-import org.apache.stratos.cloud.controller.interfaces.Iaas;
-import org.apache.stratos.cloud.controller.jcloud.ComputeServiceBuilderUtil;
-import org.apache.stratos.cloud.controller.util.CloudControllerConstants;
-import org.apache.stratos.cloud.controller.util.CloudControllerUtil;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jclouds.compute.ComputeServiceContext;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadataBuilder;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.compute.domain.TemplateBuilder;
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.openstack.nova.v2_0.NovaAsyncClient;
-import org.jclouds.openstack.nova.v2_0.NovaClient;
-import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions;
-import org.jclouds.openstack.nova.v2_0.domain.FloatingIP;
-import org.jclouds.openstack.nova.v2_0.domain.KeyPair;
-import org.jclouds.openstack.nova.v2_0.extensions.FloatingIPClient;
-import org.jclouds.openstack.nova.v2_0.extensions.KeyPairClient;
-import org.jclouds.rest.InsufficientResourcesException;
-import org.jclouds.rest.RestContext;
-import org.apache.stratos.cloud.controller.util.IaasProvider;
-import org.wso2.carbon.utils.CarbonUtils;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
-public class OpenstackNovaIaas extends Iaas {
-
- private static final Log log = LogFactory.getLog(OpenstackNovaIaas.class);
- private static final String SUCCESSFUL_LOG_LINE = "A key-pair is created successfully in ";
- private static final String FAILED_LOG_LINE = "Key-pair is unable to create in ";
-
- @Override
- public void buildComputeServiceAndTemplate(IaasProvider iaasInfo) {
-
- // builds and sets Compute Service
- ComputeServiceBuilderUtil.buildDefaultComputeService(iaasInfo);
-
- // builds and sets Template
- buildTemplate(iaasInfo);
-
- }
-
- private void buildTemplate(IaasProvider iaas) {
- if (iaas.getComputeService() == null) {
- throw new CloudControllerException("Compute service is null for IaaS provider: " +
- iaas.getName());
- }
-
- // // if domain to template map is null
- // if (entity.getDomainToTemplateMap() == null) {
- // // we initialize it
- // entity.setDomainToTemplateMap(new HashMap<String, Template>());
- // }
-
- TemplateBuilder templateBuilder = iaas.getComputeService().templateBuilder();
- templateBuilder.imageId(iaas.getImage());
-
- // to avoid creation of template objects in each and every time, we create all
- // at once!
- // for (org.apache.cartridge.autoscaler.service.util.ServiceContext temp :
- // serviceContexts) {
-
- String instanceType;
-
- // set instance type
- if (((instanceType = iaas.getProperty("instanceType")) != null)) {
-
- templateBuilder.hardwareId(instanceType);
- }
-
- 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?
- boolean blockUntilRunning = Boolean.parseBoolean(iaas.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(new int[]{});
-
- if (iaas.getProperty("securityGroups") != null) {
- template.getOptions()
- .as(NovaTemplateOptions.class)
- .securityGroupNames(iaas.getProperty("securityGroups")
- .split(CloudControllerConstants.ENTRY_SEPARATOR));
- }
-
- if (iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER) != null) {
- template.getOptions()
- .as(NovaTemplateOptions.class)
- .userData(ComputeServiceBuilderUtil.getUserData(CarbonUtils.getCarbonHome() +
- File.separator +
- iaas.getProperty(CloudControllerConstants.PAYLOAD_FOLDER)));
- }
-
- if (iaas.getProperty("keyPair") != null) {
- template.getOptions().as(NovaTemplateOptions.class)
- .keyPairName(iaas.getProperty("keyPair"));
- }
-
- // set Template
- iaas.setTemplate(template);
- }
-
- @Override
- public void setDynamicPayload(IaasProvider iaasInfo) {
-
- if (iaasInfo.getTemplate() != null && iaasInfo.getPayload() != null) {
-
- iaasInfo.getTemplate().getOptions().as(NovaTemplateOptions.class).userData(iaasInfo.getPayload());
- }
-
- }
-
- @Override
- public synchronized boolean createKeyPairFromPublicKey(IaasProvider iaasInfo, String region, String keyPairName,
- String publicKey) {
-
- String openstackNovaMsg = " Openstack-nova. Region: " + region + " - Name: ";
-
- ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- @SuppressWarnings("unchecked")
- RestContext<NovaClient, NovaAsyncClient> restContext = context.unwrap(RestContext.class);
-
- KeyPairClient api = restContext.getApi().getKeyPairExtensionForZone(region).get();
-
- KeyPair keyPair = api.createKeyPairWithPublicKey(keyPairName, publicKey);
-
- if (keyPair != null) {
-
- iaasInfo.getTemplate().getOptions().as(NovaTemplateOptions.class)
- .keyPairName(keyPair.getName());
-
- log.info(SUCCESSFUL_LOG_LINE + openstackNovaMsg + keyPair.getName());
- return true;
- }
-
- log.error(FAILED_LOG_LINE + openstackNovaMsg);
- return false;
-
- }
-
- @Override
- public synchronized String associateAddress(IaasProvider iaasInfo, NodeMetadata node) {
-
- ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- @SuppressWarnings("unchecked")
- RestContext<NovaClient, NovaAsyncClient> restContext = context.unwrap(RestContext.class);
-
- NovaClient novaClient = restContext.getApi();
- String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
-
- FloatingIPClient floatingIp = novaClient.getFloatingIPExtensionForZone(region).get();
-
- String ip=null;
- // first try to find an unassigned IP.
- ArrayList<FloatingIP> unassignedIps =
- Lists.newArrayList(Iterables.filter(floatingIp.listFloatingIPs(),
- new Predicate<FloatingIP>() {
-
- @Override
- public boolean apply(FloatingIP arg0) {
- //FIXME is this the correct filter?
- return arg0.getFixedIp() == null;
- }
-
- }));
-
- if (!unassignedIps.isEmpty()) {
- // try to prevent multiple parallel launches from choosing the same
- // ip.
- Collections.shuffle(unassignedIps);
- ip = Iterables.getLast(unassignedIps).getIp();
- }
-
- // if no unassigned IP is available, we'll try to allocate an IP.
- if (ip == null || ip.isEmpty()) {
-
- try {
- ip = floatingIp.allocate().getIp();
-
- } catch (InsufficientResourcesException e) {
- String msg = "Failed to allocate an IP address. All IP addresses are in use.";
- log.error(msg, e);
- throw new CloudControllerException(msg, e);
- }
- }
-
- // wait till the fixed IP address gets assigned - this is needed before we associate a public IP
-
- while(node.getPrivateAddresses() == null){
- CloudControllerUtil.sleep(1000);
- }
-
- int retries =0;
- while(retries < 5 && !associateIp(floatingIp, ip, node.getProviderId()) ){
-
- // wait for 5s
- CloudControllerUtil.sleep(5000);
- retries++;
- }
-
- NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip)).build();
-
- log.info("Successfully associated an IP address "+ip+" for node with id: "+node.getId());
-
- return ip;
- }
-
- @Override
- public synchronized void releaseAddress(IaasProvider iaasInfo, String ip){
-
- ComputeServiceContext context = iaasInfo.getComputeService().getContext();
- @SuppressWarnings("unchecked")
- RestContext<NovaClient, NovaAsyncClient> restContext = context.unwrap(RestContext.class);
-
- NovaClient novaClient = restContext.getApi();
- String region = ComputeServiceBuilderUtil.extractRegion(iaasInfo);
-
- FloatingIPClient floatingIpClient = novaClient.getFloatingIPExtensionForZone(region).get();
-
- for (FloatingIP floatingIP: floatingIpClient.listFloatingIPs()) {
- if(floatingIP.getIp().equals(ip)){
- floatingIpClient.deallocate(floatingIP.getId());
- break;
- }
- }
-
- }
-
- private boolean associateIp(FloatingIPClient client, String ip, String id){
- try{
- client.addFloatingIPToServer(ip, id);
- return true;
- }catch(RuntimeException ex){
- return false;
- }
- }
-
-}