Create a new resource

Explaining SampleResource

The SampleResource is a resource intended to illustrate how to support new resources in OpenNaaS. It offers a skeleton that can be used as a base to develop new resource types.

Resources are created by providing a resource descriptor to OpenNaaS ResourceManager, which delegates descriptor interpretation to a ResourceRepository based on the resource type specified in the descriptor. This ResourceRepository is one the of pieces to provide for OpenNaaS being able to support a new resource type. Its responsibility is to:

  • create resources given a correct descriptor,
  • persist the descriptor and
  • manage resource life-cycle through life-cycle calls (createResource, startResource, stopResource, removeResource).

Once a resource has been created it may be started for it to be active. During the start process ResourceBootstrapper comes into play. It is the responsible of initializing the resource model and it is also required as part of the new resource type support.

An active resource has an initialized model and some capabilities to operate with it.

Capabilities are per resource-type functional packages that users may interact to get resource state and alter it. They often delegate to drivers some of its operations, that’s because while capabilities are fabric unaware, drivers are fabric specific.

The ExampleCapability requires no drivers, because it can provide all functionality by its own. However, an ExampleActionSet class is provided as a guide.

A capability ActionSet defines which actions should be provided by a driver in order to be suitable for the capability.

When a resource is created in OpenNaaS, which capabilities should be loaded for it and what drivers should they use is specified in the resource descriptor. A descriptor for sample resource using a example capability can be found in  OPENNAAS_PATH/utils/examples/descriptors/sampleresource.descriptor

In order for all pieces to communicate with each other, some of them should export or consume OSGi services. It is the case of capabilities and drivers, but also resource repository and bootstrapper. The following file is used to achieve this goal:  OPENNAAS_PATH/src/main/resources/OSGI-INF/blueprint/core.xml

Blueprint is essentially a standardized version of Spring DM. It is a dependency injection framework that simplifies interaction with the OSGi container—for example, providing standard XML elements to import and export OSGi services.

Create a new resource

You can create a new basic resource for OpenNaaS following the next steps:

1. Copy SampleResource.

  • You can find a basic resource at OPENNAAS_PATH/extensions/bundles/sampleresource. Copy that directory and change the folder name to match your new resource (e.g. myresource)
  • Open the folder and edit the pom.xml to change all the sampleresouce to myresource. The file will look like that:
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  	<!--  Maven configuration -->
	<name>OpenNaaS :: My Resource </name>
	<description>My Resource  Implementation</description>

					| the following instructions build a simple set of public/private
					classes into an OSGi bundle
  • (If you want the parent pom.xml to compile the new resource you need to add the module).
  • Now, you can import the Maven project into your IDE, which will make easier for you to work with the project.

2. Create the descriptor

Use the sampleresource.descriptor available at OPENNAAS_PATH/utils/examples/descriptors. Your new descriptor will be:

	<!-- Capability information -->
	<!-- Resource information. It specify type and name-->

Create a feature

Because applications and other tools typically consist of multiple OSGi bundles, it is often convenient to aggregate inter-dependent or related bundles into a larger unit of deployment. A feature enables you to deploy multiple bundles (and, optionally, dependencies on other features) in a single step.