Java Code Examples for org.apache.brooklyn.util.core.ResourceUtils

The following examples show how to use org.apache.brooklyn.util.core.ResourceUtils. These examples are extracted from open source projects. 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 Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
 * Reads the given file(s) in-order, returning the contents of the first file that can be read.
 * Returns the file contents, or null if none of the files can be read.
 * @param files             list of file paths
private static String getFileContents(Iterable<String> files) {
    Iterator<String> fi = files.iterator();
    while (fi.hasNext()) {
        String file =;
        if (groovyTruth(file)) {
            try {
                // see comment above
                String result = ResourceUtils.create().getResourceAsString(file);
                if (result!=null) return result;
                log.debug("Invalid file "+file+" ; " + (!fi.hasNext() ? "no more files to try" : "trying next file")+" (null)");
            } catch (Exception e) {
                log.debug("Invalid file "+file+" ; " + (!fi.hasNext() ? "no more files to try" : "trying next file"), e);
    return null;
Example 2
protected void postStartCustom() {
    // now run the creation script
    String creationScript;
    String creationScriptUrl = entity().getConfig(PostgreSqlNode.CREATION_SCRIPT_URL);
    if (creationScriptUrl != null) {
        creationScript = ResourceUtils.create(entity()).getResourceAsString(creationScriptUrl);
    } else {
        creationScript = entity().getConfig(PostgreSqlNode.CREATION_SCRIPT_CONTENTS);

    // and finally connect sensors
Example 3
Source Project: brooklyn-library   Source File:    License: Apache License 2.0 6 votes vote down vote up
public synchronized static String installBrooklynChefHostedConfig() {
    if (defaultConfigFile!=null) return defaultConfigFile;
    File tempDir = Files.createTempDir();
    ResourceUtils r = ResourceUtils.create(ChefServerTasksIntegrationTest.class);
    for (String f: new String[] { "knife.rb", "brooklyn-tests.pem", "brooklyn-validator.pem" }) {
        InputStream in = r.getResourceFromUrl("classpath:///org/apache/brooklyn/entity/chef/hosted-chef-brooklyn-credentials/"+f);
        try {
            FileUtil.copyTo(in, new File(tempDir, f));
        } finally {
    File knifeConfig = new File(tempDir, "knife.rb");
    defaultConfigFile = knifeConfig.getPath();
    return defaultConfigFile;
Example 4
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
public VersionSummary getVersion() {
    if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.SERVER_STATUS, null))
        throw WebResourceUtils.forbidden("User '%s' is not authorized to perform this operation", Entitlements.getEntitlementContext().user());
    // TODO
    // * "" is probably the wrong name
    // * we should include brooklyn.version and a build timestamp in this file
    // * the authority for brooklyn should probably be core rather than brooklyn-rest-server
    InputStream input = ResourceUtils.create(this).getResourceFromUrl("classpath://");
    Properties properties = new Properties();
    String gitSha1 = null, gitBranch = null;
    try {
        gitSha1 = properties.getProperty(BUILD_SHA_1_PROPERTY);
        gitBranch = properties.getProperty(BUILD_BRANCH_PROPERTY);
    } catch (IOException e) {
        log.error("Failed to load", e);
    gitSha1 = BrooklynVersion.INSTANCE.getSha1FromOsgiManifest();

    FluentIterable<BrooklynFeatureSummary> features = FluentIterable.from(BrooklynVersion.getFeatures(mgmt()))

    return new VersionSummary(BrooklynVersion.get(), gitSha1, gitBranch, features.toList());
Example 5
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
protected void computeAndSetApp(BrooklynLauncher launcher, ResourceUtils utils, GroovyClassLoader loader)
    throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, InstantiationException {
    if (app != null) {
        // Create the instance of the brooklyn app
        log.debug("Loading the user's application: {}", app);
        if (isYamlApp()) {
            log.debug("Loading application as YAML spec: {}", app);
            String content = utils.getResourceAsString(app);
        } else {
            EntitySpec<? extends Application> appSpec = loadApplicationFromClasspathOrParse(utils, loader, app);
Example 6
@Test(groups={"Live", "WIP"}, enabled=false)
public void testRebindsToJcloudsMachineWithInvalidTemplate() throws Exception {
    ResourceUtils resourceUtils = ResourceUtils.create(this);
            new File(mementoDir, "locations/briByOel"),
            new File(mementoDir, "locations/VNapYjwp"),
    TestApplication newApp = rebind();
    JcloudsLocation loc = (JcloudsLocation) newApp.getManagementContext().getLocationManager().getLocation("briByOel");
    JcloudsSshMachineLocation machine = (JcloudsSshMachineLocation) newApp.getManagementContext().getLocationManager().getLocation("VNapYjwp");
    assertEquals(ImmutableSet.of(loc.getChildren()), ImmutableSet.of(machine));
Example 7
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
public void testHistoricLocationWithoutSemaphoresStops() throws Exception {
    ResourceUtils resourceUtils = ResourceUtils.create(this);
            new File(mementoDir, "locations/afy79330h5"),
            new File(mementoDir, "locations/l27nwbyisk"),

    JcloudsLocation jcloudsLoc = (JcloudsLocation) mgmt().getLocationManager().getLocation("afy79330h5");
    JcloudsSshMachineLocation machine = (JcloudsSshMachineLocation) mgmt().getLocationManager().getLocation("l27nwbyisk");
Example 8
public void testBrooklynManagedBundleInstall() throws Exception {

    TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V1_PATH);

    OsgiBundleInstallationResult br = ((ManagementContextInternal)mgmt()).getOsgiManager().get().install( 
        new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V1_URL) ).get();
    Assert.assertEquals(br.getVersionedName().toString(), BROOKLYN_TEST_MORE_ENTITIES_SYMBOLIC_NAME_FULL+":"+"0.1.0");
    // bundle installed
    Map<String, ManagedBundle> bundles = ((ManagementContextInternal)mgmt()).getOsgiManager().get().getManagedBundles();
    Asserts.assertSize(bundles.keySet(), 1);
    Assert.assertTrue(bundles.keySet().contains( br.getMetadata().getId() ));
    // types installed
    RegisteredType t = mgmt().getTypeRegistry().get(BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
    Assert.assertEquals(t.getContainingBundle(), br.getVersionedName().toString());
    // can deploy
    createAndStartApplication("services: [ { type: "+BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY+" } ]");
Example 9
protected RegisteredType installWrappedMoreEntity() throws Exception {

        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_OSGI_ENTITIES_PATH);
        TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), BROOKLYN_TEST_MORE_ENTITIES_V2_PATH);

            new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_OSGI_ENTITIES_URL) ).checkNoError();
            new ResourceUtils(getClass()).getResourceFromUrl(BROOKLYN_TEST_MORE_ENTITIES_V2_URL) ).get();
            "  id: wrapped-more-entity",
            "  version: 1.0",
            "  item:",
            "    services:",
            "    - type: " + BROOKLYN_TEST_MORE_ENTITIES_MORE_ENTITY);
        RegisteredType ci = Preconditions.checkNotNull( mgmt().getTypeRegistry().get("wrapped-more-entity") );
        return ci;
Example 10
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
static void installJavaScanningMoreEntitiesV2(ManagementContext mgmt, Object context) throws FileNotFoundException {
    // scanning bundle functionality added in 0.12.0, relatively new compared to non-osgi scanning
    TestResourceUnavailableException.throwIfResourceUnavailable(context.getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
    TestResourceUnavailableException.throwIfResourceUnavailable(context.getClass(), OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH);
    CampYamlLiteTest.installWithoutCatalogBom(mgmt, OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
    BundleMaker bm = new BundleMaker(mgmt);
    File f = Os.newTempFile(context.getClass(), "jar");
    Streams.copy(ResourceUtils.create(context).getResourceFromUrl(OsgiTestResources.BROOKLYN_TEST_MORE_ENTITIES_V2_PATH), new FileOutputStream(f));
    f = bm.copyRemoving(f, MutableSet.of(""));
    f = bm.copyAdding(f, MutableMap.of(new ZipEntry(""),
        new ByteArrayInputStream( Strings.lines(
            "  scanJavaAnnotations: true").getBytes() ) ));
    ((ManagementContextInternal)mgmt).getOsgiManager().get().install(new FileInputStream(f)).checkNoError();
Example 11
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
private String getLocalKeyStorePath(String keystoreUrl) {
    ResourceUtils res = ResourceUtils.create(this);
    res.checkUrlExists(keystoreUrl, BrooklynWebConfig.KEYSTORE_URL.getName());
    if (new File(keystoreUrl).exists()) {
        return keystoreUrl;
    } else {
        InputStream keystoreStream;
        try {
            keystoreStream = res.getResourceFromUrl(keystoreUrl);
        } catch (Exception e) {
            throw new IllegalArgumentException("Unable to access URL: "+keystoreUrl, e);
        File tmp = Os.newTempFile("brooklyn-keystore", "ks");
        try {
            FileUtil.copyTo(keystoreStream, tmp);
        } finally {
        return tmp.getAbsolutePath();
Example 12
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
/** yaml variant of VanillaSoftwareProcessAndChildrenIntegrationTest */
public void testVanillaSoftwareYamlWithChildStartedAfter() {
    SimpleYamlLauncher l = new SimpleYamlLauncherForTests();
    try {
        Application app = l.launchAppYaml("vanilla-software-with-child-blueprint.yaml");"started "+app);

        Entity p1 = Iterables.getOnlyElement( app.getChildren() );
        Long d1 = Long.parseLong( Strings.getFirstWordAfter(new ResourceUtils(this).getResourceAsString(Os.mergePaths(p1.getAttribute(SoftwareProcess.RUN_DIR), "DATE")), "utc") );
        Entity p2 = Iterables.getOnlyElement( p1.getChildren() );
        Long d2 = Long.parseLong( Strings.getFirstWordAfter(new ResourceUtils(this).getResourceAsString(Os.mergePaths(p2.getAttribute(SoftwareProcess.RUN_DIR), "DATE")), "utc") );
        Assert.assertTrue( d2-d1 > 2 && d2-d1 < 10, "p2 should have started 3s after parent, but it did not ("+(d2-d1)+"s difference" );
    } finally {
Example 13
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
/** returns URL for accessing the java agent, throwing if not applicable;
 * prefers on classpath where it should be, but will fall back to taking from maven hosted
 * (known problem in Eclipse where JARs are not always copied)
public String getJmxAgentJarUrl() {
    MavenArtifact artifact = getJmxAgentJarMavenArtifact();
    if (artifact==null)
        throw new IllegalStateException("Either JMX is not enabled or there is an error in the configuration (JMX mode "+getJmxAgentMode()+" does not support agent JAR)");
    String jar = "classpath://" + artifact.getFilename();
    if (ResourceUtils.create(this).doesUrlExist(jar))
        return jar;

    String result = MavenRetriever.localUrl(artifact);
    if (warnedAboutNotOnClasspath) {
        log.debug("JMX JAR for "+artifact+" is not on the classpath; taking from "+result);
    } else {
        log.warn("JMX JAR for "+artifact+" is not on the classpath; taking from "+result+" (subsequent similar messages will be logged at debug)");
        warnedAboutNotOnClasspath = true;
    return result;
Example 14
public UrlsExternalConfigSupplier(ManagementContext managementContext, String name, Map<String, String> config) throws IOException {
    super(managementContext, name);
    this.config = config;
    resourceUtils = ResourceUtils.create(

    Map<String, String> missing = Maps.newLinkedHashMap();
    for (Map.Entry<String, String> entry : config.entrySet()) {
        String target = entry.getValue();
        if (!resourceUtils.doesUrlExist(target)) {
            missing.put(entry.getKey(), entry.getValue());
    if (missing.size() > 0) {
        throw new IllegalStateException("URLs for external config '"+getName()+"' not found: "+missing);
Example 15
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
public void install() {
    String resourceName = "/"+MyEntityApp.class.getName().replace(".", "/")+".class";
    ResourceUtils r = ResourceUtils.create(this);
    if (r.getResourceFromUrl(resourceName) == null) 
        throw new IllegalStateException("Cannot find resource "+resourceName);
    String tmpFile = "/tmp/brooklyn-test-MyEntityApp-"+Identifiers.makeRandomId(6)+".class";
    int result = getMachine().installTo(resourceName, tmpFile);
    if (result!=0) throw new IllegalStateException("Cannot install "+resourceName+" to "+tmpFile);
    String saveAs = "classes/"+MyEntityApp.class.getPackage().getName().replace(".", "/")+"/"+MyEntityApp.class.getSimpleName()+".class";
            "curl -L \"file://"+tmpFile+"\" --create-dirs -o "+saveAs+" || exit 9"
Example 16
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 6 votes vote down vote up
/** task to install a file given a url, where the url is resolved remotely first then locally */
public static TaskFactory<?> installFromUrl(final ResourceUtils utils, final Map<String, ?> props, final SshMachineLocation location, final String url, final String destPath) {
    return new TaskFactory<TaskAdaptable<?>>() {
        public TaskAdaptable<?> newTask() {
            return Tasks.<Void>builder().displayName("installing "+Urls.getBasename(url)).description("installing "+url+" to "+destPath).body(new Runnable() {
                public void run() {
                    int result = location.installTo(utils, props, url, destPath);
                    if (result!=0) 
                        throw new IllegalStateException("Failed to install '"+url+"' to '"+destPath+"' at "+location+": exit code "+result);
Example 17
Source Project: brooklyn-library   Source File:    License: Apache License 2.0 5 votes vote down vote up
public void start(Collection<? extends Location> locations) {
    Machines.warnIfLocalhost(locations, "CassandraCluster does not support multiple nodes on localhost, " +
            "due to assumptions Cassandra makes about the use of the same port numbers used across the cluster.");

    // force this to be set - even if it is using the default
    sensors().set(CLUSTER_NAME, getConfig(CLUSTER_NAME));


    // TODO wait until all nodes which we think are up are consistent 
    // i.e. all known nodes use the same schema, as reported by
    // SshEffectorTasks.ssh("echo \"describe cluster;\" | /bin/cassandra-cli");
    // once we've done that we can revert to using 2 seed nodes.
    // see CassandraCluster.DEFAULT_SEED_QUORUM
    // (also ensure the cluster is ready if we are about to run a creation script)

    String scriptUrl = getConfig(CassandraNode.CREATION_SCRIPT_URL);
    if (Strings.isNonEmpty(scriptUrl)) {
        executeScript(new ResourceUtils(this).getResourceAsString(scriptUrl));

Example 18
Source Project: brooklyn-library   Source File:    License: Apache License 2.0 5 votes vote down vote up
public void testBigIntegerFormattedCorrectly() {
    Map<String, Object> substitutions = ImmutableMap.<String, Object>builder()
            .put("entity", new MockInputForTemplate())
            .put("driver", new MockInputForTemplate())

    String templatedUrl = CassandraNode.CASSANDRA_CONFIG_TEMPLATE_URL.getDefaultValue();
    String url = TemplateProcessor.processTemplateContents(templatedUrl, ImmutableMap.of("entity", ImmutableMap.of("majorMinorVersion", "1.2")));
    String templateContents = new ResourceUtils(this).getResourceAsString(url);
    String processedTemplate = TemplateProcessor.processTemplateContents(templateContents, substitutions);
    Assert.assertEquals(processedTemplate.indexOf("775,808"), -1);
    Assert.assertTrue(processedTemplate.indexOf("-9223372036854775808") > 0);
Example 19
public static void downloadResource(String url, File target){
        try {
            downloadResource(new ResourceUtils(null).getResourceFromUrl(url), target);
        } catch (Exception e) {
            throw Throwables.propagate(e);
Example 20
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'");
    String datestamp = sdf.format(generationTime);
    String declarations = getHostsDeclaration(hosts);
    return template
        .replaceAll(DATESTAMP_MARKER, datestamp)
        .replace(HOSTS_DECLARATIONS_MARKER, declarations);
Example 21
public void testScriptGeneration() {
    Date generationTime = new Date(0);
    String generatedScript = GeoscalingScriptGenerator.generateScriptString(generationTime, HOSTS);
    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);
Example 22
Source Project: brooklyn-library   Source File:    License: Apache License 2.0 5 votes vote down vote up
@Nullable private static String getDatabaseCreationScriptAsString(Entity entity) {
    String url = entity.getConfig(MySqlMaster.MASTER_CREATION_SCRIPT_URL);
    if (!Strings.isBlank(url))
        return new ResourceUtils(entity).getResourceAsString(url);
    String contents = entity.getConfig(MySqlMaster.MASTER_CREATION_SCRIPT_CONTENTS);
    if (!Strings.isBlank(contents))
        return contents;
    return null;
Example 23
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 5 votes vote down vote up
public void testRenameClass() throws Exception {
    String xsltTemplate = ResourceUtils.create(XsltTransformerTest.class).getResourceAsString("classpath://brooklyn/entity/rebind/transformer/impl/renameClass.xslt");
    String xslt = TemplateProcessor.processTemplateContents(xsltTemplate, ImmutableMap.of("old_val", "MyClassBefore", "new_val", "MyClassAfter"));
    String input = 
            "<entity myattrib=\"myval\">"+NEWLINE+
            "  <type myattrib2=\"myval2\">mytype.Before</type>"+NEWLINE+
            "  <config>"+NEWLINE+
            "    <test.conf1>"+NEWLINE+
            "      <MyClassBefore>"+NEWLINE+
            "      </MyClassBefore>"+NEWLINE+
            "    </test.conf1>"+NEWLINE+
            "  </config>"+NEWLINE+
    String expected = 
            "<entity myattrib=\"myval\">"+NEWLINE+
            "  <type myattrib2=\"myval2\">mytype.Before</type>"+NEWLINE+
            "  <config>"+NEWLINE+
            "    <test.conf1>"+NEWLINE+
            "      <MyClassAfter>"+NEWLINE+
            "      </MyClassAfter>"+NEWLINE+
            "    </test.conf1>"+NEWLINE+
            "  </config>"+NEWLINE+
    XsltTransformer transformer = new XsltTransformer(xslt);
    String result = transformer.transform(input);
    assertEquals(result, expected);
Example 24
private File givenLegacyEntityFile(final String entityId) throws IOException {
    // load template entity config file
    final String persistedEntity = ResourceUtils.create(RebindWithDeserializingClassRenamesTest.class)
            .getResourceAsString(RESOURCE_PATH + entityId);
    // create a private/writable copy of the legacy config file
    final File persistedEntityFile = new File(mementoDir, Os.mergePaths("entities", entityId));
    Files.write(persistedEntityFile.toPath(), persistedEntity.getBytes());
    return persistedEntityFile;
Example 25
private static void assertAllClassesListedAtUrl(ResourceUtils loader, String url, Iterable<?> resourceClasses) {
    String text = loader.getResourceAsString(url);
    List<String> missingClasses = MutableList.of();
    for (Object c: resourceClasses) {
        if (c instanceof Class) c = ((Class<?>)c).getName();
        else c = c.getClass().getName();
        if (text.indexOf(c.toString())==-1) missingClasses.add(c.toString());
    if (!missingClasses.isEmpty())"Missing entries at "+url+": "+missingClasses);
Example 26
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 5 votes vote down vote up
static List<String> getIpAddressWebsites() {
    String file = new ResourceUtils(LocalhostExternalIpLoader.class)
    Iterable<String> lines = Splitter.on('\n')
    List<String> urls = Lists.newArrayList(Iterables.filter(lines, Predicates.not(StringPredicates.startsWith("#"))));
    return urls;
Example 27
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 5 votes vote down vote up
public Application launchAppYaml(String url, boolean waitForTasksToComplete) {
    try {
        Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl(url));
        Application app = launchAppYaml(input, waitForTasksToComplete);"Application started from YAML file "+url+": "+app);
        return app;
    } catch (Exception e) {
        throw Exceptions.propagate(e);
Example 28
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 5 votes vote down vote up
 * Installs the given URL at the indicated destination path.
 * <p>
 * Attempts to curl the source URL on the remote machine,
 * then if that fails, loads locally (from classpath or file) and transfers.
 * <p>
 * Use {@link ArchiveUtils} to handle directories and their contents properly.
 * TODO allow s3://bucket/file URIs for AWS S3 resources
 * TODO use PAX-URL style URIs for maven artifacts
 * TODO use subtasks here for greater visibility?; deprecate in favour of SshTasks.installFromUrl?
 * @param utils A {@link ResourceUtils} that can resolve the source URLs
 * @param url The source URL to be installed
 * @param destPath The file to be created on the destination
 * @see ArchiveUtils#deploy(String, SshMachineLocation, String)
 * @see ArchiveUtils#deploy(String, SshMachineLocation, String, String)
 * @see ResourceUtils#getResourceFromUrl(String)
public int installTo(ResourceUtils utils, Map<String,?> props, String url, String destPath) {
    LOG.debug("installing {} to {} on {}, attempting remote curl", new Object[] { url, destPath, this });

    try {
        PipedInputStream insO = new PipedInputStream(); OutputStream outO = new PipedOutputStream(insO);
        PipedInputStream insE = new PipedInputStream(); OutputStream outE = new PipedOutputStream(insE);
        StreamGobbler sgsO = new StreamGobbler(insO, null, LOG); sgsO.setLogPrefix("[curl @ "+address+":stdout] ").start();
        StreamGobbler sgsE = new StreamGobbler(insE, null, LOG); sgsE.setLogPrefix("[curl @ "+address+":stdout] ").start();
        Map<String, ?> sshProps = MutableMap.<String, Object>builder().putAll(props).put("out", outO).put("err", outE).build();
        int result = execScript(sshProps, "copying remote resource "+url+" to server",  ImmutableList.of(
                BashCommands.INSTALL_CURL, // TODO should hold the 'installing' mutex
                "mkdir -p `dirname '"+destPath+"'`",
                "curl "+url+" -L --silent --insecure --show-error --fail --connect-timeout 60 --max-time 600 --retry 5 -o '"+destPath+"'"));
        if (result != 0) {
            LOG.debug("installing {} to {} on {}, curl failed, attempting local fetch and copy", new Object[] { url, destPath, this });
            try {
                Tasks.setBlockingDetails("retrieving resource "+url+" for copying across");
                InputStream stream = utils.getResourceFromUrl(url);
                Tasks.setBlockingDetails("copying resource "+url+" to server");
                result = copyTo(props, stream, destPath);
            } finally {
        if (result == 0) {
            LOG.debug("installing {} complete; {} on {}", new Object[] { url, destPath, this });
        } else {
            LOG.warn("installing {} failed; {} on {}: {}", new Object[] { url, destPath, this, result });
        return result;
    } catch (IOException e) {
        throw Throwables.propagate(e);
Example 29
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 5 votes vote down vote up
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()) {
        Dumper.dumpInfo(entity);"Expected NOT to find 'messages.txt'");
Example 30
Source Project: brooklyn-server   Source File:    License: Apache License 2.0 5 votes vote down vote up
private synchronized void loadTheDefaultCatalog(boolean lookOnDiskForDefaultCatalog) {
    if (defaultCatalog!=null) return;
    BrooklynProperties props = BrooklynProperties.Factory.newEmpty();
        // if default catalog is picked up from the system, we might get random stuff from ~/.brooklyn/ instead of the default;
        // useful as an integration check that we default correctly, but irritating for people to use if they have such a catalog installed
        (lookOnDiskForDefaultCatalog ? "" :
            "data:,"+Urls.encode(new ResourceUtils(this).getResourceAsString("classpath:/brooklyn/"))));
    LocalManagementContext mgmt = newManagementContext(props);
    defaultCatalog = mgmt.getCatalog();"ENTITIES loaded for DEFAULT: "+defaultCatalog.getCatalogItems(Predicates.alwaysTrue()));