<commit_before>package brooklyn.example

import brooklyn.entity.basic.AbstractApplication
import brooklyn.entity.group.Cluster
import brooklyn.entity.webapp.tomcat.TomcatCluster
import brooklyn.entity.webapp.tomcat.TomcatNode

import brooklyn.location.basic.SshMachineLocation
import com.google.common.base.Preconditions
import brooklyn.location.basic.GeneralPurposeLocation
import brooklyn.location.basic.FixedListMachineProvisioningLocation
import brooklyn.location.Location

/**
 * Starts some tomcat nodes, on localhost, using ssh;
 * installs from scratch each time, for now, which may be overkill, but signposts.
 * then dumps JMX stats periodically.
 * 
 * @author alex
 */
public class SimpleTomcatApp extends AbstractApplication {
    Cluster tc = new TomcatCluster(displayName:'MyTomcat', initialSize: 3, owner: this);

    public static void main(String[] argv) {
        def app = new SimpleTomcatApp()
        URL resource = SimpleTomcatApp.class.getClassLoader().getResource("hello-world.war")
        Preconditions.checkState resource != null, "Unable to locate resource hello-world.war"
        app.tc.template.setConfig(TomcatNode.WAR, resource.getPath())
           //TODO:
//        app.tc.policy << new ElasticityPolicy(app.tc, TomcatCluster.REQS_PER_SEC, low:100, high:250);
        app.tc.initialSize = 2  //override initial size

        Collection<InetAddress> hosts = [
            Inet4Address.getByAddress((byte[])[192,168,144,241]),
            Inet4Address.getByAddress((byte[])[192,168,144,242])
        ]
        Collection<SshMachineLocation> machines = hosts.collect {
            new SshMachineLocation(address: it, userName: "cloudsoft")
        }
        Location location = new FixedListMachineProvisioningLocation<SshMachineLocation>(machines: machines, name: "London")

        app.tc.start([location])

        Thread t = []
        t.start {
            while (!t.isInterrupted()) {
                Thread.sleep 5000
                app.getEntities().each { if (it in TomcatNode) {
                        println it.toString()
                        println "Requests per second: " + it.getAttribute(TomcatNode.REQUESTS_PER_SECOND)
                        println "Error count: " + it.getAttribute(TomcatNode.ERROR_COUNT)
                    }
                }
            }
        }
<commit_msg>Modify SimpleTomcatApp to use new DynamicCluster class<commit_after>package brooklyn.example

import brooklyn.entity.basic.AbstractApplication
import brooklyn.entity.group.Cluster
import brooklyn.entity.webapp.tomcat.TomcatCluster
import brooklyn.entity.webapp.tomcat.TomcatNode

import brooklyn.location.basic.SshMachineLocation
import com.google.common.base.Preconditions
import brooklyn.location.basic.GeneralPurposeLocation
import brooklyn.location.basic.FixedListMachineProvisioningLocation
import brooklyn.location.Location
import brooklyn.entity.group.DynamicCluster

/**
 * Starts some tomcat nodes, on localhost, using ssh;
 * installs from scratch each time, for now, which may be overkill, but signposts.
 * then dumps JMX stats periodically.
 * 
 * @author alex
 */
public class SimpleTomcatApp extends AbstractApplication {
    DynamicCluster tc = new DynamicCluster(displayName:'MyTomcat', initialSize: 1,
        newEntity: {
            def tc = new TomcatNode()
            URL resource = SimpleTomcatApp.class.getClassLoader().getResource("hello-world.war")
            Preconditions.checkState resource != null, "Unable to locate resource hello-world.war"
            tc.setConfig(TomcatNode.WAR, resource.getPath())
            return tc;
        },
        owner: this);

    public static void main(String[] argv) {
        def app = new SimpleTomcatApp()
           //TODO:
//        app.tc.policy << new ElasticityPolicy(app.tc, TomcatCluster.REQS_PER_SEC, low:100, high:250);
        app.tc.initialSize = 2  //override initial size

        Collection<InetAddress> hosts = [
            Inet4Address.getByAddress((byte[])[192,168,144,241]),
            Inet4Address.getByAddress((byte[])[192,168,144,242]),
            Inet4Address.getByAddress((byte[])[192,168,144,243]),
            Inet4Address.getByAddress((byte[])[192,168,144,244]),
            Inet4Address.getByAddress((byte[])[192,168,144,245]),
            Inet4Address.getByAddress((byte[])[192,168,144,246])
        ]
        Collection<SshMachineLocation> machines = hosts.collect {
            new SshMachineLocation(address: it, userName: "cloudsoft")
        }
        Location location = new FixedListMachineProvisioningLocation<SshMachineLocation>(machines: machines, name: "London")

        app.tc.start([location])

        Thread t = []
        t.start {
            while (!t.isInterrupted()) {
                Thread.sleep 5000
                app.getEntities().each { if (it in TomcatNode) {
                        println it.toString()
                        println "Requests per second: " + it.getAttribute(TomcatNode.REQUESTS_PER_SECOND)
                        println "Error count: " + it.getAttribute(TomcatNode.ERROR_COUNT)
                    }
                }
            }
        }

{'fraction_non_alphanumeric': 0.10099241097489783, 'fraction_numerical': 0.024907569566063437, 'mean_word_length': 2.8358208955223883, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1562958', 'n_tokens_mistral': 1534, 'n_tokens_neox': 1421, 'n_words': 295}