Repository: stratos Updated Branches: refs/heads/stratos-4.1.x 13930c37c -> b73ff9468
Adding validation to the Kubernetes cluster Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/b73ff946 Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/b73ff946 Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/b73ff946 Branch: refs/heads/stratos-4.1.x Commit: b73ff946890e61ddce72cafaee3bd98ef182d40d Parents: 13930c3 Author: gayangunarathne <[email protected]> Authored: Tue Nov 10 13:52:18 2015 +0530 Committer: gayangunarathne <[email protected]> Committed: Tue Nov 10 13:52:47 2015 +0530 ---------------------------------------------------------------------- .../KubernetesClusterAlreadyUsedException.java | 49 ++++++++++++++++++++ .../impl/CloudControllerServiceImpl.java | 19 ++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/b73ff946/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/KubernetesClusterAlreadyUsedException.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/KubernetesClusterAlreadyUsedException.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/KubernetesClusterAlreadyUsedException.java new file mode 100644 index 0000000..93b866c --- /dev/null +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/exception/KubernetesClusterAlreadyUsedException.java @@ -0,0 +1,49 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * +*/ + +package org.apache.stratos.cloud.controller.exception; + +/** + * Exception class for handling invalid Kubernetes cluster + */ +public class KubernetesClusterAlreadyUsedException extends Exception { + + private String message; + + public KubernetesClusterAlreadyUsedException(String message, Exception exception) { + super(message, exception); + this.message = message; + } + + public KubernetesClusterAlreadyUsedException(Exception exception) { + super(exception); + } + + public KubernetesClusterAlreadyUsedException(String msg) { + super(msg); + this.message = msg; + } + + @Override + public String getMessage() { + return this.message; + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b73ff946/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java index c255189..812679d 100644 --- a/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java +++ b/components/org.apache.stratos.cloud.controller/src/main/java/org/apache/stratos/cloud/controller/services/impl/CloudControllerServiceImpl.java @@ -35,7 +35,7 @@ import org.apache.stratos.cloud.controller.messaging.topology.TopologyManager; import org.apache.stratos.cloud.controller.services.CloudControllerService; import org.apache.stratos.cloud.controller.util.CloudControllerConstants; import org.apache.stratos.cloud.controller.util.CloudControllerUtil; -import org.apache.stratos.common.*; +import org.apache.stratos.common.Property; import org.apache.stratos.common.domain.LoadBalancingIPType; import org.apache.stratos.common.threading.StratosThreadPool; import org.apache.stratos.messaging.domain.topology.*; @@ -43,7 +43,6 @@ import org.wso2.carbon.registry.core.exceptions.RegistryException; import java.util.*; import java.util.Map.Entry; -import java.util.Properties; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; @@ -56,12 +55,14 @@ import java.util.concurrent.locks.Lock; */ public class CloudControllerServiceImpl implements CloudControllerService { - private static final Log log = LogFactory.getLog(CloudControllerServiceImpl.class); + private static final Log log = LogFactory.getLog(CloudControllerServiceImpl.class); private static final String PERSISTENCE_MAPPING = "PERSISTENCE_MAPPING"; public static final String PAYLOAD_PARAMETER = "payload_parameter."; + public static final String KUBERNETES_PROVIDER = "kubernetes"; + public static final String KUBERNETES_CLUSTER = "cluster"; - private CloudControllerContext cloudControllerContext = CloudControllerContext.getInstance(); + private CloudControllerContext cloudControllerContext = CloudControllerContext.getInstance(); private ExecutorService executorService; public CloudControllerServiceImpl() { @@ -1363,6 +1364,16 @@ public class CloudControllerServiceImpl implements CloudControllerService { if (StringUtils.isEmpty(kubernetesClusterId)) { throw new NonExistingKubernetesClusterException("Kubernetes cluster id cannot be empty"); } + Collection<NetworkPartition> networkPartitions=CloudControllerContext.getInstance().getNetworkPartitions(); + for(NetworkPartition networkPartition:networkPartitions){ + if(networkPartition.getProvider().equals(KUBERNETES_PROVIDER)){ + for(Property property:networkPartition.getProperties().getProperties()){ + if(property.getName().equals(KUBERNETES_CLUSTER)&&property.getValue().equals(kubernetesClusterId)){ + new KubernetesClusterAlreadyUsedException("Kubernetes cluster is already used in the network partition"); + } + } + } + } Lock lock = null; try {
