Difference between revisions of "Contexts"

From GCube System
Jump to: navigation, search
(The gHN Context)
Line 1: Line 1:
Within the implementation of gCube services, some functionality needs to be accessed by different components and for different purposes.  
+
Within service implementations, some functionality needs to be accessed by different components and for different purposes.  
  
The most obvious case is functionality that exposes the configuration of the service, its RI, or the gHN on which the RI is deployed; as shown later in the Guide,
+
The most obvious case of ''shared functionality'' is that required to expose the configuration of the service, or the configuration of its RI, or the configuration of the gHN on which the RI is deployed. There is also information related to scope and security that is dynamically acquired and needed by different components. Beyond information access, there are utilities and behaviours - general-purpose or service-specific - which may be called upon from multiple and functionally unrelated components.  
there is also dynamically acquired information related to scope and security that may need to be shared within service implementations. And beyond information access,
+
there are general-purpose or service-specific utilities and behaviours that may be called upon from multiple and functionally unrelated components.  
+
  
In gCF, the approach to shared functionality is to centralise it in distinguished components, called '''contexts''', which are easily accessible from any other implementation component. gCF contexts are singleton classes, in that they are designed to be instantiated only once and to expose the single instance to all their clients.
+
The gCF approach to shared functionality is to centralise it in distinguished components, called '''contexts''', which are directly accessible from any other implementation component. gCF contexts are singleton classes, in that they are designed to be instantiated only once and to expose the single instance to all their clients.
  
There are different type of contexts in gCF, each of which centralises functionality that is conceptually associated with the service and its RI, the gHN on which the RI is deployed, the port-types of the service, and even the port-types of remote target services. Some of these contexts are fully defined within gCF (e.g. the context of the gHN). Others are only partially implemented and need to be specialised within individual service implementations. Collectively, the context form a inheritance hierarchy contained in the <code>contexts</code> package:
+
There are different type of contexts in gCF, each of which centralises functionality that is conceptually associated with the key entities of service implementations: the service and its RI, the gHN on which the RI is deployed, the port-types of the service, and even the port-types of the target services of the RI. Some are fully defined within gCF (e.g. the context of the gHN). Others are only partially implemented and need to be specialised within service implementations. Collectively, the context form a inheritance hierarchy contained in the <code>contexts</code> package:
  
 
[[Image:contexts.jpg]]
 
[[Image:contexts.jpg]]
  
As indicated in the diagram, the entire framework has dependencies on the <code>contexts</code> packages, in line with the definition of contexts as repositories of shared functionality. The high-level roles of the components in the package is summarised below:
+
As shown in the diagram, the entire framework has dependencies on the <code>contexts</code> packages, in line with the definition of contexts as repositories of shared functionality. The high-level roles of the components in the package is summarised below:
  
 
* <code>GCUBEContext</code>: the base implementation for all contexts in gCF.
 
* <code>GCUBEContext</code>: the base implementation for all contexts in gCF.
Line 25: Line 23:
 
* <code>GCUBERemotePortTypeContext</code>: a concrete specialisation of <code>GCUBEContext</code> for a port-type of a target gCube Service.
 
* <code>GCUBERemotePortTypeContext</code>: a concrete specialisation of <code>GCUBEContext</code> for a port-type of a target gCube Service.
  
Before discussing each context class in detail, we refine our the service model to reflect those that are central to the perspective of the service developer:
+
Before discussing each context class in detail, we refine our the service model to introduce key context classes from the perspective of the service developer:
  
 
[[Image:model&contexts.jpg]]
 
[[Image:model&contexts.jpg]]
  
The figures shows that the <code>GHNContext</code> and <code>GCUBERemotePortTypeContext</code> are fully implemented by gCF and live outside the boundary of service implementations. In contrast, service and the port-type contexts fall in the scope of service implementations as specialisations of gCF context classes.
+
The figure shows that the <code>GHNContext</code> and <code>GCUBERemotePortTypeContext</code> are fully implemented by the framework and live outside the boundary of specific service implementations. In contrast, service and the port-type contexts fall in the scope of service implementations as specialisations of gCF context classes.
  
 
== Common Facilities ==
 
== Common Facilities ==
Line 65: Line 63:
 
== The gHN Context ==
 
== The gHN Context ==
  
