http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesGroupException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesGroupException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesGroupException.java
new file mode 100644
index 0000000..5edd926
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesGroupException.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.autoscaler.exception.kubernetes;
+
+/**
+ * Exception class for handling invalid Kubernetes Group
+ */
+public class InvalidKubernetesGroupException extends Exception {
+
+    private String message;
+
+    public InvalidKubernetesGroupException(String message, Exception 
exception){
+        super(message, exception);
+        this.message = message;
+    }
+
+    public InvalidKubernetesGroupException(Exception exception){
+        super(exception);
+    }
+
+    public InvalidKubernetesGroupException(String msg){
+        super(msg);
+        this.message = msg;
+    }
+
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesHostException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesHostException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesHostException.java
new file mode 100644
index 0000000..f0c651c
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesHostException.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.autoscaler.exception.kubernetes;
+
+/**
+ * Exception class for handling invalid Kubernetes Host
+ */
+public class InvalidKubernetesHostException extends Exception {
+
+    private String message;
+
+    public InvalidKubernetesHostException(String message, Exception exception){
+        super(message, exception);
+        this.message = message;
+    }
+
+    public InvalidKubernetesHostException(Exception exception){
+        super(exception);
+    }
+
+    public InvalidKubernetesHostException(String msg){
+        super(msg);
+        this.message = msg;
+    }
+
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesMasterException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesMasterException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesMasterException.java
new file mode 100644
index 0000000..5852952
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidKubernetesMasterException.java
@@ -0,0 +1,27 @@
+package org.apache.stratos.autoscaler.exception.kubernetes;
+
+/**
+ * Exception class for handling invalid Kubernetes Master
+ */
+public class InvalidKubernetesMasterException extends Exception {
+    private String message;
+
+    public InvalidKubernetesMasterException(String message, Exception 
exception){
+        super(message, exception);
+        this.message = message;
+    }
+
+    public InvalidKubernetesMasterException(Exception exception){
+        super(exception);
+    }
+
+    public InvalidKubernetesMasterException(String msg){
+        super(msg);
+        this.message = msg;
+    }
+
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidServiceGroupException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidServiceGroupException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidServiceGroupException.java
new file mode 100644
index 0000000..6c1f709
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/InvalidServiceGroupException.java
@@ -0,0 +1,46 @@
+/*
+ * 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.autoscaler.exception.kubernetes;
+
+public class InvalidServiceGroupException extends Exception {
+
+
+    private static final long serialVersionUID = 2651280146514042590L;
+
+    private String message;
+
+    public InvalidServiceGroupException(String msg) {
+        super(msg);
+        this.setMessage(msg);
+    }
+
+    public InvalidServiceGroupException(String msg, Exception ex) {
+        super(msg, ex);
+        this.setMessage(msg);
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/KubernetesEndpointValidationException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/KubernetesEndpointValidationException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/KubernetesEndpointValidationException.java
new file mode 100644
index 0000000..ce80ed7
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/KubernetesEndpointValidationException.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.autoscaler.exception.kubernetes;
+
+/**
+ * Exception class for handling Kubernetes endpoint validation
+ */
+public class KubernetesEndpointValidationException extends Exception {
+    private String message;
+
+    public KubernetesEndpointValidationException(String message, Exception 
exception){
+        super(message, exception);
+        this.setMessage(message);
+    }
+
+    public KubernetesEndpointValidationException(String msg) {
+        super(msg);
+        this.message = msg;
+    }
+    public KubernetesEndpointValidationException(Exception exception){
+        super(exception);
+    }
+
+
+    public String getMessage() {
+        return message;
+    }
+
+
+    public void setMessage(String message) {
+        this.message = message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesGroupException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesGroupException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesGroupException.java
new file mode 100644
index 0000000..ec982d9
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesGroupException.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.autoscaler.exception.kubernetes;
+
+/**
+ * Exception class for handling non-existing Kubernetes Group
+ */
+public class NonExistingKubernetesGroupException extends Exception {
+
+    private String message;
+
+    public NonExistingKubernetesGroupException(String message, Exception 
exception){
+        super(message, exception);
+        this.message = message;
+    }
+
+    public NonExistingKubernetesGroupException(Exception exception){
+        super(exception);
+    }
+
+    public NonExistingKubernetesGroupException(String msg){
+        super(msg);
+        this.message = msg;
+    }
+
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesHostException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesHostException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesHostException.java
new file mode 100644
index 0000000..99c2588
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesHostException.java
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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.autoscaler.exception.kubernetes;
+
+/**
+ * Exception class for handling non-existing Kubernetes Host
+ */
+public class NonExistingKubernetesHostException extends Exception {
+    private String message;
+
+    public NonExistingKubernetesHostException(String message, Exception 
exception){
+        super(message, exception);
+        this.message = message;
+    }
+
+    public NonExistingKubernetesHostException(Exception exception){
+        super(exception);
+    }
+
+    public NonExistingKubernetesHostException(String msg){
+        super(msg);
+        this.message = msg;
+    }
+
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesMasterException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesMasterException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesMasterException.java
new file mode 100644
index 0000000..48228b5
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/kubernetes/NonExistingKubernetesMasterException.java
@@ -0,0 +1,48 @@
+/*
+ *
+ * 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.autoscaler.exception.kubernetes;
+
+/**
+ * Exception class for handling non-existing Kubernetes Master
+ */
+public class NonExistingKubernetesMasterException extends Exception {
+    private String message;
+
+    public NonExistingKubernetesMasterException(String message, Exception 
exception){
+        super(message, exception);
+        this.message = message;
+    }
+
+    public NonExistingKubernetesMasterException(Exception exception){
+        super(exception);
+    }
+
+    public NonExistingKubernetesMasterException(String msg){
+        super(msg);
+        this.message = msg;
+    }
+
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/partition/InvalidPartitionException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/partition/InvalidPartitionException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/partition/InvalidPartitionException.java
new file mode 100644
index 0000000..0acc9e9
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/partition/InvalidPartitionException.java
@@ -0,0 +1,51 @@
+package org.apache.stratos.autoscaler.exception.partition;
+/*
+ *
+ * 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.
+ *
+*/
+
+
+/**
+ *
+ */
+public class InvalidPartitionException extends Exception {
+
+    private static final long serialVersionUID = -7521673271244696906L;
+    private String message;
+
+    public InvalidPartitionException(String message, Exception exception){
+        super(message, exception);
+        this.message = message;
+    }
+
+
+    public InvalidPartitionException(Exception exception){
+        super(exception);
+    }
+    
+    public InvalidPartitionException(String msg){
+        super(msg);
+        this.message = msg;
+    }
+    
+    @Override
+    public String getMessage() {
+        return this.message;
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/partition/PartitionValidationException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/partition/PartitionValidationException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/partition/PartitionValidationException.java
new file mode 100644
index 0000000..ae36f34
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/partition/PartitionValidationException.java
@@ -0,0 +1,54 @@
+package org.apache.stratos.autoscaler.exception.partition;
+/*
+ *
+ * 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.
+ *
+*/
+
+
+/**
+ *
+ */
+public class PartitionValidationException extends Exception {
+
+       private static final long serialVersionUID = -3904452358279522141L;
+       private String message;
+
+       public PartitionValidationException(String message, Exception 
exception){
+        super(message, exception);
+        this.setMessage(message);
+    }
+
+       public PartitionValidationException(String msg) {
+               super(msg);
+               this.message = msg;
+       }
+    public PartitionValidationException(Exception exception){
+        super(exception);
+    }
+
+
+       public String getMessage() {
+               return message;
+       }
+
+
+       public void setMessage(String message) {
+               this.message = message;
+       }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/policy/InvalidPolicyException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/policy/InvalidPolicyException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/policy/InvalidPolicyException.java
new file mode 100644
index 0000000..c8d4494
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/policy/InvalidPolicyException.java
@@ -0,0 +1,46 @@
+/*
+ * 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.autoscaler.exception.policy;
+
+public class InvalidPolicyException extends Exception {
+
+       private static final long serialVersionUID = -4914522749282514366L;
+       private String message;
+       
+       public InvalidPolicyException(String message) {
+               super(message);
+               this.message = message;
+       }
+       
+       public InvalidPolicyException(String message,Throwable e) {
+               super(message,e);
+               this.message = message;
+       }
+       
+       public InvalidPolicyException(Throwable e) {
+               super(e);
+       }
+       
+       @Override
+       public String getMessage() {
+               return message;
+       }
+       
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/policy/PolicyValidationException.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/policy/PolicyValidationException.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/policy/PolicyValidationException.java
new file mode 100644
index 0000000..c3a5fbe
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/exception/policy/PolicyValidationException.java
@@ -0,0 +1,56 @@
+package org.apache.stratos.autoscaler.exception.policy;
+/*
+ *
+ * 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.
+ *
+*/
+
+
+/**
+ *
+ */
+public class PolicyValidationException extends Exception {
+
+    private static final long serialVersionUID = -7423800138697480115L;
+    private String message;
+
+    public PolicyValidationException(String message, Exception exception){
+        super(message, exception);
+        this.setMessage(message);
+    }
+
+
+    public PolicyValidationException(Exception exception){
+        super(exception);
+    }
+    
+    public PolicyValidationException(String msg){
+        super(msg);
+        this.setMessage(msg);
+    }
+
+
+       public String getMessage() {
+               return message;
+       }
+
+
+       public void setMessage(String message) {
+               this.message = message;
+       }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java
index 204cc79..39601d9 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/interfaces/AutoScalerServiceInterface.java
@@ -22,12 +22,13 @@
 package org.apache.stratos.autoscaler.interfaces;
 
 import org.apache.stratos.autoscaler.applications.pojo.ApplicationContext;
+import org.apache.stratos.autoscaler.exception.kubernetes.*;
 import org.apache.stratos.autoscaler.policy.model.DeploymentPolicy;
 import org.apache.stratos.autoscaler.exception.*;
-import org.apache.stratos.autoscaler.exception.ApplicationDefinitionException;
-import org.apache.stratos.autoscaler.exception.InvalidPartitionException;
-import org.apache.stratos.autoscaler.exception.InvalidPolicyException;
-import org.apache.stratos.autoscaler.exception.NonExistingLBException;
+import 
org.apache.stratos.autoscaler.exception.application.ApplicationDefinitionException;
+import 
org.apache.stratos.autoscaler.exception.partition.InvalidPartitionException;
+import org.apache.stratos.autoscaler.exception.policy.InvalidPolicyException;
+import 
org.apache.stratos.autoscaler.exception.cartridge.NonExistingLBException;
 import org.apache.stratos.autoscaler.partition.PartitionGroup;
 import org.apache.stratos.autoscaler.pojo.ServiceGroup;
 import org.apache.stratos.autoscaler.policy.model.AutoscalePolicy;
@@ -99,7 +100,7 @@ public interface AutoScalerServiceInterface {
      * Register a Kubernetes cluster.
      *
      * @param kubernetesGroup
-     * @throws InvalidKubernetesGroupException
+     * @throws 
org.apache.stratos.autoscaler.exception.kubernetes.InvalidKubernetesGroupException
      */
     public boolean addKubernetesGroup(KubernetesGroup kubernetesGroup) throws 
InvalidKubernetesGroupException;
 
@@ -108,7 +109,7 @@ public interface AutoScalerServiceInterface {
      *
      * @param groupId
      * @param kubernetesHost
-     * @throws InvalidKubernetesHostException
+     * @throws 
org.apache.stratos.autoscaler.exception.kubernetes.InvalidKubernetesHostException
      */
     public boolean addKubernetesHost(String groupId, KubernetesHost 
kubernetesHost) throws
             InvalidKubernetesHostException, 
NonExistingKubernetesGroupException;

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/kubernetes/KubernetesManager.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/kubernetes/KubernetesManager.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/kubernetes/KubernetesManager.java
index 1c45da6..4eb420a 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/kubernetes/KubernetesManager.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/kubernetes/KubernetesManager.java
@@ -23,7 +23,7 @@ import com.google.common.net.InetAddresses;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.exception.*;
+import org.apache.stratos.autoscaler.exception.kubernetes.*;
 import org.apache.stratos.autoscaler.registry.RegistryManager;
 import org.apache.stratos.autoscaler.util.AutoScalerConstants;
 import org.apache.stratos.common.kubernetes.KubernetesGroup;

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
index 7413d50..4625785 100644
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/Monitor.java
@@ -18,6 +18,8 @@
  */
 package org.apache.stratos.autoscaler.monitor;
 
+import org.apache.stratos.autoscaler.monitor.component.ParentComponentMonitor;
+
 /**
  * Abstract class for the monitoring functionality in autoscaler.
  */

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
new file mode 100644
index 0000000..6fbcaab
--- /dev/null
+++ 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorFactory.java
@@ -0,0 +1,256 @@
+/*
+ * 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.autoscaler.monitor;
+
+import org.apache.stratos.autoscaler.context.AutoscalerContext;
+import org.apache.stratos.autoscaler.applications.ApplicationHolder;
+import 
org.apache.stratos.autoscaler.applications.dependency.context.ApplicationChildContext;
+import 
org.apache.stratos.autoscaler.applications.dependency.context.ClusterChildContext;
+import 
org.apache.stratos.autoscaler.applications.dependency.context.GroupChildContext;
+import org.apache.stratos.autoscaler.client.CloudControllerClient;
+import 
org.apache.stratos.autoscaler.exception.application.DependencyBuilderException;
+import 
org.apache.stratos.autoscaler.exception.partition.PartitionValidationException;
+import 
org.apache.stratos.autoscaler.exception.policy.PolicyValidationException;
+import 
org.apache.stratos.autoscaler.exception.application.TopologyInConsistentException;
+import org.apache.stratos.autoscaler.monitor.cluster.AbstractClusterMonitor;
+import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitorFactory;
+import org.apache.stratos.autoscaler.monitor.component.ApplicationMonitor;
+import org.apache.stratos.autoscaler.monitor.component.GroupMonitor;
+import org.apache.stratos.autoscaler.monitor.component.ParentComponentMonitor;
+import org.apache.stratos.messaging.domain.applications.Application;
+import org.apache.stratos.messaging.domain.applications.Group;
+import org.apache.stratos.messaging.domain.topology.Cluster;
+import org.apache.stratos.messaging.domain.topology.Service;
+import org.apache.stratos.messaging.domain.topology.Topology;
+import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
+
+import java.util.List;
+
+/**
+ * Factory class to get the Monitors.
+ */
+public class MonitorFactory {
+
+    /**
+     * Factor method used to create relevant monitors based on the given 
context
+     *
+     * @param context       Application/Group/Cluster context
+     * @param appId         appId of the application which requires to create 
app monitor
+     * @param parentMonitor parent of the monitor
+     * @return Monitor which can be 
ApplicationMonitor/GroupMonitor/ClusterMonitor
+     * @throws TopologyInConsistentException throws while traversing thr 
topology
+     * @throws DependencyBuilderException    throws while building dependency 
for app monitor
+     * @throws PolicyValidationException     throws while validating the 
policy associated with cluster
+     * @throws PartitionValidationException  throws while validating the 
partition used in a cluster
+     */
+    public static Monitor getMonitor(ParentComponentMonitor parentMonitor,
+                                     ApplicationChildContext context, String 
appId, List<String> instanceId)
+            throws TopologyInConsistentException,
+            DependencyBuilderException, PolicyValidationException, 
PartitionValidationException {
+       
+        Monitor monitor;
+        if (context instanceof GroupChildContext) {
+            monitor = getGroupMonitor(parentMonitor, context, appId, 
instanceId);
+        } else if (context instanceof ClusterChildContext) {
+            monitor = getClusterMonitor(parentMonitor, (ClusterChildContext) 
context);
+            if (monitor != null) {
+               //((AbstractClusterMonitor)monitor).startScheduler();
+                ClusterChildContext clusterChildCtxt = (ClusterChildContext) 
context;
+                AbstractClusterMonitor clusterMonitor = 
(AbstractClusterMonitor)monitor;
+                // FIXME: passing null as alias for cluster instance 
temporarily. should be removed.
+                createClusterInstance(clusterChildCtxt.getServiceName(), 
clusterMonitor.getClusterId(), null, instanceId.get(0));
+               
AutoscalerContext.getInstance().addClusterMonitor((AbstractClusterMonitor)monitor);
+                       }
+        } else {
+            monitor = getApplicationMonitor(appId);
+        }
+        return monitor;
+    }
+
+    private static void createClusterInstance (String serviceType, String 
clusterId, String alias, String instanceId) {
+        CloudControllerClient.getInstance().createClusterInstance(serviceType, 
clusterId, alias, instanceId);
+    }
+
+    /**
+     * This will create the GroupMonitor based on given groupId by going thr 
Topology
+     *
+     * @param parentMonitor parent of the monitor
+     * @param context       groupId of the group
+     * @param appId         appId of the relevant application
+     * @return Group monitor
+     * @throws DependencyBuilderException    throws while building dependency 
for app monitor
+     * @throws TopologyInConsistentException throws while traversing thr 
topology
+     */
+    public static Monitor getGroupMonitor(ParentComponentMonitor parentMonitor,
+                                          ApplicationChildContext context, 
String appId, List<String> instanceIds)
+            throws DependencyBuilderException,
+            TopologyInConsistentException {
+        GroupMonitor groupMonitor;
+        ApplicationHolder.acquireReadLock();
+
+        try {
+            Group group = ApplicationHolder.getApplications().
+                    getApplication(appId).getGroupRecursively(context.getId());
+            groupMonitor = new GroupMonitor(group, appId, instanceIds);
+            groupMonitor.setAppId(appId);
+            if (parentMonitor != null) {
+                groupMonitor.setParent(parentMonitor);
+                //Setting the dependent behaviour of the monitor
+                if (parentMonitor.hasStartupDependents() || 
(context.hasStartupDependents() && context.hasChild())) {
+                    groupMonitor.setHasStartupDependents(true);
+                } else {
+                    groupMonitor.setHasStartupDependents(false);
+                }
+
+                if(group.isGroupScalingEnabled()) {
+                    groupMonitor.setGroupScalingEnabled(true);
+                } else if(parentMonitor instanceof GroupMonitor) {
+                    if(((GroupMonitor)parentMonitor).isGroupScalingEnabled() ||
+                            parentMonitor.hasGroupScalingDependent()) {
+                        groupMonitor.setHasGroupScalingDependent(true);
+                    }
+                }
+
+                //Starting the minimum dependencies
+                groupMonitor.startMinimumDependencies(group, instanceIds);
+                //TODO*********** make it sync with the topology in the restart
+
+                /*if (group.getStatus() != groupMonitor.getStatus()) {
+                    //updating the status, if the group is not in created 
state when creating group Monitor
+                    //so that groupMonitor will notify the parent (useful when 
restarting stratos)
+                    groupMonitor.setStatus(group.getStatus());
+                }*/
+            }
+
+        } finally {
+            ApplicationHolder.releaseReadLock();
+
+        }
+        return groupMonitor;
+
+    }
+
+    /**
+     * This will create a new app monitor based on the give appId by getting 
the
+     * application from Topology
+     *
+     * @param appId appId of the application which requires to create app 
monitor
+     * @return ApplicationMonitor
+     * @throws DependencyBuilderException    throws while building dependency 
for app monitor
+     * @throws TopologyInConsistentException throws while traversing thr 
topology
+     */
+    public static ApplicationMonitor getApplicationMonitor(String appId)
+            throws DependencyBuilderException,
+            TopologyInConsistentException, PolicyValidationException {
+        ApplicationMonitor applicationMonitor;
+        ApplicationHolder.acquireReadLock();
+        try {
+            Application application = 
ApplicationHolder.getApplications().getApplication(appId);
+            if (application != null) {
+                applicationMonitor = new ApplicationMonitor(application);
+                applicationMonitor.setHasStartupDependents(false);
+                applicationMonitor.startMinimumDependencies(application);
+
+            } else {
+                String msg = "[Application] " + appId + " cannot be found in 
the Topology";
+                throw new TopologyInConsistentException(msg);
+            }
+        } finally {
+            ApplicationHolder.releaseReadLock();
+
+        }
+
+        return applicationMonitor;
+
+    }
+
+    /**
+     * Updates ClusterContext for given cluster
+     *
+     * @param parentMonitor parent of the monitor
+     * @param context
+     * @return ClusterMonitor - Updated ClusterContext
+     * @throws 
org.apache.stratos.autoscaler.exception.policy.PolicyValidationException
+     * @throws 
org.apache.stratos.autoscaler.exception.partition.PartitionValidationException
+     */
+    public static AbstractClusterMonitor 
getClusterMonitor(ParentComponentMonitor parentMonitor,
+                                                            
ClusterChildContext context)
+            throws PolicyValidationException,
+            PartitionValidationException,
+            TopologyInConsistentException {
+       
+        //Retrieving the Cluster from Topology
+        String clusterId = context.getId();
+        String serviceName = context.getServiceName();
+        Cluster cluster;
+        //acquire read lock for the service and cluster
+        TopologyManager.acquireReadLockForCluster(serviceName, clusterId);
+        try {
+            Topology topology = TopologyManager.getTopology();
+            if (topology.serviceExists(serviceName)) {
+                Service service = topology.getService(serviceName);
+                if (service.clusterExists(clusterId)) {
+                    cluster = service.getCluster(clusterId);
+                } else {
+                    String msg = "[Cluster] " + clusterId + " cannot be found 
in the " +
+                            "Topology for [service] " + serviceName;
+                    throw new TopologyInConsistentException(msg);
+                }
+            } else {
+                String msg = "[Service] " + serviceName + " cannot be found in 
the Topology";
+                throw new TopologyInConsistentException(msg);
+            }
+            AbstractClusterMonitor clusterMonitor = 
ClusterMonitorFactory.getMonitor(cluster);
+            //Setting the parent of the cluster monitor
+            clusterMonitor.setParent(parentMonitor);
+            clusterMonitor.setId(clusterId);
+
+            //setting the startup dependent behaviour of the cluster monitor
+            if(parentMonitor.hasStartupDependents() || 
(context.hasStartupDependents() && context.hasChild())) {
+                clusterMonitor.setHasStartupDependents(true);
+            } else {
+                clusterMonitor.setHasStartupDependents(false);
+            }
+
+            //setting the scaling dependent behaviour of the cluster monitor
+            if(parentMonitor.hasGroupScalingDependent() || 
(context.isGroupScalingEnabled())) {
+                clusterMonitor.setHasGroupScalingDependent(true);
+            } else {
+                clusterMonitor.setHasGroupScalingDependent(false);
+            }
+            //setting the status of the cluster, if it doesn't match with 
Topology cluster status.
+            //TODO after adding cluster instances*************
+            /*if (cluster.getStatus(null) != clusterMonitor.getStatus()) {
+                //updating the status, so that it will notify the parent
+                clusterMonitor.setStatus(cluster.getStatus(null));
+            } else {
+                if(!cluster.hasMembers()) {
+                    
StatusChecker.getInstance().onMemberStatusChange(clusterId);
+                }
+            }*/
+            if(cluster.getInstanceContextCount() > 0) {
+                //Starting the cluster monitor as existing instances are found
+            }
+            return clusterMonitor;
+
+        } finally {
+            TopologyManager.releaseReadLockForCluster(serviceName, clusterId);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
deleted file mode 100644
index 39593d1..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/MonitorStatusEventBuilder.java
+++ /dev/null
@@ -1,92 +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.autoscaler.monitor;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.monitor.cluster.AbstractClusterMonitor;
-import org.apache.stratos.autoscaler.monitor.events.*;
-import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
-import org.apache.stratos.messaging.domain.applications.ApplicationStatus;
-import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-import org.apache.stratos.messaging.domain.applications.GroupStatus;
-import org.apache.stratos.messaging.domain.topology.lifecycle.LifeCycleState;
-
-/**
- * This will build the necessary monitor status events to be sent to the 
parent/child  monitor
- */
-public class MonitorStatusEventBuilder {
-    private static final Log log = 
LogFactory.getLog(MonitorStatusEventBuilder.class);
-
-    public static void handleClusterStatusEvent(ParentComponentMonitor parent, 
ClusterStatus status, String clusterId) {
-        ClusterStatusEvent clusterStatusEvent = new ClusterStatusEvent(status, 
clusterId, null);
-        notifyParent(parent, clusterStatusEvent);
-    }
-
-    public static void handleGroupStatusEvent(ParentComponentMonitor parent, 
GroupStatus status,
-                                              String groupId, String 
instanceId) {
-        GroupStatusEvent groupStatusEvent = new GroupStatusEvent(status, 
groupId, instanceId);
-        notifyParent(parent, groupStatusEvent);
-    }
-
-    public static void handleApplicationStatusEvent(ParentComponentMonitor 
parent, ApplicationStatus status,
-                                                    String appId, String 
instanceId) {
-        ApplicationStatusEvent applicationStatusEvent = new 
ApplicationStatusEvent(status, appId, instanceId);
-        notifyParent(parent, applicationStatusEvent);
-    }
-
-    public static void handleClusterScalingEvent(ParentComponentMonitor parent,
-                                                 String networkPartitionId, 
float factor, String appId) {
-
-        //Send notifications to parent of the cluster monitor
-        MonitorScalingEvent monitorScalingEvent = new 
MonitorScalingEvent(appId, networkPartitionId, null,factor) ;
-        notifyParent(parent, monitorScalingEvent);
-    }
-
-    private static void notifyParent(ParentComponentMonitor parent, 
MonitorStatusEvent statusEvent) {
-        parent.onChildStatusEvent(statusEvent);
-    }
-
-    public static void notifyChildren (ParentComponentMonitor 
componentMonitor, MonitorStatusEvent statusEvent) {
-        for (Monitor activeChildMonitor : 
componentMonitor.getAliasToActiveMonitorsMap().values()) {
-            activeChildMonitor.onParentStatusEvent(statusEvent);
-        }
-    }
-
-    public static void notifyChildGroup(Monitor child, GroupStatus state, 
String instanceId) {
-        MonitorStatusEvent statusEvent = new GroupStatusEvent(state, 
child.getId(), instanceId);
-        child.onParentStatusEvent(statusEvent);
-    }
-
-    public static void notifyChildCluster(Monitor child, ClusterStatus state, 
String instanceId) {
-        MonitorStatusEvent statusEvent = new ClusterStatusEvent(state, 
child.getId(), instanceId);
-        child.onParentStatusEvent(statusEvent);
-    }
-
-    private static void notifyParent(ParentComponentMonitor parent, 
MonitorScalingEvent scalingEvent) {
-        parent.onChildScalingEvent(scalingEvent);
-    }
-
-    public static void notifyChildren (ParentComponentMonitor 
componentMonitor, MonitorScalingEvent scalingEvent) {
-        for (Monitor activeChildMonitor : 
componentMonitor.getAliasToActiveMonitorsMap().values()) {
-            activeChildMonitor.onParentScalingEvent(scalingEvent);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/stratos/blob/e9902546/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
----------------------------------------------------------------------
diff --git 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
 
b/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
deleted file mode 100644
index 92e2a54..0000000
--- 
a/components/org.apache.stratos.autoscaler/src/main/java/org/apache/stratos/autoscaler/monitor/ParentComponentMonitor.java
+++ /dev/null
@@ -1,640 +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.autoscaler.monitor;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.stratos.autoscaler.Constants;
-import org.apache.stratos.autoscaler.algorithm.AutoscaleAlgorithm;
-import org.apache.stratos.autoscaler.algorithm.OneAfterAnother;
-import org.apache.stratos.autoscaler.algorithm.RoundRobin;
-import org.apache.stratos.autoscaler.applications.ApplicationHolder;
-import org.apache.stratos.autoscaler.applications.dependency.DependencyBuilder;
-import org.apache.stratos.autoscaler.applications.dependency.DependencyTree;
-import 
org.apache.stratos.autoscaler.applications.dependency.context.ApplicationChildContext;
-import 
org.apache.stratos.autoscaler.applications.dependency.context.ClusterChildContext;
-import 
org.apache.stratos.autoscaler.applications.dependency.context.GroupChildContext;
-import org.apache.stratos.autoscaler.applications.topic.ApplicationBuilder;
-import 
org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher;
-import org.apache.stratos.autoscaler.exception.*;
-import 
org.apache.stratos.autoscaler.monitor.application.ApplicationMonitorFactory;
-import org.apache.stratos.autoscaler.monitor.cluster.AbstractClusterMonitor;
-import org.apache.stratos.autoscaler.monitor.group.GroupMonitor;
-import org.apache.stratos.autoscaler.status.processor.StatusChecker;
-import org.apache.stratos.messaging.domain.applications.GroupStatus;
-import org.apache.stratos.messaging.domain.applications.ParentComponent;
-import org.apache.stratos.messaging.domain.instance.Instance;
-import org.apache.stratos.messaging.domain.topology.ClusterStatus;
-import org.apache.stratos.messaging.message.receiver.topology.TopologyManager;
-
-import java.util.*;
-
-/**
- * Monitor is to monitor it's child monitors and
- * control them according to the dependencies respectively.
- */
-public abstract class ParentComponentMonitor extends Monitor {
-    private static final Log log = 
LogFactory.getLog(ParentComponentMonitor.class);
-
-    //The monitors dependency tree with all the start-able/kill-able 
dependencies
-    protected DependencyTree startupDependencyTree;
-    //The monitors dependency tree with all the scaling dependencies
-    protected DependencyTree scalingDependencyTree;
-    //monitors map, key=GroupAlias/clusterId and 
value=GroupMonitor/AbstractClusterMonitor
-    protected Map<String, Monitor> aliasToActiveMonitorsMap;
-    //monitors map, stopped monitors
-    protected List<String> inactiveMonitorsList;
-    //terminating monitors list
-    protected List<String> terminatingMonitorsList;
-
-    public ParentComponentMonitor(ParentComponent component) throws 
DependencyBuilderException {
-        aliasToActiveMonitorsMap = new HashMap<String, Monitor>();
-        inactiveMonitorsList = new ArrayList<String>();
-        terminatingMonitorsList = new ArrayList<String>();
-        //clusterIdToClusterMonitorsMap = new HashMap<String, 
AbstractClusterMonitor>();
-        this.id = component.getUniqueIdentifier();
-        //Building the startup dependencies for this monitor within the 
immediate children
-        startupDependencyTree = 
DependencyBuilder.getInstance().buildDependency(component);
-        //Building the scaling dependencies for this monitor within the 
immediate children
-        scalingDependencyTree = 
DependencyBuilder.getInstance().buildDependency(component);
-    }
-
-    /**
-     * This will start the parallel dependencies at once from the top level.
-     * it will get invoked when the monitor starts up only.
-     */
-    public void startDependency(ParentComponent component, List<String> 
instanceIds) throws TopologyInConsistentException {
-        //start the first dependency
-        List<ApplicationChildContext> applicationContexts = 
this.startupDependencyTree.
-                getStarAbleDependencies();
-        startDependency(applicationContexts, instanceIds);
-
-    }
-
-    /**
-     * This will start the parallel dependencies at once from the top level.
-     * it will get invoked when the monitor starts up only.
-     */
-    public void startDependency(ParentComponent component, String instanceId)
-                                                            throws 
TopologyInConsistentException,
-                                                                    
ParentMonitorNotFoundException {
-        //start the first dependency
-        List<ApplicationChildContext> applicationContexts = 
this.startupDependencyTree.
-                getStarAbleDependencies();
-        startDependency(applicationContexts, instanceId);
-
-    }
-
-    /**
-     * This will start the parallel dependencies at once from the top level.
-     * it will get invoked when the monitor starts up only.
-     */
-    public void startDependency(ParentComponent component) throws 
TopologyInConsistentException {
-        //start the first dependency
-        List<ApplicationChildContext> applicationContexts = 
this.startupDependencyTree.
-                getStarAbleDependencies();
-        Collection<Instance> contexts = 
component.getInstanceIdToInstanceContextMap().values();
-        //traversing through all the Instance context and start them
-        List<String> instanceIds = new ArrayList<String>();
-        for (Instance context : contexts) {
-            instanceIds.add(context.getInstanceId());
-        }
-        startDependency(applicationContexts, instanceIds);
-    }
-
-    /**
-     * This will get invoked based on the activation event of its one of the 
child
-     *
-     * @param id alias/clusterId of which receive the activated event
-     */
-    public boolean startDependency(String id, String instanceId) throws 
TopologyInConsistentException {
-        List<ApplicationChildContext> applicationContexts = 
this.startupDependencyTree
-                .getStarAbleDependencies(id);
-        List<String> instanceIds = new ArrayList<String>();
-        instanceIds.add(instanceId);
-        return startDependency(applicationContexts, instanceIds);
-    }
-
-    public boolean startAllChildrenDependency(ParentComponent component, 
String instanceId) throws TopologyInConsistentException {
-        /*List<ApplicationChildContext> applicationContexts = 
this.startupDependencyTree
-                .findAllChildrenOfAppContext(id);*/
-        return false;//startDependency(applicationContexts, instanceId);
-    }
-
-    /**
-     * This will start the parallel dependencies at once from the top level
-     * by traversing to find the terminated dependencies.
-     * it will get invoked when start a child monitor on termination of a sub 
tree
-     */
-    public void startDependencyOnTermination() throws 
TopologyInConsistentException {
-        //start the first dependency which went to terminated
-        List<ApplicationChildContext> applicationContexts = 
this.startupDependencyTree.
-                getStarAbleDependenciesByTermination();
-        //FIXME to create new instanceIds
-        //startDependency(applicationContexts, null);
-
-    }
-
-
-    /**
-     * To start the dependency of the given application contexts
-     *
-     * @param applicationContexts the found applicationContexts to be started
-     */
-    private boolean startDependency(List<ApplicationChildContext> 
applicationContexts, List<String> instanceIds) {
-        if (applicationContexts != null && applicationContexts.isEmpty()) {
-            //all the groups/clusters have been started and waiting for 
activation
-            log.info("There is no child found for the [group]: " + this.id);
-            return false;
-
-        }
-        for (ApplicationChildContext context : applicationContexts) {
-            if (log.isDebugEnabled()) {
-                log.debug("Dependency check for the Group " + context.getId() 
+ " started");
-            }
-            if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
-                //to avoid if it is already started
-                startMonitor(this, context, instanceIds);
-            } else {
-                //starting a new instance of the child
-                Monitor monitor = 
aliasToActiveMonitorsMap.get(context.getId());
-                for (String instanceId : instanceIds) {
-                    if (context instanceof ClusterChildContext) {
-                        MonitorStatusEventBuilder.notifyChildCluster(monitor, 
ClusterStatus.Created, instanceId);
-                    } else if (context instanceof GroupChildContext) {
-                        MonitorStatusEventBuilder.notifyChildGroup(monitor, 
GroupStatus.Created, instanceId);
-                    }
-                }
-
-            }
-        }
-
-        return true;
-
-    }
-
-    /**
-     * To start the dependency of the given application contexts
-     *
-     * @param applicationContexts the found applicationContexts to be started
-     */
-    private boolean startDependency(List<ApplicationChildContext> 
applicationContexts, String instanceId)
-            throws ParentMonitorNotFoundException {
-        if (applicationContexts != null && applicationContexts.isEmpty()) {
-            //all the groups/clusters have been started and waiting for 
activation
-            log.info("There is no child found for the [group]: " + this.id);
-            return false;
-
-        }
-        for (ApplicationChildContext context : applicationContexts) {
-            if (log.isDebugEnabled()) {
-                log.debug("Dependency check for the Group " + context.getId() 
+ " started");
-            }
-            //FIXME whether to start new monitor or throw exception
-            if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
-                String msg = "Required Monitor cannot be fount in the 
hierarchy";
-                throw new ParentMonitorNotFoundException(msg);
-            } else {
-                //starting a new instance of the child
-                Monitor monitor = 
aliasToActiveMonitorsMap.get(context.getId());
-                if (context instanceof ClusterChildContext) {
-                    MonitorStatusEventBuilder.notifyChildCluster(monitor, 
ClusterStatus.Created, instanceId);
-                } else if (context instanceof GroupChildContext) {
-                    MonitorStatusEventBuilder.notifyChildGroup(monitor, 
GroupStatus.Created, instanceId);
-                }
-
-            }
-        }
-
-        return true;
-
-    }
-
-    protected String generateInstanceId(ParentComponent component) {
-        String instanceId = component.getUniqueIdentifier() + "_" +
-                (component.getInstanceContextCount() + 1);
-        return instanceId;
-    }
-
-    /**
-     * This will start the child monitors based on the active of siblings 
according to start up order
-     *
-     * @param eventId parent id of the event which received
-     */
-    protected void onChildActivatedEvent(String eventId, String instanceId) {
-        try {
-            //if the activated monitor is in in_active map move it to active 
map
-            if (this.inactiveMonitorsList.contains(eventId)) {
-                this.inactiveMonitorsList.remove(eventId);
-            }
-
-            if (this.terminatingMonitorsList.contains(eventId)) {
-                this.terminatingMonitorsList.remove(eventId);
-            }
-
-            boolean startDep = startDependency(eventId, instanceId);
-            if (log.isDebugEnabled()) {
-                log.debug("started a child: " + startDep + " by the 
group/cluster: " + eventId);
-
-            }
-            if (!startDep) {
-                StatusChecker.getInstance().onChildStatusChange(eventId, 
this.id, this.appId, instanceId);
-            }
-        } catch (TopologyInConsistentException e) {
-            //TODO revert the siblings and notify parent, change a flag for 
reverting/un-subscription
-            log.error(e);
-        }
-
-    }
-
-    /**
-     * @param eventId
-     */
-    protected void onChildInactiveEvent(String eventId, String instanceId) {
-        List<ApplicationChildContext> terminationList;
-        Monitor monitor;
-        terminationList = 
this.startupDependencyTree.getTerminationDependencies(eventId);
-        //Need to notify the parent about the status  change from 
Active-->InActive
-        if (this.parent != null) {
-            StatusChecker.getInstance().onChildStatusChange(eventId, this.id, 
this.appId, instanceId);
-        }
-        //TODO checking whether terminating them in reverse order,
-        // TODO if so can handle it in the parent event.
-
-        //Since it is reached the most independent unit and has few 
independent monitors,
-        // has to put the children down to terminating
-        if (this.startupDependencyTree.getTerminationBehavior() ==
-                DependencyTree.TerminationBehavior.TERMINATE_ALL &&
-                terminationList.size() == 
this.aliasToActiveMonitorsMap.size()) {
-            //handling the killall scenario
-            if (this.parent != null) {
-                //send terminating to the parent. So that it will push 
terminating to its children
-                ApplicationBuilder.handleGroupTerminatingEvent(this.appId, 
eventId, instanceId);
-            } else {
-                //if it is an application, send terminating event individually 
for children
-                sendTerminatingEventOnNotification(terminationList, eventId, 
true, instanceId);
-            }
-            log.info("The group" + eventId + " has been marked as terminating 
" +
-                    "due to all the children are to be terminated");
-        } else {
-            sendTerminatingEventOnNotification(terminationList, eventId, 
false, instanceId);
-        }
-    }
-
-    private void 
sendTerminatingEventOnNotification(List<ApplicationChildContext> 
terminationList,
-                                                    String notifier, boolean 
terminateAll, String instanceId) {
-        Monitor monitor;
-        //Checking the termination dependents status
-        for (ApplicationChildContext terminationContext : terminationList) {
-            //Check whether dependent is in_active, then start to kill it
-            monitor = this.aliasToActiveMonitorsMap.
-                    get(terminationContext.getId());
-            //start to kill it
-            if (monitor != null) {
-                if (monitor instanceof GroupMonitor) {
-                    //it is a group, so not sending terminating as it can be 
in inActive. If group needs terminating,
-                    //it will be handled by the terminating case of its 
children
-                    if (terminateAll || !notifier.equals(monitor.getId())) {
-                        
ApplicationBuilder.handleGroupTerminatingEvent(this.appId,
-                                terminationContext.getId(), instanceId);
-                    }
-                } else {
-                    if (log.isInfoEnabled()) {
-                        log.info("Publishing Cluster Terminating event for 
[application]: " + appId +
-                                " [group] " + this.id + " [cluster]: " + 
terminationContext.getId());
-                    }
-                    
ClusterStatusEventPublisher.sendClusterTerminatingEvent(this.appId,
-                            ((AbstractClusterMonitor) monitor).getServiceId(),
-                            terminationContext.getId(), instanceId);
-                }
-            } else {
-                log.warn("The relevant [monitor] " + 
terminationContext.getId() +
-                        "is not in the active map....");
-            }
-
-        }
-    }
-
-    /**
-     * Act upon one of its children got terminated
-     *
-     * @param eventId id of the notifier
-     */
-
-    protected void onChildTerminatedEvent(String eventId, String instanceId) {
-        List<ApplicationChildContext> terminationList;
-        boolean allDependentTerminated = false;
-
-        ApplicationChildContext context = this.startupDependencyTree.
-                findApplicationContextWithIdInPrimaryTree(eventId);
-        context.setTerminated(true);
-        terminationList = 
this.startupDependencyTree.getTerminationDependencies(eventId);
-        //Make sure that all the dependents have been terminated properly to 
start the recovery
-        if (terminationList != null) {
-            allDependentTerminated = allDependentTerminated(terminationList);
-        }
-
-        List<ApplicationChildContext> parentContexts = 
this.startupDependencyTree.
-                findAllParentContextWithId(eventId);
-        boolean parentsTerminated = false;
-        boolean allParentsActive = false;
-        //make sure all the parent contexts got terminated or whether all of 
them are active
-        if (parentContexts != null) {
-            parentsTerminated = allParentTerminated(parentContexts);
-            allParentsActive = allParentActive(parentContexts);
-        }
-
-        if ((terminationList.isEmpty() || allDependentTerminated) &&
-                (parentContexts.isEmpty() || parentsTerminated || 
allParentsActive)) {
-            //Find the non existent monitor by traversing dependency tree
-            try {
-                this.startDependencyOnTermination();
-            } catch (TopologyInConsistentException e) {
-                //TODO revert the siblings and notify parent, change a flag 
for reverting/un-subscription
-                log.error("Error while starting the monitor upon termination" 
+ e);
-            }
-        } else {
-            StatusChecker.getInstance().onChildStatusChange(eventId, this.id, 
this.appId, instanceId);
-            log.info("Checking the status of group/application as no dependent 
found...");
-        }
-
-
-    }
-
-    private boolean allDependentTerminated(List<ApplicationChildContext> 
terminationList) {
-        boolean allDependentTerminated = false;
-        for (ApplicationChildContext context1 : terminationList) {
-            if (this.aliasToActiveMonitorsMap.containsKey(context1.getId())) {
-                log.warn("Dependent [monitor] " + context1.getId() + " not in 
the correct state");
-                allDependentTerminated = false;
-                return allDependentTerminated;
-            } else if (this.inactiveMonitorsList.contains(context1.getId())) {
-                log.info("Waiting for the [dependent] " + context1.getId() + " 
to be terminated...");
-                allDependentTerminated = false;
-                return allDependentTerminated;
-            } else {
-                allDependentTerminated = true;
-            }
-        }
-        return allDependentTerminated;
-    }
-
-
-    private boolean allParentTerminated(List<ApplicationChildContext> 
parentContexts) {
-        boolean parentsTerminated = false;
-        for (ApplicationChildContext context1 : parentContexts) {
-            if (this.inactiveMonitorsList.contains(context1.getId())) {
-                log.info("Waiting for the [Parent Monitor] " + context1.getId()
-                        + " to be terminated");
-                parentsTerminated = false;
-                return parentsTerminated;
-            } else if 
(this.aliasToActiveMonitorsMap.containsKey(context1.getId())) {
-                if (parentsTerminated) {
-                    log.warn("Found the Dependent [monitor] " + 
context1.getId()
-                            + " in the active list wrong state");
-                }
-            } else {
-                log.info("[Parent Monitor] " + context1.getId()
-                        + " has already been terminated");
-                parentsTerminated = true;
-            }
-        }
-        return parentsTerminated;
-    }
-
-    private boolean allParentActive(List<ApplicationChildContext> 
parentContexts) {
-        boolean parentsActive = false;
-        for (ApplicationChildContext context1 : parentContexts) {
-            if (this.inactiveMonitorsList.contains(context1.getId()) ||
-                    this.terminatingMonitorsList.contains(context1.getId())) {
-                parentsActive = false;
-                log.info("Dependent [Monitor] " + context1.getId()
-                        + " is not yet active");
-                return parentsActive;
-            } else if 
(this.aliasToActiveMonitorsMap.containsKey(context1.getId())) {
-                Monitor monitor = 
this.aliasToActiveMonitorsMap.get(context1.getId());
-
-                if (monitor instanceof GroupMonitor) {
-                    GroupMonitor monitor1 = (GroupMonitor) monitor;
-                    ApplicationHolder.acquireReadLock();
-                    try {
-                        //TODO***********
-                        /*if (monitor1.getStatus() == GroupStatus.Active) {
-                            parentsActive = true;
-
-                        }*/
-                    } finally {
-                        ApplicationHolder.releaseReadLock();
-                    }
-                } else if (monitor instanceof AbstractClusterMonitor) {
-                    AbstractClusterMonitor monitor1 = (AbstractClusterMonitor) 
monitor;
-                    
TopologyManager.acquireReadLockForCluster(monitor1.getServiceId(),
-                            monitor1.getClusterId());
-                    try {
-                        if (monitor1.getStatus() == ClusterStatus.Active) {
-                            parentsActive = true;
-                        }
-                    } finally {
-                        
TopologyManager.releaseReadLockForCluster(monitor1.getServiceId(),
-                                monitor1.getClusterId());
-                    }
-                }
-
-            }
-        }
-        return parentsActive;
-    }
-
-    // move to inactive monitors list to use in the Terminated event
-    protected synchronized void markMonitorAsInactive(String monitorKey) {
-
-        if (!this.inactiveMonitorsList.contains(monitorKey)) {
-            this.inactiveMonitorsList.add(monitorKey);
-        }
-    }
-
-    // move to inactive monitors list to use in the Terminated event
-    protected synchronized void markMonitorAsTerminating(String monitorKey) {
-        if (!this.terminatingMonitorsList.contains(monitorKey)) {
-            if (this.inactiveMonitorsList.contains(monitorKey)) {
-                this.inactiveMonitorsList.remove(monitorKey);
-            }
-            this.terminatingMonitorsList.add(monitorKey);
-        }
-    }
-
-    protected synchronized void startMonitor(ParentComponentMonitor parent,
-                                             ApplicationChildContext context, 
List<String> instanceId) {
-        Thread th = null;
-        if (!this.aliasToActiveMonitorsMap.containsKey(context.getId())) {
-            th = new Thread(
-                    new MonitorAdder(parent, context, this.appId, instanceId));
-            if (log.isDebugEnabled()) {
-                log.debug(String
-                        .format("Monitor Adder has been added: [cluster] %s ",
-                                context.getId()));
-            }
-        }
-        if (th != null) {
-            th.start();
-            log.info(String
-                    .format("Monitor thread has been started successfully: 
[cluster] %s ",
-                            context.getId()));
-        }
-    }
-
-    public Map<String, Monitor> getAliasToActiveMonitorsMap() {
-        return aliasToActiveMonitorsMap;
-    }
-
-    public void setAliasToActiveMonitorsMap(Map<String, Monitor> 
aliasToActiveMonitorsMap) {
-        this.aliasToActiveMonitorsMap = aliasToActiveMonitorsMap;
-    }
-
-    public boolean hasActiveMonitors() {
-        boolean hasMonitor = false;
-        if ((this.aliasToActiveMonitorsMap != null && 
!this.aliasToActiveMonitorsMap.isEmpty())) {
-            hasMonitor = true;
-        }
-        return hasMonitor;
-    }
-
-    public boolean hasMonitors() {
-
-        return this.aliasToActiveMonitorsMap != null;
-    }
-
-    public boolean hasIndependentChild() {
-        boolean hasInDepChild = false;
-        for (Monitor monitor : this.aliasToActiveMonitorsMap.values()) {
-            if (!monitor.hasStartupDependents()) {
-                hasInDepChild = true;
-                break;
-            }
-        }
-        return hasInDepChild;
-    }
-
-    public List<String> getAliasToInActiveMonitorsMap() {
-        return this.inactiveMonitorsList;
-    }
-
-    public void setAliasToInActiveMonitorsMap(List<String> 
inactiveMonitorsList) {
-        this.inactiveMonitorsList = inactiveMonitorsList;
-    }
-
-    public List<String> getTerminatingMonitorsList() {
-        return terminatingMonitorsList;
-    }
-
-    public void setTerminatingMonitorsList(List<String> 
terminatingMonitorsList) {
-        this.terminatingMonitorsList = terminatingMonitorsList;
-    }
-
-    public AutoscaleAlgorithm getAutoscaleAlgorithm(String partitionAlgorithm) 
{
-        AutoscaleAlgorithm autoscaleAlgorithm = null;
-        if (log.isDebugEnabled()) {
-            log.debug(String.format("Partition algorithm is ", 
partitionAlgorithm));
-        }
-        if (Constants.ROUND_ROBIN_ALGORITHM_ID.equals(partitionAlgorithm)) {
-
-            autoscaleAlgorithm = new RoundRobin();
-        } else if 
(Constants.ONE_AFTER_ANOTHER_ALGORITHM_ID.equals(partitionAlgorithm)) {
-
-            autoscaleAlgorithm = new OneAfterAnother();
-        } else {
-            if (log.isErrorEnabled()) {
-                log.error(String.format("Partition algorithm %s could not be 
identified !", partitionAlgorithm));
-            }
-        }
-        return autoscaleAlgorithm;
-    }
-
-    private class MonitorAdder implements Runnable {
-        private ApplicationChildContext context;
-        private ParentComponentMonitor parent;
-        private String appId;
-        private List<String> instanceId;
-
-        public MonitorAdder(ParentComponentMonitor parent, 
ApplicationChildContext context,
-                            String appId, List<String> instanceId) {
-            this.parent = parent;
-            this.context = context;
-            this.appId = appId;
-            this.instanceId = instanceId;
-        }
-
-        public void run() {
-            Monitor monitor = null;
-            int retries = 5;
-            boolean success;
-            do {
-                try {
-                    Thread.sleep(5000);
-                } catch (InterruptedException e1) {
-                }
-
-                if (log.isDebugEnabled()) {
-                    log.debug("Monitor is going to be started for 
[group/cluster] "
-                            + context.getId());
-                }
-                try {
-                    monitor = ApplicationMonitorFactory.getMonitor(parent, 
context, appId, instanceId);
-                } catch (DependencyBuilderException e) {
-                    String msg = "Monitor creation failed for: " + 
context.getId();
-                    log.warn(msg, e);
-                    retries--;
-                } catch (TopologyInConsistentException e) {
-                    String msg = "Monitor creation failed for: " + 
context.getId();
-                    log.warn(msg, e);
-                    retries--;
-                } catch (PolicyValidationException e) {
-                    String msg = "Monitor creation failed for: " + 
context.getId();
-                    log.warn(msg, e);
-                    retries--;
-                } catch (PartitionValidationException e) {
-                    String msg = "Monitor creation failed for: " + 
context.getId();
-                    log.warn(msg, e);
-                    retries--;
-
-                }
-                success = true;
-
-            } while (!success && retries != 0);
-
-
-            if (monitor == null) {
-                String msg = "Monitor creation failed, even after retrying for 
5 times, "
-                        + "for : " + context.getId();
-                log.error(msg);
-                //TODO parent.notify();
-                throw new RuntimeException(msg);
-            }
-
-            aliasToActiveMonitorsMap.put(context.getId(), monitor);
-            // ApplicationBuilder.
-            if (log.isInfoEnabled()) {
-                log.info(String.format("Monitor has been added successfully 
for: %s",
-                        context.getId()));
-            }
-        }
-    }
-
-
-}
\ No newline at end of file

Reply via email to