Java Code Examples for org.apache.brooklyn.core.entity.Entities#dumpInfo()
The following examples show how to use
org.apache.brooklyn.core.entity.Entities#dumpInfo() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KafkaLiveTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
/** * Test that can install, start and use a Kafka cluster with two brokers. */ @Override protected void doTest(Location loc) throws Exception { final KafkaCluster cluster = app.createAndManageChild(EntitySpec.create(KafkaCluster.class) .configure("startTimeout", 300) // 5 minutes .configure("initialSize", 2)); app.start(ImmutableList.of(loc)); Asserts.succeedsEventually(MutableMap.of("timeout", 300000l), new Callable<Void>() { @Override public Void call() { assertTrue(cluster.getAttribute(Startable.SERVICE_UP)); assertTrue(cluster.getZooKeeper().getAttribute(Startable.SERVICE_UP)); assertEquals(cluster.getCurrentSize().intValue(), 2); return null; } }); Entities.dumpInfo(cluster); KafkaSupport support = new KafkaSupport(cluster); support.sendMessage("brooklyn", "TEST_MESSAGE"); String message = support.getMessage("brooklyn"); assertEquals(message, "TEST_MESSAGE"); }
Example 2
Source File: KubernetesLocationYamlLiveTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
/** * Assumes that the {@link DockerContainer} entities have display names of "mysql" and "wordpress", * and that they use ports 3306 and 80 respectively. */ protected void runWordpress(String yaml, String randomId) throws Exception { Entity app = createStartWaitAndLogApplication(yaml); Entities.dumpInfo(app); Iterable<DockerContainer> containers = Entities.descendantsAndSelf(app, DockerContainer.class); DockerContainer mysql = Iterables.find(containers, EntityPredicates.displayNameEqualTo("mysql")); DockerContainer wordpress = Iterables.find(containers, EntityPredicates.displayNameEqualTo("wordpress")); String mysqlPublicPort = assertAttributeEventuallyNonNull(mysql, Sensors.newStringSensor("docker.port.3306.mapped.public")); assertReachableEventually(HostAndPort.fromString(mysqlPublicPort)); assertAttributeEquals(mysql, KubernetesPod.KUBERNETES_NAMESPACE, "brooklyn"); assertAttributeEquals(mysql, KubernetesPod.KUBERNETES_SERVICE, "wordpress-mysql-" + randomId); String wordpressPublicPort = assertAttributeEventuallyNonNull(wordpress, Sensors.newStringSensor("docker.port.80.mapped.public")); assertReachableEventually(HostAndPort.fromString(wordpressPublicPort)); assertAttributeEquals(wordpress, KubernetesPod.KUBERNETES_NAMESPACE, "brooklyn"); assertAttributeEquals(wordpress, KubernetesPod.KUBERNETES_SERVICE, "wordpress-" + randomId); // TODO more assertions (e.g. wordpress can successfully reach the database) }
Example 3
Source File: KarafContainerTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Test(groups = {"Integration", "WIP"}) public void canStartupAndShutdown() throws Exception { karaf = app.createAndManageChild(EntitySpec.create(KarafContainer.class) .configure("name", Identifiers.makeRandomId(8)) .configure("displayName", "Karaf Test")); app.start(ImmutableList.of(localhost)); EntityAsserts.assertAttributeEqualsEventually(karaf, Attributes.SERVICE_UP, true); Entities.dumpInfo(karaf); final int pid = karaf.getAttribute(KarafContainer.KARAF_PID); Entities.submit(app, SshEffectorTasks.requirePidRunning(pid).machine(localhost.obtain())).get(); karaf.stop(); EntityAsserts.assertAttributeEqualsEventually(karaf, Attributes.SERVICE_UP, false); Asserts.succeedsEventually(new Runnable() { @Override public void run() { try { Assert.assertFalse(Entities.submit(app, SshEffectorTasks.isPidRunning(pid).machine(localhost.obtain())).get()); } catch (NoMachinesAvailableException e) { throw Exceptions.propagate(e); } }}); }
Example 4
Source File: EntityLocationUtilsTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testCount() { @SuppressWarnings("unused") SoftwareProcess r1 = app.createAndManageChild(EntitySpec.create(SoftwareProcess.class, RestMockSimpleEntity.class)); SoftwareProcess r2 = app.createAndManageChild(EntitySpec.create(SoftwareProcess.class, RestMockSimpleEntity.class)); Entities.start(app, Arrays.<Location>asList(loc)); Entities.dumpInfo(app); log.info("r2loc: "+r2.getLocations()); log.info("props: "+((LocationInternal)r2.getLocations().iterator().next()).config().getInternalConfigMap().getAllConfigInheritedRawValuesIgnoringErrors()); Map<Location, Integer> counts = new EntityLocationUtils(mgmt).countLeafEntitiesByLocatedLocations(); log.info("count: "+counts); assertEquals(ImmutableList.copyOf(counts.values()), ImmutableList.of(2), "counts="+counts); }
Example 5
Source File: MongoDBShardedDeploymentEc2LiveTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
@Override protected void doTest(Location loc) throws Exception { final MongoDBShardedDeployment deployment = app.createAndManageChild(EntitySpec.create(MongoDBShardedDeployment.class) .configure(MongoDBShardedDeployment.INITIAL_ROUTER_CLUSTER_SIZE, ROUTER_CLUSTER_SIZE) .configure(MongoDBShardedDeployment.SHARD_REPLICASET_SIZE, REPLICASET_SIZE) .configure(MongoDBShardedDeployment.INITIAL_SHARD_CLUSTER_SIZE, SHARD_CLUSTER_SIZE) .configure(MongoDBShardedDeployment.MONGODB_REPLICA_SET_SPEC, EntitySpec.create(MongoDBReplicaSet.class) .configure(MongoDBServer.MONGODB_CONF_TEMPLATE_URL, "classpath:///test-mongodb.conf") .configure(MongoDBReplicaSet.MEMBER_SPEC, EntitySpec.create(MongoDBServer.class))) .configure(MongoDBShardedDeployment.MONGODB_ROUTER_SPEC, EntitySpec.create(MongoDBRouter.class) .configure(MongoDBConfigServer.MONGODB_CONF_TEMPLATE_URL, "classpath:///test-mongodb-router.conf")) .configure(MongoDBShardedDeployment.MONGODB_CONFIG_SERVER_SPEC, EntitySpec.create(MongoDBConfigServer.class) .configure(MongoDBConfigServer.MONGODB_CONF_TEMPLATE_URL, "classpath:///test-mongodb-configserver.conf"))); app.start(ImmutableList.of(loc)); Entities.dumpInfo(app); Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT), new Runnable() { @Override public void run() { Assert.assertEquals(deployment.getRouterCluster().getCurrentSize(), ROUTER_CLUSTER_SIZE); Assert.assertEquals(deployment.getShardCluster().getCurrentSize(), SHARD_CLUSTER_SIZE); Assert.assertEquals(deployment.getConfigCluster().getCurrentSize(), MongoDBShardedDeployment.CONFIG_CLUSTER_SIZE.getDefaultValue()); for (Entity entity : deployment.getShardCluster().getMembers()) { Assert.assertEquals(((MongoDBReplicaSet) entity).getCurrentSize(), REPLICASET_SIZE); } } }); }
Example 6
Source File: KafkaIntegrationTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
/** * Test that we can start a cluster with zookeeper and one broker. * * Connects to the zookeeper controller and tests sending and receiving messages on a topic. */ @Test(groups = "Integration") public void testTwoBrokerCluster() throws InterruptedException { final KafkaCluster cluster = app.createAndManageChild(EntitySpec.create(KafkaCluster.class) .configure(KafkaCluster.INITIAL_SIZE, 2)); cluster.start(ImmutableList.of(testLocation)); Asserts.succeedsEventually(MutableMap.of("timeout", Duration.TWO_MINUTES), new Callable<Void>() { @Override public Void call() { assertTrue(cluster.getAttribute(Startable.SERVICE_UP)); assertTrue(cluster.getZooKeeper().getAttribute(Startable.SERVICE_UP)); assertEquals(cluster.getCurrentSize().intValue(), 2); return null; } }); Entities.dumpInfo(cluster); final KafkaSupport support = new KafkaSupport(cluster); support.sendMessage("brooklyn", "TEST_MESSAGE"); Asserts.succeedsEventually(MutableMap.of("timeout", Duration.FIVE_SECONDS), new Runnable() { @Override public void run() { String message = support.getMessage("brooklyn"); assertEquals(message, "TEST_MESSAGE"); } }); }
Example 7
Source File: KubernetesLocationYamlLiveTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected <T extends Entity> void checkNginxResource(Entity app, Class<T> type) { T entity = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, type)); Entities.dumpInfo(app); assertEntityHealthy(entity); assertAttributeEqualsEventually(entity, KubernetesResource.RESOURCE_NAME, "nginx-replication-controller"); assertAttributeEqualsEventually(entity, KubernetesResource.RESOURCE_TYPE, "ReplicationController"); assertAttributeEqualsEventually(entity, KubernetesResource.KUBERNETES_NAMESPACE, "default"); assertAttributeEventually(entity, SoftwareProcess.ADDRESS, and(notNull(), not(equalTo("0.0.0.0")))); assertAttributeEventually(entity, SoftwareProcess.SUBNET_ADDRESS, and(notNull(), not(equalTo("0.0.0.0")))); }
Example 8
Source File: BindDnsServerIntegrationTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
@Test(groups = "Integration") public void testMapsSeveralEntitiesOnOneMachine() { origApp.start(ImmutableList.of(origApp.newLocalhostProvisioningLocation())); EntityAsserts.assertAttributeEqualsEventually(dns, Attributes.SERVICE_UP, true); logDnsMappings(); // One host with one A, two CNAME and one PTR record assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet().size(), 1); assertMapSizes(3, 1, 2, 1); String key = Iterables.getOnlyElement(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).keySet()); assertEquals(dns.getAttribute(BindDnsServer.ADDRESS_MAPPINGS).get(key).size(), 3); Entities.dumpInfo(dns); }
Example 9
Source File: WebClusterDatabaseExample.java From brooklyn-library with Apache License 2.0 | 5 votes |
public static void main(String[] argv) { List<String> args = Lists.newArrayList(argv); String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); BrooklynLauncher launcher = BrooklynLauncher.newInstance() .application(EntitySpec.create(StartableApplication.class, WebClusterDatabaseExample.class).displayName("Brooklyn WebApp Cluster with Database example")) .restServerPort(port) .location(location) .start(); Entities.dumpInfo(launcher.getApplications()); }
Example 10
Source File: WebClusterApp.java From brooklyn-library with Apache License 2.0 | 5 votes |
public static void main(String[] argv) { List<String> args = Lists.newArrayList(argv); String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); BrooklynLauncher launcher = BrooklynLauncher.newInstance() .application(EntitySpec.create(StartableApplication.class, WebClusterApp.class).displayName("Brooklyn WebApp Cluster example")) .restServerPort(port) .location(location) .start(); Entities.dumpInfo(launcher.getApplications()); }
Example 11
Source File: CassandraDatacenterLiveTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
/** * Test a Cassandra Datacenter: * <ol> * <li>Create two node datacenter * <li>Confirm allows access via the Astyanax API through both nodes. * <li>Confirm can size * </ol> */ protected void runCluster(EntitySpec<CassandraDatacenter> datacenterSpec, boolean usesVnodes) throws Exception { cluster = app.createAndManageChild(datacenterSpec); assertEquals(cluster.getCurrentSize().intValue(), 0); app.start(ImmutableList.of(testLocation)); // Check cluster is up and healthy EntityAsserts.assertAttributeEqualsEventually(cluster, CassandraDatacenter.GROUP_SIZE, 2); Entities.dumpInfo(app); List<CassandraNode> members = castToCassandraNodes(cluster.getMembers()); assertNodesConsistent(members); if (usesVnodes) { assertVnodeTokensConsistent(members); } else { assertSingleTokenConsistent(members); } // Can connect via Astyanax checkConnectionRepeatedly(2, 5, members); // Resize cluster.resize(3); assertEquals(cluster.getMembers().size(), 3, "members="+cluster.getMembers()); if (usesVnodes) { assertVnodeTokensConsistent(castToCassandraNodes(cluster.getMembers())); } else { assertSingleTokenConsistent(castToCassandraNodes(cluster.getMembers())); } checkConnectionRepeatedly(2, 5, cluster.getMembers()); }
Example 12
Source File: CassandraNodeIntegrationTest.java From brooklyn-library with Apache License 2.0 | 5 votes |
/** * Test that a node starts and sets SERVICE_UP correctly. */ @Test(groups = "Integration") public void canStartupAndShutdown() { cassandra = app.createAndManageChild(EntitySpec.create(CassandraNode.class) .configure("jmxPort", "11099+") .configure("rmiRegistryPort", "19001+")); app.start(ImmutableList.of(testLocation)); EntityAsserts.assertAttributeEqualsEventually(cassandra, Startable.SERVICE_UP, true); Entities.dumpInfo(app); cassandra.stop(); EntityAsserts.assertAttributeEqualsEventually(cassandra, Startable.SERVICE_UP, false); }
Example 13
Source File: BrooklynRestResourceTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected void waitForApplicationToBeRunning(final URI applicationRef, Duration timeout) { if (applicationRef==null) throw new NullPointerException("No application URI available (consider using BrooklynRestResourceTest.clientDeploy)"); boolean started = Repeater.create("Wait for application startup") .until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { Status status = getApplicationStatus(applicationRef); if (status == Status.ERROR) { Assert.fail("Application failed with ERROR"); } return status == Status.RUNNING; } }) .backoffTo(Duration.ONE_SECOND) .limitTimeTo(timeout) .run(); if (!started) { log.warn("Did not start application "+applicationRef+" ("+getApplicationStatus(applicationRef)+"):"); Collection<Application> apps = getManagementContext().getApplications(); for (Application app: apps) Entities.dumpInfo(app); } assertTrue(started); }
Example 14
Source File: SingleWebServerExample.java From brooklyn-library with Apache License 2.0 | 5 votes |
public static void main(String[] argv) throws Exception { List<String> args = Lists.newArrayList(argv); String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); String location = CommandLineUtil.getCommandLineOption(args, "--location", "localhost"); BrooklynLauncher launcher = BrooklynLauncher.newInstance() .application(EntitySpec.create(StartableApplication.class, SingleWebServerExample.class).displayName("Brooklyn WebApp example")) .restServerPort(port) .location(location) .start(); Entities.dumpInfo(launcher.getApplications()); }
Example 15
Source File: WebClusterDatabaseExampleApp.java From brooklyn-library with Apache License 2.0 | 5 votes |
public static void main(String[] argv) { List<String> args = Lists.newArrayList(argv); String port = CommandLineUtil.getCommandLineOption(args, "--port", "8081+"); String location = CommandLineUtil.getCommandLineOption(args, "--location", DEFAULT_LOCATION); BrooklynLauncher launcher = BrooklynLauncher.newInstance() .application(EntitySpec.create(StartableApplication.class, WebClusterDatabaseExampleApp.class) .displayName("Brooklyn WebApp Cluster with Database example")) .restServerPort(port) .location(location) .start(); Entities.dumpInfo(launcher.getApplications()); }
Example 16
Source File: KubernetesLocationYamlLiveTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
protected <T extends Entity> void checkPod(Entity app, Class<T> type) { T container = Iterables.getOnlyElement(Entities.descendantsAndSelf(app, type)); Entities.dumpInfo(app); String publicMapped = assertAttributeEventuallyNonNull(container, Sensors.newStringSensor("docker.port.8080.mapped.public")); HostAndPort publicPort = HostAndPort.fromString(publicMapped); assertReachableEventually(publicPort); assertHttpStatusCodeEventuallyEquals("http://" + publicPort.getHostText() + ":" + publicPort.getPort(), 200); }
Example 17
Source File: RedisClusterViaRestIntegrationTest.java From brooklyn-library with Apache License 2.0 | 4 votes |
/** REST seems to show up a different behaviour in context entity used when adding children entities, * causing different config to be set, so we test that, using Redis as a comparatively simple example. */ @Test(groups = "Integration") public void testDeployRedisCluster() throws InterruptedException, ExecutionException, TimeoutException { final URI webConsoleUri = URI.create(getBaseUriRest()); // Test setup final EntitySpec<BrooklynNode> spec = EntitySpec.create(BrooklynNode.class); final ManagementContext mgmt = getManagementContextFromJettyServerAttributes(server); final BrooklynNode node = mgmt.getEntityManager().createEntity(spec); node.sensors().set(BrooklynNode.WEB_CONSOLE_URI, webConsoleUri); // Deploy it. final String blueprint = "location: localhost\n" + "services:\n" + "- type: org.apache.brooklyn.entity.nosql.redis.RedisCluster"; HttpToolResponse response = node.http().post( "/applications", ImmutableMap.of("Content-Type", "text/yaml"), blueprint.getBytes()); HttpAsserts.assertHealthyStatusCode(response.getResponseCode()); // Assert application is eventually running and not on fire. final Entity entity = mgmt.getApplications().iterator().next().getChildren().iterator().next(); assertTrue(entity instanceof RedisCluster, "expected " + RedisCluster.class.getName() + ", found: " + entity); RedisCluster cluster = RedisCluster.class.cast(entity); Entities.dumpInfo(cluster); assertDownloadUrl(cluster.getMaster()); for (Entity slave : cluster.getSlaves().getMembers()) { assertDownloadUrl(slave); } @SuppressWarnings("unchecked") String taskId = Strings.toString( ((Map<String,Object>) Yamls.parseAll(response.getContentAsString()).iterator().next()).get("id") ); Task<?> task = mgmt.getExecutionManager().getTask(taskId); Assert.assertNotNull(task); task.get(Duration.minutes(20)); Entities.dumpInfo(cluster); EntityAsserts.assertAttributeEquals(entity, SoftwareProcess.SERVICE_UP, true); }
Example 18
Source File: CassandraNodeIntegrationTest.java From brooklyn-library with Apache License 2.0 | 4 votes |
/** * Cassandra v2 needs Java >= 1.7. If you have java 6 as the defult locally, then you can use * something like {@code .configure("shell.env", MutableMap.of("JAVA_HOME", "/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home"))} */ @Test(groups = "Integration") public void testCassandraVersion2() throws Exception { // TODO In v2.0.10, the bin/cassandra script changed to add an additional check for JMX connectivity. // This causes cassandera script to hang for us (presumably due to the CLASSPATH/JVM_OPTS we're passing // in, regarding JMX agent). // See: // - https://issues.apache.org/jira/browse/CASSANDRA-7254 // - https://github.com/apache/cassandra/blame/trunk/bin/cassandra#L211-216 String version = "2.0.9"; String majorMinorVersion = "2.0"; cassandra = app.createAndManageChild(EntitySpec.create(CassandraNode.class) .configure(CassandraNode.SUGGESTED_VERSION, version) .configure(CassandraNode.NUM_TOKENS_PER_NODE, 256) .configure("jmxPort", "11099+") .configure("rmiRegistryPort", "19001+")); app.start(ImmutableList.of(testLocation)); EntityAsserts.assertAttributeEqualsEventually(cassandra, Startable.SERVICE_UP, true); Entities.dumpInfo(app); AstyanaxSample astyanax = new AstyanaxSample(cassandra); astyanax.astyanaxTest(); assertEquals(cassandra.getMajorMinorVersion(), majorMinorVersion); Asserts.succeedsEventually(new Runnable() { @Override public void run() { assertNotNull(cassandra.getAttribute(CassandraNode.TOKENS)); assertEquals(cassandra.getAttribute(CassandraNode.TOKENS).size(), 256, "tokens="+cassandra.getAttribute(CassandraNode.TOKENS)); assertEquals(cassandra.getAttribute(CassandraNode.PEERS), (Integer)256); assertEquals(cassandra.getAttribute(CassandraNode.LIVE_NODE_COUNT), (Integer)1); assertTrue(cassandra.getAttribute(CassandraNode.SERVICE_UP_JMX)); assertNotNull(cassandra.getAttribute(CassandraNode.THRIFT_PORT_LATENCY)); assertNotNull(cassandra.getAttribute(CassandraNode.READ_PENDING)); assertNotNull(cassandra.getAttribute(CassandraNode.READ_ACTIVE)); EntityAsserts.assertAttribute(cassandra, CassandraNode.READ_COMPLETED, MathPredicates.greaterThanOrEqual(1)); assertNotNull(cassandra.getAttribute(CassandraNode.WRITE_PENDING)); assertNotNull(cassandra.getAttribute(CassandraNode.WRITE_ACTIVE)); EntityAsserts.assertAttribute(cassandra, CassandraNode.WRITE_COMPLETED, MathPredicates.greaterThanOrEqual(1)); assertNotNull(cassandra.getAttribute(CassandraNode.READS_PER_SECOND_LAST)); assertNotNull(cassandra.getAttribute(CassandraNode.WRITES_PER_SECOND_LAST)); assertNotNull(cassandra.getAttribute(CassandraNode.THRIFT_PORT_LATENCY_IN_WINDOW)); assertNotNull(cassandra.getAttribute(CassandraNode.READS_PER_SECOND_IN_WINDOW)); assertNotNull(cassandra.getAttribute(CassandraNode.WRITES_PER_SECOND_IN_WINDOW)); // an example MXBean EntityAsserts.assertAttribute(cassandra, CassandraNode.MAX_HEAP_MEMORY, MathPredicates.greaterThanOrEqual(1)); }}); cassandra.stop(); EntityAsserts.assertAttributeEqualsEventually(cassandra, Startable.SERVICE_UP, false); }
Example 19
Source File: CassandraDatacenterIntegrationTest.java From brooklyn-library with Apache License 2.0 | 4 votes |
/** * Test that a single node cluster starts up and allows access via the Astyanax API. * Only one node because Cassandra can only run one node per VM! */ protected void runStartAndShutdownClusterSizeOne(EntitySpec<CassandraDatacenter> datacenterSpec, final boolean assertToken) throws Exception { cluster = app.createAndManageChild(datacenterSpec); assertEquals(cluster.getCurrentSize().intValue(), 0); app.start(ImmutableList.of(testLocation)); Entities.dumpInfo(app); final CassandraNode node = (CassandraNode) Iterables.get(cluster.getMembers(), 0); String nodeAddr = checkNotNull(node.getAttribute(CassandraNode.HOSTNAME), "hostname") + ":" + checkNotNull(node.getAttribute(CassandraNode.THRIFT_PORT), "thriftPort"); EntityAsserts.assertAttributeEqualsEventually(cluster, CassandraDatacenter.GROUP_SIZE, 1); EntityAsserts.assertAttributeEqualsEventually(cluster, CassandraDatacenter.CASSANDRA_CLUSTER_NODES, ImmutableList.of(nodeAddr)); EntityAsserts.assertAttributeEqualsEventually(node, Startable.SERVICE_UP, true); if (assertToken) { PosNeg63TokenGenerator tg = new PosNeg63TokenGenerator(); tg.growingCluster(1); EntityAsserts.assertAttributeEqualsEventually(node, CassandraNode.TOKENS, ImmutableSet.of(tg.newToken().add(BigInteger.valueOf(42)))); } // may take some time to be consistent (with new thrift_latency checks on the node, // contactability should not be an issue, but consistency still might be) Asserts.succeedsEventually(MutableMap.of("timeout", 120*1000), new Runnable() { @Override public void run() { boolean open = CassandraDatacenterLiveTest.isSocketOpen(node); Boolean consistant = open ? CassandraDatacenterLiveTest.areVersionsConsistent(node) : null; Integer numPeers = node.getAttribute(CassandraNode.PEERS); Integer liveNodeCount = node.getAttribute(CassandraNode.LIVE_NODE_COUNT); String msg = "consistency: " + (!open ? "unreachable" : consistant==null ? "error" : consistant)+"; " + "peer group sizes: "+numPeers + "; live node count: " + liveNodeCount; assertTrue(open, msg); assertEquals(consistant, Boolean.TRUE, msg); if (assertToken) { assertEquals(numPeers, (Integer)1, msg); } else { assertTrue(numPeers != null && numPeers >= 1, msg); } assertEquals(liveNodeCount, (Integer)1, msg); }}); CassandraDatacenterLiveTest.checkConnectionRepeatedly(2, 5, ImmutableList.of(node)); }
Example 20
Source File: BrooklynNodeRestTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Test(groups = "WIP") public void testBrooklynNodeRestDeployAndMirror() { final SimpleYamlLauncher l = new SimpleYamlLauncherForTests(); try { TestApplication app = TestApplication.Factory.newManagedInstanceForTests(l.getManagementContext()); BrooklynNode bn = app.createAndManageChild(EntitySpec.create(BrooklynNode.class, SameBrooklynNodeImpl.class)); bn.start(MutableSet.<Location>of()); URI uri = bn.getAttribute(BrooklynNode.WEB_CONSOLE_URI); Assert.assertNotNull(uri); EntityAsserts.assertAttributeEqualsEventually(bn, Attributes.SERVICE_UP, true); log.info("Created BrooklynNode: "+bn); // deploy Task<?> t = bn.invoke(BrooklynNode.DEPLOY_BLUEPRINT, ConfigBag.newInstance() .configure(BrooklynNode.DeployBlueprintEffector.BLUEPRINT_TYPE, TestApplication.class.getName()) .configure(BrooklynNode.DeployBlueprintEffector.BLUEPRINT_CONFIG, MutableMap.<String,Object>of("x", 1, "y", "Y")) .getAllConfig()); log.info("Deployment result: "+t.getUnchecked()); MutableSet<Application> apps = MutableSet.copyOf( l.getManagementContext().getApplications() ); Assert.assertEquals(apps.size(), 2); apps.remove(app); Application newApp = Iterables.getOnlyElement(apps); Entities.dumpInfo(newApp); Assert.assertEquals(newApp.getConfig(new BasicConfigKey<Integer>(Integer.class, "x")), (Integer)1); // check mirror String newAppId = newApp.getId(); BrooklynEntityMirror mirror = app.createAndManageChild(EntitySpec.create(BrooklynEntityMirror.class) .configure(BrooklynEntityMirror.MIRRORED_ENTITY_URL, Urls.mergePaths(uri.toString(), "/v1/applications/"+newAppId+"/entities/"+newAppId)) .configure(BrooklynEntityMirror.MIRRORED_ENTITY_ID, newAppId) .configure(BrooklynEntityMirror.POLL_PERIOD, Duration.millis(10))); Entities.dumpInfo(mirror); EntityAsserts.assertAttributeEqualsEventually(mirror, Attributes.SERVICE_UP, true); ((EntityInternal)newApp).sensors().set(TestEntity.NAME, "foo"); EntityAsserts.assertAttributeEqualsEventually(mirror, TestEntity.NAME, "foo"); log.info("Mirror successfully validated"); // also try deploying by invoking deploy through json // (catch issues when effector params are map) HttpClient client = HttpTool.httpClientBuilder().build(); HttpToolResponse result = HttpTool.httpPost(client, URI.create(Urls.mergePaths(uri.toString(), "/v1/applications/"+app.getId()+"/entities/"+bn.getId() +"/effectors/deployBlueprint")), MutableMap.of(com.google.common.net.HttpHeaders.CONTENT_TYPE, "application/json"), Jsonya.newInstance() .put("blueprintType", TestApplication.class.getName()) .put("blueprintConfig", MutableMap.of(TestEntity.CONF_NAME.getName(), "foo")) .toString().getBytes()); log.info("Deploy effector invoked, result: "+result); HttpTestUtils.assertHealthyStatusCode( result.getResponseCode() ); Repeater.create().every(Duration.millis(10)).until(new Callable<Boolean>() { @Override public Boolean call() throws Exception { return l.getManagementContext().getApplications().size() == 3; } }).limitTimeTo(Duration.TEN_SECONDS).runRequiringTrue(); apps = MutableSet.copyOf( l.getManagementContext().getApplications() ); apps.removeAll( MutableSet.of(app, newApp) ); Application newApp2 = Iterables.getOnlyElement(apps); Entities.dumpInfo(newApp2); EntityAsserts.assertAttributeEqualsEventually(newApp2, Attributes.SERVICE_UP, true); Assert.assertEquals(newApp2.getConfig(TestEntity.CONF_NAME), "foo"); } finally { l.destroyAll(); } log.info("DONE"); }