/** task to install a file given a url, where the url is resolved remotely first then locally */ public static TaskFactory<?> installFromUrl(final SshMachineLocation location, final String url, final String destPath) { return installFromUrl(ResourceUtils.create(SshTasks.class), ImmutableMap.<String,Object>of(), location, url, destPath); } /** task to install a file given a url, where the url is resolved remotely first then locally */
public static String generateScriptString(Date generationTime, Collection<HostGeoInfo> hosts) { String template = ResourceUtils.create(GeoscalingScriptGenerator.class).getResourceAsString(PHP_SCRIPT_TEMPLATE_RESOURCE); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss 'UTC'"); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); String datestamp = sdf.format(generationTime); String declarations = getHostsDeclaration(hosts); return template .replaceAll(DATESTAMP_MARKER, datestamp) .replace(HOSTS_DECLARATIONS_MARKER, declarations); }
/** Fails-fast if value of the given key is null or unresolveable. */ public static String getRequiredUrlConfig(Entity entity, ConfigKey<String> urlKey) { String url = entity.getConfig(urlKey); Preconditions.checkNotNull(url, "Key %s on %s should not be null", urlKey, entity); if (!ResourceUtils.create(entity).doesUrlExist(url)) { throw new IllegalStateException(String.format("Key %s on %s contains unavailable URL %s", urlKey, entity, url)); } return url; }
private static void addPropertiesFromUrl(BrooklynPropertiesImpl p, String url, boolean warnIfNotFound) { if (url==null) return; try { p.addFrom(ResourceUtils.create(BrooklynPropertiesImpl.class).getResourceFromUrl(url)); } catch (Exception e) { if (warnIfNotFound) LOG.warn("Could not load {}; continuing", url); if (LOG.isTraceEnabled()) LOG.trace("Could not load "+url+"; continuing", e); } }
protected Builder xsltTransformerRecursiveCopyWithExtraRules(String ...rules) { String xsltTemplate = ResourceUtils.create(this).getResourceAsString("classpath://org/apache/brooklyn/core/mgmt/rebind/transformer/recursiveCopyWithExtraRules.xslt"); String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, ImmutableMap.of("extra_rules", Strings.join(rules, "\n"))); return xsltTransformer(xslt); }
private String prepareServiceConfigurationXmlContent(String config, Map<String, String> configMap) { return TemplateProcessor.processTemplateContents( ResourceUtils.create().getResourceAsString(config().get(CustomService.SERVICE_CONFIG_TEMPLATE_URL)), this, ImmutableMap.<String,String>of("configKey", config)); }
protected Builder xsltTransformerFromXsltFreemarkerTemplateUrl(String templateUrl, Map<String,String> vars) { String xsltTemplate = ResourceUtils.create(this).getResourceAsString(templateUrl); String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, vars); return xsltTransformer(xslt); } protected Builder xsltTransformerRecursiveCopyWithExtraRules(String ...rules) {
protected void assertCannotFindMessages(Entity entity) { ResourceUtils ru = ResourceUtils.create(entity); Iterable<URL> files = ru.getResources("org/apache/brooklyn/test/osgi/resources/message.txt"); if (files.iterator().hasNext()) { Entities.dumpInfo(entity); Assert.fail("Expected NOT to find 'messages.txt'"); } }
protected void assertCanFindMessages(Entity entity) { ResourceUtils ru = ResourceUtils.create(entity); Iterable<URL> files = ru.getResources("org/apache/brooklyn/test/osgi/resources/message.txt"); if (!files.iterator().hasNext()) { Entities.dumpInfo(entity); Assert.fail("Expected to find 'messages.txt'"); } }
@Test(groups="Integration") // runs without internet but doesn't assert what it should, and can take a long time, so integration public void testBadExampleWar() { String url = BrooklynMavenArtifacts.localUrl("example", "brooklyn-example-GOODBYE-world-sql-webapp", "war"); Assert.assertFalse(ResourceUtils.create(this).doesUrlExist(url), "should not exist: "+url); }
@Test public void testScriptGeneration() { Date generationTime = new Date(0); String generatedScript = GeoscalingScriptGenerator.generateScriptString(generationTime, HOSTS); assertTrue(generatedScript.contains("1.2.3")); String expectedScript = ResourceUtils.create(this).getResourceAsString("org/apache/brooklyn/entity/dns/geoscaling/expectedScript.php"); assertEqualsNormalizedEol(generatedScript, expectedScript); //also make sure leading slash is allowed String expectedScript2 = ResourceUtils.create(this).getResourceAsString("org/apache/brooklyn/entity/dns/geoscaling/expectedScript.php"); assertEqualsNormalizedEol(generatedScript, expectedScript2); }
@Test public void testEncodeDecodeRsaPublicKey() throws Exception { String data = ResourceUtils.create(this).getResourceAsString("classpath://brooklyn/util/crypto/sample_rsa.pem.pub"); PublicKey key = AuthorizedKeysParser.decodePublicKey(data); String data2 = AuthorizedKeysParser.encodePublicKey(key); Assert.assertTrue(data.contains(data2), "Expected to find '"+data2+"' in '"+data+"'"); PublicKey key2 = AuthorizedKeysParser.decodePublicKey(data2); Assert.assertEquals(key2, key); }
@Test public void testEncodeDecodeDsaPublicKey() throws Exception { String data = ResourceUtils.create(this).getResourceAsString("classpath://brooklyn/util/crypto/sample_dsa.pem.pub"); PublicKey key = AuthorizedKeysParser.decodePublicKey(data); String data2 = AuthorizedKeysParser.encodePublicKey(key); Assert.assertTrue(data.contains(data2), "Expected to find '"+data2+"' in '"+data+"'"); PublicKey key2 = AuthorizedKeysParser.decodePublicKey(data2); Assert.assertEquals(key2, key); }
private Object loadApplicationFromClasspathOrParse(String appName) throws Exception { LaunchCommand launchCommand = new Main.LaunchCommand(); ResourceUtils resourceUtils = ResourceUtils.create(this); GroovyClassLoader loader = new GroovyClassLoader(CliTest.class.getClassLoader()); return launchCommand.loadApplicationFromClasspathOrParse(resourceUtils, loader, appName); }
@BeforeMethod(alwaysRun = true) public void setUp() throws Exception { if (BROOKLYN_THIS_CLASSPATH==null) { BROOKLYN_THIS_CLASSPATH = ResourceUtils.create(MAIN_CLASS).getClassLoaderDir(); } app = TestApplication.Factory.newManagedInstanceForTests(); loc = app.newLocalhostProvisioningLocation(MutableMap.of("address", "localhost")); }
@Override public String call(ConfigBag parameters) { return ResourceUtils.create(entity()).getResourceAsString( parameters.get(FILENAME) ); } }
@BeforeMethod(alwaysRun=true) public void setUp() throws Exception { mementoDir = Files.createTempDir(); managementContext = RebindTestUtils.newPersistingManagementContext(mementoDir, classLoader); if (BROOKLYN_THIS_CLASSPATH==null) { BROOKLYN_THIS_CLASSPATH = ResourceUtils.create(MAIN_CLASS).getClassLoaderDir(); } app = TestApplication.Factory.newManagedInstanceForTests(managementContext); loc = app.newLocalhostProvisioningLocation(MutableMap.of("address", "localhost")); }
@Override public void run() { try { byte[] bytes = Streams.readFullyAndClose(ResourceUtils.create(this).getResourceFromUrl(url)); // confirm this follow redirects! Assert.assertTrue(bytes.length > 100*1000, "download of "+url+" is suspect ("+Strings.makeSizeString(bytes.length)+")"); // (could also check it is a zip etc) } catch (Exception e) { throw Exceptions.propagate(e); } }}); }
@Test(groups="Integration") public void testHistoricHosted() { // NB: this should be a version known to be up at sonatype or maven central, NOT necessarily the current version! String snapshot = MavenRetriever.hostedUrl(MavenArtifact.fromCoordinate("org.apache.brooklyn:brooklyn-utils-common:jar:0.7.0-SNAPSHOT")); log.info("Sample snapshot URL is: "+snapshot); checkValidArchive(snapshot); ResourceUtils.create(this).checkUrlExists(snapshot); // NB: this should be a version known to be up at sonatype or maven central, NOT necessarily the current version! String release = MavenRetriever.hostedUrl(MavenArtifact.fromCoordinate("io.brooklyn:brooklyn-utils-common:jar:0.6.0")); log.info("Sample release URL is: "+release); checkValidArchive(release); }
public void testJmxrmiJarExistence() { app = TestApplication.Factory.newManagedInstanceForTests(); JmxSupport support = new JmxSupport(app, null); app.config().set(JmxSupport.JMX_AGENT_MODE, JmxAgentModes.JMX_RMI_CUSTOM_AGENT); Assert.assertEquals(support.getJmxAgentJarMavenArtifact().getArtifactId(), "brooklyn-jmxrmi-agent"); Assert.assertTrue(ResourceUtils.create(this).doesUrlExist(support.getJmxAgentJarUrl()), support.getJmxAgentJarUrl()); }