Prev |  | Next

## Creating Plans

Plans are similar to PARs in that they encapsulate the artifacts of an application as a single unit. However plans are XML files that refer to their artifacts, whereas PARs are JAR files that physically contain their artifacts. Plans, known as parent plans may refer to other plans, known as child plans.

Plans share several benefits with PARs:

- A plan has a (symbolic) name and a version.
- A plan may be scoped, although this is optional. See Plans and Scoping for more on scoping.
- A plan is visible to management interfaces.
- A plan can be undeployed and redeployed as a unit.
- A plan may be atomic, although this is optional.

Plans have the following additional benefits compared to PARs:

- Virgo deploys the artifacts in the plan in the order in which they are listed in the XML file, which gives you complete control over deployment order. With a PAR, the order of deployment of the included artifacts is not guaranteed.
- Since plans refer to their artifacts, it is easier to share content between plans as well as update individual parts of a plan without having to physically repackage (re-JAR) it.
- Plans may contain child plans, but PARs cannot contain other PARs.
- You can make certain plans deploy faster by disabling the provisioning of bundles to satisfy missing dependencies, but you cannot disable provisioning for PARs.
- You can specify whether a plan is scoped or unscoped and atomic or non-atomic; PARs are always scoped and atomic.

The artifacts of a plan are usually stored in Virgo's repository. This means, for example, that if you drop one of the plan’s artifacts in the `pickup` directory rather than adding it to the repository, the plan will fail to deploy because it will not find the artifact.

The artifacts of a plan may also be stored outside Virgo's repository, somewhere else on the file system and referenced from the plan using URIs. Such artifacts must be available on the file system when the plan is deployed and when Virgo restarts while the plan is deployed. If you delete any of these artifacts, deployment of the plan may fail, either when it is initially deployed or when Virgo restarts.

### Creating the Plan XML File

Plans are XML files that have a `.plan` file extension, such as `multi-artifact.plan`. The structure of the XML file is simple: the root element is `<plan>` with attributes specifying the name of the plan, the version, atomicity, and scoping. Then, for each artifact that makes up your application, you add a `<artifact>` element, using its attributes to specify the type of artifact and its name and version. The following is a simple example of a plan’s XML file:

    <?xml version="1.0" encoding="UTF-8"?>
    <plan name="multi-artifact.plan" version="1.0.0" scoped="true" atomic="true"
            xmlns="http://www.eclipse.org/virgo/schema/plan"
    		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    		xsi:schemaLocation="
    		        http://www.eclipse.org/virgo/schema/plan
    		        http://www.eclipse.org/virgo/schema/plan/eclipse-virgo-plan.xsd">

        <artifact type="configuration" name="app-properties" version="1.0.0"/>
        <artifact type="bundle" name="com.springsource.exciting.app" version="[2.0.0, 3.1.0)"/>

    </plan>

In the preceding example, the name of the plan is `multi-artifact.plan` and its version is `1.0.0`. The plan is both scoped and atomic. The plan contains two artifacts: one is a bundle called `com.springsource.exciting.app` and the other is a configuration file called `app-properties`.

The following table describes the attributes of the `<plan>` element.

Table 4.2. Attributes of the <plan> Element

Attribute | Description | Required?
--- | --- | ---
`name` | Specifies the name of this plan. Virgo uses the name as one component of the unique identifier of this plan. | Yes.
`version` | Specifies the version of this plan. You must use OSGi version specification syntax, such as `2.1.0`. Virgo uses the version as one component of the unique identifier of this plan. | Yes.

`scoped`

Specifies whether Virgo should install the artifacts into plan-specific scope so that only the application described by this plan has access to the artifacts. If you disable scoping, then Virgo installs the artifacts into the global scope, which means they are then available for access by all other deployed artifacts. Set the attribute to `true` to enable scoping or `false` to disable it.

Yes.

`atomic`

Specifies whether you want to tie together the lifecycle of the artifacts in this plan. Making a plan atomic means that if you start, stop, or uninstall a single artifact in the plan, Virgo escalates the operation to the whole plan. Also Virgo prevents artifacts of an atomic plan from being in inconsistent states. For example, if one artifact should fail to start, then Virgo stops all artifacts in the plan. Set this attribute to `true` to enable atomicity or `false` to disable it.

Yes.

`provisioning`

