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="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <parent>
    <artifactId>org.opennaas.extensions.bundles</artifactId>
    <groupId>org.opennaas</groupId>
    <version>0.25-SNAPSHOT</version>
  </parent>
  <artifactId>org.opennaas.extensions.myresource</artifactId>
  	<!--  Maven configuration -->
  	<modelVersion>4.0.0</modelVersion>
  	<packaging>bundle</packaging>
	<name>OpenNaaS :: My Resource </name>
	<description>My Resource  Implementation</description>
 	<dependencies>
		<dependency>
			<groupId>org.opennaas</groupId>
			<artifactId>org.opennaas.core.resources</artifactId>
		</dependency>
		<dependency>
			<groupId>org.opennaas</groupId>
			<artifactId>org.opennaas.extensions.queuemanager</artifactId>
		</dependency>
		<dependency>
			<groupId>org.apache.karaf.shell</groupId>
			<artifactId>org.apache.karaf.shell.console</artifactId>
		</dependency>

 	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.ops4j</groupId>
				<artifactId>maven-pax-plugin</artifactId>
			</plugin>
			<plugin>
				<groupId>org.apache.felix</groupId>
				<artifactId>maven-bundle-plugin</artifactId>
				<extensions>true</extensions>
				<!--
					| the following instructions build a simple set of public/private
					classes into an OSGi bundle
				-->
				<configuration>
					<instructions>
						<Bundle-Activator>org.opennaas.extensions.myresource.capability.example.Activator</Bundle-Activator>
						<Import-Package>org.slf4j,*</Import-Package>
						<Export-Package>
							org.opennaas.extensions.myresource.capability.example;version="${project.version}"
						</Export-Package>
						</instructions>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>
  • (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:

<resourceDescriptor>
	<!-- Capability information -->
	<capabilityDescriptors>
		<information><type>name</type></information>
	</capabilityDescriptors>
	<!-- Resource information. It specify type and name-->
	<information>
		<type>myresource</type>
		<name>resource5</name>
	</information>
	<properties/>
</resourceDescriptor>

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.