/** * Consider using {@link #readFullyStringAndClose(InputStream)} instead. */ public static String readFullyString(InputStream is) { return readFully(reader(is)); }
@Test public void testSimpleYamlArtifactParse() throws IOException { BasicCampPlatform platform = MockWebPlatform.populate(new BasicCampPlatform()); Reader input = Streams.reader(getClass().getResourceAsStream("pdp-single-artifact.yaml")); DeploymentPlan plan = platform.pdp().parseDeploymentPlan(input); log.info("DP is:\n"+plan.toString()); Assert.assertEquals(plan.getName(), "sample"); Assert.assertEquals(plan.getArtifacts().size(), 1); Assert.assertEquals(plan.getServices().size(), 0); Artifact artifact1 = plan.getArtifacts().iterator().next(); Assert.assertEquals(artifact1.getName(), "sample WAR"); }
protected void customizeConfiguration() throws ExecutionException, InterruptedException, URISyntaxException { log.info("Copying creation script " + getEntity().toString()); // TODO check these semantics are what we really want? String configScriptUrl = entity.getConfig(RubyRepNode.CONFIGURATION_SCRIPT_URL); Reader configContents; if (configScriptUrl != null) { // If set accept as-is configContents = Streams.reader(resource.getResourceFromUrl(configScriptUrl)); } else { String configScriptContents = processTemplate(entity.getConfig(RubyRepNode.TEMPLATE_CONFIGURATION_URL)); configContents = Streams.newReaderWithContents(configScriptContents); } getMachine().copyTo(configContents, getRunDir() + "/rubyrep.conf"); }
@Test public void testSimpleYamlServiceParse() throws IOException { BasicCampPlatform platform = MockWebPlatform.populate(new BasicCampPlatform()); Reader input = Streams.reader(getClass().getResourceAsStream("pdp-single-service.yaml")); DeploymentPlan plan = platform.pdp().parseDeploymentPlan(input); log.info("DP is:\n"+plan.toString()); Assert.assertEquals(plan.getName(), "sample"); Assert.assertEquals(plan.getArtifacts().size(), 0); Assert.assertEquals(plan.getServices().size(), 1); Service service1 = plan.getServices().iterator().next(); Assert.assertEquals(service1.getName(), "Hello WAR"); }
@SuppressWarnings("unchecked") public void testToyInterpreter() { @SuppressWarnings("rawtypes") Map y1 = Yamls.getAs( Yamls.parseAll( Streams.reader(getClass().getResourceAsStream("yaml-sample-toy-interpreter.yaml"))), Map.class ); log.info("pre-interpreter have: "+y1); BasicCampPlatform p = new BasicCampPlatform(); p.pdp().addInterpreter(new ToyInterpreter()); Map<String, Object> y2 = p.pdp().applyInterpreters(y1); log.info("interpreter gives: "+y2); Map<String, Object> y3 = Yamls.getAs( Yamls.parseAll( Streams.reader(getClass().getResourceAsStream("yaml-sample-toy-interpreter-result.yaml"))), Map.class ); Assert.assertEquals(y2, y3); }
/** * @return A task that gathers machine details by SSHing to the machine and running * a Bash script to gather data. */ public static Task<BasicMachineDetails> taskForSshMachineLocation(SshMachineLocation location) { BufferedReader reader = new BufferedReader(Streams.reader( new ResourceUtils(BasicMachineDetails.class).getResourceFromUrl( "classpath://org/apache/brooklyn/location/basic/os-details.sh"))); List<String> script; try { script = CharStreams.readLines(reader); } catch (IOException e) { LOG.error("Error reading os-details script", e); throw Throwables.propagate(e); } finally { try { reader.close(); } catch (IOException e) { // Not rethrowing e because it might obscure an exception caught by the first catch LOG.error("Error closing os-details script reader", e); } } Task<BasicMachineDetails> task = new PlainSshExecTaskFactory<String>(location, script) .summary("Getting machine details for: " + location) .requiringZeroAndReturningStdout() .returning(taskToMachineDetailsFunction(location)) .newTask() .asTask(); return task; }
public Object parseDslExpression(String input) { String s1 = Yamls.getAs( Yamls.parseAll( Streams.reader(Streams.newInputStreamWithContents(input)) ), String.class ); BasicCampPlatform p = new BasicCampPlatform(); p.pdp().addInterpreter(new BrooklynDslInterpreter()); Object out = p.pdp().applyInterpreters(MutableMap.of("key", s1)).get("key"); log.debug("parsed "+input+" as "+out+" ("+(out==null ? "null" : out.getClass())+")"); return out; }
@Test public void testReloadBrooklynPropertiesDeploy() { brooklynMgmt.reloadBrooklynProperties(); CampPlatform reloadedPlatform = brooklynMgmt.getScratchpad().get(BrooklynCampConstants.CAMP_PLATFORM); Assert.assertNotNull(reloadedPlatform); Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("test-entity-basic-template.yaml")); AssemblyTemplate template = reloadedPlatform.pdp().registerDeploymentPlan(input); try { Assembly assembly = template.getInstantiator().newInstance().instantiate(template, reloadedPlatform); LOG.info("Test - created " + assembly); final Entity app = brooklynMgmt.getEntityManager().getEntity(assembly.getId()); LOG.info("App - " + app); Assert.assertEquals(app.getDisplayName(), "test-entity-basic-template"); EntityAsserts.assertAttributeEqualsEventually(app, Startable.SERVICE_UP, true); } catch (Exception e) { LOG.warn("Unable to instantiate " + template + " (rethrowing): " + e); throw Exceptions.propagate(e); } } }
@Test(groups={"Integration", "WIP", "Broken"}) public void testJavaWebWithMemberSpecRebind() throws Exception { Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("test-java-web-app-spec-and-db-with-function.yaml")); AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); final Application app = (Application) mgmt().getEntityManager().getEntity(assembly.getId()); Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app); for (Task<?> t: tasks) t.blockUntilEnded(); Entities.dumpInfo(app); Application app2 = rebind(app); Assert.assertEquals(app2.getChildren().size(), 2); }
/** as {@link JavaWebAppsIntegrationTest#testWithDbDeploy()} but with rebind */ @Test(groups={"Integration", "WIP", "Broken"}) public void testJavaWebAppDeployAndRebind() throws Exception { Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("java-web-app-and-db-with-function.yaml")); AssemblyTemplate at = platform.pdp().registerDeploymentPlan(input); Assembly assembly = at.getInstantiator().newInstance().instantiate(at, platform); final Application app = (Application) mgmt().getEntityManager().getEntity(assembly.getId()); Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt().getExecutionManager(), app); for (Task<?> t: tasks) t.blockUntilEnded(); Entities.dumpInfo(app); Application app2 = rebind(app); Assert.assertEquals(app2.getChildren().size(), 2); }
protected void runCatalogTest(String catalogFile, Reader yamlApp, Predicate<? super Application> assertion) throws Exception { Reader catalogInput = Streams.reader(new ResourceUtils(this).getResourceFromUrl(catalogFile)); String catalogContent = Streams.readFullyAndClose(catalogInput); Iterable<? extends CatalogItem<?, ?>> items = launcher.getManagementContext().getCatalog().addItems(catalogContent); try { final Application app = launcher.launchAppYaml(yamlApp); assertNoFires(app); assertTrue(assertion.apply(app)); Application newApp = rebind(); assertNoFires(newApp); assertTrue(assertion.apply(app)); } finally { for (CatalogItem<?, ?> item : items) { launcher.getManagementContext().getCatalog().deleteCatalogItem(item.getSymbolicName(), item.getVersion()); } } }