Specifies whether Virgo installs bundles from the repository to attempt to satisfy any missing dependencies in the plan. Missing dependencies prevent one or more bundles in the plan from resolving. For example, a bundle which imports a package cannot resolve if the package is missing, that is, not exported by another bundle.

A value of `auto` instructs Virgo to install bundles from the repository to attempt to satisfy any missing dependencies in the plan. This is known as auto-provisioning.

A value of `disabled` prevents Virgo from installing bundles from the repository to attempt to satisfy any missing dependencies in the plan. This value can make the plan deploy faster, although if there are missing dependencies, deployment will fail.

A value of `inherit`, which is the default if no value is specified, inherits the parent plan's provisioning behaviour. If the plan does not have a parent, it inherits Virgo's auto-provisioning behaviour.

No. If not specified, defaults to `inherit`.

The following table describes the attributes of the `<artifact>` element. Note that you must either specify `type`, `name`, and (optionally) `version`, in which case Virgo's repository is searched for the artifact, or `uri` in which case the artifact is obtained directly from the file system. If you specify `uri`, you must not specify `type`, `name`, or `version`.

Table 4.3. Attributes of the <artifact> Element

Attribute | Description | Required?
--- | --- | ---

`type`

Specifies the type of the artifact. Valid values are:

- `bundle`: Specifies an OSGi bundle. Use this artifact type for WAR files and Web application bundles.
- `configuration`: Specifies that the artifact is a configuration file. Configuration files contain name/value pairs that set initial values for configuration properties of a bundle.
- `plan`: Specifies that the artifact is a plan.
- `par`: Specifies that the artifact is a PAR.

Yes, unless `uri` is specified in which case `type` must not be specified and is automatically determined from the artifact.

`name` | Specifies the name of the artifact. See Artifact Names for guidelines for determining the name of an artifact. | Yes, unless `uri` is specified in which case `name` must not be specified and is automatically determined from the artifact.

`version`

Specifies the range of versions of this artifact that Virgo should look up in its repositories and then install and deploy. You must use OSGi version specification syntax, such as `[1.0.0, 2.0.0)`. Note that a single version number represents the range from that version number upwards. For example, `1.3` represents the range of versions greater than or equal to `1.3`.

No. If `uri` is specified, `version` must not be specified. If neither `uri` nor `version` are specified, `version` defaults to `0`, which in OSGi means 0 to infinity, or any version.

`uri`

Specifies an optional, absolute URI string beginning with `file:` that refers to the artifact on the file system. Such an artifact must be available on the file system when the plan is deployed and when Virgo restarts while the plan is deployed. If you delete such an artifact, deployment of the plan may fail, either when it is initially deployed or when Virgo restarts. This attribute is normally omitted so that the artifact is searched for in Virgo's repository.

No. If not specified, Virgo searches for the artifact in its repository.

### Artifact Names

When you create a plan, you use the `name` attribute of the `<artifact>` element to specify the name of all the plan’s dependencies. This section describes how to determine the name of an artifact, which is not always obvious.

Use the following guidelines to determine the name of an artifact:

- Bundle: In this context, a bundle refers to a standard OSGi bundle as well as a Web Application Bundle and a WAR file. The name of a bundle is the value of the `Bundle-SymbolicName` header in the `META-INF/MANIFEST.MF` file of the `*.jar`. If a WAR file has `Bundle-SymbolicName` header then it will be treated as a Web Application Bundle. The following `MANIFEST.MF` snippet shows a bundle with name `com.springsource.exciting.app`:

      Bundle-SymbolicName: org.eclispe.virgo.exciting.app

  If the bundle does not contain a `META-INF/MANIFEST.MF` file or the `MANIFEST.MF` doesn't contain a `Bundle-SymbolicName` header, then the name of the bundle is its filename minus the `.jar` or `.war` extension.

- Configuration File: The name of a configuration or PID (Persistent Identity) is its filename minus the `.properties` extension. The PID can also be specified within the properties file with the service.pid property.

- Plan: The name of a plan is the value of the required `name` attribute of the `<plan>` element in the plan’s XML file. In the following XML snippet, the plan name is `multi-artifact.plan`:

      <?xml version="1.0" encoding="UTF-8"?>
      <plan name="multi-artifact.plan" version="3.5.0" scoped="true" atomic="true"
              xmlns="http://www.eclipse.org/virgo/schema/plan"
      ...

