/*
 * Copyright 2012-2013 by Cloudsoft Corp.
 *
 * Licensed 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 brooklyn.demo;

import java.util.Arrays;
import java.util.List;

import brooklyn.entity.basic.AbstractApplication;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.basic.StartableApplication;
import brooklyn.entity.nosql.cassandra.CassandraCluster;
import brooklyn.entity.nosql.cassandra.CassandraFabric;
import brooklyn.entity.nosql.cassandra.CassandraNode;
import brooklyn.entity.proxying.EntitySpec;
import brooklyn.launcher.BrooklynLauncher;
import brooklyn.policy.PolicySpec;
import brooklyn.policy.ha.ServiceFailureDetector;
import brooklyn.policy.ha.ServiceReplacer;
import brooklyn.policy.ha.ServiceRestarter;
import brooklyn.util.CommandLineUtil;

import com.google.common.collect.Lists;

public class WideAreaCassandraCluster extends AbstractApplication {

    public static final String DEFAULT_LOCATION_SPEC = "aws-ec2:us-east-1,rackspace-cloudservers-uk";

    @Override
    public void init() {
        addChild(EntitySpec.create(CassandraFabric.class)
                .configure(CassandraCluster.CLUSTER_NAME, "Brooklyn")
                .configure(CassandraCluster.INITIAL_SIZE, 2) // per location
                .configure(CassandraCluster.ENDPOINT_SNITCH_NAME, "brooklyn.entity.nosql.cassandra.customsnitch.MultiCloudSnitch")
                .configure(CassandraNode.CUSTOM_SNITCH_JAR_URL, "classpath://brooklyn/entity/nosql/cassandra/cassandra-multicloud-snitch.jar")
                .configure(CassandraFabric.MEMBER_SPEC, EntitySpec.create(CassandraCluster.class)
                        .configure(CassandraCluster.MEMBER_SPEC, EntitySpec.create(CassandraNode.class)
                                .policy(PolicySpec.create(ServiceFailureDetector.class))
                                .policy(PolicySpec.create(ServiceRestarter.class)
                                        .configure(ServiceRestarter.FAILURE_SENSOR_TO_MONITOR, ServiceFailureDetector.ENTITY_FAILED)))
                        .policy(PolicySpec.create(ServiceReplacer.class)
                                .configure(ServiceReplacer.FAILURE_SENSOR_TO_MONITOR, ServiceRestarter.ENTITY_RESTART_FAILED))));
    }
    
    public static void main(String[] argv) {
        List<String> args = Lists.newArrayList(argv);
        String port =  CommandLineUtil.getCommandLineOption(args, "--port", "8081+");
        String locations = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION_SPEC);

        BrooklynLauncher launcher = BrooklynLauncher.newInstance()
                 .application(EntitySpec.create(StartableApplication.class, WideAreaCassandraCluster.class)
                         .displayName("Cassandra"))
                 .webconsolePort(port)
                 .locations(Arrays.asList(locations))
                 .start();
             
        Entities.dumpInfo(launcher.getApplications());
    }
}

@@ -669,16 +669,163 @@
 .List;%0A%0A
+import brooklyn.catalog.Catalog;%0Aimport brooklyn.catalog.CatalogConfig;%0Aimport brooklyn.config.ConfigKey;%0Aimport brooklyn.entity.basic.ConfigKeys;%0A
 import b
@@ -858,32 +858,32 @@
 actApplication;%0A
-
 import brooklyn.
@@ -1462,16 +1462,144 @@
 Lists;%0A%0A
+@Catalog(name=%22Wide Area Cassandra Cluster Application%22, description=%22Deploy a Cassandra cluster across multiple geographies.%22)%0A
 public c
@@ -1761,17 +1761,290 @@
 rs-uk%22;%0A
+%09%0A%09@CatalogConfig(label=%22Initial Cluster Size (per location)%22, priority=2)%0A    public static final ConfigKey%3CInteger%3E CASSANDRA_CLUSTER_SIZE = ConfigKeys.newConfigKey(%0A        %22cassandra.cluster.initialSize%22, %22Initial size of the Cassandra clusterss%22, 2);      %0A    %0A    %0A%09
 %0A
-
     @Ove
@@ -2260,17 +2260,49 @@
 L_SIZE, 
-2
+getConfig(CASSANDRA_CLUSTER_SIZE)
 ) // per

Update WideAreaCassandraCluster.java