The <code>GHNContext</code> specialises <code>GCUBEContext</code> for gCube Hosting Nodes.
+
The <code>GHNContext</code> specialises <code>GCUBEContext</code> to serve as the gCF context for gCube Hosting Nodes.
It is the gCF component that is responsible for:
+
In particular, the <code>GHNContext</code> is the gCF component that is responsible for:
  
* managing the lifetime of the gHN, from its initialisation to its shutdown and failure.  
+
* managing the lifetime of the gHN, from its initialisation to its shutdown and failure. This functionality supports the internal operation of the gHN and is typically transparent to most service developers.
* exposing the configuration of the gHN and the host environment.  
+
* exposing the configuration of the gHN and its hosting environment. This is functionality that most developers may need to rely upon for the implementation of their services.
  
Clients can obtain the single instance of the <code>GHNContext</code> by invoking its static method <code>getContext()</code>.  
+
Clients can obtain the single instance of the <code>GHNContext</code> by invoking its static method <code>getContext()</code>. The first invocation of the method triggers the initialisation of the instance.
  
 
=== Lifetime Management===
 
=== Lifetime Management===
Line 79: Line 77:
 
[[Image|GHNStates.jpg]]
 
[[Image|GHNStates.jpg]]
  
The different states of a gHN are represented by the values of the inner enumeration <code>GHNContext.GHNSatus</code>:
+
The different states of a gHN are represented by the values of the inner enumeration <code>GHNContext.GHNSatus</code>:
  
 +
