Skip to content
This repository was archived by the owner on Mar 20, 2024. It is now read-only.

Commit

Permalink
Allow for the default download URL to be overridden
Browse files Browse the repository at this point in the history
  • Loading branch information
pacphi committed Jun 29, 2018
1 parent 02ed7e0 commit 761c93d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 4 deletions.
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Optional
## Clone

```
git clone https://github.com/pacphi/cf-get-service-details.git
git clone https://github.com/pacphi/cf-service-inventory-report.git
```

## How to configure
Expand Down Expand Up @@ -57,6 +57,27 @@ At a minimum you should supply values for the following keys
* `mail.from` - originator email address
* `mail.recipients` - email addresses that will be sent an email with CSV attachments

### to override the default download URL

On application start-up, a versioned Mongo executable is downloaded from a default location (addressable from the public internet). If you would like to download the executable from an alternate location and/or select an alternate version, add the following:

* `spring.mongodb.embedded.verson` - version of the Mongo executable (e.g., `3.4.15`)
* `spring.mongodb.embedded.download.path` - the path to the parent directory hosting OS-specific sub-directories and version(s) of Mongo executables (e.g., `https://fastdl.mongodb.org/`)
* `spring.mongodb.embedded.download.alternate` - this is a boolean property and must be set to true to activate alternate download URL

As an example, the following

```
spring:
mongodb:
embedded:
version: 3.4.15
download:
path: https://fastdl.mongodb.org/
alternate: true
```

would download the Mongo executable from `https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.4.15.tgz` when the app is running on a Mac OSX host.

## How to Build

Expand Down
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
springBootVersion = '2.0.2.RELEASE'
springBootVersion = '2.0.3.RELEASE'
}
repositories {
mavenCentral()
Expand All @@ -23,6 +23,10 @@ repositories {
mavenCentral()
}

bootRun {
// support passing -Dsystem.property=value to bootRun task
systemProperties = System.properties
}

dependencies {
compileOnly('org.projectlombok:lombok:1.18.0')
Expand All @@ -33,7 +37,7 @@ dependencies {
compile('org.springframework.boot:spring-boot-starter-mail')
compile('com.sendgrid:sendgrid-java:4.2.1')
compile('org.springframework.boot:spring-boot-starter-data-mongodb-reactive')
runtime('de.flapdoodle.embed:de.flapdoodle.embed.mongo')
compile('de.flapdoodle.embed:de.flapdoodle.embed.mongo:2.1.1')
compile('org.cloudfoundry:cloudfoundry-client-reactor:3.10.0.RELEASE')
compile('org.cloudfoundry:cloudfoundry-operations:3.10.0.RELEASE')
compile('io.projectreactor:reactor-core:3.1.7.RELEASE')
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/io/pivotal/cfapp/MongoConfig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.pivotal.cfapp;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration;
import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration;
Expand All @@ -17,6 +20,19 @@

import com.mongodb.reactivestreams.client.MongoClient;
import com.mongodb.reactivestreams.client.MongoClients;

import de.flapdoodle.embed.mongo.Command;
import de.flapdoodle.embed.mongo.config.DownloadConfigBuilder;
import de.flapdoodle.embed.mongo.config.ExtractedArtifactStoreBuilder;
import de.flapdoodle.embed.mongo.config.RuntimeConfigBuilder;
import de.flapdoodle.embed.process.config.IRuntimeConfig;
import de.flapdoodle.embed.process.config.io.ProcessOutput;
import de.flapdoodle.embed.process.config.store.IDownloadConfig;
import de.flapdoodle.embed.process.io.Processors;
import de.flapdoodle.embed.process.io.Slf4jLevel;
import de.flapdoodle.embed.process.io.progress.Slf4jProgressListener;
import de.flapdoodle.embed.process.store.IArtifactStore;
import io.pivotal.cfapp.config.AdditionalEmbeddedMongoProperties;


@SpringBootApplication(exclude = { MongoAutoConfiguration.class, MongoDataAutoConfiguration.class })
Expand Down Expand Up @@ -54,4 +70,32 @@ protected String getDatabaseName() {
return "cf-service-inventory";
}

@ConditionalOnProperty(prefix="spring.mongodb.embedded.download", name = "alternate", havingValue = "true")
@Bean
IRuntimeConfig embeddedMongoRuntimeConfig(AdditionalEmbeddedMongoProperties settings) {
Command command = Command.MongoD;
Logger logger = LoggerFactory
.getLogger(getClass().getPackage().getName() + ".EmbeddedMongo");
ProcessOutput processOutput = new ProcessOutput(
Processors.logTo(logger, Slf4jLevel.INFO),
Processors.logTo(logger, Slf4jLevel.ERROR), Processors.named(
"[console>]", Processors.logTo(logger, Slf4jLevel.DEBUG)));
IDownloadConfig downloadConfig =
new DownloadConfigBuilder()
.defaultsForCommand(command)
.downloadPath(settings.getPath())
.progressListener(new Slf4jProgressListener(logger))
.build();
IArtifactStore artifactStore =
new ExtractedArtifactStoreBuilder()
.defaults(command)
.download(downloadConfig)
.build();
return
new RuntimeConfigBuilder()
.defaultsWithLogger(command, logger)
.processOutput(processOutput)
.artifactStore(artifactStore)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.pivotal.cfapp.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import lombok.Data;

@Data
@Configuration
@ConfigurationProperties(prefix = "spring.mongodb.embedded.download")
public class AdditionalEmbeddedMongoProperties {

private String path;

}
6 changes: 5 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ mail:
# - recipient_account
subject: "PCF Service Inventory Report"


logging:
level:
de.flapdoodle.embed.mongo: INFO
org.springframework.boot: INFO
com.sendgrid: DEBUG

# Options are: none, java-mail or sendgrid
notification:
Expand Down

0 comments on commit 761c93d

Please sign in to comment.