When developing Java applications that make use of MMBase it is often required to get cloud instances. The standard MMBase way of getting a cloud instance is to provide credentials (for example user name / password). While that method is well suited when user interaction is possible, it poses problems when the actor acquiring the cloud is a Java class because the class then needs to store the credentials somewhere. The CloudProvider addresses this problem by delegating the repetitive task of getting the credentials and acquiring Classes used to define the CloudProvider behaviour.
The MMBase Cloud Provider serves clouds to requesting clients. It is designed in such a way that client code does not have to provide explicit credentials. The MMBase Cloud Provider works like commons-logging. You will typicaly have a private static cloud provider instance in you class and every time you need a cloud you will request that cloud to the cloud provider.
import net.sf.mmapps.modules.cloudprovider.CloudProvider; import net.sf.mmapps.modules.cloudprovider.CloudProviderFactory; import org.mmbase.bridge.*; public class CloudProviderDemo{ private static CloudProvider cloudProvider = CloudProviderFactory.getCloudProvider(); pulbic void performSomeAction(){ Cloud cloud = cloudProvider.getAdminCloud(); cloud.getNode(123); } }
The cloud provider is configured using a properties file in net.sf.mmapps.modules.cloudprovider (or WEB-INF/classes/ ) the file is calles cloudprovider.properties and currently looks like this
# # property file showing # cloud_provider_class=net.sf.mmapps.modules.cloudprovider.ConfiguredUsernameAndPasswordCloudProvider username=admin password=admin2k # RMI cloud example to get an instance call CloudProviderFactory.getCloudProvider("foo"); #foo.cloud_provider_class=net.sf.mmapps.modules.cloudprovider.impl.ConfiguredUsernameAndPasswordCloudProvider #foo.cloudcontextname=rmi://foo.com:4022/remotecontext #foo.username=foo #foo.password=bar