You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by ni...@apache.org on 2013/11/27 19:54:59 UTC
[02/26] git commit: adding partition validator
adding partition validator
Project: http://git-wip-us.apache.org/repos/asf/incubator-stratos/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-stratos/commit/c00725ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-stratos/tree/c00725ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-stratos/diff/c00725ae
Branch: refs/heads/master
Commit: c00725aee8869ae5cb24f690c8e4059c6d7646fc
Parents: 7ea5e79
Author: Nirmal Fernando <ni...@apache.org>
Authored: Fri Nov 22 14:05:50 2013 +0530
Committer: Nirmal Fernando <ni...@apache.org>
Committed: Fri Nov 22 14:05:50 2013 +0530
----------------------------------------------------------------------
.../validate/AWSEC2PartitionValidator.java | 67 ++++++++++++++++++++
.../OpenstackNovaPartitionValidator.java | 67 ++++++++++++++++++++
.../validate/interfaces/PartitionValidator.java | 52 +++++++++++++++
3 files changed, 186 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c00725ae/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
new file mode 100644
index 0000000..037e23d
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/AWSEC2PartitionValidator.java
@@ -0,0 +1,67 @@
+/*
+ * 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.stratos.cloud.controller.interfaces.Iaas;
+import org.apache.stratos.cloud.controller.util.IaasProvider;
+import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator;
+import org.apache.stratos.messaging.domain.topology.Scope;
+
+
+/**
+ * AWS-EC2 {@link PartitionValidator} implementation.
+ * @author nirmal
+ *
+ */
+public class AWSEC2PartitionValidator implements PartitionValidator {
+
+ private static final String NAME = "ec2";
+ private IaasProvider iaasProvider;
+ private Iaas iaas;
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean validate(Properties properties) {
+ // validate the existence of the region and zone properties.
+ if (properties.containsKey(Scope.REGION.toString())) {
+ String region = properties.getProperty(Scope.REGION.name());
+ if (iaas.isValidRegion(iaasProvider, region)) {
+ if (properties.containsKey(Scope.ZONE.toString())) {
+ String zone = properties.getProperty(Scope.ZONE.name());
+ return iaas.isValidZone(iaasProvider, region, zone);
+ } else {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void setIaasProvider(IaasProvider iaas) {
+ this.iaasProvider = iaas;
+ this.iaas = iaas.getIaas();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c00725ae/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
new file mode 100644
index 0000000..88e4be2
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/OpenstackNovaPartitionValidator.java
@@ -0,0 +1,67 @@
+/*
+ * 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.stratos.cloud.controller.interfaces.Iaas;
+import org.apache.stratos.cloud.controller.util.IaasProvider;
+import org.apache.stratos.cloud.controller.validate.interfaces.PartitionValidator;
+import org.apache.stratos.messaging.domain.topology.Scope;
+
+
+/**
+ * The Openstack Nova {@link PartitionValidator} implementation.
+ * @author nirmal
+ *
+ */
+public class OpenstackNovaPartitionValidator implements PartitionValidator {
+
+ private static final String NAME = "openstack";
+ private IaasProvider iaasProvider;
+ private Iaas iaas;
+
+ @Override
+ public String getName() {
+ return NAME;
+ }
+
+ @Override
+ public boolean validate(Properties properties) {
+ // validate the existence of the zone and hosts properties.
+ if (properties.containsKey(Scope.ZONE.toString())) {
+ String zone = properties.getProperty(Scope.ZONE.toString());
+ if (iaas.isValidZone(iaasProvider, null, zone)) {
+ if (properties.containsKey(Scope.HOST.toString())) {
+ String host = properties.getProperty(Scope.HOST.toString());
+ return iaas.isValidHost(iaasProvider, zone, host);
+ } else {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void setIaasProvider(IaasProvider iaas) {
+ this.iaasProvider = iaas;
+ this.iaas = iaas.getIaas();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/c00725ae/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
new file mode 100644
index 0000000..7279bab
--- /dev/null
+++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/validate/interfaces/PartitionValidator.java
@@ -0,0 +1,52 @@
+/*
+ * 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.interfaces.Iaas;
+import org.apache.stratos.cloud.controller.util.IaasProvider;
+
+/**
+ * All the Partition Validators should implement this interface.
+ * @author nirmal
+ *
+ */
+public interface PartitionValidator {
+
+ /**
+ * set the IaasProvider reference.
+ * @param iaas {@link IaasProvider}
+ */
+ public void setIaasProvider(IaasProvider iaas);
+
+ /**
+ * Should return the name of this validator.
+ * @return name.
+ */
+ public String getName();
+
+
+ /**
+ * Validate the given properties for its existent in this partition.
+ * @param properties set of properties to be validated.
+ * @return whether it's validated to true or not.
+ */
+ public boolean validate(Properties properties);
+}