* <code>Status.DOWN</code>: this is the state of a gHN that is not running within the current JVM (or not running at all). This is at once a start and terminal state for the gHN and is detected during the initialisation of the <code>GHNContext</code>. When the gHN is in this state, the <code>GHNContext</code> can only be used to access the gHN configuration and hardware-related information, as described [[Contexts#Configuration Management|below]].
 +
* <code>Status.RUNNING</code>: this is the state of a gHN that is running within the current JVM. When the gHN is in this state, the <code>GHNContext</code> engages in the following activities:
 +
** at regular intervals, it publishes in the infrastructure a profile for the gHN. During its initialisation, in particular, the <code>GHNContext</code> synthesises a <code>GCUBEHostingNode</code> resource that models the local gHN (either from scratch or from local traces of previous gHN startups) and periodically derives a gHN profile from a serialisation of the resource state.
 +
** it maintains and exposes to clients a record of the RIs of the deployed services along with their current state. One distinguished client, the <code>handlers.GCUBEHandler</code> relies on it to block calls to RIs that have failed or are not yet ready to process them (i.e. they have reached the<code>ServiceContext.Status.FAILED</code> state or have not yet reached the <code>ServiceContext.Status.READY</code>, as discussed [[#Service Contexts|below]]). 
 +
* <code>Status.UPDATED</code>:  this is the transitional state of a gHN that has changed some of its state. This is a short-lived state that is used internally to trigger publication of the gHN profile within the infrastructure. After publication, the gHN reverts immediately to the <code>GHNStatus.RUNNING</code>.
  
includes:
+
Only privileged clients and the gHN itself can trigger state transitions. All clients, however, can inspect the current state of the gHN (cf. <code>getStatus()</code>) and be notified of state transitions, as discussed [[#Event Management|below]].
** synthesise a profile for the gHN and publish it at regular intervals in the infrastructure to reflect the latest state of the gHN. In particular, the <code>GHNContext</code> builds a <code>GCUBEHostingNode</code> resource for the gHN.
+
 
+
The <code>GHNContext</code> also manages the lifetime of the gHN, from its initialisation to its shutdown or failure. First, it models the different states in which the gHN can be during its lifetime using the enumerated values of its inner <code>GHNContext.Status</code> class:
+
 
+
* <code>Status.DOWN</code>: the state of a gHN that is not operative. When the gHN is in this state, the <code>GHNContext</code> can only be used to access the gHN configuration and hardware-related information, as described [[Contexts#Configuration Management|above]].
+
* <code>Status.RUNNING</code>: the state of a gHN that is fully operative within the infrastructure.
+
* <code>Status.UPDATED</code>:  the state of a gHN that has updated some of its properties. This is a transitional state that is used internally to trigger publication of the gHN profile within the infrastructure. After publication, the gHN reverts to its previous state.
+
 
+
While only privileged clients and the gHN itself can trigger state transitions, all clients can inspect the current state of the gHN (cf. <code>getStatus()</code>) and be notified of state transitions, as discussed [[#Event Management|below]].
+
  
 
=== Configuration Management ===
 
=== Configuration Management ===

Revision as of 13:56, 26 January 2009

Within service implementations, some functionality needs to be accessed by different components and for different purposes.

The most obvious case of shared functionality is that required to expose the configuration of the service, or the configuration of its RI, or the configuration of the gHN on which the RI is deployed. There is also information related to scope and security that is dynamically acquired and needed by different components. Beyond information access, there are utilities and behaviours - general-purpose or service-specific - which may be called upon from multiple and functionally unrelated components.

The gCF approach to shared functionality is to centralise it in distinguished components, called contexts, which are directly accessible from any other implementation component. gCF contexts are singleton classes, in that they are designed to be instantiated only once and to expose the single instance to all their clients.

There are different type of contexts in gCF, each of which centralises functionality that is conceptually associated with the key entities of service implementations: the service and its RI, the gHN on which the RI is deployed, the port-types of the service, and even the port-types of the target services of the RI. Some are fully defined within gCF (e.g. the context of the gHN). Others are only partially implemented and need to be specialised within service implementations. Collectively, the context form a inheritance hierarchy contained in the contexts package:

Contexts.jpg

As shown in the diagram, the entire framework has dependencies on the contexts packages, in line with the definition of contexts as repositories of shared functionality. The high-level roles of the components in the package is summarised below:

  • GCUBEContext: the base implementation for all contexts in gCF.
  • GCUBEGHNContext: a concrete specialisation of GCUBEContext for a gCube Hosting Node.
  • GCUBEServiceContext: a concrete specialisation of GCUBEContext for a gCube Service and its RIs.
  • GCUBEPortTypeContext: a concrete specialisation of GCUBEContext for a port-type of gCube Service.
  • GCUBEStatefulPortTypeContext: a concrete specialisation of GCUBEPortTypeContext for a stateful port-type of a gCube Service.
  • GCUBERemotePortTypeContext: a concrete specialisation of GCUBEContext for a port-type of a target gCube Service.

Before discussing each context class in detail, we refine our the service model to introduce key context classes from the perspective of the service developer:

Model&contexts.jpg

The figure shows that the GHNContext and GCUBERemotePortTypeContext are fully implemented by the framework and live outside the boundary of specific service implementations. In contrast, service and the port-type contexts fall in the scope of service implementations as specialisations of gCF context classes.

Common Facilities

All gCF contexts offer basic facilities for configuration and local file management.

The primary form of configuration supported by gC contexts is based on named access to arbitrary objects. The underlying configuration mechanism is based on a dedicated implementation of the JNDI interface; in particular, gCF contexts act as a wrappers of standard JNDI contexts and offer a much simplified interface to named access.

The underlying JNDI implementation remains opaque to both clients and implementers of context classes. Developers are only exposed to the configuration files that are then used to populate the JNDI implementation wrapped by the contexts. As we discuss below, the direct subclasses of GCUBEContext are responsible for establishing conventions on the naming and location of such files, for the definition and documentation of pre-defined configuration properties, and for loading all the configuration properties from the files. As most service developers specialise these subclasses, they need only to author the configuration files. The syntax for authoring JNDI configuration is based on XML, and its definition is lifted from technologies that underlies gCF. Conventions on context-specific configuration authoring are discussed below in relation to each type of context.

As to file management, gCF contexts offers facilities to access:

  • files stored in the local file system for reading or writing purposes. Here the main goal is to abstract over the location in which the files are stored and thus to avoid gHN-specific dependencies. While actual location in which files are stored is specific to the type of context, as we discuss below, all contexts offer basic backup facilities: transparently to their clients, they create copies of files that are about to be modified and used backups whenever the original files are corrupted. In the second case, access is read-only
  • files packaged along with the context, or more generally on the classpath, for read-only purposes.

In both cases, the gCF contexts are agnostic to the content of the files. This may be service-specific configuration that lives outside the standard JNDI framework, or any form of state that is deemed suitable for file storage.

The basic operations for configuration and file management are following (see the code documentation for signature details):

  • getProperty(name,mandatory?): resolves a configuration property from its name. An optional flag indicates whether the presence property is deemed mandatory or else is optional (default). The flag is used for error and log management purposes.
  • getResource(path): returns a classpath file resource given its path. A relative path is resolved with respect to the context implementation, while an absolute path is resolved directly against the classpath.
  • getFile(path,mode): returns a java.io.File for read or write access. A write access mode induces backups and a read access (default) relies on backups to recover from failures. In write mode, directories that are specified in the path but do not exist are automatically created, while paths that identify directories are disallowed.

The following refinement of the service model emphasises the configuration and file management role of contexts:

Model&contexts2.jpg

The gHN Context

The GHNContext specialises GCUBEContext to serve as the gCF context for gCube Hosting Nodes. In particular, the GHNContext is the gCF component that is responsible for:

  • managing the lifetime of the gHN, from its initialisation to its shutdown and failure. This functionality supports the internal operation of the gHN and is typically transparent to most service developers.
  • exposing the configuration of the gHN and its hosting environment. This is functionality that most developers may need to rely upon for the implementation of their services.

Clients can obtain the single instance of the GHNContext by invoking its static method getContext(). The first invocation of the method triggers the initialisation of the instance.

Lifetime Management

For lifetime management purposes, the GHNContext models the gHN context as the finite state machine showed below.

GHNStates.jpg

The different states of a gHN are represented by the values of the inner enumeration GHNContext.GHNSatus:

  • Status.DOWN: this is the state of a gHN that is not running within the current JVM (or not running at all). This is at once a start and terminal state for the gHN and is detected during the initialisation of the GHNContext. When the gHN is in this state, the GHNContext can only be used to access the gHN configuration and hardware-related information, as described below.
  • Status.RUNNING: this is the state of a gHN that is running within the current JVM. When the gHN is in this state, the GHNContext engages in the following activities:
    • at regular intervals, it publishes in the infrastructure a profile for the gHN. During its initialisation, in particular, the GHNContext synthesises a GCUBEHostingNode resource that models the local gHN (either from scratch or from local traces of previous gHN startups) and periodically derives a gHN profile from a serialisation of the resource state.
    • it maintains and exposes to clients a record of the RIs of the deployed services along with their current state. One distinguished client, the handlers.GCUBEHandler relies on it to block calls to RIs that have failed or are not yet ready to process them (i.e. they have reached theServiceContext.Status.FAILED state or have not yet reached the ServiceContext.Status.READY, as discussed below).
  • Status.UPDATED: this is the transitional state of a gHN that has changed some of its state. This is a short-lived state that is used internally to trigger publication of the gHN profile within the infrastructure. After publication, the gHN reverts immediately to the GHNStatus.RUNNING.

Only privileged clients and the gHN itself can trigger state transitions. All clients, however, can inspect the current state of the gHN (cf. getStatus()) and be notified of state transitions, as discussed below.

Configuration Management

This includes:

    • configuration related to the infrastructure in which the gHN operates, as described in detail in the Administrator's Guide. Some configuration properties - most noticeably those properties that benefit from some form of post-processing - are exposed by dedicated methods (cf. getInfrastructure(), getStartScopes(), getMode(), getType(), getHostame(), getPort(), etc.). Other configuration properties can be accessed with the generic facilities inherited from GCUBEContext (cf. getProperty()). .
    • configuration related to the implementations of core gCF interfaces, e.g. discovery, publishing, and remote notification interfaces (cf. getImplementation()).
    • statistics and other information related to the underlying hardware (getFreeSpace), getUptime(), getMemoryUsage(), getCPUInfo(), getLoadStatistics(), etc.).

Note: The GHNContext can expose gHN configuration and hardware-related information even when the gHN is not running in the client process, or not running at all (i.e. when its status is DOWN).

Note: The facilities for file management that GHNContextinherits from GCUBEContext (cf. getFile()) are for internal use in gCF and service developers should not use them. Instead, clients access the file system using dedicated facilities in the service context.

Event Management

The GHNContext allows clients to subscribe to be notified of GHN lifetime events, such as state transition events and RI registration events (cf. subscribeGHNEvents(), GHNContext.GHNTopic). Subscription requires the registration of a dedicated event consumer (cf. GHNContext.GHNConsumer). Clients can derive GHNContext.GHNConsumer and selectively implement only the callbacks that correspond to the events of interest.

Service Contexts

[coming soon]

PortType Contexts

[coming soon]