spring-cloud-nfs-connector-cloudfoundry
Spring Cloud NFS Service Connectors for CloudFoundry Volume Services.
When running in CloudFoundry this Spring Cloud Connector allows you to easily configure your application to write to reliable, non-ephemeral nfs volumes.
Add a connector to your project
The maven coordinates for this Spring Cloud Connector are as follows:
<dependency>
  <groupId>com.github.paulcwarren</groupId>
  <artifactId>spring-cloud-nfs-connector-cloudfoundry</artifactId>
  <version>1.0.0</version>
</dependency> 
In your Spring application create an @Configuration class that extends AbstractCloudConfig to create a NFSConnector bean. This bean provides access to the nfs volumes bund to the application.
@Configuration
public class NFSConfig extends AbstractCloudConfig {
	@Bean
    	public NFSServiceConnector nfs() {
        	return connectionFactory().service(NFSServiceConnector.class);
    	}
} 
Usage example:
@Component
public class ExampleNFS {
    @Autowired
    NFSServiceConnector nfs;
    public void writeFile(String name, InputStream contents){
    	File file = new File(nfs.getVolumeMounts()[0].getContainerDir(), name);
        IOUtils.copyToFile(contents, file);
    }
    public InputStream readFile(String name){
    	File file = new File(nfs.getVolumeMounts()[0].getContainerDir(), name);
        return IOUtils.openInputStream(file);
    }
} 
Deploy and run
Cloud Foundry
- Create an NFS service from the marketplace using the NFS Service Broker.
- Push your app with cf push
- After the app has been pushed bind your new created service to your app (e.g: cf bs nameofmyapp nameofmyservice)
- Restage your app: cf restage nameofmyapp
 JarCasting
 JarCasting