Difference between revisions of "Virtual Platform"

From Gcube Wiki
Jump to: navigation, search
(Created page with '== Role == The ''Virtual Platform'' is a model to be extended for transparently interfacing a potentially unlimited number of hosting environments. This library has been designe…')
 
(Implementing a new virtual platform)
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Role ==
 
== Role ==
  
The ''Virtual Platform'' is a model to be extended for transparently interfacing a potentially unlimited number of hosting environments. This library has been designed and implement to allow to manage the lifecycle of execution units running on a different platform than gCore  
+
The ''Virtual Platform'' is a model to be extended for transparently interfacing a potentially unlimited number of hosting environments. This library provides an implementation of the ''Virtual Platform'' model. By extending and implementing the classes and interfaces of the library it is possible to bridge and manage the lifecycle of execution units running on a different platform than gCore.
  
The gCube enabling technology is capable of dynamically instantiating platforms (along with their resources) compliant to such a model. When new software designed to run on a specific platform is uploaded in the software repository and then requested for deployment, a virtual image of the target platform is created to manage such software.  
+
The gCube enabling technology is capable of dynamically instantiating platforms (along with their resources) compliant to such a model. When new software designed to run on a specific platform is uploaded in the [[Software Repository]] and then requested for deployment, a virtual image of the target platform is created to manage such software.
  
 
== Design ==
 
== Design ==
TBP
+
The library has been designed having in mind its two-fold role:
 +
 
 +
* to model the basic behavior of a virtual platform (package ''org.gcube.vremanagement.virtualplatform.model'')
 +
* to offer a platform-independent way to instantiate and interact with a concrete virtual platform implementation (package ''org.gcube.vremanagement.virtualplatform.image'')
 +
 
 +
 
 +
== Implementing a new virtual platform ==
 +
 
 +
The complexity of the implementation of a virtual platform depends on the interface of the concrete platform to interface. However, creating a bridge with the gCube enabling layer requires an handful steps described below.
 +
 
 +
=== Defining the platform interface ===
 +
 
 +
Defining the platform interface firstly requires to extend of the following abstract class:
 +
 
 +
<source lang="java">
 +
package org.gcube.vremanagement.virtualplatform.model;
 +
 
 +
public abstract class TargetPlatform<RESOURCE extends Package> {
 +
 
 +
}
 +
 
 +
</source>
 +
 
 +
The <em>RESOURCE</em> type defines the type of objects accepted for deployment, undeployment, activation and deactivation of execution units on the target platform. Although it's an abstract class, sub-classes of <em>TargetPlatform</em> are not forced to implement any method. This allows to have also virtual platforms that support only part of the lifeclycle of a unit (for example, they do not support activation or deactivation, or do not have dynamic deployment features). Thus, all the methods are provided with a default implementation.
 +
 
 +
==== Methods for platform configuration ====
 +
 
 +
<source lang="java">
 +
/**
 +
* Sets the base URL of the platform
 +
* @param url
 +
*/
 +
public void setBaseURL(URL url)
 +
 
 +
/**
 +
* Sets the password to use for the admin user in the target platform, if any
 +
* @param password the password
 +
*/
 +
public  void setPassword(String password)
 +
 
 +
/**
 +
* Sets the admin user, if any
 +
* @param user the user
 +
*/
 +
public void setUser(String user)
 +
 
 +
/**
 +
* Sets the base URL of the platform
 +
* @param url
 +
*/
 +
public void setBaseURL(URL url)
 +
 
 +
/**
 +
* Sets the password to use for the admin user in the target platform, if any
 +
* @param password the password
 +
*/
 +
public  void setPassword(String password)
 +
 
 +
/**
 +
* Sets the admin user, if any
 +
* @param user the user
 +
*/
 +
public void setUser(String user)
 +
</source>
 +
 
 +
==== Methods for platform management ====
 +
 
 +
