/*
 * 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.status.processor.cluster;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stratos.autoscaler.context.AutoscalerContext;
import org.apache.stratos.autoscaler.context.cluster.ClusterInstanceContext;
import org.apache.stratos.autoscaler.context.partition.network.NetworkPartitionContext;
import org.apache.stratos.autoscaler.event.publisher.ClusterStatusEventPublisher;
import org.apache.stratos.autoscaler.monitor.cluster.ClusterMonitor;
import org.apache.stratos.autoscaler.status.processor.StatusProcessor;

/**
 * Cluster active status processor
 */
public class ClusterStatusActiveProcessor extends ClusterStatusProcessor {
    private static final Log log = LogFactory.getLog(ClusterStatusActiveProcessor.class);
    private ClusterStatusProcessor nextProcessor;

    @Override
    public void setNext(StatusProcessor nextProcessor) {
        this.nextProcessor = (ClusterStatusProcessor) nextProcessor;
    }

    @Override
    public boolean process(String type, String clusterId, String instanceId) {
        boolean statusChanged;
        if (type == null || (ClusterStatusActiveProcessor.class.getName().equals(type))) {
            statusChanged = doProcess(clusterId, instanceId);
            if (statusChanged) {
                return true;
            }

        } else {
            if (nextProcessor != null) {
                // ask the next processor to take care of the message.
                return nextProcessor.process(type, clusterId, instanceId);
            } else {
                log.warn(String.format("No possible state change found for [type] %s [cluster] %s " +
                        "[instance] %s", type, clusterId, instanceId));
            }
        }
        return false;
    }

    private boolean doProcess(String clusterId, String instanceId) {
        ClusterMonitor monitor = AutoscalerContext.getInstance().
                getClusterMonitor(clusterId);
        boolean clusterActive = false;
        for (NetworkPartitionContext clusterLevelNetworkPartitionContext :
                monitor.getNetworkPartitionCtxts()) {
            //minimum check per partition
            ClusterInstanceContext instanceContext =
                    (ClusterInstanceContext) clusterLevelNetworkPartitionContext.
                            getInstanceContext(instanceId);
            if (instanceContext != null) {
                if (instanceContext.getActiveMembers() >= instanceContext.getMinInstanceCount()) {
                    clusterActive = true;
                }
                break;
            }
        }
        if (clusterActive) {
            if (log.isInfoEnabled()) {
                log.info("Publishing cluster activated event for [application]: "
                        + monitor.getAppId() + " [cluster]: " + clusterId);
            }
            //TODO service call
            ClusterStatusEventPublisher.sendClusterActivatedEvent(monitor.getAppId(),
                    monitor.getServiceId(), monitor.getClusterId(), instanceId);
        }
        return clusterActive;
    }
}

@@ -2412,16 +2412,41 @@
 og.warn(
+%0A                        
 String.f
@@ -2496,16 +2496,17 @@
 type%5D %25s
+,
  %5Bcluste
@@ -2510,20 +2510,39 @@
 ster%5D %25s
- %22 +
+, %5Binstance%5D %25s%22, type,
 %0A       
@@ -2562,30 +2562,15 @@
     
-%22%5Binstance%5D %25s%22, type,
+       
  clu
@@ -2938,32 +2938,16 @@
 ontext :
-%0A               
  monitor
@@ -3071,36 +3071,16 @@
 ontext =
-%0A                   
  (Cluste
@@ -3134,24 +3134,16 @@
 ontext.%0A
-        
         
@@ -3528,16 +3528,30 @@
 og.info(
+String.format(
 %22Publish
@@ -3594,18 +3594,41 @@
 lication
-%5D:
+-id%5D %25s, %5Bcluster-id%5D %25s,
  %22%0A     
@@ -3647,16 +3647,44 @@
        +
+ %22%5Bcluster-instance-id%5D %25s%22,
  monitor
@@ -3698,38 +3698,33 @@
 Id()
+,
  
-+ %22 %5B
 cluster
-%5D: %22 + cluster
+Id, instance
 Id)
+)
 ;%0A  
@@ -3806,16 +3806,37 @@
 ublisher
+%0A                    
 .sendClu
@@ -3873,36 +3873,16 @@
 AppId(),
-%0A                   
  monitor
@@ -3921,16 +3921,44 @@
 terId(),
+%0A                           
  instanc

Add instance id to log messages in autoscaler ClusterStatusActiveProcessor