Repository: stratos Updated Branches: refs/heads/master 2ec7fed1d -> 8c359dc1b
http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ComputeServiceBuilderUtil.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ComputeServiceBuilderUtil.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ComputeServiceBuilderUtil.java new file mode 100644 index 0000000..0da7025 --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ComputeServiceBuilderUtil.java @@ -0,0 +1,187 @@ +/* + * 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.util; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +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.domain.IaasProvider; +import org.jclouds.ContextBuilder; +import org.jclouds.compute.ComputeServiceContext; +import org.jclouds.enterprise.config.EnterpriseConfigurationModule; +import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; +import org.jclouds.sshj.config.SshjSshClientModule; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; +import java.util.Properties; + +/** + * This class is responsible for creating a JClouds specific ComputeService object. + */ +public class ComputeServiceBuilderUtil { + + private static final Log log = LogFactory.getLog(ComputeServiceBuilderUtil.class); + + public static byte[] getUserData(String payloadFileName) { + byte[] bytes = null; + try { + File file = new File(payloadFileName); + if (!file.exists()) { + handleException("Payload file " + payloadFileName + " does not exist"); + } + if (!file.canRead()) { + handleException("Payload file " + payloadFileName + " does cannot be read"); + } + bytes = getBytesFromFile(file); + + } catch (IOException e) { + handleException("Cannot read data from payload file " + payloadFileName, e); + } + return bytes; + } + + + public static void buildDefaultComputeService(IaasProvider iaas) { + + Properties properties = new Properties(); + + // load properties + for (Map.Entry<String, String> entry : iaas.getProperties().entrySet()) { + properties.put(entry.getKey(), entry.getValue()); + } + + // set modules + Iterable<Module> modules = + ImmutableSet.<Module> of(new SshjSshClientModule(), new SLF4JLoggingModule(), + new EnterpriseConfigurationModule()); + + // build context + ContextBuilder builder = + ContextBuilder.newBuilder(iaas.getProvider()) + .credentials(iaas.getIdentity(), iaas.getCredential()).modules(modules) + .overrides(properties); + + // set the compute service object + iaas.setComputeService(builder.buildView(ComputeServiceContext.class).getComputeService()); + } + + public static String extractRegion(IaasProvider iaas) { + String region; + // try to find region + if ((region = iaas.getProperty(CloudControllerConstants.REGION_PROPERTY)) == null) { + // if the property, isn't specified, try to obtain from the image id + // image id can be in following format - {region}/{UUID} + region = iaas.getImage().contains("/") ? iaas.getImage().split("/")[0] : null; + } + + return region; + } + + public static String extractZone(IaasProvider iaas) { + + return iaas.getProperty(CloudControllerConstants.AVAILABILITY_ZONE); + } + + /** Returns the contents of the file in a byte array + * + * @param file + * - Input File + * @return Bytes from the file + * @throws java.io.IOException + * , if retrieving the file contents failed. + */ + public static byte[] getBytesFromFile(File file) throws IOException { + if (!file.exists()) { + log.error("Payload file " + file.getAbsolutePath() + " does not exist"); + return null; + } + InputStream is = new FileInputStream(file); + byte[] bytes; + + try { + // Get the size of the file + long length = file.length(); + + // You cannot create an array using a long type. + // It needs to be an int type. + // Before converting to an int type, check + // to ensure that file is not larger than Integer.MAX_VALUE. + if (length > Integer.MAX_VALUE) { + if (log.isDebugEnabled()) { + log.debug("File is too large"); + } + } + + // Create the byte array to hold the data + bytes = new byte[(int) length]; + + // Read in the bytes + int offset = 0; + int numRead; + while (offset < bytes.length && + (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { + offset += numRead; + } + + // Ensure all the bytes have been read in + if (offset < bytes.length) { + throw new IOException("Could not completely read file " + file.getName()); + } + } finally { + // Close the input stream and return bytes + is.close(); + } + + return bytes; + } + + /** + * handles the exception + * + * @param msg + * exception message + */ + private static void handleException(String msg) { + log.error(msg); + throw new CloudControllerException(msg); + } + + /** + * handles the exception + * + * @param msg + * exception message + * @param e + * exception + */ + private static void handleException(String msg, Exception e) { + log.error(msg, e); + throw new CloudControllerException(msg, e); + + } + + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java index c142abf..1fd0709 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/PodActivationWatcher.java @@ -21,10 +21,10 @@ package org.apache.stratos.cloud.controller.util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.pojo.MemberContext; +import org.apache.stratos.cloud.controller.domain.MemberContext; import org.apache.stratos.cloud.controller.registry.RegistryManager; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; -import org.apache.stratos.cloud.controller.topology.TopologyBuilder; +import org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder; +import org.apache.stratos.cloud.controller.messaging.topology.TopologyBuilder; import org.apache.stratos.kubernetes.client.KubernetesApiClient; import org.apache.stratos.kubernetes.client.model.Pod; http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceReferenceHolder.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceReferenceHolder.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceReferenceHolder.java deleted file mode 100644 index 08ccd77..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/util/ServiceReferenceHolder.java +++ /dev/null @@ -1,79 +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.util; - -import org.apache.axis2.engine.AxisConfiguration; -import org.wso2.carbon.caching.impl.DistributedMapProvider; -import org.wso2.carbon.ntask.core.service.TaskService; -import org.wso2.carbon.registry.core.Registry; -import org.wso2.carbon.registry.core.session.UserRegistry; - -/** - * Singleton class to hold all the service references. - */ -public class ServiceReferenceHolder { - - private static ServiceReferenceHolder instance; - private TaskService taskService; - private Registry registry; - private AxisConfiguration axisConfiguration; - private DistributedMapProvider distributedMapProvider; - - private ServiceReferenceHolder() { - } - - public static ServiceReferenceHolder getInstance() { - if (instance == null) { - instance = new ServiceReferenceHolder(); - } - return instance; - } - - public void setAxisConfiguration(AxisConfiguration axisConfiguration) { - this.axisConfiguration = axisConfiguration; - } - - public AxisConfiguration getAxisConfiguration() { - return axisConfiguration; - } - - public TaskService getTaskService() { - return taskService; - } - - public void setTaskService(TaskService taskService) { - this.taskService = taskService; - } - - public void setRegistry(UserRegistry governanceSystemRegistry) { - registry = governanceSystemRegistry; - } - - public Registry getRegistry() { - return registry; - } - - public void setDistributedMapProvider(DistributedMapProvider distributedMapProvider) { - this.distributedMapProvider = distributedMapProvider; - } - - public DistributedMapProvider getDistributedMapProvider() { - return distributedMapProvider; - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java deleted file mode 100644 index 0627347..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java +++ /dev/null @@ -1,123 +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.validate; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException; -import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; -import org.apache.stratos.cloud.controller.interfaces.Iaas; -import org.apache.stratos.cloud.controller.pojo.IaasProvider; -import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.apache.stratos.cloud.controller.util.CloudControllerUtil; -import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator; -import org.apache.stratos.messaging.domain.topology.Scope; - -import java.util.Properties; - - -/** - * AWS-EC2 {@link PartitionValidator} implementation. - * - * - */ -public class AWSEC2PartitionValidator implements PartitionValidator { - - private static final Log log = LogFactory.getLog(AWSEC2PartitionValidator.class); - private IaasProvider iaasProvider; - private Iaas iaas; - - @Override - public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException { - // validate the existence of the region and zone properties. - try { - if (properties.containsKey(Scope.region.toString())) { - String region = properties.getProperty(Scope.region.toString()); - - if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) { - - String msg = - "Invalid Partition Detected : " + partitionId + - " - Cause: Invalid Region: " + region; - log.error(msg); - throw new InvalidPartitionException(msg); - } - - iaas.isValidRegion(region); - - IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider); - - Iaas updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - updatedIaas.setIaasProvider(updatedIaasProvider); - - if (properties.containsKey(Scope.zone.toString())) { - String zone = properties.getProperty(Scope.zone.toString()); - iaas.isValidZone(region, zone); - updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone); - updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - updatedIaas.setIaasProvider(updatedIaasProvider); - } - - updateOtherProperties(updatedIaasProvider, properties); - - return updatedIaasProvider; - - } else { - - return iaasProvider; - } - } catch (Exception ex) { - String msg = "Invalid Partition Detected : "+partitionId+". Cause: "+ex.getMessage(); - log.error(msg, ex); - throw new InvalidPartitionException(msg, ex); - } - - } - - private void updateOtherProperties(IaasProvider updatedIaasProvider, - Properties properties) { - Iaas updatedIaas; - try { - updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - - for (Object property : properties.keySet()) { - if (property instanceof String) { - String key = (String) property; - updatedIaasProvider.setProperty(key, - properties.getProperty(key)); - if (log.isDebugEnabled()) { - log.debug("Added property " + key - + " to the IaasProvider."); - } - } - } - updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - updatedIaas.setIaasProvider(updatedIaasProvider); - } catch (InvalidIaasProviderException ignore) { - } - - } - - @Override - public void setIaasProvider(IaasProvider iaas) { - this.iaasProvider = iaas; - this.iaas = iaas.getIaas(); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/CloudstackPartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/CloudstackPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/CloudstackPartitionValidator.java deleted file mode 100644 index 878e49d..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/CloudstackPartitionValidator.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.apache.stratos.cloud.controller.validate; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; -import org.apache.stratos.cloud.controller.interfaces.Iaas; -import org.apache.stratos.cloud.controller.pojo.IaasProvider; -import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.apache.stratos.cloud.controller.util.CloudControllerUtil; -import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator; -import org.apache.stratos.messaging.domain.topology.Scope; - -import java.util.Properties; - - -public class CloudstackPartitionValidator implements PartitionValidator { - - - private static final Log log = LogFactory.getLog(AWSEC2PartitionValidator.class); - private IaasProvider iaasProvider; - private Iaas iaas; - - - @Override - public void setIaasProvider(IaasProvider iaas) { - this.iaasProvider = iaas; - this.iaas = iaas.getIaas(); - } - - @Override - public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException { - - try { - IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider); - Iaas updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - updatedIaas.setIaasProvider(updatedIaasProvider); - - if (properties.containsKey(Scope.zone.toString())) { - String zone = properties.getProperty(Scope.zone.toString()); - iaas.isValidZone(null, zone); - updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone); - updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - updatedIaas.setIaasProvider(updatedIaasProvider); - } - - } catch (Exception ex) { - String msg = "Invalid Partition Detected : "+partitionId+". Cause: "+ex.getMessage(); - log.error(msg, ex); - throw new InvalidPartitionException(msg, ex); - } - return iaasProvider; - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/DockerPartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/DockerPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/DockerPartitionValidator.java deleted file mode 100644 index cb008e0..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/DockerPartitionValidator.java +++ /dev/null @@ -1,79 +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.validate; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException; -import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; -import org.apache.stratos.cloud.controller.iaases.AWSEC2Iaas; -import org.apache.stratos.cloud.controller.interfaces.Iaas; -import org.apache.stratos.cloud.controller.pojo.IaasProvider; -import org.apache.stratos.cloud.controller.util.CloudControllerUtil; -import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator; - -import java.util.Properties; - -/** - * Docker partition validator definition. - */ -public class DockerPartitionValidator implements PartitionValidator { - private static final Log log = LogFactory.getLog(AWSEC2Iaas.class); - - private IaasProvider iaasProvider; - - @Override - public void setIaasProvider(IaasProvider iaasProvider) { - this.iaasProvider = iaasProvider; - } - - @Override - public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException { - // in Docker case currently we only update the custom properties passed via Partitions, and - // no validation done as of now. - IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider); - updateOtherProperties(updatedIaasProvider, properties); - return updatedIaasProvider; - } - - private void updateOtherProperties(IaasProvider updatedIaasProvider, - Properties properties) { - Iaas updatedIaas; - try { - updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - - for (Object property : properties.keySet()) { - if (property instanceof String) { - String key = (String) property; - updatedIaasProvider.setProperty(key, - properties.getProperty(key)); - if (log.isDebugEnabled()) { - log.debug("Added property " + key - + " to the IaasProvider."); - } - } - } - updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - updatedIaas.setIaasProvider(updatedIaasProvider); - } catch (InvalidIaasProviderException ignore) { - } - - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/GCEPartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/GCEPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/GCEPartitionValidator.java deleted file mode 100644 index 7d07d40..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/GCEPartitionValidator.java +++ /dev/null @@ -1,54 +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.validate; - -import java.util.Properties; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; -import org.apache.stratos.cloud.controller.interfaces.Iaas; -import org.apache.stratos.cloud.controller.pojo.IaasProvider; -import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator; - - -/** - * The VCloud {@link PartitionValidator} implementation. - * - */ -public class GCEPartitionValidator implements PartitionValidator { - - private static final Log log = LogFactory.getLog(VCloudPartitionValidator.class); - private IaasProvider iaasProvider; - private Iaas iaas; - - @Override - public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException { - //TODO: implement real validation logic - return iaasProvider; - - } - - @Override - public void setIaasProvider(IaasProvider iaas) { - this.iaasProvider = iaas; - this.iaas = iaas.getIaas(); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java deleted file mode 100644 index 4b49910..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java +++ /dev/null @@ -1,122 +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.validate; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.exception.InvalidIaasProviderException; -import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; -import org.apache.stratos.cloud.controller.interfaces.Iaas; -import org.apache.stratos.cloud.controller.pojo.IaasProvider; -import org.apache.stratos.cloud.controller.util.CloudControllerConstants; -import org.apache.stratos.cloud.controller.util.CloudControllerUtil; -import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator; -import org.apache.stratos.messaging.domain.topology.Scope; - -import java.util.Properties; - - -/** - * The Openstack Nova {@link PartitionValidator} implementation. - * - * - */ -public class OpenstackNovaPartitionValidator implements PartitionValidator { - - private static final Log log = LogFactory.getLog(OpenstackNovaPartitionValidator.class); - private IaasProvider iaasProvider; - private Iaas iaas; - - @Override - public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException { - try { - // validate the existence of the zone and hosts properties. - if (properties.containsKey(Scope.region.toString())) { - String region = properties.getProperty(Scope.region.toString()); - - if (iaasProvider.getImage() != null && !iaasProvider.getImage().contains(region)) { - - String msg = - "Invalid Partition Detected : " + partitionId + - " - Cause: Invalid Region: " + region; - log.error(msg); - throw new InvalidPartitionException(msg); - } - - iaas.isValidRegion(region); - - IaasProvider updatedIaasProvider = new IaasProvider(iaasProvider); - Iaas updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - updatedIaas.setIaasProvider(updatedIaasProvider); - - if (properties.containsKey(Scope.zone.toString())) { - String zone = properties.getProperty(Scope.zone.toString()); - iaas.isValidZone(region, zone); - - updatedIaasProvider.setProperty(CloudControllerConstants.AVAILABILITY_ZONE, zone); - updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - updatedIaas.setIaasProvider(updatedIaasProvider); - } - - updateOtherProperties(updatedIaasProvider, properties); - - return updatedIaasProvider; - - } else { - - return iaasProvider; - } - } catch (Exception ex) { - String msg = "Invalid Partition Detected : "+partitionId+". Cause: "+ex.getMessage(); - log.error(msg, ex); - throw new InvalidPartitionException(msg, ex); - } - } - - private void updateOtherProperties(IaasProvider updatedIaasProvider, - Properties properties) { - Iaas updatedIaas; - try { - updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - - for (Object property : properties.keySet()) { - if (property instanceof String) { - String key = (String) property; - updatedIaasProvider.setProperty(key, - properties.getProperty(key)); - if (log.isDebugEnabled()) { - log.debug("Added property " + key - + " to the IaasProvider."); - } - } - } - updatedIaas = CloudControllerUtil.getIaas(updatedIaasProvider); - updatedIaas.setIaasProvider(updatedIaasProvider); - } catch (InvalidIaasProviderException ignore) { - } - - } - - @Override - public void setIaasProvider(IaasProvider iaas) { - this.iaasProvider = iaas; - this.iaas = iaas.getIaas(); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/VCloudPartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/VCloudPartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/VCloudPartitionValidator.java deleted file mode 100644 index bcaaa41..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/VCloudPartitionValidator.java +++ /dev/null @@ -1,56 +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.validate; - -import java.util.Properties; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; -import org.apache.stratos.cloud.controller.interfaces.Iaas; -import org.apache.stratos.cloud.controller.pojo.IaasProvider; -import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator; - - -/** - * The VCloud {@link PartitionValidator} implementation. - * - */ -public class VCloudPartitionValidator implements PartitionValidator { - - @SuppressWarnings("unused") - private static final Log log = LogFactory.getLog(VCloudPartitionValidator.class); - private IaasProvider iaasProvider; - @SuppressWarnings("unused") - private Iaas iaas; - - @Override - public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException { - //TODO: implement real validation logic - return iaasProvider; - - } - - @Override - public void setIaasProvider(IaasProvider iaas) { - this.iaasProvider = iaas; - this.iaas = iaas.getIaas(); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java deleted file mode 100644 index ae8ec86..0000000 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java +++ /dev/null @@ -1,47 +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.validate.interfaces; - -import java.util.Properties; - -import org.apache.stratos.cloud.controller.exception.InvalidPartitionException; -import org.apache.stratos.cloud.controller.pojo.IaasProvider; - -/** - * All the Partition Validators should implement this interface. - * - * - */ -public interface PartitionValidator { - - /** - * set the IaasProvider reference. - * @param iaas {@link IaasProvider} - */ - public void setIaasProvider(IaasProvider iaas); - - /** - * Validate the given properties for its existent in this partition. - * @param partitionId partition id. - * @param properties set of properties to be validated. - * @return cloned and modified {@link IaasProvider} which maps to the given partition. - * @throws InvalidPartitionException if at least one property is evaluated to be invalid. - */ - public IaasProvider validate(String partitionId, Properties properties) throws InvalidPartitionException; -} http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/services.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/services.xml index c78bd62..f0283f5 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/services.xml +++ b/components/org.apache.stratos.cloud.controller/src/main/resources/META-INF/services.xml @@ -22,7 +22,7 @@ <serviceGroup> <service name="CloudControllerService" scope="application"> - <parameter name="ServiceClass">org.apache.stratos.cloud.controller.impl.CloudControllerServiceImpl</parameter> + <parameter name="ServiceClass">org.apache.stratos.cloud.controller.services.CloudControllerServiceImpl</parameter> <messageReceivers> <messageReceiver mep="http://www.w3.org/ns/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> <messageReceiver mep="http://www.w3.org/ns/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java index aad5b61..7f75802 100644 --- a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java +++ b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomValidationTest.java @@ -21,7 +21,7 @@ package org.apache.cartridge.autoscaler.service.axiom; import java.io.File; import org.apache.axiom.om.OMElement; -import org.apache.stratos.cloud.controller.axiom.AxiomXpathParserUtil; +import org.apache.stratos.cloud.controller.util.AxiomXpathParserUtil; import org.xml.sax.SAXParseException; import junit.framework.TestCase; http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java index 016a9f9..b5bef36 100644 --- a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java +++ b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/AxiomXpathParserTest.java @@ -22,9 +22,9 @@ import junit.framework.TestCase; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMNode; -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.AxiomXpathParserUtil; +import org.apache.stratos.cloud.controller.config.parser.CloudControllerConfigParser; +import org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder; import java.io.File; import java.util.List; http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/FasterLookupDataHolderTest.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/FasterLookupDataHolderTest.java b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/FasterLookupDataHolderTest.java index 69e6b50..a60271f 100644 --- a/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/FasterLookupDataHolderTest.java +++ b/components/org.apache.stratos.cloud.controller/src/test/java/org/apache/cartridge/autoscaler/service/axiom/FasterLookupDataHolderTest.java @@ -18,8 +18,8 @@ */ package org.apache.cartridge.autoscaler.service.axiom; -import org.apache.stratos.cloud.controller.pojo.MemberContext; -import org.apache.stratos.cloud.controller.runtime.FasterLookUpDataHolder; +import org.apache.stratos.cloud.controller.domain.MemberContext; +import org.apache.stratos.cloud.controller.context.FasterLookUpDataHolder; import junit.framework.TestCase; public class FasterLookupDataHolderTest extends TestCase { http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/components/org.apache.stratos.cloud.controller/src/test/resources/cloud-controller.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/test/resources/cloud-controller.xml b/components/org.apache.stratos.cloud.controller/src/test/resources/cloud-controller.xml index 3b1052e..9a256d1 100644 --- a/components/org.apache.stratos.cloud.controller/src/test/resources/cloud-controller.xml +++ b/components/org.apache.stratos.cloud.controller/src/test/resources/cloud-controller.xml @@ -56,7 +56,7 @@ name="A.x" value="a"/> <property name="B" value="b"/> <imageId>tempEC2</imageId> </iaasProvider> --> <iaasProvider type="openstack" name="openstack specific details"> - <className>org.apache.stratos.cloud.controller.iaases.OpenstackNovaIaas</className> + <className>org.apache.stratos.cloud.controller.iaas.OpenstackNovaIaas</className> <provider>openstack-nova</provider> <identity svns:secretAlias="cloud.controller.openstack.identity">demo:demo</identity> <credential svns:secretAlias="cloud.controller.openstack.credential">openstack</credential> http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/conf/cloud-controller.xml ---------------------------------------------------------------------- diff --git a/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/conf/cloud-controller.xml b/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/conf/cloud-controller.xml index 76ac074..03ab854 100644 --- a/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/conf/cloud-controller.xml +++ b/features/cloud-controller/org.apache.stratos.cloud.controller.feature/src/main/resources/conf/cloud-controller.xml @@ -50,7 +50,7 @@ same property over and over again. --> <iaasProviders> <!-- iaasProvider type="openstack" name="openstack specific details"> - <className>org.apache.stratos.cloud.controller.iaases.OpenstackNovaIaas</className> + <className>org.apache.stratos.cloud.controller.iaas.OpenstackNovaIaas</className> <provider>openstack-nova</provider> <identity svns:secretAlias="cloud.controller.openstack.identity">demo:demo</identity> <credential svns:secretAlias="cloud.controller.openstack.credential">openstack</credential> @@ -61,7 +61,7 @@ <property name="Y" value="y" /> </iaasProvider --> <iaasProvider type="docker" name="Docker"> - <className>org.apache.stratos.cloud.controller.iaases.DockerIaas</className> + <className>org.apache.stratos.cloud.controller.iaas.DockerIaas</className> <provider>docker</provider> <identity svns:secretAlias="cloud.controller.docker.identity">identity</identity> <credential svns:secretAlias="cloud.controller.docker.credential">credential</credential> http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/tools/stratos-installer/config/all/repository/conf/cloud-controller.xml ---------------------------------------------------------------------- diff --git a/tools/stratos-installer/config/all/repository/conf/cloud-controller.xml b/tools/stratos-installer/config/all/repository/conf/cloud-controller.xml index f2ab267..14f97e1 100644 --- a/tools/stratos-installer/config/all/repository/conf/cloud-controller.xml +++ b/tools/stratos-installer/config/all/repository/conf/cloud-controller.xml @@ -50,7 +50,7 @@ same property over and over again. --> <iaasProviders> <EC2_PROVIDER_STARTiaasProvider type="ec2" name="ec2 specific details"> - <className>org.apache.stratos.cloud.controller.iaases.AWSEC2Iaas</className> + <className>org.apache.stratos.cloud.controller.iaas.AWSEC2Iaas</className> <provider>aws-ec2</provider> <identity svns:secretAlias="cloud.controller.ec2.identity">EC2_IDENTITY</identity> <credential svns:secretAlias="cloud.controller.ec2.credential">EC2_CREDENTIAL</credential> @@ -61,7 +61,7 @@ <property name="keyPair" value="EC2_KEYPAIR"/> </iaasProviderEC2_PROVIDER_END> <OPENSTACK_PROVIDER_STARTiaasProvider type="openstack" name="openstack specific details"> - <className>org.apache.stratos.cloud.controller.iaases.OpenstackNovaIaas</className> + <className>org.apache.stratos.cloud.controller.iaas.OpenstackNovaIaas</className> <provider>openstack-nova</provider> <identity svns:secretAlias="cloud.controller.openstack.identity">OPENSTACK_IDENTITY</identity> <credential svns:secretAlias="cloud.controller.openstack.credential">OPENSTACK_CREDENTIAL</credential> @@ -74,7 +74,7 @@ <property name="keyPair" value="OPENSTACK_KEYPAIR"/> </iaasProviderOPENSTACK_PROVIDER_END> <VCLOUD_PROVIDER_STARTiaasProvider type="vcloud" name="VMware vCloud specific details"> - <className>org.apache.stratos.cloud.controller.iaases.VCloudIaas</className> + <className>org.apache.stratos.cloud.controller.iaas.VCloudIaas</className> <provider>vcloud</provider> <identity svns:secretAlias="cloud.controller.vcloud.identity">VCLOUD_IDENTITY</identity> <credential svns:secretAlias="cloud.controller.vcloud.credential">VCLOUD_CREDENTIAL</credential> @@ -86,7 +86,7 @@ <property name="Y" value="y" /> </iaasProviderVCLOUD_PROVIDER_END> <GCE_PROVIDER_STARTiaasProvider type="gce" name="GCE specific details"> - <className>org.apache.stratos.cloud.controller.iaases.GCEIaas</className> + <className>org.apache.stratos.cloud.controller.iaas.GCEIaas</className> <provider>google-compute-engine</provider> <identity svns:secretAlias="cloud.controller.gce.identity">GCE_IDENTITY</identity> <credential svns:secretAlias="cloud.controller.gce.credential">GCE_CREDENTIAL</credential> http://git-wip-us.apache.org/repos/asf/stratos/blob/8c359dc1/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml ---------------------------------------------------------------------- diff --git a/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml b/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml index 7a2f220..d79ded0 100644 --- a/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml +++ b/tools/stratos-installer/config/cc/repository/conf/cloud-controller.xml @@ -51,7 +51,7 @@ same property over and over again. --> <iaasProviders> <EC2_PROVIDER_STARTiaasProvider type="ec2" name="ec2 specific details"> - <className>org.apache.stratos.cloud.controller.iaases.AWSEC2Iaas</className> + <className>org.apache.stratos.cloud.controller.iaas.AWSEC2Iaas</className> <provider>aws-ec2</provider> <identity svns:secretAlias="cloud.controller.ec2.identity">EC2_IDENTITY</identity> <credential svns:secretAlias="cloud.controller.ec2.credential">EC2_CREDENTIAL</credential> @@ -62,7 +62,7 @@ <property name="keyPair" value="EC2_KEYPAIR"/> </iaasProviderEC2_PROVIDER_END> <OPENSTACK_PROVIDER_STARTiaasProvider type="openstack" name="openstack specific details"> - <className>org.apache.stratos.cloud.controller.iaases.OpenstackNovaIaas</className> + <className>org.apache.stratos.cloud.controller.iaas.OpenstackNovaIaas</className> <provider>openstack-nova</provider> <identity svns:secretAlias="cloud.controller.openstack.identity">OPENSTACK_IDENTITY</identity> <credential svns:secretAlias="cloud.controller.openstack.credential">OPENSTACK_CREDENTIAL</credential> @@ -75,7 +75,7 @@ <property name="keyPair" value="OPENSTACK_KEYPAIR"/> </iaasProviderOPENSTACK_PROVIDER_END> <VCLOUD_PROVIDER_STARTiaasProvider type="vcloud" name="VMware vCloud specific details"> - <className>org.apache.stratos.cloud.controller.iaases.VCloudIaas</className> + <className>org.apache.stratos.cloud.controller.iaas.VCloudIaas</className> <provider>vcloud</provider> <identity svns:secretAlias="cloud.controller.vcloud.identity">VCLOUD_IDENTITY</identity> <credential svns:secretAlias="cloud.controller.vcloud.credential">VCLOUD_CREDENTIAL</credential>