- PAR: The name of a PAR is the value of the `Application-SymbolicName` header in the `META-INF/MANIFEST.MF` file of the `*.par` file. The following `MANIFEST.MF` snippet shows a PAR with name `com.springsource.my.par`:

      Application-SymbolicName: org.eclipse.virgo.my.par

  If the PAR does not contain a `META-INF/MANIFEST.MF` file, then the name of the PAR is its filename minus the `.par` extension.

### Supplying Properties to Artifacts

It is possible to pass properties to an artifact specified in a plan. An example of this can be seen in the Admin Console plan where the context path to be used in the Admin console is passed from the plan.

        <artifact type="bundle" name="org.eclipse.virgo.apps.admin.web" version="[3.0, 4.0)">
            <property name="header:Web-ContextPath" value="/admin" />
        </artifact>

The only supported property is `header` which will overwrite the given manifest header with the supplied value. This should be used with care!

### Using the Plan

Because a plan is a list of artifacts, rather than a physical file that contains the artifacts, there are a few additional steps you must perform before you deploy it to Virgo.

1. Copy the artifacts that make up the plan to the `usr` repository, which by default is the `$SERVER_HOME/repository/usr` directory, where `$SERVER_HOME` refers to the top-level installation directory of Virgo. Note that you might have configured the server differently; in which case, copy the artifacts to your custom repository directory.

2. Restart Virgo if the repository used is not a watched repository.

3. After the server has started, either use the Admin Console to deploy the plan, or manually deploy it by copying the plan’s XML file into the `$SERVER_HOME/pickup` directory.

   This results in Virgo deploying the plan.

4. To undeploy the plan, use the Admin Console, or simply delete it from the `$SERVER_HOME/pickup` directory.

### Plans and Scoping

As described in previous sections, you can specify that a plan be scoped. This means that Virgo installs the artifacts that make up the plan into a plan-specific scope so that only the application described by the plan has access to the artifacts. If you disable scoping, then Virgo installs the artifacts into the global scope, which means they are available for access by all other deployed artifacts. This section describes scoping in a bit more detail. It also describes how you can change the default behavior of scoping, with respect to services, so that a service that is in a scope can be made globally available.

If a bundle in a given scope imports a package and a bundle in the same scope exports the package, then the import may only be satisfied by the bundle in the scope, and not by any bundles outside the scope, including the global scope. Similarly, package exports from bundles in a scope are not visible to bundles in the global scope.

If a bundle in a scope uses Spring DM (or the blueprint service) to obtain a service reference and a bundle in the same scope uses Spring DM (or the blueprint service) to publish a matching service, then the service reference may only bind to the service published in the scope (and not to any services outside the scope). Services published by bundles in a scope are not visible to bundles in the global scope.

However, sometimes it is useful to make a service in a scope globally available to artifacts outside the scope. To do this, publish the service with the `org.eclipse.virgo.service.scope` service property set to `global`. Use the `<service-properties>` child element of `<service>`, as shown in the following example:

    <service id="publishIntoGlobal" interface="java.lang.CharSequence">
      <service-properties>
        <beans:entry key="org.eclipse.virgo.service.scope" value="global" />
      </service-properties>
      <beans:bean class="java.lang.String">
        <beans:constructor-arg value="foo"/>
      </beans:bean>
    </service>

A scope forms a boundary for automatic propagation of load time weaving and bundle refresh. Additionally, a synthetic context bundle is generated for each scope. This bundle imports all the packages exported by other bundles in the scope. The class loader of the synthetic context bundle is used for thread context class loading. So, for example, hibernate will be able to load classes of any of the exported packages of the bundles in a scope using the thread context class loader.

To ensure predictable class loading behaviour and avoid other issues associated with split packages (packages whose classes are split across more than one bundle), the synthetic context bundle has a restriction: no package may be exported by more than one bundle in the scope. If this restriction is broken, the scoped application will fail to deploy. This restriction can cause problems for substitutable exports.

#### Web Applications and Scoping

A Web Application Bundle (WAB) or WAR has its bundle class loader set as the TCCL, even when the WAB or WAR belongs to a PAR or scoped plan. To enable the TCCL to load classes of other bundles in the same scope as a WAB or WAR, use a WAB which imports the necessary packages.

Also a WAB or WAR has its own per-application trace, independent of the per-application trace of any PAR or scoped plan to which the WAB or WAR belongs.

Prev | Up | Next
| Home |