Search in sources :

Example 6 with Network

use of io.fabric8.maven.docker.model.Network in project fabric8 by jboss-fuse.

the class MQProfileTest method testMQCreateNetwork.

@Test
public void testMQCreateNetwork() throws Exception {
    System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
    // System.out.println(executeCommand("shell:info"));
    // System.out.println(executeCommand("fabric:info"));
    // System.out.println(executeCommand("fabric:profile-list"));
    executeCommand("mq-create --no-ssl --group us-east --network us-west --jmx-user admin --jmx-password admin --networks-username admin --networks-password admin --minimumInstances 1 us-east");
    executeCommand("mq-create --no-ssl --group us-west --network us-east --jmx-user admin --jmx-password admin --networks-username admin --networks-password admin --minimumInstances 1 us-west");
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
        Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 4).withName("child").withProfiles("default").assertProvisioningResult().build();
        try {
            LinkedList<Container> containerList = new LinkedList<Container>(containers);
            Container eastBroker = containerList.removeLast();
            Container westBroker = containerList.removeLast();
            Profile eastBrokerProfile = eastBroker.getVersion().getRequiredProfile("mq-broker-us-east.us-east");
            eastBroker.setProfiles(new Profile[] { eastBrokerProfile });
            Profile westBrokerProfile = eastBroker.getVersion().getRequiredProfile("mq-broker-us-west.us-west");
            westBroker.setProfiles(new Profile[] { westBrokerProfile });
            Provision.provisioningSuccess(Arrays.asList(westBroker, eastBroker), PROVISION_TIMEOUT);
            waitForBroker("us-east");
            waitForBroker("us-west");
            final BrokerViewMBean brokerEast = (BrokerViewMBean) Provision.getMBean(eastBroker, new ObjectName("org.apache.activemq:type=Broker,brokerName=us-east"), BrokerViewMBean.class, 120000);
            final BrokerViewMBean brokerWest = (BrokerViewMBean) Provision.getMBean(westBroker, new ObjectName("org.apache.activemq:type=Broker,brokerName=us-west"), BrokerViewMBean.class, 120000);
            Assert.assertNotNull("Cannot get BrokerViewMBean from JMX", brokerEast);
            Assert.assertNotNull("Cannot get BrokerViewMBean from JMX", brokerWest);
            Container eastProducer = containerList.removeLast();
            executeCommand("container-add-profile " + eastProducer.getId() + " example-mq-producer mq-client-us-east");
            Container westConsumer = containerList.removeLast();
            executeCommand("container-add-profile " + westConsumer.getId() + " example-mq-consumer mq-client-us-west");
            Provision.provisioningSuccess(Arrays.asList(eastProducer, westConsumer), PROVISION_TIMEOUT);
            System.out.println(executeCommand("fabric:container-list"));
            Provision.waitForCondition(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    while (brokerEast.getTotalEnqueueCount() == 0 || brokerWest.getTotalDequeueCount() == 0) {
                        Thread.sleep(1000);
                    }
                    return true;
                }
            }, 120000L);
            System.out.println(executeCommand("fabric:container-connect -u admin -p admin " + eastBroker.getId() + " bstat"));
            System.out.println(executeCommand("fabric:container-connect -u admin -p admin " + westBroker.getId() + " bstat"));
            Assert.assertFalse("Messages not sent", brokerEast.getTotalEnqueueCount() == 0);
            Assert.assertFalse("Messages not received", brokerWest.getTotalDequeueCount() == 0);
        } finally {
            ContainerBuilder.destroy(containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : LinkedList(java.util.LinkedList) Profile(io.fabric8.api.Profile) ObjectName(javax.management.ObjectName) BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) Test(org.junit.Test)

Aggregations

Container (io.fabric8.api.Container)2 Profile (io.fabric8.api.Profile)2 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)2 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)2 Container (io.fabric8.maven.docker.model.Container)2 Network (io.fabric8.maven.docker.model.Network)2 Test (org.junit.Test)2 FabricService (io.fabric8.api.FabricService)1 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)1 Pod (io.fabric8.kubernetes.api.model.Pod)1 PodList (io.fabric8.kubernetes.api.model.PodList)1 Service (io.fabric8.kubernetes.api.model.Service)1 ServiceList (io.fabric8.kubernetes.api.model.ServiceList)1 NetworkConfig (io.fabric8.maven.docker.config.NetworkConfig)1 Timestamp (io.fabric8.maven.docker.util.Timestamp)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 ObjectName (javax.management.ObjectName)1