The following methods allow to manage the platform as a whole (the lifetime of the execution units follow the platform's status):
 +
 
 +
<source lang="java">
 +
/**
 +
* Initializes the platform
 +
* @throws Exception
 +
*/
 +
public void initialize() throws Exception
 +
 +
/**
 +
* Shutdowns the platform
 +
* @throws Exception
 +
*/
 +
public void shutdown() throws Exception
 +
/**
 +
* Checks whether the platform is available or not
 +
* @return true if the platform is available, false otherwise
 +
*/
 +
public boolean isAvailable()
 +
 
 +
</source>
 +
 
 +
==== Methods for execution unit management ====
 +
 
 +
The following methods allow to manager execution units over the platform:
 +
 
 +
<source lang="java">
 +
/**
 +
* Gets the filter to select the appropriate files to deploy on the platform. The filter is used
 +
* to select the files belonging the platform in case of multiple files available in the package.
 +
* @return the filter or null if no filter is available
 +
*/
 +
public FileFilter getAcceptedFilesFilter()
 +
 
 +
/**
 +
* Deploys a resource into the platform
 +
* @param resource the resource to deploy
 +
* @return the deployed resource
 +
* @throws Exception
 +
*/
 +
public DeployedPackage deploy(RESOURCE resource) throws Exception
 +
 +
/**
 +
* Undeploys a resource from the platform
 +
* @param resource the resource to undeploy
 +
* @return the undeployed resource
 +
* @throws Exception
 +
*/
 +
public UndeployedPackage undeploy(RESOURCE resource) throws Exception
 +
 +
/**
 +
* Activates the resource in the platform
 +
* @param resource the resource to activate
 +
* @return <tt>true</tt> if the resource was successfully activated, <tt>false</tt> otherwise
 +
* @throws Exception
 +
*/
 +
public boolean activate(RESOURCE resource) throws Exception
 +
 +
/**
 +
* Deactivates the resource on the platform
 +
* @param resource the resource to deactivate
 +
* @return <tt>true</tt> if the resource was successfully deactivated, <tt>false</tt> otherwise
 +
* @throws Exception
 +
*/
 +
public boolean deactivate(RESOURCE resource) throws Exception
 +
 +
/**
 +
* Lists all the resources deployed
 +
* @return the resources
 +
* @throws Exception
 +
*/
 +
public PackageSet<RESOURCE> list() throws Exception
 +
</source>
 +
 
 +
=== Resources for the platform ===
 +
 
 +
==== Package ====
 +
 
 +
==== DeployedPackage ====
 +
 
 +
==== UndeployedPackage ====
 +
 
 +
=== Configuration ===
 +
 
 +
A platform configuration consists of a properties file with the following syntax:
 +
 
 +
<source lang="text">
 +
Name=
 +
Version=
 +
PlatformClass=
 +
Resources=
 +
ResourceFolder=
 +
DedicatedClassLoader=
 +
BaseURL=
 +
User=
 +
Password=
 +
</source>
 +
 
 +
The following properties has to be filled by the developer of the virtual platform:
 +
* ''Name'' and ''Version'' are arbitrary values decided by the developer. The values will be used to match the ones reported in the profile of a package that aims to target this platform;
 +
* ''PlatformClass'' is the entry point to the platform functionalities. It must be a subclass of <em>org.gcube.vremanagement.virtualplatform.model.TargetPlatform</em>
 +
* ''Resources'' and ''ResourceFolder'' are both used to select the resources belonging the platform. These resources will be loaded on the classpath created for managing the platform;
 +
* ''DedicatedClassLoader'' is a boolean flag (then allowed values are true or false) stating if a dedicated Java classloader must be created for the platform;
 +
 
 +
The last three properties have to be filled by the Site Manager that configure an instance of the virtual platform and their role is to bridge it with the concrete platform. All of them are optional:
 +
* ''BaseURL'' is the runtime network entrypoint of the platform;
 +
* ''User and ''Password'' are the credentials to access to the concrete platform.
 +
 
 +
== Managing platforms ==
 +
 
 +
 
 +
=== Instantiating ===
 +
 
 +
A virtual platform can be instantiated starting from its configuration object. The list of configuration objects available on the node can be obtained by invoking the <em>listAvailablePlatforms()</em> method on the Platforms class. Starting from a given folder, the method reads and loads all the platform [[Virtual_Platform#Configuration|configuration files]].
 +
 
 +
<source lang="java">
 +
import org.gcube.vremanagement.virtualplatform.image.PlatformConfiguration;
 +
import org.gcube.vremanagement.virtualplatform.image.VirtualPlatform;
 +
import org.gcube.vremanagement.virtualplatform.image.Platforms;
 +
 
 +
 
 +
 
 +
List<PlatformConfiguration> configurations = Platforms.listAvailablePlatforms(new File(GHNContext.getContext().getVirtualPlatformsLocation()));
 +
for (PlatformConfiguration config : configurations){
 +
  VirtualPlatform vp = new VirtualPlatform(config)
 +
  //plays with the platform
 +
}
 +
</source>
 +
 
 +
=== Playing with the platform ===
 +
 
 +
=== Managing Packages ===
 +
 
 +
==== Deployment ====
 +
 
 +
==== Activation ====
 +
 
 +
==== Deactivation ====
 +
 
 +
==== Undeployment ====

Latest revision as of 03:23, 26 July 2011

Role

The Virtual Platform is a model to be extended for transparently interfacing a potentially unlimited number of hosting environments. This library provides an implementation of the Virtual Platform model. By extending and implementing the classes and interfaces of the library it is possible to bridge and manage the lifecycle of execution units running on a different platform than gCore.

The gCube enabling technology is capable of dynamically instantiating platforms (along with their resources) compliant to such a model. When new software designed to run on a specific platform is uploaded in the Software Repository and then requested for deployment, a virtual image of the target platform is created to manage such software.

Design

The library has been designed having in mind its two-fold role:

  • to model the basic behavior of a virtual platform (package org.gcube.vremanagement.virtualplatform.model)
  • to offer a platform-independent way to instantiate and interact with a concrete virtual platform implementation (package org.gcube.vremanagement.virtualplatform.image)


Implementing a new virtual platform

The complexity of the implementation of a virtual platform depends on the interface of the concrete platform to interface. However, creating a bridge with the gCube enabling layer requires an handful steps described below.

Defining the platform interface

Defining the platform interface firstly requires to extend of the following abstract class:

package org.gcube.vremanagement.virtualplatform.model;
 
public abstract class TargetPlatform<RESOURCE extends Package> {
 
}

The RESOURCE type defines the type of objects accepted for deployment, undeployment, activation and deactivation of execution units on the target platform. Although it's an abstract class, sub-classes of TargetPlatform are not forced to implement any method. This allows to have also virtual platforms that support only part of the lifeclycle of a unit (for example, they do not support activation or deactivation, or do not have dynamic deployment features). Thus, all the methods are provided with a default implementation.

Methods for platform configuration

	/**
	 * Sets the base URL of the platform
	 * @param url
	 */
	public void setBaseURL(URL url) 
 
	/**
	 * Sets the password to use for the admin user in the target platform, if any
	 * @param password the password
	 */
	public  void setPassword(String password)
 
	/**
	 * Sets the admin user, if any
	 * @param user the user
	 */
	public void setUser(String user) 
 
	/**
	 * Sets the base URL of the platform
	 * @param url
	 */
	public void setBaseURL(URL url) 
 
	/**
	 * Sets the password to use for the admin user in the target platform, if any
	 * @param password the password
	 */
	public  void setPassword(String password) 
 
	/**
	 * Sets the admin user, if any
	 * @param user the user
	 */
	public void setUser(String user)

Methods for platform management

The following methods allow to manage the platform as a whole (the lifetime of the execution units follow the platform's status):

	/**
	 * Initializes the platform
	 * @throws Exception
	 */
	public void initialize() throws Exception
 
	/**
	 * Shutdowns the platform
	 * @throws Exception
	 */
	public void shutdown() throws Exception 
	/**
	 * Checks whether the platform is available or not
	 * @return true if the platform is available, false otherwise
	 */
	public boolean isAvailable()

Methods for execution unit management

The following methods allow to manager execution units over the platform:

	/**
	 * Gets the filter to select the appropriate files to deploy on the platform. The filter is used
	 * to select the files belonging the platform in case of multiple files available in the package.
	 * @return the filter or null if no filter is available
	 */
	public FileFilter getAcceptedFilesFilter() 
 
	/**
	 * Deploys a resource into the platform
	 * @param resource the resource to deploy
	 * @return the deployed resource
	 * @throws Exception
	 */
	public DeployedPackage deploy(RESOURCE resource) throws Exception 
 
	/**
	 * Undeploys a resource from the platform
	 * @param resource the resource to undeploy
	 * @return the undeployed resource
	 * @throws Exception
	 */
	public UndeployedPackage undeploy(RESOURCE resource) throws Exception 
 
	/**
	 * Activates the resource in the platform
	 * @param resource the resource to activate
	 * @return <tt>true</tt> if the resource was successfully activated, <tt>false</tt> otherwise
	 * @throws Exception
	 */
	public boolean activate(RESOURCE resource) throws Exception
 
	/**
	 * Deactivates the resource on the platform
	 * @param resource the resource to deactivate
	 * @return <tt>true</tt> if the resource was successfully deactivated, <tt>false</tt> otherwise
	 * @throws Exception
	 */
	public boolean deactivate(RESOURCE resource) throws Exception 
 
	/**
	 * Lists all the resources deployed
	 * @return the resources
	 * @throws Exception
	 */
	public PackageSet<RESOURCE> list() throws Exception

Resources for the platform

Package

DeployedPackage

UndeployedPackage

Configuration

A platform configuration consists of a properties file with the following syntax:

Name=
Version=
PlatformClass=
Resources=
ResourceFolder=
DedicatedClassLoader=
BaseURL=
User=
Password=

The following properties has to be filled by the developer of the virtual platform:

  • Name and Version are arbitrary values decided by the developer. The values will be used to match the ones reported in the profile of a package that aims to target this platform;
  • PlatformClass is the entry point to the platform functionalities. It must be a subclass of org.gcube.vremanagement.virtualplatform.model.TargetPlatform
  • Resources and ResourceFolder are both used to select the resources belonging the platform. These resources will be loaded on the classpath created for managing the platform;
  • DedicatedClassLoader is a boolean flag (then allowed values are true or false) stating if a dedicated Java classloader must be created for the platform;

The last three properties have to be filled by the Site Manager that configure an instance of the virtual platform and their role is to bridge it with the concrete platform. All of them are optional:

  • BaseURL is the runtime network entrypoint of the platform;
  • User and Password are the credentials to access to the concrete platform.

Managing platforms

Instantiating

A virtual platform can be instantiated starting from its configuration object. The list of configuration objects available on the node can be obtained by invoking the listAvailablePlatforms() method on the Platforms class. Starting from a given folder, the method reads and loads all the platform configuration files.

import org.gcube.vremanagement.virtualplatform.image.PlatformConfiguration;
import org.gcube.vremanagement.virtualplatform.image.VirtualPlatform;
import org.gcube.vremanagement.virtualplatform.image.Platforms;
 
 
 
List<PlatformConfiguration> configurations = Platforms.listAvailablePlatforms(new File(GHNContext.getContext().getVirtualPlatformsLocation()));
for (PlatformConfiguration config : configurations){
   VirtualPlatform vp = new VirtualPlatform(config)
   //plays with the platform
}

Playing with the platform

Managing Packages

Deployment

Activation

Deactivation

Undeployment